File indexing completed on 2024-05-12 16:41:09
0001 /*********************************************************************************** 0002 Copyright (C) 2011-2012 by Holger Danielsson (holger.danielsson@versanet.de) 0003 ***********************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #ifndef USERMENUTREE_H 0015 #define USERMENUTREE_H 0016 0017 #include <QStyledItemDelegate> 0018 #include <QContextMenuEvent> 0019 #include <QPainter> 0020 #include <QTreeWidget> 0021 #include <QTreeWidgetItem> 0022 #include <QXmlStreamWriter> 0023 0024 namespace KileMenu { 0025 0026 class MenuentryDelegate : public QStyledItemDelegate { 0027 public: 0028 MenuentryDelegate(QObject *parent=0) : QStyledItemDelegate(parent) {} 0029 0030 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override; 0031 }; 0032 0033 0034 class UserMenuTree : public QTreeWidget 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 explicit UserMenuTree(QWidget *parent); 0040 ~UserMenuTree() {} 0041 0042 bool insertMenuItem(QTreeWidgetItem *current, bool below=true); 0043 bool insertSubmenu(QTreeWidgetItem *current, bool below=true); 0044 bool insertSeparator(QTreeWidgetItem *current, bool below=true); 0045 0046 void itemDelete(QTreeWidgetItem *current); 0047 void itemUp(); 0048 void itemDown(); 0049 void contextMenuRequested(const QPoint &pos); 0050 0051 bool readXml(const QString &filename); 0052 bool writeXml(const QString &filename); 0053 bool errorCheck(); 0054 bool isItemExecutable(const QString &filename); 0055 0056 bool isEmpty(); 0057 0058 private: 0059 UserMenuItem *m_popupItem; 0060 0061 void setErrorCodes(); 0062 bool checkSubmenuError(UserMenuItem *item); 0063 0064 QStringList m_envPathlist; 0065 void initEnvPathlist(); 0066 0067 void insertMenuItemAbove(QTreeWidgetItem *current, UserMenuData::MenuType type, const QString &menulabel); 0068 void insertMenuItemBelow(QTreeWidgetItem *current, UserMenuData::MenuType type, const QString &menulabel); 0069 void insertIntoSubmenu(QTreeWidgetItem *current, UserMenuData::MenuType type); 0070 0071 void deleteMenuTree(); 0072 0073 int itemIndex(QTreeWidgetItem *parent, QTreeWidgetItem *item); 0074 QTreeWidgetItem *itemAtIndex(QTreeWidgetItem *parent, int index); 0075 int numChildren(QTreeWidgetItem *parent); 0076 0077 void insertItem(QTreeWidgetItem *parent, int index, QTreeWidgetItem *item); 0078 void takeItem(QTreeWidgetItem *parent, QTreeWidgetItem *item); 0079 0080 UserMenuItem *readXmlSeparator(); 0081 UserMenuItem *readXmlSubmenu(const QDomElement &element); 0082 UserMenuItem *readXmlMenuentry(const QDomElement &element); 0083 0084 void writeXmlItem(QXmlStreamWriter *xml, UserMenuItem *item); 0085 void writeXmlMenuentry(QXmlStreamWriter *xml, UserMenuItem *item); 0086 void writeXmlSubmenu(QXmlStreamWriter *xml, UserMenuItem *item); 0087 void writeXmlSeparator(QXmlStreamWriter *xml); 0088 0089 void checkMenuTitle(UserMenuItem *item); 0090 void checkSubmenu(UserMenuItem *item); 0091 0092 bool str2bool(const QString &value); 0093 QString getMenuTitle(const QString &title); 0094 void itemInfo(UserMenuItem *item); 0095 }; 0096 0097 0098 } 0099 0100 #endif