author | sandman <sandman> | 2002-09-20 01:42:10 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-20 01:42:10 (UTC) |
commit | b1f3d33cb0b3f203f153074a8812d5988c3031b2 (patch) (unidiff) | |
tree | 1734ac2808dab8f0982b23a2a9101486fcdcfee5 /noncore/settings/appearance2/sample.cpp | |
parent | 9204c61f669fb265f6c5f14bfd6ca363a2929e40 (diff) | |
download | opie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.zip opie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.tar.gz opie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.tar.bz2 |
New experimental appearance settings
Diffstat (limited to 'noncore/settings/appearance2/sample.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/appearance2/sample.cpp | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/noncore/settings/appearance2/sample.cpp b/noncore/settings/appearance2/sample.cpp new file mode 100644 index 0000000..ee27d60 --- a/dev/null +++ b/noncore/settings/appearance2/sample.cpp | |||
@@ -0,0 +1,236 @@ | |||
1 | #include <qvbox.h> | ||
2 | #include <qpopupmenu.h> | ||
3 | #include <qpainter.h> | ||
4 | #include <qmenubar.h> | ||
5 | #include <qcheckbox.h> | ||
6 | #include <qpushbutton.h> | ||
7 | #include <qscrollbar.h> | ||
8 | #include <qlayout.h> | ||
9 | #include <qwhatsthis.h> | ||
10 | #include <qpixmapcache.h> | ||
11 | #include <qtimer.h> | ||
12 | #include <qobjectlist.h> | ||
13 | |||
14 | #include "sample.h" | ||
15 | |||
16 | |||
17 | class SampleText : public QWidget | ||
18 | { | ||
19 | public: | ||
20 | SampleText( const QString &t, bool h, QWidget *parent ) | ||
21 | : QWidget( parent ), hl(h), text(t) | ||
22 | { | ||
23 | if ( hl ) | ||
24 | setBackgroundMode( PaletteHighlight ); | ||
25 | else | ||
26 | setBackgroundMode( PaletteBase ); | ||
27 | } | ||
28 | |||
29 | QSize sizeHint() const | ||
30 | { | ||
31 | QFontMetrics fm(font()); | ||
32 | return QSize( fm.width(text)+10, fm.height()+4 ); | ||
33 | } | ||
34 | |||
35 | void paintEvent( QPaintEvent * ) | ||
36 | { | ||
37 | QPainter p(this); | ||
38 | if ( hl ) | ||
39 | p.setPen( colorGroup().highlightedText() ); | ||
40 | else | ||
41 | p.setPen( colorGroup().text() ); | ||
42 | p.drawText( rect(), AlignCenter, text ); | ||
43 | } | ||
44 | |||
45 | private: | ||
46 | bool hl; | ||
47 | QString text; | ||
48 | }; | ||
49 | |||
50 | |||
51 | SampleWindow::SampleWindow( QWidget *parent ) : QWidget(parent), iface(0) | ||
52 | { | ||
53 | init(); | ||
54 | } | ||
55 | |||
56 | QSize SampleWindow::sizeHint() const | ||
57 | { | ||
58 | return container->sizeHint() + QSize( 10, 35 ); | ||
59 | } | ||
60 | |||
61 | void SampleWindow::setFont( const QFont &f ) | ||
62 | { | ||
63 | QWidget::setFont( f ); | ||
64 | popup->setFont( f ); | ||
65 | QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); | ||
66 | } | ||
67 | |||
68 | static void setStyleRecursive ( QWidget *w, QStyle *s ) | ||
69 | { | ||
70 | QObjectList *childObjects=(QObjectList*)w->children(); | ||
71 | if ( childObjects ) { | ||
72 | QObject * o; | ||
73 | for(o=childObjects->first();o!=0;o=childObjects->next()) { | ||
74 | if( o->isWidgetType() ) { | ||
75 | setStyleRecursive((QWidget *)o,s); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | w->setStyle( s ); | ||
80 | } | ||
81 | |||
82 | |||
83 | void SampleWindow::setStyle2 ( QStyle *sty ) | ||
84 | { | ||
85 | QPixmapCache::clear ( ); | ||
86 | QPalette p = palette ( ); | ||
87 | sty-> polish ( p ); | ||
88 | setStyleRecursive ( this, sty ); | ||
89 | QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); | ||
90 | } | ||
91 | |||
92 | |||
93 | void SampleWindow::setDecoration( WindowDecorationInterface *i ) | ||
94 | { | ||
95 | iface = i; | ||
96 | wd.rect = QRect( 0, 0, 150, 75 ); | ||
97 | wd.caption = tr("Sample"); | ||
98 | wd.palette = palette(); | ||
99 | wd.flags = WindowDecorationInterface::WindowData::Dialog | | ||
100 | WindowDecorationInterface::WindowData::Active; | ||
101 | wd.reserved = 1; | ||
102 | |||
103 | th = iface->metric(WindowDecorationInterface::TitleHeight, &wd); | ||
104 | tb = iface->metric(WindowDecorationInterface::TopBorder, &wd); | ||
105 | lb = iface->metric(WindowDecorationInterface::LeftBorder, &wd); | ||
106 | rb = iface->metric(WindowDecorationInterface::RightBorder, &wd); | ||
107 | bb = iface->metric(WindowDecorationInterface::BottomBorder, &wd); | ||
108 | |||
109 | int yoff = th + tb; | ||
110 | int xoff = lb; | ||
111 | |||
112 | wd.rect.setX( 0 ); | ||
113 | wd.rect.setWidth( width() - lb - rb ); | ||
114 | wd.rect.setY( 0 ); | ||
115 | wd.rect.setHeight( height() - yoff - bb ); | ||
116 | |||
117 | container->setGeometry( xoff, yoff, wd.rect.width(), wd.rect.height() ); | ||
118 | setMinimumSize( container->sizeHint().width()+lb+rb, | ||
119 | container->sizeHint().height()+tb+th+bb ); | ||
120 | } | ||
121 | |||
122 | void SampleWindow::paintEvent( QPaintEvent * ) | ||
123 | { | ||
124 | if ( !iface ) | ||
125 | return; | ||
126 | |||
127 | QPainter p( this ); | ||
128 | |||
129 | p.translate( lb, th+tb ); | ||
130 | |||
131 | iface->drawArea(WindowDecorationInterface::Border, &p, &wd); | ||
132 | iface->drawArea(WindowDecorationInterface::Title, &p, &wd); | ||
133 | |||
134 | p.setPen(palette().active().color(QColorGroup::HighlightedText)); | ||
135 | QFont f( font() ); | ||
136 | f.setWeight( QFont::Bold ); | ||
137 | p.setFont(f); | ||
138 | iface->drawArea(WindowDecorationInterface::TitleText, &p, &wd); | ||
139 | |||
140 | QRect brect( 0, -th, iface->metric(WindowDecorationInterface::HelpWidth,&wd), th ); | ||
141 | iface->drawButton( WindowDecorationInterface::Help, &p, &wd, | ||
142 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | ||
143 | brect.moveBy( wd.rect.width() - | ||
144 | iface->metric(WindowDecorationInterface::OKWidth,&wd) - | ||
145 | iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); | ||
146 | iface->drawButton( WindowDecorationInterface::Close, &p, &wd, | ||
147 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | ||
148 | brect.moveBy( iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 ); | ||
149 | iface->drawButton( WindowDecorationInterface::OK, &p, &wd, | ||
150 | brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 ); | ||
151 | } | ||
152 | |||
153 | void SampleWindow::init() | ||
154 | { | ||
155 | container = new QVBox( this ); | ||
156 | popup = new QPopupMenu( this ); | ||
157 | popup->insertItem( tr("Normal Item"), 1 ); | ||
158 | popup->insertItem( tr("Disabled Item"), 2 ); | ||
159 | popup->setItemEnabled(2, FALSE); | ||
160 | QMenuBar *mb = new QMenuBar( container ); | ||
161 | mb->insertItem( tr("Menu"), popup ); | ||
162 | QHBox *hb = new QHBox( container ); | ||
163 | QWidget *w = new QWidget( hb ); | ||
164 | (void)new QScrollBar( 0, 0, 0, 0, 0, Vertical, hb ); | ||
165 | |||
166 | QGridLayout *gl = new QGridLayout( w, 2, 2, 4 ); | ||
167 | SampleText *l = new SampleText( tr("Normal Text"), FALSE, w ); | ||
168 | gl->addWidget( l, 0, 0 ); | ||
169 | |||
170 | l = new SampleText( tr("Highlighted Text"), TRUE, w ); | ||
171 | gl->addWidget( l, 1, 0 ); | ||
172 | |||
173 | QPushButton *pb = new QPushButton( tr("Button"), w ); | ||
174 | gl->addWidget( pb, 0, 1 ); | ||
175 | pb->setFocusPolicy( NoFocus ); | ||
176 | |||
177 | QCheckBox *cb = new QCheckBox( tr("Check Box"), w ); | ||
178 | gl->addWidget( cb, 1, 1 ); | ||
179 | cb->setFocusPolicy( NoFocus ); | ||
180 | cb->setChecked( TRUE ); | ||
181 | |||
182 | QWhatsThis::add( this, tr("Sample window using the selected settings.") ); | ||
183 | } | ||
184 | |||
185 | bool SampleWindow::eventFilter( QObject *, QEvent *e ) | ||
186 | { | ||
187 | switch ( e->type() ) { | ||
188 | case QEvent::MouseButtonPress: | ||
189 | case QEvent::MouseButtonRelease: | ||
190 | case QEvent::MouseButtonDblClick: | ||
191 | case QEvent::MouseMove: | ||
192 | case QEvent::KeyPress: | ||
193 | case QEvent::KeyRelease: | ||
194 | return TRUE; | ||
195 | default: | ||
196 | break; | ||
197 | } | ||
198 | |||
199 | return FALSE; | ||
200 | } | ||
201 | |||
202 | void SampleWindow::paletteChange( const QPalette &old ) | ||
203 | { | ||
204 | QWidget::paletteChange ( old ); | ||
205 | wd. palette = palette ( ); | ||
206 | popup-> setPalette ( palette ( )); | ||
207 | } | ||
208 | |||
209 | void SampleWindow::setPalette ( const QPalette &pal ) | ||
210 | { | ||
211 | QPixmapCache::clear ( ); | ||
212 | QPalette p = pal; | ||
213 | style ( ). polish ( p ); | ||
214 | |||
215 | QWidget::setPalette ( p ); | ||
216 | } | ||
217 | |||
218 | void SampleWindow::resizeEvent( QResizeEvent *re ) | ||
219 | { | ||
220 | wd.rect = QRect( 0, 0, 150, 75 ); | ||
221 | |||
222 | wd.rect.setX( 0 ); | ||
223 | wd.rect.setWidth( width() - lb - rb ); | ||
224 | wd.rect.setY( 0 ); | ||
225 | wd.rect.setHeight( height() - th - tb - bb ); | ||
226 | |||
227 | container->setGeometry( lb, th+tb, wd.rect.width(), wd.rect.height() ); | ||
228 | QWidget::resizeEvent( re ); | ||
229 | } | ||
230 | |||
231 | void SampleWindow::fixGeometry() | ||
232 | { | ||
233 | setMinimumSize( container->sizeHint().width()+lb+rb, | ||
234 | container->sizeHint().height()+tb+th+bb ); | ||
235 | } | ||
236 | |||