Some work on "add item" interface menus.

This commit is contained in:
Martin Rotter 2015-11-06 12:47:12 +01:00
parent 779f42f5dd
commit c3384af89e
7 changed files with 56 additions and 7 deletions

View File

@ -63,8 +63,6 @@ FeedsModel::FeedsModel(QObject *parent)
connect(m_autoUpdateTimer, SIGNAL(timeout()), this, SLOT(executeNextAutoUpdate()));
loadActivatedServiceAccounts();
// Setup the timer.
updateAutoUpdateStatus();
}

View File

@ -39,6 +39,7 @@
#include "gui/dialogs/formbackupdatabasesettings.h"
#include "gui/dialogs/formrestoredatabasesettings.h"
#include "gui/notifications/notification.h"
#include "services/abstract/serviceroot.h"
#include "services/standard/gui/formstandardimportexport.h"
#include <QCloseEvent>
@ -171,6 +172,37 @@ void FormMain::switchMainMenu() {
m_ui->m_menuBar->setVisible(m_ui->m_actionSwitchMainMenu->isChecked());
}
void FormMain::updateAddItemMenu() {
// TODO: clear nevymaže z paměti. - edit, stačí nastavit parent na to menu
// a při clear to i vymaže z paměti.
m_ui->m_menuAddItem->clear();
foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) {
QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem);
QList<QAction*> root_actions = activated_root->specificAddItemActions();
root_menu->setIcon(activated_root->icon());
root_menu->setToolTip(activated_root->description());
if (root_actions.isEmpty()) {
QAction *no_action = new QAction(qApp->icons()->fromTheme(QSL("dialog-error")),
tr("No possible actions"),
m_ui->m_menuAddItem);
no_action->setEnabled(false);
root_menu->addAction(no_action);
}
else {
foreach (QAction *action, root_actions) {
action->setParent(root_menu);
}
root_menu->addActions(root_actions);
}
m_ui->m_menuAddItem->addMenu(root_menu);
}
}
void FormMain::switchVisibility(bool force_hide) {
if (force_hide || isVisible()) {
if (SystemTrayIcon::isSystemTrayActivated()) {
@ -335,6 +367,8 @@ void FormMain::createConnections() {
connect(m_statusBar->fullscreenSwitcher(), SIGNAL(toggled(bool)), m_ui->m_actionFullscreen, SLOT(setChecked(bool)));
connect(m_ui->m_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool)));
connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu()));
// Menu "File" connections.
connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds()));
connect(m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds()));
@ -395,7 +429,6 @@ void FormMain::loadWebBrowserMenu(int index) {
}
void FormMain::exportFeeds() {
// TODO: crash
QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
this);
form.data()->setMode(FeedsImportExportModel::Export);
@ -404,7 +437,6 @@ void FormMain::exportFeeds() {
}
void FormMain::importFeeds() {
// TODO: crash
QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
this);
form.data()->setMode(FeedsImportExportModel::Import);

View File

@ -78,6 +78,8 @@ class FormMain : public QMainWindow {
void switchMainMenu();
private slots:
void updateAddItemMenu();
// Loads web browser menu if user selects to change tabs.
void loadWebBrowserMenu(int index);

View File

@ -488,6 +488,9 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
m_contextMenuCategories = new QMenu(tr("Context menu for categories"), this);
}
else {
// TODO: clear nevymaže z paměti.
// http://doc.qt.io/qt-4.8/qmenu.html#clear
m_contextMenuCategories->clear();
}
@ -503,6 +506,11 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
if (!specific_actions.isEmpty()) {
m_contextMenuCategories->addSeparator();
foreach (QAction *action, specific_actions) {
action->setParent(m_contextMenuCategories);
}
m_contextMenuCategories->addActions(specific_actions);
}
}
@ -514,6 +522,8 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) {
else {
// FIXME: Položky jsou mazány při opětovném otevření kontextového nabíky ale je lepší je mazat
// hned při zavření kontextove nabíky.
// TODO: clear nevymaže z paměti.
m_contextMenuFeeds->clear();
}
@ -529,6 +539,11 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) {
if (!specific_actions.isEmpty()) {
m_contextMenuFeeds->addSeparator();
foreach (QAction *action, specific_actions) {
action->setParent(m_contextMenuFeeds);
}
m_contextMenuFeeds->addActions(specific_actions);
}
}

View File

@ -100,7 +100,7 @@ int StandardFeed::countOfUnreadMessages() const {
}
QList<QAction*> StandardFeed::specificContextMenuActions() {
return serviceRoot()->getMenuForFeed(this);
return serviceRoot()->getContextMenuForFeed(this);
}
StandardServiceRoot *StandardFeed::serviceRoot() {

View File

@ -211,7 +211,7 @@ QHash<int,StandardCategory*> StandardServiceRoot::allCategories() {
return categoriesForItem(this);
}
QList<QAction*> StandardServiceRoot::getMenuForFeed(StandardFeed *feed) {
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) {
QList<QAction*> list;
// Fetch feed metadata.

View File

@ -53,7 +53,8 @@ class StandardServiceRoot : public ServiceRoot {
// consists of ID of parent item and pointer to category.
QHash<int,StandardCategory*> allCategories();
QList<QAction*> getMenuForFeed(StandardFeed *feed);
// Returns context specific menu actions for given feed.
QList<QAction*> getContextMenuForFeed(StandardFeed *feed);
// Access to standard recycle bin.
StandardRecycleBin *recycleBin() const;
@ -63,6 +64,7 @@ class StandardServiceRoot : public ServiceRoot {
// NOTE: This is used for import/export of the model.
bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message);
// Return "add feed" and "add category" items.
QList<QAction*> specificAddItemActions();
private: