Yearly copyright bump :)
[quassel.git] / src / qtui / settingspages / fontssettingspage.cpp
index b82c72f..2695a4f 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -21,6 +21,8 @@
 #include "fontssettingspage.h"
 
 #include "qtui.h"
+#include "qtuisettings.h"
+#include "qtuistyle.h"
 
 #include <QFontDialog>
 
@@ -31,26 +33,29 @@ FontsSettingsPage::FontsSettingsPage(QWidget *parent)
   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.chooseNickList, SIGNAL(clicked()), mapper, SLOT(map()));
+  connect(ui.chooseInputLine, 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.chooseNickList, ui.demoNickList);
+  mapper->setMapping(ui.chooseInputLine, ui.demoInputLine);
   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 *)));
 
-  connect(ui.customAppFonts, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
+  //connect(ui.customAppFonts, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkTopic, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
-  connect(ui.checkNickList, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkBufferView, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
+  connect(ui.checkNickList, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
+  connect(ui.checkInputLine, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkNicks, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkTimestamp, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
 
@@ -69,10 +74,21 @@ void FontsSettingsPage::defaults() {
 
 void FontsSettingsPage::load() {
   load(Settings::Custom);
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::load(Settings::Mode mode) {
+  QtUiSettings s;
+  bool useInputLineFont = s.value("UseInputLineFont", QVariant(false)).toBool();
+  QFont inputLineFont;
+  if(useInputLineFont) {
+    ui.checkInputLine->setChecked(true);
+    inputLineFont = s.value("InputLineFont").value<QFont>();
+  } else {
+    inputLineFont = qApp->font();
+  }
+  initLabel(ui.demoInputLine, inputLineFont);
+
   QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode);
   initLabel(ui.demoChatMessages, chatFormat.font());
   QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender, mode);
@@ -83,6 +99,7 @@ void FontsSettingsPage::load(Settings::Mode mode) {
     initLabel(ui.demoNicks, chatFormat.font());
     ui.checkNicks->setChecked(false);
   }
+
   QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp, mode);
   if(timestampFormat.hasProperty(QTextFormat::FontFamily)) {
     initLabel(ui.demoTimestamp, timestampFormat.font());
@@ -92,30 +109,37 @@ void FontsSettingsPage::load(Settings::Mode mode) {
     ui.checkTimestamp->setChecked(false);
   }
 
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::save() {
+  QtUiSettings s;
+  s.setValue("UseInputLineFont", (ui.checkInputLine->checkState() == Qt::Checked));
+  s.setValue("InputLineFont", ui.demoInputLine->font());
+
   QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None);
   chatFormat.setFont(ui.demoChatMessages->font());
   QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom);
 
-  //FIXME: actually remove font properties from the formats
   QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender);
-  if(ui.checkNicks->checkState() == Qt::Checked) nicksFormat.setFont(ui.demoNicks->font());
-  else nicksFormat.setFont(chatFormat.font());
+  if(ui.checkNicks->checkState() == Qt::Checked)
+    nicksFormat.setFont(ui.demoNicks->font());
+  else
+    clearFontFromFormat(nicksFormat);
   QtUi::style()->setFormat(UiStyle::Sender, nicksFormat, Settings::Custom);
 
   QTextCharFormat timestampFormat = QtUi::style()->format(UiStyle::Timestamp);
-  if(ui.checkTimestamp->checkState() == Qt::Checked) timestampFormat.setFont(ui.demoTimestamp->font());
-  else timestampFormat.setFont(chatFormat.font());
+  if(ui.checkTimestamp->checkState() == Qt::Checked)
+    timestampFormat.setFont(ui.demoTimestamp->font());
+  else
+    clearFontFromFormat(timestampFormat);
   QtUi::style()->setFormat(UiStyle::Timestamp, timestampFormat, Settings::Custom);
 
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::widgetHasChanged() {
-  if(!hasChanged()) changeState(true);
+  if(!hasChanged()) setChangedState(true);
 }
 
 void FontsSettingsPage::initLabel(QLabel *label, const QFont &font) {
@@ -137,3 +161,18 @@ void FontsSettingsPage::chooseFont(QWidget *widget) {
     setFont(label, font);
   }
 }
+
+void FontsSettingsPage::clearFontFromFormat(QTextCharFormat &fmt) {
+  fmt.clearProperty(QTextFormat::FontFamily);
+  fmt.clearProperty(QTextFormat::FontPointSize);
+  fmt.clearProperty(QTextFormat::FontPixelSize);
+  fmt.clearProperty(QTextFormat::FontWeight);
+  fmt.clearProperty(QTextFormat::FontItalic);
+  fmt.clearProperty(QTextFormat::TextUnderlineStyle);
+  fmt.clearProperty(QTextFormat::FontOverline);
+  fmt.clearProperty(QTextFormat::FontStrikeOut);
+  fmt.clearProperty(QTextFormat::FontFixedPitch);
+  fmt.clearProperty(QTextFormat::FontCapitalization);
+  fmt.clearProperty(QTextFormat::FontWordSpacing);
+  fmt.clearProperty(QTextFormat::FontLetterSpacing);
+}