Build with clang.
[kdepim.git] / kalarm / fontcolourbutton.cpp
blob1dd4610d82d0e0c24c08f5d12b695777391aeff4
1 /*
2 * fontcolourbutton.cpp - pushbutton widget to select a font and colour
3 * Program: kalarm
4 * Copyright © 2003-2009 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "kalarm.h"
22 #include "fontcolourbutton.moc"
24 #include "autoqpointer.h"
25 #include "fontcolour.h"
26 #include "preferences.h"
27 #include "pushbutton.h"
29 #include <klineedit.h>
30 #include <klocale.h>
31 #include <kdebug.h>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
37 /*=============================================================================
38 = Class FontColourButton
39 = Font/colour selection button.
40 =============================================================================*/
42 FontColourButton::FontColourButton(QWidget* parent)
43 : PushButton(i18nc("@action:button", "Font && Color..."), parent),
44 mReadOnly(false)
46 connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
47 setWhatsThis(i18nc("@info:whatsthis", "Choose the font, and foreground and background color, for the alarm message."));
50 void FontColourButton::setDefaultFont()
52 mDefaultFont = true;
55 void FontColourButton::setFont(const QFont& font)
57 mDefaultFont = false;
58 mFont = font;
61 /******************************************************************************
62 * Called when the OK button is clicked.
63 * Display a font and colour selection dialog and get the selections.
65 void FontColourButton::slotButtonPressed()
67 // Use AutoQPointer to guard against crash on application exit while
68 // the dialogue is still open. It prevents double deletion (both on
69 // deletion of FontColourButton, and on return from this function).
70 AutoQPointer<FontColourDlg> dlg = new FontColourDlg(mBgColour, mFgColour, mFont, mDefaultFont,
71 i18nc("@title:window", "Choose Alarm Font & Color"), this);
72 dlg->setReadOnly(mReadOnly);
73 if (dlg->exec() == QDialog::Accepted)
75 mDefaultFont = dlg->defaultFont();
76 mFont = dlg->font();
77 mBgColour = dlg->bgColour();
78 mFgColour = dlg->fgColour();
79 emit selected(mFgColour, mBgColour);
84 /*=============================================================================
85 = Class FontColourDlg
86 = Font/colour selection dialog.
87 =============================================================================*/
89 FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font,
90 bool defaultFont, const QString& caption, QWidget* parent)
91 : KDialog(parent),
92 mReadOnly(false)
94 setCaption(caption);
95 setButtons(Ok|Cancel);
96 QWidget* page = new QWidget(this);
97 setMainWidget(page);
98 QVBoxLayout* layout = new QVBoxLayout(page);
99 layout->setMargin(0);
100 layout->setSpacing(spacingHint());
101 mChooser = new FontColourChooser(page, QStringList(), QString(), true, true);
102 mChooser->setBgColour(bgColour);
103 mChooser->setFgColour(fgColour);
104 if (defaultFont)
105 mChooser->setDefaultFont();
106 else
107 mChooser->setFont(font);
108 layout->addWidget(mChooser);
109 layout->addSpacing(KDialog::spacingHint());
110 connect(this,SIGNAL(okClicked()),SLOT(slotOk()));
113 /******************************************************************************
114 * Called when the OK button is clicked.
116 void FontColourDlg::slotOk()
118 if (mReadOnly)
120 reject();
121 return;
123 mDefaultFont = mChooser->defaultFont();
124 mFont = mChooser->font();
125 mBgColour = mChooser->bgColour();
126 mFgColour = mChooser->fgColour();
127 accept();
130 void FontColourDlg::setReadOnly(bool ro)
132 mReadOnly = ro;
133 mChooser->setReadOnly(mReadOnly);
136 // vim: et sw=4: