1 /*
2 Copyright 2010-2012 Sergey Levin
3 
4 
5 This file is part of crosti.
6 
7 Crosti is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Crosti is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with crosti.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #include "theme.h"
23 #include "info.h"
24 
25 #include <QFile>
26 #include <QTextStream>
27 #include <QTextCodec>
28 #include <QSettings>
29 #include <QApplication>
30 
31 
Theme()32 Theme::Theme():
33   _name(),
34   _btnStyle(),
35   _groupboxStyle(),
36   _lineeditStyle(),
37   _progressbarStyle(),
38   _menuStyle(),
39   _spinboxStyle(),
40   _widgetStyle()
41 {
42   QSettings rsettings(QApplication::organizationName(),QApplication::applicationName());
43   load(rsettings.value("theme").value<QString>());
44 }
45 
load(const QString & name)46 void Theme::load(const QString &name){
47  if(name!="")_name=name;
48  _btnStyle=loadStyle("btn.qss");
49  _lineeditStyle=loadStyle("lineedit.qss");
50  _progressbarStyle=loadStyle("progressbar.qss");
51  _menuStyle=loadStyle("menu.qss");
52  _spinboxStyle=loadStyle("spinbox.qss");
53  _groupboxStyle=loadStyle("groupbox.qss");
54  _widgetStyle=loadStyle("widget.qss");
55 }
56 
57 
loadStyle(const QString & name)58 QString Theme::loadStyle(const QString &name){
59  QString result="";
60  if(_name!=""){
61    QString path=Info::dataPath()+"/system/theme/"+_name+"/"+name;
62    QFile file(path);
63    if(file.open(QIODevice::ReadOnly|QIODevice::Text)){
64      QTextStream in(&file);
65      QTextCodec *codec=QTextCodec::codecForName("UTF8");
66      in.setCodec(codec);
67      result=in.readAll();
68      file.close();
69    }
70  }
71  return result;
72 }
73 
74 
75