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

kalarm

  • sources
  • kde-4.12
  • 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.moc"
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 <QHBoxLayout>
34 #include <QVBoxLayout>
35 
36 
37 /*=============================================================================
38 = Class FontColourButton
39 = Font/colour selection button.
40 =============================================================================*/
41 
42 FontColourButton::FontColourButton(QWidget* parent)
43  : PushButton(i18nc("@action:button", "Font && Color..."), parent),
44  mDefaultFont(true),
45  mReadOnly(false)
46 {
47  connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
48  setWhatsThis(i18nc("@info:whatsthis", "Choose the font, and foreground and background color, for the alarm message."));
49 }
50 
51 void FontColourButton::setDefaultFont()
52 {
53  mDefaultFont = true;
54 }
55 
56 void FontColourButton::setFont(const QFont& font)
57 {
58  mDefaultFont = false;
59  mFont = font;
60 }
61 
62 /******************************************************************************
63 * Called when the OK button is clicked.
64 * Display a font and colour selection dialog and get the selections.
65 */
66 void FontColourButton::slotButtonPressed()
67 {
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)
75  {
76  mDefaultFont = dlg->defaultFont();
77  mFont = dlg->font();
78  mBgColour = dlg->bgColour();
79  mFgColour = dlg->fgColour();
80  emit selected(mFgColour, mBgColour);
81  }
82 }
83 
84 
85 /*=============================================================================
86 = Class FontColourDlg
87 = Font/colour selection dialog.
88 =============================================================================*/
89 
90 FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font,
91  bool defaultFont, const QString& caption, QWidget* parent)
92  : KDialog(parent),
93  mReadOnly(false)
94 {
95  setCaption(caption);
96  setButtons(Ok|Cancel);
97  QWidget* page = new QWidget(this);
98  setMainWidget(page);
99  QVBoxLayout* layout = new QVBoxLayout(page);
100  layout->setMargin(0);
101  layout->setSpacing(spacingHint());
102  mChooser = new FontColourChooser(page, QStringList(), QString(), true, true);
103  mChooser->setBgColour(bgColour);
104  mChooser->setFgColour(fgColour);
105  if (defaultFont)
106  mChooser->setDefaultFont();
107  else
108  mChooser->setFont(font);
109  layout->addWidget(mChooser);
110  layout->addSpacing(KDialog::spacingHint());
111  connect(this,SIGNAL(okClicked()),SLOT(slotOk()));
112 }
113 
114 /******************************************************************************
115 * Called when the OK button is clicked.
116 */
117 void FontColourDlg::slotOk()
118 {
119  if (mReadOnly)
120  {
121  reject();
122  return;
123  }
124  mDefaultFont = mChooser->defaultFont();
125  mFont = mChooser->font();
126  mBgColour = mChooser->bgColour();
127  mFgColour = mChooser->fgColour();
128  accept();
129 }
130 
131 void FontColourDlg::setReadOnly(bool ro)
132 {
133  mReadOnly = ro;
134  mChooser->setReadOnly(mReadOnly);
135 }
136 
137 // vim: et sw=4:
FontColourButton::FontColourButton
FontColourButton(QWidget *parent=0)
Definition: fontcolourbutton.cpp:42
FontColourChooser
Definition: fontcolour.h:33
FontColourButton::slotButtonPressed
void slotButtonPressed()
Definition: fontcolourbutton.cpp:66
FontColourChooser::setReadOnly
void setReadOnly(bool)
Definition: fontcolour.cpp:190
FontColourDlg::slotOk
virtual void slotOk()
Definition: fontcolourbutton.cpp:117
FontColourChooser::fgColour
QColor fgColour() const
Definition: fontcolour.cpp:159
QWidget
FontColourButton::setDefaultFont
void setDefaultFont()
Definition: fontcolourbutton.cpp:51
KDialog
FontColourChooser::font
QFont font() const
Definition: fontcolour.cpp:135
FontColourButton::font
QFont font() const
Definition: fontcolourbutton.h:42
FontColourDlg
Definition: fontcolourbutton.h:65
PushButton
fontcolour.h
pushbutton.h
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:90
FontColourChooser::bgColour
QColor bgColour() const
Definition: fontcolour.cpp:154
FontColourChooser::setFont
void setFont(const QFont &, bool onlyFixed=false)
Definition: fontcolour.cpp:123
AutoQPointer
FontColourChooser::defaultFont
bool defaultFont() const
Definition: fontcolour.cpp:130
preferences.h
FontColourButton::setFont
void setFont(const QFont &)
Definition: fontcolourbutton.cpp:56
kalarm.h
FontColourChooser::setBgColour
void setBgColour(const QColor &)
Definition: fontcolour.cpp:140
FontColourDlg::setReadOnly
void setReadOnly(bool)
Definition: fontcolourbutton.cpp:131
FontColourButton::selected
void selected(const QColor &fg, const QColor &bg)
Signal emitted whenever a font or colour has been selected.
FontColourChooser::setDefaultFont
void setDefaultFont()
Definition: fontcolour.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 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

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