source: smplayer/trunk/src/images.cpp

Last change on this file was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

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