|
| 1 | +/* Copyright 2007-2015 QReal Research Group |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. */ |
| 14 | + |
| 15 | +#include "styles.h" |
| 16 | + |
| 17 | +#include <QApplication> |
| 18 | +#include <QSettings> |
| 19 | +#include <QPalette> |
| 20 | +#include <QColor> |
| 21 | + |
| 22 | +using namespace qReal; |
| 23 | + |
| 24 | +QPalette Styles::loadPalette(QString pathToPalette) const { |
| 25 | + QSettings settings(pathToPalette, QSettings::IniFormat); |
| 26 | + QPalette palette; |
| 27 | + |
| 28 | + const QMap<QString, QPalette::ColorRole> colorRoles = { |
| 29 | + {"Window", QPalette::Window}, |
| 30 | + {"WindowText", QPalette::WindowText}, |
| 31 | + {"Base", QPalette::Base}, |
| 32 | + {"AlternateBase", QPalette::AlternateBase}, |
| 33 | + {"ToolTipBase", QPalette::ToolTipBase}, |
| 34 | + {"ToolTipText", QPalette::ToolTipText}, |
| 35 | + {"Text", QPalette::Text}, |
| 36 | + {"Dark", QPalette::Dark}, |
| 37 | + {"Shadow", QPalette::Shadow}, |
| 38 | + {"Button", QPalette::Button}, |
| 39 | + {"ButtonText", QPalette::ButtonText}, |
| 40 | + {"BrightText", QPalette::BrightText}, |
| 41 | + {"Link", QPalette::Link}, |
| 42 | + {"Highlight", QPalette::Highlight}, |
| 43 | + {"HighlightedText", QPalette::HighlightedText} |
| 44 | + }; |
| 45 | + |
| 46 | + for (const auto &group : {"PaletteActive", "PaletteDisabled"}) { |
| 47 | + QPalette::ColorGroup colorGroup = (QString(group) == "PaletteDisabled") ? QPalette::Disabled : QPalette::Active; |
| 48 | + |
| 49 | + for (auto it = colorRoles.begin(); it != colorRoles.end(); ++it) { |
| 50 | + QStringList rgb = settings.value(QString(group) + "/" + it.key()).toStringList(); |
| 51 | + if (!rgb.isEmpty()) { |
| 52 | + QColor color(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()); |
| 53 | + palette.setColor(colorGroup, it.value(), color); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return palette; |
| 59 | +} |
0 commit comments