source: smplayer/trunk/src/images.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

  • Property svn:eol-style set to LF
File size: 4.3 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "images.h"
20#include <QFile>
21#include <QDebug>
22
23#ifdef USE_RESOURCES
24#include <QResource>
25#endif
26
27#ifdef SMCODE
28#include "global.h"
29#include "preferences.h"
30#include "paths.h"
31using namespace Global;
32#endif
33
34QString Images::current_theme;
35QString Images::themes_path;
36
37#ifdef USE_RESOURCES
38QString Images::last_resource_loaded;
39bool Images::has_rcc = false;
40
41QString Images::resourceFilename() {
42 QString filename = QString::null;
43
44 if ((!themes_path.isEmpty()) && (!current_theme.isEmpty())) {
45 filename = themes_path +"/"+ current_theme +"/"+ current_theme +".rcc";
46 }
47
48 qDebug() << "Images::resourceFilename:" << filename;
49
50 return filename;
51}
52#endif
53
54void Images::setTheme(const QString & name) {
55 current_theme = name;
56
57#ifdef SMCODE
58 QString dir = Paths::configPath() + "/themes/" + name;
59 if (QFile::exists(dir)) {
60 setThemesPath(Paths::configPath() + "/themes/");
61 } else {
62 setThemesPath(Paths::themesPath());
63 }
64#endif
65
66#ifdef USE_RESOURCES
67 if (!last_resource_loaded.isEmpty()) {
68 qDebug() << "Images::setTheme: unloading" << last_resource_loaded;
69 QResource::unregisterResource(last_resource_loaded);
70 last_resource_loaded = QString::null;
71 }
72
73 QString rs_file = resourceFilename();
74 if ((!rs_file.isEmpty()) && (QFile::exists(rs_file))) {
75 qDebug() << "Images::setTheme: loading" << rs_file;
76 QResource::registerResource(rs_file);
77 last_resource_loaded = rs_file;
78 has_rcc = true;
79 } else {
80 has_rcc = false;
81 }
82 qDebug() << "Images::setTheme: has_rcc:" << has_rcc;
83#endif
84}
85
86void Images::setThemesPath(const QString & folder) {
87 themes_path = folder;
88 qDebug() << "Images::setThemesPath:" << themes_path;
89}
90
91QString Images::file(const QString & name) {
92#ifdef SMCODE
93 if (current_theme != pref->iconset) {
94 setTheme(pref->iconset);
95 }
96#endif
97
98 QString icon_name;
99 if (!current_theme.isEmpty()) {
100 #ifdef USE_RESOURCES
101 if (has_rcc) {
102 icon_name = ":/" + current_theme + "/"+ name;
103 } else {
104 icon_name = themes_path +"/"+ current_theme + "/"+ name;
105 }
106 #else
107 icon_name = themes_path +"/"+ current_theme + "/"+ name;
108 #endif
109 }
110
111 bool has_extension = name.contains(".");
112 if (!has_extension) icon_name += ".png";
113
114 //qDebug() << "Images::file:" << icon_name;
115 if ((icon_name.isEmpty()) || (!QFile::exists(icon_name))) {
116 icon_name = ":/default-theme/" + name;
117 if (!has_extension) icon_name += ".png";
118 }
119
120 //qDebug() << "Images::file:" << icon_name;
121 return icon_name;
122}
123
124
125QPixmap Images::icon(QString name, int size) {
126 QString icon_name = file(name);
127 QPixmap p(icon_name);
128
129 if (!p.isNull()) {
130 if (size != -1) {
131 p = resize(&p, size);
132 }
133 }
134
135 return p;
136}
137
138QPixmap Images::resize(QPixmap *p, int size) {
139 return QPixmap::fromImage( (*p).toImage().scaled(size,size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation) );
140}
141
142QPixmap Images::flip(QPixmap *p) {
143 return QPixmap::fromImage( (*p).toImage().mirrored(true, false) );
144}
145
146QPixmap Images::flippedIcon(QString name, int size) {
147 QPixmap p = icon(name, size);
148 p = flip(&p);
149 return p;
150}
151
152#ifdef SMCODE
153QString Images::styleSheet(){
154 QString filename;
155 filename = themesDirectory() + "/main.css";
156 QFile file(filename);
157 if (file.exists()) {
158 file.open(QFile::ReadOnly | QFile::Text);
159 QString css = QString::fromUtf8(file.readAll().constData());
160 return css;
161 }
162 else
163 return "";
164}
165
166QString Images::themesDirectory(){
167 QString skin = pref->iconset;
168 QString dirname;
169 if (!skin.isEmpty()) {
170 dirname = Paths::configPath() + "/themes/" + skin;
171 if (!QFile::exists(dirname)) {
172 dirname = Paths::themesPath() + "/" + skin ;
173 }
174 }
175 return dirname;
176}
177#endif
Note: See TracBrowser for help on using the repository browser.