1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "fontssettingspage.h"
25 #include <QFontDialog>
27 FontsSettingsPage::FontsSettingsPage(QWidget *parent)
28 : SettingsPage(tr("Appearance"), tr("Fonts"), parent) {
31 mapper = new QSignalMapper(this);
32 connect(ui.chooseGeneral, SIGNAL(clicked()), mapper, SLOT(map()));
33 connect(ui.chooseTopic, SIGNAL(clicked()), mapper, SLOT(map()));
34 connect(ui.chooseNickList, SIGNAL(clicked()), mapper, SLOT(map()));
35 connect(ui.chooseBufferView, SIGNAL(clicked()), mapper, SLOT(map()));
36 connect(ui.chooseChatMessages, SIGNAL(clicked()), mapper, SLOT(map()));
37 connect(ui.chooseNicks, SIGNAL(clicked()), mapper, SLOT(map()));
38 connect(ui.chooseTimestamp, SIGNAL(clicked()), mapper, SLOT(map()));
40 mapper->setMapping(ui.chooseGeneral, ui.demoGeneral);
41 mapper->setMapping(ui.chooseTopic, ui.demoTopic);
42 mapper->setMapping(ui.chooseNickList, ui.demoNickList);
43 mapper->setMapping(ui.chooseBufferView, ui.demoBufferView);
44 mapper->setMapping(ui.chooseChatMessages, ui.demoChatMessages);
45 mapper->setMapping(ui.chooseNicks, ui.demoNicks);
46 mapper->setMapping(ui.chooseTimestamp, ui.demoTimestamp);
48 connect(mapper, SIGNAL(mapped(QWidget *)), this, SLOT(chooseFont(QWidget *)));
54 bool FontsSettingsPage::hasChanged() const {
59 void FontsSettingsPage::defaults() {
60 load(Settings::Default);
64 void FontsSettingsPage::load() {
65 load(Settings::Custom);
69 void FontsSettingsPage::load(Settings::Mode mode) {
70 QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode);
71 setFont(ui.demoChatMessages, chatFormat.font());
72 QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender, mode);
73 if(nicksFormat.hasProperty(QTextFormat::FontFamily)) {
74 setFont(ui.demoNicks, nicksFormat.font());
75 ui.checkNicks->setChecked(true);
77 setFont(ui.demoNicks, chatFormat.font());
78 ui.checkNicks->setChecked(false);
80 QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp, mode);
81 if(timestampFormat.hasProperty(QTextFormat::FontFamily)) {
82 setFont(ui.demoTimestamp, timestampFormat.font());
83 ui.checkTimestamp->setChecked(true);
85 setFont(ui.demoTimestamp, chatFormat.font());
86 ui.checkTimestamp->setChecked(false);
91 void FontsSettingsPage::save() {
92 QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None);
93 chatFormat.setFont(ui.demoChatMessages->font());
94 QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom);
95 if(ui.checkNicks->checkState() == Qt::Checked) {
96 QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender);
97 nicksFormat.setFont(ui.demoNicks->font());
98 QtUi::style()->setFormat(UiStyle::Sender, nicksFormat, Settings::Custom);
100 if(ui.checkTimestamp->checkState() == Qt::Checked) {
101 QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp);
102 timestampFormat.setFont(ui.demoTimestamp->font());
103 QtUi::style()->setFormat(UiStyle::Timestamp, timestampFormat, Settings::Custom);
108 void FontsSettingsPage::setFont(QLabel *label, const QFont &font) {
109 QFontInfo fontInfo(font);
110 label->setFont(font);
111 label->setText(QString("%1 %2").arg(fontInfo.family()).arg(fontInfo.pointSize()));
114 void FontsSettingsPage::chooseFont(QWidget *widget) {
115 QLabel *label = qobject_cast<QLabel *>(widget);
118 QFont font = QFontDialog::getFont(&ok, label->font());
120 setFont(label, font);