Diffstat (limited to 'core/settings/launcher/tabdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/launcher/tabdialog.cpp | 381 |
1 files changed, 381 insertions, 0 deletions
diff --git a/core/settings/launcher/tabdialog.cpp b/core/settings/launcher/tabdialog.cpp new file mode 100644 index 0000000..7b01cc7 --- a/dev/null +++ b/core/settings/launcher/tabdialog.cpp | |||
@@ -0,0 +1,381 @@ | |||
1 | |||
2 | #include <qpe/resource.h> | ||
3 | #include <qpe/config.h> | ||
4 | |||
5 | #include <qlayout.h> | ||
6 | #include <qvbox.h> | ||
7 | #include <qtabbar.h> | ||
8 | #include <qiconview.h> | ||
9 | #include <qapplication.h> | ||
10 | #include <qlabel.h> | ||
11 | #include <qradiobutton.h> | ||
12 | #include <qbuttongroup.h> | ||
13 | |||
14 | #include <opie/ofontselector.h> | ||
15 | #include <opie/otabwidget.h> | ||
16 | #include <opie/ocolorbutton.h> | ||
17 | |||
18 | #include "tabdialog.h" | ||
19 | |||
20 | |||
21 | class SampleItem : public QIconViewItem { | ||
22 | public: | ||
23 | SampleItem ( QIconView *v, const QString &text, const QPixmap &pix ) : QIconViewItem ( v, text ) | ||
24 | { | ||
25 | m_large = pix; | ||
26 | m_small. convertFromImage ( pix. convertToImage ( ). smoothScale ( pix. width ( ) / 2, pix. height ( ) / 2 )); | ||
27 | } | ||
28 | |||
29 | void sizeChange ( ) | ||
30 | { | ||
31 | calcRect ( ); | ||
32 | repaint ( ); | ||
33 | } | ||
34 | |||
35 | QPixmap *pixmap ( ) const | ||
36 | { | ||
37 | if ( iconView ( )-> itemTextPos ( ) == QIconView::Right ) | ||
38 | return (QPixmap *) &m_small; | ||
39 | else | ||
40 | return (QPixmap *) &m_large; | ||
41 | } | ||
42 | private: | ||
43 | QPixmap m_large, m_small; | ||
44 | }; | ||
45 | |||
46 | class SampleView : public QIconView { | ||
47 | public: | ||
48 | SampleView ( QWidget *parent = 0, const char *name = 0 ) : QIconView ( parent, name ) | ||
49 | { | ||
50 | setItemsMovable ( false ); | ||
51 | setAutoArrange ( true ); | ||
52 | setSorting ( true ); | ||
53 | setFrameStyle ( QFrame::NoFrame ); | ||
54 | setSpacing ( 4 ); | ||
55 | setMargin ( 0 ); | ||
56 | setSelectionMode ( QIconView::NoSelection ); | ||
57 | setBackgroundMode ( PaletteBase ); | ||
58 | setViewMode ( TabConfig::Icon ); | ||
59 | calculateGrid ( Bottom ); | ||
60 | |||
61 | |||
62 | new SampleItem ( this, tr( "Sample 1" ), Resource::loadPixmap ( "DateBook" )); | ||
63 | new SampleItem ( this, tr( "Sample 2" ), Resource::loadPixmap ( "Calibrate" )); | ||
64 | new SampleItem ( this, tr( "Sample 3" ), Resource::loadPixmap ( "UnknownDocument" )); | ||
65 | |||
66 | setBackgroundType ( TabConfig::Ruled, QString::null ); | ||
67 | |||
68 | setMaximumHeight ( firstItem ( )-> height ( ) + 16 ); | ||
69 | } | ||
70 | |||
71 | void setViewMode ( TabConfig::ViewMode m ) | ||
72 | { | ||
73 | viewport ( )-> setUpdatesEnabled ( false ); | ||
74 | |||
75 | switch ( m ) { | ||
76 | case TabConfig::List: | ||
77 | setItemTextPos( QIconView::Right ); | ||
78 | break; | ||
79 | case TabConfig::Icon: | ||
80 | setItemTextPos( QIconView::Bottom ); | ||
81 | break; | ||
82 | } | ||
83 | // hideOrShowItems ( false ); | ||
84 | |||
85 | for ( QIconViewItem *it = firstItem ( ); it; it = it-> nextItem ( )) | ||
86 | ((SampleItem *) it )-> sizeChange ( ); | ||
87 | arrangeItemsInGrid ( true ); | ||
88 | viewport ( )-> setUpdatesEnabled ( true ); | ||
89 | update ( ); | ||
90 | } | ||
91 | |||
92 | |||
93 | void setBackgroundType( TabConfig::BackgroundType t, const QString &val ) | ||
94 | { | ||
95 | switch ( t ) { | ||
96 | case TabConfig::Ruled: { | ||
97 | QPixmap bg ( width ( ), 9 ); | ||
98 | QPainter painter ( &bg ); | ||
99 | for ( int i = 0; i < 3; i++ ) { | ||
100 | painter. setPen ( white ); | ||
101 | painter. drawLine ( 0, i*3, width()-1, i*3 ); | ||
102 | painter. drawLine ( 0, i*3+1, width()-1, i*3+1 ); | ||
103 | painter. setPen ( colorGroup().background().light(105) ); | ||
104 | painter. drawLine ( 0, i*3+2, width()-1, i*3+2 ); | ||
105 | } | ||
106 | painter.end ( ); | ||
107 | setBackgroundPixmap ( bg ); | ||
108 | break; | ||
109 | } | ||
110 | |||
111 | case TabConfig::SolidColor: { | ||
112 | setBackgroundPixmap ( QPixmap ( )); | ||
113 | if ( val. isEmpty ( )) | ||
114 | setBackgroundColor ( colorGroup ( ). base ( )); | ||
115 | else | ||
116 | setBackgroundColor ( val ); | ||
117 | break; | ||
118 | } | ||
119 | |||
120 | case TabConfig::Image: { | ||
121 | qDebug( "Loading image: %s", val.latin1() ); | ||
122 | QPixmap bg ( Resource::loadPixmap ( "wallpaper/" + val )); | ||
123 | if ( bg. isNull ( )) { | ||
124 | QImageIO imgio; | ||
125 | imgio. setFileName ( val ); | ||
126 | QSize ds = qApp-> desktop ( )-> size ( ); | ||
127 | QString param ( "Scale( %1, %2, ScaleMin )" ); // No tr | ||
128 | imgio. setParameters ( param. arg ( ds. width ( )). arg ( ds. height ( )). latin1 ( )); | ||
129 | imgio. read ( ); | ||
130 | bg = imgio. image ( ); | ||
131 | } | ||
132 | setBackgroundPixmap ( bg ); | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | m_bgtype = t; | ||
137 | viewport ( )-> update ( ); | ||
138 | } | ||
139 | |||
140 | void setTextColor ( const QColor &tc ) | ||
141 | { | ||
142 | m_textcolor = tc; | ||
143 | QColorGroup cg = colorGroup ( ); | ||
144 | cg. setColor ( QColorGroup::Text, tc ); | ||
145 | setPalette ( QPalette ( cg, cg, cg )); | ||
146 | viewport ( )-> update ( ); | ||
147 | } | ||
148 | |||
149 | void setViewFont ( const QFont &f ) | ||
150 | { | ||
151 | setFont ( f ); | ||
152 | } | ||
153 | |||
154 | void setItemTextPos ( ItemTextPos pos ) | ||
155 | { | ||
156 | calculateGrid ( pos ); | ||
157 | QIconView::setItemTextPos( pos ); | ||
158 | } | ||
159 | |||
160 | void calculateGrid ( ItemTextPos pos ) | ||
161 | { | ||
162 | int dw = QApplication::desktop ( )-> width ( ); | ||
163 | int viewerWidth = dw - style ( ).scrollBarExtent ( ). width ( ); | ||
164 | if ( pos == Bottom ) { | ||
165 | int cols = 3; | ||
166 | if ( viewerWidth <= 200 ) | ||
167 | cols = 2; | ||
168 | else if ( viewerWidth >= 400 ) | ||
169 | cols = viewerWidth/96; | ||
170 | setSpacing ( 4 ); | ||
171 | setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); | ||
172 | setGridY ( fontMetrics ( ). height ( ) * 2 + 24 ); | ||
173 | } | ||
174 | else { | ||
175 | int cols = 2; | ||
176 | if ( viewerWidth < 150 ) | ||
177 | cols = 1; | ||
178 | else if ( viewerWidth >= 400 ) | ||
179 | cols = viewerWidth / 150; | ||
180 | setSpacing ( 2 ); | ||
181 | setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); | ||
182 | setGridY ( fontMetrics ( ). height ( ) + 2 ); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | void paletteChange( const QPalette &p ) | ||
187 | { | ||
188 | unsetPalette ( ); | ||
189 | QIconView::paletteChange ( p ); | ||
190 | if ( m_bgtype == TabConfig::Ruled ) | ||
191 | setBackgroundType ( TabConfig::Ruled, QString::null ); | ||
192 | QColorGroup cg = colorGroup ( ); | ||
193 | cg.setColor ( QColorGroup::Text, m_textcolor ); | ||
194 | setPalette ( QPalette ( cg, cg, cg )); | ||
195 | } | ||
196 | |||
197 | void setBackgroundPixmap ( const QPixmap &pm ) | ||
198 | { | ||
199 | m_bgpix = pm; | ||
200 | } | ||
201 | |||
202 | void setBackgroundColor ( const QColor &c ) | ||
203 | { | ||
204 | m_bgcolor = c; | ||
205 | } | ||
206 | |||
207 | void drawBackground ( QPainter *p, const QRect &r ) | ||
208 | { | ||
209 | if ( !m_bgpix. isNull ( )) { | ||
210 | p-> drawTiledPixmap ( r, m_bgpix, QPoint (( r. x ( ) + contentsX ( )) % m_bgpix. width ( ), | ||
211 | ( r. y ( ) + contentsY ( )) % m_bgpix. height ( ))); | ||
212 | } | ||
213 | else | ||
214 | p-> fillRect ( r, m_bgcolor ); | ||
215 | } | ||
216 | |||
217 | private: | ||
218 | QColor m_textcolor; | ||
219 | QColor m_bgcolor; | ||
220 | QPixmap m_bgpix; | ||
221 | TabConfig::BackgroundType m_bgtype; | ||
222 | }; | ||
223 | |||
224 | |||
225 | |||
226 | TabDialog::TabDialog ( const QPixmap *tabicon, const QString &tabname, TabConfig &tc, QWidget *parent, const char *name, bool modal, WFlags fl ) | ||
227 | : QDialog ( parent, name, modal, fl ) | ||
228 | { | ||
229 | setCaption ( tr( "Edit Tab" )); | ||
230 | |||
231 | QVBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); | ||
232 | |||
233 | OTabWidget *tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom ); | ||
234 | QWidget *bgtab; | ||
235 | |||
236 | tw-> addTab ( bgtab = createBgTab ( tw ), "appearance/backgroundtabicon.png", tr( "Background" )); | ||
237 | tw-> addTab ( createFontTab ( tw ), "appearance/fonttabicon.png", tr( "Font" )); | ||
238 | tw-> addTab ( createIconTab ( tw ), "appearance/colorstabicon.png", tr( "Icons" ) ); | ||
239 | |||
240 | tw-> setCurrentTab ( bgtab ); | ||
241 | |||
242 | QWidget *sample = new QVBox ( this ); | ||
243 | QTabBar *tb = new QTabBar ( sample ); | ||
244 | QString name ( tr( "Previewing %1" ). arg ( tabname )); | ||
245 | |||
246 | tb-> addTab ( tabicon ? new QTab ( *tabicon, name ) : new QTab ( name )); | ||
247 | |||
248 | m_sample = new SampleView ( sample ); | ||
249 | |||
250 | lay-> addWidget ( tw, 10 ); | ||
251 | lay-> addWidget ( sample, 1 ); | ||
252 | } | ||
253 | |||
254 | |||
255 | TabDialog::~TabDialog ( ) | ||
256 | { | ||
257 | } | ||
258 | |||
259 | QWidget *TabDialog::createFontTab ( QWidget *parent ) | ||
260 | { | ||
261 | Config config ( "qpe" ); | ||
262 | config. setGroup ( "Appearance" ); | ||
263 | |||
264 | QString familyStr = config.readEntry( "FontFamily", "Helvetica" ); | ||
265 | QString styleStr = config.readEntry( "FontStyle", "Regular" ); | ||
266 | int size = config.readNumEntry( "FontSize", 10 ); | ||
267 | |||
268 | m_fontselect = new OFontSelector ( parent, "FontTab" ); | ||
269 | m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); | ||
270 | |||
271 | connect( m_fontselect, SIGNAL( fontSelected ( const QFont & )), | ||
272 | this, SLOT( fontClicked ( const QFont & ))); | ||
273 | |||
274 | return m_fontselect; | ||
275 | } | ||
276 | |||
277 | QWidget *TabDialog::createBgTab ( QWidget *parent ) | ||
278 | { | ||
279 | QWidget *tab = new QWidget( parent, "AdvancedTab" ); | ||
280 | QVBoxLayout *vertLayout = new QVBoxLayout( tab, 4, 4 ); | ||
281 | |||
282 | QGridLayout* gridLayout = new QGridLayout ( vertLayout ); | ||
283 | gridLayout-> setColStretch ( 1, 10 ); | ||
284 | |||
285 | QLabel* label = new QLabel( tr( "Type:" ), tab ); | ||
286 | gridLayout-> addWidget ( label, 0, 0 ); | ||
287 | m_bgtype = new QButtonGroup( tab, "buttongroup" ); | ||
288 | m_bgtype-> hide ( ); | ||
289 | m_bgtype-> setExclusive ( true ); | ||
290 | |||
291 | QRadioButton *rb; | ||
292 | rb = new QRadioButton( tr( "Ruled" ), tab, "ruled" ); | ||
293 | m_bgtype-> insert ( rb, TabConfig::Ruled ); | ||
294 | gridLayout-> addWidget( rb, 0, 1 ); | ||
295 | |||
296 | QHBoxLayout *hb = new QHBoxLayout ( ); | ||
297 | hb-> setSpacing ( 4 ); | ||
298 | |||
299 | rb = new QRadioButton( tr( "Solid color" ), tab, "solid" ); | ||
300 | m_bgtype-> insert ( rb, TabConfig::SolidColor ); | ||
301 | hb-> addWidget ( rb ); | ||
302 | |||
303 | m_solidcolor = new OColorButton ( tab ); | ||
304 | connect ( m_solidcolor, SIGNAL( colorSelected ( const QColor & )), this, SLOT( colorClicked ( const QColor & ))); | ||
305 | hb-> addWidget ( m_solidcolor ); | ||
306 | hb-> addStretch ( 10 ); | ||
307 | |||
308 | gridLayout-> addLayout ( hb, 1, 1 ); | ||
309 | |||
310 | rb = new QRadioButton( tr( "Image" ), tab, "image" ); | ||
311 | m_bgtype-> insert ( rb, TabConfig::Image ); | ||
312 | gridLayout-> addWidget( rb, 3, 1 ); | ||
313 | |||
314 | QPushButton *p; | ||
315 | |||
316 | connect ( m_bgtype, SIGNAL( clicked ( int )), this, SLOT( bgTypeClicked ( int ))); | ||
317 | |||
318 | vertLayout-> addStretch ( 10 ); | ||
319 | |||
320 | return tab; | ||
321 | } | ||
322 | |||
323 | QWidget *TabDialog::createIconTab ( QWidget *parent ) | ||
324 | { | ||
325 | QWidget *tab = new QWidget( parent, "AdvancedTab" ); | ||
326 | QVBoxLayout *vertLayout = new QVBoxLayout( tab, 4, 4 ); | ||
327 | |||
328 | QGridLayout* gridLayout = new QGridLayout ( vertLayout ); | ||
329 | gridLayout-> setColStretch ( 1, 10 ); | ||
330 | |||
331 | QLabel* label = new QLabel( tr( "Size:" ), tab ); | ||
332 | gridLayout-> addWidget ( label, 0, 0 ); | ||
333 | m_iconsize = new QButtonGroup( tab, "buttongroup" ); | ||
334 | m_iconsize-> hide ( ); | ||
335 | m_iconsize-> setExclusive ( true ); | ||
336 | |||
337 | QRadioButton *rb; | ||
338 | rb = new QRadioButton( tr( "Small" ), tab, "iconsmall" ); | ||
339 | m_iconsize-> insert ( rb, TabConfig::List ); | ||
340 | gridLayout-> addWidget( rb, 0, 1 ); | ||
341 | |||
342 | rb = new QRadioButton( tr( "Large" ), tab, "iconlarge" ); | ||
343 | m_iconsize-> insert ( rb, TabConfig::Icon ); | ||
344 | gridLayout-> addWidget( rb, 1, 1 ); | ||
345 | |||
346 | connect ( m_iconsize, SIGNAL( clicked ( int )), this, SLOT( iconSizeClicked ( int ))); | ||
347 | |||
348 | vertLayout-> addStretch ( 10 ); | ||
349 | |||
350 | return tab; | ||
351 | } | ||
352 | |||
353 | |||
354 | void TabDialog::iconSizeClicked ( int s ) | ||
355 | { | ||
356 | m_sample-> setViewMode ((TabConfig::ViewMode) s ); | ||
357 | } | ||
358 | |||
359 | void TabDialog::fontClicked ( const QFont &f ) | ||
360 | { | ||
361 | m_sample-> setViewFont ( f ); | ||
362 | } | ||
363 | |||
364 | void TabDialog::bgTypeClicked ( int t ) | ||
365 | { | ||
366 | QString s; | ||
367 | |||
368 | m_solidcolor-> setEnabled ( t == TabConfig::SolidColor ); | ||
369 | //m_imagebrowse-> setEnabled ( t == TabConfig::Image ); | ||
370 | //m_imagedefault-> setEnabled ( t == TabConfig::Image ); | ||
371 | |||
372 | if ( t == TabConfig::SolidColor ) | ||
373 | s = m_solidcolor-> color ( ). name ( ); | ||
374 | |||
375 | m_sample-> setBackgroundType ((TabConfig::BackgroundType) t, s ); | ||
376 | } | ||
377 | |||
378 | void TabDialog::colorClicked ( const QColor &col ) | ||
379 | { | ||
380 | m_sample-> setBackgroundType ( TabConfig::SolidColor, col. name ( )); | ||
381 | } | ||