~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to ima/src/italc_side_bar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080617134654-2y5m7ki93r5c1ysf
Tags: upstream-1.0.9~rc3
ImportĀ upstreamĀ versionĀ 1.0.9~rc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * italc_side_bar.cpp - implementation iTALC's side-bar
 
3
 *
 
4
 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
 
5
 *
 
6
 * This file is part of iTALC - http://italc.sourceforge.net
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#include "italc_side_bar.h"
 
27
#include "fast_qimage.h"
 
28
 
 
29
#include <QtGui/QPainter>
 
30
#include <QtGui/QMenu>
 
31
#include <QtGui/QContextMenuEvent>
 
32
 
 
33
#include <config.h>
 
34
 
 
35
 
 
36
 
 
37
italcSideBar::italcSideBar( KMultiTabBarStyle _style, QWidget * _parent,
 
38
                                                        QWidget * _splitter ) :
 
39
        KMultiTabBar( Left, _parent ),
 
40
        m_openedTab( -1 )
 
41
{
 
42
        setAttribute( Qt::WA_OpaquePaintEvent, TRUE );
 
43
        setStyle( _style );
 
44
        m_tabWidgetParent = new QWidget( _splitter );
 
45
        m_tabWidgetParent->hide();
 
46
        QVBoxLayout * vl = new QVBoxLayout( m_tabWidgetParent );
 
47
        vl->setSpacing( 0 );
 
48
        vl->setMargin( 0 );
 
49
}
 
50
 
 
51
 
 
52
 
 
53
 
 
54
italcSideBar::~italcSideBar()
 
55
{
 
56
}
 
57
 
 
58
 
 
59
 
 
60
 
 
61
void italcSideBar::setTab( const int _id, const bool _state )
 
62
{
 
63
        if( m_widgets[_id] != NULL )
 
64
        {
 
65
                KMultiTabBar::setTab( _id, _state );
 
66
                if( _state )
 
67
                {
 
68
                        m_widgets[_id]->show();
 
69
                        m_openedTab = _id;
 
70
                        m_tabWidgetParent->show();
 
71
                }
 
72
                else
 
73
                {
 
74
                        m_widgets[_id]->hide();
 
75
                        m_openedTab = -1;
 
76
                }
 
77
        }
 
78
}
 
79
 
 
80
 
 
81
 
 
82
 
 
83
int italcSideBar::appendTab( sideBarWidget * _sbw, const int _id )
 
84
{
 
85
        int ret = KMultiTabBar::appendTab( _sbw->icon(), _id,
 
86
                                                _sbw->title(),
 
87
                                                _sbw->description()
 
88
                                                );
 
89
        m_widgets[_id] = _sbw;
 
90
        _sbw->hide();
 
91
        _sbw->setMinimumWidth( 300 );
 
92
        connect( tab( _id ), SIGNAL( clicked( int ) ), this,
 
93
                                        SLOT( tabClicked( int ) ) );
 
94
        return( ret );
 
95
}
 
96
 
 
97
 
 
98
 
 
99
void italcSideBar::tabClicked( int _id )
 
100
{
 
101
        // disable all other tabbar-buttons 
 
102
        QMap<int, QWidget *>::Iterator it;
 
103
        for( it = m_widgets.begin(); it != m_widgets.end(); ++it )
 
104
        {
 
105
                if( it.key() != _id )
 
106
                {
 
107
                        setTab( it.key(), FALSE );
 
108
                }
 
109
        }
 
110
 
 
111
        setTab( _id, isTabRaised( _id ) );
 
112
 
 
113
        if( m_openedTab == -1 )
 
114
        {
 
115
                m_tabWidgetParent->hide();
 
116
        }
 
117
        else
 
118
        {
 
119
                m_tabWidgetParent->show();
 
120
        }
 
121
}
 
122
 
 
123
 
 
124
 
 
125
 
 
126
void italcSideBar::paintEvent( QPaintEvent * _pe )
 
127
{
 
128
        QWidget::paintEvent( _pe );
 
129
 
 
130
        QPainter p( this );
 
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  );
 
135
 
 
136
        p.rotate( 270 );
 
137
        p.drawImage( -height()+3, width()-22, fastQImage(
 
138
                        QImage( ":/resources/logo.png" ) ).scaled( 24, 24 ) );
 
139
        QFont f = p.font();
 
140
        f.setBold( TRUE );
 
141
        f.setPointSize( 15 );
 
142
        p.setFont( f );
 
143
        p.setPen( QColor( 255, 216, 0 ) );
 
144
        p.drawText( -height()+32, width()-3,
 
145
                                QString( "iTALC %1" ).arg( PACKAGE_VERSION ) );
 
146
}
 
147
 
 
148
 
 
149
 
 
150
 
 
151
void italcSideBar::contextMenuEvent( QContextMenuEvent * _e )
 
152
{
 
153
        QMenu m( this );
 
154
        foreach( KMultiTabBarTab * tab, tabs() )
 
155
        {
 
156
                QAction * ma = m.addAction( tab->text() );
 
157
                ma->setCheckable( TRUE );
 
158
                ma->setChecked( tab->isTabVisible() );
 
159
        }
 
160
        connect( &m, SIGNAL( triggered( QAction * ) ),
 
161
                        this, SLOT( toggleButton( QAction * ) ) );
 
162
        m.exec( _e->globalPos() );
 
163
}
 
164
 
 
165
 
 
166
 
 
167
 
 
168
void italcSideBar::toggleButton( QAction * _a )
 
169
{
 
170
        foreach( KMultiTabBarTab * tab, tabs() )
 
171
        {
 
172
                if( tab->text() == _a->text() )
 
173
                {
 
174
                        if (tab->isTabVisible())
 
175
                        {
 
176
                                tab->setTabVisible(FALSE);
 
177
                                if ( m_openedTab == tab->id() )
 
178
                                {
 
179
                                        setTab( tab->id(), FALSE );
 
180
                                        m_tabWidgetParent->hide();
 
181
                                }
 
182
                        }
 
183
                        else
 
184
                        {
 
185
                                tab->setTabVisible(TRUE);
 
186
                                if ( m_openedTab == -1 )
 
187
                                {
 
188
                                        setTab( tab->id(), TRUE );
 
189
                                }
 
190
                        }
 
191
                        break;
 
192
                }
 
193
        }
 
194
        update();
 
195
}
 
196
 
 
197
 
 
198
 
 
199
 
 
200
 
 
201