Warning, file /pim/kalarm/src/fontcolourbutton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * fontcolourbutton.cpp - pushbutton widget to select a font and colour 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2003-2022 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "fontcolourbutton.h" 0010 0011 #include "fontcolour.h" 0012 #include "lib/autoqpointer.h" 0013 0014 #include <KLocalizedString> 0015 0016 #include <QVBoxLayout> 0017 #include <QStyle> 0018 #include <QDialogButtonBox> 0019 0020 0021 /*============================================================================= 0022 = Class FontColourButton 0023 = Font/colour selection button. 0024 =============================================================================*/ 0025 0026 FontColourButton::FontColourButton(QWidget* parent) 0027 : PushButton(i18nc("@action:button", "Font && Color..."), parent) 0028 { 0029 connect(this, &FontColourButton::clicked, this, &FontColourButton::slotButtonPressed); 0030 setToolTip(i18nc("@info:tooltip", "Set alarm message font and color")); 0031 setWhatsThis(i18nc("@info:whatsthis", "Choose the font, and foreground and background color, for the alarm message.")); 0032 } 0033 0034 void FontColourButton::setFont(const QFont& font, bool defaultFont) 0035 { 0036 mDefaultFont = defaultFont; 0037 mFont = font; 0038 } 0039 0040 /****************************************************************************** 0041 * Called when the OK button is clicked. 0042 * Display a font and colour selection dialog and get the selections. 0043 */ 0044 void FontColourButton::slotButtonPressed() 0045 { 0046 // Use AutoQPointer to guard against crash on application exit while 0047 // the dialogue is still open. It prevents double deletion (both on 0048 // deletion of FontColourButton, and on return from this function). 0049 AutoQPointer<FontColourDlg> dlg = new FontColourDlg(mBgColour, mFgColour, mFont, mDefaultFont, 0050 i18nc("@title:window", "Choose Alarm Font & Color"), this); 0051 dlg->setReadOnly(mReadOnly); 0052 if (dlg->exec() == QDialog::Accepted) 0053 { 0054 mDefaultFont = dlg->defaultFont(); 0055 mFont = dlg->font(); 0056 mBgColour = dlg->bgColour(); 0057 mFgColour = dlg->fgColour(); 0058 Q_EMIT selected(mFgColour, mBgColour); 0059 } 0060 } 0061 0062 0063 /*============================================================================= 0064 = Class FontColourDlg 0065 = Font/colour selection dialog. 0066 =============================================================================*/ 0067 0068 FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font, 0069 bool defaultFont, const QString& caption, QWidget* parent) 0070 : QDialog(parent) 0071 { 0072 setWindowTitle(caption); 0073 0074 auto layout = new QVBoxLayout(this); 0075 mChooser = new FontColourChooser(this, QStringList(), QString(), true, true); 0076 mChooser->setBgColour(bgColour); 0077 mChooser->setFgColour(fgColour); 0078 mChooser->setFont(font, defaultFont); 0079 layout->addWidget(mChooser); 0080 layout->addSpacing(style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0081 0082 auto buttonBox = new QDialogButtonBox(this); 0083 buttonBox->addButton(QDialogButtonBox::Ok); 0084 buttonBox->addButton(QDialogButtonBox::Cancel); 0085 layout->addWidget(buttonBox); 0086 connect(buttonBox, &QDialogButtonBox::accepted, 0087 this, &FontColourDlg::slotOk); 0088 connect(buttonBox, &QDialogButtonBox::rejected, 0089 this, &FontColourDlg::reject); 0090 } 0091 0092 /****************************************************************************** 0093 * Called when the OK button is clicked. 0094 */ 0095 void FontColourDlg::slotOk() 0096 { 0097 if (mReadOnly) 0098 { 0099 reject(); 0100 return; 0101 } 0102 mDefaultFont = mChooser->defaultFont(); 0103 mFont = mChooser->font(); 0104 mBgColour = mChooser->bgColour(); 0105 mFgColour = mChooser->fgColour(); 0106 accept(); 0107 } 0108 0109 void FontColourDlg::setReadOnly(bool ro) 0110 { 0111 mReadOnly = ro; 0112 mChooser->setReadOnly(mReadOnly); 0113 } 0114 0115 #include "moc_fontcolourbutton.cpp" 0116 0117 // vim: et sw=4: