1 /* This file is part of Clementine. 2 Copyright 2010, David Sansome <davidsansome@gmail.com> 3 Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com> 4 5 Clementine is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 Clementine is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef CORE_STYLESHEETLOADER_H_ 20 #define CORE_STYLESHEETLOADER_H_ 21 22 #include <QString> 23 #include <QPalette> 24 #include <QWidget> 25 #include <QMap> 26 27 class StyleSheetLoader : public QObject { 28 public: 29 explicit StyleSheetLoader(QObject* parent = nullptr); 30 31 // Sets the given stylesheet on the given widget. 32 // If the stylesheet contains strings like %palette-[role], these get replaced 33 // with actual palette colours. 34 // The stylesheet is reloaded when the widget's palette changes. 35 void SetStyleSheet(QWidget* widget, const QString& filename); 36 37 protected: 38 bool eventFilter(QObject* obj, QEvent* event); 39 40 private: 41 void UpdateStyleSheet(QWidget* widget); 42 void ReplaceColor(QString* css, const QString& name, const QPalette& palette, 43 QPalette::ColorRole role) const; 44 45 private: 46 QMap<QWidget*, QString> filenames_; 47 }; 48 49 #endif // CORE_STYLESHEETLOADER_H_ 50