summaryrefslogtreecommitdiffstats
path: root/kalarm/fontcolourbutton.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kalarm/fontcolourbutton.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kalarm/fontcolourbutton.cpp')
-rw-r--r--kalarm/fontcolourbutton.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/kalarm/fontcolourbutton.cpp b/kalarm/fontcolourbutton.cpp
new file mode 100644
index 000000000..b3a55359a
--- /dev/null
+++ b/kalarm/fontcolourbutton.cpp
@@ -0,0 +1,161 @@
+/*
+ * fontcolourbutton.cpp - pushbutton widget to select a font and colour
+ * Program: kalarm
+ * Copyright © 2003-2005,2007,2008 by David Jarvie <djarvie@kde.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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kalarm.h"
+
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qwhatsthis.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+#include "fontcolour.h"
+#include "preferences.h"
+#include "pushbutton.h"
+#include "fontcolourbutton.moc"
+
+
+/*=============================================================================
+= Class FontColourButton
+= Font/colour selection button.
+=============================================================================*/
+
+FontColourButton::FontColourButton(QWidget* parent, const char* name)
+ : QFrame(parent, name),
+ mReadOnly(false)
+{
+ setFrameStyle(NoFrame);
+ QHBoxLayout* layout = new QHBoxLayout(this, 0, KDialog::spacingHint());
+
+ mButton = new PushButton(i18n("Font && Co&lor..."), this);
+ mButton->setFixedSize(mButton->sizeHint());
+ connect(mButton, SIGNAL(clicked()), SLOT(slotButtonPressed()));
+ QWhatsThis::add(mButton,
+ i18n("Choose the font, and foreground and background color, for the alarm message."));
+ layout->addWidget(mButton);
+
+ // Font and colour sample display
+ mSample = new QLineEdit(this);
+ mSample->setMinimumHeight(QMAX(mSample->fontMetrics().lineSpacing(), mButton->height()*3/2));
+ mSample->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::MinimumExpanding);
+ mSample->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
+ mSample->setCursorPosition(0);
+ mSample->setAlignment(Qt::AlignCenter);
+ QWhatsThis::add(mSample,
+ i18n("This sample text illustrates the current font and color settings. "
+ "You may edit it to test special characters."));
+ layout->addWidget(mSample);
+}
+
+void FontColourButton::setDefaultFont()
+{
+ mDefaultFont = true;
+ mSample->setFont(Preferences::messageFont());
+}
+
+void FontColourButton::setFont(const QFont& font)
+{
+ mDefaultFont = false;
+ mFont = font;
+ mSample->setFont(mFont);
+}
+
+void FontColourButton::setBgColour(const QColor& colour)
+{
+ mBgColour = colour;
+ mSample->setPaletteBackgroundColor(mBgColour);
+}
+
+void FontColourButton::setFgColour(const QColor& colour)
+{
+ mFgColour = colour;
+ mSample->setPaletteForegroundColor(mFgColour);
+}
+
+/******************************************************************************
+* Called when the OK button is clicked.
+* Display a font and colour selection dialog and get the selections.
+*/
+void FontColourButton::slotButtonPressed()
+{
+ FontColourDlg dlg(mBgColour, mFgColour, mFont, mDefaultFont,
+ i18n("Choose Alarm Font & Color"), this, "fontColourDlg");
+ dlg.setReadOnly(mReadOnly);
+ if (dlg.exec() == QDialog::Accepted)
+ {
+ mDefaultFont = dlg.defaultFont();
+ mFont = dlg.font();
+ mSample->setFont(mFont);
+ mBgColour = dlg.bgColour();
+ mSample->setPaletteBackgroundColor(mBgColour);
+ mFgColour = dlg.fgColour();
+ mSample->setPaletteForegroundColor(mFgColour);
+ emit selected();
+ }
+}
+
+
+/*=============================================================================
+= Class FontColourDlg
+= Font/colour selection dialog.
+=============================================================================*/
+
+FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font,
+ bool defaultFont, const QString& caption, QWidget* parent, const char* name)
+ : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false),
+ mReadOnly(false)
+{
+ QWidget* page = new QWidget(this);
+ setMainWidget(page);
+ QVBoxLayout* layout = new QVBoxLayout(page, 0, spacingHint());
+ mChooser = new FontColourChooser(page, 0, false, QStringList(), QString::null, false, true, true);
+ mChooser->setBgColour(bgColour);
+ mChooser->setFgColour(fgColour);
+ if (defaultFont)
+ mChooser->setDefaultFont();
+ else
+ mChooser->setFont(font);
+ layout->addWidget(mChooser);
+ layout->addSpacing(KDialog::spacingHint());
+}
+
+/******************************************************************************
+* Called when the OK button is clicked.
+*/
+void FontColourDlg::slotOk()
+{
+ if (mReadOnly)
+ {
+ reject();
+ return;
+ }
+ mDefaultFont = mChooser->defaultFont();
+ mFont = mChooser->font();
+ mBgColour = mChooser->bgColour();
+ mFgColour = mChooser->fgColour();
+ accept();
+}
+
+void FontColourDlg::setReadOnly(bool ro)
+{
+ mReadOnly = ro;
+ mChooser->setReadOnly(mReadOnly);
+}