• 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
fontcolour.cpp
Go to the documentation of this file.
1 /*
2  * fontcolour.cpp - font and colour chooser widget
3  * Program: kalarm
4  * Copyright © 2001-2009 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 "kalarmapp.h"
22 #include "preferences.h"
23 #include "colourbutton.h"
24 #include "checkbox.h"
25 #include "fontcolour.h"
26 
27 #include <kglobal.h>
28 #include <kfontchooser.h>
29 #include <kfontdialog.h>
30 #include <kcolordialog.h>
31 #include <khbox.h>
32 
33 #include <QGroupBox>
34 #include <QPushButton>
35 #include <QLabel>
36 #include <QVBoxLayout>
37 #include <QHBoxLayout>
38 
39 
40 FontColourChooser::FontColourChooser(QWidget *parent,
41  const QStringList &fontList, const QString& frameLabel, bool fg, bool defaultFont, int visibleListSize)
42  : QWidget(parent),
43  mFgColourButton(0),
44  mReadOnly(false)
45 {
46  QVBoxLayout* topLayout = new QVBoxLayout(this);
47  topLayout->setMargin(0);
48  topLayout->setSpacing(KDialog::spacingHint());
49  QWidget* page = this;
50  if (!frameLabel.isNull())
51  {
52  page = new QGroupBox(frameLabel, this);
53  topLayout->addWidget(page);
54  topLayout = new QVBoxLayout(page);
55  topLayout->setMargin(KDialog::marginHint());
56  topLayout->setSpacing(KDialog::spacingHint());
57  }
58  QHBoxLayout* hlayout = new QHBoxLayout();
59  hlayout->setMargin(0);
60  topLayout->addLayout(hlayout);
61  QVBoxLayout* colourLayout = new QVBoxLayout();
62  colourLayout->setMargin(0);
63  hlayout->addLayout(colourLayout);
64  if (fg)
65  {
66  KHBox* box = new KHBox(page); // to group widgets for QWhatsThis text
67  box->setMargin(0);
68  box->setSpacing(KDialog::spacingHint()/2);
69  colourLayout->addWidget(box);
70 
71  QLabel* label = new QLabel(i18nc("@label:listbox", "Foreground color:"), box);
72  box->setStretchFactor(new QWidget(box), 0);
73  mFgColourButton = new ColourButton(box);
74  connect(mFgColourButton, SIGNAL(changed(QColor)), SLOT(setSampleColour()));
75  label->setBuddy(mFgColourButton);
76  box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message foreground color"));
77  }
78 
79  KHBox* box = new KHBox(page); // to group widgets for QWhatsThis text
80  box->setMargin(0);
81  box->setSpacing(KDialog::spacingHint()/2);
82  colourLayout->addWidget(box);
83 
84  QLabel* label = new QLabel(i18nc("@label:listbox", "Background color:"), box);
85  box->setStretchFactor(new QWidget(box), 0);
86  mBgColourButton = new ColourButton(box);
87  connect(mBgColourButton, SIGNAL(changed(QColor)), SLOT(setSampleColour()));
88  label->setBuddy(mBgColourButton);
89  box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message background color"));
90  hlayout->addStretch();
91 
92  if (defaultFont)
93  {
94  QHBoxLayout* layout = new QHBoxLayout();
95  layout->setMargin(0);
96  topLayout->addLayout(layout);
97  mDefaultFont = new CheckBox(i18nc("@option:check", "Use default font"), page);
98  mDefaultFont->setMinimumSize(mDefaultFont->sizeHint());
99  connect(mDefaultFont, SIGNAL(toggled(bool)), SLOT(slotDefaultFontToggled(bool)));
100  mDefaultFont->setWhatsThis(i18nc("@info:whatsthis", "Check to use the default font current at the time the alarm is displayed."));
101  layout->addWidget(mDefaultFont);
102  layout->addWidget(new QWidget(page)); // left adjust the widget
103  }
104  else
105  mDefaultFont = 0;
106 
107  mFontChooser = new KFontChooser(page, KFontChooser::DisplayFrame, fontList, visibleListSize);
108  mFontChooser->installEventFilter(this); // for read-only mode
109  QList<QWidget*> kids = mFontChooser->findChildren<QWidget*>();
110  for (int i = 0, end = kids.count(); i < end; ++i)
111  kids[i]->installEventFilter(this);
112  topLayout->addWidget(mFontChooser);
113 
114  slotDefaultFontToggled(false);
115 }
116 
117 void FontColourChooser::setDefaultFont()
118 {
119  if (mDefaultFont)
120  mDefaultFont->setChecked(true);
121 }
122 
123 void FontColourChooser::setFont(const QFont& font, bool onlyFixed)
124 {
125  if (mDefaultFont)
126  mDefaultFont->setChecked(false);
127  mFontChooser->setFont(font, onlyFixed);
128 }
129 
130 bool FontColourChooser::defaultFont() const
131 {
132  return mDefaultFont ? mDefaultFont->isChecked() : false;
133 }
134 
135 QFont FontColourChooser::font() const
136 {
137  return (mDefaultFont && mDefaultFont->isChecked()) ? QFont() : mFontChooser->font();
138 }
139 
140 void FontColourChooser::setBgColour(const QColor& colour)
141 {
142  mBgColourButton->setColor(colour);
143  mFontChooser->setBackgroundColor(colour);
144 }
145 
146 void FontColourChooser::setSampleColour()
147 {
148  QColor bg = mBgColourButton->color();
149  mFontChooser->setBackgroundColor(bg);
150  QColor fg = fgColour();
151  mFontChooser->setColor(fg);
152 }
153 
154 QColor FontColourChooser::bgColour() const
155 {
156  return mBgColourButton->color();
157 }
158 
159 QColor FontColourChooser::fgColour() const
160 {
161  if (mFgColourButton)
162  return mFgColourButton->color();
163  else
164  {
165  QColor bg = mBgColourButton->color();
166  QPalette pal(bg, bg);
167  return pal.color(QPalette::Active, QPalette::Text);
168  }
169 }
170 
171 QString FontColourChooser::sampleText() const
172 {
173  return mFontChooser->sampleText();
174 }
175 
176 void FontColourChooser::setSampleText(const QString& text)
177 {
178  mFontChooser->setSampleText(text);
179 }
180 
181 void FontColourChooser::setFgColour(const QColor& colour)
182 {
183  if (mFgColourButton)
184  {
185  mFgColourButton->setColor(colour);
186  mFontChooser->setColor(colour);
187  }
188 }
189 
190 void FontColourChooser::setReadOnly(bool ro)
191 {
192  if (ro != mReadOnly)
193  {
194  mReadOnly = ro;
195  if (mFgColourButton)
196  mFgColourButton->setReadOnly(ro);
197  mBgColourButton->setReadOnly(ro);
198  mDefaultFont->setReadOnly(ro);
199  }
200 }
201 
202 bool FontColourChooser::eventFilter(QObject*, QEvent* e)
203 {
204  if (mReadOnly)
205  {
206  switch (e->type())
207  {
208  case QEvent::MouseMove:
209  case QEvent::MouseButtonPress:
210  case QEvent::MouseButtonRelease:
211  case QEvent::MouseButtonDblClick:
212  case QEvent::KeyPress:
213  case QEvent::KeyRelease:
214  return true; // prevent the event being handled
215  default:
216  break;
217  }
218  }
219  return false;
220 }
221 
222 void FontColourChooser::slotDefaultFontToggled(bool on)
223 {
224  mFontChooser->setEnabled(!on);
225 }
226 #include "moc_fontcolour.cpp"
227 
228 // vim: et sw=4:
QWidget::layout
QLayout * layout() const
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
QEvent
QWidget
QEvent::type
Type type() const
FontColourChooser::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: fontcolour.cpp:202
text
virtual QByteArray text(quint32 serialNumber) const =0
FontColourChooser::setReadOnly
void setReadOnly(bool)
Definition: fontcolour.cpp:190
QFont
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
FontColourChooser::fgColour
QColor fgColour() const
Definition: fontcolour.cpp:159
QCheckBox::sizeHint
virtual QSize sizeHint() const
QHBoxLayout
FontColourChooser::font
QFont font() const
Definition: fontcolour.cpp:135
checkbox.h
QString::isNull
bool isNull() const
QLabel::setBuddy
void setBuddy(QWidget *buddy)
fontcolour.h
kalarmapp.h
the KAlarm application object
QWidget::setMinimumSize
void setMinimumSize(const QSize &)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
QGroupBox
CheckBox
FontColourChooser::setFgColour
void setFgColour(const QColor &)
Definition: fontcolour.cpp:181
QObject
colourbutton.h
QVBoxLayout
FontColourChooser::bgColour
QColor bgColour() const
Definition: fontcolour.cpp:154
QString
QList
QColor
ColourButton::setReadOnly
virtual void setReadOnly(bool readOnly)
QLayout::setMargin
void setMargin(int margin)
FontColourChooser::setFont
void setFont(const QFont &, bool onlyFixed=false)
Definition: fontcolour.cpp:123
ColourButton
QStringList
FontColourChooser::defaultFont
bool defaultFont() const
Definition: fontcolour.cpp:130
preferences.h
FontColourChooser::setSampleText
void setSampleText(const QString &text)
Definition: fontcolour.cpp:176
QAbstractButton::setChecked
void setChecked(bool)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QBoxLayout::addStretch
void addStretch(int stretch)
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
FontColourChooser::setBgColour
void setBgColour(const QColor &)
Definition: fontcolour.cpp:140
KHBox
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QPalette
QBoxLayout::setSpacing
void setSpacing(int spacing)
FontColourChooser::FontColourChooser
FontColourChooser(QWidget *parent=0, const QStringList &fontList=QStringList(), const QString &frameLabel=i18n("Requested font"), bool fg=true, bool defaultFont=false, int visibleListSize=8)
Definition: fontcolour.cpp:40
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
FontColourChooser::setDefaultFont
void setDefaultFont()
Definition: fontcolour.cpp:117
FontColourChooser::sampleText
QString sampleText() const
Definition: fontcolour.cpp:171
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