File indexing completed on 2024-03-24 05:54:39
0001 /* 0002 * SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 **/ 0006 0007 #ifndef regexpeditorwindow_h 0008 #define regexpeditorwindow_h 0009 0010 #include <QWidget> 0011 0012 #include "widgetfactory.h" 0013 0014 class ConcWidget; 0015 class QMenu; 0016 class QHBoxLayout; 0017 0018 /** Widget representing the editor window of a regular expression editor. 0019 0020 @internal 0021 This widget represent the editor part (That is the location where the 0022 regexp widgets are located). 0023 0024 Furthermore, it also responsible for: 0025 @li Widget traversal operations (see e.g. @ref hasSelection, @ref 0026 clearSelection, and @ref applyRegExpToSelection ). 0027 @li Containing global information for regexp editing. (See @ref 0028 _pasteData and @ref _insertInAction ) 0029 0030 All subclasses of @ref RegExpWidget contains a pointer to the @ref 0031 RegExpEditorWindow which the widget is a child of. They use this 0032 pointer to start operations like rubber band selection, cut/paste etc. 0033 */ 0034 class RegExpEditorWindow : public QWidget 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 explicit RegExpEditorWindow(QWidget *parent); 0040 ~RegExpEditorWindow() override; 0041 0042 /** 0043 Returns an object which represent the regular expression "drawn" in 0044 the editor window. This object is capable of generating a textual 0045 representation of the regexp (see @ref RegExp::emacs, and @ref 0046 RegExp::perl etc) 0047 */ 0048 RegExp *regExp() const; 0049 0050 /** 0051 This method returns true if the rectangle starting at `globalPos' with 0052 size `size' overlaps the rubber-band rectangle. 0053 Note this method is only valid while doing rubber-band 0054 selection. Afterwards, use @ref pointSelected instead. 0055 */ 0056 bool selectionOverlap(const QPointF &globalPos, QSize size) const; 0057 0058 /** 0059 returns true if `pos' lays on top of a widget that is selected. 0060 */ 0061 bool pointSelected(const QPointF &pos) const; 0062 0063 /** 0064 returns true if the editor has a selection. 0065 */ 0066 bool hasSelection() const; 0067 0068 /** 0069 clears the selection, and if `update', invokes update on all the 0070 widgets 0071 */ 0072 void clearSelection(bool update); 0073 0074 /** 0075 invoked update on the top widget, and ensures that `focusChild' is 0076 visible. It's valid for `focusChild' to be 0. 0077 */ 0078 void updateContent(QWidget *focusChild); 0079 0080 RegExp *pasteData() 0081 { 0082 return _pasteData; 0083 } 0084 0085 bool isPasteing() const 0086 { 0087 return _pasteInAction; 0088 } 0089 0090 bool isInserting() const 0091 { 0092 return _insertInAction; 0093 } 0094 0095 /** 0096 Returns the type currently being inserted. 0097 This is the type, which was given to @ref slotInsertRegExp 0098 */ 0099 RegExpType insertType() const 0100 { 0101 return _insertTp; 0102 } 0103 0104 /** 0105 Create a regexp widget, so that it wraps around the current selected 0106 regexp. 0107 */ 0108 void applyRegExpToSelection(RegExpType tp); 0109 0110 /** 0111 Pops up the RMB menu, which contains cut, copy, past, ... 0112 */ 0113 void showRMBMenu(bool enableCutCopy); 0114 0115 QSize sizeHint() const override; 0116 0117 public Q_SLOTS: 0118 0119 /** 0120 Set the editor window to the regular expression given as argument 0121 */ 0122 void slotSetRegExp(RegExp *regexp); 0123 0124 /** 0125 Change editing mode to insertion. This means that the cursor will 0126 change to a cross (where ever inserting of the `type' is allowed), 0127 and the next mouse press in allowed places will result in that a 0128 regular expression of type `type' will be inserted there. 0129 0130 Note this method do not do the actual insertion. 0131 0132 This method is used when the user presses one of the buttons to the 0133 right of the editor window. 0134 */ 0135 void slotInsertRegExp(RegExpType type); 0136 0137 /** 0138 Change editing state to selection. 0139 */ 0140 void slotDoSelect(); 0141 0142 /** 0143 Like @ref slotInsertRegExp above. This time, however, data will be 0144 submitted in as a RegExp pointer. 0145 0146 Note this method do not do the actual insertion. 0147 0148 This method is called when the user pastes data (using the RPM menu), 0149 or when a regular expression is loaded from file. 0150 */ 0151 void slotInsertRegExp(RegExp *regexp); 0152 0153 /** 0154 see @ref RegExpWidget::deleteSelection 0155 */ 0156 void slotDeleteSelection(); 0157 0158 /** 0159 This method is invoked when the user selects paste in the RMB menu. It 0160 will change the mouse cursor etc. as described in @ref 0161 slotInsertRegExp 0162 */ 0163 void slotStartPasteAction(); 0164 0165 /** 0166 Ends an insert or paste action. This involves changing cursor back to 0167 normal cursor. 0168 */ 0169 void slotEndActions(); 0170 0171 void emitChange() 0172 { 0173 Q_EMIT change(); 0174 } 0175 0176 void updateCursorUnderPoint(); 0177 0178 void slotCut(); 0179 void slotCopy(); 0180 void slotSave(); 0181 0182 Q_SIGNALS: 0183 /** 0184 This signal is emitted whenever the content of the editor window is 0185 changed. 0186 0187 If focusPoint is non-null then this point should be made visible 0188 */ 0189 void contentChanged(QPointF focusPoint); 0190 0191 /** 0192 This signal is emitted whenever mouse is being dragged in the editor 0193 window. `focusPoint' is the mouse' current position. 0194 */ 0195 void scrolling(QPointF focusPoint); 0196 0197 /** 0198 see @ref RegExpScrolledEditorWindow::doneEditing 0199 */ 0200 void doneEditing(); 0201 0202 /** 0203 see @ref RegExpScrolledEditorWindow::change 0204 */ 0205 void change(); 0206 0207 /** 0208 see @ref RegExpScrolledEditorWindow::savedRegexp 0209 */ 0210 void savedRegexp(); 0211 0212 /** 0213 see @ref RegExpScrolledEditorWindow::verifyRegExp 0214 */ 0215 void verifyRegExp(); 0216 0217 void anythingSelected(bool); 0218 void anythingOnClipboard(bool); 0219 void canSave(bool); 0220 0221 protected: 0222 void mousePressEvent(QMouseEvent *event) override; 0223 void mouseMoveEvent(QMouseEvent *event) override; 0224 void mouseReleaseEvent(QMouseEvent *event) override; 0225 void paintEvent(QPaintEvent *event) override; 0226 0227 protected Q_SLOTS: 0228 virtual void emitVerifyRegExp(); 0229 void editWidget(); 0230 0231 private: 0232 void cutCopyAux(QPointF pos); 0233 void copy(QPointF pos); 0234 void cut(QPointF pos); 0235 0236 private: 0237 /** This points to the top @ref RegExpWidget in the editor window. */ 0238 ConcWidget *_top; 0239 0240 /** This points to the layout manager for the editor window */ 0241 QHBoxLayout *_layout; 0242 0243 /** This points to the edit widget */ 0244 QPointF _PosEdit; 0245 0246 /** Start point and last point draw. Used when doing rubber band selection */ 0247 QPointF _start, _lastPoint; 0248 0249 /** The area which the rubber band selection is over */ 0250 QRectF _selection; 0251 0252 /** true when a paste action is in action (see @ref isPasteing ). */ 0253 bool _pasteInAction; 0254 0255 /** true when an insert action is in action (see @ref isInserting ). */ 0256 bool _insertInAction; 0257 0258 /** The type being inserted (see @ref insertType ) */ 0259 RegExpType _insertTp; 0260 0261 /** The data being inserted (see @ref pasteData ) */ 0262 RegExp *_pasteData = nullptr; 0263 0264 /** Popup menu used for RMB */ 0265 QMenu *_menu = nullptr; 0266 0267 QAction *_cutAction = nullptr; 0268 QAction *_copyAction = nullptr; 0269 QAction *_pasteAction = nullptr; 0270 QAction *_editAction = nullptr; 0271 QAction *_saveAction = nullptr; 0272 0273 QIcon getIcon(const QString &name); 0274 0275 bool _isDndOperation; 0276 }; 0277 0278 #endif // regexpeditorwindow_h