2
* italc_side_bar.cpp - implementation iTALC's side-bar
4
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
6
* This file is part of iTALC - http://italc.sourceforge.net
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
26
#include "italc_side_bar.h"
27
#include "fast_qimage.h"
29
#include <QtGui/QPainter>
30
#include <QtGui/QMenu>
31
#include <QtGui/QContextMenuEvent>
37
italcSideBar::italcSideBar( KMultiTabBarStyle _style, QWidget * _parent,
38
QWidget * _splitter ) :
39
KMultiTabBar( Left, _parent ),
42
setAttribute( Qt::WA_OpaquePaintEvent, TRUE );
44
m_tabWidgetParent = new QWidget( _splitter );
45
m_tabWidgetParent->hide();
46
QVBoxLayout * vl = new QVBoxLayout( m_tabWidgetParent );
54
italcSideBar::~italcSideBar()
61
void italcSideBar::setTab( const int _id, const bool _state )
63
if( m_widgets[_id] != NULL )
65
KMultiTabBar::setTab( _id, _state );
68
m_widgets[_id]->show();
70
m_tabWidgetParent->show();
74
m_widgets[_id]->hide();
83
int italcSideBar::appendTab( sideBarWidget * _sbw, const int _id )
85
int ret = KMultiTabBar::appendTab( _sbw->icon(), _id,
89
m_widgets[_id] = _sbw;
91
_sbw->setMinimumWidth( 300 );
92
connect( tab( _id ), SIGNAL( clicked( int ) ), this,
93
SLOT( tabClicked( int ) ) );
99
void italcSideBar::tabClicked( int _id )
101
// disable all other tabbar-buttons
102
QMap<int, QWidget *>::Iterator it;
103
for( it = m_widgets.begin(); it != m_widgets.end(); ++it )
105
if( it.key() != _id )
107
setTab( it.key(), FALSE );
111
setTab( _id, isTabRaised( _id ) );
113
if( m_openedTab == -1 )
115
m_tabWidgetParent->hide();
119
m_tabWidgetParent->show();
126
void italcSideBar::paintEvent( QPaintEvent * _pe )
128
QWidget::paintEvent( _pe );
131
QLinearGradient linearGrad( QPoint( 0, 0 ), QPoint( 0, height() ) );
132
linearGrad.setColorAt( 0.1, QColor( 0, 64, 224 ) );
133
linearGrad.setColorAt( 1, Qt::black );
134
p.fillRect( 0, 0, width(), height(), linearGrad );
137
p.drawImage( -height()+3, width()-22, fastQImage(
138
QImage( ":/resources/logo.png" ) ).scaled( 24, 24 ) );
141
f.setPointSize( 15 );
143
p.setPen( QColor( 255, 216, 0 ) );
144
p.drawText( -height()+32, width()-3,
145
QString( "iTALC %1" ).arg( PACKAGE_VERSION ) );
151
void italcSideBar::contextMenuEvent( QContextMenuEvent * _e )
154
foreach( KMultiTabBarTab * tab, tabs() )
156
QAction * ma = m.addAction( tab->text() );
157
ma->setCheckable( TRUE );
158
ma->setChecked( tab->isTabVisible() );
160
connect( &m, SIGNAL( triggered( QAction * ) ),
161
this, SLOT( toggleButton( QAction * ) ) );
162
m.exec( _e->globalPos() );
168
void italcSideBar::toggleButton( QAction * _a )
170
foreach( KMultiTabBarTab * tab, tabs() )
172
if( tab->text() == _a->text() )
174
if (tab->isTabVisible())
176
tab->setTabVisible(FALSE);
177
if ( m_openedTab == tab->id() )
179
setTab( tab->id(), FALSE );
180
m_tabWidgetParent->hide();
185
tab->setTabVisible(TRUE);
186
if ( m_openedTab == -1 )
188
setTab( tab->id(), TRUE );