author | sandman <sandman> | 2002-09-21 01:37:32 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-21 01:37:32 (UTC) |
commit | 4b0a34a494dbea653b79a945b8c59ee0be62ac75 (patch) (side-by-side diff) | |
tree | 7b9e091423487ed7e4c590b340b84b9ad9d81f44 | |
parent | 1a8d7cd34db3b9f443bcb956f85c41336a60e948 (diff) | |
download | opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.zip opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.tar.gz opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.tar.bz2 |
- Improved style and color preview
- color schemes can be editied now
-rw-r--r-- | noncore/settings/appearance2/appearance.cpp | 105 | ||||
-rw-r--r-- | noncore/settings/appearance2/colorlistitem.h | 95 | ||||
-rw-r--r-- | noncore/settings/appearance2/editScheme.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/appearance2/editScheme.h | 8 | ||||
-rw-r--r-- | noncore/settings/appearance2/sample.cpp | 11 |
5 files changed, 152 insertions, 77 deletions
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp index 52c7125..cf3069e 100644 --- a/noncore/settings/appearance2/appearance.cpp +++ b/noncore/settings/appearance2/appearance.cpp @@ -102,40 +102,24 @@ public: if ( *iface ) (*iface)->addRef(); return QS_OK; } Q_REFCOUNT private: ulong ref; }; -struct { - QColorGroup::ColorRole role; - const char *key; - const char *def; -} colorLUT [] = { - { QColorGroup::Base, "Base", "#FFFFFF" }, - { QColorGroup::Background, "Background", "#E5E1D5" }, - { QColorGroup::Button, "Button", "#D6CDBB" }, - { QColorGroup::ButtonText, "ButtonText", "#000000" }, - { QColorGroup::Highlight, "Highlight", "#800000" }, - { QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF" }, - { QColorGroup::Text, "Text", "#000000" }, - - { QColorGroup::NColorRoles, 0, 0 } -}; - void Appearance::loadStyles ( QListBox *list ) { #if QT_VERSION >= 300 list->insertStringList(QStyleFactory::styles()); #else list->insertItem( new StyleListItem ( "Windows", new QWindowsStyle ( ))); list->insertItem( new StyleListItem ( "Light", new LightStyle ( ))); #ifndef QT_NO_STYLE_MOTIF list->insertItem( new StyleListItem ( "Motif", new QMotifStyle ( ))); #endif #ifndef QT_NO_STYLE_MOTIFPLUS @@ -177,65 +161,43 @@ void Appearance::loadDecos ( QListBox *list ) for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { QLibrary *lib = new QLibrary ( path + "/" + *it ); WindowDecorationInterface *iface; if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK ) list-> insertItem ( new DecoListItem ( lib, iface )); else delete lib; } } } -static QPalette readColorPalette ( Config &config ) -{ - QColor bgcolor( config. readEntry( "Background", "#E5E1D5" ) ); - QColor btncolor( config. readEntry( "Button", "#D6CDBB" ) ); - QPalette pal( btncolor, bgcolor ); - - QString color = config. readEntry( "Highlight", "#800000" ); - pal.setColor( QColorGroup::Highlight, QColor(color) ); - color = config. readEntry( "HighlightedText", "#FFFFFF" ); - pal.setColor( QColorGroup::HighlightedText, QColor(color) ); - color = config. readEntry( "Text", "#000000" ); - pal.setColor( QColorGroup::Text, QColor(color) ); - color = config. readEntry( "ButtonText", "#000000" ); - pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) ); - color = config. readEntry( "Base", "#FFFFFF" ); - pal.setColor( QColorGroup::Base, QColor(color) ); - - pal.setColor( QPalette::Disabled, QColorGroup::Text, pal.color(QPalette::Active, QColorGroup::Background).dark() ); - - return pal; -} - void Appearance::loadColors ( QListBox *list ) { list-> clear ( ); { Config config ( "qpe" ); config. setGroup ( "Appearance" ); - list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), readColorPalette ( config ))); + list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), config )); } QString path = QPEApplication::qpeDir ( ) + "/etc/colors/"; QStringList sl = QDir ( path ). entryList ( "*.scheme" ); for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { QString name = (*it). left ((*it). find ( ".scheme" )); Config config ( path + *it, Config::File ); config. setGroup ( "Colors" ); - list-> insertItem ( new ColorListItem ( name, readColorPalette ( config ))); + list-> insertItem ( new ColorListItem ( name, config )); } } void Appearance::loadFonts ( QListBox *list ) { FontDatabase fd; QStringList f = fd. families ( ); for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) list-> insertItem ( new FontListItem ( *it, fd. styles ( *it ), fd. pointSizes ( *it ))); } @@ -475,34 +437,33 @@ void Appearance::accept ( ) config.writeEntry( "Style", item-> key ( )); } if ( newtabstyle != m_original_tabstyle ) { config. writeEntry ( "TabStyle", newtabstyle ); } if ( m_font_changed ) { config.writeEntry( "FontFamily", m_font_family_list-> text ( newfontfamily )); config.writeEntry( "FontStyle", m_font_style_list-> text ( newfontstyle )); config.writeEntry( "FontSize", m_font_size_list-> text ( newfontsize )); } -/* - if ( schemeChanged ) + + if ( m_color_changed ) { - int i; - for ( i = 0; i < MAX_CONTROL; i++ ) - { - config.writeEntry( controlList[i], controlColor[i] ); - } + ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); + + if ( item ) + item-> save ( config ); } -*/ + config. write ( ); // need to flush the config info first Global::applyStyle ( ); if ( QMessageBox::warning ( this, tr( "Restart" ), tr( "Do you want to restart Opie now?" ), tr( "Yes" ), tr( "No" ), 0, 0, 1 ) == 0 ) { QCopEnvelope e( "QPE/System", "restart()" ); } QDialog::accept ( ); } void Appearance::done ( int r ) { @@ -643,67 +604,85 @@ void Appearance::colorClicked ( int index ) if ( item ) m_sample-> setPalette ( item-> palette ( )); m_color_changed |= ( item-> palette ( ) != qApp-> palette ( )); } void Appearance::editSchemeClicked ( ) { ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); -/* - EditScheme* editdlg = new EditScheme( this, "editScheme", TRUE, 0, - 9, controlLabel, controlColor ); - editdlg->showMaximized(); - if ( editdlg->exec() == QDialog::Accepted ) - { - int i; - for ( i = 0; i < MAX_CONTROL; i++ ) - { - controlColor[i] = editdlg->colorList[i]; + int cnt = 0; + QString controlLabel [QColorGroup::NColorRoles]; + QString controlColor [QColorGroup::NColorRoles]; + + for ( QColorGroup::ColorRole role = (QColorGroup::ColorRole) 0; role != QColorGroup::NColorRoles; ((int) role )++ ) { + QColor col = item-> color ( role ); + + if ( col. isValid ( )) { + controlLabel [cnt] = item-> label ( role ); + controlColor [cnt] = col. name ( ); + + cnt++; + } + } + + EditScheme* editdlg = new EditScheme( this, "editScheme", true, 0, cnt, controlLabel, controlColor ); + editdlg-> showMaximized ( ); + if ( editdlg-> exec ( ) == QDialog::Accepted ) { + ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 ); + cnt = 0; + + for ( QColorGroup::ColorRole role = (QColorGroup::ColorRole) 0; role != QColorGroup::NColorRoles; ((int) role )++ ) { + if ( item-> color ( role ). isValid ( )) { + citem-> setColor ( role, QColor ( controlColor [cnt] )); + cnt++; + } } + + m_color_list-> setCurrentItem ( 0 ); + colorClicked ( 0 ); + m_color_changed = true; } delete editdlg; - */ } void Appearance::saveSchemeClicked() { ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); if ( !item ) return; QDialog *d = new QDialog ( this, 0, true ); d-> setCaption ( tr( "Save Scheme" )); QLineEdit *ed = new QLineEdit ( this ); ( new QVBoxLayout ( d, 4, 4 ))-> addWidget ( ed ); if ( d-> exec ( ) == QDialog::Accepted ) { QString schemename = ed-> text ( ); QFile file ( QPEApplication::qpeDir() + "/etc/colors/" + schemename + ".scheme" ); if ( !file. exists ( )) { QPalette p = item-> palette ( ); Config config ( file.name(), Config::File ); - config.setGroup( "Colors" ); + config. setGroup( "Colors" ); - for ( int i = 0; colorLUT [i]. role != QColorGroup::NColorRoles; i++ ) - config.writeEntry ( colorLUT [i]. key, p. color ( QPalette::Active, colorLUT [i]. role ). name ( )); - + item-> save ( config ); + config. write ( ); // need to flush the config info first loadColors ( m_color_list ); } else { QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." )); } } delete d; } void Appearance::deleteSchemeClicked() diff --git a/noncore/settings/appearance2/colorlistitem.h b/noncore/settings/appearance2/colorlistitem.h index c7318a6..1ff6ecc 100644 --- a/noncore/settings/appearance2/colorlistitem.h +++ b/noncore/settings/appearance2/colorlistitem.h @@ -1,28 +1,113 @@ #ifndef COLORLISTITEM_H #define COLORLISTITEM_H #include <qlistbox.h> #include <qpalette.h> +#include <qapplication.h> + +#include <qpe/config.h> + +class Appearance; class ColorListItem : public QListBoxText { public: - ColorListItem ( const QString &t, const QPalette &pal ) : QListBoxText ( t ) - { - m_pal = pal; + ColorListItem ( const QString &t, Config &cfg ) : QListBoxText ( t ) + { + m_colors = new QColor [s_colorcount]; + load ( cfg ); } virtual ~ColorListItem ( ) { + delete [] m_colors; } QPalette palette ( ) { - return m_pal; + return m_palette; + } + + bool load ( Config &cfg ) + { + for ( int i = 0; i < s_colorcount; i++ ) + m_colors [i] = QColor ( cfg. readEntry ( s_colorlut [i]. m_key, s_colorlut [i]. m_def )); + + buildPalette ( ); + return true; + } + + void buildPalette ( ) + { + m_palette = QPalette ( m_colors [r2i(QColorGroup::Button)], m_colors [r2i(QColorGroup::Background)] ); + m_palette. setColor ( QColorGroup::Highlight, m_colors [r2i(QColorGroup::Highlight)] ); + m_palette. setColor ( QColorGroup::HighlightedText, m_colors [r2i(QColorGroup::HighlightedText)] ); + m_palette. setColor ( QColorGroup::Text, m_colors [r2i(QColorGroup::Text)] ); + m_palette. setColor ( QPalette::Active, QColorGroup::ButtonText, m_colors [r2i(QColorGroup::ButtonText)] ); + m_palette. setColor ( QColorGroup::Base, m_colors [r2i(QColorGroup::Base)] ); + m_palette. setColor ( QPalette::Disabled, QColorGroup::Text, m_palette. color ( QPalette::Active, QColorGroup::Background ). dark ( )); } + bool save ( Config &cfg ) + { + for ( int i = 0; i < s_colorcount; i++ ) + cfg. writeEntry ( s_colorlut [i]. m_key, m_colors [i]. name ( )); + return true; + } + + QColor color ( QColorGroup::ColorRole role ) + { + int i = r2i ( role ); + return i >= 0 ? m_colors [i] : QColor ( ); + } + + void setColor ( QColorGroup::ColorRole role, QColor c ) + { + int i = r2i ( role ); + if ( i >= 0 ) { + m_colors [i] = c; + buildPalette ( ); + } + } + + QString label ( QColorGroup::ColorRole role ) + { + int i = r2i ( role ); + return i >= 0 ? qApp-> translate ( "Appearance", s_colorlut [i]. m_label ) : QString::null; + } + private: - QPalette m_pal; + QPalette m_palette; + QColor *m_colors; + + static struct colorlut { + QColorGroup::ColorRole m_role; + const char * m_key; + const char * m_def; + const char * m_label; + } const s_colorlut []; + static const int s_colorcount; + + static int r2i ( QColorGroup::ColorRole role ) + { + for ( int i = 0; i < s_colorcount; i++ ) { + if ( s_colorlut [i]. m_role == role ) + return i; + } + return -1; + } }; +const ColorListItem::colorlut ColorListItem::s_colorlut [] = { + { QColorGroup::Base, "Base", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Base" ) }, + { QColorGroup::Background, "Background", "#E5E1D5", QT_TRANSLATE_NOOP( "Appearance", "Background" ) }, + { QColorGroup::Button, "Button", "#D6CDBB", QT_TRANSLATE_NOOP( "Appearance", "Button" ) }, + { QColorGroup::ButtonText, "ButtonText", "#000000", QT_TRANSLATE_NOOP( "Appearance", "Button Text" ) }, + { QColorGroup::Highlight, "Highlight", "#800000", QT_TRANSLATE_NOOP( "Appearance", "Highlight" ) }, + { QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Highlighted Text" ) }, + { QColorGroup::Text, "Text", "#000000", QT_TRANSLATE_NOOP( "Appearance", "Text" ) } +}; + +const int ColorListItem::s_colorcount = sizeof( s_colorlut ) / sizeof ( s_colorlut [0] ); + #endif diff --git a/noncore/settings/appearance2/editScheme.cpp b/noncore/settings/appearance2/editScheme.cpp index 2453c7b..4f2ac2c 100644 --- a/noncore/settings/appearance2/editScheme.cpp +++ b/noncore/settings/appearance2/editScheme.cpp @@ -20,56 +20,60 @@ #include "editScheme.h" #include "opie/colorpopupmenu.h" #include <qaction.h> #include <qlabel.h> #include <qlayout.h> #include <qpopupmenu.h> #include <qscrollview.h> #include <qtoolbutton.h> EditScheme::EditScheme( QWidget* parent, const char* name, bool modal, WFlags fl, - int max, QString list[], QString colors[] ) + int max, QString *list, QString *colors ) : QDialog( parent, name, modal, fl ) { setCaption( tr( "Edit scheme" ) ); QGridLayout* layout = new QGridLayout( this ); layout->setSpacing( 4 ); layout->setMargin( 4 ); maxCount = max; + colorList = colors; + surfaceList = list; + colorButtons = new QToolButton * [max]; int i; QLabel* label; ColorPopupMenu* colorPopupMenu; for ( i = 0; i < max; i++ ) { - colorList[i] = colors[i]; - surfaceList[i] = list[i]; +// colorList[i] = colors[i]; +// surfaceList[i] = list[i]; label = new QLabel( tr( surfaceList[i] ), this ); layout->addWidget( label, i, 0 ); colorButtons[i] = new QToolButton( this, list[i] ); colorButtons[i]->setPalette( QPalette( QColor( colors[i] ) ) ); layout->addWidget( colorButtons[i], i, 1 ); colorPopupMenu = new ColorPopupMenu( colors[i], 0, list[i] ); colorButtons[i]->setPopup( colorPopupMenu ); colorButtons[i]->setPopupDelay( 0 ); connect( colorPopupMenu, SIGNAL( colorSelected( const QColor& ) ), this, SLOT( changeColor( const QColor& ) ) ); } } EditScheme::~EditScheme() { + delete [] colorButtons; } void EditScheme::changeColor( const QColor& color ) { QString name( sender()->name() ); int i; for ( i = 0; i < maxCount; i++ ) { if ( name == colorButtons[i]->name() ) { break; diff --git a/noncore/settings/appearance2/editScheme.h b/noncore/settings/appearance2/editScheme.h index cf238c6..583050f 100644 --- a/noncore/settings/appearance2/editScheme.h +++ b/noncore/settings/appearance2/editScheme.h @@ -22,27 +22,27 @@ #include <qdialog.h> #include <qtoolbutton.h> class QColor; class EditScheme : public QDialog { Q_OBJECT public: EditScheme( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0, - int = 0, QString[] = 0, QString[] = 0 ); + int = 0, QString * = 0, QString * = 0 ); ~EditScheme(); int maxCount; - QString surfaceList[9]; - QString colorList[9]; + QString * surfaceList; + QString * colorList; - QToolButton* colorButtons[9]; + QToolButton** colorButtons; protected slots: void changeColor( const QColor& ); }; #endif // EDITSCHEME_H diff --git a/noncore/settings/appearance2/sample.cpp b/noncore/settings/appearance2/sample.cpp index ee27d60..e447002 100644 --- a/noncore/settings/appearance2/sample.cpp +++ b/noncore/settings/appearance2/sample.cpp @@ -1,24 +1,25 @@ #include <qvbox.h> #include <qpopupmenu.h> #include <qpainter.h> #include <qmenubar.h> #include <qcheckbox.h> #include <qpushbutton.h> #include <qscrollbar.h> #include <qlayout.h> #include <qwhatsthis.h> #include <qpixmapcache.h> #include <qtimer.h> #include <qobjectlist.h> +#include <qcommonstyle.h> #include "sample.h" class SampleText : public QWidget { public: SampleText( const QString &t, bool h, QWidget *parent ) : QWidget( parent ), hl(h), text(t) { if ( hl ) setBackgroundMode( PaletteHighlight ); @@ -58,43 +59,49 @@ QSize SampleWindow::sizeHint() const return container->sizeHint() + QSize( 10, 35 ); } void SampleWindow::setFont( const QFont &f ) { QWidget::setFont( f ); popup->setFont( f ); QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); } static void setStyleRecursive ( QWidget *w, QStyle *s ) { + w->setStyle( s ); QObjectList *childObjects=(QObjectList*)w->children(); if ( childObjects ) { QObject * o; for(o=childObjects->first();o!=0;o=childObjects->next()) { if( o->isWidgetType() ) { setStyleRecursive((QWidget *)o,s); } } } - w->setStyle( s ); } void SampleWindow::setStyle2 ( QStyle *sty ) { + typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool); + + extern QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl); + QPixmapCache::clear ( ); QPalette p = palette ( ); sty-> polish ( p ); + qt_set_draw_menu_bar_impl ( 0 ); setStyleRecursive ( this, sty ); + setPalette ( p ); QTimer::singleShot ( 0, this, SLOT( fixGeometry ( ))); } void SampleWindow::setDecoration( WindowDecorationInterface *i ) { iface = i; wd.rect = QRect( 0, 0, 150, 75 ); wd.caption = tr("Sample"); wd.palette = palette(); wd.flags = WindowDecorationInterface::WindowData::Dialog | WindowDecorationInterface::WindowData::Active; @@ -197,30 +204,30 @@ bool SampleWindow::eventFilter( QObject *, QEvent *e ) } return FALSE; } void SampleWindow::paletteChange( const QPalette &old ) { QWidget::paletteChange ( old ); wd. palette = palette ( ); popup-> setPalette ( palette ( )); } + void SampleWindow::setPalette ( const QPalette &pal ) { QPixmapCache::clear ( ); QPalette p = pal; style ( ). polish ( p ); - QWidget::setPalette ( p ); } void SampleWindow::resizeEvent( QResizeEvent *re ) { wd.rect = QRect( 0, 0, 150, 75 ); wd.rect.setX( 0 ); wd.rect.setWidth( width() - lb - rb ); wd.rect.setY( 0 ); wd.rect.setHeight( height() - th - tb - bb ); |