File indexing completed on 2024-05-05 05:50:16
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 <KConfigCore/KConfig> 0032 0033 #include <QDBusConnection> 0034 0035 namespace QtCurve { 0036 0037 using namespace KWin; 0038 0039 static void 0040 insertColorEntries(QComboBox *combo) 0041 { 0042 combo->insertItem(ShadowConfig::CT_FOCUS, i18n("Focus")); 0043 combo->insertItem(ShadowConfig::CT_HOVER, i18n("Hover")); 0044 combo->insertItem(ShadowConfig::CT_SELECTION, i18n("Selection Background")); 0045 combo->insertItem(ShadowConfig::CT_TITLEBAR, i18n("Titlebar")); 0046 combo->insertItem(ShadowConfig::CT_GRAY, i18n("Gray")); 0047 combo->insertItem(ShadowConfig::CT_CUSTOM, i18n("Custom:")); 0048 } 0049 0050 static void insertSizeEntries(QComboBox *combo) 0051 { 0052 combo->insertItem(KWin::QtCurveConfig::BORDER_NONE, i18n("No Border")); 0053 combo->insertItem(KWin::QtCurveConfig::BORDER_NO_SIDES, i18n("No Side Border")); 0054 combo->insertItem(KWin::QtCurveConfig::BORDER_TINY, i18n("Tiny")); 0055 combo->insertItem(KWin::QtCurveConfig::BORDER_NORMAL, i18n("Normal")); 0056 combo->insertItem(KWin::QtCurveConfig::BORDER_LARGE, i18n("Large")); 0057 combo->insertItem(KWin::QtCurveConfig::BORDER_VERY_LARGE, i18n("Very Large")); 0058 combo->insertItem(KWin::QtCurveConfig::BORDER_HUGE, i18n("Huge")); 0059 combo->insertItem(KWin::QtCurveConfig::BORDER_VERY_HUGE, i18n("Very Huge")); 0060 combo->insertItem(KWin::QtCurveConfig::BORDER_OVERSIZED, i18n("Oversized")); 0061 } 0062 0063 static void insertShadeEntries(QComboBox *combo) 0064 { 0065 combo->insertItem(KWin::QtCurveConfig::SHADE_NONE, i18n("None")); 0066 combo->insertItem(KWin::QtCurveConfig::SHADE_DARK, i18n("Dark")); 0067 combo->insertItem(KWin::QtCurveConfig::SHADE_LIGHT, i18n("Light")); 0068 combo->insertItem(KWin::QtCurveConfig::SHADE_SHADOW, i18n("Shadow")); 0069 } 0070 0071 static const char *constDBusService = "org.kde.kcontrol.QtCurve"; 0072 0073 KWinConfig::KWinConfig(KConfig *config, QWidget *parent) 0074 : QWidget(parent) 0075 , m_activeShadows(QPalette::Active) 0076 , m_inactiveShadows(QPalette::Inactive) 0077 { 0078 Q_UNUSED(config); 0079 0080 if (!QDBusConnection::sessionBus().registerService(constDBusService)) { 0081 m_ok = false; 0082 QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); 0083 layout->addWidget(new QLabel(i18n("<h3>Already Open</h3><p>Another " 0084 "QtCurve configuration dialog is " 0085 "already open. Please close the " 0086 "other before proceeding."), this)); 0087 } else { 0088 m_ok = true; 0089 0090 setupUi(this); 0091 0092 insertSizeEntries(borderSize); 0093 insertColorEntries(activeShadowColorType); 0094 insertColorEntries(inactiveShadowColorType); 0095 insertShadeEntries(outerBorder); 0096 insertShadeEntries(innerBorder); 0097 0098 load(nullptr); 0099 connect(qtcSlot(borderSize, currentIndexChanged, (int)), 0100 qtcSlot(this, sizeChanged)); 0101 connect(qtcSlot(roundBottom, toggled), qtcSlot(this, changed)); 0102 connect(qtcSlot(outerBorder, currentIndexChanged, (int)), 0103 qtcSlot(this, outerBorderChanged)); 0104 connect(qtcSlot(innerBorder, currentIndexChanged, (int)), 0105 qtcSlot(this, innerBorderChanged)); 0106 connect(qtcSlot(borderlessMax, toggled), qtcSlot(this, changed)); 0107 connect(qtcSlot(titleBarPad, valueChanged, (int)), 0108 qtcSlot(this, changed)); 0109 connect(qtcSlot(edgePad, valueChanged, (int)), qtcSlot(this, changed)); 0110 titleBarPad->setRange(-5, 10); 0111 edgePad->setRange(0, 10); 0112 connect(qtcSlot(useShadows, toggled), qtcSlot(this, shadowsChanged)); 0113 connect(qtcSlot(activeShadowSize, valueChanged, (int)), 0114 qtcSlot(this, changed)); 0115 connect(qtcSlot(activeShadowHOffset, valueChanged, (int)), 0116 qtcSlot(this, changed)); 0117 connect(qtcSlot(activeShadowVOffset, valueChanged, (int)), 0118 qtcSlot(this, changed)); 0119 connect(qtcSlot(activeShadowColorType, currentIndexChanged, (int)), 0120 qtcSlot(this, activeShadowColorTypeChanged)); 0121 connect(qtcSlot(activeShadowColor, changed), qtcSlot(this, changed)); 0122 connect(qtcSlot(inactiveShadowSize, valueChanged, (int)), 0123 qtcSlot(this, changed)); 0124 connect(qtcSlot(inactiveShadowHOffset, valueChanged, (int)), 0125 qtcSlot(this, changed)); 0126 connect(qtcSlot(inactiveShadowVOffset, valueChanged, (int)), 0127 qtcSlot(this, changed)); 0128 connect(qtcSlot(inactiveShadowColorType, currentIndexChanged, (int)), 0129 qtcSlot(this, inactiveShadowColorTypeChanged)); 0130 connect(qtcSlot(inactiveShadowColor, changed), qtcSlot(this, changed)); 0131 connect(qtcSlot(inactiveUsesActiveGradients, toggled), 0132 qtcSlot(this, changed)); 0133 activeShadowColorTypeChanged(); 0134 inactiveShadowColorTypeChanged(); 0135 activeShadowSize->setRange(ShadowConfig::MIN_SIZE, 0136 ShadowConfig::MAX_SIZE); 0137 inactiveShadowSize->setRange(ShadowConfig::MIN_SIZE, 0138 ShadowConfig::MAX_SIZE); 0139 activeShadowHOffset->setRange(ShadowConfig::MIN_OFFSET, 0140 ShadowConfig::MAX_OFFSET); 0141 inactiveShadowHOffset->setRange(ShadowConfig::MIN_OFFSET, 0142 ShadowConfig::MAX_OFFSET); 0143 activeShadowVOffset->setRange(ShadowConfig::MIN_OFFSET, 0144 ShadowConfig::MAX_OFFSET); 0145 inactiveShadowVOffset->setRange(ShadowConfig::MIN_OFFSET, 0146 ShadowConfig::MAX_OFFSET); 0147 setShadows(); 0148 0149 // TODO: remove 0150 grouping->setVisible(false); 0151 groupingLabel->setVisible(false); 0152 connect(qtcSlot(activeOpacity, valueChanged, (int)), 0153 qtcSlot(this, changed)); 0154 connect(qtcSlot(inactiveOpacity, valueChanged, (int)), 0155 qtcSlot(this, changed)); 0156 connect(qtcSlot(opaqueBorder, toggled), qtcSlot(this, changed)); 0157 } 0158 } 0159 0160 KWinConfig::~KWinConfig() 0161 { 0162 if (m_ok) { 0163 QDBusConnection::sessionBus().unregisterService(constDBusService); 0164 } 0165 } 0166 0167 void KWinConfig::load(KConfig *c) 0168 { 0169 if (!m_ok) 0170 return; 0171 0172 KConfig *cfg=c ? c : new KConfig("kwinqtcurverc"); 0173 0174 m_activeShadows.load(cfg); 0175 m_inactiveShadows.load(cfg); 0176 setShadows(); 0177 KWin::QtCurveConfig config; 0178 0179 config.load(cfg, c ? KWIN_GROUP : nullptr); 0180 setWidgets(config); 0181 if(!c) 0182 delete cfg; 0183 } 0184 0185 void KWinConfig::save(KConfig *c) 0186 { 0187 if (!m_ok) 0188 return; 0189 0190 KConfig *cfg=c ? c : new KConfig("kwinqtcurverc"); 0191 0192 KWin::QtCurveConfig config; 0193 0194 config.setBorderSize((KWin::QtCurveConfig::Size)borderSize->currentIndex()); 0195 config.setRoundBottom(roundBottom->isChecked()); 0196 config.setOuterBorder((KWin::QtCurveConfig::Shade)outerBorder->currentIndex()); 0197 config.setInnerBorder((KWin::QtCurveConfig::Shade)innerBorder->currentIndex()); 0198 config.setBorderlessMax(borderlessMax->isChecked()); 0199 config.setTitleBarPad(titleBarPad->value()); 0200 config.setEdgePad(edgePad->value()); 0201 0202 config.setCustomShadows(useShadows->isChecked()); 0203 if(useShadows->isChecked()) 0204 { 0205 m_activeShadows.setShadowSize(activeShadowSize->value()); 0206 m_activeShadows.setHorizontalOffset(activeShadowHOffset->value()); 0207 m_activeShadows.setVerticalOffset(activeShadowVOffset->value()); 0208 m_activeShadows.setColorType((ShadowConfig::ColorType)activeShadowColorType->currentIndex()); 0209 if(ShadowConfig::CT_CUSTOM==activeShadowColorType->currentIndex()) 0210 m_activeShadows.setColor(activeShadowColor->color()); 0211 m_inactiveShadows.setShadowSize(inactiveShadowSize->value()); 0212 m_inactiveShadows.setHorizontalOffset(inactiveShadowHOffset->value()); 0213 m_inactiveShadows.setVerticalOffset(inactiveShadowVOffset->value()); 0214 m_inactiveShadows.setColorType((ShadowConfig::ColorType)inactiveShadowColorType->currentIndex()); 0215 m_inactiveShadows.setShadowType(inactiveUsesActiveGradients->isChecked() 0216 ? ShadowConfig::SH_ACTIVE 0217 : ShadowConfig::SH_INACTIVE); 0218 if(ShadowConfig::CT_CUSTOM==inactiveShadowColorType->currentIndex()) 0219 m_inactiveShadows.setColor(inactiveShadowColor->color()); 0220 } 0221 else 0222 { 0223 m_activeShadows.defaults(); 0224 m_inactiveShadows.defaults(); 0225 } 0226 m_activeShadows.save(cfg); 0227 m_inactiveShadows.save(cfg); 0228 config.setOpacity(activeOpacity->value(), true); 0229 config.setOpacity(inactiveOpacity->value(), false); 0230 config.setOpaqueBorder(opaqueBorder->isChecked()); 0231 config.save(cfg, c ? KWIN_GROUP : nullptr); 0232 cfg->sync(); 0233 if(!c) 0234 delete cfg; 0235 } 0236 0237 void KWinConfig::defaults() 0238 { 0239 if (!m_ok) 0240 return; 0241 0242 setWidgets(KWin::QtCurveConfig()); 0243 m_activeShadows.defaults(); 0244 m_inactiveShadows.defaults(); 0245 setShadows(); 0246 } 0247 0248 void KWinConfig::outerBorderChanged() 0249 { 0250 if(KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex()) 0251 innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_NONE); 0252 if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex()) 0253 useShadows->setChecked(true); 0254 setWidgetStates(); 0255 emit changed(); 0256 } 0257 0258 void KWinConfig::innerBorderChanged() 0259 { 0260 if(KWin::QtCurveConfig::SHADE_NONE!=innerBorder->currentIndex() && 0261 KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex()) 0262 outerBorder->setCurrentIndex(innerBorder->currentIndex()); 0263 if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex()) 0264 useShadows->setChecked(true); 0265 emit changed(); 0266 } 0267 0268 void KWinConfig::shadowsChanged() 0269 { 0270 if(!useShadows->isChecked()) 0271 { 0272 if(KWin::QtCurveConfig::SHADE_SHADOW==outerBorder->currentIndex()) 0273 outerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_DARK); 0274 if(KWin::QtCurveConfig::SHADE_SHADOW==innerBorder->currentIndex()) 0275 innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_DARK); 0276 } 0277 emit changed(); 0278 } 0279 0280 void KWinConfig::activeShadowColorTypeChanged() 0281 { 0282 activeShadowColor->setEnabled(ShadowConfig::CT_CUSTOM==activeShadowColorType->currentIndex()); 0283 if(m_activeShadows.colorType()!=activeShadowColorType->currentIndex()) 0284 emit changed(); 0285 } 0286 0287 void KWinConfig::inactiveShadowColorTypeChanged() 0288 { 0289 inactiveShadowColor->setEnabled(ShadowConfig::CT_CUSTOM==inactiveShadowColorType->currentIndex()); 0290 if(m_inactiveShadows.colorType()!=inactiveShadowColorType->currentIndex()) 0291 emit changed(); 0292 } 0293 0294 void KWinConfig::sizeChanged() 0295 { 0296 setWidgetStates(); 0297 emit changed(); 0298 } 0299 0300 void KWinConfig::setWidgets(const KWin::QtCurveConfig &cfg) 0301 { 0302 borderSize->setCurrentIndex(cfg.borderSize()); 0303 roundBottom->setChecked(cfg.roundBottom()); 0304 outerBorder->setCurrentIndex(cfg.outerBorder()); 0305 innerBorder->setCurrentIndex(cfg.innerBorder()); 0306 borderlessMax->setChecked(cfg.borderlessMax()); 0307 titleBarPad->setValue(cfg.titleBarPad()); 0308 edgePad->setValue(cfg.edgePad()); 0309 useShadows->setChecked(cfg.customShadows()); 0310 activeOpacity->setValue(cfg.opacity(true)); 0311 inactiveOpacity->setValue(cfg.opacity(false)); 0312 opaqueBorder->setChecked(cfg.opaqueBorder()); 0313 setWidgetStates(); 0314 } 0315 0316 void KWinConfig::setWidgetStates() 0317 { 0318 if(KWin::QtCurveConfig::BORDER_NONE==borderSize->currentIndex()) 0319 { 0320 roundBottom->setEnabled(false); 0321 roundBottom->setChecked(false); 0322 } 0323 else 0324 roundBottom->setEnabled(true); 0325 0326 if(KWin::QtCurveConfig::SHADE_NONE==outerBorder->currentIndex() || 0327 borderSize->currentIndex()<KWin::QtCurveConfig::BORDER_TINY) 0328 { 0329 innerBorder->setEnabled(false); 0330 innerBorder->setCurrentIndex(KWin::QtCurveConfig::SHADE_NONE); 0331 } 0332 else 0333 innerBorder->setEnabled(true); 0334 } 0335 0336 void KWinConfig::setNote(const QString &txt) 0337 { 0338 noteLabel->setText(txt); 0339 } 0340 0341 void KWinConfig::setShadows() 0342 { 0343 activeShadowSize->setValue(m_activeShadows.shadowSize()); 0344 activeShadowHOffset->setValue(m_activeShadows.horizontalOffset()); 0345 activeShadowVOffset->setValue(m_activeShadows.verticalOffset()); 0346 activeShadowColor->setColor(m_activeShadows.color()); 0347 activeShadowColorType->setCurrentIndex(m_activeShadows.colorType()); 0348 inactiveShadowSize->setValue(m_inactiveShadows.shadowSize()); 0349 inactiveShadowHOffset->setValue(m_inactiveShadows.horizontalOffset()); 0350 inactiveShadowVOffset->setValue(m_inactiveShadows.verticalOffset()); 0351 inactiveShadowColor->setColor(m_inactiveShadows.color()); 0352 inactiveShadowColorType->setCurrentIndex(m_inactiveShadows.colorType()); 0353 inactiveUsesActiveGradients->setChecked(ShadowConfig::SH_ACTIVE==m_inactiveShadows.shadowType()); 0354 } 0355 0356 } 0357 0358 extern "C" Q_DECL_EXPORT QObject* 0359 allocate_config(KConfig *config, QWidget *parent) 0360 { 0361 return new QtCurve::KWinConfig(config, parent); 0362 } 0363 0364 #include "qtcurvekwinconfig.moc"