source: smplayer/vendor/current/src/images.cpp@ 177

Last change on this file since 177 was 175, checked in by Silvan Scherrer, 10 years ago

smplayer: update vendor to version 16.4

File size: 4.3 KB
RevLine 
[90]1/* smplayer, GUI front-end for mplayer.
[175]2 Copyright (C) 2006-2016 Ricardo Villalba <[email protected]>
[90]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
[168]19#include "images.h"
20#include <QFile>
21#include <QDebug>
[90]22
[168]23#ifdef USE_RESOURCES
24#include <QResource>
25#endif
26
27#ifdef SMCODE
[90]28#include "global.h"
29#include "preferences.h"
30#include "paths.h"
[168]31using namespace Global;
32#endif
[90]33
[168]34QString Images::current_theme;
35QString Images::themes_path;
[90]36
[168]37#ifdef USE_RESOURCES
38QString Images::last_resource_loaded;
[175]39bool Images::has_rcc = false;
[90]40
[168]41QString Images::resourceFilename() {
42 QString filename = QString::null;
[90]43
[168]44 if ((!themes_path.isEmpty()) && (!current_theme.isEmpty())) {
45 filename = themes_path +"/"+ current_theme +"/"+ current_theme +".rcc";
[90]46 }
47
[168]48 qDebug() << "Images::resourceFilename:" << filename;
[90]49
50 return filename;
51}
[168]52#endif
[90]53
[168]54void Images::setTheme(const QString & name) {
55 current_theme = name;
[90]56
[168]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
[90]65
[168]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;
[90]71 }
72
[168]73 QString rs_file = resourceFilename();
[175]74 if ((!rs_file.isEmpty()) && (QFile::exists(rs_file))) {
[168]75 qDebug() << "Images::setTheme: loading" << rs_file;
76 QResource::registerResource(rs_file);
77 last_resource_loaded = rs_file;
[175]78 has_rcc = true;
79 } else {
80 has_rcc = false;
[90]81 }
[175]82 qDebug() << "Images::setTheme: has_rcc:" << has_rcc;
[168]83#endif
84}
[90]85
[168]86void Images::setThemesPath(const QString & folder) {
87 themes_path = folder;
88 qDebug() << "Images::setThemesPath:" << themes_path;
[90]89}
90
[168]91QString Images::file(const QString & name) {
92#ifdef SMCODE
93 if (current_theme != pref->iconset) {
94 setTheme(pref->iconset);
95 }
96#endif
[90]97
[175]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
[90]109 }
110
[175]111 bool has_extension = name.contains(".");
112 if (!has_extension) icon_name += ".png";
113
[168]114 //qDebug() << "Images::file:" << icon_name;
[175]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;
[168]121 return icon_name;
[90]122}
123
124
[168]125QPixmap Images::icon(QString name, int size) {
126 QString icon_name = file(name);
127 QPixmap p(icon_name);
[90]128
[168]129 if (!p.isNull()) {
130 if (size != -1) {
131 p = resize(&p, size);
[90]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
[168]146QPixmap Images::flippedIcon(QString name, int size) {
147 QPixmap p = icon(name, size);
[90]148 p = flip(&p);
149 return p;
150}
[137]151
[168]152#ifdef SMCODE
[137]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}
[168]177#endif
Note: See TracBrowser for help on using the repository browser.