summaryrefslogtreecommitdiffstats
path: root/src/modules/editor/scripteditor.h
blob: d7bc435fb2efc649f23b47be6bd1a379a44c2dbf (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
#ifndef _SCRIPTEDITOR_H_
#define _SCRIPTEDITOR_H_

//=============================================================================
//
//   File : scripteditor.h
//   Created on Sun Mar 28 1999 16:11:48 CEST by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 1999-2004 Szymon Stefanek <pragma at kvirc dot net>
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program 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 General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "kvi_scripteditor.h"

#include <qlabel.h>
#include <kvi_tal_textedit.h>
#include <qsyntaxhighlighter.h>
#include <qdialog.h>
#include <qcheckbox.h>
#include "kvi_tal_listbox.h"
#include <qevent.h> 
#include "kvi_qcstring.h"

#include "kvi_tal_popupmenu.h"

#include "kvi_pointerlist.h"
#include "kvi_selectors.h"
typedef KviPointerList<int> ColumnList;

class KviCompletionBox: public KviTalListBox
{
	Q_OBJECT
public:
	KviCompletionBox(QWidget * parent);
	~KviCompletionBox(){};
	
	void updateContents(QString word);
protected:
	virtual void keyPressEvent(QKeyEvent * e);
};

class KviScriptEditorWidget : public KviTalTextEdit
{
	Q_OBJECT
	Q_PROPERTY(bool contextSensitiveHelp READ contextSensitiveHelp)
public:
	KviScriptEditorWidget(QWidget * pParent);
	virtual ~KviScriptEditorWidget();
public:
	void updateOptions();
	void find1();
	QString m_szFind;
	KviCompletionBox *completelistbox;
	void completition(bool bCanComplete = 1);
	void getWordBeforeCursor(QString &buffer,int index,bool *);
	void getWordOnCursor(QString &buffer,int index) const;
	bool contextSensitiveHelp() const;
public slots:
	void slotFind();
	void slotHelp();
	void slotReplace();
	void slotComplete(const QString &str);

signals:
	void keyPressed();
protected:
	virtual void keyPressEvent(QKeyEvent * e);
	void contentsMousePressEvent(QMouseEvent *);
#ifdef COMPILE_USE_QT4
	Q3PopupMenu *createPopupMenu( const QPoint& pos );
#else
	QPopupMenu *createPopupMenu( const QPoint& pos );
#endif
	QWidget *m_pParent;
	QString m_szHelp;

};

#ifdef COMPILE_USE_QT4
	#include <q3syntaxhighlighter.h>
	#define QSyntaxHighlighter Q3SyntaxHighlighter
#else
	#include <qobjectlist.h>
#endif
class KviScriptSyntaxHighlighter : public QSyntaxHighlighter
{
public:
	KviScriptSyntaxHighlighter(KviScriptEditorWidget * pWidget);
	virtual ~KviScriptSyntaxHighlighter();
public:
	virtual int highlightParagraph(const QString & text,int endStateOfLastPara);
};

class KviScriptEditorWidgetColorOptions : public QDialog
{
	Q_OBJECT
public:
	KviScriptEditorWidgetColorOptions(QWidget * pParent);
	~KviScriptEditorWidgetColorOptions();
private:
	KviPointerList<KviSelectorInterface> * m_pSelectorInterfaceList;
protected:
	KviColorSelector * addColorSelector(QWidget * pParent,const QString & txt,QColor * pOption,bool bEnabled);

protected slots:
	void okClicked();
};

class QTimer;

class KviScriptEditorImplementation : public KviScriptEditor
{
	Q_OBJECT
public:
	KviScriptEditorImplementation(QWidget * par);
	virtual ~KviScriptEditorImplementation();
protected:
	KviScriptEditorWidget * m_pEditor;
	QLabel                * m_pRowColLabel;
	QPoint                  m_lastCursorPos;
public:
	virtual void setText(const QString &txt);
	virtual void getText(QString &txt);
	virtual void setText(const KviQCString &txt);
	virtual void getText(KviQCString &txt);
	virtual void setFindText(const QString & text);
	virtual void setEnabled(bool bEnabled);
	virtual void setFocus();
	virtual bool isModified();
	void setFindLineeditReadOnly(bool b);
	void setCursorPosition(QPoint);
	QPoint getCursor();
	QLineEdit *m_pFindlineedit;
	QLineEdit * getFindlineedit();
protected:
	virtual void focusInEvent(QFocusEvent *e);
	void loadOptions();
	void saveOptions();
protected slots:
	void saveToFile();
	void loadFromFile();
	void configureColors();
	void updateRowColLabel();
	void slotFind();
	void slotReplaceAll(const QString &,const QString &);
	void slotInitFind();
	void slotNextFind(const QString &);
signals:
	void find( const QString &);
	void replaceAll( const QString &, const QString &);
	void initFind();
	void nextFind(const QString &);
};

class KviScriptEditorReplaceDialog: public QDialog
{
	Q_OBJECT
public:
	KviScriptEditorReplaceDialog( QWidget* parent = 0, const char* name = 0);
    ~KviScriptEditorReplaceDialog();
	QLineEdit *m_pFindlineedit;
	QLineEdit *m_pReplacelineedit;
protected:
	QLabel *findlabel;
	QLabel *replacelabel;
	QPushButton *replacebutton;
	QPushButton *replace;
	QPushButton *findNext;

//	QPushButton *cancelbutton;
	KviStyledCheckBox *checkReplaceAll;
	QWidget *m_pParent;
protected slots:
	void textChanged(const QString &);
	void slotReplace();
	void slotNextFind();
signals:
	void replaceAll( const QString &,const QString &);
	void initFind();
	void nextFind(const QString &);
	
};


#endif //!_SCRIPTEDITOR_H_