#endif
#include "fontutils.h"
-AboutView::AboutView(QWidget *parent) : QWidget(parent) {
+AboutView::AboutView(QWidget *parent) : View(parent) {
QBoxLayout *hLayout = new QHBoxLayout(this);
hLayout->setAlignment(Qt::AlignCenter);
#include "view.h"
#include "constants.h"
-class AboutView : public QWidget, public View {
+class AboutView : public View {
Q_OBJECT
--- /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 "channellistview.h"
+#include "painterutils.h"
+
+ChannelListView::ChannelListView() {
+
+ setSelectionMode(QAbstractItemView::NoSelection);
+
+ // layout
+ setSpacing(15);
+ setFlow(QListView::LeftToRight);
+ setWrapping(true);
+ setResizeMode(QListView::Adjust);
+ setMovement(QListView::Static);
+ setUniformItemSizes(true);
+
+ // cosmetics
+ setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+ setFrameShape(QFrame::NoFrame);
+ setAttribute(Qt::WA_MacShowFocusRect, false);
+
+ QPalette p = palette();
+ /*
+ p.setColor(QPalette::Base, p.window().color());
+ p.setColor(QPalette::Text, p.windowText().color());
+ */
+ p.setColor(QPalette::Disabled, QPalette::Base, p.base().color());
+ p.setColor(QPalette::Disabled, QPalette::Text, p.text().color());
+ setPalette(p);
+
+ verticalScrollBar()->setPageStep(3);
+ verticalScrollBar()->setSingleStep(1);
+
+ setMouseTracking(true);
+
+}
+
+void ChannelListView::mousePressEvent(QMouseEvent *event) {
+ if (event->button() == Qt::RightButton)
+ emit contextMenu(event->pos());
+ else
+ QListView::mousePressEvent(event);
+}
+
+void ChannelListView::mouseMoveEvent(QMouseEvent *event) {
+ QWidget::mouseMoveEvent(event);
+ const QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) setCursor(Qt::PointingHandCursor);
+ else unsetCursor();
+}
+
+void ChannelListView::paintEvent(QPaintEvent *event) {
+ if (!errorMessage.isEmpty())
+ PainterUtils::centeredMessage(errorMessage, viewport());
+ else
+ QListView::paintEvent(event);
+}
--- /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 CHANNELLISTVIEW_H
+#define CHANNELLISTVIEW_H
+
+#include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
+
+class ChannelListView : public QListView {
+
+ Q_OBJECT
+
+public:
+ ChannelListView();
+ void setErrorMessage(const QString &value) { errorMessage = value; }
+ void clearErrorMessage() { errorMessage.clear(); }
+
+signals:
+ void contextMenu(QPoint point);
+
+protected:
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ QString errorMessage;
+
+};
+
+#endif // CHANNELLISTVIEW_H
#include "ytsearch.h"
#include "channelaggregator.h"
#include "aggregatevideosource.h"
-#include "painterutils.h"
#include "mainwindow.h"
#include "iconutils.h"
#ifdef APP_EXTRA
#include "extra.h"
#endif
+#include "channellistview.h"
static const char *sortByKey = "subscriptionsSortBy";
static const char *showUpdatedKey = "subscriptionsShowUpdated";
-ChannelView::ChannelView(QWidget *parent) : QListView(parent),
+ChannelView::ChannelView(QWidget *parent) : View(parent),
showUpdated(false),
sortBy(SortByName) {
- setItemDelegate(new ChannelItemDelegate(this));
- setSelectionMode(QAbstractItemView::NoSelection);
+ QBoxLayout *layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->setSpacing(0);
- // layout
- setSpacing(15);
- setFlow(QListView::LeftToRight);
- setWrapping(true);
- setResizeMode(QListView::Adjust);
- setMovement(QListView::Static);
- setUniformItemSizes(true);
+ listView = new ChannelListView();
+ listView->setItemDelegate(new ChannelItemDelegate(this));
- // cosmetics
- setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- setFrameShape(QFrame::NoFrame);
- setAttribute(Qt::WA_MacShowFocusRect, false);
-
- QPalette p = palette();
- /*
- p.setColor(QPalette::Base, p.window().color());
- p.setColor(QPalette::Text, p.windowText().color());
- */
- p.setColor(QPalette::Disabled, QPalette::Base, p.base().color());
- p.setColor(QPalette::Disabled, QPalette::Text, p.text().color());
- setPalette(p);
-
- verticalScrollBar()->setPageStep(3);
- verticalScrollBar()->setSingleStep(1);
-
- setMouseTracking(true);
+ channelsModel = new ChannelModel(this);
+ listView->setModel(channelsModel);
- connect(this, SIGNAL(clicked(const QModelIndex &)),
- SLOT(itemActivated(const QModelIndex &)));
- connect(this, SIGNAL(entered(const QModelIndex &)),
- SLOT(itemEntered(const QModelIndex &)));
+ connect(listView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemActivated(const QModelIndex &)));
+ connect(listView, SIGNAL(contextMenu(QPoint)), SLOT(showContextMenu(QPoint)));
+ connect(listView, SIGNAL(viewportEntered()), channelsModel, SLOT(clearHover()));
- channelsModel = new ChannelModel(this);
- setModel(channelsModel);
- connect(this, SIGNAL(viewportEntered()),
- channelsModel, SLOT(clearHover()));
+ layout->addWidget(listView);
setupActions();
MainWindow::instance()->showActionInStatusBar(action, false);
}
-void ChannelView::mousePressEvent(QMouseEvent *event) {
- if (event->button() == Qt::RightButton)
- showContextMenu(event->pos());
- else
- QListView::mousePressEvent(event);
-}
-
-void ChannelView::mouseMoveEvent(QMouseEvent *event) {
- QListView::mouseMoveEvent(event);
- const QModelIndex index = indexAt(event->pos());
- if (index.isValid()) setCursor(Qt::PointingHandCursor);
- else unsetCursor();
-}
-
-void ChannelView::leaveEvent(QEvent *event) {
- QListView::leaveEvent(event);
- // channelsModel->clearHover();
-}
-
-void ChannelView::itemEntered(const QModelIndex &) {
- // channelsModel->setHoveredRow(index.row());
-}
-
void ChannelView::itemActivated(const QModelIndex &index) {
ChannelModel::ItemTypes itemType = channelsModel->typeForIndex(index);
if (itemType == ChannelModel::ItemChannel) {
}
void ChannelView::showContextMenu(const QPoint &point) {
- const QModelIndex index = indexAt(point);
+ const QModelIndex index = listView->indexAt(point);
if (!index.isValid()) return;
YTChannel *channel = channelsModel->channelForIndex(index);
menu.exec(mapToGlobal(point));
}
-void ChannelView::paintEvent(QPaintEvent *event) {
- if (model()->rowCount() < 3) {
- QString msg;
- if (!errorMessage.isEmpty())
- msg = errorMessage;
- else if (showUpdated)
- msg = tr("There are no updated subscriptions at this time.");
- else
- msg = tr("You have no subscriptions. "
- "Use the star symbol to subscribe to channels.");
- PainterUtils::centeredMessage(msg, viewport());
- } else QListView::paintEvent(event);
- // PainterUtils::topShadow(viewport());
-}
-
void ChannelView::toggleShowUpdated(bool enable) {
showUpdated = enable;
updateQuery(true);
void ChannelView::updateQuery(bool transition) {
Q_UNUSED(transition);
- errorMessage.clear();
+ listView->clearErrorMessage();
if (!Database::exists()) return;
QString sql = "select user_id from subscriptions";
channelsModel->setQuery(sql, Database::instance().getConnection());
if (channelsModel->lastError().isValid()) {
qWarning() << channelsModel->lastError().text();
- errorMessage = channelsModel->lastError().text();
+ listView->setErrorMessage(channelsModel->lastError().text());
+ } else if (channelsModel->rowCount() < 3) {
+ QString msg;
+ if (showUpdated)
+ msg = tr("There are no updated subscriptions at this time.");
+ else
+ msg = tr("You have no subscriptions. "
+ "Use the star symbol to subscribe to channels.");
+ listView->setErrorMessage(msg);
}
}
class VideoSource;
class ChannelModel;
+class ChannelListView;
-class ChannelView : public QListView, public View {
+class ChannelView : public View {
Q_OBJECT
void appear();
void disappear();
-protected:
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void leaveEvent(QEvent *event);
- void paintEvent(QPaintEvent *event);
-
private:
enum SortBy {
SortByName = 0,
};
private slots:
- void itemEntered(const QModelIndex &index);
void itemActivated(const QModelIndex &index);
void showContextMenu(const QPoint &point);
void toggleShowUpdated(bool enable);
private:
void setupActions();
+ ChannelListView *listView;
ChannelModel *channelsModel;
QList<QAction*> statusActions;
bool showUpdated;
SortBy sortBy;
- QString errorMessage;
QAction *markAsWatchedAction;
};
}
void DownloadListView::leaveEvent(QEvent * /* event */) {
- DownloadModel *downloadModel = dynamic_cast<DownloadModel *>(model());
+ DownloadModel *downloadModel = qobject_cast<DownloadModel *>(model());
if (downloadModel) downloadModel->clearHover();
}
const QRect itemRect = visualRect(itemIndex);
// qDebug() << " itemRect.x()" << itemRect.x();
- PlaylistItemDelegate *delegate = dynamic_cast<PlaylistItemDelegate *>(itemDelegate());
+ PlaylistItemDelegate *delegate = qobject_cast<PlaylistItemDelegate *>(itemDelegate());
if (!delegate) return false;
QRect buttonRect = delegate->downloadButtonRect(itemRect);
#include "playlistitemdelegate.h"
#include "segmentedcontrol.h"
-DownloadView::DownloadView(QWidget *parent) : QWidget(parent) {
+DownloadView::DownloadView(QWidget *parent) : View(parent) {
QBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
class DownloadListView;
class DownloadSettings;
-class DownloadView : public QWidget, public View {
+class DownloadView : public View {
Q_OBJECT
#include "macutils.h"
#endif
-HomeView::HomeView(QWidget *parent) : QWidget(parent),
+HomeView::HomeView(QWidget *parent) : View(parent),
standardFeedsView(0),
channelsView(0) {
class StandardFeedsView;
class ChannelView;
-class HomeView : public QWidget, public View {
+class HomeView : public View {
Q_OBJECT
// Hack to give focus to searchlineedit
QMetaObject::invokeMethod(views->currentWidget(), "appear");
- View* view = dynamic_cast<View *> (views->currentWidget());
+ View* view = qobject_cast<View *> (views->currentWidget());
QString desc = view->metadata().value("description").toString();
if (!desc.isEmpty()) showMessage(desc);
compactViewAct->toggle();
// call hide method on the current view
- View* oldView = dynamic_cast<View *> (views->currentWidget());
+ View* oldView = qobject_cast<View *> (views->currentWidget());
if (oldView) {
oldView->disappear();
views->currentWidget()->setEnabled(false);
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// call show method on the new view
- View* newView = dynamic_cast<View *> (widget);
+ View* newView = qobject_cast<View *> (widget);
if (newView) {
widget->setEnabled(true);
QHash<QString,QVariant> metadata = newView->metadata();
return i;
}
-MediaView::MediaView(QWidget *parent) : QWidget(parent)
+MediaView::MediaView(QWidget *parent) : View(parent)
, stopped(false)
, downloadItem(0)
#ifdef APP_SNAPSHOT
SearchParams* MediaView::getSearchParams() {
VideoSource *videoSource = playlistModel->getVideoSource();
if (videoSource && videoSource->metaObject()->className() == QLatin1String("YTSearch")) {
- YTSearch *search = dynamic_cast<YTSearch *>(videoSource);
+ YTSearch *search = qobject_cast<YTSearch *>(videoSource);
return search->getSearchParams();
}
return 0;
QHash<QString, QAction*>* globalActions();
}
-class MediaView : public QWidget, public View {
+class MediaView : public View {
Q_OBJECT
static const int maxRecentElements = 10;
- YTSearch *search = dynamic_cast<YTSearch *>(videoSource);
+ YTSearch *search = qobject_cast<YTSearch *>(videoSource);
SearchParams *searchParams = search->getSearchParams();
// save keyword
else
beginRow = rowCount(QModelIndex());
- const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( data );
+ const VideoMimeData* videoMimeData = qobject_cast<const VideoMimeData*>( data );
if(!videoMimeData ) return false;
QList<Video*> droppedVideos = videoMimeData->videos();
}
void PlaylistView::itemEntered(const QModelIndex &index) {
- PlaylistModel *listModel = dynamic_cast<PlaylistModel *>(model());
+ PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
if (listModel) listModel->setHoveredRow(index.row());
}
void PlaylistView::leaveEvent(QEvent *event) {
QListView::leaveEvent(event);
- PlaylistModel *listModel = dynamic_cast<PlaylistModel *>(model());
+ PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
if (listModel) listModel->clearHover();
}
} else if (isHoveringAuthor(event)) {
emit authorPushed(index);
} else if (isShowMoreItem(index)) {
- PlaylistModel *listModel = dynamic_cast<PlaylistModel *>(model());
+ PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
listModel->searchMore();
unsetCursor();
}
const QRect itemRect = visualRect(itemIndex);
// qDebug() << " itemRect.x()" << itemRect.x();
- PlaylistItemDelegate *delegate = dynamic_cast<PlaylistItemDelegate *>(itemDelegate());
+ PlaylistItemDelegate *delegate = qobject_cast<PlaylistItemDelegate *>(itemDelegate());
if (!delegate) return false;
QRect rect = delegate->authorRect(itemIndex);
#include "ytregions.h"
#include "mainwindow.h"
-RegionsView::RegionsView(QWidget *parent) : QWidget(parent) {
+RegionsView::RegionsView(QWidget *parent) : View(parent) {
QBoxLayout *l = new QVBoxLayout(this);
l->setMargin(30);
l->setSpacing(30);
struct YTRegion;
-class RegionsView : public QWidget, public View {
+class RegionsView : public View {
Q_OBJECT
void emitTextChanged(const QString &text);
QString text();
QLineEdit *getLineEdit();
+ QWidget *toWidget() { return qobject_cast<QWidget*>(this); }
public slots:
void returnPressed();
static const QString recentChannelsKey = "recentChannels";
static const int PADDING = 30;
-SearchView::SearchView(QWidget *parent) : QWidget(parent) {
+SearchView::SearchView(QWidget *parent) : View(parent) {
#if defined(APP_MAC) | defined(APP_WIN)
// speedup painting since we'll paint the whole background
class ChannelSuggest;
class Suggestion;
-class SearchView : public QWidget, public View {
+class SearchView : public View {
Q_OBJECT
virtual void returnPressed() = 0;
virtual QString text() = 0;
virtual QLineEdit *getLineEdit() = 0;
-
- QWidget *toWidget() {
- return dynamic_cast<QWidget*>(this);
- }
+ virtual QWidget *toWidget() = 0;
signals:
void textChanged(const QString &text);
QHash<QString, QAction*>* globalActions();
}
-StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent),
+StandardFeedsView::StandardFeedsView(QWidget *parent) : View(parent),
layout(0) {
QPalette p = palette();
p.setBrush(QPalette::Window, Qt::black);
struct YTCategory;
class YTStandardFeed;
-class StandardFeedsView : public QWidget, public View {
+class StandardFeedsView : public View {
Q_OBJECT
void VideoAreaWidget::dropEvent(QDropEvent *event) {
- const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
+ const VideoMimeData* videoMimeData = qobject_cast<const VideoMimeData*>( event->mimeData() );
if(!videoMimeData ) return;
QList<Video*> droppedVideos = videoMimeData->videos();
class VideoMimeData : public QMimeData {
+ Q_OBJECT
+
public:
VideoMimeData();
#ifndef VIEW_H
#define VIEW_H
-class View {
+#include <QWidget>
+#include <QHash>
+#include <QString>
+#include <QVariant>
+
+class View : public QWidget {
+
+ Q_OBJECT
public:
+ View(QWidget *parent = 0) : QWidget(parent) { }
virtual QHash<QString, QVariant> metadata() { return QHash<QString, QVariant>(); }
virtual void appear() {}
virtual void disappear() {}