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

Last change on this file since 170 was 170, checked in by Silvan Scherrer, 11 years ago

SMPlayer: updated trunk to 14.9.0

  • Property svn:eol-style set to LF
File size: 3.8 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 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;
39
40QString Images::resourceFilename() {
41 QString filename = QString::null;
42
43 if ((!themes_path.isEmpty()) && (!current_theme.isEmpty())) {
44 filename = themes_path +"/"+ current_theme +"/"+ current_theme +".rcc";
45 }
46
47 qDebug() << "Images::resourceFilename:" << filename;
48
49 return filename;
50}
51#endif
52
53void Images::setTheme(const QString & name) {
54 current_theme = name;
55
56#ifdef SMCODE
57 QString dir = Paths::configPath() + "/themes/" + name;
58 if (QFile::exists(dir)) {
59 setThemesPath(Paths::configPath() + "/themes/");
60 } else {
61 setThemesPath(Paths::themesPath());
62 }
63#endif
64
65#ifdef USE_RESOURCES
66 if (!last_resource_loaded.isEmpty()) {
67 qDebug() << "Images::setTheme: unloading" << last_resource_loaded;
68 QResource::unregisterResource(last_resource_loaded);
69 last_resource_loaded = QString::null;
70 }
71
72 QString rs_file = resourceFilename();
73 if (QFile::exists(rs_file)) {
74 qDebug() << "Images::setTheme: loading" << rs_file;
75 QResource::registerResource(rs_file);
76 last_resource_loaded = rs_file;
77 }
78#endif
79}
80
81void Images::setThemesPath(const QString & folder) {
82 themes_path = folder;
83 qDebug() << "Images::setThemesPath:" << themes_path;
84}
85
86QString Images::file(const QString & name) {
87#ifdef SMCODE
88 if (current_theme != pref->iconset) {
89 setTheme(pref->iconset);
90 }
91#endif
92
93#ifdef USE_RESOURCES
94 QString icon_name = ":/" + current_theme + "/"+ name + ".png";
95#else
96 QString icon_name = themes_path +"/"+ current_theme + "/"+ name + ".png";
97#endif
98 if (!QFile::exists(icon_name)) {
99 icon_name = ":/icons-png/" + name + ".png";
100 }
101
102 //qDebug() << "Images::file:" << icon_name;
103 return icon_name;
104}
105
106
107QPixmap Images::icon(QString name, int size) {
108 QString icon_name = file(name);
109 QPixmap p(icon_name);
110
111 if (!p.isNull()) {
112 if (size != -1) {
113 p = resize(&p, size);
114 }
115 }
116
117 return p;
118}
119
120QPixmap Images::resize(QPixmap *p, int size) {
121 return QPixmap::fromImage( (*p).toImage().scaled(size,size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation) );
122}
123
124QPixmap Images::flip(QPixmap *p) {
125 return QPixmap::fromImage( (*p).toImage().mirrored(true, false) );
126}
127
128QPixmap Images::flippedIcon(QString name, int size) {
129 QPixmap p = icon(name, size);
130 p = flip(&p);
131 return p;
132}
133
134#ifdef SMCODE
135QString Images::styleSheet(){
136 QString filename;
137 filename = themesDirectory() + "/main.css";
138 QFile file(filename);
139 if (file.exists()) {
140 file.open(QFile::ReadOnly | QFile::Text);
141 QString css = QString::fromUtf8(file.readAll().constData());
142 return css;
143 }
144 else
145 return "";
146}
147
148QString Images::themesDirectory(){
149 QString skin = pref->iconset;
150 QString dirname;
151 if (!skin.isEmpty()) {
152 dirname = Paths::configPath() + "/themes/" + skin;
153 if (!QFile::exists(dirname)) {
154 dirname = Paths::themesPath() + "/" + skin ;
155 }
156 }
157 return dirname;
158}
159#endif
Note: See TracBrowser for help on using the repository browser.