kalarm Library API Documentation

fontcolour.cpp

00001 /*
00002  *  fontcolour.cpp  -  font and colour chooser widget
00003  *  Program:  kalarm
00004  *  (C) 2001, 2002 by David Jarvie  software@astrojar.org.uk
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
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include <qobjectlist.h>
00022 #include <qwidget.h>
00023 #include <qgroupbox.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 
00027 #include <kdialog.h>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 
00031 #include "fontcolour.moc"
00032 
00033 
00034 FontColourChooser::FontColourChooser(QWidget *parent, const char *name,
00035           bool onlyFixed, const QStringList &fontList,
00036           bool makeFrame, const QString& frameLabel, bool fg, int visibleListSize)
00037    : QWidget(parent, name)
00038 {
00039    QVBoxLayout* topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00040    QWidget* page = this;
00041    if (makeFrame)
00042    {
00043       page = new QGroupBox(frameLabel, this);
00044       topLayout->addWidget(page);
00045       topLayout = new QVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
00046       topLayout->addSpacing(fontMetrics().lineSpacing()/2);
00047    }
00048 
00049    QGridLayout* grid = new QGridLayout(topLayout, (fg ? 3 : 2), 2);
00050    grid->addRowSpacing(0, KDialog::marginHint());
00051    int gridRow = 1;
00052 
00053    QLabel* label;
00054    if (fg)
00055    {
00056       label = new QLabel(i18n("Foreground color:"), page);
00057       grid->addWidget(label, gridRow, 0, AlignRight);
00058       label->setFixedSize(label->sizeHint());
00059       m_fgColourButton = new ColourCombo(page);
00060       grid->addWidget(m_fgColourButton, gridRow, 1, AlignRight);
00061       connect(m_fgColourButton, SIGNAL(activated(const QString&)), SLOT(setSampleColour()));
00062       ++gridRow;
00063    }
00064 
00065    label = new QLabel(i18n("Background color:"), page);
00066    label->setMinimumSize(label->sizeHint());
00067    grid->addWidget(label, gridRow, 0);
00068    m_bgColourButton = new ColourCombo(page);
00069    m_bgColourButton->setMinimumSize(m_bgColourButton->sizeHint());
00070    grid->addWidget(m_bgColourButton, gridRow, 1, AlignRight);
00071    connect(m_bgColourButton, SIGNAL(activated(const QString&)), SLOT(setSampleColour()));
00072 
00073    m_fontChooser = new KFontChooser(page, name, onlyFixed, fontList, false, visibleListSize);
00074    topLayout->addWidget(m_fontChooser);
00075 }
00076 
00077 FontColourChooser::~FontColourChooser()
00078 {
00079 }
00080 
00081 void FontColourChooser::setFgColour(const QColor& colour)
00082 {
00083    if (m_fgColourButton)
00084    {
00085       m_fgColourButton->setColour(colour);
00086       m_fontChooser->setColor(colour);
00087    }
00088 }
00089 
00090 void FontColourChooser::setBgColour(const QColor& colour)
00091 {
00092    m_bgColourButton->setColour(colour);
00093    m_fontChooser->setBackgroundColor(colour);
00094 }
00095 
00096 void FontColourChooser::setSampleColour()
00097 {
00098    QColor bg = m_bgColourButton->color();
00099    m_fontChooser->setBackgroundColor(bg);
00100    QColor fg = fgColour();
00101    m_fontChooser->setColor(fg);
00102 }
00103 
00104 QColor FontColourChooser::fgColour() const
00105 {
00106    QColor bg = m_bgColourButton->color();
00107    QPalette pal(bg, bg);
00108    return pal.color(QPalette::Active, QColorGroup::Text);
00109 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:26 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001