SVN_SILENT made messages (after extraction)
[kdepim.git] / kalarm / fontcolourbutton.cpp
blob69f56c3825932852e46eb926816c4981d614d906
1 /*
2 * fontcolourbutton.cpp - pushbutton widget to select a font and colour
3 * Program: kalarm
4 * Copyright © 2003-2013 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.h"
24 #include "autoqpointer.h"
25 #include "fontcolour.h"
26 #include "preferences.h"
27 #include "pushbutton.h"
29 #include <KLocalizedString>
31 #include <QVBoxLayout>
32 #include <QStyle>
33 #include <QDialogButtonBox>
34 #include "kalarm_debug.h"
37 /*=============================================================================
38 = Class FontColourButton
39 = Font/colour selection button.
40 =============================================================================*/
42 FontColourButton::FontColourButton(QWidget* parent)
43 : PushButton(i18nc("@action:button", "Font && Color..."), parent),
44 mDefaultFont(true),
45 mReadOnly(false)
47 connect(this, &FontColourButton::clicked, this, &FontColourButton::slotButtonPressed);
48 setWhatsThis(i18nc("@info:whatsthis", "Choose the font, and foreground and background color, for the alarm message."));
51 void FontColourButton::setDefaultFont()
53 mDefaultFont = true;
56 void FontColourButton::setFont(const QFont& font)
58 mDefaultFont = false;
59 mFont = font;
62 /******************************************************************************
63 * Called when the OK button is clicked.
64 * Display a font and colour selection dialog and get the selections.
66 void FontColourButton::slotButtonPressed()
68 // Use AutoQPointer to guard against crash on application exit while
69 // the dialogue is still open. It prevents double deletion (both on
70 // deletion of FontColourButton, and on return from this function).
71 AutoQPointer<FontColourDlg> dlg = new FontColourDlg(mBgColour, mFgColour, mFont, mDefaultFont,
72 i18nc("@title:window", "Choose Alarm Font & Color"), this);
73 dlg->setReadOnly(mReadOnly);
74 if (dlg->exec() == QDialog::Accepted)
76 mDefaultFont = dlg->defaultFont();
77 mFont = dlg->font();
78 mBgColour = dlg->bgColour();
79 mFgColour = dlg->fgColour();
80 Q_EMIT selected(mFgColour, mBgColour);
85 /*=============================================================================
86 = Class FontColourDlg
87 = Font/colour selection dialog.
88 =============================================================================*/
90 FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font,
91 bool defaultFont, const QString& caption, QWidget* parent)
92 : QDialog(parent),
93 mReadOnly(false)
95 setWindowTitle(caption);
97 QVBoxLayout* layout = new QVBoxLayout(this);
98 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
99 mChooser = new FontColourChooser(this, QStringList(), QString(), true, true);
100 mChooser->setBgColour(bgColour);
101 mChooser->setFgColour(fgColour);
102 if (defaultFont)
103 mChooser->setDefaultFont();
104 else
105 mChooser->setFont(font);
106 layout->addWidget(mChooser);
107 layout->addSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
109 QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
110 buttonBox->addButton(QDialogButtonBox::Ok);
111 buttonBox->addButton(QDialogButtonBox::Cancel);
112 layout->addWidget(buttonBox);
113 connect(buttonBox, &QDialogButtonBox::accepted,
114 this, &FontColourDlg::slotOk);
115 connect(buttonBox, &QDialogButtonBox::rejected,
116 this, &FontColourDlg::reject);
119 /******************************************************************************
120 * Called when the OK button is clicked.
122 void FontColourDlg::slotOk()
124 if (mReadOnly)
126 reject();
127 return;
129 mDefaultFont = mChooser->defaultFont();
130 mFont = mChooser->font();
131 mBgColour = mChooser->bgColour();
132 mFgColour = mChooser->fgColour();
133 accept();
136 void FontColourDlg::setReadOnly(bool ro)
138 mReadOnly = ro;
139 mChooser->setReadOnly(mReadOnly);
142 // vim: et sw=4: