kwin Library API Documentation

b2/config/config.cpp

00001 /*
00002  *  This file contains the B2 configuration widget
00003  *
00004  *  Copyright (c) 2001
00005  *      Karol Szwed <gallium@kde.org>
00006  *      http://gallium.n3.net/
00007  */
00008 
00009 #include "config.h"
00010 #include <kglobal.h>
00011 #include <qwhatsthis.h>
00012 #include <qvbox.h>
00013 #include <klocale.h>
00014 
00015 
00016 extern "C"
00017 {
00018     KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent )
00019     {
00020         return(new B2Config(conf, parent));
00021     }
00022 }
00023 
00024 
00025 /* NOTE:
00026  * 'conf'   is a pointer to the kwindecoration modules open kwin config,
00027  *          and is by default set to the "Style" group.
00028  *
00029  * 'parent' is the parent of the QObject, which is a VBox inside the
00030  *          Configure tab in kwindecoration
00031  */
00032 
00033 B2Config::B2Config( KConfig* conf, QWidget* parent )
00034     : QObject( parent )
00035 {
00036     KGlobal::locale()->insertCatalogue("kwin_b2_config");
00037     b2Config = new KConfig("kwinb2rc");
00038     gb = new QVBox(parent);
00039 
00040     cbColorBorder = new QCheckBox(
00041             i18n("Draw window frames using &titlebar colors"), gb);
00042     QWhatsThis::add(cbColorBorder,
00043             i18n("When selected, the window borders "
00044                 "are drawn using the titlebar colors; otherwise, they are "
00045                 "drawn using normal border colors."));
00046 
00047     // Grab Handle
00048     showGrabHandleCb = new QCheckBox(
00049         i18n("Draw &resize handle"), gb);
00050     QWhatsThis::add(showGrabHandleCb,
00051         i18n("When selected, decorations are drawn with a \"grab handle\" "
00052          "in the bottom right corner of the windows; "
00053          "otherwise, no grab handle is drawn."));
00054 
00055     // Double click menu option support
00056     actionsGB = new QHGroupBox(i18n("Actions Settings"), gb);
00057     QLabel *menuDblClickLabel = new QLabel(actionsGB);
00058     menuDblClickLabel->setText(i18n("Double click on menu button:"));
00059     menuDblClickOp = new QComboBox(actionsGB);
00060     menuDblClickOp->insertItem(i18n("Do Nothing"));
00061     menuDblClickOp->insertItem(i18n("Minimize Window"));
00062     menuDblClickOp->insertItem(i18n("Shade Window"));
00063     menuDblClickOp->insertItem(i18n("Close Window"));
00064 
00065     QWhatsThis::add(menuDblClickOp,
00066         i18n("An action can be associated to a double click "
00067          "of the menu button. Leave it to none if in doubt."));
00068 
00069     // Load configuration options
00070     load(conf);
00071 
00072     // Ensure we track user changes properly
00073     connect(cbColorBorder, SIGNAL(clicked()),
00074             this, SLOT(slotSelectionChanged()));
00075     connect(showGrabHandleCb, SIGNAL(clicked()),
00076             this, SLOT(slotSelectionChanged()));
00077     connect(menuDblClickOp, SIGNAL(activated(int)),
00078             this, SLOT(slotSelectionChanged()));
00079     // Make the widgets visible in kwindecoration
00080     gb->show();
00081 }
00082 
00083 
00084 B2Config::~B2Config()
00085 {
00086     delete b2Config;
00087     delete gb;
00088 }
00089 
00090 
00091 void B2Config::slotSelectionChanged()
00092 {
00093     emit changed();
00094 }
00095 
00096 
00097 // Loads the configurable options from the kwinrc config file
00098 // It is passed the open config from kwindecoration to improve efficiency
00099 void B2Config::load(KConfig * /*conf*/)
00100 {
00101     b2Config->setGroup("General");
00102 
00103     bool override = b2Config->readBoolEntry("UseTitleBarBorderColors", false);
00104     cbColorBorder->setChecked(override);
00105 
00106     override = b2Config->readBoolEntry( "DrawGrabHandle", true );
00107     showGrabHandleCb->setChecked(override);
00108 
00109     QString returnString = b2Config->readEntry(
00110                     "MenuButtonDoubleClickOperation", "NoOp");
00111 
00112     int op;
00113     if (returnString == "Close") {
00114         op = 3;
00115     } else if (returnString == "Shade") {
00116         op = 2;
00117     } else if (returnString == "Minimize") {
00118         op = 1;
00119     } else {
00120         op = 0;
00121     }
00122 
00123     menuDblClickOp->setCurrentItem(op);
00124 
00125 }
00126 
00127 static QString opToString(int op)
00128 {
00129     switch (op) {
00130     case 1:
00131         return "Minimize";
00132     case 2:
00133         return "Shade";
00134     case 3:
00135         return "Close";
00136     case 0:
00137     default:
00138         return "NoOp";
00139     }
00140 }
00141 
00142 
00143 // Saves the configurable options to the kwinrc config file
00144 void B2Config::save(KConfig * /*conf*/)
00145 {
00146     b2Config->setGroup("General");
00147     b2Config->writeEntry("UseTitleBarBorderColors", cbColorBorder->isChecked());
00148     b2Config->writeEntry("DrawGrabHandle", showGrabHandleCb->isChecked());
00149     b2Config->writeEntry("MenuButtonDoubleClickOperation",
00150         opToString(menuDblClickOp->currentItem()));
00151     // Ensure others trying to read this config get updated
00152     b2Config->sync();
00153 }
00154 
00155 
00156 // Sets UI widget defaults which must correspond to style defaults
00157 void B2Config::defaults()
00158 {
00159     cbColorBorder->setChecked(false);
00160     showGrabHandleCb->setChecked(true);
00161     menuDblClickOp->setCurrentItem(0);
00162 }
00163 
00164 #include "config.moc"
00165 // vim: ts=4
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 6 02:41:04 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003