Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

appearance.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (c)  2002 Trolltech AS <info@trolltech.com>
00005                              Copyright (c)  2002 Dan Williams <drw@handhelds.org>
00006                              Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
00007               =.
00008             .=l.
00009            .>+-=
00010  _;:,     .>    :=|.         This program is free software; you can
00011 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00012 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00013 .="- .-=="i,     .._         License as published by the Free Software
00014  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00015      ._= =}       :          or (at your option) any later version.
00016     .%`+i>       _;_.
00017     .i_,=:_.      -<s.       This program is distributed in the hope that
00018      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00019     : ..    .:,     . . .    without even the implied warranty of
00020     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00021   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00022 ..}^=.=       =       ;      Library General Public License for more
00023 ++=   -.     .`     .:       details.
00024 :     =  ...= . :.=-
00025  -.   .:....=;==+<;          You should have received a copy of the GNU
00026   -_. . .   )=.  =           Library General Public License along with
00027     --        :-=`           this library; see the file COPYING.LIB.
00028                              If not, write to the Free Software Foundation,
00029                              Inc., 59 Temple Place - Suite 330,
00030                              Boston, MA 02111-1307, USA.
00031 */
00032 
00033 #include "appearance.h"
00034 #include "editScheme.h"
00035 #include "stylelistitem.h"
00036 #include "decolistitem.h"
00037 #include "colorlistitem.h"
00038 #include "exceptlistitem.h"
00039 #include "sample.h"
00040 
00041 /* OPIE */
00042 #include <opie2/odevice.h>
00043 #include <opie2/ofiledialog.h>
00044 #include <opie2/otabwidget.h>
00045 #include <opie2/odebug.h>
00046 
00047 #include <qpe/config.h>
00048 #include <qpe/global.h>
00049 #include <qpe/qpeapplication.h>
00050 #include <qpe/qpemessagebox.h>
00051 #include <qpe/qcopenvelope_qws.h>
00052 #include <qpe/qpestyle.h>
00053 #include <qpe/lightstyle.h>
00054 #include <qpe/styleinterface.h>
00055 
00056 /* QT */
00057 #include <qbuttongroup.h>
00058 #include <qcheckbox.h>
00059 #include <qcombobox.h>
00060 #include <qdialog.h>
00061 #include <qdir.h>
00062 #include <qlabel.h>
00063 #include <qlayout.h>
00064 #include <qlineedit.h>
00065 #include <qlistbox.h>
00066 #include <qmessagebox.h>
00067 #include <qpushbutton.h>
00068 #include <qradiobutton.h>
00069 #if QT_VERSION >= 0x030000
00070 #include <qstylefactory.h>
00071 #endif
00072 #include <qtoolbutton.h>
00073 #include <qwindowsstyle.h>
00074 #include <qlistview.h>
00075 #include <qheader.h>
00076 #include <qvbox.h>
00077 #include <qwhatsthis.h>
00078 
00079 using namespace Opie;
00080 using namespace Opie::Ui;
00081 using namespace Opie::Core;
00082 
00083 class DefaultWindowDecoration : public WindowDecorationInterface
00084 {
00085 public:
00086     DefaultWindowDecoration() : ref(0) {}
00087     QString name() const
00088     {
00089         return "Default";
00090     }
00091     QPixmap icon() const
00092     {
00093         return QPixmap();
00094     }
00095     QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00096     {
00097         *iface = 0;
00098         if ( uuid == IID_QUnknown )
00099             *iface = this;
00100         else if ( uuid == IID_WindowDecoration )
00101             *iface = this;
00102 
00103         if ( *iface )
00104             (*iface)->addRef();
00105         return QS_OK;
00106     }
00107     Q_REFCOUNT
00108 
00109 private:
00110     ulong ref;
00111 };
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 QWidget *Appearance::createStyleTab ( QWidget *parent, Config &cfg )
00120 {
00121     QWidget* tab = new QWidget( parent, "StyleTab" );
00122     QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
00123 
00124     m_style_list = new QListBox( tab, "m_style_list" );
00125     vertLayout->addWidget( m_style_list );
00126     QWhatsThis::add( m_style_list, tr( "Styles control the way items such as buttons and scroll bars appear in all applications.\n\nClick here to select an available style." ) );
00127 
00128     m_style_settings = new QPushButton ( tr( "Settings..." ), tab );
00129     connect ( m_style_settings, SIGNAL( clicked()), this, SLOT( styleSettingsClicked()));
00130     vertLayout-> addWidget ( m_style_settings );
00131     QWhatsThis::add( m_style_settings, tr( "Click here to configure the currently selected style.\n\nNote:  This option is not available for all styles." ) );
00132 
00133     QString s = cfg. readEntry ( "Style", "Light" );
00134 
00135 
00136 #if QT_VERSION >= 0x030000
00137     m_style_list->insertStringList(QStyleFactory::styles());
00138 #else
00139     m_style_list-> insertItem ( new StyleListItem ( "Windows", new QWindowsStyle ( )));
00140     m_style_list-> insertItem ( new StyleListItem ( "Light", new LightStyle ( )));
00141     m_style_list-> insertItem ( new StyleListItem ( "QPE", new QPEStyle ( )));
00142 #endif
00143 
00144     {
00145         QString path = QPEApplication::qpeDir ( );
00146         path.append( "/plugins/styles/" );
00147         QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
00148 
00149         for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
00150         {
00151             QString libstr = path;
00152             libstr.append( "/" );
00153             libstr.append( *it );
00154             QLibrary *lib = new QLibrary ( libstr );
00155             StyleInterface *iface;
00156 
00157             if (( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK ) && iface )
00158             {
00159                 StyleListItem *slit = new StyleListItem ( lib, iface );
00160                 m_style_list-> insertItem ( slit );
00161 
00162                 if ( slit-> key ( ) == s )
00163                     m_style_list-> setCurrentItem ( slit );
00164             }
00165             else
00166                 delete lib;
00167         }
00168     }
00169 
00170     m_original_style = m_style_list-> currentItem ( );
00171     styleClicked ( m_original_style );
00172 
00173     connect( m_style_list, SIGNAL( highlighted(int) ), this, SLOT( styleClicked(int) ) );
00174 
00175     return tab;
00176 }
00177 
00178 QWidget *Appearance::createDecoTab ( QWidget *parent, Config &cfg )
00179 {
00180     QWidget* tab = new QWidget( parent, "DecoTab" );
00181     QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
00182 
00183     m_deco_list = new QListBox( tab, "m_deco_list" );
00184     vertLayout->addWidget( m_deco_list );
00185     QWhatsThis::add( m_deco_list, tr( "Window decorations control the way the application title bar and its buttons appear.\n\nClick here to select an available decoration." ) );
00186 
00187     QString s = cfg. readEntry ( "Decoration", "libflat.so" );
00188 
00189     m_deco_list-> insertItem ( new DecoListItem ( "QPE" ));
00190 
00191     {
00192         QString path = QPEApplication::qpeDir();
00193         path.append( "/plugins/decorations/" );
00194         QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
00195 
00196         for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
00197         {
00198             QString libstr = path;
00199             libstr.append( "/" );
00200             libstr.append( *it );
00201             QLibrary *lib = new QLibrary ( libstr );
00202             WindowDecorationInterface *iface;
00203 
00204             if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK )
00205             {
00206                 DecoListItem *dlit = new DecoListItem ( lib, iface );
00207                 m_deco_list-> insertItem ( dlit );
00208 
00209                 if ( dlit-> key ( ) == s )
00210                     m_deco_list-> setCurrentItem ( dlit );
00211             }
00212             else
00213                 delete lib;
00214         }
00215     }
00216 
00217     m_original_deco = m_deco_list-> currentItem ( );
00218     if ( m_deco_list-> currentItem  ( ) < 0 )
00219         m_deco_list-> setCurrentItem ( 0 );
00220     decoClicked ( m_original_deco );
00221 
00222     connect( m_deco_list, SIGNAL( highlighted(int) ), this, SLOT( decoClicked(int) ) );
00223 
00224     return tab;
00225 }
00226 
00227 QWidget *Appearance::createFontTab ( QWidget *parent, Config &cfg )
00228 {
00229     QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" );
00230     QString styleStr = cfg. readEntry ( "FontStyle", "Regular" );
00231     int size = cfg. readNumEntry ( "FontSize", 10 );
00232 
00233     m_fontselect = new OFontSelector ( false, parent, "FontTab" );
00234     m_fontselect-> setSelectedFont ( familyStr, styleStr, size );
00235     QWhatsThis::add( m_fontselect, tr( "Select the desired name, style and size of the default font applications will use." ) );
00236 
00237     connect( m_fontselect, SIGNAL( fontSelected(const QFont&)),
00238              this, SLOT( fontClicked(const QFont&)));
00239 
00240     return m_fontselect;
00241 }
00242 
00243 QWidget *Appearance::createColorTab ( QWidget *parent, Config &cfg )
00244 {
00245     QWidget *tab = new QWidget( parent, "ColorTab" );
00246     QGridLayout *gridLayout = new QGridLayout( tab, 0, 0, 3, 3 );
00247     gridLayout->setRowStretch ( 3, 10 );
00248 
00249     m_color_list = new QListBox ( tab );
00250     gridLayout->addMultiCellWidget ( m_color_list, 0, 3, 0, 0 );
00251     connect( m_color_list, SIGNAL( highlighted(int) ), this, SLOT( colorClicked(int) ) );
00252     QWhatsThis::add( m_color_list, tr( "Color schemes are a collection of colors which are used for various parts of the display.\n\nClick here to select an available scheme." ) );
00253 
00254     m_color_list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), cfg ));
00255 
00256     QString path = QPEApplication::qpeDir ( );
00257     path.append( "/etc/colors/" );
00258     QStringList sl = QDir ( path ). entryList ( "*.scheme" );
00259 
00260     for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
00261     {
00262         QString name = (*it). left ((*it). find ( ".scheme" ));
00263         QString pathstr = path;
00264         pathstr.append( *it );
00265         Config config ( pathstr, Config::File );
00266         config. setGroup ( "Colors" );
00267 
00268         m_color_list-> insertItem ( new ColorListItem ( name, config ));
00269     }
00270 
00271     m_color_list-> setCurrentItem ( 0 );
00272 
00273     QPushButton* tempButton = new QPushButton( tab, "editSchemeButton" );
00274     tempButton->setText( tr( "Edit..." ) );
00275     connect( tempButton, SIGNAL( clicked() ), this, SLOT( editSchemeClicked() ) );
00276     gridLayout->addWidget( tempButton, 0, 1 );
00277     QWhatsThis::add( tempButton, tr( "Click here to change the colors in the current color scheme." ) );
00278 
00279     tempButton = new QPushButton( tab, "deleteSchemeButton" );
00280     tempButton->setText( tr( "Delete" ) );
00281     connect( tempButton, SIGNAL( clicked() ), this, SLOT( deleteSchemeClicked() ) );
00282     gridLayout->addWidget( tempButton, 1, 1 );
00283     QWhatsThis::add( tempButton, tr( "Click here to delete the color scheme selected in the list to the left." ) );
00284 
00285     tempButton = new QPushButton( tab, "saveSchemeButton" );
00286     tempButton->setText( tr( "Save" ) );
00287     connect( tempButton, SIGNAL( clicked() ), this, SLOT( saveSchemeClicked() ) );
00288     gridLayout->addWidget( tempButton, 2, 1 );
00289     QWhatsThis::add( tempButton, tr( "Click here to name and save the current color scheme." ) );
00290 
00291     return tab;
00292 }
00293 
00294 QWidget *Appearance::createAdvancedTab ( QWidget *parent, Config &cfg )
00295 {
00296     QWidget *tab = new QWidget ( parent );
00297     QVBoxLayout *vertLayout = new QVBoxLayout( tab, 3, 3 );
00298 
00299     /*
00300      * show scrollbars on the left?
00301      */
00302     m_leftHand = new QCheckBox( tr("Show Scrollbars on the left"), tab );
00303     m_leftHand->setChecked( cfg.readBoolEntry( "LeftHand", false ) );
00304     QWhatsThis::add( m_leftHand, tr( "Click here to display scrollbars on the left side instead of the right." ) );
00305     vertLayout->addWidget( m_leftHand );
00306 
00307     QFrame *f = new QFrame ( tab );
00308     f-> setFrameStyle ( QFrame::HLine | QFrame::Sunken );
00309     vertLayout-> addWidget ( f );
00310     vertLayout-> addSpacing ( 3 );
00311 
00312 
00313     QGridLayout* gridLayout = new QGridLayout ( vertLayout, 0, 0, 3, 0 );
00314 
00315     int style = cfg. readNumEntry ( "TabStyle", 2 ) - 1;
00316     bool tabtop = ( cfg. readEntry ( "TabPosition", "Top" ) == "Top" );
00317 
00318     QLabel* label = new QLabel( tr( "Tab style:" ), tab );
00319     gridLayout-> addWidget ( label, 0, 0 );
00320     QWhatsThis::add( label, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) );
00321 
00322     QButtonGroup* btngrp = new QButtonGroup( tab, "buttongroup" );
00323     btngrp-> hide ( );
00324     btngrp-> setExclusive ( true );
00325 
00326     m_tabstyle_list = new QComboBox ( false, tab, "tabstyle" );
00327     m_tabstyle_list-> insertItem ( tr( "Tabs" ));
00328     m_tabstyle_list-> insertItem ( tr( "Tabs w/icons" ));
00329     m_tabstyle_list-> insertItem ( tr( "Drop down list" ));
00330     m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" ));
00331     m_tabstyle_list-> setCurrentItem ( style );
00332     gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 );
00333     QWhatsThis::add( m_tabstyle_list, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) );
00334 
00335     m_tabstyle_top = new QRadioButton( tr( "Top" ), tab, "tabpostop" );
00336     btngrp-> insert ( m_tabstyle_top );
00337     gridLayout-> addWidget( m_tabstyle_top, 1, 1 );
00338     QWhatsThis::add( m_tabstyle_top, tr( "Click here so that tabs appear at the top of the window." ) );
00339 
00340     m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" );
00341     btngrp-> insert ( m_tabstyle_bottom );
00342     gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 );
00343     QWhatsThis::add( m_tabstyle_bottom, tr( "Click here so that tabs appear at the bottom of the window." ) );
00344 
00345     m_tabstyle_top-> setChecked ( tabtop );
00346     m_tabstyle_bottom-> setChecked ( !tabtop );
00347 
00348     m_original_tabstyle = style;
00349     m_original_tabpos = tabtop;
00350 
00351     vertLayout-> addSpacing ( 3 );
00352     QHBoxLayout *rotLay = new QHBoxLayout ( vertLayout, 3 );
00353 
00354     QLabel* rotlabel = new QLabel( tr( "Rotation direction:" ), tab );
00355     m_rotdir_cw = new QRadioButton( tab, "rotdir_cw" );
00356     m_rotdir_ccw = new QRadioButton( tab, "rotdir_ccw" );
00357     m_rotdir_flip = new QRadioButton( tab, "rotdir_flip" );
00358     QButtonGroup* rotbtngrp = new QButtonGroup( tab, "rotbuttongroup" );
00359 
00360     rotbtngrp-> hide ( );
00361     rotbtngrp-> setExclusive ( true );
00362     rotbtngrp-> insert ( m_rotdir_cw );
00363     rotbtngrp-> insert ( m_rotdir_ccw );
00364     rotbtngrp-> insert ( m_rotdir_flip );
00365 
00366     QImage ccwImage = Opie::Core::OResource::loadImage( "redo", Opie::Core::OResource::SmallIcon );
00367     QPixmap cw, ccw, flip;
00368     cw.convertFromImage( ccwImage );
00369     ccw.convertFromImage( ccwImage.mirror( 1, 0 ) );
00370     flip.convertFromImage( Opie::Core::OResource::loadImage( "pass", Opie::Core::OResource::SmallIcon ) );
00371 
00372     m_rotdir_cw-> setPixmap( cw );
00373     m_rotdir_ccw-> setPixmap( ccw );
00374     m_rotdir_flip-> setPixmap( flip );
00375 
00376     rotLay-> addWidget ( rotlabel, 0 );
00377     rotLay-> addWidget ( m_rotdir_cw, 0 );
00378     rotLay-> addWidget ( m_rotdir_ccw, 0 );
00379     rotLay-> addWidget ( m_rotdir_flip, 0 );
00380 
00381     int rotDirection = cfg.readNumEntry( "rotatedir" );
00382     ODirection rot = CW;
00383 
00384     if (rotDirection == -1)
00385     {
00386         rot = ODevice::inst ( )-> direction ( );
00387     }
00388     else
00389     {
00390         rot = (ODirection)rotDirection;
00391     }
00392 
00393     m_rotdir_cw-> setChecked ( rot == CW );
00394     m_rotdir_ccw-> setChecked ( rot == CCW );
00395     m_rotdir_flip-> setChecked ( rot == Flip );
00396 
00397     QFrame *f2 = new QFrame ( tab );
00398     f2-> setFrameStyle ( QFrame::HLine | QFrame::Sunken );
00399     vertLayout-> addWidget ( f2 );
00400     vertLayout-> addSpacing ( 3 );
00401 
00402     QHBoxLayout *bigIconlay = new QHBoxLayout ( vertLayout, 3 );
00403 
00404     QLabel* label2 = new QLabel( tr( "Big Icon size:" ), tab );
00405     bigIconlay-> addWidget ( label2, 0, 0 );
00406 
00407     m_bigIconSize = new QSpinBox(0, 128, 1, tab);
00408     m_bigIconSize->setValue(cfg.readNumEntry( "BigIconSize", AppLnk::bigIconSize() ));
00409     bigIconlay->addWidget( m_bigIconSize );
00410     label2->setBuddy( m_bigIconSize );
00411     QWhatsThis::add( label2, tr( "Big Icon Size determines the size of the application icons in Launcher" ) );
00412     QWhatsThis::add( m_bigIconSize, tr( "Big Icon Size determines the size of the application icons in Launcher" ) );
00413 
00414     QHBoxLayout *smallIconlay = new QHBoxLayout ( vertLayout, 3 );
00415 
00416     QLabel* label3 = new QLabel( tr( "Small Icon size:" ), tab );
00417     smallIconlay-> addWidget ( label3, 0, 0 );
00418 
00419     m_smallIconSize = new QSpinBox(0, 128, 1, tab);
00420     m_smallIconSize->setValue(cfg.readNumEntry( "SmallIconSize", AppLnk::smallIconSize() ));
00421     smallIconlay->addWidget( m_smallIconSize );
00422     label3->setBuddy( m_smallIconSize );
00423     QWhatsThis::add( label3, tr( "Small Icon Size determines the size of many of the icons seen in applications (in menus, tab bars, tool bars, etc.), as well as the size of taskbar." ) );
00424     QWhatsThis::add( m_smallIconSize, tr( "Small Icon Size determines the size of many of the icons seen in applications (in menus, tab bars, tool bars, etc.), as well as the size of taskbar." ) );
00425 
00426     m_useBigPixmaps = new QCheckBox( tr("use Big Pixmaps"), tab);
00427     m_useBigPixmaps->setChecked(cfg.readBoolEntry( "useBigPixmaps", qApp->desktop()->width() > 320 ));
00428     vertLayout->addWidget( m_useBigPixmaps );
00429     QWhatsThis::add( m_useBigPixmaps, tr( "Enlarge toolbar pixmaps, you probably want to enable this option for devices with screen resolution greater than 240x320" ) );
00430 
00431     /*
00432      * add a spacing
00433      */
00434     vertLayout->addItem( new QSpacerItem( 1, 1, QSizePolicy::MinimumExpanding,  QSizePolicy::MinimumExpanding ) );
00435     return tab;
00436 }
00437 
00438 
00439 Appearance::Appearance( QWidget* parent,  const char* name, WFlags )
00440         : QDialog ( parent, name, true, WStyle_ContextHelp )
00441 {
00442     setCaption( tr( "Appearance Settings" ) );
00443 
00444     Config config( "qpe" );
00445     config.setGroup( "Appearance" );
00446 
00447     QVBoxLayout *top = new QVBoxLayout ( this, 3, 3 );
00448 
00449     m_sample = new SampleWindow ( this );
00450 
00451     m_sample-> setDecoration ( new DefaultWindowDecoration ( ) );
00452     QWhatsThis::add( m_sample, tr( "This is a preview window.  Look here to see your new appearance as options are changed." ) );
00453 
00454     OTabWidget* tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom );
00455     QWidget *styletab;
00456 
00457     m_color_list = 0;
00458 
00459     tw-> addTab ( styletab = createStyleTab ( tw, config ), "appearance", tr( "Style" ));
00460     tw-> addTab ( createFontTab ( tw, config ), "font", tr( "Font" ));
00461     tw-> addTab ( createColorTab ( tw, config ), "appearance/color", tr( "Colors" ) );
00462     tw-> addTab ( createDecoTab ( tw, config ), "appearance/deco", tr( "Windows" ) );
00463     tw-> addTab ( m_advtab = createAdvancedTab ( tw, config ), "SettingsIcon", tr( "Advanced" ) );
00464 
00465     top-> addWidget ( tw, 10 );
00466     top-> addWidget ( m_sample, 1 );
00467 
00468     tw-> setCurrentTab ( styletab );
00469     connect ( tw, SIGNAL( currentChanged(QWidget*)), this, SLOT( tabChanged(QWidget*)));
00470 
00471     m_style_changed = m_font_changed = m_color_changed = m_deco_changed = false;
00472 }
00473 
00474 Appearance::~Appearance()
00475 {}
00476 
00477 void Appearance::tabChanged ( QWidget *w )
00478 {
00479     if ( w == m_advtab )
00480     {
00481         m_sample-> hide ( );
00482         updateGeometry ( ); // shouldn't be necessary ...
00483     }
00484     else
00485         m_sample-> show ( );
00486 }
00487 
00488 void Appearance::accept ( )
00489 {
00490     bool newtabpos = m_tabstyle_top-> isChecked ( );
00491     int newtabstyle = m_tabstyle_list-> currentItem ( );
00492 
00493     Config config ( "qpe" );
00494     config. setGroup ( "Appearance" );
00495 
00496     if ( m_style_changed )
00497     {
00498         StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( ));
00499         if ( item )
00500             config.writeEntry( "Style", item-> key ( ));
00501     }
00502 
00503     if ( m_deco_changed )
00504     {
00505         DecoListItem *item = (DecoListItem *) m_deco_list-> item ( m_deco_list-> currentItem ( ));
00506         if ( item )
00507             config.writeEntry( "Decoration", item-> key ( ));
00508     }
00509 
00510     if (( newtabstyle != m_original_tabstyle ) || ( newtabpos != m_original_tabpos ))
00511     {
00512         config. writeEntry ( "TabStyle", newtabstyle + 1 );
00513         config. writeEntry ( "TabPosition", newtabpos ? "Top" : "Bottom" );
00514     }
00515 
00516     if ( m_font_changed )
00517     {
00518         config. writeEntry ( "FontFamily", m_fontselect-> fontFamily ( ));
00519         config. writeEntry ( "FontStyle", m_fontselect-> fontStyle ( ));
00520         config. writeEntry ( "FontSize", m_fontselect-> fontSize ( ));
00521     }
00522 
00523 
00524     if ( m_color_changed )
00525     {
00526         ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
00527 
00528         if ( item )
00529             item-> save ( config );
00530     }
00531 
00532     ODirection rot;
00533     if (m_rotdir_ccw-> isChecked ( ))
00534     {
00535         rot = CCW;
00536     }
00537     else if (m_rotdir_cw-> isChecked ( ))
00538     {
00539         rot = CW;
00540     }
00541     else
00542     {
00543         rot = Flip;
00544     }
00545     config. writeEntry ( "rotatedir", (int)rot );
00546 
00547     config. writeEntry( "LeftHand", m_leftHand->isChecked() );
00548 
00549     config. writeEntry( "useBigPixmaps", m_useBigPixmaps->isChecked() );
00550     config. writeEntry( "BigIconSize", m_bigIconSize->value() );
00551     config. writeEntry( "SmallIconSize", m_smallIconSize->value() );
00552 
00553     config. write ( ); // need to flush the config info first
00554     Global::applyStyle ( );
00555 
00556     QDialog::accept ( );
00557 }
00558 
00559 void Appearance::done ( int r )
00560 {
00561     QDialog::done ( r );
00562     close ( );
00563 }
00564 
00565 
00566 void Appearance::styleClicked ( int index )
00567 {
00568     StyleListItem *sli = (StyleListItem *) m_style_list-> item ( index );
00569     m_style_settings-> setEnabled ( sli ? sli-> hasSettings ( ) : false );
00570 
00571     if ( m_sample && sli && sli-> style ( ))
00572     {
00573         int ci = m_color_list ? m_color_list-> currentItem ( ) : -1;
00574 
00575         m_sample-> setStyle2 ( sli-> style ( ), ci < 0 ? palette ( ) : ((ColorListItem *) m_color_list-> item ( ci ))-> palette ( ));
00576     }
00577 
00578     m_style_changed |= ( index != m_original_style );
00579 }
00580 
00581 void Appearance::styleSettingsClicked ( )
00582 {
00583     StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( ));
00584 
00585     if ( item && item-> hasSettings ( ))
00586     {
00587         QDialog *d = new QDialog ( this, "SETTINGS-DLG", true );
00588         QVBoxLayout *vbox = new QVBoxLayout ( d, 3, 0 );
00589 
00590         QWidget *w = item-> settings ( d );
00591 
00592         if ( w )
00593         {
00594             vbox-> addWidget ( w );
00595 
00596             d-> setCaption ( w-> caption ( ));
00597 
00598             bool accepted = ( QPEApplication::execDialog ( d ) == QDialog::Accepted );
00599 
00600             if ( item-> setSettings ( accepted ))
00601                 m_style_changed = true;
00602         }
00603         delete d;
00604     }
00605 }
00606 
00607 void Appearance::decoClicked ( int index )
00608 {
00609     DecoListItem *dli = (DecoListItem *) m_deco_list-> item ( index );
00610 
00611     if ( m_sample )
00612     {
00613         if ( dli && dli-> interface ( ))
00614             m_sample-> setDecoration ( dli-> interface ( ));
00615         else
00616             m_sample-> setDecoration ( new DefaultWindowDecoration ( ));
00617         m_sample-> repaint ( );
00618     }
00619     m_deco_changed |= ( index != m_original_deco );
00620 }
00621 
00622 void Appearance::fontClicked ( const QFont &f )
00623 {
00624     m_font_changed |= ( f != m_sample-> font ( ));
00625     m_sample-> setFont ( f );
00626 }
00627 
00628 void Appearance::colorClicked ( int index )
00629 {
00630     ColorListItem *item = (ColorListItem *) m_color_list-> item ( index );
00631 
00632     if ( item )
00633         m_sample-> setPalette ( item-> palette ( ));
00634 
00635     m_color_changed |= ( item-> palette ( ) != qApp-> palette ( ));
00636 }
00637 
00638 
00639 void Appearance::editSchemeClicked ( )
00640 {
00641     ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
00642 
00643     int cnt = 0;
00644     QString labels [QColorGroup::NColorRoles];
00645     QColor colors [QColorGroup::NColorRoles];
00646 
00647     for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
00648     {
00649         QColor col = item->color( static_cast<QColorGroup::ColorRole>( role ) );
00650 
00651         if ( col. isValid ( ))
00652         {
00653             labels[cnt] = item->label( static_cast<QColorGroup::ColorRole>( role ) );
00654             colors[cnt] = col;
00655 
00656             cnt++;
00657         }
00658     }
00659 
00660     EditScheme* editdlg = new EditScheme( cnt, labels, colors, this, "editScheme", true );
00661     if ( QPEApplication::execDialog( editdlg ) == QDialog::Accepted )
00662     {
00663         ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 );
00664         cnt = 0;
00665 
00666         for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
00667         {
00668             if ( item->color( static_cast<QColorGroup::ColorRole>( role ) ).isValid() )
00669             {
00670                 citem->setColor( static_cast<QColorGroup::ColorRole>( role ), colors[cnt] );
00671                 cnt++;
00672             }
00673         }
00674 
00675         m_color_list-> setCurrentItem ( 0 );
00676         colorClicked ( 0 );
00677 
00678         m_color_changed = true;
00679     }
00680     delete editdlg;
00681 }
00682 
00683 
00684 void Appearance::saveSchemeClicked()
00685 {
00686     ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
00687 
00688     if ( !item )
00689         return;
00690 
00691     QDialog *d = new QDialog ( this, 0, true );
00692     d-> setCaption ( tr( "Save Scheme" ));
00693     QLineEdit *ed = new QLineEdit ( d );
00694     ( new QVBoxLayout ( d, 3, 3 ))-> addWidget ( ed );
00695     ed-> setFocus ( );
00696 
00697     if ( d-> exec ( ) == QDialog::Accepted )
00698     {
00699         QString schemename = ed-> text ( );
00700         QString filestr = QPEApplication::qpeDir();
00701         filestr.append( "/etc/colors/" );
00702         filestr.append( schemename );
00703         filestr.append( ".scheme" );
00704         QFile file ( filestr );
00705         if ( !file. exists ( ))
00706         {
00707             QPalette p = item-> palette ( );
00708 
00709             Config config ( file.name(), Config::File );
00710             config. setGroup( "Colors" );
00711 
00712             item-> save ( config );
00713 
00714             config. write ( ); // need to flush the config info first
00715 
00716             m_color_list-> insertItem ( new ColorListItem ( schemename, config ));
00717         }
00718         else
00719         {
00720             QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." ));
00721         }
00722     }
00723     delete d;
00724 }
00725 
00726 void Appearance::deleteSchemeClicked()
00727 {
00728     ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
00729 
00730     if ( !item )
00731         return;
00732 
00733     if ( m_color_list-> currentItem ( ) > 0 )
00734     {
00735         if ( QPEMessageBox::confirmDelete ( this, tr( "Delete scheme" ), item-> text ( ) ) )
00736         {
00737             QString filestr = QPEApplication::qpeDir ( );
00738             filestr.append( "/etc/colors/" );
00739             filestr.append( item-> text ( ) );
00740             filestr.append( ".scheme" );
00741             QFile::remove ( filestr );
00742             delete item;
00743         }
00744     }
00745     else
00746     {
00747         QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." ));
00748     }
00749 }

Generated on Sat Nov 5 16:17:46 2005 for OPIE by  doxygen 1.4.2