src/regionsview.h \
src/ytsinglevideosource.h \
src/sidebarheader.h \
- src/utils.h \
+ src/iconutils.h \
src/diskcache.h \
src/gridwidget.h \
src/painterutils.h \
src/regionsview.cpp \
src/ytsinglevideosource.cpp \
src/sidebarheader.cpp \
- src/utils.cpp \
+ src/iconutils.cpp \
src/diskcache.cpp \
src/gridwidget.cpp \
src/painterutils.cpp \
#include "aggregatevideosource.h"
#include "painterutils.h"
#include "mainwindow.h"
-#include "utils.h"
+#include "iconutils.h"
#ifdef APP_EXTRA
#include "extra.h"
#endif
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);
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()));
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));
foreach (QAction *action, statusActions) {
window()->addAction(action);
- Utils::setupAction(action);
+ IconUtils::setupAction(action);
}
}
#include "mainwindow.h"
#include "mediaview.h"
#include "ytstandardfeed.h"
-#include "utils.h"
+#include "iconutils.h"
#include "channelaggregator.h"
#ifdef APP_MAC
#include "macutils.h"
foreach (QAction* action, bar->actions()) {
addAction(action);
- Utils::setupAction(action);
+ IconUtils::setupAction(action);
}
}
--- /dev/null
+/* $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) +
+ ")");
+}
--- /dev/null
+/* $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
#include "constants.h"
#include "mainwindow.h"
#include "searchparams.h"
-#include "utils.h"
+#include "iconutils.h"
#ifdef APP_EXTRA
#include "extra.h"
#endif
#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 };
#include "downloadview.h"
#include "spacer.h"
#include "constants.h"
-#include "utils.h"
+#include "iconutils.h"
#include "global.h"
#include "videodefinition.h"
#include "fontutils.h"
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);
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));
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
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);
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));
/*
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);
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);
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);
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);
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);
// add actions to the MainWindow so that they work
// when the menu is hidden
addAction(action);
- Utils::setupAction(action);
+ IconUtils::setupAction(action);
}
}
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);
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);
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
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"));
}
}
#include "searchparams.h"
#include "ytsinglevideosource.h"
#include "channelaggregator.h"
-#include "utils.h"
+#include "iconutils.h"
#include "ytuser.h"
#ifdef APP_SNAPSHOT
#include "snapshotsettings.h"
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() {
#include "playlistmodel.h"
#include "fontutils.h"
#include "downloaditem.h"
-#include "utils.h"
+#include "iconutils.h"
#include "videodefinition.h"
#include "video.h"
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();
}
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();
}
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();
}
#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
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) {
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);
}
/*
- 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);
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) {
/*
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);
public:
SearchLineEdit(QWidget *parent = 0);
- QString inactiveText() const;
void setInactiveText(const QString &text);
QMenu *menu() const;
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:
void returnPressed();
private:
- SearchButton *m_searchButton;
- QString m_inactiveText;
- AutoComplete *completion;
+ SearchButton *searchButton;
+ QString inactiveText;
+ AutoComplete *autoComplete;
};
#endif // SEARCHLINEEDIT_H
$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) { }
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()));
foreach (QAction* action, actions()) {
window()->addAction(action);
- Utils::setupAction(action);
+ IconUtils::setupAction(action);
}
QWidget *spacerWidget = new QWidget(this);
#include "networkaccess.h"
#include "searchparams.h"
#include "video.h"
-#include "utils.h"
#include "ytuser.h"
namespace The {