From: Manuel Nickschas Date: Mon, 16 Feb 2009 09:42:17 +0000 (+0100) Subject: Move font settings to general appearance settingspage X-Git-Tag: 0.4.0~23 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=c14a00f37179e49f034dc64b4da0c86b51caed5d Move font settings to general appearance settingspage This retires our old fonts settingspage for now, since most of what was on there didn't work anyway. You can now choose fonts for the ChatView, the input line and (this is brandnew!1!!) the buffer views and nick list. Also added tooltips for that settingspage and changed the wording a bit. --- diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index cd48764d..299ebce0 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -44,11 +44,12 @@ InputWidget::InputWidget(QWidget *parent) ui.ownNick->installEventFilter(new MouseWheelFilter(this)); ui.inputEdit->installEventFilter(new JumpKeyHandler(this)); - QtUiSettings s; - bool useInputLineFont = s.value("UseInputLineFont", QVariant(false)).toBool(); - if(useInputLineFont) { - ui.inputEdit->setFont(s.value("InputLineFont").value()); - } + QtUiStyleSettings s("Fonts"); + s.notify("InputLine", this, SLOT(setFont(QVariant))); + QFont font = s.value("InputLine", QFont()).value(); + if(font.family().isEmpty()) + font = QApplication::font(); + setFont(font); ActionCollection *coll = QtUi::actionCollection(); @@ -61,6 +62,13 @@ InputWidget::InputWidget(QWidget *parent) InputWidget::~InputWidget() { } +void InputWidget::setCustomFont(const QVariant &v) { + QFont font = v.value(); + if(font.family().isEmpty()) + font = QApplication::font(); + ui.inputEdit->setFont(font); +} + void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { Q_UNUSED(previous) NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value(); diff --git a/src/qtui/inputwidget.h b/src/qtui/inputwidget.h index 89fe3938..297830b9 100644 --- a/src/qtui/inputwidget.h +++ b/src/qtui/inputwidget.h @@ -48,6 +48,7 @@ protected slots: virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); private slots: + void setCustomFont(const QVariant &font); void sendText(QString text); void changeNick(const QString &newNick) const; diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 53324dde..2b758d50 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -89,7 +89,6 @@ #include "settingspages/bufferviewsettingspage.h" #include "settingspages/chatmonitorsettingspage.h" #include "settingspages/colorsettingspage.h" -#include "settingspages/fontssettingspage.h" #include "settingspages/generalsettingspage.h" #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" @@ -724,7 +723,6 @@ void MainWin::showSettingsDlg() { //Category: Appearance dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General dlg->registerSettingsPage(new ColorSettingsPage(dlg)); - dlg->registerSettingsPage(new FontsSettingsPage(dlg)); dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); dlg->registerSettingsPage(new BacklogSettingsPage(dlg)); diff --git a/src/qtui/settingspages/appearancesettingspage.cpp b/src/qtui/settingspages/appearancesettingspage.cpp index 91e32a01..c6a8b455 100644 --- a/src/qtui/settingspages/appearancesettingspage.cpp +++ b/src/qtui/settingspages/appearancesettingspage.cpp @@ -24,9 +24,12 @@ #include "chatviewsettings.h" #include "qtui.h" #include "qtuisettings.h" +#include "qtuistyle.h" #include "util.h" #include +#include +#include #include AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) @@ -47,6 +50,17 @@ AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) foreach(QCheckBox *checkBox, findChildren()) { connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); } + + mapper = new QSignalMapper(this); + connect(mapper, SIGNAL(mapped(QWidget *)), this, SLOT(chooseFont(QWidget *))); + + connect(ui.chooseChatView, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseBufferView, SIGNAL(clicked()), mapper, SLOT(map())); + connect(ui.chooseInputLine, SIGNAL(clicked()), mapper, SLOT(map())); + + mapper->setMapping(ui.chooseChatView, ui.demoChatView); + mapper->setMapping(ui.chooseBufferView, ui.demoBufferView); + mapper->setMapping(ui.chooseInputLine, ui.demoInputLine); } void AppearanceSettingsPage::initStyleComboBox() { @@ -67,12 +81,13 @@ void AppearanceSettingsPage::initLanguageComboBox() { _locales << locale; ui.languageComboBox->addItem(QLocale::languageToString(locale.language())); } - } void AppearanceSettingsPage::defaults() { ui.styleComboBox->setCurrentIndex(0); + loadFonts(Settings::Default); + _fontsChanged = true; widgetHasChanged(); } @@ -104,9 +119,30 @@ void AppearanceSettingsPage::load() { BufferSettings bufferSettings; SettingsPage::load(ui.showUserStateIcons, bufferSettings.showUserStateIcons()); + loadFonts(Settings::Custom); + setChangedState(false); } +void AppearanceSettingsPage::loadFonts(Settings::Mode mode) { + QtUiStyleSettings s("Fonts"); + + QFont inputLineFont; + if(mode == Settings::Custom) + inputLineFont = s.value("InputLine", QFont()).value(); + setFont(ui.demoInputLine, inputLineFont); + + QFont bufferViewFont; + if(mode == Settings::Custom) + bufferViewFont = s.value("BufferView", QFont()).value(); + setFont(ui.demoBufferView, bufferViewFont); + + QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode); + setFont(ui.demoChatView, chatFormat.font()); + + _fontsChanged = false; +} + void AppearanceSettingsPage::save() { QtUiSettings uiSettings; @@ -128,6 +164,24 @@ void AppearanceSettingsPage::save() { BufferSettings bufferSettings; bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked()); + // Fonts + QtUiStyleSettings fontSettings("Fonts"); + if(ui.demoInputLine->font() != QApplication::font()) + fontSettings.setValue("InputLine", ui.demoInputLine->font()); + else + fontSettings.setValue("InputLine", ""); + + if(ui.demoBufferView->font() != QApplication::font()) + fontSettings.setValue("BufferView", ui.demoBufferView->font()); + else + fontSettings.setValue("BufferView", ""); + + QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None); + chatFormat.setFont(ui.demoChatView->font()); + QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom); + + _fontsChanged = false; + load(); setChangedState(false); } @@ -145,11 +199,33 @@ QLocale AppearanceSettingsPage::selectedLocale() const { return locale; } +void AppearanceSettingsPage::setFont(QLabel *label, const QFont &font_) { + QFont font = font_; + if(font.family().isEmpty()) + font = QApplication::font(); + label->setFont(font); + label->setText(QString("%1 %2").arg(font.family()).arg(font.pointSize())); + widgetHasChanged(); +} + +void AppearanceSettingsPage::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); + _fontsChanged = true; + } +} + void AppearanceSettingsPage::widgetHasChanged() { setChangedState(testHasChanged()); } bool AppearanceSettingsPage::testHasChanged() { + if(_fontsChanged) return true; // comparisons are nasty for now + if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true; if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation()) @@ -158,7 +234,3 @@ bool AppearanceSettingsPage::testHasChanged() { return false; } - - - - diff --git a/src/qtui/settingspages/appearancesettingspage.h b/src/qtui/settingspages/appearancesettingspage.h index 9cbfc192..c3e51a94 100644 --- a/src/qtui/settingspages/appearancesettingspage.h +++ b/src/qtui/settingspages/appearancesettingspage.h @@ -24,10 +24,14 @@ #include #include #include +#include +#include "settings.h" #include "settingspage.h" #include "ui_appearancesettingspage.h" +class QSignalMapper; + class AppearanceSettingsPage : public SettingsPage { Q_OBJECT @@ -40,19 +44,26 @@ public slots: void save(); void load(); void defaults(); - + private slots: void widgetHasChanged(); - -private: - Ui::AppearanceSettingsPage ui; - QHash settings; - QList _locales; + void loadFonts(Settings::Mode mode); + void setFont(QLabel *label, const QFont &font); + void chooseFont(QWidget *label); + +private: bool testHasChanged(); void initStyleComboBox(); void initLanguageComboBox(); QLocale selectedLocale() const; + void clearFontFromFormat(QTextCharFormat &fmt); + + Ui::AppearanceSettingsPage ui; + QHash settings; + QList _locales; + QSignalMapper *mapper; + bool _fontsChanged; }; #endif diff --git a/src/qtui/settingspages/appearancesettingspage.ui b/src/qtui/settingspages/appearancesettingspage.ui index bc1e26b6..a988b837 100644 --- a/src/qtui/settingspages/appearancesettingspage.ui +++ b/src/qtui/settingspages/appearancesettingspage.ui @@ -1,54 +1,208 @@ - + + AppearanceSettingsPage - - + + 0 0 - 396 - 324 + 521 + 447 - + Form - + - - - Client style: + + + Client Style - + - + + + Set application style + + - - - Language: + + + Language - + - + + + Set the application language. Requires restart! + - - <System Default> + + <System Default> - - <Original> + + <Original> - - - - Note: needs client restart for full effect! + + + + + + + Fonts + + + + + + Set font for the main chat window and the chat monitor + + + Chat window: + + + + + + + + 0 + 0 + + + + Set font for the main chat window and the chat monitor + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Set font for channel and nick lists + + + Channel list: + + + + + + + + 0 + 0 + + + + Set font for channel and nick lists + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... + + + + + + + Set font for the input line + + + Input line: + + + + + + + + 0 + 0 + + + + Set font for the input line + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Font + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Choose... @@ -56,27 +210,33 @@ - - - Misc: + + + Misc - + - - - Show Web Previews + + + Show a website preview window when hovering the mouse over a web address + + + Show previews of webpages on URL hover - + true - - - Use Icons to represent away state of Users + + + Show status icons in channel and nick lists + + + Use icons in channel and nick lists - + true @@ -85,11 +245,11 @@ - - + + Qt::Vertical - + 20 40 diff --git a/src/qtui/settingspages/settingspages.inc b/src/qtui/settingspages/settingspages.inc index f33ac22e..d4ccb4d0 100644 --- a/src/qtui/settingspages/settingspages.inc +++ b/src/qtui/settingspages/settingspages.inc @@ -1,7 +1,7 @@ # Putting $FOO in SETTINGSPAGES automatically includes # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui -set(SETTINGSPAGES aliases appearance backlog bufferview color chatmonitor fonts general highlight identities networks) +set(SETTINGSPAGES aliases appearance backlog bufferview color chatmonitor general highlight identities networks) # Specify additional files (e.g. for subdialogs) here! set(SP_SOURCES aliasesmodel.cpp identityeditwidget.cpp notificationssettingspage.cpp) diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index ccea4e8c..d6c11069 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -60,6 +60,10 @@ BufferView::BufferView(QWidget *parent) BufferViewDelegate *tristateDelegate = new BufferViewDelegate(this); setItemDelegate(tristateDelegate); delete oldDelegate; + + UiStyleSettings s("QtUiStyle/Fonts"); // li'l dirty here, but fonts are stored in QtUiStyle :/ + s.notify("BufferView", this, SLOT(setCustomFont(QVariant))); + setCustomFont(s.value("BufferView", QFont())); } void BufferView::init() { @@ -188,6 +192,13 @@ void BufferView::setRootIndexForNetworkId(const NetworkId &networkId) { } } +void BufferView::setCustomFont(const QVariant &v) { + QFont font = v.value(); + if(font.family().isEmpty()) + font = QApplication::font(); + setFont(font); +} + void BufferView::joinChannel(const QModelIndex &index) { BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value(); diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index 419f33b1..f72b7a6c 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -81,6 +81,8 @@ private slots: void on_configChanged(); + void setCustomFont(const QVariant &font); + private: QPointer _config; diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index e27640e3..bbb36a75 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -20,6 +20,7 @@ #include "nickview.h" +#include #include #include #include @@ -66,6 +67,10 @@ NickView::NickView(QWidget *parent) // afaik this is better on Mac and Windows connect(this, SIGNAL(activated(QModelIndex)), SLOT(startQuery(QModelIndex))); #endif + + UiStyleSettings s("QtUiStyle/Fonts"); // li'l dirty here, but fonts are stored in QtUiStyle :/ + s.notify("BufferView", this, SLOT(setCustomFont(QVariant))); // yes, we share the BufferView settings + setCustomFont(s.value("BufferView", QFont())); } void NickView::init() { @@ -87,6 +92,13 @@ void NickView::setModel(QAbstractItemModel *model_) { init(); } +void NickView::setCustomFont(const QVariant &v) { + QFont font = v.value(); + if(font.family().isEmpty()) + font = QApplication::font(); + setFont(font); +} + void NickView::rowsInserted(const QModelIndex &parent, int start, int end) { QTreeView::rowsInserted(parent, start, end); if(model()->data(parent, NetworkModel::ItemTypeRole) == NetworkModel::UserCategoryItemType && !isExpanded(parent)) { diff --git a/src/uisupport/nickview.h b/src/uisupport/nickview.h index 0a567e55..5fd4eede 100644 --- a/src/uisupport/nickview.h +++ b/src/uisupport/nickview.h @@ -45,6 +45,9 @@ public slots: void showContextMenu(const QPoint & pos); void startQuery(const QModelIndex & modelIndex); +private slots: + void setCustomFont(const QVariant &); + signals: void selectionUpdated();