📄 appearance.cpp
字号:
sample = new SampleWindow( this ); AppearanceSettingsBaseLayout->addWidget( sample ); wdiface = 0; styleiface = 0; wdLoader = new PluginLoader( "decorations" ); styleLoader = new PluginLoader( "styles" ); wdIsPlugin = FALSE;#ifdef DEBUG maxFontSize = 24;#else maxFontSize = qApp->desktop()->width() >= 640 ? 14 : 12;#endif populateStyleList(); populateColorList(); populateDecorationList(); Config config("qpe"); config.setGroup( "Appearance" ); QString s = config.readEntry( "Style", "Qtopia" ); unsigned i; if ( s == "QPE" ) s = "Qtopia"; for ( i = 0; i < styleList->count(); i++ ) { PluginItem *item = (PluginItem*)styleList->item(i); if ( item->filename() == s || item->text() == s ) { styleList->setCurrentItem( i ); break; } } connect( styleList, SIGNAL(highlighted(int)), this, SLOT(styleSelected(int)) ); s = config.readEntry( "Scheme", "Desert" ); connect( colorList, SIGNAL(highlighted(int)), this, SLOT(colorSelected(int)) ); colorList->setCurrentItem( colorListIDs.findIndex(s) ); s = config.readEntry( "Decoration" ); for ( i = 0; i < decorationList->count(); i++ ) { PluginItem *item = (PluginItem*)decorationList->item(i); if ( item->filename() == s || item->text() == s ) { decorationList->setCurrentItem( i ); break; } } connect( decorationList, SIGNAL(highlighted(int)), this, SLOT(decorationSelected(int)) ); decorationSelected( decorationList->currentItem() ); s = config.readEntry( "FontFamily", "Helvetica" ); prefFontSize = config.readNumEntry( "FontSize", font().pointSize() ); populateFontList(s,prefFontSize); connect( fontList, SIGNAL(highlighted(const QString&)), this, SLOT(fontSelected(const QString&)) ); connect( fontSize, SIGNAL(activated(const QString&)), this, SLOT(fontSizeSelected(const QString&)) );}AppearanceSettings::~AppearanceSettings(){ delete styleLoader; delete wdLoader;}void AppearanceSettings::accept(){ Config config("qpe"); config.setGroup( "Appearance" ); QString s; PluginItem *item = (PluginItem *)styleList->item( styleList->currentItem() ); if ( item ) { s = item->filename().isEmpty() ? item->text() : item->filename(); config.writeEntry( "Style", s ); } item = (PluginItem *)decorationList->item( decorationList->currentItem() ); if ( item ) { s = item->filename().isEmpty() ? item->text() : item->filename(); config.writeEntry( "Decoration", s ); } s = colorListIDs[colorList->currentItem()]; config.writeEntry( "Scheme", s ); Config scheme( QPEApplication::qpeDir() + "etc/colors/" + s + ".scheme", Config::File ); scheme.setGroup("Colors"); QString color = scheme.readEntry( "Background", "#E5E1D5" ); config.writeEntry( "Background", color ); color = scheme.readEntry( "Button", "#D6CDBB" ); config.writeEntry( "Button", color ); color = scheme.readEntry( "Highlight", "#800000" ); config.writeEntry( "Highlight", color ); color = scheme.readEntry( "HighlightedText", "#FFFFFF" ); config.writeEntry( "HighlightedText", color ); color = scheme.readEntry( "Text", "#000000" ); config.writeEntry( "Text", color ); color = scheme.readEntry( "ButtonText", "#000000" ); config.writeEntry( "ButtonText", color ); color = scheme.readEntry( "Base", "#FFFFFF" ); config.writeEntry( "Base", color ); QFontMetrics fm(sample->fontMetrics()); config.writeEntry( "FontFamily", fontList->currentText() ); config.writeEntry( "FontSize", fontSize->currentText().toInt() );#ifndef QPE_FONT_HEIGHT_TO_ICONSIZE#define QPE_FONT_HEIGHT_TO_ICONSIZE(x) (x+1)#endif config.writeEntry( "IconSize", QPE_FONT_HEIGHT_TO_ICONSIZE(fm.height()) ); config.write(); // need to flush the config info first Global::applyStyle(); QDialog::accept();}void AppearanceSettings::done(int r) { QDialog::done(r); close();}void AppearanceSettings::colorSelected( int id ){ Config config( QPEApplication::qpeDir() + "etc/colors/" + colorListIDs[id] + ".scheme", Config::File ); config.setGroup( "Colors" ); 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() ); sample->setPalette( pal );}void AppearanceSettings::styleSelected( int idx ){ QString style("Qtopia"); PluginItem *item = (PluginItem *)styleList->item( idx ); if ( item ) style = item->filename().isEmpty() ? item->text() : item->filename(); StyleInterface *oldIface = styleiface; QStyle *newStyle = 0; styleiface = 0; if ( style == "Windows" ) { // No tr newStyle = new QWindowsStyle; } else if ( style == "QPE" || style == "Qtopia" ) { newStyle = new QPEStyle; } else { StyleInterface *iface = 0; if ( styleLoader->queryInterface( style, IID_Style, (QUnknownInterface**)&iface ) == QS_OK && iface ) { newStyle = iface->style(); styleiface = iface; } } if (!newStyle) newStyle = new QPEStyle; sample->setUpdatesEnabled( FALSE ); QPixmapCache::clear(); setStyle( sample, newStyle ); QTimer::singleShot( 0, this, SLOT(fixSampleGeometry()) ); if ( oldIface ) styleLoader->releaseInterface( oldIface );}void AppearanceSettings::decorationSelected( int idx ){ if ( wdIsPlugin ) { wdLoader->releaseInterface( wdiface ); } else { delete wdiface; } wdiface = 0; wdIsPlugin = FALSE; QString dec("Qtopia"); PluginItem *item = (PluginItem *)decorationList->item( idx ); if ( item ) dec = item->filename().isEmpty() ? item->text() : item->filename(); if ( dec != "Qtopia" ) { if ( wdLoader->queryInterface( dec, IID_WindowDecoration, (QUnknownInterface**)&wdiface ) == QS_OK && wdiface ) wdIsPlugin = TRUE; } if ( !wdiface ) wdiface = new DefaultWindowDecoration; sample->setDecoration( wdiface ); sample->repaint();}void AppearanceSettings::fontSelected( const QString &name ){ sample->setUpdatesEnabled( FALSE ); fontSize->clear(); int diff = 1000; FontDatabase fd; QValueList<int> pointSizes = fd.pointSizes( name.lower() ); QValueList<int>::Iterator it; for ( it = pointSizes.begin(); it != pointSizes.end(); ++it ) { if ( *it <= maxFontSize ) { fontSize->insertItem( QString::number( *it ) ); if ( QABS(*it-prefFontSize) < diff ) { diff = QABS(*it - prefFontSize); fontSize->setCurrentItem( fontSize->count()-1 ); } } } QFont f( name, fontSize->currentText().toInt() ); sample->setFont( f ); QTimer::singleShot( 0, this, SLOT(fixSampleGeometry()) );}void AppearanceSettings::fontSizeSelected( const QString &sz ){ prefFontSize = sz.toInt(); sample->setUpdatesEnabled( FALSE ); sample->setFont( QFont(fontList->currentText(),prefFontSize) ); QTimer::singleShot( 0, this, SLOT(fixSampleGeometry()) );}void AppearanceSettings::setStyle( 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() ) { setStyle((QWidget *)o,s); } } }}void AppearanceSettings::populateStyleList(){ (void)new PluginItem( styleList, "Qtopia");#if QT_VERSION >= 0x030000// styleList->insertStringList(QStyleFactory::styles());#else (void)new PluginItem( styleList, "Windows"); // No tr QStringList list = styleLoader->list(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { StyleInterface *iface = 0; if ( styleLoader->queryInterface( *it, IID_Style, (QUnknownInterface**)&iface ) == QS_OK ) { PluginItem *item = new PluginItem( styleList, iface->name() ); item->setFilename( *it ); styleLoader->releaseInterface( iface ); } }#endif}void AppearanceSettings::populateColorList(){ QDir dir( QPEApplication::qpeDir() + "etc/colors" ); QStringList list = dir.entryList( "*.scheme" ); // No tr colorListIDs.clear(); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { Config scheme( QPEApplication::qpeDir() + "etc/colors/" + *it, Config::File ); QString name = (*it).left( (*it).find( ".scheme" ) ); colorListIDs.append(name); scheme.setGroup("Global"); colorList->insertItem( scheme.readEntry("Name",name+"-DEF") ); }}void AppearanceSettings::populateDecorationList(){ (void)new PluginItem( decorationList, "Qtopia" ); QStringList list = wdLoader->list(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { WindowDecorationInterface *iface = 0; if ( wdLoader->queryInterface( *it, IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { PluginItem *item = new PluginItem( decorationList, iface->name() ); item->setFilename( *it ); wdLoader->releaseInterface( iface ); } }}void AppearanceSettings::populateFontList(const QString& cur, int cursz){ FontDatabase fd; QStringList f = fd.families(); for ( QStringList::ConstIterator it=f.begin(); it!=f.end(); ++it ) { QString n = *it; n[0] = n[0].upper(); fontList->insertItem(n); if ( (*it).lower() == cur.lower() ) fontList->setCurrentItem(fontList->count()-1); } fontSize->insertItem( QString::number( cursz ) ); fontSelected( fontList->currentText() );}void AppearanceSettings::fixSampleGeometry(){ sample->fixGeometry(); sample->setUpdatesEnabled( TRUE ); sample->repaint( FALSE ); // repaint decoration}#include "appearance.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -