From 2add28c5ef486373ef41e6a98fbcd91a5730bc7e Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Thu, 13 Aug 2009 19:18:20 +0200 Subject: [PATCH] Removed THAction class, use plain QAction --- src/MediaView.cpp | 7 +-- src/MediaView.h | 7 ++- src/thlibrary/thblackbar.cpp | 35 +++++++-------- src/thlibrary/thblackbar.h | 85 ++++++++++++++++++------------------ src/thlibrary/thlibrary.pri | 9 +--- 5 files changed, 70 insertions(+), 73 deletions(-) diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 9825010..cee7f62 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -19,13 +19,13 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { splitter->setChildrenCollapsible(false); sortBar = new THBlackBar(this); - mostRelevantAction = new THAction(tr("Most relevant"), this); + mostRelevantAction = new QAction(tr("Most relevant"), this); connect(mostRelevantAction, SIGNAL(triggered()), this, SLOT(searchMostRelevant()), Qt::QueuedConnection); sortBar->addAction(mostRelevantAction); - mostRecentAction = new THAction(tr("Most recent"), this); + mostRecentAction = new QAction(tr("Most recent"), this); connect(mostRecentAction, SIGNAL(triggered()), this, SLOT(searchMostRecent()), Qt::QueuedConnection); sortBar->addAction(mostRecentAction); - mostViewedAction = new THAction(tr("Most viewed"), this); + mostViewedAction = new QAction(tr("Most viewed"), this); connect(mostViewedAction, SIGNAL(triggered()), this, SLOT(searchMostViewed()), Qt::QueuedConnection); sortBar->addAction(mostViewedAction); @@ -129,6 +129,7 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) case Phonon::ErrorState: qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType(); + videoAreaWidget->showError(mediaObject->errorString()); // recover from errors by skipping to the next video skip(); break; diff --git a/src/MediaView.h b/src/MediaView.h index a4a8996..3ef1bf8 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -7,7 +7,6 @@ #include #include "View.h" #include "ListModel.h" -#include "thaction.h" #include "thblackbar.h" #include "searchparams.h" #include "playlistwidget.h" @@ -78,9 +77,9 @@ private: // sortBar THBlackBar *sortBar; - THAction *mostRelevantAction; - THAction *mostRecentAction; - THAction *mostViewedAction; + QAction *mostRelevantAction; + QAction *mostRecentAction; + QAction *mostViewedAction; // phonon Phonon::MediaObject *mediaObject; diff --git a/src/thlibrary/thblackbar.cpp b/src/thlibrary/thblackbar.cpp index d2f3348..d2bbc65 100644 --- a/src/thlibrary/thblackbar.cpp +++ b/src/thlibrary/thblackbar.cpp @@ -3,16 +3,15 @@ #include #include "thblackbar.h" -#include "thaction.h" /* ============================================================================ * PRIVATE Class */ class THBlackBar::Private { public: - QList actionList; - THAction *checkedAction; - THAction *hoveredAction; + QList actionList; + QAction *checkedAction; + QAction *hoveredAction; }; /* ============================================================================ @@ -36,13 +35,14 @@ THBlackBar::~THBlackBar() { /* ============================================================================ * PUBLIC Methods */ -THAction *THBlackBar::addAction (THAction *action) { +QAction *THBlackBar::addAction (QAction *action) { + action->setCheckable(true); d->actionList.append(action); return(action); } -THAction *THBlackBar::addAction (const QString& text) { - THAction *action = new THAction(text, this); +QAction *THBlackBar::addAction (const QString& text) { + QAction *action = new QAction(text, this); d->actionList.append(action); return(action); } @@ -92,7 +92,7 @@ void THBlackBar::paintEvent (QPaintEvent *event) { // Draw Buttons // p.translate(0, 4); QRect rect(buttonsX, 0, buttonWidth, height); - foreach (THAction *action, d->actionList) { + foreach (QAction *action, d->actionList) { drawButton(&p, rect, action); rect.moveLeft(rect.x() + rect.width()); } @@ -107,14 +107,15 @@ void THBlackBar::paintEvent (QPaintEvent *event) { void THBlackBar::mouseMoveEvent (QMouseEvent *event) { QWidget::mouseMoveEvent(event); - THAction *action = hoveredAction(event->pos()); + QAction *action = hoveredAction(event->pos()); + if (action == NULL && d->hoveredAction != NULL) { - d->hoveredAction->hover(false); + // d->hoveredAction->hover(false); d->hoveredAction = NULL; update(); } else if (action != NULL) { d->hoveredAction = action; - action->hover(true); + action->hover(); update(); } } @@ -138,7 +139,7 @@ void THBlackBar::mousePressEvent (QMouseEvent *event) { } } -THAction *THBlackBar::hoveredAction (const QPoint& pos) const { +QAction *THBlackBar::hoveredAction (const QPoint& pos) const { if (pos.y() <= 0 || pos.y() >= height()) return(NULL); @@ -168,7 +169,7 @@ int THBlackBar::calculateButtonWidth (void) const { smallerBoldFont.setPointSize(smallerBoldFont.pointSize()*.85); QFontMetrics fontMetrics(smallerBoldFont); int tmpItemWidth, itemWidth = 0; - foreach (THAction *action, d->actionList) { + foreach (QAction *action, d->actionList) { tmpItemWidth = fontMetrics.width(action->text()); if (itemWidth < tmpItemWidth) itemWidth = tmpItemWidth; } @@ -181,7 +182,7 @@ int THBlackBar::calculateButtonWidth (void) const { */ void THBlackBar::drawUnselectedButton ( QPainter *painter, const QRect& rect, - const THAction *action) + const QAction *action) { QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, rect.height() / 2)); linearGrad.setColorAt(0, QColor(0x8e, 0x8e, 0x8e)); @@ -197,7 +198,7 @@ void THBlackBar::drawUnselectedButton ( QPainter *painter, void THBlackBar::drawSelectedButton ( QPainter *painter, const QRect& rect, - const THAction *action) + const QAction *action) { QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, rect.height() / 2)); linearGrad.setColorAt(0, QColor(0x6d, 0x6d, 0x6d)); @@ -207,7 +208,7 @@ void THBlackBar::drawSelectedButton ( QPainter *painter, void THBlackBar::drawButton ( QPainter *painter, const QRect& rect, - const THAction *action) + const QAction *action) { if (action->isChecked()) drawSelectedButton(painter, rect, action); @@ -219,7 +220,7 @@ void THBlackBar::drawButton ( QPainter *painter, const QRect& rect, const QLinearGradient& gradient, const QColor& color, - const THAction *action) + const QAction *action) { painter->save(); diff --git a/src/thlibrary/thblackbar.h b/src/thlibrary/thblackbar.h index 73e4739..ec0ff11 100644 --- a/src/thlibrary/thblackbar.h +++ b/src/thlibrary/thblackbar.h @@ -2,50 +2,51 @@ #define _THBLACKBAR_H_ #include -class THAction; +#include class THBlackBar : public QWidget { - Q_OBJECT - - public: - THBlackBar (QWidget *parent = 0); - ~THBlackBar(); - - public: - THAction *addAction (THAction *action); - THAction *addAction (const QString& text); - void setCheckedAction(int index); - - QSize minimumSizeHint (void) const; - - protected: - void paintEvent (QPaintEvent *event); - - void mouseMoveEvent (QMouseEvent *event); - void mousePressEvent (QMouseEvent *event); - - private: - void drawUnselectedButton ( QPainter *painter, - const QRect& rect, - const THAction *action); - void drawSelectedButton ( QPainter *painter, - const QRect& rect, - const THAction *action); - void drawButton ( QPainter *painter, - const QRect& rect, - const THAction *action); - void drawButton ( QPainter *painter, - const QRect& rect, - const QLinearGradient& gradient, - const QColor& color, - const THAction *action); - - THAction *hoveredAction (const QPoint& pos) const; - int calculateButtonWidth (void) const; - - private: - class Private; - Private *d; + + Q_OBJECT + + public: + THBlackBar (QWidget *parent = 0); + ~THBlackBar(); + + public: + QAction *addAction (QAction *action); + QAction *addAction (const QString& text); + void setCheckedAction(int index); + + QSize minimumSizeHint (void) const; + + protected: + void paintEvent (QPaintEvent *event); + + void mouseMoveEvent (QMouseEvent *event); + void mousePressEvent (QMouseEvent *event); + + private: + void drawUnselectedButton ( QPainter *painter, + const QRect& rect, + const QAction *action); + void drawSelectedButton ( QPainter *painter, + const QRect& rect, + const QAction *action); + void drawButton ( QPainter *painter, + const QRect& rect, + const QAction *action); + void drawButton ( QPainter *painter, + const QRect& rect, + const QLinearGradient& gradient, + const QColor& color, + const QAction *action); + + QAction *hoveredAction (const QPoint& pos) const; + int calculateButtonWidth (void) const; + + private: + class Private; + Private *d; }; #endif /* !_THBLACKBAR_H_ */ diff --git a/src/thlibrary/thlibrary.pri b/src/thlibrary/thlibrary.pri index 9d80992..e87b1c3 100644 --- a/src/thlibrary/thlibrary.pri +++ b/src/thlibrary/thlibrary.pri @@ -1,9 +1,4 @@ DEPENDPATH += $$PWD INCLUDEPATH += $$PWD - -HEADERS += thaction.h \ - thactiongroup.h \ - thblackbar.h -SOURCES += thaction.cpp \ - thactiongroup.cpp \ - thblackbar.cpp +HEADERS += thblackbar.h +SOURCES += thblackbar.cpp -- 2.39.5