Added context menu for feeds.

This commit is contained in:
Martin Rotter 2013-12-28 14:23:49 +01:00
parent 0e83739327
commit 10c0c67105
3 changed files with 41 additions and 2 deletions

View File

@ -5,12 +5,14 @@
#include "core/feedsmodel.h" #include "core/feedsmodel.h"
#include "core/feedsproxymodel.h" #include "core/feedsproxymodel.h"
#include "core/feedsmodelrootitem.h" #include "core/feedsmodelrootitem.h"
#include "gui/formmain.h"
#include <QMenu>
#include <QHeaderView> #include <QHeaderView>
#include <QContextMenuEvent>
FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) { FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenu(NULL) {
m_proxyModel = new FeedsProxyModel(this); m_proxyModel = new FeedsProxyModel(this);
m_sourceModel = m_proxyModel->sourceModel(); m_sourceModel = m_proxyModel->sourceModel();
@ -82,6 +84,14 @@ void FeedsView::updateCountsOfAllFeeds(bool update_total_too) {
m_sourceModel->reloadWholeLayout(); m_sourceModel->reloadWholeLayout();
} }
void FeedsView::initializeContextMenu() {
m_contextMenu = new QMenu(tr("Context menu for feeds"), this);
m_contextMenu->addActions(QList<QAction*>() <<
FormMain::getInstance()->m_ui->m_actionUpdateSelectedFeeds <<
FormMain::getInstance()->m_ui->m_actionMarkFeedsAsRead <<
FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread);
}
void FeedsView::setupAppearance() { void FeedsView::setupAppearance() {
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
// Setup column resize strategies. // Setup column resize strategies.
@ -121,3 +131,20 @@ void FeedsView::selectionChanged(const QItemSelection &selected,
emit feedsSelected(m_selectedFeeds); 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());
}

View File

@ -40,17 +40,28 @@ class FeedsView : public QTreeView {
void updateCountsOfAllFeeds(bool update_total_too = true); void updateCountsOfAllFeeds(bool update_total_too = true);
protected: protected:
void initializeContextMenu();
// Sets up appearance of this widget. // Sets up appearance of this widget.
void setupAppearance(); void setupAppearance();
// Make feeds loadable.
void selectionChanged(const QItemSelection &selected, void selectionChanged(const QItemSelection &selected,
const QItemSelection &deselected); const QItemSelection &deselected);
// Show custom context menu.
void contextMenuEvent(QContextMenuEvent *event);
signals: signals:
// Emitted if currently selected feeds needs to be reloaded.
void feedsNeedToBeReloaded(int mark_current_index_read); void feedsNeedToBeReloaded(int mark_current_index_read);
// Emitted if user selects new feeds.
void feedsSelected(const QList<int> &feed_ids); void feedsSelected(const QList<int> &feed_ids);
private: private:
QMenu *m_contextMenu;
QList<int> m_selectedFeeds; QList<int> m_selectedFeeds;
FeedsModel *m_sourceModel; FeedsModel *m_sourceModel;
FeedsProxyModel *m_proxyModel; FeedsProxyModel *m_proxyModel;

View File

@ -13,6 +13,7 @@ class FormMain : public QMainWindow {
friend class TabWidget; friend class TabWidget;
friend class FeedMessageViewer; friend class FeedMessageViewer;
friend class MessagesView; friend class MessagesView;
friend class FeedsView;
public: public:
// Constructors and destructors. // Constructors and destructors.