new style for the progressbars, display more info
[case] / src / utils.cpp
1 // case - file manager for N900
2 // Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
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 3 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, see <http://www.gnu.org/licenses/>.
16
17
18 #include "utils.h"
19
20
21 void themeImage(const QPalette &p, QImage &image, const bool inverse) {
22     image = image.convertToFormat(QImage::Format_Indexed8);
23
24     QRgb highlight = p.highlight().color().rgb();
25     QRgb second;
26     if (inverse) {
27         second = p.text().color().rgb();
28     } else {
29         second = p.buttonText().color().rgb();
30     }
31
32     QVector<QRgb> colorTable = image.colorTable();
33     for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
34         if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | second;
35         else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
36     }
37     image.setColorTable(colorTable);
38 }
39
40
41 bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse) {
42     QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
43     if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
44     if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
45
46     QImage inverseIconImage = iconImage;
47
48     themeImage(p, iconImage, false);
49     themeImage(p, inverseIconImage, true);
50
51     normal = QPixmap::fromImage(iconImage);
52     inverse = QPixmap::fromImage(inverseIconImage);
53     return true;
54 }
55
56
57 bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored) {
58     QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
59     if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
60     if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
61
62     themeImage(p, iconImage, false);
63
64     normal = QIcon(QPixmap::fromImage(iconImage));
65     mirrored = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));
66     return true;
67 }