From 10c0c671056e6f026f5c64153578e2f62483edb0 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 28 Dec 2013 14:23:49 +0100 Subject: [PATCH] Added context menu for feeds. --- src/gui/feedsview.cpp | 31 +++++++++++++++++++++++++++++-- src/gui/feedsview.h | 11 +++++++++++ src/gui/formmain.h | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 358359e50..a433555d3 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -5,12 +5,14 @@ #include "core/feedsmodel.h" #include "core/feedsproxymodel.h" #include "core/feedsmodelrootitem.h" +#include "gui/formmain.h" - +#include #include +#include -FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) { +FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenu(NULL) { m_proxyModel = new FeedsProxyModel(this); m_sourceModel = m_proxyModel->sourceModel(); @@ -82,6 +84,14 @@ void FeedsView::updateCountsOfAllFeeds(bool update_total_too) { m_sourceModel->reloadWholeLayout(); } +void FeedsView::initializeContextMenu() { + m_contextMenu = new QMenu(tr("Context menu for feeds"), this); + m_contextMenu->addActions(QList() << + FormMain::getInstance()->m_ui->m_actionUpdateSelectedFeeds << + FormMain::getInstance()->m_ui->m_actionMarkFeedsAsRead << + FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread); +} + void FeedsView::setupAppearance() { #if QT_VERSION >= 0x050000 // Setup column resize strategies. @@ -121,3 +131,20 @@ void FeedsView::selectionChanged(const QItemSelection &selected, emit feedsSelected(m_selectedFeeds); } + +void FeedsView::contextMenuEvent(QContextMenuEvent *event) { + QModelIndex clicked_index = indexAt(event->pos()); + + if (!clicked_index.isValid()) { + qDebug("Context menu for FeedsView will not be shown because " + "user clicked on invalid item."); + return; + } + + if (m_contextMenu == NULL) { + // Context menu is not initialized, initialize. + initializeContextMenu(); + } + + m_contextMenu->exec(event->globalPos()); +} diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index e757daf98..37367ae85 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -40,17 +40,28 @@ class FeedsView : public QTreeView { void updateCountsOfAllFeeds(bool update_total_too = true); protected: + void initializeContextMenu(); + // Sets up appearance of this widget. void setupAppearance(); + // Make feeds loadable. void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + // Show custom context menu. + void contextMenuEvent(QContextMenuEvent *event); + signals: + // Emitted if currently selected feeds needs to be reloaded. void feedsNeedToBeReloaded(int mark_current_index_read); + + // Emitted if user selects new feeds. void feedsSelected(const QList &feed_ids); private: + QMenu *m_contextMenu; + QList m_selectedFeeds; FeedsModel *m_sourceModel; FeedsProxyModel *m_proxyModel; diff --git a/src/gui/formmain.h b/src/gui/formmain.h index 4222faed8..d3a201a98 100644 --- a/src/gui/formmain.h +++ b/src/gui/formmain.h @@ -13,6 +13,7 @@ class FormMain : public QMainWindow { friend class TabWidget; friend class FeedMessageViewer; friend class MessagesView; + friend class FeedsView; public: // Constructors and destructors.