From: Flavio Tordini Date: Thu, 16 Oct 2014 07:27:20 +0000 (+0200) Subject: Renamed Utils to IconUtils X-Git-Tag: 2.3~7 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8b58ae3581d341a88ffc2dc639fbfa3e091de7c1;p=minitube Renamed Utils to IconUtils --- diff --git a/minitube.pro b/minitube.pro index 23de691..effa02e 100644 --- a/minitube.pro +++ b/minitube.pro @@ -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 \ diff --git a/src/channelview.cpp b/src/channelview.cpp index f5cb3ac..af5cb01 100644 --- a/src/channelview.cpp +++ b/src/channelview.cpp @@ -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); } } diff --git a/src/homeview.cpp b/src/homeview.cpp index a3b5435..1d56c26 100644 --- a/src/homeview.cpp +++ b/src/homeview.cpp @@ -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 index 0000000..75ded53 --- /dev/null +++ b/src/iconutils.cpp @@ -0,0 +1,111 @@ +/* $BEGIN_LICENSE + +This file is part of Minitube. +Copyright 2009, Flavio Tordini + +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 . + +$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 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() << 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 index 0000000..398fc4c --- /dev/null +++ b/src/iconutils.h @@ -0,0 +1,45 @@ +/* $BEGIN_LICENSE + +This file is part of Minitube. +Copyright 2009, Flavio Tordini + +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 . + +$END_LICENSE */ + +#ifndef ICONUTILS_H +#define ICONUTILS_H + +#include + +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 sizes = QList()); + 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 diff --git a/src/main.cpp b/src/main.cpp index a1232c9..1fab51c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d7093d6..1602b9a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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 *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(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(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(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 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(16, 16))); #else - definitionAct->setIcon(Utils::icon("video-display")); + definitionAct->setIcon(IconUtils::icon("video-display")); #endif definitionAct->setShortcuts(QList() << 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(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")); } } diff --git a/src/mediaview.cpp b/src/mediaview.cpp index 7b62b1e..1f70318 100644 --- a/src/mediaview.cpp +++ b/src/mediaview.cpp @@ -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 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() { diff --git a/src/playlistitemdelegate.cpp b/src/playlistitemdelegate.cpp index f0de4b4..81bdae4 100644 --- a/src/playlistitemdelegate.cpp +++ b/src/playlistitemdelegate.cpp @@ -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(); } diff --git a/src/searchlineedit.cpp b/src/searchlineedit.cpp index 20b50d2..1d04f68 100644 --- a/src/searchlineedit.cpp +++ b/src/searchlineedit.cpp @@ -7,44 +7,54 @@ #include #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(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) { diff --git a/src/searchlineedit.h b/src/searchlineedit.h index 5f9fd85..64b0d28 100644 --- a/src/searchlineedit.h +++ b/src/searchlineedit.h @@ -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 diff --git a/src/sidebarheader.cpp b/src/sidebarheader.cpp index dc8026e..8399a96 100644 --- a/src/sidebarheader.cpp +++ b/src/sidebarheader.cpp @@ -19,11 +19,11 @@ along with Minitube. If not, see . $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); diff --git a/src/ytsearch.cpp b/src/ytsearch.cpp index 68b22c6..58f7a02 100644 --- a/src/ytsearch.cpp +++ b/src/ytsearch.cpp @@ -24,7 +24,6 @@ $END_LICENSE */ #include "networkaccess.h" #include "searchparams.h" #include "video.h" -#include "utils.h" #include "ytuser.h" namespace The {