00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "IconLoader.h"
00017
00018 #include <QPixmap>
00019 #include <QApplication>
00020 #include <QPainter>
00021 #include <QPalette>
00022
00023 static const char *autoInvertExceptions[] = {
00024
00025
00026
00027
00028
00029
00030
00031 "fileclose",
00032 "filenew-22",
00033 "filenew",
00034 "fileopen-22",
00035 "fileopen",
00036 "fileopenaudio",
00037 "fileopensession",
00038 "filesave-22",
00039 "filesave",
00040 "filesaveas-22",
00041 "filesaveas",
00042 "help",
00043 "editcut",
00044 "editcopy",
00045 "editpaste",
00046 "editdelete",
00047 "exit",
00048 "zoom-fit",
00049 "zoom-in",
00050 "zoom-out",
00051 "zoom"
00052 };
00053
00054 QIcon
00055 IconLoader::load(QString name)
00056 {
00057 QPixmap pmap(loadPixmap(name));
00058 if (pmap.isNull()) return QIcon();
00059 else return QIcon(pmap);
00060 }
00061
00062 QPixmap
00063 IconLoader::loadPixmap(QString name)
00064 {
00065 QColor bg = QApplication::palette().window().color();
00066 if (bg.red() + bg.green() + bg.blue() > 384) {
00067 QPixmap pmap(QString(":icons/%1").arg(name));
00068 if (pmap.isNull()) {
00069 pmap = QPixmap(QString(":icons/%1.png").arg(name));
00070 }
00071 return pmap;
00072 }
00073
00074 QPixmap pmap(QString(":icons/%1").arg(name));
00075 if (pmap.isNull()) {
00076 pmap = QPixmap(QString(":icons/%1_inverse.png").arg(name));
00077 if (pmap.isNull()) {
00078 pmap = QPixmap(QString(":icons/%1.png").arg(name));
00079 }
00080 }
00081 if (pmap.isNull()) return pmap;
00082
00083 for (int i = 0; i < sizeof(autoInvertExceptions)/
00084 sizeof(autoInvertExceptions[0]); ++i) {
00085 if (autoInvertExceptions[i] == name) {
00086 return pmap;
00087 }
00088 }
00089
00090
00091
00092
00093 QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32);
00094
00095 for (int y = 0; y < img.height(); ++y) {
00096 for (int x = 0; x < img.width(); ++x) {
00097
00098 QRgb rgba = img.pixel(x, y);
00099 QColor colour = QColor
00100 (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));
00101
00102 int alpha = colour.alpha();
00103 if (colour.saturation() < 5 && colour.alpha() > 10) {
00104 colour.setHsv(colour.hue(),
00105 colour.saturation(),
00106 255 - colour.value());
00107 colour.setAlpha(alpha);
00108 img.setPixel(x, y, colour.rgba());
00109 }
00110 }
00111 }
00112
00113 pmap = QPixmap::fromImage(img);
00114 return pmap;
00115 }
00116