File indexing completed on 2024-05-12 17:08:27
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "coloreditor.h" 0008 0009 #include <QDebug> 0010 #include <QStandardPaths> 0011 0012 #include <KConfig> 0013 #include <KConfigGroup> 0014 0015 ColorEditor::ColorEditor(QObject *parent) 0016 : QObject(parent) 0017 { 0018 } 0019 0020 ColorEditor::~ColorEditor() 0021 { 0022 } 0023 0024 void ColorEditor::load() 0025 { 0026 const QString colorsFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/plasma/desktoptheme/" + m_theme + "/colors"; 0027 0028 KConfig c(colorsFile); 0029 0030 KConfigGroup cg(&c, "Colors:Window"); 0031 0032 m_textColor = cg.readEntry("ForegroundNormal", QColor()); 0033 m_highlightColor = cg.readEntry("DecorationHover", QColor()); 0034 m_backgroundColor = cg.readEntry("BackgroundNormal", QColor()); 0035 m_linkColor = cg.readEntry("ForegroundLink", QColor()); 0036 m_visitedLinkColor = cg.readEntry("ForegroundVisited", QColor()); 0037 0038 cg = KConfigGroup(&c, "Colors:Button"); 0039 m_buttonTextColor = cg.readEntry("ForegroundNormal", QColor()); 0040 m_buttonBackgroundColor = cg.readEntry("BackgroundNormal", QColor()); 0041 m_buttonHoverColor = cg.readEntry("DecorationHover", QColor()); 0042 m_buttonFocusColor = cg.readEntry("DecorationFocus", QColor()); 0043 0044 cg = KConfigGroup(&c, "Colors:View"); 0045 m_viewTextColor = cg.readEntry("ForegroundNormal", QColor()); 0046 m_viewBackgroundColor = cg.readEntry("BackgroundNormal", QColor()); 0047 m_viewHoverColor = cg.readEntry("DecorationHover", QColor()); 0048 m_viewFocusColor = cg.readEntry("DecorationFocus", QColor()); 0049 0050 cg = KConfigGroup(&c, "Colors:Complementary"); 0051 m_complementaryTextColor = cg.readEntry("ForegroundNormal", QColor()); 0052 m_complementaryBackgroundColor = cg.readEntry("BackgroundNormal", QColor()); 0053 m_complementaryHoverColor = cg.readEntry("DecorationHover", QColor()); 0054 m_complementaryFocusColor = cg.readEntry("DecorationFocus", QColor()); 0055 0056 emit colorsChanged(); 0057 } 0058 0059 void ColorEditor::save() 0060 { 0061 const QString colorsFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/plasma/desktoptheme/" + m_theme + "/colors"; 0062 0063 KConfig c(colorsFile); 0064 0065 KConfigGroup cg(&c, "Colors:Window"); 0066 0067 cg.writeEntry("ForegroundNormal", m_textColor); 0068 cg.writeEntry("DecorationHover", m_highlightColor); 0069 cg.writeEntry("BackgroundNormal", m_backgroundColor); 0070 cg.writeEntry("ForegroundLink", m_linkColor); 0071 cg.writeEntry("ForegroundVisited", m_visitedLinkColor); 0072 cg.sync(); 0073 0074 cg = KConfigGroup(&c, "Colors:Button"); 0075 cg.writeEntry("ForegroundNormal", m_buttonTextColor); 0076 cg.writeEntry("BackgroundNormal", m_buttonBackgroundColor); 0077 cg.writeEntry("DecorationHover", m_buttonHoverColor); 0078 cg.writeEntry("DecorationFocus", m_buttonFocusColor); 0079 cg.sync(); 0080 0081 cg = KConfigGroup(&c, "Colors:View"); 0082 cg.writeEntry("ForegroundNormal", m_viewTextColor); 0083 cg.writeEntry("BackgroundNormal", m_viewBackgroundColor); 0084 cg.writeEntry("DecorationHover", m_viewHoverColor); 0085 cg.writeEntry("DecorationFocus", m_viewFocusColor); 0086 cg.sync(); 0087 0088 cg = KConfigGroup(&c, "Colors:Complementary"); 0089 cg.writeEntry("ForegroundNormal", m_complementaryTextColor); 0090 cg.writeEntry("BackgroundNormal", m_complementaryBackgroundColor); 0091 cg.writeEntry("DecorationHover", m_complementaryHoverColor); 0092 cg.writeEntry("DecorationFocus", m_complementaryFocusColor); 0093 cg.sync(); 0094 } 0095 0096 QString ColorEditor::theme() const 0097 { 0098 return m_theme; 0099 } 0100 0101 void ColorEditor::setTheme(const QString &theme) 0102 { 0103 if (theme == m_theme) { 0104 return; 0105 } 0106 0107 m_theme = theme; 0108 emit themeChanged(); 0109 load(); 0110 } 0111 0112 QColor ColorEditor::textColor() const 0113 { 0114 return m_textColor; 0115 } 0116 0117 void ColorEditor::setTextColor(const QColor &color) 0118 { 0119 if (color == m_textColor) { 0120 return; 0121 } 0122 0123 m_textColor = color; 0124 emit colorsChanged(); 0125 } 0126 0127 QColor ColorEditor::highlightColor() const 0128 { 0129 return m_highlightColor; 0130 } 0131 0132 void ColorEditor::setHighlightColor(const QColor &color) 0133 { 0134 if (color == m_highlightColor) { 0135 return; 0136 } 0137 0138 m_highlightColor = color; 0139 emit colorsChanged(); 0140 } 0141 0142 QColor ColorEditor::backgroundColor() const 0143 { 0144 return m_backgroundColor; 0145 } 0146 0147 void ColorEditor::setBackgroundColor(const QColor &color) 0148 { 0149 if (color == m_backgroundColor) { 0150 return; 0151 } 0152 0153 m_backgroundColor = color; 0154 emit colorsChanged(); 0155 } 0156 0157 QColor ColorEditor::buttonTextColor() const 0158 { 0159 return m_buttonTextColor; 0160 } 0161 0162 void ColorEditor::setButtonTextColor(const QColor &color) 0163 { 0164 if (color == m_buttonTextColor) { 0165 return; 0166 } 0167 0168 m_buttonTextColor = color; 0169 emit colorsChanged(); 0170 } 0171 0172 QColor ColorEditor::buttonBackgroundColor() const 0173 { 0174 return m_buttonBackgroundColor; 0175 } 0176 0177 void ColorEditor::setButtonBackgroundColor(const QColor &color) 0178 { 0179 if (color == m_buttonBackgroundColor) { 0180 return; 0181 } 0182 0183 m_buttonBackgroundColor = color; 0184 emit colorsChanged(); 0185 } 0186 0187 QColor ColorEditor::linkColor() const 0188 { 0189 return m_linkColor; 0190 } 0191 0192 void ColorEditor::setLinkColor(const QColor &color) 0193 { 0194 if (color == m_linkColor) { 0195 return; 0196 } 0197 0198 m_linkColor = color; 0199 emit colorsChanged(); 0200 } 0201 0202 QColor ColorEditor::visitedLinkColor() const 0203 { 0204 return m_visitedLinkColor; 0205 } 0206 0207 void ColorEditor::setVisitedLinkColor(const QColor &color) 0208 { 0209 if (color == m_visitedLinkColor) { 0210 return; 0211 } 0212 0213 m_visitedLinkColor = color; 0214 emit colorsChanged(); 0215 } 0216 0217 QColor ColorEditor::buttonHoverColor() const 0218 { 0219 return m_buttonHoverColor; 0220 } 0221 0222 void ColorEditor::setButtonHoverColor(const QColor &color) 0223 { 0224 if (color == m_buttonHoverColor) { 0225 return; 0226 } 0227 0228 m_buttonHoverColor = color; 0229 emit colorsChanged(); 0230 } 0231 0232 QColor ColorEditor::buttonFocusColor() const 0233 { 0234 return m_buttonFocusColor; 0235 } 0236 0237 void ColorEditor::setButtonFocusColor(const QColor &color) 0238 { 0239 if (color == m_buttonFocusColor) { 0240 return; 0241 } 0242 0243 m_buttonFocusColor = color; 0244 emit colorsChanged(); 0245 } 0246 0247 QColor ColorEditor::viewTextColor() const 0248 { 0249 return m_viewTextColor; 0250 } 0251 0252 void ColorEditor::setViewTextColor(const QColor &color) 0253 { 0254 if (color == m_viewTextColor) { 0255 return; 0256 } 0257 0258 m_viewTextColor = color; 0259 emit colorsChanged(); 0260 } 0261 0262 QColor ColorEditor::viewBackgroundColor() const 0263 { 0264 return m_viewBackgroundColor; 0265 } 0266 0267 void ColorEditor::setViewBackgroundColor(const QColor &color) 0268 { 0269 if (color == m_viewBackgroundColor) { 0270 return; 0271 } 0272 0273 m_viewBackgroundColor = color; 0274 emit colorsChanged(); 0275 } 0276 0277 QColor ColorEditor::viewHoverColor() const 0278 { 0279 return m_viewHoverColor; 0280 } 0281 0282 void ColorEditor::setViewHoverColor(const QColor &color) 0283 { 0284 if (color == m_viewHoverColor) { 0285 return; 0286 } 0287 0288 m_viewHoverColor = color; 0289 emit colorsChanged(); 0290 } 0291 0292 QColor ColorEditor::viewFocusColor() const 0293 { 0294 return m_viewFocusColor; 0295 } 0296 0297 void ColorEditor::setViewFocusColor(const QColor &color) 0298 { 0299 if (color == m_viewFocusColor) { 0300 return; 0301 } 0302 0303 m_viewFocusColor = color; 0304 emit colorsChanged(); 0305 } 0306 0307 QColor ColorEditor::complementaryTextColor() const 0308 { 0309 return m_complementaryTextColor; 0310 } 0311 0312 void ColorEditor::setComplementaryTextColor(const QColor &color) 0313 { 0314 if (color == m_complementaryTextColor) { 0315 return; 0316 } 0317 0318 m_complementaryTextColor = color; 0319 emit colorsChanged(); 0320 } 0321 0322 QColor ColorEditor::complementaryBackgroundColor() const 0323 { 0324 return m_complementaryBackgroundColor; 0325 } 0326 0327 void ColorEditor::setComplementaryBackgroundColor(const QColor &color) 0328 { 0329 if (color == m_complementaryBackgroundColor) { 0330 return; 0331 } 0332 0333 m_complementaryBackgroundColor = color; 0334 emit colorsChanged(); 0335 } 0336 0337 QColor ColorEditor::complementaryHoverColor() const 0338 { 0339 return m_complementaryHoverColor; 0340 } 0341 0342 void ColorEditor::setComplementaryHoverColor(const QColor &color) 0343 { 0344 if (color == m_complementaryHoverColor) { 0345 return; 0346 } 0347 0348 m_complementaryHoverColor = color; 0349 emit colorsChanged(); 0350 } 0351 0352 QColor ColorEditor::complementaryFocusColor() const 0353 { 0354 return m_complementaryFocusColor; 0355 } 0356 0357 void ColorEditor::setComplementaryFocusColor(const QColor &color) 0358 { 0359 if (color == m_complementaryHoverColor) { 0360 return; 0361 } 0362 0363 m_complementaryFocusColor = color; 0364 emit colorsChanged(); 0365 } 0366 0367 #include "moc_coloreditor.cpp"