]> git.sur5r.net Git - minitube/commitdiff
Renamed Utils to IconUtils
authorFlavio Tordini <flavio.tordini@gmail.com>
Thu, 16 Oct 2014 07:27:20 +0000 (09:27 +0200)
committerFlavio <flavio.tordini@gmail.com>
Thu, 16 Oct 2014 07:27:20 +0000 (09:27 +0200)
13 files changed:
minitube.pro
src/channelview.cpp
src/homeview.cpp
src/iconutils.cpp [new file with mode: 0644]
src/iconutils.h [new file with mode: 0644]
src/main.cpp
src/mainwindow.cpp
src/mediaview.cpp
src/playlistitemdelegate.cpp
src/searchlineedit.cpp
src/searchlineedit.h
src/sidebarheader.cpp
src/ytsearch.cpp

index 23de6916943729a8dd681ae7426635af41599153..effa02ed02b9d980f9ccaa1fcaee22cb59f2d20c 100644 (file)
@@ -78,7 +78,7 @@ HEADERS += src/video.h \
     src/regionsview.h \
     src/ytsinglevideosource.h \
     src/sidebarheader.h \
-    src/utils.h \
+    src/iconutils.h \
     src/diskcache.h \
     src/gridwidget.h \
     src/painterutils.h \
@@ -144,7 +144,7 @@ SOURCES += src/main.cpp \
     src/regionsview.cpp \
     src/ytsinglevideosource.cpp \
     src/sidebarheader.cpp \
-    src/utils.cpp \
+    src/iconutils.cpp \
     src/diskcache.cpp \
     src/gridwidget.cpp \
     src/painterutils.cpp \
index f5cb3ac57913a2c5b1b98c291ea3b89ac692f306..af5cb0184f8b57c4caf1f739424209473acbef62 100644 (file)
@@ -30,7 +30,7 @@ $END_LICENSE */
 #include "aggregatevideosource.h"
 #include "painterutils.h"
 #include "mainwindow.h"
-#include "utils.h"
+#include "iconutils.h"
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
@@ -137,7 +137,7 @@ void ChannelView::setupActions() {
 
     QToolButton *sortButton = new QToolButton(this);
     sortButton->setText(tr("Sort by"));
-    sortButton->setIcon(Utils::icon("sort"));
+    sortButton->setIcon(IconUtils::icon("sort"));
     sortButton->setIconSize(QSize(16, 16));
     sortButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     sortButton->setPopupMode(QToolButton::InstantPopup);
@@ -148,7 +148,7 @@ void ChannelView::setupActions() {
     statusActions << widgetAction;
 
     markAsWatchedAction = new QAction(
-                Utils::icon("mark-watched"), tr("Mark all as watched"), this);
+                IconUtils::icon("mark-watched"), tr("Mark all as watched"), this);
     markAsWatchedAction->setEnabled(false);
     markAsWatchedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
     connect(markAsWatchedAction, SIGNAL(triggered()), SLOT(markAllAsWatched()));
@@ -156,7 +156,7 @@ void ChannelView::setupActions() {
 
     showUpdated = settings.value(showUpdatedKey, false).toBool();
     QAction *showUpdatedAction = new QAction(
-                Utils::icon("show-updated"), tr("Show Updated"), this);
+                IconUtils::icon("show-updated"), tr("Show Updated"), this);
     showUpdatedAction->setCheckable(true);
     showUpdatedAction->setChecked(showUpdated);
     showUpdatedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
@@ -165,7 +165,7 @@ void ChannelView::setupActions() {
 
     foreach (QAction *action, statusActions) {
         window()->addAction(action);
-        Utils::setupAction(action);
+        IconUtils::setupAction(action);
     }
 }
 
index a3b54350e04adaa4b45d40ae0642f4215276dfa9..1d56c26553dd6d3d802895ccc313f36b16e858e7 100644 (file)
@@ -26,7 +26,7 @@ $END_LICENSE */
 #include "mainwindow.h"
 #include "mediaview.h"
 #include "ytstandardfeed.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "channelaggregator.h"
 #ifdef APP_MAC
 #include "macutils.h"
@@ -78,7 +78,7 @@ void HomeView::setupBar() {
 
     foreach (QAction* action, bar->actions()) {
         addAction(action);
-        Utils::setupAction(action);
+        IconUtils::setupAction(action);
     }
 }
 
diff --git a/src/iconutils.cpp b/src/iconutils.cpp
new file mode 100644 (file)
index 0000000..75ded53
--- /dev/null
@@ -0,0 +1,111 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube 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.
+
+Minitube 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 Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
+#include "iconutils.h"
+
+QIcon IconUtils::fromTheme(const QString &name) {
+    const QLatin1String symbolic("-symbolic");
+    if (name.endsWith(symbolic)) return QIcon::fromTheme(name);
+    QIcon icon;
+    icon = QIcon::fromTheme(name + symbolic);
+    if (icon.isNull()) return QIcon::fromTheme(name);
+    return icon;
+}
+
+QIcon IconUtils::fromResources(const QString &name) {
+    QIcon icon = QIcon(QString(":/images/%1.png").arg(name));
+    if (!icon.isNull()) {
+        icon.addPixmap(QString(":/images/%1_active.png").arg(name), QIcon::Active);
+        icon.addPixmap(QString(":/images/%1_selected.png").arg(name), QIcon::Selected);
+        icon.addPixmap(QString(":/images/%1_disabled.png").arg(name), QIcon::Disabled);
+    }
+    return icon;
+}
+
+QIcon IconUtils::icon(const QString &name) {
+#if defined(APP_MAC) || defined(APP_WIN)
+    return fromResources(name);
+#else
+    QIcon icon = fromTheme(name);
+    if (icon.isNull()) icon = fromResources(name);
+    return icon;
+#endif
+}
+
+QIcon IconUtils::icon(const QStringList &names) {
+    QIcon icon;
+    foreach (QString name, names) {
+        icon = IconUtils::icon(name);
+        if (!icon.availableSizes().isEmpty()) break;
+    }
+    return icon;
+}
+
+QIcon IconUtils::tintedIcon(const QString &name, const QColor &color, QList<QSize> sizes) {
+    QIcon i = IconUtils::icon(name);
+    QIcon t;
+    if (sizes.isEmpty()) sizes = i.availableSizes();
+    foreach (QSize size, sizes) {
+        QPixmap pixmap = i.pixmap(size);
+        QImage tintedImage = tinted(pixmap.toImage(), color);
+        t.addPixmap(QPixmap::fromImage(tintedImage));
+    }
+    return t;
+}
+
+QIcon IconUtils::tintedIcon(const QString &name, const QColor &color, const QSize &size) {
+    return IconUtils::tintedIcon(name, color, QList<QSize>() << size);
+}
+
+QImage IconUtils::grayscaled(const QImage &image) {
+    QImage img = image;
+    int pixels = img.width() * img.height();
+    unsigned int *data = (unsigned int *)img.bits();
+    for (int i = 0; i < pixels; ++i) {
+        int val = qGray(data[i]);
+        data[i] = qRgba(val, val, val, qAlpha(data[i]));
+    }
+    return img;
+}
+
+QImage IconUtils::tinted(const QImage &image, const QColor &color,
+                         QPainter::CompositionMode mode) {
+    QImage img(image.size(), QImage::Format_ARGB32_Premultiplied);
+    QPainter painter(&img);
+    painter.drawImage(0, 0, grayscaled(image));
+    painter.setCompositionMode(mode);
+    painter.fillRect(img.rect(), color);
+    painter.end();
+    img.setAlphaChannel(image.alphaChannel());
+    return img;
+}
+
+void IconUtils::setupAction(QAction *action) {
+    // never autorepeat.
+    // unexperienced users tend to keep keys pressed for a "long" time
+    action->setAutoRepeat(false);
+
+    // show keyboard shortcuts in the status bar
+    if (!action->shortcut().isEmpty())
+        action->setStatusTip(action->statusTip() +
+                             " (" +
+                             action->shortcut().toString(QKeySequence::NativeText) +
+                             ")");
+}
diff --git a/src/iconutils.h b/src/iconutils.h
new file mode 100644 (file)
index 0000000..398fc4c
--- /dev/null
@@ -0,0 +1,45 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube 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.
+
+Minitube 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 Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
+#ifndef ICONUTILS_H
+#define ICONUTILS_H
+
+#include <QtGui>
+
+class IconUtils {
+
+public:
+    static QIcon fromTheme(const QString &name);
+    static QIcon fromResources(const QString &name);
+    static QIcon icon(const QString &name);
+    static QIcon icon(const QStringList &names);
+    static QIcon tintedIcon(const QString &name, const QColor &color,
+                            QList<QSize> sizes = QList<QSize>());
+    static QIcon tintedIcon(const QString &name, const QColor &color, const QSize &size);
+    static void setupAction(QAction *action);
+
+private:
+    IconUtils() { }
+    static QImage grayscaled(const QImage &image);
+    static QImage tinted(const QImage &image, const QColor &color,
+                         QPainter::CompositionMode mode = QPainter::CompositionMode_Screen);
+};
+
+#endif // ICONUTILS_H
index a1232c921b94411cc27e511179b78254853d1f9e..1fab51c285ccdcfbcee1b2f84a88197c0a4c599a 100644 (file)
@@ -26,7 +26,7 @@ $END_LICENSE */
 #include "constants.h"
 #include "mainwindow.h"
 #include "searchparams.h"
-#include "utils.h"
+#include "iconutils.h"
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
@@ -103,7 +103,7 @@ int main(int argc, char **argv) {
 #ifndef APP_MAC
     QIcon appIcon;
     if (QDir(dataDir).exists()) {
-        appIcon = Utils::icon(Constants::UNIX_NAME);
+        appIcon = IconUtils::icon(Constants::UNIX_NAME);
     } else {
         dataDir = qApp->applicationDirPath() + "/data";
         const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
index d7093d6ffff15c7109fe2a5b1fbe8d383d672c52..1602b9a594978275af77070a056a80dc02026061 100644 (file)
@@ -26,7 +26,7 @@ $END_LICENSE */
 #include "downloadview.h"
 #include "spacer.h"
 #include "constants.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "global.h"
 #include "videodefinition.h"
 #include "fontutils.h"
@@ -264,7 +264,7 @@ void MainWindow::createActions() {
 
     QHash<QString, QAction*> *actions = The::globalActions();
 
-    stopAct = new QAction(Utils::icon("media-playback-stop"), tr("&Stop"), this);
+    stopAct = new QAction(IconUtils::icon("media-playback-stop"), tr("&Stop"), this);
     stopAct->setStatusTip(tr("Stop playback and go back to the search view"));
     stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
     stopAct->setEnabled(false);
@@ -272,7 +272,7 @@ void MainWindow::createActions() {
     connect(stopAct, SIGNAL(triggered()), SLOT(stop()));
 
     skipBackwardAct = new QAction(
-                Utils::icon("media-skip-backward"),
+                IconUtils::icon("media-skip-backward"),
                 tr("P&revious"), this);
     skipBackwardAct->setStatusTip(tr("Go back to the previous track"));
     skipBackwardAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
@@ -280,21 +280,21 @@ void MainWindow::createActions() {
     actions->insert("previous", skipBackwardAct);
     connect(skipBackwardAct, SIGNAL(triggered()), mediaView, SLOT(skipBackward()));
 
-    skipAct = new QAction(Utils::icon("media-skip-forward"), tr("S&kip"), this);
+    skipAct = new QAction(IconUtils::icon("media-skip-forward"), tr("S&kip"), this);
     skipAct->setStatusTip(tr("Skip to the next video"));
     skipAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Right) << QKeySequence(Qt::Key_MediaNext));
     skipAct->setEnabled(false);
     actions->insert("skip", skipAct);
     connect(skipAct, SIGNAL(triggered()), mediaView, SLOT(skip()));
 
-    pauseAct = new QAction(Utils::icon("media-playback-pause"), tr("&Pause"), this);
+    pauseAct = new QAction(IconUtils::icon("media-playback-pause"), tr("&Pause"), this);
     pauseAct->setStatusTip(tr("Pause playback"));
     pauseAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Space) << QKeySequence(Qt::Key_MediaPlay));
     pauseAct->setEnabled(false);
     actions->insert("pause", pauseAct);
     connect(pauseAct, SIGNAL(triggered()), mediaView, SLOT(pause()));
 
-    fullscreenAct = new QAction(Utils::icon("view-fullscreen"), tr("&Full Screen"), this);
+    fullscreenAct = new QAction(IconUtils::icon("view-fullscreen"), tr("&Full Screen"), this);
     fullscreenAct->setStatusTip(tr("Go full screen"));
     QList<QKeySequence> fsShortcuts;
 #ifdef APP_MAC
@@ -428,7 +428,7 @@ void MainWindow::createActions() {
     addAction(volumeDownAct);
 
     volumeMuteAct = new QAction(this);
-    volumeMuteAct->setIcon(Utils::icon("audio-volume-high"));
+    volumeMuteAct->setIcon(IconUtils::icon("audio-volume-high"));
     volumeMuteAct->setStatusTip(tr("Mute volume"));
     volumeMuteAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
     actions->insert("volume-mute", volumeMuteAct);
@@ -437,10 +437,10 @@ void MainWindow::createActions() {
 
     QAction *definitionAct = new QAction(this);
 #ifdef Q_OS_LINUX
-    definitionAct->setIcon(Utils::tintedIcon("video-display", QColor(0, 0, 0),
+    definitionAct->setIcon(IconUtils::tintedIcon("video-display", QColor(0, 0, 0),
                                              QList<QSize>() << QSize(16, 16)));
 #else
-    definitionAct->setIcon(Utils::icon("video-display"));
+    definitionAct->setIcon(IconUtils::icon("video-display"));
 #endif
     definitionAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_D));
     /*
@@ -456,7 +456,7 @@ void MainWindow::createActions() {
 
     QAction *action;
 
-    action = new QAction(Utils::icon("media-playback-start"), tr("&Manually Start Playing"), this);
+    action = new QAction(IconUtils::icon("media-playback-start"), tr("&Manually Start Playing"), this);
     action->setStatusTip(tr("Manually start playing videos"));
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T));
     action->setCheckable(true);
@@ -467,7 +467,7 @@ void MainWindow::createActions() {
     action->setStatusTip(tr("Show details about video downloads"));
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
     action->setCheckable(true);
-    action->setIcon(Utils::icon("document-save"));
+    action->setIcon(IconUtils::icon("document-save"));
     action->setVisible(false);
     connect(action, SIGNAL(toggled(bool)), SLOT(toggleDownloads(bool)));
     actions->insert("downloads", action);
@@ -475,7 +475,7 @@ void MainWindow::createActions() {
     action = new QAction(tr("&Download"), this);
     action->setStatusTip(tr("Download the current video"));
     action->setShortcut(QKeySequence::Save);
-    action->setIcon(Utils::icon("document-save"));
+    action->setIcon(IconUtils::icon("document-save"));
     action->setEnabled(false);
     action->setVisible(false);
     action->setPriority(QAction::LowPriority);
@@ -534,12 +534,12 @@ void MainWindow::createActions() {
     actions->insert("restore", action);
     connect(action, SIGNAL(triggered()), SLOT(restore()));
 
-    action = new QAction(Utils::icon("go-top"), tr("&Float on Top"), this);
+    action = new QAction(IconUtils::icon("go-top"), tr("&Float on Top"), this);
     action->setCheckable(true);
     actions->insert("ontop", action);
     connect(action, SIGNAL(toggled(bool)), SLOT(floatOnTop(bool)));
 
-    action = new QAction(Utils::icon("media-playback-stop"), tr("&Stop After This Video"), this);
+    action = new QAction(IconUtils::icon("media-playback-stop"), tr("&Stop After This Video"), this);
     action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Escape));
     action->setCheckable(true);
     action->setEnabled(false);
@@ -565,7 +565,7 @@ void MainWindow::createActions() {
     action = new QAction(tr("More..."), this);
     actions->insert("more-region", action);
 
-    action = new QAction(Utils::icon(QStringList() << "view-list-symbolic" << "view-list" << "format-justify-fill"), tr("&Related Videos"), this);
+    action = new QAction(IconUtils::icon("view-list"), tr("&Related Videos"), this);
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
     action->setStatusTip(tr("Watch videos related to the current one"));
     action->setEnabled(false);
@@ -594,7 +594,7 @@ void MainWindow::createActions() {
         // add actions to the MainWindow so that they work
         // when the menu is hidden
         addAction(action);
-        Utils::setupAction(action);
+        IconUtils::setupAction(action);
     }
 }
 
@@ -1057,7 +1057,7 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState
 
     case Phonon::PlayingState:
         pauseAct->setEnabled(true);
-        pauseAct->setIcon(Utils::icon("media-playback-pause"));
+        pauseAct->setIcon(IconUtils::icon("media-playback-pause"));
         pauseAct->setText(tr("&Pause"));
         pauseAct->setStatusTip(tr("Pause playback") + " (" +  pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
         // stopAct->setEnabled(true);
@@ -1070,7 +1070,7 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState
 
     case Phonon::PausedState:
         pauseAct->setEnabled(true);
-        pauseAct->setIcon(Utils::icon("media-playback-start"));
+        pauseAct->setIcon(IconUtils::icon("media-playback-start"));
         pauseAct->setText(tr("&Play"));
         pauseAct->setStatusTip(tr("Resume playback") + " (" +  pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
         // stopAct->setEnabled(true);
@@ -1173,11 +1173,11 @@ void MainWindow::updateUIForFullscreen() {
         fullscreenAct->setShortcuts(QList<QKeySequence>(fsShortcuts)
                                     << QKeySequence(Qt::Key_Escape));
         fullscreenAct->setText(tr("Leave &Full Screen"));
-        fullscreenAct->setIcon(Utils::icon("view-restore"));
+        fullscreenAct->setIcon(IconUtils::icon("view-restore"));
     } else {
         fullscreenAct->setShortcuts(fsShortcuts);
         fullscreenAct->setText(fsText);
-        fullscreenAct->setIcon(Utils::icon("view-fullscreen"));
+        fullscreenAct->setIcon(IconUtils::icon("view-fullscreen"));
     }
 
     // No compact view action when in full screen
@@ -1422,10 +1422,10 @@ void MainWindow::volumeChanged(qreal newVolume) {
 
 void MainWindow::volumeMutedChanged(bool muted) {
     if (muted) {
-        volumeMuteAct->setIcon(Utils::icon("audio-volume-muted"));
+        volumeMuteAct->setIcon(IconUtils::icon("audio-volume-muted"));
         statusBar()->showMessage(tr("Volume is muted"));
     } else {
-        volumeMuteAct->setIcon(Utils::icon("audio-volume-high"));
+        volumeMuteAct->setIcon(IconUtils::icon("audio-volume-high"));
         statusBar()->showMessage(tr("Volume is unmuted"));
     }
 }
index 7b62b1ee5f6611ee3f6dbc404ad1a63f4dc60cc4..1f703181f425f850e451912a19487c3a1c5dda53 100644 (file)
@@ -44,7 +44,7 @@ $END_LICENSE */
 #include "searchparams.h"
 #include "ytsinglevideosource.h"
 #include "channelaggregator.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "ytuser.h"
 #ifdef APP_SNAPSHOT
 #include "snapshotsettings.h"
@@ -1122,17 +1122,17 @@ void MediaView::updateSubscriptionAction(Video *video, bool subscribed) {
         if (tintedIcon.isNull()) {
             QList<QSize> sizes;
             sizes << QSize(16, 16);
-            tintedIcon = Utils::tintedIcon("bookmark-new", QColor(254, 240, 0), sizes);
+            tintedIcon = IconUtils::tintedIcon("bookmark-new", QColor(254, 240, 0), sizes);
         }
         subscribeAction->setIcon(tintedIcon);
 #else
-        subscribeAction->setIcon(Utils::icon("bookmark-remove"));
+        subscribeAction->setIcon(IconUtils::icon("bookmark-remove"));
 #endif
     } else {
-        subscribeAction->setIcon(Utils::icon("bookmark-new"));
+        subscribeAction->setIcon(IconUtils::icon("bookmark-new"));
     }
 
-    Utils::setupAction(subscribeAction);
+    IconUtils::setupAction(subscribeAction);
 }
 
 void MediaView::toggleSubscription() {
index f0de4b47c98dae7e1a1f9c53bc1aa3cb91432524..81bdae47612e9e13789d06d7ce8eb47ce01e395d 100644 (file)
@@ -22,7 +22,7 @@ $END_LICENSE */
 #include "playlistmodel.h"
 #include "fontutils.h"
 #include "downloaditem.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "videodefinition.h"
 #include "video.h"
 
@@ -380,7 +380,7 @@ void PlaylistItemDelegate::paintDownloadInfo( QPainter* painter,
     if (status != Finished && status != Failed && status != Idle) {
         if (downloadButtonHovered) message = tr("Stop downloading");
         painter->save();
-        QIcon closeIcon = Utils::icon("window-close");
+        QIcon closeIcon = IconUtils::icon("window-close");
         painter->drawPixmap(downloadButtonRect(line), closeIcon.pixmap(16, 16, iconMode));
         painter->restore();
     }
@@ -393,7 +393,7 @@ void PlaylistItemDelegate::paintDownloadInfo( QPainter* painter,
             message = tr("Open parent folder");
 #endif
         painter->save();
-        QIcon searchIcon = Utils::icon("system-search");
+        QIcon searchIcon = IconUtils::icon("system-search");
         painter->drawPixmap(downloadButtonRect(line), searchIcon.pixmap(16, 16, iconMode));
         painter->restore();
     }
@@ -401,7 +401,7 @@ void PlaylistItemDelegate::paintDownloadInfo( QPainter* painter,
     else if (status == Failed || status == Idle) {
         if (downloadButtonHovered) message = tr("Restart downloading");
         painter->save();
-        QIcon searchIcon = Utils::icon("view-refresh");
+        QIcon searchIcon = IconUtils::icon("view-refresh");
         painter->drawPixmap(downloadButtonRect(line), searchIcon.pixmap(16, 16, iconMode));
         painter->restore();
     }
index 20b50d2b2fad90a3cc9b6d7fb19e8d32f0644627..1d04f680b02a70a33d67c5ef8384485505540a55 100644 (file)
@@ -7,44 +7,54 @@
 #include <QStyleOptionFrameV2>
 
 #include "autocomplete.h"
+#include "iconutils.h"
 
-ClearButton::ClearButton(QWidget *parent)
-    : QAbstractButton(parent)
-{
+ClearButton::ClearButton(QWidget *parent) : QAbstractButton(parent), hovered(false), mousePressed(false) {
     setCursor(Qt::ArrowCursor);
     setToolTip(tr("Clear"));
     setVisible(false);
     setFocusPolicy(Qt::NoFocus);
 }
 
-void ClearButton::paintEvent(QPaintEvent *event)
-{
-    Q_UNUSED(event);
+void ClearButton::paintEvent(QPaintEvent *e) {
+    Q_UNUSED(e);
     QPainter painter(this);
-    int height = this->height();
-
-    painter.setRenderHint(QPainter::Antialiasing, true);
-    // QColor color = palette().color(QPalette::Mid);
-    painter.setBrush(isDown()
-                     ? palette().color(QPalette::Dark)
-                         : palette().color(QPalette::Mid));
-    painter.setPen(painter.brush().color());
-    int size = width();
-    int offset = size / 3.5;
-    int radius = size - offset * 2;
-    painter.drawEllipse(offset, offset, radius, radius);
-
-    painter.setPen(QPen(palette().color(QPalette::Base),2));
-    int border = offset * 1.6;
-    painter.drawLine(border, border, width() - border, height - border);
-    painter.drawLine(border, height - border, width() - border, border);
-}
-
-void ClearButton::textChanged(const QString &text)
-{
+    const int h = height();
+    int iconSize = 16;
+    if (h > 30) iconSize = 22;
+    QIcon::Mode iconMode = QIcon::Normal;
+    if (mousePressed) iconMode = QIcon::Active;
+    QPixmap p = IconUtils::icon("edit-clear").pixmap(iconSize, iconSize, iconMode);
+    // QPixmap p = IconUtils::tintedIcon("edit-clear", Qt::black, QSize(iconSize, iconSize)).pixmap(iconSize, iconSize, iconMode);
+    int x = (width() - p.width()) / 2;
+    int y = (h - p.height()) / 2;
+    painter.drawPixmap(x, y, p);
+}
+
+void ClearButton::textChanged(const QString &text) {
     setVisible(!text.isEmpty());
 }
 
+void ClearButton::enterEvent(QEvent *e) {
+    Q_UNUSED(e);
+    hovered = true;
+}
+
+void ClearButton::leaveEvent(QEvent *e) {
+    Q_UNUSED(e);
+    hovered = false;
+}
+
+void ClearButton::mousePressEvent(QEvent *e) {
+    Q_UNUSED(e);
+    mousePressed = true;
+}
+
+void ClearButton::mouseReleaseEvent(QEvent *e) {
+    Q_UNUSED(e);
+    mousePressed = false;
+}
+
 /*
     Search icon on the left hand side of the search widget
     When a menu is set a down arrow appears
@@ -61,15 +71,13 @@ protected:
 
 SearchButton::SearchButton(QWidget *parent)
     : QAbstractButton(parent),
-    m_menu(0)
-{
+    m_menu(0) {
     setObjectName(QLatin1String("SearchButton"));
     setCursor(Qt::ArrowCursor);
     setFocusPolicy(Qt::NoFocus);
 }
 
-void SearchButton::mousePressEvent(QMouseEvent *event)
-{
+void SearchButton::mousePressEvent(QMouseEvent *event) {
     if (m_menu && event->button() == Qt::LeftButton) {
         QWidget *p = parentWidget();
         if (p) {
@@ -81,40 +89,16 @@ void SearchButton::mousePressEvent(QMouseEvent *event)
     QAbstractButton::mousePressEvent(event);
 }
 
-void SearchButton::paintEvent(QPaintEvent *event)
-{
+void SearchButton::paintEvent(QPaintEvent *event) {
     Q_UNUSED(event);
-    QPainterPath myPath;
-
-    int radius = (height() / 5) * 2;
-    QRect circle(height() / 5.5, height() / 3.5, radius, radius);
-    myPath.addEllipse(circle);
-
-    myPath.arcMoveTo(circle, 315);
-    QPointF c = myPath.currentPosition();
-    int diff = height() / 6;
-    myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff);
-
     QPainter painter(this);
-    painter.setRenderHint(QPainter::Antialiasing, true);
-    painter.setPen(QPen(palette().color(QPalette::Mid), height() / 10));
-    painter.drawPath(myPath);
-
-    if (m_menu) {
-        QPainterPath dropPath;
-        dropPath.arcMoveTo(circle, 320);
-        QPointF c = dropPath.currentPosition();
-        c = QPointF(c.x() + 3.5, c.y() + 0.5);
-        dropPath.moveTo(c);
-        dropPath.lineTo(c.x() + 4, c.y());
-        dropPath.lineTo(c.x() + 2, c.y() + 2);
-        dropPath.closeSubpath();
-        painter.setPen(Qt::darkGray);
-        painter.setBrush(Qt::darkGray);
-        painter.setRenderHint(QPainter::Antialiasing, false);
-        painter.drawPath(dropPath);
-    }
-    painter.end();
+    const int h = height();
+    int iconSize = 16;
+    if (h > 30) iconSize = 22;
+    QPixmap p = IconUtils::fromTheme("edit-find-symbolic").pixmap(iconSize, iconSize);
+    int x = (width() - p.width()) / 2;
+    int y = (h - p.height()) / 2;
+    painter.drawPixmap(x, y, p);
 }
 
 /*
@@ -124,26 +108,24 @@ void SearchButton::paintEvent(QPaintEvent *event)
     - When there is text a clear button is displayed on the right hand side
  */
 SearchLineEdit::SearchLineEdit(QWidget *parent) : ExLineEdit(parent),
-m_searchButton(new SearchButton(this))
-{
+searchButton(new SearchButton(this)) {
     connect(lineEdit(), SIGNAL(textChanged(const QString &)), SIGNAL(textChanged(const QString &)));
     connect(lineEdit(), SIGNAL(textEdited(const QString &)), SIGNAL(textEdited(const QString &)));
     connect(lineEdit(), SIGNAL(returnPressed()), SLOT(returnPressed()));
 
-    setLeftWidget(m_searchButton);
-    m_inactiveText = tr("Search");
+    setLeftWidget(searchButton);
+    inactiveText = tr("Search");
 
     QSizePolicy policy = sizePolicy();
     setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy());
 
     // completion
-    completion = new AutoComplete(this, m_lineEdit);
-    connect(completion, SIGNAL(suggestionAccepted(Suggestion*)), SIGNAL(suggestionAccepted(Suggestion*)));
+    autoComplete = new AutoComplete(this, m_lineEdit);
+    connect(autoComplete, SIGNAL(suggestionAccepted(Suggestion*)), SIGNAL(suggestionAccepted(Suggestion*)));
 }
 
-void SearchLineEdit::paintEvent(QPaintEvent *event)
-{
-    if (lineEdit()->text().isEmpty() && !hasFocus() && !m_inactiveText.isEmpty()) {
+void SearchLineEdit::paintEvent(QPaintEvent *event) {
+    if (lineEdit()->text().isEmpty() && !hasFocus() && !inactiveText.isEmpty()) {
         ExLineEdit::paintEvent(event);
         QStyleOptionFrameV2 panel;
         initStyleOption(&panel);
@@ -154,69 +136,58 @@ void SearchLineEdit::paintEvent(QPaintEvent *event)
                        r.width() - 2 * horizontalMargin, fm.height());
         QPainter painter(this);
         painter.setPen(palette().brush(QPalette::Disabled, QPalette::Text).color());
-        painter.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, m_inactiveText);
+        painter.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, inactiveText);
     } else {
         ExLineEdit::paintEvent(event);
     }
 }
 
-void SearchLineEdit::resizeEvent(QResizeEvent *event)
-{
+void SearchLineEdit::resizeEvent(QResizeEvent *event) {
     updateGeometries();
     ExLineEdit::resizeEvent(event);
 }
 
-void SearchLineEdit::updateGeometries()
-{
+void SearchLineEdit::updateGeometries() {
     int menuHeight = height();
     int menuWidth = menuHeight + 1;
-    if (!m_searchButton->m_menu)
+    if (!searchButton->m_menu)
         menuWidth = (menuHeight / 5) * 4;
-    m_searchButton->resize(QSize(menuWidth, menuHeight));
-}
-
-QString SearchLineEdit::inactiveText() const
-{
-    return m_inactiveText;
+    searchButton->resize(QSize(menuWidth, menuHeight));
 }
 
-void SearchLineEdit::setInactiveText(const QString &text)
-{
-    m_inactiveText = text;
+void SearchLineEdit::setInactiveText(const QString &text) {
+    inactiveText = text;
 }
 
-void SearchLineEdit::setMenu(QMenu *menu)
-{
-    if (m_searchButton->m_menu)
-        m_searchButton->m_menu->deleteLater();
-    m_searchButton->m_menu = menu;
+void SearchLineEdit::setMenu(QMenu *menu) {
+    if (searchButton->m_menu)
+        searchButton->m_menu->deleteLater();
+    searchButton->m_menu = menu;
     updateGeometries();
 }
 
-QMenu *SearchLineEdit::menu() const
-{
-    if (!m_searchButton->m_menu) {
-        m_searchButton->m_menu = new QMenu(m_searchButton);
+QMenu *SearchLineEdit::menu() const {
+    if (!searchButton->m_menu) {
+        searchButton->m_menu = new QMenu(searchButton);
         if (isVisible())
             (const_cast<SearchLineEdit*>(this))->updateGeometries();
     }
-    return m_searchButton->m_menu;
+    return searchButton->m_menu;
 }
 
-void SearchLineEdit::returnPressed()
-{
+void SearchLineEdit::returnPressed() {
     if (!lineEdit()->text().isEmpty()) {
-        completion->preventSuggest();
+        autoComplete->preventSuggest();
         emit search(lineEdit()->text());
     }
 }
 
 void SearchLineEdit::enableSuggest() {
-    completion->enableSuggest();
+    autoComplete->enableSuggest();
 }
 
 void SearchLineEdit::preventSuggest() {
-    completion->preventSuggest();
+    autoComplete->preventSuggest();
 }
 
 void SearchLineEdit::focusInEvent(QFocusEvent *event) {
index 5f9fd858d3496cf0ded401c2cb593af14ca704fb..64b0d285a1da979d2b66eee1eb7e863dee741297 100644 (file)
@@ -17,25 +17,33 @@ class Suggester;
 /*
     Clear button on the right hand side of the search widget.
     Hidden by default
-    "A circle with an X in it"
  */
-class ClearButton : public QAbstractButton
-{
+class ClearButton : public QAbstractButton {
+
     Q_OBJECT
 
 public:
     ClearButton(QWidget *parent = 0);
-    void paintEvent(QPaintEvent *event);
+    void paintEvent(QPaintEvent *e);
 
 public slots:
     void textChanged(const QString &text);
+
+protected:
+    void enterEvent(QEvent *e);
+    void leaveEvent(QEvent *e);
+
+    void mousePressEvent(QEvent *e);
+    void mouseReleaseEvent(QEvent *e);
+
+private:
+    bool hovered;
+    bool mousePressed;
 };
 
+class SearchLineEdit : public ExLineEdit {
 
-class SearchLineEdit : public ExLineEdit
-{
     Q_OBJECT
-    Q_PROPERTY(QString inactiveText READ inactiveText WRITE setInactiveText)
 
 signals:
     void textChanged(const QString &text);
@@ -46,7 +54,6 @@ signals:
 public:
     SearchLineEdit(QWidget *parent = 0);
 
-    QString inactiveText() const;
     void setInactiveText(const QString &text);
 
     QMenu *menu() const;
@@ -55,7 +62,7 @@ public:
     void enableSuggest();
     void preventSuggest();
     void selectAll() { lineEdit()->selectAll(); }
-    void setSuggester(Suggester *suggester) { completion->setSuggester(suggester); }
+    void setSuggester(Suggester *suggester) { autoComplete->setSuggester(suggester); }
     void setText(const QString &text) { lineEdit()->setText(text); }
 
 protected:
@@ -67,9 +74,9 @@ private slots:
     void returnPressed();
 
 private:
-    SearchButton *m_searchButton;
-    QString m_inactiveText;
-    AutoComplete *completion;
+    SearchButton *searchButton;
+    QString inactiveText;
+    AutoComplete *autoComplete;
 };
 
 #endif // SEARCHLINEEDIT_H
index dc8026e4550d18d651f923ca02e13c4ccae375ee..8399a9641b253a99e9b11b577db430c5157e4a53 100644 (file)
@@ -19,11 +19,11 @@ along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
 $END_LICENSE */
 
 #include "sidebarheader.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "mediaview.h"
 #include "videosource.h"
 #include "fontutils.h"
-#include "utils.h"
+#include "iconutils.h"
 
 SidebarHeader::SidebarHeader(QWidget *parent) : QToolBar(parent) { }
 
@@ -35,14 +35,14 @@ void SidebarHeader::setup() {
     setIconSize(QSize(16, 16));
 
     backAction = new QAction(
-                Utils::icon("go-previous"),
+                IconUtils::icon("go-previous"),
                 tr("&Back"), this);
     backAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Left));
     connect(backAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goBack()));
     addAction(backAction);
 
     forwardAction = new QAction(
-                Utils::icon("go-next"),
+                IconUtils::icon("go-next"),
                 tr("&Back"), this);
     forwardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Right));
     connect(forwardAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goForward()));
@@ -50,7 +50,7 @@ void SidebarHeader::setup() {
 
     foreach (QAction* action, actions()) {
         window()->addAction(action);
-        Utils::setupAction(action);
+        IconUtils::setupAction(action);
     }
 
     QWidget *spacerWidget = new QWidget(this);
index 68b22c6e1854bc828b7c1460ff63c212183c9147..58f7a021031b0651142da1c174f8b0f7bdbe64e0 100644 (file)
@@ -24,7 +24,6 @@ $END_LICENSE */
 #include "networkaccess.h"
 #include "searchparams.h"
 #include "video.h"
-#include "utils.h"
 #include "ytuser.h"
 
 namespace The {