File indexing completed on 2024-05-12 16:41:08
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 USERMENUITEM_H 0015 #define USERMENUITEM_H 0016 0017 #include <QTreeWidget> 0018 #include <QTreeWidgetItem> 0019 #include <QIcon> 0020 0021 #include <KLocalizedString> 0022 #include <QKeySequence> 0023 0024 #include "usermenu/usermenudata.h" 0025 0026 #define EMPTY_MENUENTRY i18n("???") 0027 #define EMPTY_SUBMENU i18n(" >") 0028 #define LENGTH_SUBSTITUTE 3 0029 0030 namespace KileMenu { 0031 0032 ////////////////////////////// UserMenuItem ////////////////////////////// 0033 0034 class UserMenuItem : public QTreeWidgetItem { 0035 0036 public: 0037 0038 UserMenuItem(UserMenuData::MenuType type, const QString &menutitle = QString()); 0039 UserMenuItem(QTreeWidget *parent, QTreeWidgetItem *preceding, 0040 UserMenuData::MenuType type, const QString &menutitle = QString()); 0041 UserMenuItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding, 0042 UserMenuData::MenuType type, const QString &menutitle = QString()); 0043 0044 virtual ~UserMenuItem() {} 0045 0046 enum ModelUserError { MODEL_ERROR_NONE=0x00, 0047 MODEL_ERROR_EMPTY=0x01, 0048 MODEL_ERROR_SUBMENU=0x02, 0049 MODEL_ERROR_TEXT=0x04, 0050 MODEL_ERROR_FILE_EMPTY=0x08, 0051 MODEL_ERROR_FILE_EXIST=0x10, 0052 MODEL_ERROR_FILE_EXECUTABLE=0x20, 0053 }; 0054 0055 void setModelData(bool executable=false); 0056 QString updateMenutitle(); 0057 0058 void setMenutype(UserMenuData::MenuType type) { 0059 m_data.menutype = type; 0060 } 0061 UserMenuData::MenuType menutype() { 0062 return m_data.menutype; 0063 } 0064 0065 void setMenutitle(const QString &s) { 0066 m_data.menutitle = s; 0067 } 0068 const QString &menutitle() { 0069 return m_data.menutitle; 0070 } 0071 0072 void setMenuicon(const QString &icon) { 0073 m_data.icon = icon; 0074 } 0075 QString menuicon() { 0076 return m_data.icon; 0077 } 0078 0079 void setFilename(const QString &filename) { 0080 m_data.filename = filename; 0081 } 0082 const QString &filename() { 0083 return m_data.filename; 0084 } 0085 0086 void setParameter(const QString ¶meter) { 0087 m_data.parameter = parameter; 0088 } 0089 const QString ¶meter() { 0090 return m_data.parameter; 0091 } 0092 0093 void setPlaintext(const QString &text) { 0094 m_data.text = text; 0095 } 0096 const QString &plaintext() { 0097 return m_data.text; 0098 } 0099 0100 void setShortcut(const QString &shortcut) { 0101 m_data.shortcut = shortcut; 0102 } 0103 QString shortcut() { 0104 return m_data.shortcut; 0105 } 0106 0107 // checkboxes 0108 void setNeedsSelection(bool state) { 0109 m_data.needsSelection = state; 0110 } 0111 bool needsSelection() { 0112 return m_data.needsSelection; 0113 } 0114 0115 void setUseContextMenu(bool state) { 0116 m_data.useContextMenu = state; 0117 } 0118 bool useContextMenu() { 0119 return m_data.useContextMenu; 0120 } 0121 0122 void setReplaceSelection(bool state) { 0123 m_data.replaceSelection = state; 0124 } 0125 bool replaceSelection() { 0126 return m_data.replaceSelection; 0127 } 0128 0129 void setSelectInsertion(bool state) { 0130 m_data.selectInsertion = state; 0131 } 0132 bool selectInsertion() { 0133 return m_data.selectInsertion; 0134 } 0135 0136 void setInsertOutput(bool state) { 0137 m_data.insertOutput = state; 0138 } 0139 bool insertOutput() { 0140 return m_data.insertOutput; 0141 } 0142 0143 private: 0144 UserMenuData m_data; 0145 0146 void clear(); 0147 void initItem(UserMenuData::MenuType type, const QString &menutitle); 0148 0149 }; 0150 0151 0152 } 0153 0154 #endif