3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
26 QIcon Utils::themeIcon(const QString &name) {
27 if (QIcon::hasThemeIcon(name))
28 return QIcon::fromTheme(name);
30 return QIcon(QString(":/images/%1.png").arg(name));
33 QIcon Utils::icon(const QString &name) {
35 return Extra::getIcon(name);
37 return themeIcon(name);
41 QIcon Utils::icon(const QStringList &names) {
43 foreach (QString name, names) {
44 icon = Utils::themeIcon(name);
45 if (!icon.availableSizes().isEmpty()) break;
50 QIcon Utils::tintedIcon(const QString &name, const QColor &color, QList<QSize> sizes) {
53 if (sizes.isEmpty()) sizes = i.availableSizes();
54 foreach (QSize size, sizes) {
55 QPixmap pixmap = i.pixmap(size);
56 QImage tintedImage = tinted(pixmap.toImage(), color);
57 t.addPixmap(QPixmap::fromImage(tintedImage));
62 QImage Utils::grayscaled(const QImage &image) {
64 int pixels = img.width() * img.height();
65 unsigned int *data = (unsigned int *)img.bits();
66 for (int i = 0; i < pixels; ++i) {
67 int val = qGray(data[i]);
68 data[i] = qRgba(val, val, val, qAlpha(data[i]));
73 QImage Utils::tinted(const QImage &image, const QColor &color,
74 QPainter::CompositionMode mode) {
75 QImage img(image.size(), QImage::Format_ARGB32_Premultiplied);
76 QPainter painter(&img);
77 painter.drawImage(0, 0, grayscaled(image));
78 painter.setCompositionMode(mode);
79 painter.fillRect(img.rect(), color);
81 img.setAlphaChannel(image.alphaChannel());
85 void Utils::setupAction(QAction *action) {
87 // unexperienced users tend to keep keys pressed for a "long" time
88 action->setAutoRepeat(false);
90 // show keyboard shortcuts in the status bar
91 if (!action->shortcut().isEmpty())
92 action->setStatusTip(action->statusTip() +
94 action->shortcut().toString(QKeySequence::NativeText) +