Warning, file /system/qtcurve/qt4/kwinconfig/qtcurvekwinconfig.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  *   Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #include "config.h"
0024 
0025 #include "qtcurvekwinconfig.h"
0026 
0027 #include <common/common.h>
0028 
0029 #include <qtcurve-utils/qtutils.h>
0030 
0031 #include <kconfig.h>
0032 #include <klocale.h>
0033 #include <kglobal.h>
0034 #include <kdeversion.h>
0035 
0036 #include <QDBusConnection>
0037 
0038 namespace QtCurve {
0039 
0040 using namespace KWin;
0041 
0042 static void
0043 insertColorEntries(QComboBox *combo)
0044 {
0045     combo->insertItem(ShadowConfig::CT_FOCUS, i18n("Focus"));
0046     combo->insertItem(ShadowConfig::CT_HOVER, i18n("Hover"));
0047     combo->insertItem(ShadowConfig::CT_SELECTION, i18n("Selection Background"));
0048     combo->insertItem(ShadowConfig::CT_TITLEBAR, i18n("Titlebar"));
0049     combo->insertItem(ShadowConfig::CT_GRAY, i18n("Gray"));
0050     combo->insertItem(ShadowConfig::CT_CUSTOM, i18n("Custom:"));
0051 }
0052 
0053 static void insertSizeEntries(QComboBox *combo)
0054 {
0055     combo->insertItem(KWin::QtCurveConfig::BORDER_NONE, i18n("No Border"));
0056     combo->insertItem(KWin::QtCurveConfig::BORDER_NO_SIDES, i18n("No Side Border"));
0057     combo->insertItem(KWin::QtCurveConfig::BORDER_TINY, i18n("Tiny"));
0058     combo->insertItem(KWin::QtCurveConfig::BORDER_NORMAL, i18n("Normal"));
0059     combo->insertItem(KWin::QtCurveConfig::BORDER_LARGE, i18n("Large"));
0060     combo->insertItem(KWin::QtCurveConfig::BORDER_VERY_LARGE, i18n("Very Large"));
0061     combo->insertItem(KWin::QtCurveConfig::BORDER_HUGE, i18n("Huge"));
0062     combo->insertItem(KWin::QtCurveConfig::BORDER_VERY_HUGE, i18n("Very Huge"));
0063     combo->insertItem(KWin::QtCurveConfig::BORDER_OVERSIZED, i18n("Oversized"));
0064 }
0065 
0066 static void insertShadeEntries(QComboBox *combo)
0067 {
0068     combo->insertItem(KWin::QtCurveConfig::SHADE_NONE, i18n("None"));
0069     combo->insertItem(KWin::QtCurveConfig::SHADE_DARK, i18n("Dark"));
0070     combo->insertItem(KWin::QtCurveConfig::SHADE_LIGHT, i18n("Light"));
0071     combo->insertItem(KWin::QtCurveConfig::SHADE_SHADOW, i18n("Shadow"));
0072 }
0073 
0074 static const char *constDBusService = "org.kde.kcontrol.QtCurve";
0075 
0076 KWinConfig::KWinConfig(KConfig *config, QWidget *parent)
0077                  : QWidget(parent)
0078                  , m_activeShadows(QPalette::Active)
0079                  , m_inactiveShadows(QPalette::Inactive)
0080 {
0081     Q_UNUSED(config);
0082 
0083     KGlobal::locale()->insertCatalog("qtcurve");
0084     KGlobal::locale()->insertCatalog("kwin_clients");
0085 
0086     if (!QDBusConnection::sessionBus().registerService(constDBusService)) {
0087         m_ok = false;
0088         QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
0089         layout->addWidget(new QLabel(i18n("<h3>Already Open</h3><p>Another "
0090                                           "QtCurve configuration dialog is "
0091                                           "already open. Please close the "
0092                                           "other before proceeding."), this));
0093     } else {
0094         m_ok = true;
0095 
0096         setupUi(this);
0097 
0098         insertSizeEntries(borderSize);
0099         insertColorEntries(activeShadowColorType);
0100         insertColorEntries(inactiveShadowColorType);
0101         insertShadeEntries(outerBorder);
0102         insertShadeEntries(innerBorder);
0103 
0104         load(nullptr);
0105         connect(borderSize, SIGNAL(currentIndexChanged(int)), this, SLOT(sizeChanged()));
0106         connect(roundBottom, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
0107         connect(outerBorder, SIGNAL(currentIndexChanged(int)), this, SLOT(outerBorderChanged()));
0108         connect(innerBorder, SIGNAL(currentIndexChanged(int)), this, SLOT(innerBorderChanged()));
0109         connect(borderlessMax, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
0110         connect(titleBarPad, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0111         connect(edgePad, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0112         titleBarPad->setRange(-5, 10);
0113         edgePad->setRange(0, 10);
0114         connect(useShadows, SIGNAL(toggled(bool)), this, SLOT(shadowsChanged()));
0115         connect(activeShadowSize, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0116         connect(activeShadowHOffset, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0117         connect(activeShadowVOffset, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0118         connect(activeShadowColorType, SIGNAL(currentIndexChanged(int)), this, SLOT(activeShadowColorTypeChanged()));
0119         connect(activeShadowColor, SIGNAL(changed(const QColor &)), this, SIGNAL(changed()));
0120         connect(inactiveShadowSize, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0121         connect(inactiveShadowHOffset, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0122         connect(inactiveShadowVOffset, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0123         connect(inactiveShadowColorType, SIGNAL(currentIndexChanged(int)), this, SLOT(inactiveShadowColorTypeChanged()));
0124         connect(inactiveShadowColor, SIGNAL(changed(const QColor &)), this, SIGNAL(changed()));
0125         connect(inactiveUsesActiveGradients, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
0126         activeShadowColorTypeChanged();
0127         inactiveShadowColorTypeChanged();
0128         activeShadowSize->setRange(ShadowConfig::MIN_SIZE,
0129                                    ShadowConfig::MAX_SIZE);
0130         inactiveShadowSize->setRange(ShadowConfig::MIN_SIZE,
0131                                      ShadowConfig::MAX_SIZE);
0132         activeShadowHOffset->setRange(ShadowConfig::MIN_OFFSET,
0133                                       ShadowConfig::MAX_OFFSET);
0134         inactiveShadowHOffset->setRange(ShadowConfig::MIN_OFFSET,
0135                                         ShadowConfig::MAX_OFFSET);
0136         activeShadowVOffset->setRange(ShadowConfig::MIN_OFFSET,
0137                                       ShadowConfig::MAX_OFFSET);
0138         inactiveShadowVOffset->setRange(ShadowConfig::MIN_OFFSET,
0139                                         ShadowConfig::MAX_OFFSET);
0140         setShadows();
0141 
0142         // TODO: remove
0143         grouping->setVisible(false);
0144         groupingLabel->setVisible(false);
0145         connect(activeOpacity, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0146         connect(inactiveOpacity, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
0147         connect(opaqueBorder, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
0148     }
0149 }
0150 
0151 KWinConfig::~KWinConfig()
0152 {
0153     if (m_ok) {
0154         QDBusConnection::sessionBus().unregisterService(constDBusService);
0155     }
0156 }
0157 
0158 void KWinConfig::load(KConfig *c)
0159 {
0160     if (!m_ok)
0161         return;
0162 
0163     KConfig *cfg=c ? c : new KConfig("kwinqtcurverc");
0164 
0165     m_activeShadows.load(cfg);
0166     m_inactiveShadows.load(cfg);
0167     setShadows();
0168     KWin::QtCurveConfig config;
0169 
0170     config.load(cfg, c ? KWIN_GROUP : nullptr);
0171     setWidgets(config);
0172     if(!c)
0173         delete cfg;
0174 }
0175 
0176 void KWinConfig::save(KConfig *c)
0177 {
0178     if (!m_ok)
0179         return;
0180 
0181     KConfig *cfg=c ? c : new KConfig("kwinqtcurverc");
0182 
0183     KWin::QtCurveConfig config;
0184 
0185     config.setBorderSize((KWin::QtCurveConfig::Size)borderSize->currentIndex());
0186     config.setRoundBottom(roundBottom->isChecked());
0187     config.setOuterBorder((KWin::QtCurveConfig::Shade)outerBorder->currentIndex());
0188     config.setInnerBorder((KWin::QtCurveConfig::Shade)innerBorder->currentIndex());
0189     config.setBorderlessMax(borderlessMax->isChecked());
0190     config.setTitleBarPad(titleBarPad->value());
0191     config.setEdgePad(edgePad->value());
0192 
0193     config.setCustomShadows(useShadows->isChecked());
0194     if(useShadows->isChecked())
0195     {
0196         m_activeShadows.setShadowSize(activeShadowSize->value());
0197         m_activeShadows.setHorizontalOffset(activeShadowHOffset->value());
0198         m_activeShadows.setVerticalOffset(activeShadowVOffset->value());
0199         m_activeShadows.setColorType((ShadowConfig::ColorType)activeShadowColorType->currentIndex());
0200         if(ShadowConfig::CT_CUSTOM==activeShadowColorType->currentIndex())
0201             m_activeShadows.setColor(activeShadowColor->color());
0202         m_inactiveShadows.setShadowSize(inactiveShadowSize->value());
0203         m_inactiveShadows.setHorizontalOffset(inactiveShadowHOffset->value());
0204         m_inactiveShadows.setVerticalOffset(inactiveShadowVOffset->value());
0205         m_inactiveShadows.setColorType((ShadowConfig::ColorType)inactiveShadowColorType->currentIndex());
0206         m_inactiveShadows.setShadowType(inactiveUsesActiveGradients->isChecked()
0207                                             ? ShadowConfig::SH_ACTIVE
0208                                             : ShadowConfig::SH_INACTIVE);
0209         if(ShadowConfig::CT_CUSTOM==inactiveShadowColorType->currentIndex())
0210             m_inactiveShadows.setColor(inactiveShadowColor->color());
0211     }
0212     else
0213     {
0214         m_activeShadows.defaults();
0215         m_inactiveShadows.defaults();
0216     }
0217     m_activeShadows.save(cfg);
0218     m_inactiveShadows.save(cfg);
0219     config.setOpacity(activeOpacity->value(), true);
0220     config.setOpacity(inactiveOpacity->value(), false);
0221     config.setOpaqueBorder(opaqueBorder->isChecked());
0222     config.save(cfg, c ? KWIN_GROUP : nullptr);
0223     cfg->sync();
0224     if(!c)
0225         delete cfg;
0226 }
0227 
0228 void KWinConfig::defaults()
0229 {
0230     if (!m_ok)
0231         return;
0232 
0233     setWidgets(KWin::QtCurveConfig());
0234     m_activeShadows.defaults();
0235     m_inactiveShadows.defaults();
0236     setShadows();
0237 }
0238 
0239 void KWinConfig::outerBorderChanged()
0240 {
0241     if(KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex())
0242         innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_NONE);
0243     if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex())
0244         useShadows->setChecked(true);
0245     setWidgetStates();
0246     emit changed();
0247 }
0248 
0249 void KWinConfig::innerBorderChanged()
0250 {
0251     if(KWin::QtCurveConfig::SHADE_NONE!=innerBorder->currentIndex() &&
0252        KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex())
0253         outerBorder->setCurrentIndex(innerBorder->currentIndex());
0254     if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex())
0255         useShadows->setChecked(true);
0256     emit changed();
0257 }
0258 
0259 void KWinConfig::shadowsChanged()
0260 {
0261     if(!useShadows->isChecked())
0262     {
0263         if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex())
0264             outerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_DARK);
0265         if(KWin::QtCurveConfig::SHADE_SHADOW==innerBorder->currentIndex())
0266             innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_DARK);
0267     }
0268     emit changed();
0269 }
0270 
0271 void KWinConfig::activeShadowColorTypeChanged()
0272 {
0273     activeShadowColor->setEnabled(ShadowConfig::CT_CUSTOM==activeShadowColorType->currentIndex());
0274     if(m_activeShadows.colorType()!=activeShadowColorType->currentIndex())
0275         emit changed();
0276 }
0277 
0278 void KWinConfig::inactiveShadowColorTypeChanged()
0279 {
0280     inactiveShadowColor->setEnabled(ShadowConfig::CT_CUSTOM==inactiveShadowColorType->currentIndex());
0281     if(m_inactiveShadows.colorType()!=inactiveShadowColorType->currentIndex())
0282         emit changed();
0283 }
0284 
0285 void KWinConfig::sizeChanged()
0286 {
0287     setWidgetStates();
0288     emit changed();
0289 }
0290 
0291 void KWinConfig::setWidgets(const KWin::QtCurveConfig &cfg)
0292 {
0293     borderSize->setCurrentIndex(cfg.borderSize());
0294     roundBottom->setChecked(cfg.roundBottom());
0295     outerBorder->setCurrentIndex(cfg.outerBorder());
0296     innerBorder->setCurrentIndex(cfg.innerBorder());
0297     borderlessMax->setChecked(cfg.borderlessMax());
0298     titleBarPad->setValue(cfg.titleBarPad());
0299     edgePad->setValue(cfg.edgePad());
0300     useShadows->setChecked(cfg.customShadows());
0301     activeOpacity->setValue(cfg.opacity(true));
0302     inactiveOpacity->setValue(cfg.opacity(false));
0303     opaqueBorder->setChecked(cfg.opaqueBorder());
0304     setWidgetStates();
0305 }
0306 
0307 void KWinConfig::setWidgetStates()
0308 {
0309     if(KWin::QtCurveConfig::BORDER_NONE==borderSize->currentIndex())
0310     {
0311         roundBottom->setEnabled(false);
0312         roundBottom->setChecked(false);
0313     }
0314     else
0315         roundBottom->setEnabled(true);
0316 
0317     if(KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex() ||
0318        borderSize->currentIndex()<KWin::QtCurveConfig::BORDER_TINY)
0319     {
0320         innerBorder->setEnabled(false);
0321         innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_NONE);
0322     }
0323     else
0324         innerBorder->setEnabled(true);
0325 }
0326 
0327 void KWinConfig::setNote(const QString &txt)
0328 {
0329     noteLabel->setText(txt);
0330 }
0331 
0332 void KWinConfig::setShadows()
0333 {
0334     activeShadowSize->setValue(m_activeShadows.shadowSize());
0335     activeShadowHOffset->setValue(m_activeShadows.horizontalOffset());
0336     activeShadowVOffset->setValue(m_activeShadows.verticalOffset());
0337     activeShadowColor->setColor(m_activeShadows.color());
0338     activeShadowColorType->setCurrentIndex(m_activeShadows.colorType());
0339     inactiveShadowSize->setValue(m_inactiveShadows.shadowSize());
0340     inactiveShadowHOffset->setValue(m_inactiveShadows.horizontalOffset());
0341     inactiveShadowVOffset->setValue(m_inactiveShadows.verticalOffset());
0342     inactiveShadowColor->setColor(m_inactiveShadows.color());
0343     inactiveShadowColorType->setCurrentIndex(m_inactiveShadows.colorType());
0344     inactiveUsesActiveGradients->setChecked(ShadowConfig::SH_ACTIVE==m_inactiveShadows.shadowType());
0345 }
0346 
0347 }
0348 
0349 extern "C" Q_DECL_EXPORT QObject*
0350 allocate_config(KConfig *config, QWidget *parent)
0351 {
0352     return new QtCurve::KWinConfig(config, parent);
0353 }
0354 
0355 #include "qtcurvekwinconfig.moc"