File indexing completed on 2024-05-05 17:55:01
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 <kdeversion.h> 0024 0025 #include <KColorScheme> 0026 #include <KGlobalSettings> 0027 #include <KConfig> 0028 #include <KConfigGroup> 0029 #include <QApplication> 0030 #include "qtcurveshadowconfiguration.h" 0031 0032 namespace QtCurve { 0033 namespace KWin { 0034 0035 ShadowConfig::ShadowConfig(QPalette::ColorGroup colorGroup) 0036 : m_colorGroup(colorGroup) 0037 { 0038 defaults(); 0039 } 0040 0041 void ShadowConfig::defaults() 0042 { 0043 m_hOffset = 0; 0044 m_vOffset = 5; 0045 if(QPalette::Active==m_colorGroup) 0046 { 0047 m_size = 35; 0048 setColorType(CT_FOCUS); 0049 m_shadowType = SH_ACTIVE; 0050 } 0051 else 0052 { 0053 m_size = 30; 0054 setColorType(CT_GRAY); 0055 m_shadowType = SH_INACTIVE; 0056 } 0057 } 0058 0059 void ShadowConfig::setColorType(ColorType ct) 0060 { 0061 m_colorType = ct; 0062 switch (m_colorType) { 0063 default: 0064 case CT_FOCUS: 0065 m_color = KColorScheme(m_colorGroup) 0066 .decoration(KColorScheme::FocusColor).color(); 0067 break; 0068 case CT_HOVER: 0069 m_color = KColorScheme(m_colorGroup) 0070 .decoration(KColorScheme::HoverColor).color(); 0071 break; 0072 case CT_SELECTION: 0073 m_color = QApplication::palette().color(m_colorGroup, 0074 QPalette::Highlight); 0075 break; 0076 case CT_TITLEBAR: 0077 m_color = (m_colorGroup == QPalette::Active ? 0078 KGlobalSettings::activeTitleColor() : 0079 KGlobalSettings::inactiveTitleColor()); 0080 break; 0081 case CT_GRAY: 0082 m_color = QColor("#393835"); 0083 break; 0084 case CT_CUSTOM: 0085 break; 0086 } 0087 } 0088 0089 #define CFG_GROUP (QPalette::Active==m_colorGroup ? "ActiveShadows" : "InactiveShadows") 0090 0091 #define READ_ENTRY(name, field) do { \ 0092 field = group.readEntry(name, def.field); \ 0093 } while (0) 0094 0095 void ShadowConfig::load(KConfig *cfg) 0096 { 0097 KConfigGroup group(cfg, CFG_GROUP); 0098 ShadowConfig def(m_colorGroup); 0099 0100 READ_ENTRY("Size", m_size); 0101 READ_ENTRY("HOffset", m_hOffset); 0102 READ_ENTRY("VOffset", m_vOffset); 0103 READ_ENTRY("ColorType", m_colorType); 0104 READ_ENTRY("ShadowType", m_shadowType); 0105 0106 if(CT_CUSTOM==m_colorType) 0107 READ_ENTRY("Color", m_color); 0108 if(m_size<MIN_SIZE || m_size>MAX_SIZE) 0109 m_size=def.shadowSize(); 0110 if(m_hOffset<MIN_OFFSET || m_hOffset>MAX_OFFSET) 0111 m_hOffset=def.horizontalOffset(); 0112 if(m_vOffset<MIN_OFFSET || m_vOffset>MAX_OFFSET) 0113 m_vOffset=def.verticalOffset(); 0114 setColorType((ColorType)m_colorType); 0115 } 0116 0117 #define WRITE_ENTRY(name, field) do { \ 0118 if (def.field == field) { \ 0119 group.deleteEntry(name); \ 0120 } else { \ 0121 group.writeEntry(name, field); \ 0122 } \ 0123 } while (0) 0124 0125 void ShadowConfig::save(KConfig *cfg) 0126 { 0127 KConfigGroup group(cfg, CFG_GROUP); 0128 ShadowConfig def(m_colorGroup); 0129 0130 WRITE_ENTRY("Size", m_size); 0131 WRITE_ENTRY("HOffset", m_hOffset); 0132 WRITE_ENTRY("VOffset", m_vOffset); 0133 WRITE_ENTRY("ColorType", m_colorType); 0134 WRITE_ENTRY("ShadowType", m_shadowType); 0135 0136 if (m_colorType != CT_CUSTOM) { 0137 group.deleteEntry("Color"); 0138 } else { 0139 WRITE_ENTRY("Color", m_color); 0140 } 0141 } 0142 0143 } 0144 }