summaryrefslogtreecommitdiffstats
path: root/kregexpeditor/editorwindow.h
blob: c8899a67ccca2a86a92f49752101f84ae0b13bba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 *  Copyright (c) 2002-2003 Jesper K. Pedersen <blackie@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/
#ifndef editorwindow_h
#define editorwindow_h

#include "drag.h"
#include "widgetfactory.h"
#include <tqmultilineedit.h>
#include <tqlabel.h>
#include <tqiconset.h>
class RegExp;
class RegExpWidget;
class TQHBoxLayout;

/** Widget representing the editor window of a regular expression editor.

    @internal
    This widget represent the editor part (That is the location where the
    regexp widgets are located).

    Furthermore, it also responsible for:
    @li Widget traversal operations (see e.g. @ref hasSelection, @ref
    clearSelection, and @ref applyRegExpToSelection ).
    @li Containing global information for regexp editing. (See @ref
    _pasteData and @ref _insertInAction )

    All subclasses of @ref RegExpWidget contains a pointer to the @ref
    RegExpEditorWindow which the widget is a child of. They use this
    pointer to start operations like rubber band selection, cut/paste etc.
*/
class RegExpEditorWindow :public TQWidget
{
    Q_OBJECT
  TQ_OBJECT

public:
    RegExpEditorWindow(TQWidget *parent, const char *name = 0);

    /**
       Returns an object which represent the regular expression "drawn" in
       the editor window. This object is capable of generating a textual
       representation of the regexp (see @ref RegExp::emacs, and @ref
       RegExp::perl etc)
    */
	RegExp* regExp() const;

    /**
       This method returns true if the rectangle starting at `globalPos' with
       size `size' overlaps the rubber-band rectangle.
       Note this method is only valid while doing rubber-band
       selection. Afterwards, use @ref pointSelected instead.
    */
    bool selectionOverlap( TQPoint globalPos, TQSize size ) const;

    /**
       returns true if `pos' lays on top of a widget that is selected.
    */
    bool pointSelected( TQPoint pos ) const;

    /**
       returns true if the editor has a selection.
    */
    bool hasSelection() const;

    /**
       clears the selection, and if `update', invokes update on all the
       widgets
    */
    void clearSelection( bool update );

    /**
       invoked update on the top widget, and ensures that `focusChild' is
       visible. It's valid for `focusChild' to be 0.
    */
    void updateContent(TQWidget* focusChild);

    RegExp* pasteData() { return _pasteData; }
    bool isPasteing() const { return _pasteInAction; }
    bool isInserting() const { return _insertInAction; }

    /**
       Returns the type currently being inserted.
       This is the type, which was given to @ref slotInsertRegExp
    */
    RegExpType insertType() const { return _insertTp; }

    /**
       Create a regexp widget, so that it wraps around the current selected
       regexp.
    */
    void applyRegExpToSelection( RegExpType tp );

    /**
       Pops up the RMB menu, which contains cut, copy, past, ...
    */
    void showRMBMenu( bool enableCutCopy );

    virtual TQSize sizeHint() const;

public slots:

    /**
       Set the editor window to the regular expression given as argument
    */
    void slotSetRegExp( RegExp* regexp );

    /**
       Change editing mode to insertion. This means that the cursor will
       change to a cross (where ever inserting of the `type' is allowed),
       and the next mouse press in allowed places will result in that a
       regular expression of type `type' will be inserted there.

       Note this method do not do the actual insertion.

       This method is used when the user presses one of the buttons to the
       right of the editor window.
    */
    void slotInsertRegExp( RegExpType type );

    /**
       Change editing state to selection.
    */
    void slotDoSelect();

    /**
       Like @ref slotInsertRegExp above. This time, however,  data will be
       submitted in as a RegExp pointer.

       Note this method do not do the actual insertion.

       This method is called when the user pastes data (using the RPM menu),
       or when a regular expression is loaded from file.
    */
    void slotInsertRegExp( RegExp* regexp );

    /**
       see @ref RegExpWidget::deleteSelection
    */
    void slotDeleteSelection();

    /**
       This method is invoked when the user selects paste in the RMB menu. It
       will change the mouse cursor etc. as described in @ref
       slotInsertRegExp
    */
    void slotStartPasteAction();

    /**
       Ends an insert or paste action. This involves changing cursor back to
       normal cursor.
    */
    void slotEndActions();

    void emitChange() { emit change(); }

    void updateCursorUnderPoint();

    void slotCut();
    void slotCopy();
    void slotSave();

signals:
    /**
       This signal is emitted whenever the content of the editor window is
       changed.

       If focusPoint is non-null then this point should be made visible
    */
    void contentChanged( TQPoint focusPoint );

    /**
       This signal is emitted whenever mouse is being dragged in the editor
       window. `focusPoint' is the mouse' current position.
    */
    void scrolling( TQPoint focusPoint );

    /**
       see @ref RegExpScrolledEditorWindow::doneEditing
    */
    void doneEditing();

    /**
       see @ref RegExpScrolledEditorWindow::change
    */
    void change();

    /**
       see @ref RegExpScrolledEditorWindow::savedRegexp
    */
    void savedRegexp();

    /**
       see @ref RegExpScrolledEditorWindow::verifyRegExp
    */
    void verifyRegExp();

    void anythingSelected( bool );
    void anythingOnClipboard( bool );
    void canSave( bool );


protected:
    virtual void mousePressEvent ( TQMouseEvent* event );
    virtual void mouseMoveEvent ( TQMouseEvent* event );
    virtual void mouseReleaseEvent( TQMouseEvent *event);
    virtual void paintEvent( TQPaintEvent* event );

protected slots:
    virtual void emitVerifyRegExp();

private:
    void cutCopyAux( TQPoint pos );
    void copy( TQPoint pos );
    void cut( TQPoint pos );

private:
    /** This points to the top @ref RegExpWidget in the editor window. */
	ConcWidget *_top;

    /** This points to the tqlayout manager for the editor window */
    TQHBoxLayout* _layout;

    /** Start point and last point draw. Used when doing rubber band selection  */
    TQPoint _start, _lastPoint;

    /** The area which the rubber band selection is over */
    TQRect _selection;

    /**
        True when a rubber band selection rectangle is drawn, and need to be
        un-drawn before next rubber band selection rectangle may be drawn.
    */
    bool _undrawSelection;

    /** true when a paste action is in action (see @ref isPasteing ). */
    bool _pasteInAction;

    /** true when an insert action is in action (see @ref isInserting ). */
    bool _insertInAction;

    /** The type being inserted (see @ref insertType ) */
    RegExpType _insertTp;

    /** The data being inserted (see @ref pasteData ) */
    RegExp* _pasteData;

    /** Popup menu used for RMB */
    TQPopupMenu* _menu;

    TQIconSet getIcon( const TQString& name );

    bool _isDndOperation;
};

#endif // editorwindow_h