• Skip to content
  • Skip to link menu
KDE 4.2 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-2008 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 <klocale.h>
00029 #include <kfontchooser.h>
00030 #include <kfontdialog.h>
00031 #include <kcolordialog.h>
00032 #include <khbox.h>
00033 
00034 #include "kalarmapp.h"
00035 #include "preferences.h"
00036 #include "colourbutton.h"
00037 #include "checkbox.h"
00038 #include "fontcolour.moc"
00039 
00040 
00041 FontColourChooser::FontColourChooser(QWidget *parent,
00042           const QStringList &fontList, const QString& frameLabel, bool fg, bool defaultFont, int visibleListSize)
00043     : QWidget(parent),
00044       mFgColourButton(0),
00045       mReadOnly(false)
00046 {
00047     QVBoxLayout* topLayout = new QVBoxLayout(this);
00048     topLayout->setMargin(0);
00049     topLayout->setSpacing(KDialog::spacingHint());
00050     QWidget* page = this;
00051     if (!frameLabel.isNull())
00052     {
00053         page = new QGroupBox(frameLabel, this);
00054         topLayout->addWidget(page);
00055         topLayout = new QVBoxLayout(page);
00056         topLayout->setMargin(KDialog::marginHint());
00057         topLayout->setSpacing(KDialog::spacingHint());
00058     }
00059     QHBoxLayout* hlayout = new QHBoxLayout();
00060     hlayout->setMargin(0);
00061     topLayout->addLayout(hlayout);
00062     QVBoxLayout* colourLayout = new QVBoxLayout();
00063     colourLayout->setMargin(0);
00064     hlayout->addLayout(colourLayout);
00065     if (fg)
00066     {
00067         KHBox* box = new KHBox(page);    // to group widgets for QWhatsThis text
00068         box->setMargin(0);
00069         box->setSpacing(KDialog::spacingHint()/2);
00070         colourLayout->addWidget(box);
00071 
00072         QLabel* label = new QLabel(i18nc("@label:listbox", "Foreground color:"), box);
00073         box->setStretchFactor(new QWidget(box), 0);
00074         mFgColourButton = new ColourButton(box);
00075         connect(mFgColourButton, SIGNAL(changed(const QColor&)), SLOT(setSampleColour()));
00076         label->setBuddy(mFgColourButton);
00077         box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message foreground color"));
00078     }
00079 
00080     KHBox* box = new KHBox(page);    // to group widgets for QWhatsThis text
00081     box->setMargin(0);
00082     box->setSpacing(KDialog::spacingHint()/2);
00083     colourLayout->addWidget(box);
00084 
00085     QLabel* label = new QLabel(i18nc("@label:listbox", "Background color:"), box);
00086     box->setStretchFactor(new QWidget(box), 0);
00087     mBgColourButton = new ColourButton(box);
00088     connect(mBgColourButton, SIGNAL(changed(const QColor&)), SLOT(setSampleColour()));
00089     label->setBuddy(mBgColourButton);
00090     box->setWhatsThis(i18nc("@info:whatsthis", "Select the alarm message background color"));
00091     hlayout->addStretch();
00092 
00093     if (defaultFont)
00094     {
00095         QHBoxLayout* layout = new QHBoxLayout();
00096         layout->setMargin(0);
00097         topLayout->addLayout(layout);
00098         mDefaultFont = new CheckBox(i18nc("@option:check", "Use default font"), page);
00099         mDefaultFont->setMinimumSize(mDefaultFont->sizeHint());
00100         connect(mDefaultFont, SIGNAL(toggled(bool)), SLOT(slotDefaultFontToggled(bool)));
00101         mDefaultFont->setWhatsThis(i18nc("@info:whatsthis", "Check to use the default font current at the time the alarm is displayed."));
00102         layout->addWidget(mDefaultFont);
00103         layout->addWidget(new QWidget(page));    // left adjust the widget
00104     }
00105     else
00106         mDefaultFont = 0;
00107 
00108     mFontChooser = new KFontChooser(page, KFontChooser::DisplayFrame, fontList, visibleListSize);
00109     mFontChooser->installEventFilter(this);   // for read-only mode
00110     QList<QWidget*> kids = mFontChooser->findChildren<QWidget*>();
00111     for (int i = 0, end = kids.count();  i < end;  ++i)
00112         kids[i]->installEventFilter(this);
00113     topLayout->addWidget(mFontChooser);
00114 
00115     slotDefaultFontToggled(false);
00116 }
00117 
00118 void FontColourChooser::setDefaultFont()
00119 {
00120     if (mDefaultFont)
00121         mDefaultFont->setChecked(true);
00122 }
00123 
00124 void FontColourChooser::setFont(const QFont& font, bool onlyFixed)
00125 {
00126     if (mDefaultFont)
00127         mDefaultFont->setChecked(false);
00128     mFontChooser->setFont(font, onlyFixed);
00129 }
00130 
00131 bool FontColourChooser::defaultFont() const
00132 {
00133     return mDefaultFont ? mDefaultFont->isChecked() : false;
00134 }
00135 
00136 QFont FontColourChooser::font() const
00137 {
00138     return (mDefaultFont && mDefaultFont->isChecked()) ? QFont() : mFontChooser->font();
00139 }
00140 
00141 void FontColourChooser::setBgColour(const QColor& colour)
00142 {
00143     mBgColourButton->setColor(colour);
00144     mFontChooser->setBackgroundColor(colour);
00145 }
00146 
00147 void FontColourChooser::setSampleColour()
00148 {
00149     QColor bg = mBgColourButton->color();
00150     mFontChooser->setBackgroundColor(bg);
00151     QColor fg = fgColour();
00152     mFontChooser->setColor(fg);
00153 }
00154 
00155 QColor FontColourChooser::bgColour() const
00156 {
00157     return mBgColourButton->color();
00158 }
00159 
00160 QColor FontColourChooser::fgColour() const
00161 {
00162     if (mFgColourButton)
00163         return mFgColourButton->color();
00164     else
00165     {
00166         QColor bg = mBgColourButton->color();
00167         QPalette pal(bg, bg);
00168         return pal.color(QPalette::Active, QPalette::Text);
00169     }
00170 }
00171 
00172 QString FontColourChooser::sampleText() const
00173 {
00174     return mFontChooser->sampleText();
00175 }
00176 
00177 void FontColourChooser::setSampleText(const QString& text)
00178 {
00179     mFontChooser->setSampleText(text);
00180 }
00181 
00182 void FontColourChooser::setFgColour(const QColor& colour)
00183 {
00184     if (mFgColourButton)
00185     {
00186         mFgColourButton->setColor(colour);
00187         mFontChooser->setColor(colour);
00188     }
00189 }
00190 
00191 void FontColourChooser::setReadOnly(bool ro)
00192 {
00193     if (ro != mReadOnly)
00194     {
00195         mReadOnly = ro;
00196         if (mFgColourButton)
00197             mFgColourButton->setReadOnly(ro);
00198         mBgColourButton->setReadOnly(ro);
00199         mDefaultFont->setReadOnly(ro);
00200     }
00201 }
00202 
00203 bool FontColourChooser::eventFilter(QObject*, QEvent* e)
00204 {
00205     if (mReadOnly)
00206     {
00207         switch (e->type())
00208         {
00209             case QEvent::MouseMove:
00210             case QEvent::MouseButtonPress:
00211             case QEvent::MouseButtonRelease:
00212             case QEvent::MouseButtonDblClick:
00213             case QEvent::KeyPress:
00214             case QEvent::KeyRelease:
00215                 return true;   // prevent the event being handled
00216             default:
00217                 break;
00218         }
00219     }
00220     return false;
00221 }
00222 
00223 void FontColourChooser::slotDefaultFontToggled(bool on)
00224 {
00225     mFontChooser->setEnabled(!on);
00226 }

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
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
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