X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Futils.cpp;fp=src%2Futils.cpp;h=bf082e0cc4bfe8ea00f7d3c5d3b730996deadf2c;hb=55d99074d0b0b5eca3530d0c0f683faee48f10f9;hp=0000000000000000000000000000000000000000;hpb=88f4a205b9c4053903f1bb5ea619a537e4f8a282;p=case diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..bf082e0 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,67 @@ +// case - file manager for N900 +// Copyright (C) 2010 Lukas Hrazky +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +#include "utils.h" + + +void themeImage(const QPalette &p, QImage &image, const bool inverse) { + image = image.convertToFormat(QImage::Format_Indexed8); + + QRgb highlight = p.highlight().color().rgb(); + QRgb second; + if (inverse) { + second = p.text().color().rgb(); + } else { + second = p.buttonText().color().rgb(); + } + + QVector colorTable = image.colorTable(); + for (QVector::iterator it = colorTable.begin(); it != colorTable.end(); ++it) { + if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | second; + else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight; + } + image.setColorTable(colorTable); +} + + +bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse) { + QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM"); + if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG"); + if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF"); + + QImage inverseIconImage = iconImage; + + themeImage(p, iconImage, false); + themeImage(p, inverseIconImage, true); + + normal = QPixmap::fromImage(iconImage); + inverse = QPixmap::fromImage(inverseIconImage); + return true; +} + + +bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored) { + QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM"); + if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG"); + if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF"); + + themeImage(p, iconImage, false); + + normal = QIcon(QPixmap::fromImage(iconImage)); + mirrored = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false))); + return true; +}