[168] | 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 | #define COMPAT_WITH_OLD_ICONS 1
|
---|
| 20 |
|
---|
| 21 | #include "images.h"
|
---|
| 22 | #include "global.h"
|
---|
| 23 | #include "preferences.h"
|
---|
| 24 | #include "paths.h"
|
---|
| 25 |
|
---|
| 26 | #include <QFile>
|
---|
| 27 |
|
---|
| 28 | using namespace Global;
|
---|
| 29 |
|
---|
| 30 | QString Images::filename(const QString & name, bool png) {
|
---|
| 31 | QString filename = name;
|
---|
| 32 |
|
---|
| 33 | if (filename.endsWith("_small")) {
|
---|
| 34 | filename = filename.replace("_small", "");
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | if (png) filename += ".png";
|
---|
| 38 |
|
---|
| 39 | return filename;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | QString Images::file(const QString & icon_name) {
|
---|
| 43 | bool ok = false;
|
---|
| 44 | QString filename;
|
---|
| 45 |
|
---|
| 46 | if (!pref->iconset.isEmpty()) {
|
---|
| 47 | filename = Paths::configPath() + "/themes/" + pref->iconset + "/" + icon_name;
|
---|
| 48 | if (!QFile::exists(filename)) {
|
---|
| 49 | filename = Paths::themesPath() + "/" + pref->iconset + "/" + icon_name;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | ok = (QFile::exists(filename));
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | if (!ok) {
|
---|
| 56 | filename = ":/icons-png/" + icon_name;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | qDebug("Images::file: icon_name: '%s', filename: '%s'", icon_name.toUtf8().constData(), filename.toUtf8().constData());
|
---|
| 60 |
|
---|
| 61 | return filename;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | QPixmap Images::loadIcon(const QString & icon_name) {
|
---|
| 65 | QPixmap p;
|
---|
| 66 |
|
---|
| 67 | if (!pref->iconset.isEmpty()) {
|
---|
| 68 | QString filename = Paths::configPath() + "/themes/" + pref->iconset + "/" + icon_name;
|
---|
| 69 | if (!QFile::exists(filename)) {
|
---|
| 70 | filename = Paths::themesPath() + "/" + pref->iconset + "/" + icon_name;
|
---|
| 71 | }
|
---|
| 72 | //qDebug("Images::loadIcon: filename: '%s'", filename.toUtf8().data());
|
---|
| 73 |
|
---|
| 74 | if (QFile::exists(filename)) {
|
---|
| 75 | p.load( filename );
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | return p;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | QPixmap Images::icon(QString name, int size, bool png) {
|
---|
| 83 | bool small = false;
|
---|
| 84 |
|
---|
| 85 | if (name.endsWith("_small")) {
|
---|
| 86 | small = true;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | QString icon_name = Images::filename(name,png);
|
---|
| 90 |
|
---|
| 91 | //qDebug("%s", icon_name.toUtf8().constData());
|
---|
| 92 |
|
---|
| 93 | QPixmap p = Images::loadIcon( icon_name );
|
---|
| 94 | bool ok = !p.isNull();
|
---|
| 95 |
|
---|
| 96 | #if COMPAT_WITH_OLD_ICONS
|
---|
| 97 | if (!ok) {
|
---|
| 98 | if ( (name.startsWith("r")) ||
|
---|
| 99 | (name.startsWith("t")) ||
|
---|
| 100 | (name.startsWith("n")) )
|
---|
| 101 | {
|
---|
| 102 | QString icon_name = Images::filename("x"+name,png);
|
---|
| 103 | p = Images::loadIcon( icon_name );
|
---|
| 104 | ok = !p.isNull();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | #endif
|
---|
| 108 |
|
---|
| 109 | if (!ok) {
|
---|
| 110 | p = QPixmap(":/icons-png/" + icon_name);
|
---|
| 111 | ok = !p.isNull();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | if (ok) {
|
---|
| 115 | if (small) {
|
---|
| 116 | p = resize(&p);
|
---|
| 117 | }
|
---|
| 118 | if (size!=-1) {
|
---|
| 119 | p = resize(&p,size);
|
---|
| 120 | }
|
---|
| 121 | } else {
|
---|
| 122 | //qWarning("Images2::icon: icon '%s' not found", name.toUtf8().data());
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | return p;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | QPixmap Images::resize(QPixmap *p, int size) {
|
---|
| 129 | return QPixmap::fromImage( (*p).toImage().scaled(size,size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation) );
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | QPixmap Images::flip(QPixmap *p) {
|
---|
| 133 | return QPixmap::fromImage( (*p).toImage().mirrored(true, false) );
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | QPixmap Images::flippedIcon(QString name, int size, bool png) {
|
---|
| 137 | QPixmap p = icon(name, size, png);
|
---|
| 138 | p = flip(&p);
|
---|
| 139 | return p;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | QIcon Images::multiIcon(QString name, QString fallback_icon) {
|
---|
| 143 | QPixmap pix = Images::icon(name);
|
---|
| 144 | if (pix.isNull()) return Images::icon(fallback_icon);
|
---|
| 145 |
|
---|
| 146 | QIcon icon;
|
---|
| 147 | int w = pix.width();
|
---|
| 148 | int h = pix.height();
|
---|
| 149 | icon.addPixmap(pix.copy(0, 0, w, h/4 ), QIcon::Normal, QIcon::Off);
|
---|
| 150 | //icon.setPixmap(pix.copy(0, h/4, w, h/4 ), MyIcon::MouseOver, MyIcon::Off);
|
---|
| 151 | //icon.setPixmap(pix.copy(0, h/2, w, h/4 ), MyIcon::MouseDown, MyIcon::Off);
|
---|
| 152 | icon.addPixmap(pix.copy(0, 3*h/4, w, h/4 ), QIcon::Disabled, QIcon::Off);
|
---|
| 153 | return icon;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | QString Images::styleSheet(){
|
---|
| 157 | QString filename;
|
---|
| 158 | filename = themesDirectory() + "/main.css";
|
---|
| 159 | QFile file(filename);
|
---|
| 160 | if (file.exists()) {
|
---|
| 161 | file.open(QFile::ReadOnly | QFile::Text);
|
---|
| 162 | QString css = QString::fromUtf8(file.readAll().constData());
|
---|
| 163 | return css;
|
---|
| 164 | }
|
---|
| 165 | else
|
---|
| 166 | return "";
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | QString Images::themesDirectory(){
|
---|
| 170 | QString skin = pref->iconset;
|
---|
| 171 | QString dirname;
|
---|
| 172 | if (!skin.isEmpty()) {
|
---|
| 173 | dirname = Paths::configPath() + "/themes/" + skin;
|
---|
| 174 | if (!QFile::exists(dirname)) {
|
---|
| 175 | dirname = Paths::themesPath() + "/" + skin ;
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | return dirname;
|
---|
| 179 | }
|
---|
| 180 |
|
---|