1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
|
/* SuSE KWin window decoration
Copyright (C) 2005 Gerd Fleischer <gerdfleischer@web.de>
Copyright (C) 2005 Adrian Schroeter <adrian@suse.de>
based on the window decoration "Plastik" and "Web":
Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA.
*/
#include <klocale.h>
#include <kpixmap.h>
#include <kimageeffect.h>
#include <kpixmapeffect.h>
#include <kstandarddirs.h>
#include <kdecoration.h>
#include <qbitmap.h>
#include <qdatetime.h>
#include <qfontmetrics.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qimage.h>
#include "SUSE2client.h"
#include "SUSE2button.h"
#include "misc.h"
#include "shadow.h"
namespace KWinSUSE2
{
SUSE2Client::SUSE2Client(KDecorationBridge* bridge, KDecorationFactory* factory)
: KCommonDecoration(bridge, factory),
aCaptionBuffer(0), iCaptionBuffer(0),
aTitleBarTile(0), iTitleBarTile(0),
pixmaps_created(false),
captionBufferDirty(true),
s_titleFont(QFont())
{}
SUSE2Client::~SUSE2Client()
{
delete_pixmaps();
delete aCaptionBuffer;
delete iCaptionBuffer;
}
// pure virtual methods from KCommonDecoration
QString SUSE2Client::visibleName() const
{
return i18n("SUSE2 (Version %1)").arg("0.4.1");
}
QString SUSE2Client::defaultButtonsLeft() const
{
return "M";
}
QString SUSE2Client::defaultButtonsRight() const
{
return "HIA___X";
}
bool SUSE2Client::decorationBehaviour(DecorationBehaviour behaviour) const
{
switch (behaviour) {
case DB_MenuClose:
return Handler()->menuClose();
case DB_WindowMask:
return true;
default:
return KCommonDecoration::decorationBehaviour(behaviour);
}
}
KCommonDecorationButton *SUSE2Client::createButton(ButtonType type)
{
switch (type) {
case MenuButton:
return new SUSE2Button(MenuButton, this, "menu");
case OnAllDesktopsButton:
return new SUSE2Button(OnAllDesktopsButton, this, "on_all_desktops");
case HelpButton:
return new SUSE2Button(HelpButton, this, "help");
case MinButton:
return new SUSE2Button(MinButton, this, "minimize");
case MaxButton:
return new SUSE2Button(MaxButton, this, "maximize");
case CloseButton:
return new SUSE2Button(CloseButton, this, "close");
case AboveButton:
return new SUSE2Button(AboveButton, this, "above");
case BelowButton:
return new SUSE2Button(BelowButton, this, "below");
case ShadeButton:
return new SUSE2Button(ShadeButton, this, "shade");
default:
return 0;
}
}
int SUSE2Client::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
{
bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
switch (lm) {
case LM_BorderLeft:
case LM_BorderRight:
case LM_BorderBottom:
if (respectWindowState && maximized)
return 0;
return Handler()->borderSize();
case LM_TitleEdgeTop:
if (respectWindowState && maximized) {
return 0;
} else {
return TOPMARGIN;
}
case LM_TitleEdgeBottom:
if (respectWindowState && maximized) {
return 1;
} else {
return DECOHEIGHT;
}
case LM_TitleEdgeLeft:
case LM_TitleEdgeRight:
if (respectWindowState && maximized) {
return 0;
} else {
return 6;
}
case LM_TitleBorderLeft:
case LM_TitleBorderRight:
return 5;
case LM_ButtonWidth:
case LM_ButtonHeight:
case LM_TitleHeight:
if (respectWindowState && isToolWindow()) {
return Handler()->titleHeightTool();
} else {
return Handler()->titleHeight();
}
case LM_ButtonSpacing:
return 1;
case LM_ButtonMarginTop:
return 0;
case LM_ExplicitButtonSpacer:
return 3;
default:
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
}
}
void SUSE2Client::init()
{
s_titleFont = isToolWindow() ?
Handler()->titleFontTool()
: Handler()->titleFont();
create_pixmaps();
aCaptionBuffer = new QPixmap();
iCaptionBuffer = new QPixmap();
captionBufferDirty = true;
KCommonDecoration::init();
}
QRegion SUSE2Client::cornerShape(WindowCorner corner)
{
int w = widget()->width();
int h = widget()->height();
switch (corner) {
case WC_TopLeft:
if (layoutMetric(LM_TitleEdgeLeft) > 0 &&
(Handler()->roundCorners() == 1 ||
(Handler()->roundCorners() == 2 && maximizeMode() != MaximizeFull))) {
return QRegion(0, 0, 1, 5) + QRegion(0, 0, 2, 3) + QRegion(0, 0, 3, 2) + QRegion(0, 0, 5, 1);
} else {
return QRegion(0, 0, 1, 1);
}
case WC_TopRight:
if (layoutMetric(LM_TitleEdgeRight) > 0 &&
(Handler()->roundCorners() == 1 ||
(Handler()->roundCorners() == 2 && maximizeMode() != MaximizeFull))) {
return QRegion(w-1, 0, 1, 5) + QRegion(w-2, 0, 2, 3) + QRegion(w-3, 0, 3, 2) + QRegion(w-5, 0, 5, 1);
} else {
return QRegion(w-1, 0, 1, 1);
}
case WC_BottomLeft:
if (layoutMetric(LM_BorderLeft) > 0)
return QRegion(0, h-1, 1, 1);
else
return QRegion();
case WC_BottomRight:
if (layoutMetric(LM_BorderRight) > 0)
return QRegion(w-1, h-1, 1, 1);
else
return QRegion();
default:
return QRegion();
}
}
void SUSE2Client::paintEvent(QPaintEvent *e)
{
QRegion region = e->region();
if (captionBufferDirty) update_captionBuffer();
bool active = isActive();
QPainter painter(widget());
// colors...
const QColor windowContour = Handler()->getColor(WindowContour, active);
const QColor innerWindowContour = Handler()->getColor(TitleGradientTo, active);
const QColor deco = Handler()->getColor(TitleGradientTo, active);
const QColor aBorder = Handler()->getColor(Border, active);
const QColor darkAntiAlias = alphaBlendColors(innerWindowContour, active ? aAntialiasBase : iAntialiasBase, 140);
const QColor midAntiAlias = alphaBlendColors(innerWindowContour, active ? aAntialiasBase : iAntialiasBase, 120);
const QColor brightAntiAlias = alphaBlendColors(innerWindowContour, active ? aAntialiasBase : iAntialiasBase, 80);
const QColor innerAntiAlias = alphaBlendColors(innerWindowContour, active ? aAntialiasBase : iAntialiasBase, 170);
QRect r = widget()->rect();
int r_w = r.width();
int r_x, r_y, r_x2, r_y2;
r.coords(&r_x, &r_y, &r_x2, &r_y2);
const int borderLeft = layoutMetric(LM_BorderLeft);
const int borderRight = layoutMetric(LM_BorderRight);
const int borderBottom = layoutMetric(LM_BorderBottom);
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
const int btnMarginTop = layoutMetric(LM_ButtonMarginTop);
const int titleMargin = layoutMetric(LM_TitleBorderLeft);
const int borderBottomTop = r_y2-borderBottom+1;
const int borderLeftRight = r_x+borderLeft-1;
const int borderRightLeft = r_x2-borderRight+1;
const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;
const int sideHeight = borderBottomTop-titleEdgeBottomBottom-1;
// the title background over full width
if (maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows()) {
painter.drawTiledPixmap(r_x, r_y,
r_w, titleHeight + titleEdgeTop + titleEdgeBottom,
active ? *aTitleBarTile : *iTitleBarTile, 0, TOPMARGIN - btnMarginTop);
} else {
painter.drawTiledPixmap(r_x, r_y,
r_w, titleHeight + titleEdgeTop + titleEdgeBottom,
active ? *aTitleBarTile : *iTitleBarTile);
}
QRect Rtitle = QRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop,
r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()),
titleEdgeBottomBottom-(r_y+titleEdgeTop) );
QRect tmpRect;
// topSpacer
if(titleEdgeTop > 0) {
tmpRect.setRect(r_x, r_y, r_w, titleEdgeTop );
if (tmpRect.isValid() && region.contains(tmpRect) ) {
painter.setPen(windowContour);
if (Handler()->roundCorners() == 1 ||
(Handler()->roundCorners() == 2 && maximizeMode() != MaximizeFull)) {
// top line
if (maximizeMode() != MaximizeFull || options()->moveResizeMaximizedWindows()) {
painter.fillRect(tmpRect.left(), tmpRect.top(), 2, titleEdgeTop+1, windowContour);
painter.fillRect(tmpRect.left()+2, tmpRect.top(), 3, 3, windowContour);
painter.fillRect(tmpRect.right()-1, tmpRect.top(), 2, titleEdgeTop+1, windowContour);
painter.fillRect(tmpRect.right()-4, tmpRect.top(), 3, 3, windowContour);
painter.drawLine(tmpRect.left()+5, tmpRect.top(), tmpRect.right()-5, tmpRect.top());
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.left()+5, tmpRect.top()+1, tmpRect.right()-5, tmpRect.top()+1);
painter.setPen(windowContour);
}
painter.setPen(innerWindowContour);
// left inner corner
painter.drawPoint(tmpRect.left()+3, tmpRect.top()+2);
painter.drawPoint(tmpRect.left()+2, tmpRect.top()+3);
// right inner corner
painter.drawPoint(tmpRect.right()-3, tmpRect.top()+2);
painter.drawPoint(tmpRect.right()-2, tmpRect.top()+3);
painter.setPen(midAntiAlias);
painter.drawPoint(tmpRect.left()+3, tmpRect.top()+3);
painter.drawPoint(tmpRect.right()-3, tmpRect.top()+3);
painter.setPen(brightAntiAlias);
painter.drawPoint(tmpRect.left()+5, tmpRect.top()+2);
painter.drawPoint(tmpRect.right()-5, tmpRect.top()+2);
painter.setPen(innerAntiAlias);
painter.drawPoint(tmpRect.left()+4, tmpRect.top()+2);
painter.drawPoint(tmpRect.left()+2, tmpRect.top()+4);
painter.drawPoint(tmpRect.right()-4, tmpRect.top()+2);
painter.drawPoint(tmpRect.right()-2, tmpRect.top()+4);
} else {
// top line
if (maximizeMode() != MaximizeFull || options()->moveResizeMaximizedWindows()) {
painter.fillRect(tmpRect.left(), tmpRect.top(), 2, titleEdgeTop+1, windowContour);
painter.fillRect(tmpRect.left()+2, tmpRect.top(), 3, 2, windowContour);
painter.fillRect(tmpRect.right()-1, tmpRect.top(), 2, titleEdgeTop+1, windowContour);
painter.fillRect(tmpRect.right()-4, tmpRect.top(), 3, 2, windowContour);
painter.drawLine(tmpRect.left()+2, tmpRect.top(), tmpRect.right()-2, tmpRect.top() );
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.left()+1, tmpRect.top()+1, tmpRect.right()-1, tmpRect.top()+1);
painter.setPen(windowContour);
}
painter.setPen(alphaBlendColors(innerWindowContour, windowContour, 110));
// left corner
painter.drawLine(tmpRect.left(), tmpRect.top(), tmpRect.left()+1, tmpRect.top());
painter.drawPoint(tmpRect.left(), tmpRect.top()+1);
// right corner
painter.drawLine(tmpRect.right(), tmpRect.top(), tmpRect.right()-1, tmpRect.top());
painter.drawPoint(tmpRect.right(), tmpRect.top()+1);
painter.setPen(windowContour);
// left side
painter.drawLine(tmpRect.left(), tmpRect.top()+2, tmpRect.left(), tmpRect.bottom());
// right side
painter.drawLine(tmpRect.right(), tmpRect.top()+2, tmpRect.right(), tmpRect.bottom());
painter.setPen(innerWindowContour);
// left inner corner
painter.drawLine(tmpRect.left()+1, tmpRect.top()+2, tmpRect.left()+1, tmpRect.top()+4);
// right inner corner
painter.drawLine(tmpRect.right()-1, tmpRect.top()+2, tmpRect.right()-1, tmpRect.top()+4);
}
}
}
// leftTitleSpacer
if(titleEdgeLeft > 1)
{
tmpRect.setRect(r_x, titleEdgeTop, borderLeft, titleEdgeTop+titleHeight+titleEdgeBottom);
if (tmpRect.isValid() && region.contains(tmpRect) ) {
painter.setPen(windowContour);
painter.drawLine(tmpRect.left(), tmpRect.top(),
tmpRect.left(), tmpRect.bottom() );
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.left()+1, tmpRect.top()+1,
tmpRect.left()+1, tmpRect.bottom() );
if (Handler()->roundCorners() == 1 ||
(Handler()->roundCorners() == 2 && maximizeMode() != MaximizeFull)) {
painter.setPen(darkAntiAlias);
painter.drawPoint(tmpRect.left()+2, tmpRect.top()+1);
}
}
}
// rightTitleSpacer
if(titleEdgeRight > 1)
{
tmpRect.setRect(borderRightLeft, titleEdgeTop, borderRight, titleEdgeTop+titleHeight+titleEdgeBottom);
if (tmpRect.isValid() && region.contains(tmpRect) ) {
painter.setPen(windowContour );
painter.drawLine(tmpRect.right(), tmpRect.top(),
tmpRect.right(), tmpRect.bottom() );
painter.setPen(innerWindowContour );
painter.drawLine(tmpRect.right()-1, tmpRect.top()+1,
tmpRect.right()-1, tmpRect.bottom() );
if (Handler()->roundCorners() == 1 ||
(Handler()->roundCorners() == 2 && maximizeMode() != MaximizeFull)) {
painter.setPen(darkAntiAlias);
painter.drawPoint(tmpRect.right()-2, tmpRect.top()+1);
}
}
}
// titleSpacer
QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer;
if (Rtitle.width() > 0 && titleBfrPtr != 0) {
int tX, tW;
switch (Handler()->titleAlign()) {
// AlignCenter
case Qt::AlignHCenter:
tX = (titleBfrPtr->width() > Rtitle.width()-2 * titleMargin) ?
(Rtitle.left()+titleMargin)
: Rtitle.left()+(Rtitle.width()- titleBfrPtr->width())/2;
tW = (titleBfrPtr->width() > Rtitle.width()-2 * titleMargin) ?
(Rtitle.width()-2 * titleMargin)
: titleBfrPtr->width();
break;
// AlignRight
case Qt::AlignRight:
tX = (titleBfrPtr->width() > Rtitle.width()-2 * titleMargin) ?
(Rtitle.left()+titleMargin)
: Rtitle.right()-titleMargin-titleBfrPtr->width();
tW = (titleBfrPtr->width() > Rtitle.width()-2 * titleMargin) ?
(Rtitle.width()-2 * titleMargin)
: titleBfrPtr->width();
break;
// AlignLeft
default:
tX = (Rtitle.left()+titleMargin);
tW = (titleBfrPtr->width() > Rtitle.width()-2 * titleMargin) ?
(Rtitle.width()-2 * titleMargin)
: titleBfrPtr->width();
}
if(tW > 0) {
if (titleBfrPtr->width()+2*titleMargin > Rtitle.width()) {
QPixmap *tmp = new QPixmap(30, Rtitle.height());
QPainter fade;
fade.begin(tmp);
fade.drawPixmap(0, 0, *titleBfrPtr, Rtitle.right()-30-2*titleMargin-Rtitle.left(), 0);
QImage background = (active ? *aTitleBarTile : *iTitleBarTile).convertToImage();
QImage tmpImg = tmp->convertToImage();
QImage blended = KImageEffect::blend(tmpImg, background, gradient, KImageEffect::Red);
painter.drawPixmap(tX, Rtitle.top() - TOPMARGIN + btnMarginTop+2, *titleBfrPtr,
0, 2, tW - 2* titleMargin, -1);
painter.drawImage(Rtitle.right()-30-titleMargin, Rtitle.top() - TOPMARGIN + btnMarginTop+2,
blended, 0, 2);
} else {
painter.drawPixmap(tX, Rtitle.top() - TOPMARGIN + btnMarginTop+2, *titleBfrPtr, 0, 2);
}
}
}
// leftSpacer
if (borderLeft > 0 && sideHeight > 0) {
tmpRect.setCoords(r_x, titleEdgeBottomBottom+1, borderLeftRight, borderBottomTop-1);
if (tmpRect.isValid() && region.contains(tmpRect) ) {
if (tmpRect.width() > 2) {
painter.fillRect(tmpRect, active ? aGradientBottom : iGradientBottom);
}
painter.setPen(windowContour);
painter.drawLine(tmpRect.left(), tmpRect.top(), tmpRect.left(), tmpRect.bottom());
painter.drawLine(tmpRect.right(), tmpRect.top(), tmpRect.right(), tmpRect.bottom());
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.left()+1, tmpRect.top(), tmpRect.left()+1, tmpRect.bottom());
}
}
// rightSpacer
if (borderRight > 0 && sideHeight > 0) {
tmpRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1, r_x2, borderBottomTop-1);
if (tmpRect.isValid() && region.contains(tmpRect) ) {
if (tmpRect.width() > 2) {
painter.fillRect(tmpRect, active ? aGradientBottom : iGradientBottom);
}
painter.setPen(windowContour);
painter.drawLine(tmpRect.right(), tmpRect.top(), tmpRect.right(), tmpRect.bottom());
painter.drawLine(tmpRect.left(), tmpRect.top(), tmpRect.left(), tmpRect.bottom());
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.right()-1, tmpRect.top(), tmpRect.right()-1, tmpRect.bottom());
}
}
// bottomSpacer
if (borderBottom > 0) {
tmpRect.setCoords(r_x, borderBottomTop, r_x2, r_y2);
if (tmpRect.isValid() && region.contains(tmpRect) ) {
if (borderBottomTop > 2) {
painter.fillRect(tmpRect, active ? aGradientBottom : iGradientBottom);
}
// bottom lines
painter.setPen(innerWindowContour);
painter.drawLine(r_x, r_y2-1, r_x2, r_y2-1);
painter.setPen(windowContour);
painter.drawLine(r_x, r_y2, r_x2, r_y2); //bottom line
//bottom upper line
painter.drawLine(borderLeft-1, borderBottomTop, r_x2-borderRight+1, borderBottomTop);
if (borderLeft > 0) {
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.left()+1, tmpRect.top(), tmpRect.left()+1, tmpRect.bottom()-1);
painter.setPen(windowContour);
// rounded left bottom corner - side
painter.drawLine(tmpRect.left(), tmpRect.top(), tmpRect.left(), tmpRect.bottom()-2);
// anti-alias for the window contour...
painter.setPen(alphaBlendColors(innerWindowContour, windowContour, 90) );
painter.drawLine(tmpRect.left(), tmpRect.bottom()-1, tmpRect.left(), tmpRect.bottom());
painter.drawPoint(tmpRect.left()+1, tmpRect.bottom());
}
if (borderRight > 0) {
painter.setPen(innerWindowContour);
painter.drawLine(tmpRect.right()-1, tmpRect.top(), tmpRect.right()-1, tmpRect.bottom()-1);
painter.setPen(windowContour);
// rounded right bottom corner - side
painter.drawLine(tmpRect.right(), tmpRect.top(), tmpRect.right(), tmpRect.bottom()-2);
// anti-alias for the window contour...
painter.setPen(alphaBlendColors(innerWindowContour, windowContour, 110) );
painter.drawLine(tmpRect.right(), tmpRect.bottom()-1, tmpRect.right(), tmpRect.bottom());
painter.drawPoint(tmpRect.right()-1, tmpRect.bottom());
}
}
}
}
void SUSE2Client::updateCaption()
{
captionBufferDirty = true;
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int marginLeft = layoutMetric(LM_TitleBorderLeft);
const int marginRight = layoutMetric(LM_TitleBorderRight);
QRect g = QRect(titleEdgeLeft, titleEdgeTop, (widget()->rect()).width()-marginLeft-marginRight, titleHeight + titleEdgeBottom);
widget()->update(g);
}
void SUSE2Client::reset(unsigned long changed)
{
if (changed & SettingColors) {
// repaint the whole thing
delete_pixmaps();
create_pixmaps();
captionBufferDirty = true;
widget()->update();
updateButtons();
} else if (changed & SettingFont) {
s_titleFont = isToolWindow() ?
Handler()->titleFontTool()
: Handler()->titleFont();
// then repaint
delete_pixmaps();
create_pixmaps();
captionBufferDirty = true;
widget()->update();
updateButtons();
}
KCommonDecoration::reset(changed);
}
void SUSE2Client::create_pixmaps()
{
if(pixmaps_created)
return;
KPixmap tempPixmap;
QPainter painter;
const int titleHeight = layoutMetric(LM_TitleHeight);
// aTitleBarTile
tempPixmap.resize(30, titleHeight + TOPMARGIN + DECOHEIGHT);
KPixmapEffect::gradient(tempPixmap,
Handler()->getColor(TitleGradientFrom, true),
Handler()->getColor(TitleGradientTo, true),
KPixmapEffect::VerticalGradient);
aTitleBarTile = new QPixmap(30, titleHeight + TOPMARGIN + DECOHEIGHT);
painter.begin(aTitleBarTile);
painter.drawPixmap(0, 0, tempPixmap);
QImage t;
if (Handler()->titlebarStyle() == 0) { // new, Toplight
t = QImage(30, (titleHeight + TOPMARGIN + DECOHEIGHT)/3 + 1, 32 );
t = KImageEffect::gradient(QSize(30, t.height()),
Handler()->getColor(TitleGradientFrom, true).light(130),
Handler()->getColor(TitleGradientTo, true),
KImageEffect::VerticalGradient/*, 100, 100*/);
painter.drawImage(0, 2, t, 0, 0, -1, tempPixmap.height()-2);
t.create(t.width(), t.height()*2, t.depth());
t = KImageEffect::unbalancedGradient(QSize(30, t.height()),
Handler()->getColor(TitleGradientTo, true),
Handler()->getColor(TitleGradientFrom, true),
KImageEffect::VerticalGradient, 100, 100);
painter.drawImage(0, t.height()/2, t, 0, 0, -1, t.height());
} else { // older, Balanced
t = QImage(30, (titleHeight + TOPMARGIN + DECOHEIGHT)/2 + 1, 32 );
t = KImageEffect::gradient(QSize(30, t.height()),
Handler()->getColor(TitleGradientFrom, true).light(150),
Handler()->getColor(TitleGradientTo, true).light(110),
KImageEffect::VerticalGradient);
painter.drawImage(0, 2, t, 0, 0, -1, tempPixmap.height()-2);
t = KImageEffect::gradient(QSize(30, t.height()),
Handler()->getColor(TitleGradientTo, true),
Handler()->getColor(TitleGradientFrom, true),
KImageEffect::VerticalGradient);
painter.drawImage(0, t.height(), t, 0, 0, -1, t.height());
}
painter.end();
// iTitleBarTile
tempPixmap.resize(30, titleHeight + TOPMARGIN + DECOHEIGHT);
KPixmapEffect::gradient(tempPixmap,
Handler()->getColor(TitleGradientFrom, false),
Handler()->getColor(TitleGradientTo, false),
KPixmapEffect::VerticalGradient);
iTitleBarTile = new QPixmap(30, titleHeight + TOPMARGIN + DECOHEIGHT);
painter.begin(iTitleBarTile);
painter.drawPixmap(0, 0, tempPixmap);
painter.end();
QImage aTempImage = aTitleBarTile->convertToImage();
aGradientBottom = QColor::QColor(aTempImage.pixel(0, aTempImage.height()-1));
aAntialiasBase = QColor::QColor(aTempImage.pixel(0, 2));
QImage iTempImage = iTitleBarTile->convertToImage();
iGradientBottom = QColor::QColor(iTempImage.pixel(0, iTempImage.height()-1));
iAntialiasBase = QColor::QColor(iTempImage.pixel(0, 2));
// the gradient for the fade out effect
gradient = KImageEffect::gradient(QSize(30, titleHeight + TOPMARGIN + DECOHEIGHT),
QColor(255,255,255),
QColor(0,0,0),
KImageEffect::HorizontalGradient);
pixmaps_created = true;
}
void SUSE2Client::delete_pixmaps()
{
delete aTitleBarTile;
aTitleBarTile = 0;
delete iTitleBarTile;
iTitleBarTile = 0;
pixmaps_created = false;
}
void SUSE2Client::update_captionBuffer()
{
const uint maxCaptionLength = 110; // truncate captions longer than this!
QString c(caption());
if (c.length() > maxCaptionLength) {
QString tmpLeft = c.left(50);
QString tmpRight = c.right(50);
c = tmpLeft + QString::fromUtf8("[...]") + tmpRight;
}
QImage logo(Handler()->titleLogoURL());
int logoOffset = Handler()->titleLogoOffset();
QFontMetrics fm(s_titleFont);
int captionWidth = fm.width(c);
int logoWidth = 0;
if (Handler()->titleLogo()) {
logoWidth = logo.width() + logoOffset;
captionWidth += logoWidth;
if (logo.height()+1 > fm.height())
logo.scaleHeight(fm.height()-1);
}
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleHeight = layoutMetric(LM_TitleHeight);
QPixmap textPixmap;
QPainter painter;
if(Handler()->titleShadow()) {
// prepare the shadow
textPixmap = QPixmap(captionWidth+4, titleHeight + TOPMARGIN + DECOHEIGHT); // 4 px shadow space
textPixmap.fill(QColor(0,0,0));
textPixmap.setMask(textPixmap.createHeuristicMask(true));
painter.begin(&textPixmap);
painter.setFont(s_titleFont);
painter.setPen(white);
if (Handler()->titleLogo()) {
painter.drawText(textPixmap.rect().left(), textPixmap.rect().top()+titleEdgeTop,
textPixmap.rect().width()-logo.width() - logoOffset, textPixmap.rect().height()-titleEdgeTop-titleEdgeBottom,
AlignCenter, c);
painter.drawImage(captionWidth - logo.width(), textPixmap.rect().top() + TOPMARGIN, logo);
} else {
painter.drawText(textPixmap.rect().left(), textPixmap.rect().top()+titleEdgeTop,
textPixmap.rect().width(), textPixmap.rect().height()-titleEdgeTop-titleEdgeBottom,
AlignCenter, c);
}
painter.end();
}
QImage shadow;
ShadowEngine se;
// active
aCaptionBuffer->resize(captionWidth+4, titleHeight + TOPMARGIN + DECOHEIGHT); // 4 px shadow
painter.begin(aCaptionBuffer);
painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
if(Handler()->titleShadow()) {
shadow = se.makeShadow(textPixmap, QColor(0, 0, 0));
painter.drawImage(1, 1, shadow);
}
painter.setFont(s_titleFont);
painter.setPen(Handler()->getColor(TitleFont,true));
painter.drawText(aCaptionBuffer->rect().left(), aCaptionBuffer->rect().top() + titleEdgeTop,
aCaptionBuffer->rect().width()-logoWidth, aCaptionBuffer->rect().height() - titleEdgeTop-titleEdgeBottom,
AlignCenter, c);
if (Handler()->titleLogo())
painter.drawImage(captionWidth - logo.width(), aCaptionBuffer->rect().top() + TOPMARGIN, logo);
painter.end();
// inactive -> no shadow and no logo
iCaptionBuffer->resize(captionWidth+4, titleHeight + TOPMARGIN + DECOHEIGHT);
painter.begin(iCaptionBuffer);
painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
painter.setFont(s_titleFont);
painter.setPen(Handler()->getColor(TitleFont,false));
painter.drawText(iCaptionBuffer->rect().left(), iCaptionBuffer->rect().top() + titleEdgeTop,
iCaptionBuffer->rect().width() - logoWidth, iCaptionBuffer->rect().height() - titleEdgeTop - titleEdgeBottom,
AlignCenter, c);
painter.end();
captionBufferDirty = false;
}
} // KWinSUSE2
// kate: space-indent on; indent-width 4; replace-tabs on;
|