forked from qt/qtstyleplugins
/
qmaemo5style.cpp
2233 lines (1942 loc) · 91.7 KB
/
qmaemo5style.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
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qgtkstyle_p.h"
#include "qgtkstyle_p_p.h"
#include "qcleanlooksstyle.h"
#include "qmaemo5style.h"
#include "qmaemo5style_p.h"
#include <private/qapplication_p.h>
#include <QtCore/QLibrary>
#include <QtWidgets/QStyleOption>
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QCommandLinkButton>
#include <QtWidgets/QAbstractScrollArea>
#include <QtWidgets/QAbstractItemView>
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QScroller>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QTextBrowser>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QAbstractSpinBox>
#include <QtX11Extras/QX11Info>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QCalendarWidget>
#include <QtCore/QTimer>
#include <QtCore/QTimeLine>
#include <QtGui/qpa/qplatformfontdatabase.h>
#include <QtDebug>
#include "qpixmapcache.h"
#undef signals // Collides with GTK stymbols
#include "qgtk2painter_p.h"
#include <private/qstylehelper_p.h>
#include <hildon/hildon.h>
QT_BEGIN_NAMESPACE
QMap<QAbstractScrollArea *, ScrollBarFader *> QMaemo5StylePrivate::scrollBarFaders;
int QMaemo5StylePrivate::scrollBarFadeDelay = 3000; // [ms] hardcoded in hildon pannable area
int QMaemo5StylePrivate::scrollBarFadeDuration = 400; // [ms] hardcoded in hildon pannable area
int QMaemo5StylePrivate::scrollBarFadeUpdateInterval = 100; // [ms] hardcoded in hildon pannable area
GtkWidget *QMaemo5StylePrivate::radioButtonLeft = 0;
GtkWidget *QMaemo5StylePrivate::radioButtonMiddle = 0;
GtkWidget *QMaemo5StylePrivate::radioButtonRight = 0;
//no longer in QGtkPainter, now static in qgtkstyle.cpp, so static here, too
static GtkStateType qt_gtk_state(const QStyleOption *option)
{
GtkStateType state = GTK_STATE_NORMAL;
if (!(option->state & QStyle::State_Enabled))
state = GTK_STATE_INSENSITIVE;
else if (option->state & QStyle::State_MouseOver)
state = GTK_STATE_PRELIGHT;
return state;
}
//used to be part of QStyleHelper
//requires qmath_p.h
#include <private/qmath_p.h>
static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset)
{
const int width = dial->rect.width();
const int height = dial->rect.height();
const int r = qMin(width, height) / 2;
const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
qreal a = 0;
if (dial->maximum == dial->minimum)
a = Q_PI / 2;
else if (dial->dialWrapping)
a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI
/ (dial->maximum - dial->minimum);
else
a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI
/ (dial->maximum - dial->minimum)) / 6;
qreal xc = width / 2.0;
qreal yc = height / 2.0;
qreal len = r - QStyleHelper::calcBigLineSize(r) - 3;
qreal back = offset * len;
QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a)));
return pos;
}
QString QMaemo5StylePrivate::systemIconThemeName()
{
QString qicontheme;
gchar *gicontheme = 0;
g_object_get(gtk_settings_get_default(), "gtk-icon-theme-name", &gicontheme, NULL);
if (gicontheme)
qicontheme = QString::fromUtf8(gicontheme);
g_free(gicontheme);
return qicontheme;
}
/*!
\internal
NOTE: Reverse color in fremantle themes are set only for
GtkTextView widgets. GtkEntry returns a dark base color.
*/
GtkWidget* QMaemo5StylePrivate::getTextColorWidget() const
{
return gtkWidget("GtkTextView");
}
/*!
\internal
\reimp
*/
void QMaemo5StylePrivate::initGtkMenu() const
{
QGtkStylePrivate::initGtkMenu();
// --- create widgets for the context sensitive menu
GtkWidget *gtkMenu = gtk_menu_new();
gtk_widget_set_name(gtkMenu, "hildon-context-sensitive-menu");
gtk_widget_realize(gtkMenu);
GtkWidget *gtkMenuItem = gtk_menu_item_new_with_label("X");
gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuItem);
gtk_widget_realize(gtkMenuItem);
GtkWidget *gtkCheckMenuItem = gtk_check_menu_item_new_with_label("X");
gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkCheckMenuItem);
gtk_widget_realize(gtkCheckMenuItem);
GtkWidget *gtkMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuSeparator);
addAllSubWidgets(gtkMenu);
// --- and now for the "normal" app menu
GtkWidget *gtkMenu2 = hildon_app_menu_new();
// -- three menu buttons. Sapwood will use different background images depending on their position.
radioButtonLeft = gtk_radio_button_new(NULL);
gtk_widget_show(radioButtonLeft); // only a visible button is really added.
hildon_app_menu_add_filter( (HildonAppMenu*)gtkMenu2, (GtkButton*)radioButtonLeft);
radioButtonMiddle = gtk_radio_button_new(NULL);
gtk_widget_show(radioButtonMiddle); // only a visible button is really added.
hildon_app_menu_add_filter( (HildonAppMenu*)gtkMenu2, (GtkButton*)radioButtonMiddle);
radioButtonRight = gtk_radio_button_new(NULL);
gtk_widget_show(radioButtonRight); // only a visible button is really added.
hildon_app_menu_add_filter( (HildonAppMenu*)gtkMenu2, (GtkButton*)radioButtonRight);
addAllSubWidgets(gtkMenu2);
// and now a hack for the sapwood engine
radioButtonLeft->allocation.x = 0;
radioButtonLeft->allocation.y = 0;
GTK_WIDGET_FLAGS(radioButtonLeft) |= GTK_MAPPED;
radioButtonMiddle->allocation.x = 1;
radioButtonMiddle->allocation.y = 0;
GTK_WIDGET_FLAGS(radioButtonMiddle) |= GTK_MAPPED;
radioButtonRight->allocation.x = 2;
radioButtonRight->allocation.y = 0;
GTK_WIDGET_FLAGS(radioButtonRight) |= GTK_MAPPED;
}
void QMaemo5StylePrivate::applyCustomPaletteHash()
{
QGtkStylePrivate::applyCustomPaletteHash();
QPalette textpalette = gtkWidgetPalette("GtkTextView");
qApp->setPalette(textpalette, "QAbstractSpinBox");
qApp->setPalette(textpalette, "QLineEdit");
qApp->setPalette(textpalette, "QTextEdit");
qApp->setPalette(textpalette, "QPlainTextEdit");
QPalette calendarpalette = QApplication::palette();
QColor high = calendarpalette.color(QPalette::Highlight);
QColor base = calendarpalette.color(QPalette::Window);
calendarpalette.setColor(QPalette::Disabled, QPalette::Highlight, high.darker(130));
calendarpalette.setColor(QPalette::AlternateBase, base.lighter(250));
QApplication::setPalette(calendarpalette, "QCalendarWidget");
QPalette treeviewpalette = gtkWidgetPalette("HildonPannableArea.GtkTreeView");
GtkStyle *gtkStyle = gtk_widget_get_style(gtkWidget("HildonPannableArea.GtkTreeView"));
GdkColor gdkBase = gtkStyle->base[GTK_STATE_NORMAL];
GdkColor gdkText = gtkStyle->text[GTK_STATE_NORMAL];
QColor text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
base = QColor(gdkBase.red>>8, gdkBase.green>>8, gdkBase.blue>>8);
treeviewpalette.setBrush(QPalette::Base, base);
treeviewpalette.setBrush(QPalette::Text, text);
qApp->setPalette(treeviewpalette, "QScrollBar");
qApp->setPalette(treeviewpalette, "QAbstractItemView");
qApp->setPalette(treeviewpalette, "QScrollArea");
qApp->setPalette(treeviewpalette, "QGraphicsView");
if (gtkWidget("HildonNote-information-theme-portrait.GtkAlignment.GtkHBox.GtkVBox.GtkEventBox.GtkAlignment.GtkVBox.HildonNoteLabel-information-theme")) {
qApp->setPalette(gtkWidgetPalette("HildonNote-information-theme-portrait.GtkAlignment.GtkHBox.GtkVBox.GtkEventBox.GtkAlignment.GtkVBox.HildonNoteLabel-information-theme"),
"QMaemo5InformationBox");
} else {
qApp->setPalette(gtkWidgetPalette("HildonNote-information-theme.GtkAlignment.GtkHBox.GtkVBox.GtkEventBox.GtkAlignment.GtkVBox.HildonNoteLabel-information-theme"),
"QMaemo5InformationBox");
}
}
#define HILDON_WIDGET_ID "HILDON-WIDGET-"
const QLatin1String HILDON_MAGIC_NAME = QLS(HILDON_WIDGET_ID);
QString QMaemo5StylePrivate::getGtkNameFromQtName(const QWidget *widget)
{
int index;
if(widget && ((index = widget->objectName().indexOf(HILDON_MAGIC_NAME)) != -1))
return widget->objectName().mid(index+sizeof(HILDON_WIDGET_ID)-1);
else
return QString();
}
GtkWidget * QMaemo5StylePrivate::getGtkButtonForWidget(const QWidget *widget)
{
GtkWidget *gtkButton;
QString gtkWidgetName = getGtkNameFromQtName(widget);
if(gtkWidgetName.isEmpty())
gtkButton = gtkWidget("HildonButton-finger");
else if(!(gtkButton = gtkWidget(QHashableLatin1Literal::fromData(gtkWidgetName.toLatin1().constData()))))
gtkButton = addGtkButtonWithName(gtkWidgetName);
return gtkButton;
}
GtkWidget * QMaemo5StylePrivate::addGtkButtonWithName(const QString & widgetName)
{
// Gtk bug - a GtkButton without a label won't even create it's child widgets
GtkWidget *button = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
gtk_button_set_label(reinterpret_cast<GtkButton *>(button), "");
if(!widgetName.isEmpty())
gtk_widget_set_name(button, widgetName.toLatin1());
addWidget(button);
return button;
}
GtkWidget * QMaemo5StylePrivate::addGtkCheckButtonWithName(const QString & widgetName)
{
GtkWidget *button = hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT);
gtk_button_set_label(reinterpret_cast<GtkButton *>(button), "");
if(!widgetName.isEmpty())
gtk_widget_set_name(button, widgetName.toLatin1());
addWidget(button);
return button;
}
void QMaemo5StylePrivate::initGtkWidgets() const
{
QGtkStylePrivate::initGtkWidgets();
hildon_init();
if (!gtkWidgetMap()->contains("GtkWindow"))
return; // without window all other widgets won't be created cleanly
// ComboBoxes buttons
addWidget(hildon_number_editor_new(0,1));
addWidget(hildon_entry_new(HILDON_SIZE_FINGER_HEIGHT));
addWidget(gtk_text_view_new());
addWidget(hildon_dialog_new_with_buttons("", NULL, GTK_DIALOG_MODAL, "", 0, NULL));
addWidget(hildon_pannable_area_new());
GtkWidget *note = hildon_note_new_information(NULL, "");
gtk_widget_set_name(note, "HildonNote-InformationTheme");
addWidget(note);
// I need a tree view inside a pannable area
GtkWidget *hildonPan = gtkWidget("HildonPannableArea");
GtkWidget *gtkTreeView = gtk_tree_view_new();
gtk_container_add((GtkContainer*)hildonPan, gtkTreeView);
addWidget(gtkTreeView);
addGtkButtonWithName(QString());
addGtkCheckButtonWithName(QString());
addWidget(hildon_edit_toolbar_new_with_text("", ""));
// now for a special combobox trick...
for (int i = 0; i < 3; i++) {
const char *names[] = { "hildon-combobox-disabled-button", "hildon-combobox-active-button", "hildon-combobox-button" };
GtkWidget *popup_button = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
gtk_widget_set_name(popup_button, names[i]);
gtk_widget_set_size_request (popup_button, 60, -1);
GtkWidget *address_entry = hildon_entry_new(HILDON_SIZE_FINGER_HEIGHT);
GtkWidget *address_container_box = gtk_hbox_new(FALSE, 0);
gtk_widget_set_name(address_container_box, "hildon-combobox");
gtk_box_pack_start((GtkBox *)address_container_box, address_entry, TRUE, TRUE, 0);
gtk_box_pack_end((GtkBox *)address_container_box, popup_button, FALSE, FALSE, 0);
gtk_widget_show (address_entry);
gtk_widget_show (popup_button);
// gtk_widget_set_sensitive(popup_button, FALSE);
addWidget(address_container_box);
}
}
/*! \internal
* Returns one int value from the HildonAppMenu widget style.
*/
int QMaemo5StylePrivate::getAppMenuMetric( const char *metricName, int defaultValue ) const
{
guint value = defaultValue;
if (GtkWidget *hildonAppMenu = gtkWidget("HildonAppMenu"))
gtk_widget_style_get(hildonAppMenu, metricName, &value, NULL);
return value;
}
// Fetch the application font from the pango font description
// contained in the theme.
QFont QMaemo5StylePrivate::getThemeFont(const QString &logicalFontName)
{
QFont font;
GtkStyle *style;
if (!logicalFontName.isEmpty())
style = gtk_rc_get_style_by_paths(gtk_settings_get_default(), logicalFontName.toUtf8().constData(), NULL, G_TYPE_NONE);
else
style = gtkStyle();
if (style && qApp->desktopSettingsAware())
{
PangoFontDescription *gtk_font = style->font_desc;
font.setPointSizeF((float)(pango_font_description_get_size(gtk_font))/PANGO_SCALE);
QString family = QString::fromLatin1(pango_font_description_get_family(gtk_font));
if (!family.isEmpty())
font.setFamily(family);
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
const int weight = pango_font_description_get_weight(gtk_font);
font.setWeight(QPlatformFontDatabase::weightFromInteger(weight));
#else
int weight = pango_font_description_get_weight(gtk_font);
if (weight >= PANGO_WEIGHT_HEAVY)
font.setWeight(QFont::Black);
else if (weight >= PANGO_WEIGHT_BOLD)
font.setWeight(QFont::Bold);
else if (weight >= PANGO_WEIGHT_SEMIBOLD)
font.setWeight(QFont::DemiBold);
else if (weight >= PANGO_WEIGHT_NORMAL)
font.setWeight(QFont::Normal);
else
font.setWeight(QFont::Light);
#endif
PangoStyle fontstyle = pango_font_description_get_style(gtk_font);
if (fontstyle == PANGO_STYLE_ITALIC)
font.setStyle(QFont::StyleItalic);
else if (fontstyle == PANGO_STYLE_OBLIQUE)
font.setStyle(QFont::StyleOblique);
else
font.setStyle(QFont::StyleNormal);
}
return font;
}
/*!
\class QMaemo5Style
\brief The QMaemo5Style class provides a widget style rendered by GTK+
\since 4.6
\ingroup qtmaemo5
The QMaemo5Style style provides a look and feel that integrates Qt widgets
into Hildon-based desktop environments.
It is largely based on QGtkStyle, but does some special magic to "Hildonize" the look and feel.
\note The style requires GTK+ version 2.10 or later and the special patched GTK+ Hildon include files.
*/
/*!
Constructs a QMaemo5Style object.
*/
QMaemo5Style::QMaemo5Style()
: QGtkStyle(*new QMaemo5StylePrivate)
{
}
/*!
Destroys the QMaemo5Style object.
*/
QMaemo5Style::~QMaemo5Style()
{
}
/*!
\reimp
Sets the Maemo style file dialog hooks.
*/
void QMaemo5Style::polish(QApplication *app)
{
Q_D(QMaemo5Style);
QGtkStyle::polish(app);
}
ScrollBarFader::ScrollBarFader(QAbstractScrollArea *area, int delay, int duration, int update_interval)
: QObject(area), m_area(area), m_current_alpha(0.0)
{
m_fade_timeline = new QTimeLine(duration, this);
m_fade_timeline->setUpdateInterval(update_interval);
connect(m_fade_timeline, SIGNAL(valueChanged(qreal)), this, SLOT(fade(qreal)));
m_delay_timer = new QTimer(this);
m_delay_timer->setInterval(delay);
connect(m_delay_timer, SIGNAL(timeout()), this, SLOT(delayTimeout()));
}
ScrollBarFader::~ScrollBarFader()
{
}
void ScrollBarFader::delayTimeout()
{
m_fade_timeline->setDirection(QTimeLine::Backward);
m_fade_timeline->resume();
m_delay_timer->stop();
}
void ScrollBarFader::fade(qreal value)
{
m_current_alpha = value;
if (QScrollBar *hsb = m_area->horizontalScrollBar()) {
if (hsb->isVisible()) {
QStyleOptionSlider option;
option.initFrom(hsb);
option.subControls = QStyle::SC_All;
hsb->update(); // ### hsb->style()->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarSlider, hsb));
}
}
if (QScrollBar *vsb = m_area->verticalScrollBar()) {
if (vsb->isVisible()) {
QStyleOptionSlider option;
option.initFrom(vsb);
option.subControls = QStyle::SC_All;
vsb->update(); // ### vsb->style()->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarSlider, vsb));
}
}
}
void ScrollBarFader::show()
{
if (!m_delay_timer->isActive()) {
m_fade_timeline->setDirection(QTimeLine::Forward);
if (m_fade_timeline->state() != QTimeLine::Running)
m_fade_timeline->start();
}
m_delay_timer->start();
}
bool ScrollBarFader::eventFilter(QObject *obj, QEvent *ev)
{
if (m_area->isEnabled()) {
if (m_area == obj) {
switch (ev->type()) {
case QEvent::Show:
case QEvent::ScrollPrepare:
case QEvent::Scroll: {
show();
break;
}
default:
break;
}
} else if(ev->type() == QEvent::Wheel)
show();
}
return QObject::eventFilter(obj, ev);
}
/*!
\reimp
*/
void QMaemo5Style::polish(QWidget *widget)
{
Q_D(QMaemo5Style);
QGtkStyle::polish(widget);
if (QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea *>(widget)) {
if ((qobject_cast<QTextEdit *>(widget) && !qobject_cast<QTextBrowser *>(widget)) || qobject_cast<QPlainTextEdit *>(widget)) {
area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} else {
area->setFrameStyle(QFrame::NoFrame);
ScrollBarFader *fader = new ScrollBarFader(area, d->scrollBarFadeDelay,
d->scrollBarFadeDuration,
d->scrollBarFadeUpdateInterval);
area->installEventFilter(fader);
area->viewport()->installEventFilter(fader);
d->scrollBarFaders.insert(area, fader);
if (QAbstractItemView *itemview = qobject_cast<QAbstractItemView *>(area)) {
itemview->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
itemview->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
}
QScroller::grabGesture(area, QScroller::LeftMouseButtonGesture);
}
} else if (qobject_cast<QCommandLinkButton*>(widget)) {
widget->setFont(standardFont(QLS("SystemFont")));
widget->setAttribute(Qt::WA_Hover, false);
}
}
/*!
\reimp
*/
void QMaemo5Style::unpolish(QWidget *widget)
{
Q_D(QMaemo5Style);
QGtkStyle::unpolish(widget);
if (QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea*>(widget)) {
ScrollBarFader *fader = d->scrollBarFaders.take(area);
if (fader) {
area->viewport()->removeEventFilter(fader);
area->removeEventFilter(fader);
delete fader;
}
if (QAbstractItemView *itemview = qobject_cast<QAbstractItemView *>(area))
itemview->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
}
}
/*!
\reimp
*/
int QMaemo5Style::pixelMetric(QStyle::PixelMetric metric,
const QStyleOption *option,
const QWidget *widget) const
{
Q_D(const QMaemo5Style);
if (!d->isThemeAvailable())
return QCleanlooksStyle().pixelMetric(metric, option, widget);
switch (metric) {
case PM_DefaultLayoutSpacing:
return 8;
case PM_DefaultTopLevelMargin:
return 8;
case PM_LayoutLeftMargin:
case PM_LayoutRightMargin:
return 16;
case PM_LayoutTopMargin:
return 0;
case PM_LayoutBottomMargin:
return 8;
case PM_DialogButtonsButtonHeight:
return 70;
case PM_DialogButtonsButtonWidth:
return 180;
case PM_MessageBoxIconSize:
return 0;
case PM_ToolBarIconSize:
return 48; // thumb icon size
case PM_TabBarIconSize:
case PM_ListViewIconSize:
return 48; // thumb icon size
case PM_TextCursorWidth:
return 2;
case PM_SplitterWidth:
return 14;
case PM_HeaderGripMargin:
return 30;
case PM_SmallIconSize:
return 24;
case PM_LargeIconSize:
return 48;
case PM_ButtonShiftHorizontal: {
guint horizontal_shift = 1;
if (GtkWidget *gtkButton = d->getGtkButtonForWidget(widget))
gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
return horizontal_shift;
}
case PM_ButtonShiftVertical: {
guint vertical_shift = 1;
if (GtkWidget *gtkButton = d->getGtkButtonForWidget(widget))
gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
return vertical_shift;
}
case PM_ScrollBarSliderMin: // fall through
case PM_ScrollBarExtent: {
guint indicator_width = 6;
if (GtkWidget *hildonPan = d->gtkWidget("HildonPannableArea"))
gtk_widget_style_get(hildonPan, "indicator-width", &indicator_width, NULL);
return indicator_width;
}
case PM_ScrollView_ScrollBarSpacing:
return 0;
case PM_TabBarTabHSpace:
return 38;
case PM_TabBarTabVSpace:
return 38;
case PM_ExclusiveIndicatorWidth:
case PM_ExclusiveIndicatorHeight:
case PM_IndicatorWidth:
case PM_IndicatorHeight: {
gint size = 38, spacing = 8;
if (GtkWidget *hildonCheckButton = d->gtkWidget("HildonCheckButton-finger"))
gtk_widget_style_get(hildonCheckButton, "image-spacing", &spacing, "checkbox-size", &size, NULL);
return size + 2 * spacing;
}
case PM_CheckBoxLabelSpacing:
return 3; // image-spacing is already calculated into PM_IndicatorWidth, but we're still 3pix to narrow...
case PM_Maemo5AppMenuHorizontalSpacing:
return d->getAppMenuMetric("horizontal-spacing", 16);
case PM_Maemo5AppMenuVerticalSpacing:
return d->getAppMenuMetric("vertical-spacing", 16);
case PM_Maemo5AppMenuContentMargin:
return d->getAppMenuMetric("inner-border", 16);
case PM_Maemo5AppMenuLandscapeXOffset:
return d->getAppMenuMetric("external-border", 50);
case PM_Maemo5AppMenuFilterGroupWidth:
return d->getAppMenuMetric("filter-group-width", 444);
case PM_Maemo5AppMenuFilterGroupVerticalSpacing:
return d->getAppMenuMetric("filter-vertical-spacing", 16);
case PM_Maemo5EditBarBackButtonWidth: {
gint width = 112;
if (GtkWidget *hildonEditBar = d->gtkWidget("toolbar-edit-mode"))
gtk_widget_style_get(hildonEditBar, "arrow-width", &width, NULL);
return width;
}
case PM_Maemo5EditBarBackButtonHeight: {
gint height = 56;
if (GtkWidget *hildonEditBar = d->gtkWidget("toolbar-edit-mode"))
gtk_widget_style_get(hildonEditBar, "arrow-height", &height, NULL);
return height;
}
default:
return QGtkStyle::pixelMetric(metric, option, widget);
}
}
/*!
\reimp
*/
int QMaemo5Style::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
QStyleHintReturn *returnData = 0) const
{
Q_D(const QMaemo5Style);
if (!d->isThemeAvailable())
return QCleanlooksStyle().styleHint(hint, option, widget, returnData);
switch (hint) {
case SH_Menu_Scrollable:
return int(true);
case SH_DialogButtonBox_ButtonsHaveIcons:
case SH_ScrollBar_ContextMenu:
return int(false);
case SH_UnderlineShortcut:
return int(false);
case SH_RequestSoftwareInputPanel:
return int(RSIP_OnMouseClick);
case SH_Slider_AbsoluteSetButtons:
return int(Qt::LeftButton);
case SH_Slider_PageSetButtons:
return int(Qt::NoButton);
case SH_ItemView_ActivateItemOnSingleClick:
return int(true);
case SH_ComboBox_ListMouseTracking:
return int(false);
case SH_ComboBox_Popup:
return int(false);
case SH_ComboBox_PopupFrameStyle:
return int(QFrame::Plain | QFrame::Box);
case SH_ProgressDialog_TextLabelAlignment:
return int(Qt::AlignLeft | Qt::AlignVCenter);
default:
return QGtkStyle::styleHint(hint, option, widget, returnData);
}
}
/*!
\reimp
*/
void QMaemo5Style::drawPrimitive(QStyle::PrimitiveElement element,
const QStyleOption *option,
QPainter *painter,
const QWidget *widget) const
{
Q_D(const QMaemo5Style);
if (!d->isThemeAvailable()) {
QCleanlooksStyle().drawPrimitive(element, option, painter, widget);
return;
}
QGtk2Painter gtkPainter;
gtkPainter.reset(painter);
switch (element) {
case PE_PanelButtonTool: // fall through
case PE_PanelButtonCommand: {
bool isTool = (element == PE_PanelButtonTool);
GtkStateType state = qt_gtk_state(option);
GtkShadowType shadow = GTK_SHADOW_OUT;
if (option->state & State_On || option->state & State_Sunken) {
state = GTK_STATE_ACTIVE;
shadow = GTK_SHADOW_IN;
}
GtkWidget *gtkButton = 0;
if (isTool) {
gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
} else if (widget && qobject_cast<QDialogButtonBox *>(widget->parentWidget())) {
gtkButton = d->gtkWidget("HildonDialog.GtkAlignment.GtkHBox.hildon-dialog-action-area.GtkButton-finger");
if (!gtkButton)
// Maybe application was started in portrait mode so
// there is an additional GtkVBox in the layout. Try it.
gtkButton = d->gtkWidget("HildonDialog.GtkAlignment.GtkHBox.GtkVBox.hildon-dialog-action-area.GtkButton-finger");
} else if (widget && widget->parentWidget() && !qstrcmp(widget->parentWidget()->metaObject()->className(), "QMaemo5EditBar")) {
gtkButton = d->gtkWidget("toolbar-edit-mode.GtkAlignment.GtkHBox.GtkButton");
} else {
gtkButton = d->getGtkButtonForWidget(widget);
}
if (gtkButton) {
gtkPainter.paintBox(gtkButton, "button", option->rect, state, shadow,
gtkButton->style, QString(), 70);
}
break;
}
case PE_IndicatorBranch:
// Due to style guidelines, maemo5 does not draw
// expanders. But for compatibilitys sake we have to
if (option->state & State_Children) {
if (option->state & State_Open)
QCleanlooksStyle().drawPrimitive(PE_IndicatorArrowDown, option, painter, widget);
else
QCleanlooksStyle().drawPrimitive(PE_IndicatorArrowRight, option, painter, widget);
}
break;
case PE_FrameFocusRect:
// never required with Hildon
break;
case PE_Frame:
if ((qobject_cast<const QTextEdit *>(widget) && !qobject_cast<const QTextBrowser *>(widget)) || qobject_cast<const QPlainTextEdit *>(widget))
proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
else
QGtkStyle::drawPrimitive(element, option, painter, widget);
break;
case PE_PanelLineEdit:
{
int lineWidth = 1;
if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option))
lineWidth = panel->lineWidth;
// For embedded line edits we rely on the parent widget to fill the
// background. The entry_bg is not a uniform color in Hildon
if (lineWidth > 0) {
GtkWidget *gtkEntry = d->gtkWidget("HildonEntry-finger");
uint resolve_mask = option->palette.resolve();
QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
-gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
painter->fillRect(textRect, option->palette.base());
else {
gtkPainter.paintFlatBox(gtkEntry, "entry_bg", textRect,
option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, gtkEntry->style);
}
proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
} else if (option->state & State_Enabled) {
// Note this is a bit of a workaround. Open item editors require us to fill the line
// edit background but doing this will make it impossible to get the correct
// background color for disabled spin box, line edit and combo box.
//
// This would be more elegant if we could either get the correct fill color for
// disabled line edits or if itemview did not draw the item when an editor is open
painter->fillRect(option->rect.adjusted(lineWidth, lineWidth, -lineWidth, -lineWidth),
option->palette.brush(QPalette::Base));
}
}
break;
case PE_FrameLineEdit: {
GtkWidget *gtkEntry = d->gtkWidget("HildonEntry-finger");
gboolean interior_focus;
gint focus_line_width;
gboolean state_hint = false;
QRect rect = option->rect;
gtk_widget_style_get(gtkEntry,
"interior-focus", &interior_focus,
"focus-line-width", &focus_line_width,
"state-hint", &state_hint, NULL);
// See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
if (!interior_focus && option->state & State_HasFocus)
rect.adjust(focus_line_width, focus_line_width, -focus_line_width, -focus_line_width);
if (option->state & State_HasFocus)
GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
gtkPainter.paintShadow(gtkEntry, "entry", rect, option->state & State_Enabled ?
(state_hint && option->state & State_HasFocus ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE,
GTK_SHADOW_IN, gtkEntry->style,
option->state & State_HasFocus ? QLS("focus") : QString());
if (!interior_focus && option->state & State_HasFocus)
gtkPainter.paintShadow(gtkEntry, "entry", option->rect, option->state & State_Enabled ?
GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
GTK_SHADOW_IN, gtkEntry->style, QLS("GtkEntryShadowIn"));
if (option->state & State_HasFocus)
GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
break;
}
case PE_IndicatorCheckBox: {
GtkShadowType shadow = GTK_SHADOW_OUT;
GtkStateType state = qt_gtk_state(option);
if (option->state & State_Sunken)
state = GTK_STATE_ACTIVE;
if (option->state & State_NoChange)
shadow = GTK_SHADOW_ETCHED_IN;
else if (option->state & State_On)
shadow = GTK_SHADOW_IN;
else
shadow = GTK_SHADOW_OUT;
int spacing;
if (GtkWidget *gtkCheckButton = d->gtkWidget("HildonCheckButton-finger")) {
GtkWidget *gtkCellView = d->gtkWidget("HildonCheckButton-finger.GtkAlignment.GtkHBox.GtkCellView");
// Some styles such as aero-clone assume they can paint in the spacing area
gtkPainter.setClipRect(option->rect);
gtk_widget_style_get(gtkCheckButton, "image-spacing", &spacing, NULL);
QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
gtkPainter.paintCheckbox(gtkCellView, checkRect, state, shadow, gtkCellView->style,
QLS("checkbutton"));
}
break;
}
case PE_PanelItemViewRow:
// This primitive is only used to draw selection behind selected expander arrows.
// We try not to decorate the tree branch background unless you inherit from StyledItemDelegate
// The reason for this is that a lot of code that relies on custom item delegates will look odd having
// a gradient on the branch but a flat shaded color on the item itself.
QCommonStyle::drawPrimitive(element, option, painter, widget);
if (!option->state & State_Selected || option->rect.size().isEmpty()) {
break;
} else {
if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget)) {
if (!qobject_cast<QStyledItemDelegate*>(view->itemDelegate()))
break;
}
} // fall through
case PE_PanelItemViewItem: {
//To improve the performance we won't cache unusable states
QStyle::State old_state = option->state;
const_cast<QStyleOption*>(option)->state |= QStyle::State_Active;
const_cast<QStyleOption*>(option)->state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver);
BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("panelitem"));
QGtk2Painter gtkCachedPainter;
gtkCachedPainter.reset(p);
QRect cacheRect(0, 0, option->rect.width(), option->rect.height());
if (GtkWidget *gtkTreeView = d->gtkWidget("HildonPannableArea.GtkTreeView")) {
const char *detail = "cell_odd_ruled";
const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option);
if (vopt && vopt->features & QStyleOptionViewItemV2::Alternate)
detail = "cell_even_ruled";
int rowHeight = 70;
if (GtkWidget *gtkTreeView = d->gtkWidget("HildonPannableArea.GtkTreeView"))
gtk_widget_style_get(gtkTreeView, "row-height", &rowHeight, NULL);
if (option->rect.height() != rowHeight) {
QPixmap scalePix(option->rect.width(), rowHeight);
scalePix.fill(Qt::transparent);
QPainter scalePainter(&scalePix);
QGtk2Painter gtkScalePainter;
gtkScalePainter.reset(&scalePainter);
gtkScalePainter.setUsePixmapCache(false); // cached externally
// the sapwood engine won't scale the image, but instead tile it, which looks ridiculous
gtkScalePainter.paintFlatBox(gtkTreeView, detail, QRect(0, 0, option->rect.width(), rowHeight),
option->state & State_Selected ? GTK_STATE_SELECTED :
option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
GTK_SHADOW_NONE, gtkTreeView->style);
// don't just scale the whole pixmap - the bottom border line would look extremly ugly for big items
int dh = 8; // just an arbitrary value which looks good with the default Maemo styles
p->drawPixmap(cacheRect.topLeft(), scalePix, QRect(0, 0, scalePix.width(), dh));
p->drawPixmap(cacheRect.adjusted(0, dh, 0, -dh), scalePix, QRect(0, dh, scalePix.width(), scalePix.height() - 2 * dh));
p->drawPixmap(cacheRect.bottomLeft() - QPoint(0, dh), scalePix, QRect(0, scalePix.height() - dh, scalePix.width(), dh));
} else {
gtkCachedPainter.paintFlatBox(gtkTreeView, detail, cacheRect,
option->state & State_Selected ? GTK_STATE_SELECTED :
option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
GTK_SHADOW_NONE, gtkTreeView->style);
}
}
END_STYLE_PIXMAPCACHE
const_cast<QStyleOption*>(option)->state = old_state;
break;
}
case PE_Maemo5InformationBox: {
GtkWidget *hildonInformation;
hildonInformation = d->gtkWidget("HildonNote-information-theme");
if(!hildonInformation)
hildonInformation = d->gtkWidget("HildonNote-information-theme-portrait");
if (hildonInformation)
gtkPainter.paintFlatBox(hildonInformation, NULL, option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, hildonInformation->style, QString());
break;
}
case PE_Maemo5AppMenu: {
if (GtkWidget *hildonAppMenu = d->gtkWidget("HildonAppMenu"))
gtkPainter.paintFlatBox(hildonAppMenu, NULL, option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, hildonAppMenu->style, QString());
break;
}
case PE_Maemo5EditBar: {
if (GtkWidget *hildonEditBar = d->gtkWidget("toolbar-edit-mode"))
gtkPainter.paintFlatBox(hildonEditBar, NULL, option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, hildonEditBar->style, QString());
break;
}
case PE_Maemo5EditBarBackButton: {
if (GtkWidget *hildonEditBarBackButton = d->gtkWidget("toolbar-edit-mode.hildon-edit-toolbar-arrow")) {
GtkStateType state = qt_gtk_state(option);
GtkShadowType shadow = GTK_SHADOW_OUT;
if (option->state & State_On || option->state & State_Sunken) {
state = GTK_STATE_ACTIVE;