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
|
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "themes.h"
#include "wood.h"
#include "metal.h"
#include "../buttongroups/buttongroups.h"
#include "../lineedits/lineedits.h"
#include "../listboxcombo/listboxcombo.h"
#include "../checklists/checklists.h"
#include "../progressbar/progressbar.h"
#include "../rangecontrols/rangecontrols.h"
#include "../richtext/richtext.h"
#include <qtabwidget.h>
#include <qapplication.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qfont.h>
#include <qstylefactory.h>
#include <qaction.h>
#include <qsignalmapper.h>
#include <qdict.h>
Themes::Themes( QWidget *parent, const char *name, WFlags f )
: QMainWindow( parent, name, f )
{
appFont = QApplication::font();
tabwidget = new QTabWidget( this );
tabwidget->addTab( new ButtonsGroups( tabwidget ), "Buttons/Groups" );
QHBox *hbox = new QHBox( tabwidget );
hbox->setMargin( 5 );
(void)new LineEdits( hbox );
(void)new ProgressBar( hbox );
tabwidget->addTab( hbox, "Lineedits/Progressbar" );
tabwidget->addTab( new ListBoxCombo( tabwidget ), "Listboxes/Comboboxes" );
tabwidget->addTab( new CheckLists( tabwidget ), "Listviews" );
tabwidget->addTab( new RangeControls( tabwidget ), "Rangecontrols" );
tabwidget->addTab( new MyRichText( tabwidget ), "Fortune" );
setCentralWidget( tabwidget );
QPopupMenu *style = new QPopupMenu( this );
style->setCheckable( TRUE );
menuBar()->insertItem( "&Style" , style );
style->setCheckable( TRUE );
QActionGroup *ag = new QActionGroup( this, 0 );
ag->setExclusive( TRUE );
QSignalMapper *styleMapper = new QSignalMapper( this );
connect( styleMapper, SIGNAL( mapped( const QString& ) ), this, SLOT( makeStyle( const QString& ) ) );
QStringList list = QStyleFactory::keys();
list.sort();
#ifndef QT_NO_STYLE_WINDOWS
list.insert(list.begin(), "Norwegian Wood");
list.insert(list.begin(), "Metal");
#endif
QDict<int> stylesDict( 17, FALSE );
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
QString styleStr = *it;
QString styleAccel = styleStr;
if ( stylesDict[styleAccel.left(1)] ) {
for ( uint i = 0; i < styleAccel.length(); i++ ) {
if ( !stylesDict[styleAccel.mid( i, 1 )] ) {
stylesDict.insert(styleAccel.mid( i, 1 ), (const int *)1);
styleAccel = styleAccel.insert( i, '&' );
break;
}
}
} else {
stylesDict.insert(styleAccel.left(1), (const int *)1);
styleAccel = "&"+styleAccel;
}
QAction *a = new QAction( styleStr, QIconSet(), styleAccel, 0, ag, 0, ag->isExclusive() );
connect( a, SIGNAL( activated() ), styleMapper, SLOT(map()) );
styleMapper->setMapping( a, a->text() );
}
ag->addTo(style);
style->insertSeparator();
style->insertItem("&Quit", qApp, SLOT( quit() ), CTRL | Key_Q );
QPopupMenu * help = new QPopupMenu( this );
menuBar()->insertSeparator();
menuBar()->insertItem( "&Help", help );
help->insertItem( "&About", this, SLOT(about()), Key_F1);
help->insertItem( "About &Qt", this, SLOT(aboutQt()));
#ifndef QT_NO_STYLE_WINDOWS
qApp->setStyle( new NorwegianWoodStyle );
#endif
}
void Themes::makeStyle(const QString &style)
{
if(style == "Norwegian Wood") {
#ifndef QT_NO_STYLE_WINDOWS
qApp->setStyle( new NorwegianWoodStyle );
#endif
} else if( style == "Metal" ) {
#ifndef QT_NO_STYLE_WINDOWS
qApp->setStyle( new MetalStyle );
#endif
} else {
qApp->setStyle(style);
if(style == "Platinum") {
QPalette p( QColor( 239, 239, 239 ) );
qApp->setPalette( p, TRUE );
qApp->setFont( appFont, TRUE );
} else if(style == "Windows") {
qApp->setFont( appFont, TRUE );
} else if(style == "CDE") {
QPalette p( QColor( 75, 123, 130 ) );
p.setColor( QPalette::Active, QColorGroup::Base, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Inactive, QColorGroup::Base, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Disabled, QColorGroup::Base, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Active, QColorGroup::Highlight, Qt::white );
p.setColor( QPalette::Active, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Inactive, QColorGroup::Highlight, Qt::white );
p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::white );
p.setColor( QPalette::Disabled, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
p.setColor( QPalette::Active, QColorGroup::Foreground, Qt::white );
p.setColor( QPalette::Active, QColorGroup::Text, Qt::white );
p.setColor( QPalette::Active, QColorGroup::ButtonText, Qt::white );
p.setColor( QPalette::Inactive, QColorGroup::Foreground, Qt::white );
p.setColor( QPalette::Inactive, QColorGroup::Text, Qt::white );
p.setColor( QPalette::Inactive, QColorGroup::ButtonText, Qt::white );
p.setColor( QPalette::Disabled, QColorGroup::Foreground, Qt::lightGray );
p.setColor( QPalette::Disabled, QColorGroup::Text, Qt::lightGray );
p.setColor( QPalette::Disabled, QColorGroup::ButtonText, Qt::lightGray );
qApp->setPalette( p, TRUE );
qApp->setFont( QFont( "times", appFont.pointSize() ), TRUE );
} else if(style == "Motif" || style == "MotifPlus") {
QPalette p( QColor( 192, 192, 192 ) );
qApp->setPalette( p, TRUE );
qApp->setFont( appFont, TRUE );
}
}
}
void Themes::about()
{
QMessageBox::about( this, "Qt Themes Example",
"<p>This example demonstrates the concept of "
"<b>generalized GUI styles </b> first introduced "
" with the 2.0 release of Qt.</p>" );
}
void Themes::aboutQt()
{
QMessageBox::aboutQt( this, "Qt Themes Example" );
}
|