diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 38ebd2ed1..f01be4763 100755 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -2,6 +2,7 @@ ————— Added: +▪ Columns in message list can be hidden/shown/reordered with context menu. (issue #115) ▪ Auto-update notification is now switchable. (issue #119) ▪ Messages which are not removed or restored are not instantly deleted from list, they are striked-through instead. This is more resource friendly. ▪ Message list is now not reloaded when doing batch message operations. diff --git a/rssguard.pro b/rssguard.pro index 42fb779a1..a1eba76e2 100755 --- a/rssguard.pro +++ b/rssguard.pro @@ -331,7 +331,8 @@ HEADERS += src/core/feeddownloader.h \ src/services/tt-rss/gui/formeditttrssaccount.h \ src/gui/guiutilities.h \ src/core/messagesmodelcache.h \ - src/core/messagesmodelsqllayer.h + src/core/messagesmodelsqllayer.h \ + src/gui/treeviewcolumnsmenu.h SOURCES += src/core/feeddownloader.cpp \ src/core/feedsmodel.cpp \ @@ -454,7 +455,8 @@ SOURCES += src/core/feeddownloader.cpp \ src/services/tt-rss/gui/formeditttrssaccount.cpp \ src/gui/guiutilities.cpp \ src/core/messagesmodelcache.cpp \ - src/core/messagesmodelsqllayer.cpp + src/core/messagesmodelsqllayer.cpp \ + src/gui/treeviewcolumnsmenu.cpp FORMS += src/gui/toolbareditor.ui \ src/network-web/downloaditem.ui \ diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 93f0e9840..59ca50a09 100755 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -25,7 +25,7 @@ #include "network-web/webfactory.h" #include "gui/dialogs/formmain.h" #include "gui/messagebox.h" - +#include "gui/treeviewcolumnsmenu.h" #include "gui/styleditemdelegatewithoutfocus.h" #include @@ -43,6 +43,12 @@ MessagesView::MessagesView(QWidget *parent) createConnections(); setModel(m_proxyModel); setupAppearance(); + + header()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(header(), &QHeaderView::customContextMenuRequested, [=](const QPoint &point) { + TreeViewColumnsMenu mm(header()); + mm.exec(header()->mapToGlobal(point)); + }); } MessagesView::~MessagesView() { diff --git a/src/gui/treeviewcolumnsmenu.cpp b/src/gui/treeviewcolumnsmenu.cpp new file mode 100755 index 000000000..dcecc5ca2 --- /dev/null +++ b/src/gui/treeviewcolumnsmenu.cpp @@ -0,0 +1,52 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// RSS Guard 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. +// +// RSS Guard 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 RSS Guard. If not, see . + +#include "gui/treeviewcolumnsmenu.h" + +#include + + +TreeViewColumnsMenu::TreeViewColumnsMenu(QHeaderView *parent) : QMenu(parent) { + connect(this, &TreeViewColumnsMenu::aboutToShow, this, &TreeViewColumnsMenu::prepareMenu); +} + +TreeViewColumnsMenu::~TreeViewColumnsMenu() { +} + +void TreeViewColumnsMenu::prepareMenu() { + QHeaderView *header_view = header(); + + for (int i = 0; i < header_view->count(); i++) { + QAction *act = addAction(header_view->model()->headerData(i, Qt::Horizontal, Qt::EditRole).toString()); + + act->setData(i); + act->setCheckable(true); + act->setChecked(!header_view->isSectionHidden(i)); + + connect(act, &QAction::toggled, this, &TreeViewColumnsMenu::actionTriggered); + } +} + +void TreeViewColumnsMenu::actionTriggered(bool toggle) { + QAction *send_act = qobject_cast(sender()); + + header()->setSectionHidden(send_act->data().toInt(), !send_act->isChecked()); +} + +QHeaderView *TreeViewColumnsMenu::header() { + return qobject_cast(parent()); +} diff --git a/src/gui/treeviewcolumnsmenu.h b/src/gui/treeviewcolumnsmenu.h new file mode 100755 index 000000000..700ea2554 --- /dev/null +++ b/src/gui/treeviewcolumnsmenu.h @@ -0,0 +1,39 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// RSS Guard 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. +// +// RSS Guard 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 RSS Guard. If not, see . + +#ifndef TREEVIEWCOLUMNSMENU_H +#define TREEVIEWCOLUMNSMENU_H + +#include + + +class QHeaderView; + +class TreeViewColumnsMenu : public QMenu { + public: + explicit TreeViewColumnsMenu(QHeaderView *parent); + virtual ~TreeViewColumnsMenu(); + + private slots: + void prepareMenu(); + void actionTriggered(bool toggle); + + private: + QHeaderView *header(); +}; + +#endif // TREEVIEWCOLUMNSMENU_H