1 /* 2 * %kadu copyright begin% 3 * Copyright 2012 Wojciech Treter (juzefwt@gmail.com) 4 * Copyright 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com) 5 * Copyright 2012, 2013, 2014, 2015 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com) 6 * %kadu copyright end% 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as 10 * published by the Free Software Foundation; either version 2 of 11 * the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #pragma once 23 24 #include "exports.h" 25 26 #include <QtCore/QList> 27 #include <QtCore/QMap> 28 #include <QtCore/QPointer> 29 #include <QtWidgets/QMenu> 30 #include <injeqt/injeqt.h> 31 32 class ActionContext; 33 class ActionDescription; 34 class KaduWindowService; 35 class MenuInventory; 36 class MenuItem; 37 38 class KADUAPI KaduMenu : public QObject 39 { 40 Q_OBJECT 41 42 public: 43 enum MenuSection 44 { 45 SectionConfig, 46 SectionRecentChats, 47 SectionMiscTools, 48 SectionQuit, 49 SectionBuddies, 50 SectionOpenChat, 51 SectionBuddyListFilters, 52 SectionTools, 53 SectionHelp, 54 SectionGetInvolved, 55 SectionAbout, 56 SectionChat, 57 SectionSend, 58 SectionActionsGui, 59 SectionActions, 60 SectionView, 61 SectionManagement, 62 }; 63 64 public: 65 explicit KaduMenu(const QString &category, KaduMenu *parent = nullptr); 66 virtual ~KaduMenu(); 67 68 void attachToMenu(QMenu *menu); 69 void detachFromMenu(QMenu *menu); 70 71 bool empty() const; 72 73 KaduMenu * addAction(ActionDescription *actionDescription, KaduMenu::MenuSection section, int priority = 0); 74 KaduMenu * removeAction(ActionDescription *actionDescription); 75 void updateGuiMenuLater(); 76 void update(); 77 78 static bool lessThan(const MenuItem *a, const MenuItem *b); 79 80 QString Category; 81 QList<MenuItem *> Items; 82 bool IsSorted; 83 84 QList<QMenu *> Menus; 85 86 void sort(); 87 ActionContext * getActionContext(); 88 89 void appendTo(QMenu *menu, ActionContext *context = 0); 90 void applyTo(QMenu *menu, ActionContext *context = 0); 91 92 private: 93 QPointer<KaduWindowService> m_kaduWindowService; 94 QPointer<MenuInventory> m_menuInventory; 95 96 private slots: 97 INJEQT_SET void setKaduWindowService(KaduWindowService *kaduWindowService); 98 INJEQT_SET void setMenuInventory(MenuInventory *menuInventory); 99 100 void menuDestroyed(QObject *object); 101 102 void updateGuiMenuSlot(); 103 104 }; 105