📄 appearance.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "appearance.h"#ifndef QTOPIA_PHONE# include "samplewindow.h"#endif#include "themeparser.h"#include <qtopia/global.h>#include <qtopia/fontdatabase.h>#include <qtopia/config.h>#include <qtopia/applnk.h>#include <qtopia/qpeapplication.h>#include <qtopia/pluginloader.h>#include <qtopia/styleinterface.h>#include <qtopia/resource.h>#include <qtopia/image.h>#include <qtopia/imageselector.h>#include <qtopia/windowdecorationinterface.h>#if defined(Q_WS_QWS) && !defined(QT_NO_COP)#include <qtopia/qcopenvelope_qws.h>#endif#ifdef QTOPIA_PHONE# include <qtopia/private/phonedecoration_p.h># include <qtopia/contextbar.h># include <qtopia/phonestyle.h>#else# include <qtopia/qpestyle.h>#endif#include <qlabel.h>#include <qcheckbox.h>#include <qradiobutton.h>#include <qtabwidget.h>#include <qslider.h>#include <qfile.h>#include <qtextstream.h>#include <qdatastream.h>#include <qmessagebox.h>#include <qcombobox.h>#include <qlistbox.h>#include <qdir.h>#include <qgroupbox.h>#include <qwindowsstyle.h>#include <qobjectlist.h>#include <qlayout.h>#include <qvbox.h>#include <qmenubar.h>#include <qpushbutton.h>#include <qcheckbox.h>#include <qwhatsthis.h>#include <qpixmapcache.h>#if QT_VERSION >= 0x030000#include <qstylefactory.h>#endif#include <qaccel.h>#include <qpixmap.h>//#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX)//#include <unistd.h>//#include <linux/fb.h>//#include <sys/types.h>//#include <sys/stat.h>//#include <fcntl.h>//#include <sys/ioctl.h>//#endif#include <stdlib.h>#define SAMPLE_HEIGHT 115class PluginItem : public QListBoxText{public: PluginItem( QListBox *lb, const QString &t ) : QListBoxText( lb, t ) {} void setFilename( const QString fn ) { file = fn; } const QString &filename() const { return file; } void setThemeFilename( const QString fn ) { themeFile = fn; } const QString &themeFilename() const { return themeFile; } void setDecorationFilename( const QString fn ) { decorationFile = fn; } const QString &decorationFilename() const { return decorationFile; }private: QString file; QString themeFile; QString decorationFile;};class FontItem : public QListBoxText{public: FontItem(QListBox *lb, const QString &t, const QFont &f) : QListBoxText( lb, t ), fnt(f) {} int height(const QListBox *) const { return 20; }protected: void paint(QPainter *p) { p->setFont(fnt); QListBoxText::paint(p); }private: QFont fnt;};//===========================================================================class DefaultWindowDecoration : public WindowDecorationInterface{public: DefaultWindowDecoration() : ref(0) {} QString name() const { return qApp->translate("WindowDecoration", "Default", "List box text for default window decoration"); } QPixmap icon() const { return QPixmap(); } QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_WindowDecoration ) *iface = this; if ( *iface ) (*iface)->addRef(); return QS_OK; } Q_REFCOUNTprivate: ulong ref;};//===========================================================================AppearanceSettings::AppearanceSettings( QWidget* parent, const char* name, WFlags fl ) : AppearanceSettingsBase( parent, name, TRUE, fl|Qt::WStyle_ContextHelp ){ wdiface = 0; styleiface = 0; wdLoader = new PluginLoader( "decorations" ); styleLoader = new PluginLoader( "styles" ); wdIsPlugin = FALSE;#ifdef DEBUG maxFontSize = 24;#else maxFontSize = qApp->desktop()->width() >= 640 ? 24 : 12;#endif#ifdef QTOPIA_PHONE tabWidget->removePage(tab_3); tabWidget->removePage(tab_4); tabWidget->setFocusPolicy(NoFocus); AppearanceSettingsBaseLayout->setMargin(0); tabWidget->changeTab(tab, Resource::loadIconSet("theme"), QString::null); tabWidget->changeTab(tab_2, Resource::loadIconSet("color"), QString::null); tabWidget->changeTab(tab_5, Resource::loadIconSet("font"), QString::null); tabWidget->changeTab(tab_6, Resource::loadIconSet("background"), QString::null); tabLayout->setMargin(0); tabLayout_2->setMargin(0); tabLayout_5->setMargin(0);#ifdef QTOPIA_PHONE themeList->setFrameStyle(QFrame::NoFrame);#endif colorList->setFrameStyle(QFrame::NoFrame); fontList->setFrameStyle(QFrame::NoFrame); QAccel *accel = new QAccel(this); connect(accel, SIGNAL(activated(int)), this, SLOT(accelerator(int))); accel->insertItem(Key_Left, Key_Left); accel->insertItem(Key_Right, Key_Right);#else sample = new SampleWindow( this ); AppearanceSettingsBaseLayout->addWidget( sample ); populateStyleList(); populateDecorationList();#endif#ifdef QTOPIA_PHONE populateThemeList();#endif populateColorList(); Config config("qpe"); config.setGroup( "Appearance" ); QString s = config.readEntry( "Scheme", "Qtopia" ); connect( colorList, SIGNAL(highlighted(int)), this, SLOT(colorSelected(int)) ); colorList->setCurrentItem( colorListIDs.findIndex(s) );#ifdef QTOPIA_PHONE QString t = config.readEntry( "Theme"); int themeMatchIndex = -1; for ( unsigned i = 0; i < themeList->count(); i++ ) { PluginItem *item = (PluginItem*)themeList->item(i); if (item->themeFilename() == t && themeMatchIndex == -1) themeMatchIndex = i; } if (themeMatchIndex != -1){ themeList->setSelected( themeMatchIndex, TRUE ); themeSelected(themeMatchIndex); } connect( themeList, SIGNAL(highlighted(int)), this, SLOT(themeSelected(int)) );#else 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( "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() );#endif 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&)) );#ifndef QTOPIA_PHONE connect( fontSize, SIGNAL(activated(const QString&)), this, SLOT(fontSizeSelected(const QString&)) );#else fontSizeLabel->hide(); fontSize->hide(); ContextBar::setLabel(themeList, Key_Select, ContextBar::NoLabel); ContextBar::setLabel(colorList, Key_Select, ContextBar::NoLabel); ContextBar::setLabel(styleList, Key_Select, ContextBar::NoLabel); ContextBar::setLabel(fontList, Key_Select, ContextBar::NoLabel); previewLabel->installEventFilter(this); bgTimer = new QTimer(this); connect(bgTimer, SIGNAL(timeout()), this, SLOT(updateBackground()));#endif#ifdef QTOPIA_PHONE bgImgName = config.readEntry("BackgroundImage"); if ( !bgImgName.isEmpty() && bgImgName[0]!='/' ) bgImgName = Resource::findPixmap("wallpaper/"+bgImgName); connect(myPictures, SIGNAL(clicked()), this, SLOT(selectImage())); connect(wallpaper, SIGNAL(clicked()), this, SLOT(selectWallpaper())); connect(clearButton, SIGNAL(clicked()), this, SLOT(clearBackground()));#endif}AppearanceSettings::~AppearanceSettings(){ delete styleLoader; delete wdLoader;}void AppearanceSettings::accept(){ Config config("qpe"); config.setGroup( "Appearance" ); QString s;#ifdef QTOPIA_PHONE PluginItem *item = (PluginItem *)themeList->item( themeList->currentItem() ); if ( item ) { if (!item->themeFilename().isEmpty() && (item->themeFilename() != item->text()) ){ config.writeEntry( "Style", item->filename() ); config.writeEntry("Theme", item->themeFilename()); config.writeEntry("DecorationTheme", item->decorationFilename()); qDebug("Write config theme select %s %s", item->filename().latin1(), item->text().latin1()); }else{ s = item->themeFilename().isEmpty() ? item->text() : item->themeFilename();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -