From fa976120b864bc96902050843d0bd7a3bc7ca96f Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 8 Nov 2015 10:53:13 +0100 Subject: [PATCH] Work on menus. --- src/gui/dialogs/formmain.cpp | 20 ++++++------------ src/gui/feedsview.cpp | 3 ++- src/services/abstract/serviceroot.h | 11 +++++----- src/services/standard/standardserviceroot.cpp | 21 +++++++++++++------ src/services/standard/standardserviceroot.h | 6 +++++- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index e9382209a..52aac9651 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -173,31 +173,23 @@ void FormMain::switchMainMenu() { } 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. + // NOTE: Clear here deletes items from memory but only those OWNED by the menu. 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 root_actions = activated_root->specificAddItemActions(); + QMenu *root_menu = activated_root->addItemMenu(); - root_menu->setIcon(activated_root->icon()); - root_menu->setToolTip(activated_root->description()); + if (root_menu == NULL) { + root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem); + 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); } diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index d3ba8f629..3696162ef 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -622,7 +622,8 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) { m_contextMenuFeeds->exec(event->globalPos()); } else { - + // TODO: volaz specificke menu polozky? zobrazovat menu pro dalsi typy + // polozek jako odpadkovy kos atp. } } else { diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index ebcc8a11a..242c4a99d 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -22,6 +22,7 @@ class FeedsModel; +class QMenu; // THIS IS the root node of the service. // NOTE: The root usually contains some core functionality of the @@ -38,17 +39,17 @@ class ServiceRoot : public RootItem { // a) Add new feed // b) Add new category // c) ... - // NOTE: This method should always create new actions in memory - // before returning them because caller takes ownership of any - // actions returned from here. - virtual QList specificAddItemActions() = 0; + // NOTE: Caller does NOT take ownership of created menu! + virtual QMenu* addItemMenu() = 0; + + // TODO: dodělat menu, které se zobrazi v menubaru "Services -> tato služba". inline FeedsModel *feedsModel() const { return m_feedsModel; } protected: - FeedsModel *m_feedsModel; + FeedsModel *m_feedsModel; }; #endif // SERVICEROOT_H diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index c028dadf3..b480a713d 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -32,10 +32,11 @@ #include #include #include +#include StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent) - : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) { + : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)), m_addItemMenu(NULL) { m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME); m_icon = StandardServiceEntryPoint().icon(); m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."); @@ -47,6 +48,9 @@ StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_mo } StandardServiceRoot::~StandardServiceRoot() { + if (m_addItemMenu != NULL) { + delete m_addItemMenu; + } } bool StandardServiceRoot::canBeEdited() { @@ -324,12 +328,17 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, return !some_feed_category_error; } -QList StandardServiceRoot::specificAddItemActions() { - QList actions; +QMenu *StandardServiceRoot::addItemMenu() { + if (m_addItemMenu == NULL) { + m_addItemMenu = new QMenu(title(), NULL); + m_addItemMenu->setIcon(icon()); + m_addItemMenu->setToolTip(description()); - // TODO: vracet add feed, add category - actions.append(new QAction("abc", NULL)); - return actions; + // TODO: Add items. + m_addItemMenu->addAction(new QAction("abc", m_addItemMenu)); + } + + return m_addItemMenu; } void StandardServiceRoot::assembleCategories(CategoryAssignment categories) { diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 60409ea29..598d552be 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -27,6 +27,7 @@ class StandardRecycleBin; class StandardCategory; class StandardFeed; class FeedsImportExportModel; +class QMenu; typedef QList > CategoryAssignment; typedef QPair CategoryAssignmentItem; @@ -65,7 +66,7 @@ class StandardServiceRoot : public ServiceRoot { bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message); // Return "add feed" and "add category" items. - QList specificAddItemActions(); + QMenu *addItemMenu(); private: void loadFromDatabase(); @@ -76,6 +77,9 @@ class StandardServiceRoot : public ServiceRoot { void assembleFeeds(FeedAssignment feeds); StandardRecycleBin *m_recycleBin; + + // Menus. + QMenu *m_addItemMenu; }; #endif // STANDARDSERVICEROOT_H