2 * fontcolourbutton.cpp - pushbutton widget to select a font and colour
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.
22 #include "fontcolourbutton.moc"
24 #include "autoqpointer.h"
25 #include "fontcolour.h"
26 #include "preferences.h"
27 #include "pushbutton.h"
29 #include <klineedit.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
),
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()
55 void FontColourButton::setFont(const QFont
& 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();
77 mBgColour
= dlg
->bgColour();
78 mFgColour
= dlg
->fgColour();
79 emit
selected(mFgColour
, mBgColour
);
84 /*=============================================================================
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
)
95 setButtons(Ok
|Cancel
);
96 QWidget
* page
= new QWidget(this);
98 QVBoxLayout
* layout
= new QVBoxLayout(page
);
100 layout
->setSpacing(spacingHint());
101 mChooser
= new FontColourChooser(page
, QStringList(), QString(), true, true);
102 mChooser
->setBgColour(bgColour
);
103 mChooser
->setFgColour(fgColour
);
105 mChooser
->setDefaultFont();
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()
123 mDefaultFont
= mChooser
->defaultFont();
124 mFont
= mChooser
->font();
125 mBgColour
= mChooser
->bgColour();
126 mFgColour
= mChooser
->fgColour();
130 void FontColourDlg::setReadOnly(bool ro
)
133 mChooser
->setReadOnly(mReadOnly
);