From: Manuel Nickschas Date: Wed, 26 Dec 2007 19:52:34 +0000 (+0000) Subject: Say hello to the first settings page in our shiny new, almost working SettingsDlg... X-Git-Tag: 0.1.0~20 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=4bfbd8dcbcb398302aaad0b6707c561760d7a7ac Say hello to the first settings page in our shiny new, almost working SettingsDlg (F7)! Now you can set the ChatWidget's fonts. To make this work, I made UiStyle (and automagically its derived classes) remember custom set formats. Also, default formats can be restored. This allows to change, save and restore all the style's formats at run-time... For now, in the settings dialog you can only edit the ChatWidget's base fonts, but later on we will certainly allow more tweaking of the current style. --- diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist index f6c3b0b8..07f5651b 100644 --- a/Quassel.kdevelop.filelist +++ b/Quassel.kdevelop.filelist @@ -161,8 +161,12 @@ src/qtui/serverlist.cpp src/qtui/serverlist.h src/qtui/settingsdlg.cpp src/qtui/settingsdlg.h +src/qtui/settingspages src/qtui/settingspages.cpp src/qtui/settingspages.h +src/qtui/settingspages/settingspages.pri +src/qtui/settingspages/sp_uistyle.cpp +src/qtui/settingspages/sp_uistyle.h src/qtui/topicwidget.cpp src/qtui/topicwidget.h src/qtui/ui @@ -179,6 +183,7 @@ src/qtui/ui/identitieseditdlg.ui src/qtui/ui/mainwin.ui src/qtui/ui/networkeditdlg.ui src/qtui/ui/nickeditdlg.ui +src/qtui/ui/nicklistwidget.ui src/qtui/ui/servereditdlg.ui src/qtui/ui/serverlistdlg.ui src/qtui/ui/settingsdlg.ui @@ -205,4 +210,6 @@ src/uisupport/uisettings.cpp src/uisupport/uisettings.h src/uisupport/uistyle.cpp src/uisupport/uistyle.h +src/uisupport/uistylesettings.cpp +src/uisupport/uistylesettings.h src/uisupport/uisupport.pri diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 3d43e0a5..0563ff7e 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -65,15 +65,21 @@ QStringList Settings::allLocalKeys() { return res; } -QStringList Settings::localChildKeys() { - beginGroup(group); +QStringList Settings::localChildKeys(const QString &rootkey) { + QString g; + if(rootkey.isEmpty()) g = group; + else g = QString("%1/%2").arg(group, rootkey); + beginGroup(g); QStringList res = childKeys(); endGroup(); return res; } -QStringList Settings::localChildGroups() { - beginGroup(group); +QStringList Settings::localChildGroups(const QString &rootkey) { + QString g; + if(rootkey.isEmpty()) g = group; + else g = QString("%1/%2").arg(group, rootkey); + beginGroup(g); QStringList res = childGroups(); endGroup(); return res; diff --git a/src/common/settings.h b/src/common/settings.h index fcf9cd5b..7142e722 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -30,16 +30,19 @@ class Settings : private QSettings { public: virtual ~Settings(); - static void setGuiValue(QString, QVariant) {}; - static QVariant guiValue(QString, QVariant = QVariant()) { return QVariant(); } + //static void setGuiValue(QString, QVariant) {}; + //static QVariant guiValue(QString, QVariant = QVariant()) { return QVariant(); } + + enum Mode { Default, Custom }; + protected: Settings(QString group = "General"); void setGroup(QString group); virtual QStringList allLocalKeys(); - virtual QStringList localChildKeys(); - virtual QStringList localChildGroups(); + virtual QStringList localChildKeys(const QString &rootkey = QString()); + virtual QStringList localChildGroups(const QString &rootkey = QString()); //virtual QStringList allSessionKeys() = 0; virtual QStringList sessionKeys() = 0; diff --git a/src/core/server.cpp b/src/core/server.cpp index b222b0d7..f29e3452 100644 --- a/src/core/server.cpp +++ b/src/core/server.cpp @@ -219,9 +219,11 @@ CoreSession *Server::coreSession() const { /* Exception classes for message handling */ Server::ParseError::ParseError(QString cmd, QString prefix, QStringList params) { + Q_UNUSED(prefix); _msg = QString("Command Parse Error: ") + cmd + params.join(" "); } Server::UnknownCmdError::UnknownCmdError(QString cmd, QString prefix, QStringList params) { - _msg = QString("Unknown Command: ") + cmd; + Q_UNUSED(prefix); + _msg = QString("Unknown Command: ") + cmd + params.join(" "); } diff --git a/src/qtopia/qtopiauistyle.cpp b/src/qtopia/qtopiauistyle.cpp index 88dd9216..5876eae1 100644 --- a/src/qtopia/qtopiauistyle.cpp +++ b/src/qtopia/qtopiauistyle.cpp @@ -19,13 +19,14 @@ ***************************************************************************/ #include "qtopiauistyle.h" +#include "settings.h" -QtopiaUiStyle::QtopiaUiStyle() : UiStyle() { +QtopiaUiStyle::QtopiaUiStyle() : UiStyle("QtopiaUiStyle") { QTextCharFormat def; def.setForeground(QBrush("#000000")); def.setFont(QFont("Verdana",5)); - setFormat(None, def); + setFormat(None, def, Settings::Default); // We need to just set our internal formats; everything else is done by the base class... @@ -33,81 +34,81 @@ QtopiaUiStyle::QtopiaUiStyle() : UiStyle() { QTextCharFormat plainMsg; plainMsg.setForeground(QBrush("#000000")); - setFormat(PlainMsg, plainMsg); + setFormat(PlainMsg, plainMsg, Settings::Default); QTextCharFormat notice; notice.setForeground(QBrush("#000080")); - setFormat(NoticeMsg, notice); + setFormat(NoticeMsg, notice, Settings::Default); QTextCharFormat server; server.setForeground(QBrush("#000080")); - setFormat(ServerMsg, server); + setFormat(ServerMsg, server, Settings::Default); QTextCharFormat error; error.setForeground(QBrush("#ff0000")); - setFormat(ErrorMsg, error); + setFormat(ErrorMsg, error, Settings::Default); QTextCharFormat join; join.setForeground(QBrush("#008000")); - setFormat(JoinMsg, join); + setFormat(JoinMsg, join, Settings::Default); QTextCharFormat part; part.setForeground(QBrush("#ff0000")); - setFormat(PartMsg, part); + setFormat(PartMsg, part, Settings::Default); QTextCharFormat quit; quit.setForeground(QBrush("#ff0000")); - setFormat(QuitMsg, quit); + setFormat(QuitMsg, quit, Settings::Default); QTextCharFormat kick; kick.setForeground(QBrush("#ff0000")); - setFormat(KickMsg, kick); + setFormat(KickMsg, kick, Settings::Default); QTextCharFormat nren; nren.setForeground(QBrush("#6a5acd")); - setFormat(RenameMsg, nren); + setFormat(RenameMsg, nren, Settings::Default); QTextCharFormat mode; mode.setForeground(QBrush("#4682b4")); - setFormat(ModeMsg, mode); + setFormat(ModeMsg, mode, Settings::Default); QTextCharFormat action; action.setFontItalic(true); action.setForeground(QBrush("#8b008b")); - setFormat(ActionMsg, action); + setFormat(ActionMsg, action, Settings::Default); // Internal message element formats QTextCharFormat ts; ts.setForeground(QBrush("#808080")); - setFormat(Timestamp, ts); + setFormat(Timestamp, ts, Settings::Default); QTextCharFormat sender; sender.setAnchor(true); sender.setForeground(QBrush("#000080")); - setFormat(Sender, sender); + setFormat(Sender, sender, Settings::Default); QTextCharFormat nick; nick.setAnchor(true); nick.setFontWeight(QFont::Bold); - setFormat(Nick, nick); + setFormat(Nick, nick, Settings::Default); QTextCharFormat hostmask; hostmask.setFontItalic(true); - setFormat(Hostmask, hostmask); + setFormat(Hostmask, hostmask, Settings::Default); QTextCharFormat channel; channel.setAnchor(true); channel.setFontWeight(QFont::Bold); - setFormat(ChannelName, channel); + setFormat(ChannelName, channel, Settings::Default); QTextCharFormat flags; flags.setFontWeight(QFont::Bold); - setFormat(ModeFlags, flags); + setFormat(ModeFlags, flags, Settings::Default); QTextCharFormat url; url.setFontUnderline(true); url.setAnchor(true); - setFormat(Url, url); + setFormat(Url, url, Settings::Default); } diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 10b2b98b..0d4453d5 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -27,7 +27,6 @@ #include "nicklistwidget.h" #include "serverlist.h" #include "settingsdlg.h" -//#include "settingspage.h" #include "signalproxy.h" #include "topicwidget.h" @@ -35,6 +34,8 @@ #include "selectionmodelsynchronizer.h" #include "mappedselectionmodel.h" +#include "settingspages/fontssettingspage.h" + MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) { ui.setupUi(this); setWindowTitle("Quassel IRC"); @@ -68,6 +69,7 @@ void MainWin::init() { setupMenus(); setupViews(); + setupSettingsDlg(); // create nick dock nickDock = new QDockWidget("Nicks", this); @@ -125,6 +127,7 @@ void MainWin::init() { ui.menuViews->addAction(dock->toggleViewAction()); + //showSettingsDlg(); } MainWin::~MainWin() { @@ -186,6 +189,11 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, netViews.append(dock); } +void MainWin::setupSettingsDlg() { + settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg)); + +} + void MainWin::connectedToCore() { foreach(BufferInfo id, Client::allBufferInfos()) { emit requestBacklog(id, 1000, -1); diff --git a/src/qtui/qtui.pri b/src/qtui/qtui.pri index cd283c50..c5aaab99 100644 --- a/src/qtui/qtui.pri +++ b/src/qtui/qtui.pri @@ -17,3 +17,11 @@ FORMNAMES = identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui n for(ui, FORMNAMES) { FRMS += ui/$${ui} } + +# Include settingspages +include(settingspages/settingspages.pri) +for(page, SETTINGSPAGES) { + SRCS += settingspages/$${page}settingspage.cpp + HDRS += settingspages/$${page}settingspage.h + FRMS += settingspages/$${page}settingspage.ui +} diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index 18a7407c..c96078ec 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -20,87 +20,87 @@ #include "qtuistyle.h" -QtUiStyle::QtUiStyle() : UiStyle() { +QtUiStyle::QtUiStyle() : UiStyle("QtUiStyle") { // We need to just set our internal formats; everything else is done by the base class... // Internal message formats QTextCharFormat plainMsg; plainMsg.setForeground(QBrush("black")); - setFormat(PlainMsg, plainMsg); + setFormat(PlainMsg, plainMsg, Settings::Default); QTextCharFormat notice; notice.setForeground(QBrush("navy")); - setFormat(NoticeMsg, notice); + setFormat(NoticeMsg, notice, Settings::Default); QTextCharFormat server; server.setForeground(QBrush("navy")); - setFormat(ServerMsg, server); + setFormat(ServerMsg, server, Settings::Default); QTextCharFormat error; error.setForeground(QBrush("red")); - setFormat(ErrorMsg, error); + setFormat(ErrorMsg, error, Settings::Default); QTextCharFormat join; join.setForeground(QBrush("green")); - setFormat(JoinMsg, join); + setFormat(JoinMsg, join, Settings::Default); QTextCharFormat part; part.setForeground(QBrush("indianred")); - setFormat(PartMsg, part); + setFormat(PartMsg, part, Settings::Default); QTextCharFormat quit; quit.setForeground(QBrush("indianred")); - setFormat(QuitMsg, quit); + setFormat(QuitMsg, quit, Settings::Default); QTextCharFormat kick; kick.setForeground(QBrush("indianred")); - setFormat(KickMsg, kick); + setFormat(KickMsg, kick, Settings::Default); QTextCharFormat nren; nren.setForeground(QBrush("magenta")); - setFormat(RenameMsg, nren); + setFormat(RenameMsg, nren, Settings::Default); QTextCharFormat mode; mode.setForeground(QBrush("steelblue")); - setFormat(ModeMsg, mode); + setFormat(ModeMsg, mode, Settings::Default); QTextCharFormat action; action.setFontItalic(true); action.setForeground(QBrush("darkmagenta")); - setFormat(ActionMsg, action); + setFormat(ActionMsg, action, Settings::Default); // Internal message element formats QTextCharFormat ts; ts.setForeground(QBrush("grey")); - setFormat(Timestamp, ts); + setFormat(Timestamp, ts, Settings::Default); QTextCharFormat sender; sender.setAnchor(true); sender.setForeground(QBrush("navy")); - setFormat(Sender, sender); + setFormat(Sender, sender, Settings::Default); QTextCharFormat nick; nick.setAnchor(true); nick.setFontWeight(QFont::Bold); - setFormat(Nick, nick); + setFormat(Nick, nick, Settings::Default); QTextCharFormat hostmask; hostmask.setFontItalic(true); - setFormat(Hostmask, hostmask); + setFormat(Hostmask, hostmask, Settings::Default); QTextCharFormat channel; channel.setAnchor(true); channel.setFontWeight(QFont::Bold); - setFormat(ChannelName, channel); + setFormat(ChannelName, channel, Settings::Default); QTextCharFormat flags; flags.setFontWeight(QFont::Bold); - setFormat(ModeFlags, flags); + setFormat(ModeFlags, flags, Settings::Default); QTextCharFormat url; url.setFontUnderline(true); url.setAnchor(true); - setFormat(Url, url); + setFormat(Url, url, Settings::Default); } diff --git a/src/qtui/settingsdlg.cpp b/src/qtui/settingsdlg.cpp index 422f64da..3945cd15 100644 --- a/src/qtui/settingsdlg.cpp +++ b/src/qtui/settingsdlg.cpp @@ -23,8 +23,8 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); - ui.settingsFrame->setWidgetResizable(true); - ui.settingsFrame->setWidget(ui.settingsStack); + //ui.settingsFrame->setWidgetResizable(true); + //ui.settingsFrame->setWidget(ui.settingsStack); ui.settingsTree->setRootIsDecorated(false); connect(ui.settingsTree, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelected())); @@ -33,7 +33,7 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) { void SettingsDlg::registerSettingsPage(SettingsPage *sp) { - sp->setParent(this); + sp->setParent(ui.settingsStack); ui.settingsStack->addWidget(sp); QTreeWidgetItem *cat; @@ -43,8 +43,11 @@ void SettingsDlg::registerSettingsPage(SettingsPage *sp) { cat->setExpanded(true); cat->setFlags(Qt::ItemIsEnabled); } else cat = cats[0]; - QTreeWidgetItem *p = new QTreeWidgetItem(cat, QStringList(sp->title())); + new QTreeWidgetItem(cat, QStringList(sp->title())); pages[QString("%1$%2").arg(sp->category(), sp->title())] = sp; + updateGeometry(); + // TESTING + //selectPage(sp->category(), sp->title()); } void SettingsDlg::selectPage(const QString &cat, const QString &title) { @@ -63,28 +66,45 @@ void SettingsDlg::itemSelected() { QString cat = parent->text(0); QString title = items[0]->text(0); selectPage(cat, title); + ui.pageTitle->setText(title); } } void SettingsDlg::buttonClicked(QAbstractButton *button) { - switch(ui.buttonBox->buttonRole(button)) { - case QDialogButtonBox::AcceptRole: + switch(ui.buttonBox->standardButton(button)) { + case QDialogButtonBox::Ok: applyChanges(); accept(); break; - case QDialogButtonBox::ApplyRole: + case QDialogButtonBox::Apply: applyChanges(); break; - case QDialogButtonBox::RejectRole: + case QDialogButtonBox::Cancel: reject(); break; + case QDialogButtonBox::Reset: + reload(); + break; + case QDialogButtonBox::RestoreDefaults: + loadDefaults(); + break; default: break; } } void SettingsDlg::applyChanges() { - //SettingsInterface *sp = qobject_cast(ui.settingsStack->currentWidget()); - //if(sp) sp->applyChanges(); + foreach(SettingsPage *page, pages.values()) { + page->save(); + } } +void SettingsDlg::reload() { + SettingsPage *page = qobject_cast(ui.settingsStack->currentWidget()); + if(page) page->load(); +} + +void SettingsDlg::loadDefaults() { + SettingsPage *page = qobject_cast(ui.settingsStack->currentWidget()); + if(page) page->defaults(); +} diff --git a/src/qtui/settingsdlg.h b/src/qtui/settingsdlg.h index c4640bde..d7dc6d83 100644 --- a/src/qtui/settingsdlg.h +++ b/src/qtui/settingsdlg.h @@ -40,6 +40,8 @@ class SettingsDlg : public QDialog { void itemSelected(); void buttonClicked(QAbstractButton *); void applyChanges(); + void reload(); + void loadDefaults(); private: Ui::SettingsDlg ui; diff --git a/src/qtui/settingspages/fontssettingspage.cpp b/src/qtui/settingspages/fontssettingspage.cpp new file mode 100644 index 00000000..3a9843e3 --- /dev/null +++ b/src/qtui/settingspages/fontssettingspage.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * 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. * + * * + * 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "fontssettingspage.h" + +#include "qtui.h" + +#include + +FontsSettingsPage::FontsSettingsPage(QWidget *parent) + : SettingsPage(tr("Appearance"), tr("Fonts"), parent) { + + ui.setupUi(this); + mapper = new QSignalMapper(this); + connect(ui.chooseGeneral, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseTopic, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseNickList, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseBufferView, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseChatMessages, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseNicks, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseTimestamp, SIGNAL(clicked()), mapper, SLOT(map())); + + mapper->setMapping(ui.chooseGeneral, ui.demoGeneral); + mapper->setMapping(ui.chooseTopic, ui.demoTopic); + mapper->setMapping(ui.chooseNickList, ui.demoNickList); + mapper->setMapping(ui.chooseBufferView, ui.demoBufferView); + mapper->setMapping(ui.chooseChatMessages, ui.demoChatMessages); + mapper->setMapping(ui.chooseNicks, ui.demoNicks); + mapper->setMapping(ui.chooseTimestamp, ui.demoTimestamp); + + connect(mapper, SIGNAL(mapped(QWidget *)), this, SLOT(chooseFont(QWidget *))); + + load(); + +} + +bool FontsSettingsPage::hasChanged() const { + + return false; +} + +void FontsSettingsPage::defaults() { + load(Settings::Default); + +} + +void FontsSettingsPage::load() { + load(Settings::Custom); + changeState(false); +} + +void FontsSettingsPage::load(Settings::Mode mode) { + QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode); + setFont(ui.demoChatMessages, chatFormat.font()); + QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender, mode); + if(nicksFormat.hasProperty(QTextFormat::FontFamily)) { + setFont(ui.demoNicks, nicksFormat.font()); + ui.checkNicks->setChecked(true); + } else { + setFont(ui.demoNicks, chatFormat.font()); + ui.checkNicks->setChecked(false); + } + QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp, mode); + if(timestampFormat.hasProperty(QTextFormat::FontFamily)) { + setFont(ui.demoTimestamp, timestampFormat.font()); + ui.checkTimestamp->setChecked(true); + } else { + setFont(ui.demoTimestamp, chatFormat.font()); + ui.checkTimestamp->setChecked(false); + } + +} + +void FontsSettingsPage::save() { + QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None); + chatFormat.setFont(ui.demoChatMessages->font()); + QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom); + if(ui.checkNicks->checkState() == Qt::Checked) { + QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender); + nicksFormat.setFont(ui.demoNicks->font()); + QtUi::style()->setFormat(UiStyle::Sender, nicksFormat, Settings::Custom); + } + if(ui.checkTimestamp->checkState() == Qt::Checked) { + QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp); + timestampFormat.setFont(ui.demoTimestamp->font()); + QtUi::style()->setFormat(UiStyle::Timestamp, timestampFormat, Settings::Custom); + } + changeState(false); +} + +void FontsSettingsPage::setFont(QLabel *label, const QFont &font) { + QFontInfo fontInfo(font); + label->setFont(font); + label->setText(QString("%1 %2").arg(fontInfo.family()).arg(fontInfo.pointSize())); +} + +void FontsSettingsPage::chooseFont(QWidget *widget) { + QLabel *label = qobject_cast(widget); + Q_ASSERT(label); + bool ok; + QFont font = QFontDialog::getFont(&ok, label->font()); + if(ok) { + setFont(label, font); + } +} diff --git a/src/qtui/settingspages/fontssettingspage.h b/src/qtui/settingspages/fontssettingspage.h new file mode 100644 index 00000000..7928cb8d --- /dev/null +++ b/src/qtui/settingspages/fontssettingspage.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * 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. * + * * + * 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _FONTSSETTINGSPAGE_H_ +#define _FONTSSETTINGSPAGE_H_ + +#include "settings.h" +#include "settingspage.h" + +#include "ui_fontssettingspage.h" + +class QSignalMapper; + +class FontsSettingsPage : public SettingsPage { + Q_OBJECT + + public: + FontsSettingsPage(QWidget *parent = 0); + + bool hasChanged() const; + + public slots: + void save(); + void load(); + void defaults(); + + private slots: + void load(Settings::Mode mode); + void setFont(QLabel *label, const QFont &font); + void chooseFont(QWidget *label); + + private: + Ui::FontsSettingsPage ui; + + QSignalMapper *mapper; + +}; + +#endif diff --git a/src/qtui/settingspages/fontssettingspage.ui b/src/qtui/settingspages/fontssettingspage.ui new file mode 100644 index 00000000..d6abdec7 --- /dev/null +++ b/src/qtui/settingspages/fontssettingspage.ui @@ -0,0 +1,550 @@ + + FontsSettingsPage + + + + 0 + 0 + 524 + 400 + + + + Form + + + + + + false + + + Custom Application Fonts + + + true + + + false + + + + + + + + General: + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Topic: + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Buffer Views: + + + true + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Nick List: + + + true + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + + + + + + Chat Widget + + + + + + + + General: + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Nicks: + + + true + + + + + + + Timestamp: + + + true + + + + + + + + + + + + + true + + + + Some of these settings require a restart of the Quassel Client in order to take effect. We intend to fix this. + + + true + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + + + checkTimestamp + toggled(bool) + demoTimestamp + setEnabled(bool) + + + 46 + 292 + + + 183 + 290 + + + + + checkTimestamp + toggled(bool) + chooseTimestamp + setEnabled(bool) + + + 96 + 288 + + + 452 + 293 + + + + + checkBufferView + toggled(bool) + demoBufferView + setEnabled(bool) + + + 32 + 116 + + + 215 + 117 + + + + + checkBufferView + toggled(bool) + chooseBufferView + setEnabled(bool) + + + 86 + 113 + + + 451 + 118 + + + + + checkNickList + toggled(bool) + demoNickList + setEnabled(bool) + + + 69 + 147 + + + 199 + 151 + + + + + checkNickList + toggled(bool) + chooseNickList + setEnabled(bool) + + + 78 + 145 + + + 455 + 151 + + + + + checkTopic + toggled(bool) + demoTopic + setEnabled(bool) + + + 34 + 81 + + + 190 + 87 + + + + + checkTopic + toggled(bool) + chooseTopic + setEnabled(bool) + + + 101 + 81 + + + 451 + 82 + + + + + checkNicks + toggled(bool) + demoNicks + setEnabled(bool) + + + 40 + 255 + + + 211 + 257 + + + + + checkNicks + toggled(bool) + chooseNicks + setEnabled(bool) + + + 89 + 257 + + + 447 + 258 + + + + + diff --git a/src/qtui/settingspages/settingspages.pri b/src/qtui/settingspages/settingspages.pri new file mode 100644 index 00000000..8ee87a21 --- /dev/null +++ b/src/qtui/settingspages/settingspages.pri @@ -0,0 +1 @@ +SETTINGSPAGES = fonts diff --git a/src/qtui/ui/settingsdlg.ui b/src/qtui/ui/settingsdlg.ui index 8d87a7c1..ed001158 100644 --- a/src/qtui/ui/settingsdlg.ui +++ b/src/qtui/ui/settingsdlg.ui @@ -5,8 +5,8 @@ 0 0 - 784 - 558 + 742 + 502 @@ -25,35 +25,56 @@ 0 + + + 200 + 16777215 + + Settings - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - + - - - - 0 - 0 - + + + + 75 + true + + + + Settings + + + + + + + Qt::Horizontal + + + + + + + QFrame::StyledPanel + + + QFrame::Raised - + + + + + + + + @@ -66,7 +87,7 @@ Qt::Horizontal - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::Reset + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index 0417751c..7469454a 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -23,6 +23,7 @@ SettingsPage::SettingsPage(const QString &category, const QString &title, QWidget *parent) : QWidget(parent), _category(category), _title(title) { + _changed = false; } QString SettingsPage::category() const { @@ -34,9 +35,10 @@ QString SettingsPage::title() const { } void SettingsPage::changed() { + _changed = true; emit changed(true); } void SettingsPage::changeState(bool hasChanged) { - emit changed(hasChanged); + if(hasChanged != _changed) emit changed(hasChanged); } diff --git a/src/uisupport/settingspage.h b/src/uisupport/settingspage.h index 91171df6..b85fa504 100644 --- a/src/uisupport/settingspage.h +++ b/src/uisupport/settingspage.h @@ -53,6 +53,7 @@ class SettingsPage : public QWidget { private: QString _category, _title; + bool _changed; }; #endif diff --git a/src/uisupport/uisettings.cpp b/src/uisupport/uisettings.cpp index 2851644b..ad04720e 100644 --- a/src/uisupport/uisettings.cpp +++ b/src/uisupport/uisettings.cpp @@ -20,7 +20,7 @@ #include "uisettings.h" -UiSettings::UiSettings() : ClientSettings("UI") { +UiSettings::UiSettings(const QString &group) : ClientSettings(group) { } diff --git a/src/uisupport/uisettings.h b/src/uisupport/uisettings.h index 282190d5..1476f90a 100644 --- a/src/uisupport/uisettings.h +++ b/src/uisupport/uisettings.h @@ -26,7 +26,7 @@ class UiSettings : public ClientSettings { public: - UiSettings(); + UiSettings(const QString &group = "UI"); void setValue(const QString &key, const QVariant &data); QVariant value(const QString &key, const QVariant &def = QVariant()); diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 5d02db32..1740185b 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -19,14 +19,21 @@ ***************************************************************************/ #include "uistyle.h" +#include "uistylesettings.h" -UiStyle::UiStyle() { +UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) { // Default format QTextCharFormat def; def.setForeground(QBrush("#000000")); - def.setFont(QFont("Verdana",9)); - - _formats = QVector(NumFormatTypes, def); + def.setFont(QFont("Mono",12)); + _defaultFormats = QVector(NumFormatTypes, def); + _customFormats = QVector(NumFormatTypes, QTextFormat().toCharFormat()); + + // Load saved custom formats + UiStyleSettings s(_settingsKey); + foreach(FormatType type, s.availableFormats()) { + _customFormats[type] = s.customFormat(type); + } // Initialize color codes according to mIRC "standard" QStringList colors; @@ -68,19 +75,19 @@ UiStyle::UiStyle() { _formatCodes[QString("%Dcf%1").arg(idx)] = (FormatType)(FgCol00 + i); _formatCodes[QString("%Dcb%1").arg(idx)] = (FormatType)(BgCol00 + i); QTextCharFormat fgf, bgf; - fgf.setForeground(QBrush(QColor(colors[i]))); _formats[FgCol00 + i] = fgf; - bgf.setBackground(QBrush(QColor(colors[i]))); _formats[BgCol00 + i] = bgf; + fgf.setForeground(QBrush(QColor(colors[i]))); setFormat((FormatType)(FgCol00 + i), fgf, Settings::Default); + bgf.setBackground(QBrush(QColor(colors[i]))); setFormat((FormatType)(BgCol00 + i), bgf, Settings::Default); } // Set a few more standard formats QTextCharFormat bold; bold.setFontWeight(QFont::Bold); - setFormat(Bold, bold); + setFormat(Bold, bold, Settings::Default); QTextCharFormat italic; italic.setFontItalic(true); - setFormat(Italic, italic); + setFormat(Italic, italic, Settings::Default); QTextCharFormat underline; underline.setFontUnderline(true); - setFormat(Underline, underline); + setFormat(Underline, underline, Settings::Default); // All other formats should be defined in derived classes. } @@ -89,12 +96,24 @@ UiStyle::~ UiStyle() { } -void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt) { - _formats[ftype] = fmt; +void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt, Settings::Mode mode) { + if(mode == Settings::Default) { + _defaultFormats[ftype] = fmt; + } else { + UiStyleSettings s(_settingsKey); + if(fmt != _defaultFormats[ftype]) { + _customFormats[ftype] = fmt; + s.setCustomFormat(ftype, fmt); + } else { + _customFormats[ftype] = QTextFormat().toCharFormat(); + s.removeCustomFormat(ftype); + } + } } -QTextCharFormat UiStyle::format(FormatType ftype) const { - return _formats[ftype]; +QTextCharFormat UiStyle::format(FormatType ftype, Settings::Mode mode) const { + if(mode == Settings::Custom && _customFormats[ftype].isValid()) return _customFormats[ftype]; + else return _defaultFormats[ftype]; } UiStyle::FormatType UiStyle::formatType(const QString & code) const { diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index 3da2925a..a80af5e0 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -26,11 +26,12 @@ #include #include "message.h" +#include "settings.h" class UiStyle { public: - UiStyle(); + UiStyle(const QString &settingsKey); virtual ~UiStyle(); /** This enumerates the possible formats a text element may have. */ @@ -59,8 +60,8 @@ class UiStyle { StyledText styleString(QString); - void setFormat(FormatType, QTextCharFormat); - QTextCharFormat format(FormatType) const; + void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/); + QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const; FormatType formatType(const QString &code) const; QString formatCode(FormatType) const; @@ -71,9 +72,12 @@ class UiStyle { private: QTextCharFormat mergedFormat(QList); - QVector _formats; + QVector _defaultFormats; + QVector _customFormats; QHash _formatCodes; + QString _settingsKey; + }; #endif diff --git a/src/uisupport/uistylesettings.cpp b/src/uisupport/uistylesettings.cpp new file mode 100644 index 00000000..73d21cf0 --- /dev/null +++ b/src/uisupport/uistylesettings.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * 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. * + * * + * 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "uistylesettings.h" + +UiStyleSettings::UiStyleSettings(const QString &group) : ClientSettings(group) { + +} + +void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, QTextCharFormat format) { + setLocalValue(QString("Format/%1").arg(ftype), format); +} + +QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) { + return localValue(QString("Format/%1").arg(ftype), QTextFormat()).value().toCharFormat(); +} + +void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype) { + removeLocalKey(QString("Format/%1").arg(ftype)); +} + +QList UiStyleSettings::availableFormats() { + QList formats; + QStringList list = localChildKeys("Format"); + foreach(QString type, list) { + formats << (UiStyle::FormatType)type.toInt(); + } + return formats; +} + diff --git a/src/uisupport/uistylesettings.h b/src/uisupport/uistylesettings.h new file mode 100644 index 00000000..c09e3c7d --- /dev/null +++ b/src/uisupport/uistylesettings.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * 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. * + * * + * 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _UISTYLESETTINGS_H_ +#define _UISTYLESETTINGS_H_ + +#include "clientsettings.h" +#include "uistyle.h" + +class UiStyleSettings : public ClientSettings { + + public: + UiStyleSettings(const QString &group = "UiStyle"); + + void setCustomFormat(UiStyle::FormatType, QTextCharFormat); + QTextCharFormat customFormat(UiStyle::FormatType); + + void removeCustomFormat(UiStyle::FormatType); + QList availableFormats(); + + private: + +}; + +#endif diff --git a/src/uisupport/uisupport.pri b/src/uisupport/uisupport.pri index a67affbd..f7f0e89e 100644 --- a/src/uisupport/uisupport.pri +++ b/src/uisupport/uisupport.pri @@ -1,8 +1,8 @@ DEPMOD = common client QT_MOD = core gui network -SRCS += bufferview.cpp bufferviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp -HDRS += bufferview.h bufferviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h +SRCS += bufferview.cpp bufferviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp uistylesettings.cpp +HDRS += bufferview.h bufferviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h uistylesettings.h FORMNAMES =