1
/********************************************************************
2
Tabstrip KWin window decoration
3
This file is part of the KDE project.
5
Copyright (C) 2009 Jorge Mata <matamax123@gmail.com>
6
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 2 of the License, or
11
(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
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*********************************************************************/
22
#include <kcommondecoration.h>
23
#include "tabstripbutton.h"
24
#include "tabstripdecoration.h"
25
#include "tabstripfactory.h"
34
TabstripButton::TabstripButton( ButtonType type, TabstripDecoration *parent, QString tip )
35
: KCommonDecorationButton( type, parent ), SIZE( 16 )
37
setAutoFillBackground( false );
38
setFixedSize( SIZE, SIZE );
39
setCursor( Qt::ArrowCursor );
47
TabstripButton::~TabstripButton()
51
void TabstripButton::reset( unsigned long )
56
QSize TabstripButton::sizeHint() const
58
return QSize( SIZE, SIZE );
61
void TabstripButton::paintEvent( QPaintEvent * )
64
const bool active = client->isActive() && active_item;
67
QRect geom = QRect( 3, 3, width() - 6, height() - 6 );
69
// Determine painting colors
70
QColor bgColor = client->options()->color( KDecoration::ColorTitleBar, active );
71
QColor textColor = client->options()->color( KDecoration::ColorFont, active );
73
{ // Invert if the mouse cursor is hovering over the button
74
textColor.setRed( 255 - textColor.red() );
75
textColor.setGreen( 255 - textColor.green() );
76
textColor.setBlue( 255 - textColor.blue() );
79
// Slight optimization as we are drawing solid straight lines
80
p.setRenderHint( QPainter::Antialiasing, false );
83
p.fillRect( 0, 0, width(), height(), bgColor );
84
//p.fillRect( 0, 0, width(), height(), QColor( 255, 0, 0 ));
86
// Paint buttons with the text color
87
p.setPen( textColor );
96
p.drawText( geom.adjusted( 0, 1, 0, 0), Qt::AlignVCenter | Qt::AlignHCenter, "?" );
100
switch( client->maximizeMode() )
102
case TabstripDecoration::MaximizeRestore:
103
case TabstripDecoration::MaximizeVertical:
104
case TabstripDecoration::MaximizeHorizontal:
106
p.drawLine( geom.x() + 3, geom.y(),
107
geom.x(), geom.y() );
108
p.drawLine( geom.x(), geom.y() + 3,
109
geom.x(), geom.y() );
110
p.drawLine( geom.x() + 3, geom.y() + 1,
111
geom.x(), geom.y() + 1 );
112
p.drawLine( geom.x() + 1, geom.y() + 3,
113
geom.x(), geom.y() + 1 );
115
p.drawLine( geom.x() + geom.width() - 3, geom.y(),
116
geom.x() + geom.width(), geom.y() );
117
p.drawLine( geom.x() + geom.width(), geom.y() + 3,
118
geom.x() + geom.width(), geom.y() );
119
p.drawLine( geom.x() + geom.width() - 3, geom.y() + 1,
120
geom.x() + geom.width(), geom.y() + 1 );
121
p.drawLine( geom.x() + geom.width() - 1, geom.y() + 3,
122
geom.x() + geom.width() - 1, geom.y() );
124
p.drawLine( geom.x() + 3, geom.y() + geom.height(),
125
geom.x(), geom.y() + geom.height() );
126
p.drawLine( geom.x(), geom.y() + geom.height() - 3,
127
geom.x(), geom.y() + geom.height() );
128
p.drawLine( geom.x() + 3, geom.y() + geom.height() - 1,
129
geom.x(), geom.y() + geom.height() - 1 );
130
p.drawLine( geom.x() + 1, geom.y() + geom.height() - 3,
131
geom.x() + 1, geom.y() + geom.height() );
133
p.drawLine( geom.x() + geom.width() - 3, geom.y() + geom.height(),
134
geom.x() + geom.width(), geom.y() + geom.height() );
135
p.drawLine( geom.x() + geom.width(), geom.y() + geom.height() - 3,
136
geom.x() + geom.width(), geom.y() + geom.height() );
137
p.drawLine( geom.x() + geom.width() - 3, geom.y() + geom.height() - 1,
138
geom.x() + geom.width(), geom.y() + geom.height() - 1 );
139
p.drawLine( geom.x() + geom.width() - 1, geom.y() + geom.height() - 3,
140
geom.x() + geom.width() - 1, geom.y() + geom.height() );
142
case TabstripDecoration::MaximizeFull:
144
p.drawLine( geom.x() + 2, geom.y(),
145
geom.x() + 2, geom.y() + 2 );
146
p.drawLine( geom.x(), geom.y() + 2,
147
geom.x() + 2, geom.y() + 2 );
148
p.drawLine( geom.x() + 3, geom.y(),
149
geom.x() + 3, geom.y() + 3 );
150
p.drawLine( geom.x(), geom.y() + 3,
151
geom.x() + 3, geom.y() + 3 );
153
p.drawLine( geom.x() + geom.width() - 2, geom.y(),
154
geom.x() + geom.width() - 2, geom.y() + 2 );
155
p.drawLine( geom.x() + geom.width(), geom.y() + 2,
156
geom.x() + geom.width() - 2, geom.y() + 2 );
157
p.drawLine( geom.x() + geom.width() - 3, geom.y(),
158
geom.x() + geom.width() - 3, geom.y() + 3 );
159
p.drawLine( geom.x() + geom.width(), geom.y() + 3,
160
geom.x() + geom.width() - 3, geom.y() + 3 );
162
p.drawLine( geom.x() + 2, geom.y() + geom.height(),
163
geom.x() + 2, geom.y() + geom.height() - 2 );
164
p.drawLine( geom.x(), geom.y() + geom.height() - 2,
165
geom.x() + 2, geom.y() + geom.height() - 2 );
166
p.drawLine( geom.x() + 3, geom.y() + geom.height(),
167
geom.x() + 3, geom.y() + geom.height() - 3 );
168
p.drawLine( geom.x(), geom.y() + geom.height() - 3,
169
geom.x() + 3, geom.y() + geom.height() - 3 );
171
p.drawLine( geom.x() + geom.width() - 2, geom.y() + geom.height(),
172
geom.x() + geom.width() - 2, geom.y() + geom.height() - 2 );
173
p.drawLine( geom.x() + geom.width(), geom.y() + geom.height() - 2,
174
geom.x() + geom.width() - 2, geom.y() + geom.height() - 2 );
175
p.drawLine( geom.x() + geom.width() - 3, geom.y() + geom.height(),
176
geom.x() + geom.width() - 3, geom.y() + geom.height() - 3 );
177
p.drawLine( geom.x() + geom.width(), geom.y() + geom.height() - 3,
178
geom.x() + geom.width() - 3, geom.y() + geom.height() - 3 );
184
p.drawLine( geom.x(), geom.y() + geom.height(),
185
geom.x() + geom.width(), geom.y() + geom.height() );
186
p.drawLine( geom.x(), geom.y() + geom.height() - 1,
187
geom.x() + geom.width(), geom.y() + geom.height() - 1 );
189
p.drawLine( geom.x(), geom.y() + geom.height() - 3,
190
geom.x(), geom.y() + geom.height() );
191
p.drawLine( geom.x() + 1, geom.y() + geom.height() - 3,
192
geom.x() + 1, geom.y() + geom.height() );
194
p.drawLine( geom.x() + geom.width(), geom.y() + geom.height() - 3,
195
geom.x() + geom.width(), geom.y() + geom.height() );
196
p.drawLine( geom.x() + geom.width() - 1, geom.y() + geom.height() - 3,
197
geom.x() + geom.width() - 1, geom.y() + geom.height() );
200
case ItemCloseButton:
202
p.drawLine( geom.x() + 1, geom.y() + 1,
203
geom.x() + geom.width() - 1, geom.y() + geom.height() - 1 );
204
p.drawLine( geom.x() + 2, geom.y() + 1,
205
geom.x() + geom.width() - 1, geom.y() + geom.height() - 2 );
206
p.drawLine( geom.x() + 1, geom.y() + 2,
207
geom.x() + geom.width() - 2, geom.y() + geom.height() - 1 );
209
p.drawLine( geom.x() + 1, geom.y() + geom.height() - 1,
210
geom.x() + geom.width() - 1, geom.y() + 1 );
211
p.drawLine( geom.x() + 2, geom.y() + geom.height() - 1,
212
geom.x() + geom.width() - 1, geom.y() + 2 );
213
p.drawLine( geom.x() + 1, geom.y() + geom.height() - 2,
214
geom.x() + geom.width() - 2, geom.y() + 1 );
217
if( client->clientGroupItems().count() > 1 || !TabstripFactory::showIcon() )
219
p.drawRect( geom.x(), geom.y() + geom.height() / 2 - 5,
221
p.drawRect( geom.x(), geom.y() + geom.height() / 2 - 1,
223
p.drawRect( geom.x(), geom.y() + geom.height() / 2 + 3,
225
p.drawRect( geom.x() + 4, geom.y() + geom.height() / 2 - 5,
226
geom.width() - 5, 1 );
227
p.drawRect( geom.x() + 4, geom.y() + geom.height() / 2 - 1,
228
geom.width() - 5, 1 );
229
p.drawRect( geom.x() + 4, geom.y() + geom.height() / 2 + 3,
230
geom.width() - 5, 1 );
233
p.drawPixmap( 0, 0, client->icon().pixmap( SIZE ));
235
case OnAllDesktopsButton:
238
p.fillRect( geom.x() + geom.width() / 2 - 1, geom.y() + geom.height() / 2 - 1,
242
p.fillRect( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 - 4,
244
p.fillRect( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 + 2,
246
p.fillRect( geom.x() + geom.width() / 2 + 2, geom.y() + geom.height() / 2 - 4,
248
p.fillRect( geom.x() + geom.width() / 2 + 2, geom.y() + geom.height() / 2 + 2,
259
p.drawRect( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 + 3,
262
p.drawPoint( geom.x() + geom.width() / 2, geom.y() + geom.height() / 2 + o );
263
p.drawLine( geom.x() + geom.width() / 2 - 1, geom.y() + geom.height() / 2 + o + 1,
264
geom.x() + geom.width() / 2 + 1, geom.y() + geom.height() / 2 + o + 1 );
265
p.drawLine( geom.x() + geom.width() / 2 - 2, geom.y() + geom.height() / 2 + o + 2,
266
geom.x() + geom.width() / 2 + 2, geom.y() + geom.height() / 2 + o + 2 );
267
p.drawLine( geom.x() + geom.width() / 2 - 3, geom.y() + geom.height() / 2 + o + 3,
268
geom.x() + geom.width() / 2 + 3, geom.y() + geom.height() / 2 + o + 3 );
269
p.drawLine( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 + o + 4,
270
geom.x() + geom.width() / 2 + 4, geom.y() + geom.height() / 2 + o + 4 );
279
p.drawRect( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 - 5,
282
p.drawPoint( geom.x() + geom.width() / 2, geom.y() + geom.height() / 2 + o );
283
p.drawLine( geom.x() + geom.width() / 2 - 1, geom.y() + geom.height() / 2 + o - 1,
284
geom.x() + geom.width() / 2 + 1, geom.y() + geom.height() / 2 + o - 1 );
285
p.drawLine( geom.x() + geom.width() / 2 - 2, geom.y() + geom.height() / 2 + o - 2,
286
geom.x() + geom.width() / 2 + 2, geom.y() + geom.height() / 2 + o - 2 );
287
p.drawLine( geom.x() + geom.width() / 2 - 3, geom.y() + geom.height() / 2 + o - 3,
288
geom.x() + geom.width() / 2 + 3, geom.y() + geom.height() / 2 + o - 3 );
289
p.drawLine( geom.x() + geom.width() / 2 - 4, geom.y() + geom.height() / 2 + o - 4,
290
geom.x() + geom.width() / 2 + 4, geom.y() + geom.height() / 2 + o - 4 );
294
p.drawLine( geom.x(), geom.y(),
295
geom.x() + geom.width(), geom.y() );
296
p.drawLine( geom.x(), geom.y() + 1,
297
geom.x() + geom.width(), geom.y() + 1 );
305
void TabstripButton::enterEvent( QEvent *e )
309
KCommonDecorationButton::enterEvent( e );
312
void TabstripButton::leaveEvent( QEvent *e )
316
KCommonDecorationButton::leaveEvent( e );