File indexing completed on 2024-04-21 15:55:38
0001 /************************************************************************************* 0002 begin : 2003-07-01 17:33:00 CEST 2003 0003 copyright : (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) 0004 (C) 2008-2019 by Michel Ludwig (michel.ludwig@kdemail.net) 0005 (C) 2009 Thomas Braun (thomas.braun@virtuell-zuhause.de) 0006 0007 *************************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 #ifndef KILEACTIONS_H 0018 #define KILEACTIONS_H 0019 0020 #include <QAction> 0021 #include <KActionCollection> 0022 #include <KActionMenu> 0023 #include <KSelectAction> 0024 #include <QDialog> 0025 #include <QLineEdit> 0026 0027 class QCheckBox; 0028 0029 class KileInfo; 0030 0031 namespace KileAction 0032 { 0033 0034 enum { KeepHistory=1, ShowAlternative=2, ShowBrowseButton=4, FromLabelList=8, FromBibItemList=16, ShowLabel=32, AddProjectFile=64}; 0035 /* 0036 TagData 0037 */ 0038 0039 class TagData 0040 { 0041 public: 0042 explicit TagData(const QString &t, const QString &tB = QString(), const QString &tE = QString(), int x = 0, int y = 0, const QString &desc = QString()) 0043 : text(t), tagBegin(tB), tagEnd(tE), dx(x), dy(y), description(desc) {} 0044 0045 TagData() : text(QString()), tagBegin(QString()), tagEnd(QString()), dx(0), dy(0), description(QString()) {} 0046 0047 QString text; 0048 QString tagBegin, tagEnd; 0049 int dx,dy; 0050 QString description; 0051 }; 0052 0053 class Tag : public QAction 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 //constructors 0059 Tag(const QString &text, const QString& iconText, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, 0060 const QString &tagBegin, const QString &tagEnd = QString(), int dx = 0, int dy = 0, const QString &description = QString()); 0061 0062 Tag(const QString &text, const QString& iconText, const QString& pix, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, 0063 const QString &tagBegin, const QString &tagEnd = QString(), int dx = 0, int dy = 0, const QString &description = QString()); 0064 0065 Tag(const QString &text, const QString& iconText, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, 0066 const TagData& data); 0067 0068 Tag(const QString &text, const QString& iconText, const QString& pix, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, 0069 const TagData& data); 0070 0071 ~Tag(); 0072 0073 private: 0074 void init(const QObject *receiver = Q_NULLPTR, const char *slot = Q_NULLPTR); 0075 0076 Q_SIGNALS: 0077 //sends along tagdata so that receiver knows what to insert 0078 void triggered(const KileAction::TagData&); 0079 0080 private Q_SLOTS: 0081 //emits the triggered(TagData) signal 0082 virtual void emitData(); 0083 0084 protected: 0085 TagData m_data; 0086 }; 0087 0088 /* 0089 InputTag: adds a history list and options for a input dialog to TagData 0090 */ 0091 class InputTag : public Tag 0092 { 0093 Q_OBJECT 0094 0095 public: 0096 //constructors 0097 InputTag(KileInfo* ki, const QString &text, const QString &iconText, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, QWidget *wparent, uint options, 0098 const QString &tagBegin, const QString &tagEnd = QString(), int dx = 0, int dy = 0, const QString &description = QString(), const QString &hint = QString(), const QString &alter = QString()); 0099 0100 InputTag(KileInfo* ki, const QString &text, const QString &iconText, const QString& pix, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, QWidget *wparent, uint options, 0101 const QString &tagBegin, const QString &tagEnd = QString(), int dx = 0, int dy = 0, const QString &description = QString(), const QString &hint = QString(), const QString &alter = QString()); 0102 0103 InputTag(KileInfo* ki, const QString &text, const QString &iconText, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, QWidget *wparent, uint options, 0104 const TagData& data, const QString &hint = QString(), const QString &alter = QString()); 0105 0106 InputTag(KileInfo* ki, const QString &text, const QString &iconText, const QString& pix, const QKeySequence &cut, const QObject *receiver, const char *slot, KActionCollection *parent, const QString& name, QWidget *wparent, uint options, 0107 const TagData& data, const QString &hint = QString(), const QString &alter = QString()); 0108 0109 ~InputTag(); 0110 0111 bool hasHistory() { 0112 return (m_options & KeepHistory); 0113 } 0114 bool hasAlternative() { 0115 return (m_options & ShowAlternative); 0116 } 0117 bool hasBrowseButton() { 0118 return (m_options & ShowBrowseButton); 0119 } 0120 0121 void addToHistory(const QString& str); 0122 0123 private: 0124 void init(); 0125 0126 private Q_SLOTS: 0127 //emits the triggered(TagData) signal 0128 virtual void emitData() override; 0129 0130 private: 0131 KileInfo *m_ki; 0132 QStringList m_history; 0133 QWidget *m_parent; 0134 uint m_options; 0135 QString m_hint; 0136 QString m_alter; 0137 }; 0138 0139 0140 /* 0141 InputDialog 0142 */ 0143 class InputDialog : public QDialog 0144 { 0145 Q_OBJECT 0146 0147 public: 0148 InputDialog(const QString &caption, uint options, const QStringList& history, const QString &hint, const QString &alter, KileInfo *ki, QWidget *parent=0, const char *name=0); 0149 ~InputDialog(); 0150 0151 bool useAlternative() { 0152 return m_useAlternative; 0153 } 0154 bool useLabel() { 0155 return m_useLabel; 0156 } 0157 bool useAddProjectFile() { 0158 return m_useAddProjectFile; 0159 } 0160 0161 public Q_SLOTS: 0162 void slotBrowse(); 0163 void slotAltClicked(); 0164 0165 void setTag(const QString&); 0166 0167 Q_SIGNALS: 0168 void setInput(const QString&); 0169 0170 public: 0171 QString tag() { 0172 return m_tag; 0173 } 0174 QString label(); 0175 bool usedSelection() { 0176 return m_usedSelection; 0177 } 0178 0179 QLineEdit *m_edLabel; 0180 0181 private: 0182 QString m_tag; 0183 QString m_labelprefix; 0184 bool m_useAlternative,m_useLabel,m_usedSelection,m_useAddProjectFile; 0185 KileInfo *m_ki; 0186 }; 0187 0188 class Select : public KSelectAction 0189 { 0190 Q_OBJECT 0191 0192 public: 0193 //constructors 0194 Select(const QString &text, const QKeySequence &cut, KActionCollection *parent, const char *name); 0195 0196 public Q_SLOTS: 0197 void setItems(const QList<QAction *> &); 0198 0199 }; 0200 0201 class VariantSelection : public QAction 0202 { 0203 Q_OBJECT 0204 0205 public: 0206 VariantSelection(const QString &text, const QVariant& value, QObject *parent = Q_NULLPTR); 0207 0208 Q_SIGNALS: 0209 void triggered(const QVariant& value); 0210 void triggered(const QUrl &url); 0211 void triggered(const QString& string); 0212 0213 private Q_SLOTS: 0214 void slotTriggered(); 0215 0216 private: 0217 QVariant m_variant; 0218 }; 0219 0220 } 0221 0222 class ToolbarSelectAction : public QWidgetAction 0223 { 0224 Q_OBJECT 0225 0226 public: 0227 ToolbarSelectAction(const QString& text, QObject* parent, bool changeMainActionOnTriggering = true); 0228 0229 void addAction(QAction *action); 0230 void addSeparator(); 0231 int actionIndex(QAction *action); 0232 QAction* action(int i); 0233 QAction* currentAction(); 0234 bool containsAction(QAction *action); 0235 int currentItem() const; 0236 void setCurrentItem(int i); 0237 void setCurrentAction(QAction *action); 0238 void removeAllActions(); 0239 0240 void saveCurrentAction(); 0241 void restoreCurrentAction(); 0242 0243 protected Q_SLOTS: 0244 void slotTriggered(QAction*); 0245 void slotMainActionTriggered(); 0246 void slotMainButtonPressed(); 0247 0248 Q_SIGNALS: 0249 void mainButtonWithNoActionPressed(); 0250 0251 protected: 0252 QMenu* menu(); 0253 virtual QWidget* createWidget(QWidget *parent) override; 0254 0255 private: 0256 QList<QAction*> m_actionList; 0257 int m_currentItem; 0258 QString m_mainText; 0259 QAction *m_savedCurrentAction; 0260 }; 0261 0262 #endif