-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpolish.cpp
1176 lines (1069 loc) · 52.6 KB
/
polish.cpp
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Virtuality Style for Qt4 and Qt5
* Copyright 2009-2014 by Thomas Lübking <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
*
* 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; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QAbstractItemView>
#include <QAbstractScrollArea>
#include <QAbstractSlider>
#include <QAction>
#include <QApplication>
#include <QComboBox>
#include <QCommandLinkButton>
#include <QDockWidget>
#include <QHeaderView>
#include <QLabel>
#include <QLayout>
#include <QLCDNumber>
#include <QLineEdit>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QPainter>
#include <QPushButton>
#include <QTimer>
#include <QToolBar>
#include <QToolTip>
#include <QTreeView>
#include <QWizard>
#include <QTextBrowser>
#include <QTextDocument>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusMessage>
#include <QtDebug>
#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif
#include <cmath>
#include "FX.h"
#include "shadows.h"
#ifndef QT_NO_DBUS
#include "macmenu.h"
#endif
#ifdef BE_WS_X11
#include "xproperty.h"
#include "fixx11h.h"
#endif
#include "hacks.h"
#include "virtuality.h"
#include "animator/focus.h"
#include "animator/hover.h"
#include "animator/aprogress.h"
#include "animator/tab.h"
#include "makros.h"
#undef CCOLOR
#undef FCOLOR
#define CCOLOR(_TYPE_, _FG_) PAL.color(QPalette::Active, Style::config._TYPE_##_role[_FG_])
#define FCOLOR(_TYPE_) PAL.color(QPalette::Active, QPalette::_TYPE_)
#define FILTER_EVENTS(_WIDGET_) { _WIDGET_->removeEventFilter(this); _WIDGET_->installEventFilter(this); } // skip semicolon
#define BESPIN_MOUSE_DEBUG 0
using namespace BE;
Hacks::Config Hacks::config;
static inline void
setBoldFont(QWidget *w, bool bold = true)
{
if (w->font().pointSize() < 1)
return;
QFont fnt = w->font();
fnt.setBold(bold);
w->setFont(fnt);
}
void Style::polish(QApplication *app)
{
QPalette pal = app->palette();
polish(pal);
QPalette *opal = originalPalette;
originalPalette = 0; // so our eventfilter won't react on this... ;-P
app->setPalette(pal);
originalPalette = opal;
}
#define _SHIFTCOLOR_(clr) clr = QColor(CLAMP(clr.red()-10,0,255),CLAMP(clr.green()-10,0,255),CLAMP(clr.blue()-10,0,255))
#define _ALIGN_COLOR_(_FROM_, _TO_) \
pal.setColor(QPalette::Active, QPalette::_FROM_, pal.color(QPalette::Active, QPalette::_TO_));\
pal.setColor(QPalette::Inactive, QPalette::_FROM_, pal.color(QPalette::Inactive, QPalette::_TO_));\
pal.setColor(QPalette::Disabled, QPalette::_FROM_, pal.color(QPalette::Disabled, QPalette::_TO_));
#undef PAL
#define PAL pal
#define SWAP_ALL(_P_, _R1_, _R2_) FX::swap(_P_, QPalette::Active, _R1_, _R2_); FX::swap(_P_, QPalette::Inactive, _R1_, _R2_); FX::swap(_P_, QPalette::Disabled, _R1_, _R2_)
void Style::polish( QPalette &pal, bool onInit )
{
QColor c = pal.color(QPalette::Active, QPalette::Window);
pal.setColor( QPalette::Window, c );
if (onInit) {
_ALIGN_COLOR_(Button, Window);
_ALIGN_COLOR_(ButtonText, WindowText);
_ALIGN_COLOR_(Base, Window);
_ALIGN_COLOR_(Text, WindowText);
_ALIGN_COLOR_(ToolTipBase, WindowText);
_ALIGN_COLOR_(ToolTipText, Window);
invertedPalette = pal;
SWAP_ALL(invertedPalette, QPalette::Window, QPalette::WindowText);
SWAP_ALL(invertedPalette, QPalette::Base, QPalette::Text);
SWAP_ALL(invertedPalette, QPalette::Button, QPalette::ButtonText);
SWAP_ALL(invertedPalette, QPalette::Highlight, QPalette::HighlightedText);
invertedPalette.setColor(QPalette::PlaceholderText, FX::blend(invertedPalette.color(QPalette::Active, QPalette::Base),
invertedPalette.color(QPalette::Active, QPalette::Text), 70,30));
polish(invertedPalette, false);
}
// Style::polish(invertedPalette, true);
// QPixmap brush(32,32);
// brush.fill(pal.color(QPalette::Window).lighter(101));
// QPainter p(&brush);
// p.setPen(pal.color(QPalette::Window).darker(102));
// for (int i = 2; i < 33; i+=4)
// p.drawLine(0,i,32,i);
// p.end();
// pal.setBrush(QPalette::Active, QPalette::Base, brush);
// pal.setBrush(QPalette::Inactive, QPalette::Base, brush);
// pal.setBrush(QPalette::Disabled, QPalette::Base, brush);
// AlternateBase
pal.setColor(QPalette::AlternateBase, FX::blend(pal.color(QPalette::Active, QPalette::Base),
pal.color(QPalette::Active, QPalette::Text), 100,3));
// Link colors can not be set through qtconfig - and the colors suck
QColor link = pal.color(QPalette::Active, QPalette::Highlight);
const int vwt = FX::value(pal.color(QPalette::Active, QPalette::Window));
const int vt = FX::value(pal.color(QPalette::Active, QPalette::Base));
int h,s,v;
link.getHsv(&h,&s,&v);
if (s < 16) { // low saturated color - maybe we've more luck with the foreground
QColor link2 = pal.color(QPalette::Active, QPalette::HighlightedText);
int s2;
link2.getHsv(&h,&s2,&v);
if (s2 > s) {
link = link2;
s = s2;
}
else // re-fix attributes
link.getHsv(&h,&s,&v);
}
s = sqrt(s/255.0)*255.0;
if (vwt > 128 && vt > 128)
v = 3*v/4;
else if (vwt < 128 && vt < 128)
v = qMin(255, 7*v/6);
link.setHsv(h, s, v);
pal.setColor(QPalette::Link, link);
link = FX::blend(link, FX::blend(pal.color(QPalette::Active, QPalette::Text),
pal.color(QPalette::Active, QPalette::WindowText)), 4, 1);
pal.setColor(QPalette::LinkVisited, link);
// inactive palette
if (config.fadeInactive)
{ // fade out inactive foreground and highlight colors...
pal.setColor(QPalette::Inactive, QPalette::Window, pal.color(QPalette::Active, QPalette::Window));
pal.setColor(QPalette::Inactive, QPalette::WindowText,
FX::blend(pal.color(QPalette::Active, QPalette::Window), pal.color(QPalette::Active, QPalette::WindowText), 1,4));
pal.setColor(QPalette::Inactive, QPalette::Button, pal.color(QPalette::Active, QPalette::Button));
pal.setColor(QPalette::Inactive, QPalette::ButtonText,
FX::blend(pal.color(QPalette::Active, QPalette::Button), pal.color(QPalette::Active, QPalette::ButtonText), 1,4));
pal.setColor(QPalette::Inactive, QPalette::Base, pal.color(QPalette::Active, QPalette::Base));
pal.setColor(QPalette::Inactive, QPalette::Text,
FX::blend(pal.color(QPalette::Active, QPalette::Base), pal.color(QPalette::Active, QPalette::Text), 1,4));
}
// fade disabled palette
pal.setColor(QPalette::Disabled, QPalette::WindowText,
FX::blend(pal.color(QPalette::Active, QPalette::Window), pal.color(QPalette::Active, QPalette::WindowText),2,1));
pal.setColor(QPalette::Disabled, QPalette::Base,
FX::blend(pal.color(QPalette::Active, QPalette::Window), pal.color(QPalette::Active, QPalette::Base),1,2));
pal.setColor(QPalette::Disabled, QPalette::Text,
FX::blend(pal.color(QPalette::Active, QPalette::Base), pal.color(QPalette::Active, QPalette::Text)));
pal.setColor(QPalette::Disabled, QPalette::AlternateBase, pal.color(QPalette::Disabled, QPalette::Base));
// highlight colors
h = qGray(pal.color(QPalette::Active, QPalette::Highlight).rgb());
QColor hgt(h,h,h);
pal.setColor(QPalette::Inactive, QPalette::Highlight, hgt);
pal.setColor(QPalette::Disabled, QPalette::Highlight, hgt);
hgt = FX::blend(hgt, pal.color(QPalette::Active, QPalette::HighlightedText));
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, hgt);
h = qGray(pal.color(QPalette::Active, QPalette::HighlightedText).rgb());
hgt = QColor(h,h,h);
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, hgt);
// more on tooltips... (we force some colors...)
if (!onInit)
return;
QPalette toolPal = QApplication::palette();
const QColor bg = pal.color(QPalette::Active, QPalette::WindowText);
const QColor fg = pal.color(QPalette::Active, QPalette::Window);
toolPal.setColor(QPalette::Window, bg);
toolPal.setColor(QPalette::WindowText, fg);
toolPal.setColor(QPalette::Base, bg);
toolPal.setColor(QPalette::Text, fg);
toolPal.setColor(QPalette::Button, bg);
toolPal.setColor(QPalette::ButtonText, fg);
toolPal.setColor(QPalette::Highlight, fg); // sic!
toolPal.setColor(QPalette::HighlightedText, bg); // sic!
toolPal.setColor(QPalette::ToolTipBase, bg);
toolPal.setColor(QPalette::ToolTipText, fg);
QToolTip::setPalette(toolPal);
#ifdef BE_WS_X11
if (appType == GTK)
setupDecoFor(NULL, pal);
#endif
}
#if 0
static QMenuBar *
bar4popup(QMenu *menu)
{
if (!menu->menuAction())
return 0;
if (menu->menuAction()->associatedWidgets().isEmpty())
return 0;
foreach (QWidget *w, menu->menuAction()->associatedWidgets())
if (qobject_cast<QMenuBar*>(w))
return static_cast<QMenuBar *>(w);
return 0;
}
#endif
inline static void
polishGTK(QWidget * widget)
{
enum MyRole{Bg = Style::Bg, Fg = Style::Fg};
QColor c1, c2, c3, c4;
if (widget->objectName() == "QTabWidget" ||
widget->objectName() == "QTabBar")
{
QPalette pal = widget->palette();
pal.setColor(QPalette::Disabled, QPalette::WindowText, FX::blend(FCOLOR(WindowText), FCOLOR(Window), 3, 1));
pal.setColor(QPalette::Inactive, QPalette::Window, FCOLOR(WindowText));
pal.setColor(QPalette::Active, QPalette::Window, FCOLOR(WindowText));
pal.setColor(QPalette::Inactive, QPalette::WindowText, FCOLOR(Window));
pal.setColor(QPalette::Active, QPalette::WindowText, FCOLOR(Window));
widget->setPalette(pal);
}
if (widget->objectName() == "QMenu" )
{
QPalette pal = widget->palette();
pal.setColor(QPalette::Inactive, QPalette::Window, FCOLOR(WindowText));
pal.setColor(QPalette::Active, QPalette::Window, FCOLOR(WindowText));
pal.setColor(QPalette::Inactive, QPalette::WindowText, FCOLOR(Window));
pal.setColor(QPalette::Active, QPalette::WindowText, FCOLOR(Window));
widget->setPalette(pal);
}
}
static QAction *dockLocker = 0;
static void invertContainer(QWidget *widget, const QPalette &invertedPalette)
{
widget->setPalette(invertedPalette);
QList<QWidget*> kids = widget->findChildren<QWidget*>();
for (int i = kids.count()-1; i > -1; --i) {
QWidget *kid = kids.at(i);
if (kid->testAttribute(Qt::WA_SetPalette) || kid->testAttribute(Qt::WA_StyleSheet)) {
kid->setPalette(invertedPalette); // shitted widgets inherit the app wide palette ...
}
if (kid->testAttribute(Qt::WA_StyleSheet) && !kid->styleSheet().isEmpty()) {
QString shit(kid->styleSheet());
// the shit uses the app wide FG color, so we need to force the correct one
// NOTICE: the leading ';' is for semi-broken styleshits that omit the trailing ';'
int idx = shit.lastIndexOf('}');
if (idx > -1)
shit = shit.left(idx) + ";color:" + invertedPalette.color(QPalette::Active, QPalette::WindowText).name() + ";}";
else
shit.append(";color:" + invertedPalette.color(QPalette::Active, QPalette::WindowText).name() + ";");
kid->setStyleSheet(shit);
}
}
}
void
Style::polish( QWidget * widget )
{
// GTK-Qt gets a special handling - see above
if (appType == GTK)
{
polishGTK(widget);
return;
}
// !!! protect against polishing /QObject/ attempts! (this REALLY happens from time to time...)
if (!widget)
return;
// if (widget->inherits("QGraphicsView"))
// widget->setPalette(invertedPalette);
// qDebug() << "BESPIN" << widget;
#if BESPIN_MOUSE_DEBUG
FILTER_EVENTS(widget);
#endif
// apply any user selected hacks
Hacks::add(widget);
KStyleFeatureRequest kStyleFeatureRequest = (KStyleFeatureRequest)widget->property("KStyleFeatureRequest").toUInt();
//BEGIN Window handling -
if ( widget->isWindow() &&
// widget->testAttribute(Qt::WA_WState_Created) &&
// widget->internalWinId() &&
!(widget->inherits("QSplashScreen") || widget->inherits("KScreenSaver")
|| widget->objectName() == "decoration widget" /*|| widget->inherits("QGLWidget")*/ ) )
{
/// this is dangerous! e.g. applying to QDesktopWidget leads to infinite recursion...
/// also doesn't work bgs get transparent and applying this to everything causes funny sideeffects...
// qDebug() << widget << widget->windowType();
if ( widget->windowType() == Qt::ToolTip)
{
if (config.bg.modal.opacity < 0xff)
widget->setWindowOpacity(config.bg.modal.opacity/255.0);
if (widget->inherits("BrightnessOSDWidget")) {
// ok. some moron thinks it's required to tell me that the screen brightness just changed. not like the entire screen wouldn't tell me
// then some other moron comes around and makes this stupid thing grab input focus (bypassing the wm)
// this does nicely breag drag and drop and interfers anytime you do actually something to *tell* you what you just saw. ***grrrr***
FILTER_EVENTS(widget); // so we suppress this bloody shit.
}
if (widget->inherits("QTipLabel") || widget->inherits("KToolTipWindow") || widget->inherits("FileMetaDataToolTip"))
{
if ( !(widget->testAttribute(Qt::WA_TranslucentBackground) || kStyleFeatureRequest & NoARGB) && FX::compositingActive() )
widget->setAttribute(Qt::WA_TranslucentBackground);
widget->setProperty("BespinWindowHints", config.frame.roundness?Rounded:0);
if (!(kStyleFeatureRequest & NoShadow))
Shadows::manage(widget);
}
}
else if (widget->windowType() == Qt::Popup)
{
if (config.bg.modal.opacity < 0xff)
widget->setWindowOpacity(config.bg.modal.opacity/255.0);
if (!widget->testAttribute(Qt::WA_TranslucentBackground) && widget->mask().isEmpty()) {
if (config.invert.menus && widget->inherits("QComboBoxPrivateContainer")) {
widget->setPalette(invertedPalette);
}
if (!(kStyleFeatureRequest & NoShadow))
Shadows::manage(widget);
}
} else if (widget->windowType() == Qt::Dialog) {
if (config.bg.ringOverlay && !widget->testAttribute(Qt::WA_TranslucentBackground)) {
widget->setAttribute(Qt::WA_StyledBackground);
}
} else if ( widget->testAttribute(Qt::WA_X11NetWmWindowTypeDND) && FX::compositingActive() )
{
if (!(kStyleFeatureRequest & NoARGB))
widget->setAttribute(Qt::WA_TranslucentBackground);
widget->clearMask();
}
if ( QMainWindow *mw = qobject_cast<QMainWindow*>(widget) ) {
if (appType == Dolphin)
mw->setDockOptions(mw->dockOptions()|QMainWindow::VerticalTabs);
// mw->setTabPosition ( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea, QTabWidget::North );
if (config.invert.docks && mw->centralWidget()) {
mw->centralWidget()->setAttribute(Qt::WA_StyledBackground);
mw->centralWidget()->setProperty("Virtuality.centralWidget", true);
}
if (Hacks::config.lockDocks) {
if (!dockLocker) {
dockLocker = new QAction( "Locked Dock Positions", qApp );
dockLocker->setShortcutContext( Qt::ApplicationShortcut );
dockLocker->setShortcuts( QList<QKeySequence>() << QKeySequence("Ctrl+Alt+D") );
dockLocker->setEnabled( true );
dockLocker->setCheckable( true );
dockLocker->setChecked( true );
connect ( dockLocker, SIGNAL(toggled(bool)), SLOT(unlockDocks(bool)) );
}
widget->addAction( dockLocker );
}
} else if ( QWizard *wiz = qobject_cast<QWizard*>(widget) ) {
if (config.macStyle && wiz->pixmap(QWizard::BackgroundPixmap).isNull())
{
if (!wiz->pixmap(QWizard::WatermarkPixmap).isNull())
wiz->setPixmap( QWizard::BackgroundPixmap, wiz->pixmap(QWizard::WatermarkPixmap) );
else
{
QPixmap pix(468,128);
pix.fill(Qt::transparent);
QRect r(0,0,128,128);
QPainter p(&pix);
QColor c = wiz->palette().color(wiz->foregroundRole());
c.setAlpha(24);
p.setBrush(c);
p.setPen(Qt::NoPen);
Navi::Direction dir = wiz->layoutDirection() == Qt::LeftToRight ? Navi::E : Navi::W;
Style::drawArrow(dir, r, &p);
r.translate(170,0); Style::drawArrow(dir, r, &p);
r.translate(170,0); Style::drawArrow(dir, r, &p);
p.end();
wiz->setPixmap( QWizard::BackgroundPixmap, pix );
}
}
}
//BEGIN Popup menu handling -
if (QMenu *menu = qobject_cast<QMenu *>(widget)) {
// opacity
if ((config.bg.modal.opacity != 0xff || config.frame.roundness) && !(kStyleFeatureRequest & NoARGB)) {
if (appType == Plasma || !(menu->testAttribute(Qt::WA_TranslucentBackground))) {
menu->setAttribute(Qt::WA_TranslucentBackground);
menu->setAttribute(Qt::WA_StyledBackground);
menu->setAutoFillBackground(false);
}
} else {
menu->setAutoFillBackground(true);
}
// color swapping
if (config.invert.menus)
menu->setPalette(invertedPalette);
if (appType == Plasma) // GNARF!
menu->setWindowFlags( menu->windowFlags()|Qt::Popup);
menu->setProperty("BespinWindowHints", config.frame.roundness ? Rounded : 0);
if (!(kStyleFeatureRequest & NoShadow))
Shadows::manage(menu);
// eventfiltering to reposition MDI windows, shaping, shadows, paint ARGB bg and correct distance to menubars
FILTER_EVENTS(menu);
}
//END Popup menu handling -
/// WORKAROUND Qt color bug, uses daddies palette and FGrole, but TooltipBase as background
else if (widget->inherits("QWhatsThat"))
{
// FILTER_EVENTS(widget); // IT - LOOKS - SHIT - !
widget->setPalette(QToolTip::palette()); // so this is Qt bug WORKAROUND
// widget->setProperty("BespinWindowHints", Shadowed);
// Shadows::set(widget->winId(), Shadows::Small);
}
else
{
// talk to kwin about colors, gradients, etc.
Qt::WindowFlags ignore = Qt::Popup | Qt::ToolTip |
Qt::SplashScreen | Qt::Desktop |
Qt::X11BypassWindowManagerHint;// | Qt::FramelessWindowHint; <- could easily change mind...?!
ignore &= ~(Qt::Dialog|Qt::Sheet); // erase dialog, it's in drawer et al. but takes away window as well
// this can be expensive, so avoid for popups, combodrops etc.
if (!(widget->windowFlags() & ignore)) {
if (widget->isVisible())
setupDecoFor(widget, widget->palette());
FILTER_EVENTS(widget); // catch show event and palette changes for deco
}
}
if (kStyleFeatureRequest & Shadow)
Shadows::manage(widget);
}
//END Window handling -
//BEGIN Frames -
if (QFrame *frame = qobject_cast<QFrame*>(widget)) {
if (frame->isWindow()) {
frame->setFrameShape(QFrame::NoFrame); // no. ugly & pointless.
} else {
if (QLabel *label = qobject_cast<QLabel*>(frame)) {
if (label->parentWidget() && label->parentWidget()->inherits("KFontRequester"))
label->setAlignment(Qt::AlignCenter); // fix alignment
} else if (frame->parentWidget() && frame->parentWidget()->inherits("KTitleWidget")) {
if (config.invert.headers) {
frame->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken);
frame->setAutoFillBackground(true);
frame->setBackgroundRole(QPalette::WindowText);
frame->setForegroundRole(QPalette::Window);
if (frame->layout())
frame->layout()->setContentsMargins(F(6),0,F(6),0);
} else {
frame->setFrameShape(QFrame::NoFrame);
frame->setAutoFillBackground(false);
if (frame->layout())
frame->layout()->setContentsMargins(0,0,0,0);
}
QList<QLabel*> labels = frame->findChildren<QLabel*>();
foreach (QLabel *label, labels) {
label->setAutoFillBackground(false);
label->setBackgroundRole(frame->backgroundRole());
label->setForegroundRole(frame->foregroundRole());
}
} else if (frame->parentWidget() && frame->parentWidget()->inherits("KateView")) { // nonono..
frame->setFrameShape(QFrame::NoFrame);
}
}
// just saw they're niftier in skulpture -> had to do sth. ;-P
if ( QLCDNumber *lcd = qobject_cast<QLCDNumber*>(frame) )
{
if (lcd->frameShape() != QFrame::NoFrame)
lcd->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
lcd->setSegmentStyle(QLCDNumber::Flat);
lcd->setAutoFillBackground(true);
}
// scrollarea hovering
if ( QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea*>(frame) ) {
if (appType == Dolphin && (config.invert.docks || config.invert.toolbars) &&
area->parentWidget() && area->parentWidget()->inherits("DolphinView"))
area->parentWidget()->setContentsMargins(F(4),F(4),F(4),F(4));
Animator::Hover::manage(frame);
if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>(frame) ) {
if (widget->inherits("KCompletionBox") && !(kStyleFeatureRequest & NoShadow))
Shadows::manage(widget);
else if (widget->inherits("QTableView")) {
frame->setFrameShape(QFrame::NoFrame); // ugly and superfluous - has grid and/or headers
#if QT_VERSION >= 0x060000
if (widget->inherits("QtPrivate::QCalendarView")) {
#else
if (widget->inherits("QCalendarView")) {
#endif
// MEGAUGLY HACK
// QCalendarView looks shit. I want. *want* the selected date round.
// unfortunately the view uses a private delegate on top of QItemDelegate
// which just paints rects.
// Tried tricking by erasing with the focus frame, but that only works while
// the widget has the foucs.
// So instead we set the Highlight role to 0 alpha -> the stupid delegate will
// paint the big invisibility, what means the PE item from QTableView shines
// through... which happens to be painted by us >-)
QPalette pal = widget->palette();
QColor c = pal.color(QPalette::Active, QPalette::Highlight); c.setAlpha(0);
pal.setColor(QPalette::Active, QPalette::Highlight, c);
c = pal.color(QPalette::Inactive, QPalette::Highlight); c.setAlpha(0);
pal.setColor(QPalette::Inactive, QPalette::Highlight, c);
c = pal.color(QPalette::Disabled, QPalette::Highlight); c.setAlpha(0);
pal.setColor(QPalette::Disabled, QPalette::Highlight, c);
widget->setPalette(pal);
}
} else if (itemView->inherits("KCategorizedView")) { // fix scrolldistance...
FILTER_EVENTS(itemView);
} else if ( QTreeView* tv = qobject_cast<QTreeView*>(itemView) ) {
tv->setAnimated(true); // allow all treeviews to be animated!
}
if (qobject_cast<QHeaderView*>(itemView)) {
if (config.invert.headers) {
itemView->setBackgroundRole(QPalette::Text);
itemView->setForegroundRole(QPalette::Base);
} else {
itemView->setBackgroundRole(QPalette::Base);
itemView->setForegroundRole(QPalette::Text);
}
widget->setAttribute(Qt::WA_Hover);
} else if (QWidget *vp = itemView->viewport()) {
vp->setAttribute(Qt::WA_Hover);
}
if (appType == Amarok) // fix the palette anyway. amarok tries to reset it's slooww transparent one... gnagnagna
FILTER_EVENTS(itemView);
}
// just use <strike>broadsword</strike> <strike>gladius</strike> foil here
// the stupid viewport should use the mouse...
else if (area->viewport() && !qobject_cast<QAbstractScrollArea*>(area->parent()) &&
!qobject_cast<QGraphicsView*>(area->viewport())) {
area->viewport()->setAttribute(Qt::WA_NoMousePropagation);
}
// Dolphin Information panel still (again?) does this
// *sigh* - this cannot be true. this CANNOT be true. this CAN NOT BE TRUE!
if (area->viewport() && area->viewport()->autoFillBackground() && !area->viewport()->palette().color(area->viewport()->backgroundRole()).alpha() )
area->viewport()->setAutoFillBackground(false);
// if (QGraphicsView *qgc = qobject_cast<QGraphicsView*>(area)) {
// QWidget *runner = area;
// while (runner = runner->parentWidget()) {
// if (runner->palette() == invertedPalette) {
// if (qgc->scene()) {
// QPalette pal = area->palette();
// pal.setColor(QPalette::Text, Qt::red);
// pal.setColor(QPalette::WindowText, Qt::green);
// qDebug() << "gotcha!";
// qgc->scene()->setPalette(pal);
// QList<QGraphicsItem*> fuckers = qgc->scene()->items();
// foreach (QGraphicsItem *fucker, fuckers) {
// if (QGraphicsWidget *sucker = dynamic_cast<QGraphicsWidget*>(fucker)) {
// qDebug() << "SUCKER!" << sucker;
// sucker->setPalette(pal);
// }
// }
// }
// break;
// }
// }
// }
}
/// Tab Transition animation,
if (widget->inherits("QStackedWidget"))
// NOTICE do NOT(!) apply this on tabs explicitly, as they contain a stack!
Animator::Tab::manage(widget);
else if (widget->inherits("KColorPatch"))
widget->setAttribute(Qt::WA_NoMousePropagation);
/// QToolBox handling - a shame they look that crap by default!
else if (widget->inherits("QToolBox"))
{ // get rid of QPalette::Button
widget->setBackgroundRole(QPalette::Window);
widget->setForegroundRole(QPalette::WindowText);
if (widget->layout())
{ // get rid of nasty indention
widget->layout()->setContentsMargins(0,0,0,0);
widget->layout()->setSpacing ( 0 );
}
}
if (!frame->isWindow() && frame->frameShape() != QFrame::NoFrame && frame->lineWidth() < F(2))
frame->setLineWidth(F(2));
}
//END FRAMES -
//BEGIN PUSHBUTTONS - hovering/animation -
else if (qobject_cast<QAbstractButton*>(widget))
{
// widget->setBackgroundRole(config.btn.std_role[Bg]);
// widget->setForegroundRole(config.btn.std_role[Fg]);
widget->setAttribute(Qt::WA_Hover, false); // KHtml
if (widget->inherits("QToolBoxButton") || IS_HTML_WIDGET )
widget->setAttribute(Qt::WA_Hover); // KHtml
else
{
if (QPushButton *pbtn = qobject_cast<QPushButton*>(widget))
{
// HACK around "weird" original appearance ;-P
// also see eventFilter
if (pbtn->inherits("KUrlNavigatorButtonBase") || pbtn->inherits("BreadcrumbItemButton")) {
pbtn->setBackgroundRole(QPalette::Window);
pbtn->setForegroundRole(QPalette::Link);
QPalette pal = pbtn->palette();
pal.setColor(QPalette::Highlight, Qt::transparent);
pal.setColor(QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::Window));
pbtn->setPalette(pal);
pbtn->setCursor(Qt::PointingHandCursor);
FILTER_EVENTS(pbtn);
widget->setAttribute(Qt::WA_Hover);
} else if (!qobject_cast<QCommandLinkButton*>(pbtn)) {
QFont fnt(widget->font());
fnt.setBold(true);
widget->setFont(fnt);
}
}
else if (widget->inherits("QToolButton") &&
// of course plasma needs - again - a WORKAROUND, we seem to be unable to use bg/fg-role, are we?
!(appType == Plasma && widget->inherits("ToolButton")))
{
QPalette::ColorRole bg = QPalette::Window, fg = QPalette::WindowText;
if (QWidget *dad = widget->parentWidget())
{
bg = dad->backgroundRole();
fg = dad->foregroundRole();
}
widget->setBackgroundRole(bg);
widget->setForegroundRole(fg);
if (widget->inherits("BE::Button")) // I hover myself - QStyleSheetStyle breaks all animations :-(
widget->setAttribute(Qt::WA_Hover);
}
if (!widget->testAttribute(Qt::WA_Hover))
Animator::Hover::manage(widget);
}
// NOTICE WORKAROUND - this widget uses the style to paint the bg, but hardcodes the fg...
// TODO: inform Joseph Wenninger <[email protected]> and really fix this
// (fails all styles w/ Windowcolored ToolBtn and QPalette::ButtonText != QPalette::WindowText settings)
if (widget->inherits("KMultiTabBarTab"))
{
QPalette pal = widget->palette();
pal.setColor(QPalette::Active, QPalette::Button, pal.color(QPalette::Active, QPalette::Window));
pal.setColor(QPalette::Inactive, QPalette::Button, pal.color(QPalette::Inactive, QPalette::Window));
pal.setColor(QPalette::Disabled, QPalette::Button, pal.color(QPalette::Disabled, QPalette::Window));
pal.setColor(QPalette::Active, QPalette::ButtonText, pal.color(QPalette::Active, QPalette::WindowText));
pal.setColor(QPalette::Inactive, QPalette::ButtonText, pal.color(QPalette::Inactive, QPalette::WindowText));
pal.setColor(QPalette::Disabled, QPalette::ButtonText, pal.color(QPalette::Disabled, QPalette::WindowText));
widget->setPalette(pal);
}
}
//BEGIN COMBOBOXES - hovering/animation -
else if (QComboBox *cb = qobject_cast<QComboBox*>(widget))
{
if (cb->view()) {
cb->view()->setTextElideMode( Qt::ElideMiddle);
}
if (cb->parentWidget() && cb->parentWidget()->inherits("KUrlNavigator"))
cb->setIconSize(QSize(0,0));
if (IS_HTML_WIDGET)
widget->setAttribute(Qt::WA_Hover);
else {
Animator::Hover::manage(widget);
if (cb->isEditable())
Animator::Focus::manage(widget);
}
}
//BEGIN SLIDERS / SCROLLBARS / SCROLLAREAS - hovering/animation -
else if (qobject_cast<QAbstractSlider*>(widget))
{
FILTER_EVENTS(widget); // finish animation
widget->setAttribute(Qt::WA_Hover);
// NOTICE
// QAbstractSlider::setAttribute(Qt::WA_OpaquePaintEvent) saves surprisinlgy little CPU
// so that'd just gonna add more complexity for literally nothing...
// ...as the slider is usually not bound to e.g. a "scrollarea"
// if ( appType == Amarok && widget->inherits("VolumeDial") )
// { // OMG - i'm hacking myself =D
// QPalette pal = widget->palette();
// pal.setColor( QPalette::Highlight, pal.color( QPalette::Active, QPalette::WindowText ) );
// widget->setPalette( pal );
// }
if (widget->inherits("QScrollBar"))
{
// TODO: find a general catch for the plasma problem
if (appType == Plasma) // yes - i currently don't know how to detect those things otherwise
widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
else
{
QWidget *dad = widget;
while ((dad = dad->parentWidget()))
{ // digg for a potential KHTMLView ancestor, making this a html input scroller
if (dad->inherits("KHTMLView"))
{ // NOTICE this slows down things as it triggers a repaint of the frame
widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
// ...but this would re-enbale speed - just: how to get the proper palette
// what if there's a bg image?
// TODO how's css/khtml policy on applying colors?
// widget->setAutoFillBackground ( true );
// widget->setBackgroundRole ( QPalette::Base ); // QPalette::Window looks wrong
// widget->setForegroundRole ( QPalette::Text );
break;
}
}
}
/// Scrollarea hovering - yes, this is /NOT/ redundant to the one above!
if (QWidget *area = widget->parentWidget())
{
if ((area = area->parentWidget())) // sic!
{
if (qobject_cast<QAbstractScrollArea*>(area))
area = 0; // this is handled for QAbstractScrollArea, but...
else // Konsole, Kate, etc. need a special handling!
area = widget->parentWidget();
}
if (area)
Animator::Hover::manage(area, true);
}
}
}
else if (qobject_cast<QLineEdit*>(widget))
Animator::Focus::manage(widget);
//BEGIN PROGRESSBARS - hover/animation and bold font -
else if (widget->inherits("QProgressBar"))
{
widget->setAttribute(Qt::WA_Hover);
setBoldFont(widget);
Animator::Progress::manage(widget);
} else if ( widget->inherits( "QTabWidget" ) )
FILTER_EVENTS(widget)
//BEGIN Tab animation, painting override -
else if (QTabBar *bar = qobject_cast<QTabBar *>(widget))
{
widget->setAttribute(Qt::WA_Hover);
if (bar->drawBase() && config.invert.headers) {
widget->setBackgroundRole(QPalette::WindowText);
widget->setForegroundRole(QPalette::Window);
}
QWidget *win = bar->window();
if (win && win->inherits("DolphinMainWindow"))
bar->setDocumentMode(true);
bar->setExpanding(false);
// the eventfilter overtakes the widget painting to allow tabs ABOVE the tabbar
FILTER_EVENTS(widget);
}
else if ( QDockWidget *dock = qobject_cast<QDockWidget*>(widget) ) {
if (config.invert.docks && dock->style() == this && (dock->window()->windowFlags() & Qt::Dialog) != Qt::Dialog) {
if (QWidget *window = widget->window())
window->setProperty("Virtuality.invertTitlebar", true);
dock->setProperty("Virtuality.inverted", true);
invertContainer(dock, invertedPalette);
dock->setAutoFillBackground(true);
}
if ( Hacks::config.lockDocks ) {
disconnect( dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(dockLocationChanged(Qt::DockWidgetArea)) );
connect( dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(dockLocationChanged(Qt::DockWidgetArea)) );
}
dock->setContentsMargins(F(4),F(4),F(4),F(4));
widget->setAttribute(Qt::WA_Hover);
if (!(kStyleFeatureRequest & NoShadow))
Shadows::manage(dock);
}
/// Menubars and toolbar default to QPalette::Button - looks crap and leads to flicker...?!
else if (QMenuBar *mbar = qobject_cast<QMenuBar *>(widget)) {
if (config.invert.menubars && qobject_cast<QMainWindow*>(mbar->parentWidget())) {
if (QWidget *window = widget->window())
window->setProperty("Virtuality.invertTitlebar", true);
mbar->setProperty("Virtuality.inverted", true);
invertContainer(mbar, invertedPalette);
mbar->setAutoFillBackground(true);
}
#ifndef QT_NO_DBUS
if ( appType != KDevelop ) //&& !(appType == QtDesigner && mbar->inherits("QDesignerMenuBar")) )
MacMenu::manage(mbar);
#endif
}
else if (widget->inherits("KFadeWidgetEffect"))
{ // interfers with our animation, is slower and cannot handle non plain backgrounds
// (unfortunately i cannot avoid the widget grabbing)
// maybe ask ereslibre to query a stylehint for this?
widget->hide();
widget->installEventFilter(&eventKiller);
}
/// hover some leftover widgets
else if (widget->inherits("QAbstractSpinBox") || widget->inherits("QSplitterHandle") ||
widget->inherits("QWebView") || // to update the scrollbars
widget->inherits("QWorkspaceTitleBar") ||
widget->inherits("Q3DockWindowResizeHandle"))
{
widget->setAttribute(Qt::WA_Hover);
if (widget->inherits("QWebView"))
FILTER_EVENTS(widget)
else if (widget->inherits("QAbstractSpinBox"))
Animator::Focus::manage(widget);
}
// this is a WORKAROUND for amarok filebrowser, see above on itemviews...
else if (widget->inherits("KDirOperator"))
{
if (widget->parentWidget() && widget->parentWidget()->inherits("FileBrowser"))
{
QPalette pal = widget->palette();
pal.setColor(QPalette::Active, QPalette::Text, pal.color(QPalette::Active, QPalette::WindowText));
pal.setColor(QPalette::Inactive, QPalette::Text, pal.color(QPalette::Inactive, QPalette::WindowText));
pal.setColor(QPalette::Disabled, QPalette::Text, pal.color(QPalette::Disabled, QPalette::WindowText));
widget->setPalette(pal);
}
} else if (widget->inherits("Marble::MarbleWidget")) {
widget->setAttribute(Qt::WA_NoMousePropagation, true);
}
#if 0
// #ifdef BE_WS_X11
if ( config.bg.opacity != 0xff && /*widget->window() &&*/
(widget->inherits("MplayerWindow") ||
widget->inherits("KSWidget") ||
widget->inherits("QX11EmbedContainer") ||
widget->inherits("QX11EmbedWidget") ||
widget->inherits("Phonon::VideoWidget")) )
{
bool vis = widget->isVisible();
widget->setWindowFlags(Qt::Window);
widget->show();
printf("%s %s %d\n", widget->className(), widget->parentWidget()->className(), widget->winId());
widget->setAttribute(Qt::WA_DontCreateNativeAncestors, widget->testAttribute(Qt::WA_DontCreateNativeAncestors));
widget->setAttribute(Qt::WA_NativeWindow);
widget->setAttribute(Qt::WA_TranslucentBackground, false);
widget->setAttribute(Qt::WA_PaintOnScreen, true);
widget->setAttribute(Qt::WA_NoSystemBackground, false);
if (QWidget *window = widget->window())
{
qDebug() << "BESPIN, reverting" << widget << window;
window->setAttribute(Qt::WA_TranslucentBackground, false);
window->setAttribute(Qt::WA_NoSystemBackground, false);
}
QApplication::setColorSpec(QApplication::NormalColor);
}
#endif
// const bool isNavigationBar = widget->inherits("NavigationBar");
const bool isTopContainer = qobject_cast<QToolBar *>(widget)/* || isNavigationBar*/;
if (isTopContainer && config.invert.toolbars)
if (QWidget *window = widget->window())
if (qobject_cast<QMainWindow*>(window)) {
widget->setProperty("Virtuality.inverted", true);
window->setProperty("Virtuality.invertTitlebar", true);
widget->setAutoFillBackground(true);
invertContainer(widget, invertedPalette);
}
// Arora needs a separator between the buttons and the lineedit - looks megadull w/ shaped buttons otherwise :-(
if ( appType == Arora && isTopContainer && widget->objectName() == "NavigationToolBar")
{
QAction *before = 0;
QToolBar *bar = static_cast<QToolBar *>(widget);
foreach ( QObject *o, bar->children() )
{
before = 0;
if ( o->inherits("QWidgetAction") && bar->widgetForAction( (before = static_cast<QAction*>(o)) )->inherits("QSplitter") )
break;
}
if ( before )
bar->insertSeparator( before );
}
if (isTopContainer || qobject_cast<QToolBar*>(widget->parent()))
{
widget->setBackgroundRole(QPalette::Window);
widget->setForegroundRole(QPalette::WindowText);
if (!isTopContainer && widget->inherits("QToolBarHandle"))
widget->setAttribute(Qt::WA_Hover);
}
const bool isDolphinStatusBar = widget->inherits("DolphinStatusBar");
if (isDolphinStatusBar) {
QMargins marg = widget->contentsMargins();
int m[4] = {marg.left(), marg.top(), marg.right(), marg.bottom()};
for (int i = 0; i < 4; ++i)
m[i] = qMax(m[i], F(2));
widget->setContentsMargins(m[0], m[1], m[2], m[3]);
}
if ((config.invert.toolbars||config.invert.titlebars) && (!isDolphinStatusBar || config.invert.docks) &&
(isDolphinStatusBar || widget->inherits("QStatusBar") || widget->inherits("KStatusBar") ||
widget->inherits("KonqFrameStatusBar") || widget->inherits("KonqStatusBarMessageLabel"))) {
widget->setAutoFillBackground(true);
widget->setProperty("Virtuality.inverted", true);
invertContainer(widget, invertedPalette);
}
/// this is for QToolBox kids - they're autofilled by default - what looks crap
if (widget->autoFillBackground() && widget->parentWidget() &&
( widget->parentWidget()->objectName() == "qt_scrollarea_viewport" ) &&
widget->parentWidget()->parentWidget() && //grampa
qobject_cast<QAbstractScrollArea*>(widget->parentWidget()->parentWidget()) &&
widget->parentWidget()->parentWidget()->parentWidget() && // grangrampa
widget->parentWidget()->parentWidget()->parentWidget()->inherits("QToolBox") )
{
widget->parentWidget()->setAutoFillBackground(false);
widget->setAutoFillBackground(false);
}
/// KHtml css colors can easily get messed up, either because i'm unsure about what colors
/// are set or KHtml does wrong OR (mainly) by html "designers"
if (IS_HTML_WIDGET)
{ // the eventfilter watches palette changes and ensures contrasted foregrounds...
FILTER_EVENTS(widget);
QEvent ev(QEvent::PaletteChange);
eventFilter(widget, &ev);
}
/// QTextDocument will *often* come with some dark colored through the CSS and no particular background
/// so if we've a dark Text role, we're printing black on black
/// should not happen and is part of WORKAROUNDs for "lousy dark theme support everywhere"
if (FX::value(widget->palette().color(QPalette::Active, QPalette::Base)) < 128) {
if (QTextEdit *edit = qobject_cast<QTextEdit*>(widget)) {
if (edit->document()) {
if (edit->autoFillBackground())
edit->document()->setDefaultStyleSheet( QString("*{color:%1;background-color:%2;}a{color:%3;}").arg(edit->palette().color(QPalette::Active, QPalette::Text).name()).arg(edit->palette().color(QPalette::Active, QPalette::Base).name()).arg(edit->palette().color(QPalette::Active, QPalette::Link).name()) );
else
edit->document()->setDefaultStyleSheet( QString("*{color:%1;}a{color:%2;}").arg(edit->palette().color(QPalette::Active, QPalette::WindowText).name()).arg(edit->palette().color(QPalette::Active, QPalette::Link).name()) );
if (!edit->document()->isEmpty()) {
if (QTextBrowser *browser = qobject_cast<QTextBrowser*>(edit)) {