Work on menus.

This commit is contained in:
Martin Rotter 2015-11-08 10:53:13 +01:00
parent c3384af89e
commit fa976120b8
5 changed files with 34 additions and 27 deletions

View file

@ -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<QAction*> 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);
}

View file

@ -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 {

View file

@ -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<QAction*> 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

View file

@ -32,10 +32,11 @@
#include <QSqlError>
#include <QStack>
#include <QCoreApplication>
#include <QMenu>
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<QAction*> StandardServiceRoot::specificAddItemActions() {
QList<QAction*> 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) {

View file

@ -27,6 +27,7 @@ class StandardRecycleBin;
class StandardCategory;
class StandardFeed;
class FeedsImportExportModel;
class QMenu;
typedef QList<QPair<int, StandardCategory*> > CategoryAssignment;
typedef QPair<int, StandardCategory*> CategoryAssignmentItem;
@ -65,7 +66,7 @@ class StandardServiceRoot : public ServiceRoot {
bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message);
// Return "add feed" and "add category" items.
QList<QAction*> 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