Back to index

kdeartwork  4.3.2
glowconfigdialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           glowconfigdialog.cpp  -  description
00003                              -------------------
00004     begin                : Thu Sep 12 2001
00005     copyright            : (C) 2001 by Henning Burchardt
00006     email                : h_burchardt@gmx.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <qbitmap.h>
00019 #include <q3buttongroup.h>
00020 #include <qcheckbox.h>
00021 #include <qcombobox.h>
00022 #include <qdir.h>
00023 #include <qfileinfo.h>
00024 #include <q3groupbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <q3listview.h>
00028 #include <qpushbutton.h>
00029 #include <qsignalmapper.h>
00030 #include <qstringlist.h>
00031 //Added by qt3to4:
00032 #include <QPixmap>
00033 #include <QHBoxLayout>
00034 #include <QVBoxLayout>
00035 #include <kconfig.h>
00036 #include <kcolorbutton.h>
00037 #include <kdebug.h>
00038 #include <kglobal.h>
00039 #include <kglobalsettings.h>
00040 #include <klocale.h>
00041 #include <kpixmap.h>
00042 #include <kpixmapeffect.h>
00043 #include <kstandarddirs.h>
00044 #include <kconfiggroup.h>
00045 #include "bitmaps.h"
00046 #include "glowconfigdialog.h"
00047 #include "../resources.h"
00048 
00049 #define NUMBER_OF_BUTTONS 5
00050 
00051 extern "C"
00052 {
00053        KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent )
00054        {
00055               return(new GlowConfigDialog(conf, parent));
00056        }
00057 }
00058 
00059 GlowConfigDialog::GlowConfigDialog( KConfig * conf, QWidget * parent )
00060        : QObject(parent)
00061 {
00062        _glowConfig = new KConfig("kwinglowrc");
00063        KGlobal::locale()->insertCatalog("kwin_glow_config");
00064 
00065        _main_group_box = new QWidget(parent);
00066        QVBoxLayout *main_group_boxLayout = new QVBoxLayout(_main_group_box);
00067        main_group_boxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
00068        main_group_boxLayout->setSpacing(6);
00069 
00070        //-------------------------------------------------------------------------
00071        // themes
00072 
00073        _theme_list_view = new Q3ListView (_main_group_box, "theme_list_view");
00074        _theme_list_view->addColumn (i18n("Theme"));
00075        _theme_list_view->addColumn (i18n("Button Size"));
00076         _theme_list_view->setAllColumnsShowFocus(true);
00077         _theme_list_view->setResizeMode(Q3ListView::AllColumns);
00078 
00079        main_group_boxLayout->addWidget (_theme_list_view);
00080        QObject::connect (_theme_list_view, SIGNAL(selectionChanged()),
00081                      this, SLOT(slotThemeListViewSelectionChanged()));
00082        slotLoadThemeList();
00083 
00084        _button_glow_color_group_box = new Q3GroupBox(
00085               0, Qt::Horizontal, i18n("Button Glow Colors"), _main_group_box);
00086        QHBoxLayout *colorHBoxLayout =
00087               new QHBoxLayout(_button_glow_color_group_box->layout());
00088 
00089        // create buttons
00090        QSize buttonSize(BITMAP_SIZE, BITMAP_SIZE);
00091        QPixmap pm(buttonSize);
00092        pm.fill(Qt::black);
00093 
00094        _stickyButton = new QPushButton(_button_glow_color_group_box);
00095        pm.setMask(QBitmap(buttonSize, stickyoff_bits, true));
00096        _stickyButton->setPixmap(pm);
00097        colorHBoxLayout->addWidget(_stickyButton);
00098        _titleButtonList.push_back(_stickyButton);
00099 
00100        _helpButton = new QPushButton(_button_glow_color_group_box);
00101        pm.setMask(QBitmap(buttonSize, help_bits, true));
00102        _helpButton->setPixmap(pm);
00103        colorHBoxLayout->addWidget(_helpButton);
00104        _titleButtonList.push_back(_helpButton);
00105 
00106        _iconifyButton = new QPushButton(_button_glow_color_group_box);
00107        pm.setMask(QBitmap(buttonSize, minimize_bits, true));
00108        _iconifyButton->setPixmap(pm);
00109        colorHBoxLayout->addWidget(_iconifyButton);
00110        _titleButtonList.push_back(_iconifyButton);
00111 
00112        _maximizeButton = new QPushButton(_button_glow_color_group_box);
00113        pm.setMask(QBitmap(buttonSize, maximizeoff_bits, true));
00114        _maximizeButton->setPixmap(pm);
00115        colorHBoxLayout->addWidget(_maximizeButton);
00116        _titleButtonList.push_back(_maximizeButton);
00117 
00118        _closeButton = new QPushButton(_button_glow_color_group_box);
00119        pm.setMask(QBitmap(buttonSize, close_bits, true));
00120        _closeButton->setPixmap(pm);
00121        colorHBoxLayout->addWidget(_closeButton);
00122        _titleButtonList.push_back(_closeButton);
00123 
00124        // create signal mapper
00125        _titleButtonMapper = new QSignalMapper(this);
00126        for( uint i=0; i<_titleButtonList.size(); i++ ) {
00127               _titleButtonMapper->setMapping(_titleButtonList[i], i);
00128               connect(_titleButtonList[i], SIGNAL(clicked()),_titleButtonMapper, SLOT(map()));
00129        }
00130        connect(_titleButtonMapper, SIGNAL(mapped(int)),this, SLOT(slotTitleButtonClicked(int)));
00131 
00132        _colorButton = new KColorButton(_button_glow_color_group_box);
00133        _colorButton->setEnabled(false);
00134        connect(_colorButton, SIGNAL(changed(const QColor&)),
00135               this, SLOT(slotColorButtonChanged(const QColor&)));
00136 
00137        colorHBoxLayout->addItem(new QSpacerItem(
00138               200, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
00139        colorHBoxLayout->addWidget(_colorButton);
00140 
00141        main_group_boxLayout->addWidget(_button_glow_color_group_box);
00142 
00143        QHBoxLayout *titlebarGradientTypeLayout = new QHBoxLayout();
00144        _titlebarGradientTypeComboBox = new QComboBox(_main_group_box);
00145 
00146     KSharedConfig::Ptr c = KGlobal::config();
00147     KConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00148     QColor activeBackground = c->readColorEntry("activeBackground");
00149     QColor activeBlend = c->readColorEntry("activeBlend");
00150 
00151        // If the colors are equal, change one to get a gradient effect
00152        if (activeBackground==activeBlend) {
00153               activeBackground = activeBackground.dark();
00154        }
00155        for (int i=0; i< KPixmapEffect::EllipticGradient; i++ ) {
00156               KPixmap gradPixmap(QSize(196,20));
00157               KPixmapEffect::gradient(gradPixmap, activeBackground,
00158                                                         activeBlend, (KPixmapEffect::GradientType) i);
00159 
00160               _titlebarGradientTypeComboBox->insertItem(gradPixmap, i);
00161        }
00162 
00163        connect(_titlebarGradientTypeComboBox, SIGNAL(activated(int)),
00164               this, SLOT(slotTitlebarGradientTypeChanged(int)));
00165        titlebarGradientTypeLayout->addWidget(
00166               new QLabel(i18n("Titlebar gradient:"), _main_group_box));
00167        titlebarGradientTypeLayout->addWidget(_titlebarGradientTypeComboBox, 0, Qt::AlignLeft);
00168         titlebarGradientTypeLayout->addStretch(10);
00169        main_group_boxLayout->addLayout(titlebarGradientTypeLayout);
00170 
00171 
00172        _showResizeHandleCheckBox = new QCheckBox(
00173                      i18n("Show resize handle"), _main_group_box);
00174        connect(_showResizeHandleCheckBox, SIGNAL(clicked()),
00175               this, SLOT(slotResizeHandleCheckBoxChanged()));
00176        main_group_boxLayout->addWidget(_showResizeHandleCheckBox);
00177 
00178        // load config and update user interface
00179        load(conf);
00180 
00181        _main_group_box->show();
00182 }
00183 
00184 GlowConfigDialog::~GlowConfigDialog()
00185 {
00186        delete _main_group_box;
00187        delete _glowConfig;
00188        delete[] _buttonConfigMap;
00189 }
00190 
00191 void GlowConfigDialog::load( KConfig* /* conf */ )
00192 {
00193        QColor color;
00194        const QColor defaultCloseButtonColor(DEFAULT_CLOSE_BUTTON_COLOR);
00195        const QColor defaultMaximizeButtonColor(DEFAULT_MAXIMIZE_BUTTON_COLOR);
00196        const QColor defaultIconifyButtonColor(DEFAULT_ICONIFY_BUTTON_COLOR);
00197        const QColor defaultHelpButtonColor(DEFAULT_HELP_BUTTON_COLOR);
00198        const QColor defaultStickyButtonColor(DEFAULT_STICKY_BUTTON_COLOR);
00199 
00200        _glowConfig->setGroup("General");
00201 
00202        _buttonConfigMap = new QColor[NUMBER_OF_BUTTONS];
00203        color = _glowConfig->readColorEntry("stickyButtonGlowColor",
00204                      &defaultStickyButtonColor);
00205        _buttonConfigMap[stickyButton] = color;
00206 
00207        color = _glowConfig->readColorEntry("helpButtonGlowColor",
00208                      &defaultHelpButtonColor);
00209        _buttonConfigMap[helpButton] = color;
00210 
00211        color = _glowConfig->readColorEntry("iconifyButtonGlowColor",
00212                      &defaultIconifyButtonColor);
00213        _buttonConfigMap[iconifyButton] = color;
00214 
00215        color = _glowConfig->readColorEntry("maximizeButtonGlowColor",
00216                      &defaultMaximizeButtonColor);
00217        _buttonConfigMap[maximizeButton] = color;
00218 
00219        color = _glowConfig->readColorEntry("closeButtonGlowColor",
00220                      &defaultCloseButtonColor);
00221        _buttonConfigMap[closeButton] = color;
00222 
00223        _showResizeHandle = _glowConfig->readEntry("showResizeHandle", true);
00224        _titlebarGradientType = static_cast<KPixmapEffect::GradientType>
00225                                                  (_glowConfig->readNumEntry("titlebarGradientType",
00226                                                  KPixmapEffect::DiagonalGradient));
00227 
00228        _showResizeHandleCheckBox->setChecked(_showResizeHandle);
00229        _titlebarGradientTypeComboBox->setCurrentItem(_titlebarGradientType);
00230 
00231        _theme_name = _glowConfig->readEntry ("themeName", "default");
00232        _theme_list_view->setSelected (
00233                      _theme_list_view->findItem (_theme_name, 0), true);
00234         slotTitleButtonClicked(0);
00235 }
00236 
00237 void GlowConfigDialog::save( KConfig* /* conf */ )
00238 {
00239        _glowConfig->setGroup("General");
00240 
00241        _glowConfig->writeEntry("stickyButtonGlowColor", _buttonConfigMap[stickyButton]);
00242        _glowConfig->writeEntry("helpButtonGlowColor", _buttonConfigMap[helpButton]);
00243        _glowConfig->writeEntry("iconifyButtonGlowColor", _buttonConfigMap[iconifyButton]);
00244        _glowConfig->writeEntry("maximizeButtonGlowColor", _buttonConfigMap[maximizeButton]);
00245        _glowConfig->writeEntry("closeButtonGlowColor", _buttonConfigMap[closeButton]);
00246 
00247        _glowConfig->writeEntry("showResizeHandle", _showResizeHandle);
00248        _glowConfig->writeEntry("titlebarGradientType", _titlebarGradientType);
00249 
00250        _glowConfig->writeEntry ("themeName", _theme_name);
00251 
00252        _glowConfig->sync();
00253 }
00254 
00255 void GlowConfigDialog::defaults()
00256 {
00257        const QColor defaultCloseButtonColor = DEFAULT_CLOSE_BUTTON_COLOR;
00258        const QColor defaultMaximizeButtonColor(DEFAULT_MAXIMIZE_BUTTON_COLOR);
00259        const QColor defaultIconifyButtonColor(DEFAULT_ICONIFY_BUTTON_COLOR);
00260        const QColor defaultHelpButtonColor(DEFAULT_HELP_BUTTON_COLOR);
00261        const QColor defaultStickyButtonColor(DEFAULT_STICKY_BUTTON_COLOR);
00262 
00263        _buttonConfigMap[stickyButton] = defaultStickyButtonColor;
00264        _buttonConfigMap[helpButton] = defaultHelpButtonColor;
00265        _buttonConfigMap[iconifyButton] = defaultIconifyButtonColor;
00266        _buttonConfigMap[maximizeButton] = defaultMaximizeButtonColor;
00267        _buttonConfigMap[closeButton] = defaultCloseButtonColor;
00268 
00269        _showResizeHandle = true;
00270        _titlebarGradientType = KPixmapEffect::DiagonalGradient;
00271 
00272        _showResizeHandleCheckBox->setChecked(_showResizeHandle);
00273        _titlebarGradientTypeComboBox->setCurrentItem(_titlebarGradientType);
00274 
00275        _theme_list_view->setSelected (
00276                      _theme_list_view->findItem("default", 0), true);
00277 }
00278 
00279 void GlowConfigDialog::slotLoadThemeList ()
00280 {
00281        QStringList dir_list=KGlobal::dirs()->findDirs("data", "kwin/glow-themes");
00282 
00283        QStringList::ConstIterator it;
00284 
00285        _theme_list_view->clear();
00286        new Q3ListViewItem (_theme_list_view, "default", "17x17");
00287 
00288        for (it=dir_list.begin(); it!=dir_list.end(); ++it)
00289        {
00290               QDir dir (*it, QString("*"), QDir::Unsorted,
00291                             QDir::Dirs | QDir::Readable);
00292               if (dir.exists())
00293               {
00294                      QFileInfoListIterator it2(*dir.entryInfoList());
00295                      QFileInfo * finfo;
00296 
00297                      while ((finfo=it2.current()))
00298                      {
00299                             if (finfo->fileName() == "." || finfo->fileName() == "..") {
00300                                    ++it2;
00301                                    continue;
00302                             }
00303 
00304                             if (! _theme_list_view->findItem (finfo->fileName(), 0))
00305                             {
00306                                    KConfig conf (dir.path() + "/" + finfo->fileName() + "/" +
00307                                                  finfo->fileName() + ".theme");
00308                                    QSize button_size = conf.readSizeEntry (
00309                                           "buttonSize", new QSize (-1, -1));
00310                                    if (button_size.width() == -1)
00311                                    {
00312                                           ++it2;
00313                                           continue;
00314                                    }
00315                                    QString size_string = QString("") +
00316                                           QString::number(button_size.width()) +
00317                                           "x" + QString::number(button_size.height());
00318                                    new Q3ListViewItem (_theme_list_view,
00319                                                  finfo->fileName(), size_string);
00320                             }
00321 
00322                             ++it2;
00323                      }
00324               }
00325        }
00326 }
00327 
00328 void GlowConfigDialog::slotTitlebarGradientTypeChanged(int index)
00329 {
00330        _titlebarGradientType = static_cast<KPixmapEffect::GradientType>(index);
00331        emit changed();
00332 }
00333 
00334 void GlowConfigDialog::slotResizeHandleCheckBoxChanged()
00335 {
00336        _showResizeHandle = _showResizeHandleCheckBox->isChecked();
00337        emit changed();
00338 }
00339 
00340 void GlowConfigDialog::slotTitleButtonClicked(int index)
00341 {
00342        for( int i=0; i< ((int) _titleButtonList.size()); i++ ) {
00343               _titleButtonList[i]->setDown(i==index);
00344        }
00345        _colorButton->setEnabled(true);
00346        _colorButton->setColor(_buttonConfigMap[index]);
00347 }
00348 
00349 void GlowConfigDialog::slotColorButtonChanged(const QColor& glowColor)
00350 {
00351        if( _stickyButton->isDown() ) {
00352               _buttonConfigMap[stickyButton] = glowColor;
00353        } else if( _helpButton->isDown() ) {
00354               _buttonConfigMap[helpButton] = glowColor;
00355        } else if( _iconifyButton->isDown() ) {
00356               _buttonConfigMap[iconifyButton] = glowColor;
00357        } else if( _maximizeButton->isDown() ) {
00358               _buttonConfigMap[maximizeButton] = glowColor;
00359        } else {
00360               _buttonConfigMap[closeButton] = glowColor;
00361        }
00362        emit changed();
00363 }
00364 
00365 void GlowConfigDialog::slotThemeListViewSelectionChanged ()
00366 {
00367        if( _theme_list_view->selectedItem() != 0 ) {
00368               _theme_name = _theme_list_view->selectedItem()->text (0);
00369 
00370               emit changed();
00371        }
00372 }
00373 
00374 #include "glowconfigdialog.moc"