• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
fontcolourbutton.cpp
Go to the documentation of this file.
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>
5  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #include "kalarm.h"
22 #include "fontcolourbutton.h"
23 
24 #include "autoqpointer.h"
25 #include "fontcolour.h"
26 #include "preferences.h"
27 #include "pushbutton.h"
28 
29 #include <klineedit.h>
30 #include <klocale.h>
31 #include <kdebug.h>
32 
33 #include <QVBoxLayout>
34 
35 
36 /*=============================================================================
37 = Class FontColourButton
38 = Font/colour selection button.
39 =============================================================================*/
40 
41 FontColourButton::FontColourButton(QWidget* parent)
42  : PushButton(i18nc("@action:button", "Font && Color..."), parent),
43  mDefaultFont(true),
44  mReadOnly(false)
45 {
46  connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
47  setWhatsThis(i18nc("@info:whatsthis", "Choose the font, and foreground and background color, for the alarm message."));
48 }
49 
50 void FontColourButton::setDefaultFont()
51 {
52  mDefaultFont = true;
53 }
54 
55 void FontColourButton::setFont(const QFont& font)
56 {
57  mDefaultFont = false;
58  mFont = font;
59 }
60 
61 /******************************************************************************
62 * Called when the OK button is clicked.
63 * Display a font and colour selection dialog and get the selections.
64 */
65 void FontColourButton::slotButtonPressed()
66 {
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)
74  {
75  mDefaultFont = dlg->defaultFont();
76  mFont = dlg->font();
77  mBgColour = dlg->bgColour();
78  mFgColour = dlg->fgColour();
79  emit selected(mFgColour, mBgColour);
80  }
81 }
82 
83 
84 /*=============================================================================
85 = Class FontColourDlg
86 = Font/colour selection dialog.
87 =============================================================================*/
88 
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)
93 {
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()));
111 }
112 
113 /******************************************************************************
114 * Called when the OK button is clicked.
115 */
116 void FontColourDlg::slotOk()
117 {
118  if (mReadOnly)
119  {
120  reject();
121  return;
122  }
123  mDefaultFont = mChooser->defaultFont();
124  mFont = mChooser->font();
125  mBgColour = mChooser->bgColour();
126  mFgColour = mChooser->fgColour();
127  accept();
128 }
129 
130 void FontColourDlg::setReadOnly(bool ro)
131 {
132  mReadOnly = ro;
133  mChooser->setReadOnly(mReadOnly);
134 }
135 #include "moc_fontcolourbutton.cpp"
136 // vim: et sw=4:
QWidget
FontColourButton::FontColourButton
FontColourButton(QWidget *parent=0)
Definition: fontcolourbutton.cpp:41
fontcolourbutton.h
FontColourChooser
Definition: fontcolour.h:33
FontColourButton::slotButtonPressed
void slotButtonPressed()
Definition: fontcolourbutton.cpp:65
FontColourChooser::setReadOnly
void setReadOnly(bool)
Definition: fontcolour.cpp:190
FontColourDlg::slotOk
virtual void slotOk()
Definition: fontcolourbutton.cpp:116
QFont
FontColourChooser::fgColour
QColor fgColour() const
Definition: fontcolour.cpp:159
FontColourButton::setDefaultFont
void setDefaultFont()
Definition: fontcolourbutton.cpp:50
KDialog
FontColourChooser::font
QFont font() const
Definition: fontcolour.cpp:135
QBoxLayout::addSpacing
void addSpacing(int size)
FontColourButton::font
QFont font() const
Definition: fontcolourbutton.h:42
FontColourDlg
Definition: fontcolourbutton.h:65
PushButton
fontcolour.h
pushbutton.h
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
FontColourChooser::setFgColour
void setFgColour(const QColor &)
Definition: fontcolour.cpp:181
autoqpointer.h
FontColourDlg::FontColourDlg
FontColourDlg(const QColor &bg, const QColor &fg, const QFont &, bool defaultFont, const QString &caption, QWidget *parent=0)
Definition: fontcolourbutton.cpp:89
QVBoxLayout
FontColourChooser::bgColour
QColor bgColour() const
Definition: fontcolour.cpp:154
QString
QColor
QLayout::setMargin
void setMargin(int margin)
FontColourChooser::setFont
void setFont(const QFont &, bool onlyFixed=false)
Definition: fontcolour.cpp:123
QStringList
AutoQPointer
FontColourChooser::defaultFont
bool defaultFont() const
Definition: fontcolour.cpp:130
preferences.h
FontColourButton::setFont
void setFont(const QFont &)
Definition: fontcolourbutton.cpp:55
FontColourDlg::fgColour
QColor fgColour() const
Definition: fontcolourbutton.h:74
FontColourDlg::font
QFont font() const
Definition: fontcolourbutton.h:72
kalarm.h
FontColourChooser::setBgColour
void setBgColour(const QColor &)
Definition: fontcolour.cpp:140
FontColourDlg::setReadOnly
void setReadOnly(bool)
Definition: fontcolourbutton.cpp:130
FontColourButton::selected
void selected(const QColor &fg, const QColor &bg)
Signal emitted whenever a font or colour has been selected.
QBoxLayout::setSpacing
void setSpacing(int spacing)
FontColourDlg::defaultFont
bool defaultFont() const
Definition: fontcolourbutton.h:71
FontColourChooser::setDefaultFont
void setDefaultFont()
Definition: fontcolour.cpp:117
FontColourDlg::bgColour
QColor bgColour() const
Definition: fontcolourbutton.h:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal