summaryrefslogtreecommitdiff
path: root/core/settings/launcher/tabdialog.cpp
Unidiff
Diffstat (limited to 'core/settings/launcher/tabdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/launcher/tabdialog.cpp121
1 files changed, 111 insertions, 10 deletions
diff --git a/core/settings/launcher/tabdialog.cpp b/core/settings/launcher/tabdialog.cpp
index ca48e66..86202f0 100644
--- a/core/settings/launcher/tabdialog.cpp
+++ b/core/settings/launcher/tabdialog.cpp
@@ -1,53 +1,83 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
25
26*/
1 27
2#include <qpe/resource.h> 28#include <qpe/resource.h>
3#include <qpe/config.h> 29#include <qpe/config.h>
30#include <qpe/applnk.h>
4 31
5#include <qlayout.h> 32#include <qlayout.h>
6#include <qvbox.h> 33#include <qvbox.h>
7#include <qtabbar.h> 34#include <qtabbar.h>
8#include <qiconview.h> 35#include <qiconview.h>
9#include <qapplication.h> 36#include <qapplication.h>
10#include <qlabel.h> 37#include <qlabel.h>
11#include <qradiobutton.h> 38#include <qradiobutton.h>
12#include <qbuttongroup.h> 39#include <qbuttongroup.h>
40#include <qpushbutton.h>
13 41
14#include <opie/ofontselector.h> 42#include <opie/ofontselector.h>
15#include <opie/otabwidget.h> 43#include <opie/otabwidget.h>
16#include <opie/ocolorbutton.h> 44#include <opie/ocolorbutton.h>
45#include <opie/ofiledialog.h>
17 46
18#include "tabdialog.h" 47#include "tabdialog.h"
19 48
20 49
21class SampleItem : public QIconViewItem { 50class SampleItem : public QIconViewItem {
22public: 51public:
23 SampleItem ( QIconView *v, const QString &text, const QPixmap &pix ) : QIconViewItem ( v, text ) 52 SampleItem ( QIconView *v, const QString &text, const QPixmap &pix ) : QIconViewItem ( v, text )
24 { 53 {
25 m_large = pix; 54 m_large = pix;
26 m_small. convertFromImage ( pix. convertToImage ( ). smoothScale ( pix. width ( ) / 2, pix. height ( ) / 2 )); 55 m_small. convertFromImage ( pix. convertToImage ( ). smoothScale ( pix. width ( ) / 2, pix. height ( ) / 2 ));
27 } 56 }
28 57
29 void sizeChange ( ) 58 void sizeChange ( )
30 { 59 {
31 calcRect ( ); 60 calcRect ( );
32 repaint ( ); 61 repaint ( );
33 } 62 }
34 63
35 QPixmap *pixmap ( ) const 64 QPixmap *pixmap ( ) const
36 { 65 {
37 if ( iconView ( )-> itemTextPos ( ) == QIconView::Right ) 66 if ( iconView ( )-> itemTextPos ( ) == QIconView::Right )
38 return (QPixmap *) &m_small; 67 return (QPixmap *) &m_small;
39 else 68 else
40 return (QPixmap *) &m_large; 69 return (QPixmap *) &m_large;
41 } 70 }
71
42private: 72private:
43 QPixmap m_large, m_small; 73 QPixmap m_large, m_small;
44}; 74};
45 75
46class SampleView : public QIconView { 76class SampleView : public QIconView {
47public: 77public:
48 SampleView ( QWidget *parent = 0, const char *name = 0 ) : QIconView ( parent, name ) 78 SampleView ( QWidget *parent = 0, const char *name = 0 ) : QIconView ( parent, name )
49 { 79 {
50 setItemsMovable ( false ); 80 setItemsMovable ( false );
51 setAutoArrange ( true ); 81 setAutoArrange ( true );
52 setSorting ( true ); 82 setSorting ( true );
53 setFrameStyle ( QFrame::NoFrame ); 83 setFrameStyle ( QFrame::NoFrame );
@@ -176,52 +206,60 @@ public:
176 if ( viewerWidth < 150 ) 206 if ( viewerWidth < 150 )
177 cols = 1; 207 cols = 1;
178 else if ( viewerWidth >= 400 ) 208 else if ( viewerWidth >= 400 )
179 cols = viewerWidth / 150; 209 cols = viewerWidth / 150;
180 setSpacing ( 2 ); 210 setSpacing ( 2 );
181 setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); 211 setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols );
182 setGridY ( fontMetrics ( ). height ( ) + 2 ); 212 setGridY ( fontMetrics ( ). height ( ) + 2 );
183 } 213 }
184 } 214 }
185 215
186 void paletteChange( const QPalette &p ) 216 void paletteChange( const QPalette &p )
187 { 217 {
218 static bool excllock = false;
219
220 if ( excllock )
221 return;
222 excllock = true;
223
188 unsetPalette ( ); 224 unsetPalette ( );
189 QIconView::paletteChange ( p ); 225 QIconView::paletteChange ( p );
190 if ( m_bgtype == TabConfig::Ruled ) 226 if ( m_bgtype == TabConfig::Ruled )
191 setBackgroundType ( TabConfig::Ruled, QString::null ); 227 setBackgroundType ( TabConfig::Ruled, QString::null );
192 QColorGroup cg = colorGroup ( ); 228 QColorGroup cg = colorGroup ( );
193 cg.setColor ( QColorGroup::Text, m_textcolor ); 229 cg.setColor ( QColorGroup::Text, m_textcolor );
194 setPalette ( QPalette ( cg, cg, cg )); 230 setPalette ( QPalette ( cg, cg, cg ));
231
232 excllock = false;
195 } 233 }
196 234
197 void setBackgroundPixmap ( const QPixmap &pm ) 235 void setBackgroundPixmap ( const QPixmap &pm )
198 { 236 {
199 m_bgpix = pm; 237 m_bgpix = pm;
200 } 238 }
201 239
202 void setBackgroundColor ( const QColor &c ) 240 void setBackgroundColor ( const QColor &c )
203 { 241 {
204 m_bgcolor = c; 242 m_bgcolor = c;
205 } 243 }
206 244
207 void drawBackground ( QPainter *p, const QRect &r ) 245 void drawBackground ( QPainter *p, const QRect &r )
208 { 246 {
209 if ( !m_bgpix. isNull ( )) { 247 if ( !m_bgpix. isNull ( )) {
210 p-> drawTiledPixmap ( r, m_bgpix, QPoint (( r. x ( ) + contentsX ( )) % m_bgpix. width ( ), 248 p-> drawTiledPixmap ( r, m_bgpix, QPoint (( r. x ( ) + contentsX ( )) % m_bgpix. width ( ),
211 ( r. y ( ) + contentsY ( )) % m_bgpix. height ( ))); 249 ( r. y ( ) + contentsY ( )) % m_bgpix. height ( )));
212 } 250 }
213 else 251 else
214 p-> fillRect ( r, m_bgcolor ); 252 p-> fillRect ( r, m_bgcolor );
215 } 253 }
216 254
217private: 255private:
218 QColor m_textcolor; 256 QColor m_textcolor;
219 QColor m_bgcolor; 257 QColor m_bgcolor;
220 QPixmap m_bgpix; 258 QPixmap m_bgpix;
221 TabConfig::BackgroundType m_bgtype; 259 TabConfig::BackgroundType m_bgtype;
222}; 260};
223 261
224 262
225 263
226TabDialog::TabDialog ( const QPixmap *tabicon, const QString &tabname, TabConfig &tc, QWidget *parent, const char *name, bool modal, WFlags fl ) 264TabDialog::TabDialog ( const QPixmap *tabicon, const QString &tabname, TabConfig &tc, QWidget *parent, const char *name, bool modal, WFlags fl )
227 : QDialog ( parent, name, modal, fl ), m_tc ( tc ) 265 : QDialog ( parent, name, modal, fl ), m_tc ( tc )
@@ -243,26 +281,29 @@ TabDialog::TabDialog ( const QPixmap *tabicon, const QString &tabname, TabConfig
243 QTabBar *tb = new QTabBar ( sample ); 281 QTabBar *tb = new QTabBar ( sample );
244 QString name ( tr( "Previewing %1" ). arg ( tabname )); 282 QString name ( tr( "Previewing %1" ). arg ( tabname ));
245 283
246 tb-> addTab ( tabicon ? new QTab ( *tabicon, name ) : new QTab ( name )); 284 tb-> addTab ( tabicon ? new QTab ( *tabicon, name ) : new QTab ( name ));
247 285
248 m_sample = new SampleView ( sample ); 286 m_sample = new SampleView ( sample );
249 287
250 lay-> addWidget ( tw, 10 ); 288 lay-> addWidget ( tw, 10 );
251 lay-> addWidget ( sample, 1 ); 289 lay-> addWidget ( sample, 1 );
252 290
253 m_iconsize-> setButton ( tc. m_view ); 291 m_iconsize-> setButton ( tc. m_view );
254 iconSizeClicked ( tc. m_view ); 292 iconSizeClicked ( tc. m_view );
293 m_iconcolor-> setColor ( QColor ( m_tc. m_text_color ));
294 iconColorClicked ( m_iconcolor-> color ( ));
255 m_bgtype-> setButton ( tc. m_bg_type ); 295 m_bgtype-> setButton ( tc. m_bg_type );
256 m_solidcolor-> setColor ( QColor ( tc. m_bg_color )); 296 m_solidcolor-> setColor ( QColor ( tc. m_bg_color ));
297 m_bgimage = tc. m_bg_image;
257 bgTypeClicked ( tc. m_bg_type ); 298 bgTypeClicked ( tc. m_bg_type );
258 m_fontselect-> setSelectedFont ( tc. m_font_family, tc. m_font_style, tc. m_font_size ); 299 m_fontselect-> setSelectedFont ( tc. m_font_family, tc. m_font_style, tc. m_font_size );
259 fontClicked ( m_fontselect-> selectedFont ( )); 300 fontClicked ( m_fontselect-> selectedFont ( ));
260} 301}
261 302
262 303
263TabDialog::~TabDialog ( ) 304TabDialog::~TabDialog ( )
264{ 305{
265} 306}
266 307
267QWidget *TabDialog::createFontTab ( QWidget *parent ) 308QWidget *TabDialog::createFontTab ( QWidget *parent )
268{ 309{
@@ -293,34 +334,48 @@ QWidget *TabDialog::createBgTab ( QWidget *parent )
293 m_bgtype-> insert ( rb, TabConfig::Ruled ); 334 m_bgtype-> insert ( rb, TabConfig::Ruled );
294 gridLayout-> addWidget( rb, 0, 1 ); 335 gridLayout-> addWidget( rb, 0, 1 );
295 336
296 QHBoxLayout *hb = new QHBoxLayout ( ); 337 QHBoxLayout *hb = new QHBoxLayout ( );
297 hb-> setSpacing ( 4 ); 338 hb-> setSpacing ( 4 );
298 339
299 rb = new QRadioButton( tr( "Solid color" ), tab, "solid" ); 340 rb = new QRadioButton( tr( "Solid color" ), tab, "solid" );
300 m_bgtype-> insert ( rb, TabConfig::SolidColor ); 341 m_bgtype-> insert ( rb, TabConfig::SolidColor );
301 hb-> addWidget ( rb ); 342 hb-> addWidget ( rb );
302 hb-> addSpacing ( 10 ); 343 hb-> addSpacing ( 10 );
303 344
304 m_solidcolor = new OColorButton ( tab ); 345 m_solidcolor = new OColorButton ( tab );
305 connect ( m_solidcolor, SIGNAL( colorSelected ( const QColor & )), this, SLOT( colorClicked ( const QColor & ))); 346 connect ( m_solidcolor, SIGNAL( colorSelected ( const QColor & )), this, SLOT( bgColorClicked ( const QColor & )));
306 hb-> addWidget ( m_solidcolor ); 347 hb-> addWidget ( m_solidcolor );
348 hb-> addStretch ( 10 );
307 349
308 gridLayout-> addLayout ( hb, 1, 1 ); 350 gridLayout-> addLayout ( hb, 1, 1 );
309 351
310 rb = new QRadioButton( tr( "Image" ), tab, "image" ); 352 hb = new QHBoxLayout ( );
353 hb-> setSpacing ( 4 );
354
355 rb = new QRadioButton( tr( "Image" ), tab, "image" );
311 m_bgtype-> insert ( rb, TabConfig::Image ); 356 m_bgtype-> insert ( rb, TabConfig::Image );
312 gridLayout-> addWidget( rb, 3, 1 ); 357 hb-> addWidget( rb );
358 hb-> addSpacing ( 10 );
359
360 m_imagebrowse = new QPushButton ( tr( "Select..." ), tab );
361 connect ( m_imagebrowse, SIGNAL( clicked ( )), this, SLOT( bgImageClicked ( )));
362 hb-> addWidget ( m_imagebrowse );
363 hb-> addStretch ( 10 );
364
365 gridLayout-> addLayout ( hb, 2, 1 );
313 366
314 //QPushButton *p; 367 QPushButton *p = new QPushButton ( tr( "Default" ), tab );
368 connect ( p, SIGNAL( clicked ( )), this, SLOT( bgDefaultClicked ( )));
369 gridLayout-> addWidget ( p, 3, 1 );
315 370
316 connect ( m_bgtype, SIGNAL( clicked ( int )), this, SLOT( bgTypeClicked ( int ))); 371 connect ( m_bgtype, SIGNAL( clicked ( int )), this, SLOT( bgTypeClicked ( int )));
317 372
318 vertLayout-> addStretch ( 10 ); 373 vertLayout-> addStretch ( 10 );
319 374
320 return tab; 375 return tab;
321} 376}
322 377
323QWidget *TabDialog::createIconTab ( QWidget *parent ) 378QWidget *TabDialog::createIconTab ( QWidget *parent )
324{ 379{
325 QWidget *tab = new QWidget( parent, "AdvancedTab" ); 380 QWidget *tab = new QWidget( parent, "AdvancedTab" );
326 QVBoxLayout *vertLayout = new QVBoxLayout( tab, 4, 4 ); 381 QVBoxLayout *vertLayout = new QVBoxLayout( tab, 4, 4 );
@@ -336,58 +391,104 @@ QWidget *TabDialog::createIconTab ( QWidget *parent )
336 391
337 QRadioButton *rb; 392 QRadioButton *rb;
338 rb = new QRadioButton( tr( "Small" ), tab, "iconsmall" ); 393 rb = new QRadioButton( tr( "Small" ), tab, "iconsmall" );
339 m_iconsize-> insert ( rb, TabConfig::List ); 394 m_iconsize-> insert ( rb, TabConfig::List );
340 gridLayout-> addWidget( rb, 0, 1 ); 395 gridLayout-> addWidget( rb, 0, 1 );
341 396
342 rb = new QRadioButton( tr( "Large" ), tab, "iconlarge" ); 397 rb = new QRadioButton( tr( "Large" ), tab, "iconlarge" );
343 m_iconsize-> insert ( rb, TabConfig::Icon ); 398 m_iconsize-> insert ( rb, TabConfig::Icon );
344 gridLayout-> addWidget( rb, 1, 1 ); 399 gridLayout-> addWidget( rb, 1, 1 );
345 400
346 connect ( m_iconsize, SIGNAL( clicked ( int )), this, SLOT( iconSizeClicked ( int ))); 401 connect ( m_iconsize, SIGNAL( clicked ( int )), this, SLOT( iconSizeClicked ( int )));
347 402
403 //vertLayout-> addSpacing ( 8 );
404
405 //gridLayout = new QGridLayout ( vertLayout );
406 gridLayout-> addRowSpacing ( 2, 8 );
407
408 label = new QLabel ( tr( "Color:" ), tab );
409 gridLayout-> addWidget ( label, 3, 0 );
410
411 m_iconcolor = new OColorButton ( tab );
412 connect ( m_iconcolor, SIGNAL( colorSelected ( const QColor & )), this, SLOT( iconColorClicked ( const QColor & )));
413 gridLayout-> addWidget ( m_iconcolor, 3, 1, AlignLeft );
414
348 vertLayout-> addStretch ( 10 ); 415 vertLayout-> addStretch ( 10 );
349 416
350 return tab; 417 return tab;
351} 418}
352 419
353 420
354void TabDialog::iconSizeClicked ( int s ) 421void TabDialog::iconSizeClicked ( int s )
355{ 422{
356 m_sample-> setViewMode ((TabConfig::ViewMode) s ); 423 m_sample-> setViewMode ((TabConfig::ViewMode) s );
357} 424}
358 425
359void TabDialog::fontClicked ( const QFont &f ) 426void TabDialog::fontClicked ( const QFont &f )
360{ 427{
361 m_sample-> setViewFont ( f ); 428 m_sample-> setViewFont ( f );
362} 429}
363 430
364void TabDialog::bgTypeClicked ( int t ) 431void TabDialog::bgTypeClicked ( int t )
365{ 432{
366 QString s; 433 QString s;
367 434
435 if ( m_bgtype-> id ( m_bgtype-> selected ( )) != t )
436 m_bgtype-> setButton ( t );
437
368 m_solidcolor-> setEnabled ( t == TabConfig::SolidColor ); 438 m_solidcolor-> setEnabled ( t == TabConfig::SolidColor );
369 //m_imagebrowse-> setEnabled ( t == TabConfig::Image ); 439 m_imagebrowse-> setEnabled ( t == TabConfig::Image );
370 //m_imagedefault-> setEnabled ( t == TabConfig::Image );
371 440
372 if ( t == TabConfig::SolidColor ) 441 if ( t == TabConfig::SolidColor )
373 s = m_solidcolor-> color ( ). name ( ); 442 s = m_solidcolor-> color ( ). name ( );
443 else if ( t == TabConfig::Image )
444 s = m_bgimage;
374 445
375 m_sample-> setBackgroundType ((TabConfig::BackgroundType) t, s ); 446 m_sample-> setBackgroundType ((TabConfig::BackgroundType) t, s );
376} 447}
377 448
378void TabDialog::colorClicked ( const QColor &col ) 449void TabDialog::bgColorClicked ( const QColor & )
450{
451 bgTypeClicked ( TabConfig::SolidColor );
452}
453
454void TabDialog::iconColorClicked ( const QColor &col )
455{
456 m_sample-> setTextColor ( col );
457}
458
459void TabDialog::bgImageClicked ( )
460{
461 // ### use OFileSelector here ###
462 // this is just a quick c&p from the old appearance app
463
464 MimeTypes types;
465 QStringList list;
466 list << "image/*";
467 types. insert ( "Images", list );
468
469 QString file = OFileDialog::getOpenFileName ( 1, "/", QString::null, types );
470 if ( !file. isEmpty ( )) {
471 m_bgimage = DocLnk ( file ). file ( );
472 bgTypeClicked ( TabConfig::Image );
473 }
474}
475
476void TabDialog::bgDefaultClicked ( )
379{ 477{
380 m_sample-> setBackgroundType ( TabConfig::SolidColor, col. name ( )); 478 m_bgimage = Resource::findPixmap ( "launcher/opie-background.jpg" );
479 bgTypeClicked ( TabConfig::Image );
381} 480}
382 481
383void TabDialog::accept ( ) 482void TabDialog::accept ( )
384{ 483{
385 m_tc. m_view = (TabConfig::ViewMode) m_iconsize-> id ( m_iconsize-> selected ( )); 484 m_tc. m_view = (TabConfig::ViewMode) m_iconsize-> id ( m_iconsize-> selected ( ));
386 m_tc. m_bg_type = (TabConfig::BackgroundType) m_bgtype-> id ( m_bgtype-> selected ( )); 485 m_tc. m_bg_type = (TabConfig::BackgroundType) m_bgtype-> id ( m_bgtype-> selected ( ));
387 m_tc. m_bg_color = m_solidcolor-> color ( ). name ( ); 486 m_tc. m_bg_color = m_solidcolor-> color ( ). name ( );
487 m_tc. m_bg_image = m_bgimage;
488 m_tc. m_text_color = m_iconcolor-> color ( ). name ( );
388 m_tc. m_font_family = m_fontselect-> fontFamily ( ); 489 m_tc. m_font_family = m_fontselect-> fontFamily ( );
389 m_tc. m_font_size = m_fontselect-> fontSize ( ); 490 m_tc. m_font_size = m_fontselect-> fontSize ( );
390 m_tc. m_font_style = m_fontselect-> fontStyle ( ); 491 m_tc. m_font_style = m_fontselect-> fontStyle ( );
391 492
392 QDialog::accept ( ); 493 QDialog::accept ( );
393} 494}