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

kalarm

fontcolour.cpp

Go to the documentation of this file.
00001 /*
00002  *  fontcolour.cpp  -  font and colour chooser widget
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2009 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <QGroupBox>
00022 #include <QPushButton>
00023 #include <QLabel>
00024 #include <QVBoxLayout>
00025 #include <QHBoxLayout>
00026 
00027 #include <kglobal.h>
00028 #include <kfontchooser.h>
00029 #include <kfontdialog.h>
00030 #include <kcolordialog.h>
00031 #include <khbox.h>
00032 
00033 #include "kalarmapp.h"
00034 #include "preferences.h"
00035 #include "colourbutton.h"
00036 #include "checkbox.h"
00037 #include "fontcolour.moc"
00038 
00039 
00040 FontColourChooser::FontColourChooser(QWidget *parent,
00041           const QStringList &fontList, const QString& frameLabel, bool fg, bool defaultFont, int visibleListSize)
00042     : QWidget(parent),
00043       mFgColourButton(0),
00044       mReadOnly(false)
00045 {
00046     QVBoxLayout* topLayout = new QVBoxLayout(this);
00047     topLayout->setMargin(0);
00048     topLayout->setSpacing(KDialog::spacingHint());
00049     QWidget* page = this;
00050     if (!frameLabel.isNull())
00051     {
00052         page = new QGroupBox(frameLabel, this);
00053         topLayout->addWidget(page);
00054         topLayout = new QVBoxLayout(page);
00055         topLayout->setMargin(KDialog::marginHint());
00056         topLayout->setSpacing(KDialog::spacingHint());
00057     }
00058     QHBoxLayout* hlayout = new QHBoxLayout();
00059     hlayout->setMargin(0);
00060     topLayout->addLayout(hlayout);
00061     QVBoxLayout* colourLayout = new QVBoxLayout();
00062     colourLayout->setMargin(0);
00063     hlayout->addLayout(colourLayout);
00064     if (fg)
00065     {
00066         KHBox* box = new KHBox(page);    // to group widgets for QWhatsThis text
00067         box->setMargin(0);
00068         box->setSpacing(KDialog::spacingHint()/2);
00069         colourLayout->addWidget(box);
00070 
00071         QLabel* label = new QLabel(i18nc("@label:listbox", "Foreground color:"), box);
00072         box->setStretchFactor(new QWidget(box), 0);
00073         mFgColourButton = new ColourButton(box);
00074         connect(mFgColourButton, SIGNAL(changed(const QColor&)), SLOT(setSampleColour()));
00075         label->setBuddy(mFgColourButton);
00076         box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message foreground color"));
00077     }
00078 
00079     KHBox* box = new KHBox(page);    // to group widgets for QWhatsThis text
00080     box->setMargin(0);
00081     box->setSpacing(KDialog::spacingHint()/2);
00082     colourLayout->addWidget(box);
00083 
00084     QLabel* label = new QLabel(i18nc("@label:listbox", "Background color:"), box);
00085     box->setStretchFactor(new QWidget(box), 0);
00086     mBgColourButton = new ColourButton(box);
00087     connect(mBgColourButton, SIGNAL(changed(const QColor&)), SLOT(setSampleColour()));
00088     label->setBuddy(mBgColourButton);
00089     box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message background color"));
00090     hlayout->addStretch();
00091 
00092     if (defaultFont)
00093     {
00094         QHBoxLayout* layout = new QHBoxLayout();
00095         layout->setMargin(0);
00096         topLayout->addLayout(layout);
00097         mDefaultFont = new CheckBox(i18nc("@option:check", "Use default font"), page);
00098         mDefaultFont->setMinimumSize(mDefaultFont->sizeHint());
00099         connect(mDefaultFont, SIGNAL(toggled(bool)), SLOT(slotDefaultFontToggled(bool)));
00100         mDefaultFont->setWhatsThis(i18nc("@info:whatsthis", "Check to use the default font current at the time the alarm is displayed."));
00101         layout->addWidget(mDefaultFont);
00102         layout->addWidget(new QWidget(page));    // left adjust the widget
00103     }
00104     else
00105         mDefaultFont = 0;
00106 
00107     mFontChooser = new KFontChooser(page, KFontChooser::DisplayFrame, fontList, visibleListSize);
00108     mFontChooser->installEventFilter(this);   // for read-only mode
00109     QList<QWidget*> kids = mFontChooser->findChildren<QWidget*>();
00110     for (int i = 0, end = kids.count();  i < end;  ++i)
00111         kids[i]->installEventFilter(this);
00112     topLayout->addWidget(mFontChooser);
00113 
00114     slotDefaultFontToggled(false);
00115 }
00116 
00117 void FontColourChooser::setDefaultFont()
00118 {
00119     if (mDefaultFont)
00120         mDefaultFont->setChecked(true);
00121 }
00122 
00123 void FontColourChooser::setFont(const QFont& font, bool onlyFixed)
00124 {
00125     if (mDefaultFont)
00126         mDefaultFont->setChecked(false);
00127     mFontChooser->setFont(font, onlyFixed);
00128 }
00129 
00130 bool FontColourChooser::defaultFont() const
00131 {
00132     return mDefaultFont ? mDefaultFont->isChecked() : false;
00133 }
00134 
00135 QFont FontColourChooser::font() const
00136 {
00137     return (mDefaultFont && mDefaultFont->isChecked()) ? QFont() : mFontChooser->font();
00138 }
00139 
00140 void FontColourChooser::setBgColour(const QColor& colour)
00141 {
00142     mBgColourButton->setColor(colour);
00143     mFontChooser->setBackgroundColor(colour);
00144 }
00145 
00146 void FontColourChooser::setSampleColour()
00147 {
00148     QColor bg = mBgColourButton->color();
00149     mFontChooser->setBackgroundColor(bg);
00150     QColor fg = fgColour();
00151     mFontChooser->setColor(fg);
00152 }
00153 
00154 QColor FontColourChooser::bgColour() const
00155 {
00156     return mBgColourButton->color();
00157 }
00158 
00159 QColor FontColourChooser::fgColour() const
00160 {
00161     if (mFgColourButton)
00162         return mFgColourButton->color();
00163     else
00164     {
00165         QColor bg = mBgColourButton->color();
00166         QPalette pal(bg, bg);
00167         return pal.color(QPalette::Active, QPalette::Text);
00168     }
00169 }
00170 
00171 QString FontColourChooser::sampleText() const
00172 {
00173     return mFontChooser->sampleText();
00174 }
00175 
00176 void FontColourChooser::setSampleText(const QString& text)
00177 {
00178     mFontChooser->setSampleText(text);
00179 }
00180 
00181 void FontColourChooser::setFgColour(const QColor& colour)
00182 {
00183     if (mFgColourButton)
00184     {
00185         mFgColourButton->setColor(colour);
00186         mFontChooser->setColor(colour);
00187     }
00188 }
00189 
00190 void FontColourChooser::setReadOnly(bool ro)
00191 {
00192     if (ro != mReadOnly)
00193     {
00194         mReadOnly = ro;
00195         if (mFgColourButton)
00196             mFgColourButton->setReadOnly(ro);
00197         mBgColourButton->setReadOnly(ro);
00198         mDefaultFont->setReadOnly(ro);
00199     }
00200 }
00201 
00202 bool FontColourChooser::eventFilter(QObject*, QEvent* e)
00203 {
00204     if (mReadOnly)
00205     {
00206         switch (e->type())
00207         {
00208             case QEvent::MouseMove:
00209             case QEvent::MouseButtonPress:
00210             case QEvent::MouseButtonRelease:
00211             case QEvent::MouseButtonDblClick:
00212             case QEvent::KeyPress:
00213             case QEvent::KeyRelease:
00214                 return true;   // prevent the event being handled
00215             default:
00216                 break;
00217         }
00218     }
00219     return false;
00220 }
00221 
00222 void FontColourChooser::slotDefaultFontToggled(bool on)
00223 {
00224     mFontChooser->setEnabled(!on);
00225 }

kalarm

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

kdepim

Skip menu "kdepim"
  •   akonadi_next
  •   kcal
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korganizer
  •   korgac
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • messageviewer
  • runtime
  •   kcm
  •       libmaildir
Generated for kdepim by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal