KVIrc 5.2.0
Developer APIs
KviInputEditor.h
Go to the documentation of this file.
1#ifndef _KVI_INPUT_EDITOR_H_
2#define _KVI_INPUT_EDITOR_H_
3//============================================================================
4//
5// File : KviInputEditor.h
6// Creation date : Fri Sep 5 2008 17:26:34 by Elvio Basello
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2008 Elvio Basello (hell at hellvis69 dot netsons dot org)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//============================================================================
26
27//
28// This file was originally part of KviInput.h
29//
30
45#include "kvi_settings.h"
46#include "KviCString.h"
47#include "KviWindow.h"
48
49#include <QMenu>
50#include <QString>
51#include <QWidget>
52
53#include <vector>
54
55class KviUserListView;
56class QDragEnterEvent;
57class QKeyEvent;
58class QFontMetrics;
59
60#define KVI_INPUT_MAX_BUFFER_SIZE 400
61#define KVI_INPUT_XTRAPADDING 1
62#define KVI_INPUT_MARGIN 4
63#define KVI_INPUT_BLINK_TIME 800
64#define KVI_INPUT_DRAG_TIMEOUT 30
65#define KVI_INPUT_DEF_BACK 100
66#define KVI_INPUT_DEF_FORE 101
67
68#ifndef ACCEL_KEY
69#define ACCEL_KEY(k) "\t" + QKeySequence(Qt::ControlModifier + Qt::Key_##k).toString()
70#endif
71
73{
74public:
75 QString szText;
76 qsizetype iStart;
77 qsizetype iLength;
80};
81
83
88class KVIRC_API KviInputEditor : public QWidget
89{
90 //Q_PROPERTY(int KviProperty_FocusOwner READ heightHint)
91 Q_PROPERTY(int TransparencyCapable READ heightHint)
92 Q_OBJECT
93 friend class KviTextIconWindow; // it uses insetIconCode(const QString &)
94 friend class KviTopicWidget; // it uses home()
95public:
103 KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView * pView = nullptr);
104 KviInputEditor(QWidget * pPar, QWidget * pInputParent, KviWindow * pWnd, KviUserListView * pView = nullptr);
105
110
111protected:
112 static int g_iInputFontCharWidth[256];
113 static QFontMetrics * g_pLastFontMetrics;
115 static int g_iCachedHeight;
116 QString m_szTextBuffer; // original buffer
122 bool m_bSpSlowFlag; // Slow paste status flag
124
125 // members for supporting input methods
126 QString m_szIMText;
132
134
137
139
140 // History stuff
141 std::vector<QString> m_History;
143
145
146 // Nick completion
152
156 QWidget * m_pInputParent;
157 QMenu * m_pIconMenu;
160
166 {
167 public:
172 enum Type
173 {
175 RemoveText
176 };
177
178 private:
184
189 QString m_szText;
190
196
197 public:
205 EditCommand(Type eType, const QString & szText, int iStartPosition)
206 : m_eType(eType), m_szText(szText), m_iStartPosition(iStartPosition)
207 {
208 }
209
215 void setStartPosition(int iStartPosition) { m_iStartPosition = iStartPosition; }
216
221 int startPosition() const { return m_iStartPosition; }
222
227 void setText(const QString & szText) { m_szText = szText; }
228
233 const QString & text() const { return m_szText; }
234
240 void setType(const Type & eType) { m_eType = eType; }
241
246 const Type & type() const { return m_eType; }
247 };
248
256 std::vector<EditCommand *> m_UndoStack;
257
265 std::vector<EditCommand *> m_RedoStack;
266
268
269public:
274 int heightHint() const;
275
281 void setText(const QString szText);
282
287 QString text() const { return m_szTextBuffer; }
288
292 QString textBeforeCursor() const;
293
299 void insertChar(QChar c);
300
306 void insertText(const QString & szTxt);
307
312 void applyOptions(bool bRefreshCachedMetrics = true);
313
319 void setMaxBufferSize(int iSize) { m_iMaxBufferSize = iSize; }
320
326 void setReadOnly(bool bReadOnly) { m_bReadOnly = bReadOnly; }
327
332 bool isReadOnly() const { return m_bReadOnly; }
333
337 void clearUndoStack();
338
339private:
347 void replaceWordBeforeCursor(const QString & szWord, const QString & szReplacement, bool bRepaint = true);
348
358 int replaceSegment(int iStart, int iLength, const QString & szString);
359
366 void getWordBeforeCursor(QString & szBuffer, bool * bIsFirstWordInLine);
367
373 static QChar getSubstituteChar(unsigned short uControlCode);
374
378 void ensureCursorVisible();
379
384 void repaintWithCursorOn();
385
386 void clearSelection();
387
393 int charIndexFromXPosition(qreal fXPos);
394
400 qreal xPositionFromCharIndex(int iChIdx);
401
406 void killDragTimer();
407
412 void handleDragSelection();
413
418 void end();
419
424 void home();
425
430 bool hasSelection();
431
438 void moveCursorTo(int iIdx, bool bRepaint = true);
439
447 void returnPressed(bool bRepaint = true);
448
458 void finishInput();
459
468 void completion(bool bShift);
469
478 void standardNickCompletion(bool bAddMask, QString & szWord, bool bFirstWordInLine, bool bInCommand);
479
488 void standardNickCompletionInsertCompletedText(const QString & szReplacedWord, QString szCompletedText, bool bFirstWordInLine, bool bInCommand);
489
495 void internalCursorRight(bool bShift);
496
502 void internalCursorLeft(bool bShift);
503
508 bool isUndoAvailable() const { return !m_bReadOnly && !m_UndoStack.empty(); }
509
514 bool isRedoAvailable() const { return !m_bReadOnly && !m_RedoStack.empty(); }
515
521 void addUndo(EditCommand * pCommand);
522
528 QFontMetrics * getLastFontMetrics(const QFont & font);
529
530public slots:
536 void iconPopupActivated(QAction * pAction);
537
546 void copyToSelection(bool bDonNotCopyToClipboard = true);
547
552 void copyToClipboard();
553
558 void removeSelected();
559
564 void cut();
565
570 void undo();
571
576 void redo();
577
582 void pasteClipboardWithConfirmation();
583
591 void pasteSelectionWithConfirmation();
592
597 void pasteSlow();
598
603 void stopPasteSlow();
604
609 void pasteFile();
610
615 void selectAll();
616
621 void clear();
622private slots:
627 void openHistory();
628
633 void toggleMultiLineEditor();
634
639 void previousChar();
640
645 void nextChar();
646
651 void previousCharSelection();
652
657 void nextCharSelection();
658
663 void previousWord();
664
669 void nextWord();
670
675 void previousWordSelection();
676
681 void nextWordSelection();
682
687 void insertBold();
688
693 void insertItalic();
698 void insertReset();
699
704 void insertUnderline();
705
710 void insertReverse();
711
716 void insertPlainText();
717
722 void insertIcon();
723
728 void insertColor();
729
734 void copyInternal();
735
740 void cutInternal();
741
746 void pasteInternal();
747
752 void undoInternal();
753
758 void redoInternal();
759
764 void selectAllInternal();
765
770 void deletePreviousWord();
771
776 void deleteNextWord();
777
782 void previousLine();
783
788 void nextLine();
789
794 void previousPage();
795
800 void nextPage();
801
806 void scrollTop();
807
812 void scrollBottom();
813
818 void search();
819
824 void scrollToLastReadLine();
825
830 void sendPlain();
831
836 void sendKvs();
837
842 void homeInternal();
843
848 void endInternal();
849
854 void homeInternalSelection();
855
860 void endInternalSelection();
861
866 void historyPrev();
867
872 void historyNext();
873
878 void returnHit();
879
884 void backspaceHit();
885
890 void deleteHit();
891
896 void escapeHit();
897
902 void toggleCommandMode();
903
909 void dummy();
910
915 void zoomIn();
916
921 void zoomOut();
922
927 void zoomDefault();
928
932 void popupTextIconWindow();
933
937 void showContextPopup(const QPoint & pos);
938
942 void showContextPopupHere();
943
947 void showSpellCheckerCorrectionsPopup();
948
952 void spellCheckerPopupCorrectionActionTriggered();
953
957 void addToHistory(const QString & szString);
958
959protected:
960 void insertIconCode(const QString & szCode);
961 void completionEscapeUnsafeToken(QString & szToken);
962 void installShortcuts();
963 virtual void drawContents(QPainter *);
964 //void resizeEvent(QResizeEvent * e) override;
965 void timerEvent(QTimerEvent * e) override;
966 void focusInEvent(QFocusEvent * e) override;
967 void focusOutEvent(QFocusEvent * e) override;
968 void keyPressEvent(QKeyEvent * e) override;
969 void keyReleaseEvent(QKeyEvent * e) override;
970 void mousePressEvent(QMouseEvent * e) override;
971 void mouseReleaseEvent(QMouseEvent * e) override;
972 void mouseDoubleClickEvent(QMouseEvent * e) override;
973 void dragEnterEvent(QDragEnterEvent * e) override;
974 void dropEvent(QDropEvent * e) override;
975 void inputMethodEvent(QInputMethodEvent * e) override;
976 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
977 void paintEvent(QPaintEvent * e) override;
978 bool checkWordSpelling(const QString & szWord);
979 void splitTextIntoSpellCheckerBlocks(const QString & szText, std::vector<KviInputEditorSpellCheckerBlock> & lBuffer);
980 KviInputEditorSpellCheckerBlock * findSpellCheckerBlockAtCursor(std::vector<KviInputEditorSpellCheckerBlock> & lBlocks);
981 void fillSpellCheckerCorrectionsPopup();
982
983 void rebuildTextBlocks();
984
985signals:
991
997};
998
999#endif //_KVI_INPUT_EDITOR_H_
KviPtrListIterator< T > end(KviPointerList< T > *ptrList)
Definition KviPtrListIterator.h:68
Contains the KviWindow class.
btnDict clear()
Definition KviCString.h:102
Definition KviInputEditor.cpp:132
Definition KviInputEditor.h:73
QString szText
Definition KviInputEditor.h:75
bool bCorrect
Definition KviInputEditor.h:79
qsizetype iLength
Definition KviInputEditor.h:77
qsizetype iStart
Definition KviInputEditor.h:76
bool bSpellCheckable
Definition KviInputEditor.h:78
Holds the command used in the {un,re}do operations.
Definition KviInputEditor.h:166
void setText(const QString &szText)
Sets the text of the command.
Definition KviInputEditor.h:227
Type
Defines the type of the command.
Definition KviInputEditor.h:173
@ InsertText
Definition KviInputEditor.h:174
int m_iStartPosition
The start position.
Definition KviInputEditor.h:195
void setStartPosition(int iStartPosition)
Sets the start position.
Definition KviInputEditor.h:215
QString m_szText
The text of the command.
Definition KviInputEditor.h:189
const Type & type() const
Returns the type of the command.
Definition KviInputEditor.h:246
void setType(const Type &eType)
Sets the type of the command.
Definition KviInputEditor.h:240
EditCommand(Type eType, const QString &szText, int iStartPosition)
Constructs the command object.
Definition KviInputEditor.h:205
int startPosition() const
Returns the start position.
Definition KviInputEditor.h:221
Type m_eType
The type of the command.
Definition KviInputEditor.h:183
const QString & text() const
Returns the text of the command.
Definition KviInputEditor.h:233
Input editor class.
Definition KviInputEditor.h:89
QString m_szLastCompletionBuffer
Definition KviInputEditor.h:149
bool m_bUpdatesEnabled
Definition KviInputEditor.h:153
int m_iCursorWidth
Definition KviInputEditor.h:123
int m_iIMStart
Definition KviInputEditor.h:127
int m_iLastCompletionCursorPosition
Definition KviInputEditor.h:150
QMenu m_SpellCheckerPopup
Definition KviInputEditor.h:158
std::vector< EditCommand * > m_UndoStack
The undo stack.
Definition KviInputEditor.h:256
KviWindow * m_pKviWindow
Definition KviInputEditor.h:155
int m_iIMLength
Definition KviInputEditor.h:128
void enterPressed()
Called when the user press enter/return.
QString m_szTextBuffer
Definition KviInputEditor.h:116
bool isUndoAvailable() const
Returns true is there are some action in the undo stack.
Definition KviInputEditor.h:508
bool isReadOnly() const
Returns true if the input line is in read only state.
Definition KviInputEditor.h:332
int m_iMaxBufferSize
Definition KviInputEditor.h:121
int m_iCurHistoryIdx
Definition KviInputEditor.h:142
int m_iSelectionEnd
Definition KviInputEditor.h:120
bool m_bLastCompletionFinished
Definition KviInputEditor.h:151
static int g_iCachedHeight
Definition KviInputEditor.h:115
void setMaxBufferSize(int iSize)
Sets the maximum buffer size.
Definition KviInputEditor.h:319
static QFontMetrics * g_pLastFontMetrics
Definition KviInputEditor.h:113
int m_iCursorPosition
Definition KviInputEditor.h:117
bool m_bReadOnly
Definition KviInputEditor.h:159
int m_iCursorTimer
Definition KviInputEditor.h:135
void setReadOnly(bool bReadOnly)
Sets the read only state for the input line.
Definition KviInputEditor.h:326
QString m_szIMText
Definition KviInputEditor.h:126
int m_iSelectionBegin
Definition KviInputEditor.h:119
KviInputEditorPrivate * m_p
Definition KviInputEditor.h:267
QString text() const
Returns the text in the buffer.
Definition KviInputEditor.h:287
int m_iSpellCheckPosition
Definition KviInputEditor.h:118
bool m_bCursorOn
Definition KviInputEditor.h:133
QString m_szLastCompletedNick
Definition KviInputEditor.h:148
int m_iSelectionAnchorChar
Definition KviInputEditor.h:138
bool isRedoAvailable() const
Returns true is there are some action in the redo stack.
Definition KviInputEditor.h:514
int m_iDragTimer
Definition KviInputEditor.h:136
KviCString m_szSaveTextBuffer
Definition KviInputEditor.h:144
QWidget * m_pInputParent
Definition KviInputEditor.h:156
KviCString m_szAltKeyCode
Definition KviInputEditor.h:154
bool m_bSpSlowFlag
Definition KviInputEditor.h:122
static int g_iInputInstances
Definition KviInputEditor.h:114
std::vector< EditCommand * > m_RedoStack
The redo stack.
Definition KviInputEditor.h:265
int m_iIMSelectionLength
Definition KviInputEditor.h:130
bool m_bIMComposing
Definition KviInputEditor.h:131
void escapePressed()
Called when the user press escape.
std::vector< QString > m_History
Definition KviInputEditor.h:141
int m_iIMSelectionBegin
Definition KviInputEditor.h:129
KviUserListView * m_pUserListView
Definition KviInputEditor.h:147
QMenu * m_pIconMenu
Definition KviInputEditor.h:157
Text icon window class.
Definition KviTextIconWindow.h:41
Definition KviTopicWidget.h:68
User list view management class.
Definition KviUserListView.h:226
Base class for all windows in KVIrc.
Definition KviWindow.h:75
#define e
Definition detector.cpp:70
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127
char szBuffer[4096]
Definition winamp.cpp:77