~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to src/images.cpp

  • Committer: Package Import Robot
  • Author(s): Mateusz Łukasik, Mateusz Łukasik, Alessio Treglia
  • Date: 2014-09-10 13:50:48 UTC
  • mfrom: (1.3.3)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20140910135048-t043hd88bhpfvfow
[ Mateusz Łukasik ]
* New upstream release.

[ Alessio Treglia ]
* Repackaging upstream sources to get rid of
  zlib/contrib/dotzlib/DotZLib.chm.
* Enable parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
*/
18
18
 
19
 
#define COMPAT_WITH_OLD_ICONS 1
20
 
 
21
19
#include "images.h"
 
20
#include <QFile>
 
21
#include <QDebug>
 
22
 
 
23
#ifdef USE_RESOURCES
 
24
#include <QResource>
 
25
#endif
 
26
 
 
27
#ifdef SMCODE
22
28
#include "global.h"
23
29
#include "preferences.h"
24
30
#include "paths.h"
25
 
 
26
 
#include <QFile>
27
 
 
28
31
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
 
                }
 
32
#endif
 
33
 
 
34
QString Images::current_theme;
 
35
QString Images::themes_path;
 
36
 
 
37
#ifdef USE_RESOURCES
 
38
QString Images::last_resource_loaded;
 
39
 
 
40
QString 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
 
 
53
void 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/");
121
60
        } else {
122
 
                //qWarning("Images2::icon: icon '%s' not found", name.toUtf8().data());
 
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
 
 
81
void Images::setThemesPath(const QString & folder) {
 
82
        themes_path = folder;
 
83
        qDebug() << "Images::setThemesPath:" << themes_path;
 
84
}
 
85
 
 
86
QString 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
 
 
107
QPixmap 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
                }
123
115
        }
124
116
 
125
117
        return p;
133
125
        return QPixmap::fromImage( (*p).toImage().mirrored(true, false) );
134
126
}
135
127
 
136
 
QPixmap Images::flippedIcon(QString name, int size, bool png) {
137
 
        QPixmap p = icon(name, size, png);
 
128
QPixmap Images::flippedIcon(QString name, int size) {
 
129
        QPixmap p = icon(name, size);
138
130
        p = flip(&p);
139
131
        return p;
140
132
}
141
133
 
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
 
 
 
134
#ifdef SMCODE
156
135
QString Images::styleSheet(){
157
136
        QString filename;
158
137
        filename = themesDirectory() + "/main.css";
177
156
        }
178
157
        return dirname;
179
158
}
180
 
 
 
159
#endif