Diffstat (limited to 'noncore/settings/appearance2/sample.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/appearance2/sample.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/appearance2/sample.cpp b/noncore/settings/appearance2/sample.cpp index b3a9d48..f6c4dca 100644 --- a/noncore/settings/appearance2/sample.cpp +++ b/noncore/settings/appearance2/sample.cpp | |||
@@ -1,220 +1,220 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> | 3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> |
4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <qvbox.h> | 29 | #include <qvbox.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qmenubar.h> | 32 | #include <qmenubar.h> |
33 | #include <qcheckbox.h> | 33 | #include <qcheckbox.h> |
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qscrollbar.h> | 35 | #include <qscrollbar.h> |
36 | #include <qlayout.h> | 36 | #include <qlayout.h> |
37 | #include <qwhatsthis.h> | 37 | #include <qwhatsthis.h> |
38 | #include <qpixmapcache.h> | 38 | #include <qpixmapcache.h> |
39 | #include <qtimer.h> | 39 | #include <qtimer.h> |
40 | #include <qobjectlist.h> | 40 | #include <qobjectlist.h> |
41 | #include <qcommonstyle.h> | 41 | #include <qcommonstyle.h> |
42 | 42 | ||
43 | #include "sample.h" | 43 | #include "sample.h" |
44 | 44 | ||
45 | 45 | ||
46 | class SampleText : public QWidget | 46 | class SampleText : public QWidget |
47 | { | 47 | { |
48 | public: | 48 | public: |
49 | SampleText( const QString &t, bool h, QWidget *parent ) | 49 | SampleText( const QString &t, bool h, QWidget *parent ) |
50 | : QWidget( parent ), hl(h), text(t) | 50 | : QWidget( parent ), hl(h), text(t) |
51 | { | 51 | { |
52 | if ( hl ) | 52 | if ( hl ) |
53 | setBackgroundMode( PaletteHighlight ); | 53 | setBackgroundMode( PaletteHighlight ); |
54 | else | 54 | else |
55 | setBackgroundMode( PaletteBase ); | 55 | setBackgroundMode( PaletteBase ); |
56 | } | 56 | } |
57 | 57 | ||
58 | QSize sizeHint() const | 58 | QSize sizeHint() const |
59 | { | 59 | { |
60 | QFontMetrics fm(font()); | 60 | QFontMetrics fm(font()); |
61 | return QSize( fm.width(text)+10, fm.height()+4 ); | 61 | return QSize( fm.width(text)+10, fm.height()+4 ); |
62 | } | 62 | } |
63 | 63 | ||
64 | void paintEvent( QPaintEvent * ) | 64 | void paintEvent( QPaintEvent * ) |
65 | { | 65 | { |
66 | QPainter p(this); | 66 | QPainter p(this); |
67 | if ( hl ) | 67 | if ( hl ) |
68 | p.setPen( colorGroup().highlightedText() ); | 68 | p.setPen( colorGroup().highlightedText() ); |
69 | else | 69 | else |
70 | p.setPen( colorGroup().text() ); | 70 | p.setPen( colorGroup().text() ); |
71 | p.drawText( rect(), AlignCenter, text ); | 71 | p.drawText( rect(), AlignCenter, text ); |
72 | } | 72 | } |
73 | 73 | ||
74 | private: | 74 | private: |
75 | bool hl; | 75 | bool hl; |
76 | QString text; | 76 | QString text; |
77 | }; | 77 | }; |
78 | 78 | ||
79 | 79 | ||
80 | SampleWindow::SampleWindow( QWidget *parent ) : QWidget(parent), iface(0) | 80 | SampleWindow::SampleWindow( QWidget *parent ) : QWidget(parent), iface(0) |
81 | { | 81 | { |
82 | init(); | 82 | init(); |
83 | } | 83 | } |
84 | 84 | ||
85 | QSize SampleWindow::sizeHint() const | 85 | QSize SampleWindow::sizeHint() const |
86 | { | 86 | { |
87 | return container->sizeHint() + QSize( 10, 35 ); | 87 | return container->sizeHint() + QSize( 10, 35 ); |
88 | } | 88 | } |
89 | 89 | ||
90 | void SampleWindow::setFont( const QFont &f ) | 90 | void SampleWindow::setFont( const QFont &f ) |
91 | { | 91 | { |
92 | QWidget::setFont( f ); | 92 | QWidget::setFont( f ); |
93 | popup->setFont( f ); | 93 | popup->setFont( f ); |
94 | QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); | 94 | QTimer::singleShot ( 0, this, SLOT( fixGeometry())); |
95 | } | 95 | } |
96 | 96 | ||
97 | static void setStyleRecursive ( QWidget *w, QStyle *s ) | 97 | static void setStyleRecursive ( QWidget *w, QStyle *s ) |
98 | { | 98 | { |
99 | w->setStyle( s ); | 99 | w->setStyle( s ); |
100 | QObjectList *childObjects=(QObjectList*)w->children(); | 100 | QObjectList *childObjects=(QObjectList*)w->children(); |
101 | if ( childObjects ) { | 101 | if ( childObjects ) { |
102 | QObject * o; | 102 | QObject * o; |
103 | for(o=childObjects->first();o!=0;o=childObjects->next()) { | 103 | for(o=childObjects->first();o!=0;o=childObjects->next()) { |
104 | if( o->isWidgetType() ) { | 104 | if( o->isWidgetType() ) { |
105 | setStyleRecursive((QWidget *)o,s); | 105 | setStyleRecursive((QWidget *)o,s); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | void SampleWindow::setStyle2 ( QStyle *sty, const QPalette &pal ) | 112 | void SampleWindow::setStyle2 ( QStyle *sty, const QPalette &pal ) |
113 | { | 113 | { |
114 | typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool); | 114 | typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool); |
115 | 115 | ||
116 | extern QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl); | 116 | extern QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl); |
117 | 117 | ||
118 | QPixmapCache::clear ( ); | 118 | QPixmapCache::clear ( ); |
119 | QPalette p = pal; // ette ( ); | 119 | QPalette p = pal; // ette ( ); |
120 | sty-> polish ( p ); | 120 | sty-> polish ( p ); |
121 | qt_set_draw_menu_bar_impl ( 0 ); | 121 | qt_set_draw_menu_bar_impl ( 0 ); |
122 | setStyleRecursive ( this, sty ); | 122 | setStyleRecursive ( this, sty ); |
123 | setPalette ( p ); | 123 | setPalette ( p ); |
124 | QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); | 124 | QTimer::singleShot ( 0, this, SLOT( fixGeometry())); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | void SampleWindow::setDecoration( WindowDecorationInterface *i ) | 128 | void SampleWindow::setDecoration( WindowDecorationInterface *i ) |
129 | { | 129 | { |
130 | iface = i; | 130 | iface = i; |
131 | wd.rect = QRect( 0, 0, 150, 75 ); | 131 | wd.rect = QRect( 0, 0, 150, 75 ); |
132 | wd.caption = tr("Sample"); | 132 | wd.caption = tr("Sample"); |
133 | wd.palette = palette(); | 133 | wd.palette = palette(); |
134 | wd.flags = WindowDecorationInterface::WindowData::Dialog | | 134 | wd.flags = WindowDecorationInterface::WindowData::Dialog | |
135 | WindowDecorationInterface::WindowData::Active; | 135 | WindowDecorationInterface::WindowData::Active; |
136 | wd.reserved = 1; | 136 | wd.reserved = 1; |
137 | 137 | ||
138 | th = iface->metric(WindowDecorationInterface::TitleHeight, &wd); | 138 | th = iface->metric(WindowDecorationInterface::TitleHeight, &wd); |
139 | tb = iface->metric(WindowDecorationInterface::TopBorder, &wd); | 139 | tb = iface->metric(WindowDecorationInterface::TopBorder, &wd); |
140 | lb = iface->metric(WindowDecorationInterface::LeftBorder, &wd); | 140 | lb = iface->metric(WindowDecorationInterface::LeftBorder, &wd); |
141 | rb = iface->metric(WindowDecorationInterface::RightBorder, &wd); | 141 | rb = iface->metric(WindowDecorationInterface::RightBorder, &wd); |
142 | bb = iface->metric(WindowDecorationInterface::BottomBorder, &wd); | 142 | bb = iface->metric(WindowDecorationInterface::BottomBorder, &wd); |
143 | 143 | ||
144 | int yoff = th + tb; | 144 | int yoff = th + tb; |
145 | int xoff = lb; | 145 | int xoff = lb; |
146 | 146 | ||
147 | wd.rect.setX( 0 ); | 147 | wd.rect.setX( 0 ); |
148 | wd.rect.setWidth( width() - lb - rb ); | 148 | wd.rect.setWidth( width() - lb - rb ); |
149 | wd.rect.setY( 0 ); | 149 | wd.rect.setY( 0 ); |
150 | wd.rect.setHeight( height() - yoff - bb ); | 150 | wd.rect.setHeight( height() - yoff - bb ); |
151 | 151 | ||
152 | container->setGeometry( xoff, yoff, wd.rect.width(), wd.rect.height() ); | 152 | container->setGeometry( xoff, yoff, wd.rect.width(), wd.rect.height() ); |
153 | setMinimumSize( container->sizeHint().width()+lb+rb, | 153 | setMinimumSize( container->sizeHint().width()+lb+rb, |
154 | container->sizeHint().height()+tb+th+bb ); | 154 | container->sizeHint().height()+tb+th+bb ); |
155 | } | 155 | } |
156 | 156 | ||
157 | void SampleWindow::paintEvent( QPaintEvent * ) | 157 | void SampleWindow::paintEvent( QPaintEvent * ) |
158 | { | 158 | { |
159 | if ( !iface ) | 159 | if ( !iface ) |
160 | return; | 160 | return; |
161 | 161 | ||
162 | QPainter p( this ); | 162 | QPainter p( this ); |
163 | 163 | ||
164 | p.translate( lb, th+tb ); | 164 | p.translate( lb, th+tb ); |
165 | 165 | ||
166 | iface->drawArea(WindowDecorationInterface::Border, &p, &wd); | 166 | iface->drawArea(WindowDecorationInterface::Border, &p, &wd); |
167 | iface->drawArea(WindowDecorationInterface::Title, &p, &wd); | 167 | iface->drawArea(WindowDecorationInterface::Title, &p, &wd); |
168 | 168 | ||
169 | p.setPen(palette().active().color(QColorGroup::HighlightedText)); | 169 | p.setPen(palette().active().color(QColorGroup::HighlightedText)); |
170 | QFont f( font() ); | 170 | QFont f( font() ); |
171 | f.setWeight( QFont::Bold ); | 171 | f.setWeight( QFont::Bold ); |
172 | p.setFont(f); | 172 | p.setFont(f); |
173 | iface->drawArea(WindowDecorationInterface::TitleText, &p, &wd); | 173 | iface->drawArea(WindowDecorationInterface::TitleText, &p, &wd); |
174 | 174 | ||
175 | QRect brect( 0, -th, iface->metric(WindowDecorationInterface::HelpWidth,&wd), th ); | 175 | QRect brect( 0, -th, iface->metric(WindowDecorationInterface::HelpWidth,&wd), th ); |
176 | iface->drawButton( WindowDecorationInterface::Help, &p, &wd, | 176 | iface->drawButton( WindowDecorationInterface::Help, &p, &wd, |
177 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | 177 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); |
178 | brect.moveBy( wd.rect.width() - | 178 | brect.moveBy( wd.rect.width() - |
179 | iface->metric(WindowDecorationInterface::OKWidth,&wd) - | 179 | iface->metric(WindowDecorationInterface::OKWidth,&wd) - |
180 | iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); | 180 | iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); |
181 | iface->drawButton( WindowDecorationInterface::Close, &p, &wd, | 181 | iface->drawButton( WindowDecorationInterface::Close, &p, &wd, |
182 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | 182 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); |
183 | brect.moveBy( iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); | 183 | brect.moveBy( iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); |
184 | iface->drawButton( WindowDecorationInterface::OK, &p, &wd, | 184 | iface->drawButton( WindowDecorationInterface::OK, &p, &wd, |
185 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | 185 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); |
186 | } | 186 | } |
187 | 187 | ||
188 | void SampleWindow::init() | 188 | void SampleWindow::init() |
189 | { | 189 | { |
190 | container = new QVBox( this ); | 190 | container = new QVBox( this ); |
191 | popup = new QPopupMenu( this ); | 191 | popup = new QPopupMenu( this ); |
192 | popup->insertItem( tr("Normal Item"), 1 ); | 192 | popup->insertItem( tr("Normal Item"), 1 ); |
193 | popup->insertItem( tr("Disabled Item"), 2 ); | 193 | popup->insertItem( tr("Disabled Item"), 2 ); |
194 | popup->setItemEnabled(2, FALSE); | 194 | popup->setItemEnabled(2, FALSE); |
195 | QMenuBar *mb = new QMenuBar( container ); | 195 | QMenuBar *mb = new QMenuBar( container ); |
196 | mb->insertItem( tr("Menu"), popup ); | 196 | mb->insertItem( tr("Menu"), popup ); |
197 | QHBox *hb = new QHBox( container ); | 197 | QHBox *hb = new QHBox( container ); |
198 | QWidget *w = new QWidget( hb ); | 198 | QWidget *w = new QWidget( hb ); |
199 | (void)new QScrollBar( 0, 0, 0, 0, 0, Vertical, hb ); | 199 | (void)new QScrollBar( 0, 0, 0, 0, 0, Vertical, hb ); |
200 | 200 | ||
201 | QGridLayout *gl = new QGridLayout( w, 2, 2, 4 ); | 201 | QGridLayout *gl = new QGridLayout( w, 2, 2, 4 ); |
202 | SampleText *l = new SampleText( tr("Normal Text"), FALSE, w ); | 202 | SampleText *l = new SampleText( tr("Normal Text"), FALSE, w ); |
203 | gl->addWidget( l, 0, 0 ); | 203 | gl->addWidget( l, 0, 0 ); |
204 | 204 | ||
205 | l = new SampleText( tr("Highlighted Text"), TRUE, w ); | 205 | l = new SampleText( tr("Highlighted Text"), TRUE, w ); |
206 | gl->addWidget( l, 1, 0 ); | 206 | gl->addWidget( l, 1, 0 ); |
207 | 207 | ||
208 | QPushButton *pb = new QPushButton( tr("Button"), w ); | 208 | QPushButton *pb = new QPushButton( tr("Button"), w ); |
209 | gl->addWidget( pb, 0, 1 ); | 209 | gl->addWidget( pb, 0, 1 ); |
210 | pb->setFocusPolicy( NoFocus ); | 210 | pb->setFocusPolicy( NoFocus ); |
211 | 211 | ||
212 | QCheckBox *cb = new QCheckBox( tr("Check Box"), w ); | 212 | QCheckBox *cb = new QCheckBox( tr("Check Box"), w ); |
213 | gl->addWidget( cb, 1, 1 ); | 213 | gl->addWidget( cb, 1, 1 ); |
214 | cb->setFocusPolicy( NoFocus ); | 214 | cb->setFocusPolicy( NoFocus ); |
215 | cb->setChecked( TRUE ); | 215 | cb->setChecked( TRUE ); |
216 | 216 | ||
217 | QWhatsThis::add( this, tr("Sample window using the selected settings.") ); | 217 | QWhatsThis::add( this, tr("Sample window using the selected settings.") ); |
218 | } | 218 | } |
219 | 219 | ||
220 | bool SampleWindow::eventFilter( QObject *, QEvent *e ) | 220 | bool SampleWindow::eventFilter( QObject *, QEvent *e ) |