source: trunk/examples/themes/themes.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1/****************************************************************************
2** $Id: themes.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include "themes.h"
12#include "wood.h"
13#include "metal.h"
14
15#include "../buttongroups/buttongroups.h"
16#include "../lineedits/lineedits.h"
17#include "../listboxcombo/listboxcombo.h"
18#include "../checklists/checklists.h"
19#include "../progressbar/progressbar.h"
20#include "../rangecontrols/rangecontrols.h"
21#include "../richtext/richtext.h"
22
23#include <qtabwidget.h>
24#include <qapplication.h>
25#include <qpopupmenu.h>
26#include <qmenubar.h>
27#include <qmessagebox.h>
28#include <qfont.h>
29#include <qstylefactory.h>
30#include <qaction.h>
31#include <qsignalmapper.h>
32#include <qdict.h>
33
34Themes::Themes( QWidget *parent, const char *name, WFlags f )
35 : QMainWindow( parent, name, f )
36{
37 appFont = QApplication::font();
38 tabwidget = new QTabWidget( this );
39
40 tabwidget->addTab( new ButtonsGroups( tabwidget ), "Buttons/Groups" );
41 QHBox *hbox = new QHBox( tabwidget );
42 hbox->setMargin( 5 );
43 (void)new LineEdits( hbox );
44 (void)new ProgressBar( hbox );
45 tabwidget->addTab( hbox, "Lineedits/Progressbar" );
46 tabwidget->addTab( new ListBoxCombo( tabwidget ), "Listboxes/Comboboxes" );
47 tabwidget->addTab( new CheckLists( tabwidget ), "Listviews" );
48 tabwidget->addTab( new RangeControls( tabwidget ), "Rangecontrols" );
49 tabwidget->addTab( new MyRichText( tabwidget ), "Fortune" );
50
51 setCentralWidget( tabwidget );
52
53 QPopupMenu *style = new QPopupMenu( this );
54 style->setCheckable( TRUE );
55 menuBar()->insertItem( "&Style" , style );
56
57 style->setCheckable( TRUE );
58 QActionGroup *ag = new QActionGroup( this, 0 );
59 ag->setExclusive( TRUE );
60 QSignalMapper *styleMapper = new QSignalMapper( this );
61 connect( styleMapper, SIGNAL( mapped( const QString& ) ), this, SLOT( makeStyle( const QString& ) ) );
62 QStringList list = QStyleFactory::keys();
63 list.sort();
64#ifndef QT_NO_STYLE_WINDOWS
65 list.insert(list.begin(), "Norwegian Wood");
66 list.insert(list.begin(), "Metal");
67#endif
68 QDict<int> stylesDict( 17, FALSE );
69 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
70 QString styleStr = *it;
71 QString styleAccel = styleStr;
72 if ( stylesDict[styleAccel.left(1)] ) {
73 for ( uint i = 0; i < styleAccel.length(); i++ ) {
74 if ( !stylesDict[styleAccel.mid( i, 1 )] ) {
75 stylesDict.insert(styleAccel.mid( i, 1 ), (const int *)1);
76 styleAccel = styleAccel.insert( i, '&' );
77 break;
78 }
79 }
80 } else {
81 stylesDict.insert(styleAccel.left(1), (const int *)1);
82 styleAccel = "&"+styleAccel;
83 }
84 QAction *a = new QAction( styleStr, QIconSet(), styleAccel, 0, ag, 0, ag->isExclusive() );
85 connect( a, SIGNAL( activated() ), styleMapper, SLOT(map()) );
86 styleMapper->setMapping( a, a->text() );
87 }
88 ag->addTo(style);
89 style->insertSeparator();
90 style->insertItem("&Quit", qApp, SLOT( quit() ), CTRL | Key_Q );
91
92 QPopupMenu * help = new QPopupMenu( this );
93 menuBar()->insertSeparator();
94 menuBar()->insertItem( "&Help", help );
95 help->insertItem( "&About", this, SLOT(about()), Key_F1);
96 help->insertItem( "About &Qt", this, SLOT(aboutQt()));
97
98#ifndef QT_NO_STYLE_WINDOWS
99 qApp->setStyle( new NorwegianWoodStyle );
100#endif
101}
102
103void Themes::makeStyle(const QString &style)
104{
105 if(style == "Norwegian Wood") {
106#ifndef QT_NO_STYLE_WINDOWS
107 qApp->setStyle( new NorwegianWoodStyle );
108#endif
109 } else if( style == "Metal" ) {
110#ifndef QT_NO_STYLE_WINDOWS
111 qApp->setStyle( new MetalStyle );
112#endif
113 } else {
114 qApp->setStyle(style);
115 if(style == "Platinum") {
116 QPalette p( QColor( 239, 239, 239 ) );
117 qApp->setPalette( p, TRUE );
118 qApp->setFont( appFont, TRUE );
119 } else if(style == "Windows") {
120 qApp->setFont( appFont, TRUE );
121 } else if(style == "CDE") {
122 QPalette p( QColor( 75, 123, 130 ) );
123 p.setColor( QPalette::Active, QColorGroup::Base, QColor( 55, 77, 78 ) );
124 p.setColor( QPalette::Inactive, QColorGroup::Base, QColor( 55, 77, 78 ) );
125 p.setColor( QPalette::Disabled, QColorGroup::Base, QColor( 55, 77, 78 ) );
126 p.setColor( QPalette::Active, QColorGroup::Highlight, Qt::white );
127 p.setColor( QPalette::Active, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
128 p.setColor( QPalette::Inactive, QColorGroup::Highlight, Qt::white );
129 p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
130 p.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::white );
131 p.setColor( QPalette::Disabled, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
132 p.setColor( QPalette::Active, QColorGroup::Foreground, Qt::white );
133 p.setColor( QPalette::Active, QColorGroup::Text, Qt::white );
134 p.setColor( QPalette::Active, QColorGroup::ButtonText, Qt::white );
135 p.setColor( QPalette::Inactive, QColorGroup::Foreground, Qt::white );
136 p.setColor( QPalette::Inactive, QColorGroup::Text, Qt::white );
137 p.setColor( QPalette::Inactive, QColorGroup::ButtonText, Qt::white );
138 p.setColor( QPalette::Disabled, QColorGroup::Foreground, Qt::lightGray );
139 p.setColor( QPalette::Disabled, QColorGroup::Text, Qt::lightGray );
140 p.setColor( QPalette::Disabled, QColorGroup::ButtonText, Qt::lightGray );
141 qApp->setPalette( p, TRUE );
142 qApp->setFont( QFont( "times", appFont.pointSize() ), TRUE );
143 } else if(style == "Motif" || style == "MotifPlus") {
144 QPalette p( QColor( 192, 192, 192 ) );
145 qApp->setPalette( p, TRUE );
146 qApp->setFont( appFont, TRUE );
147 }
148 }
149}
150
151void Themes::about()
152{
153 QMessageBox::about( this, "Qt Themes Example",
154 "<p>This example demonstrates the concept of "
155 "<b>generalized GUI styles </b> first introduced "
156 " with the 2.0 release of Qt.</p>" );
157}
158
159
160void Themes::aboutQt()
161{
162 QMessageBox::aboutQt( this, "Qt Themes Example" );
163}
164
165
Note: See TracBrowser for help on using the repository browser.