KVIrc 5.2.6
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
44#include "kvi_settings.h"
45#include "KviCString.h"
46#include "KviWindow.h"
47
48#include <QMenu>
49#include <QString>
50#include <QWidget>
51
52#include <vector>
53
54class KviUserListView;
55class QDragEnterEvent;
56class QKeyEvent;
57class QFontMetrics;
58
59#define KVI_INPUT_MAX_BUFFER_SIZE 400
60#define KVI_INPUT_XTRAPADDING 1
61#define KVI_INPUT_MARGIN 4
62#define KVI_INPUT_BLINK_TIME 800
63#define KVI_INPUT_DRAG_TIMEOUT 30
64#define KVI_INPUT_DEF_BACK 100
65#define KVI_INPUT_DEF_FORE 101
66
68{
69public:
70 QString szText;
71 qsizetype iStart;
72 qsizetype iLength;
75};
76
78
83class KVIRC_API KviInputEditor : public QWidget
84{
85 //Q_PROPERTY(int KviProperty_FocusOwner READ heightHint)
86 Q_PROPERTY(int TransparencyCapable READ heightHint)
87 Q_OBJECT
88 friend class KviTextIconWindow; // it uses insetIconCode(const QString &)
89 friend class KviTopicWidget; // it uses home()
90public:
98 KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView * pView = nullptr);
99 KviInputEditor(QWidget * pPar, QWidget * pInputParent, KviWindow * pWnd, KviUserListView * pView = nullptr);
100
105
106protected:
107 static int g_iInputFontCharWidth[256];
108 static QFontMetrics * g_pLastFontMetrics;
110 static int g_iCachedHeight;
111 QString m_szTextBuffer; // original buffer
117 bool m_bSpSlowFlag; // Slow paste status flag
119
120 // members for supporting input methods
121 QString m_szIMText;
127
129
132
134
135 // History stuff
136 std::vector<QString> m_History;
138
140
141 // Nick completion
147
151 QWidget * m_pInputParent;
152 QMenu * m_pIconMenu;
155
161 {
162 public:
167 enum Type
168 {
170 RemoveText
171 };
172
173 private:
179
184 QString m_szText;
185
191
192 public:
200 EditCommand(Type eType, const QString & szText, int iStartPosition)
201 : m_eType(eType), m_szText(szText), m_iStartPosition(iStartPosition)
202 {
203 }
204
210 void setStartPosition(int iStartPosition) { m_iStartPosition = iStartPosition; }
211
216 int startPosition() const { return m_iStartPosition; }
217
222 void setText(const QString & szText) { m_szText = szText; }
223
228 const QString & text() const { return m_szText; }
229
235 void setType(const Type & eType) { m_eType = eType; }
236
241 const Type & type() const { return m_eType; }
242 };
243
251 std::vector<std::unique_ptr<EditCommand>> m_UndoStack;
252
260 std::vector<std::unique_ptr<EditCommand>> m_RedoStack;
261
263
264public:
269 int heightHint() const;
270
276 void setText(const QString szText);
277
282 QString text() const { return m_szTextBuffer; }
283
287 QString textBeforeCursor() const;
288
294 void insertChar(QChar c);
295
301 void insertText(const QString & szTxt);
302
307 void applyOptions(bool bRefreshCachedMetrics = true);
308
314 void setMaxBufferSize(int iSize) { m_iMaxBufferSize = iSize; }
315
321 void setReadOnly(bool bReadOnly) { m_bReadOnly = bReadOnly; }
322
327 bool isReadOnly() const { return m_bReadOnly; }
328
332 void clearUndoStack();
333
334private:
342 void replaceWordBeforeCursor(const QString & szWord, const QString & szReplacement, bool bRepaint = true);
343
353 int replaceSegment(int iStart, int iLength, const QString & szString);
354
361 void getWordBeforeCursor(QString & szBuffer, bool * bIsFirstWordInLine);
362
368 static QChar getSubstituteChar(unsigned short uControlCode);
369
373 void ensureCursorVisible();
374
379 void repaintWithCursorOn();
380
381 void clearSelection();
382
388 int charIndexFromXPosition(qreal fXPos);
389
395 qreal xPositionFromCharIndex(int iChIdx);
396
401 void killDragTimer();
402
407 void handleDragSelection();
408
413 void end();
414
419 void home();
420
425 bool hasSelection();
426
433 void moveCursorTo(int iIdx, bool bRepaint = true);
434
442 void returnPressed(bool bRepaint = true);
443
453 void finishInput();
454
463 void completion(bool bShift);
464
473 void standardNickCompletion(bool bAddMask, QString & szWord, bool bFirstWordInLine, bool bInCommand);
474
483 void standardNickCompletionInsertCompletedText(const QString & szReplacedWord, QString szCompletedText, bool bFirstWordInLine, bool bInCommand);
484
490 void internalCursorRight(bool bShift);
491
497 void internalCursorLeft(bool bShift);
498
503 bool isUndoAvailable() const { return !m_bReadOnly && !m_UndoStack.empty(); }
504
509 bool isRedoAvailable() const { return !m_bReadOnly && !m_RedoStack.empty(); }
510
516 void addUndo(EditCommand * pCommand);
517
523 QFontMetrics * getLastFontMetrics(const QFont & font);
524
525public slots:
531 void iconPopupActivated(QAction * pAction);
532
541 void copyToSelection(bool bDonNotCopyToClipboard = true);
542
547 void copyToClipboard();
548
553 void removeSelected();
554
559 void cut();
560
565 void undo();
566
571 void redo();
572
577 void pasteClipboardWithConfirmation();
578
586 void pasteSelectionWithConfirmation();
587
592 void pasteSlow();
593
598 void stopPasteSlow();
599
604 void pasteFile();
605
610 void selectAll();
611
616 void clear();
617private slots:
622 void openHistory();
623
628 void toggleMultiLineEditor();
629
634 void previousChar();
635
640 void nextChar();
641
646 void previousCharSelection();
647
652 void nextCharSelection();
653
658 void previousWord();
659
664 void nextWord();
665
670 void previousWordSelection();
671
676 void nextWordSelection();
677
682 void insertBold();
683
688 void insertItalic();
693 void insertReset();
694
699 void insertUnderline();
700
705 void insertReverse();
706
711 void insertPlainText();
712
717 void insertIcon();
718
723 void insertColor();
724
729 void copyInternal();
730
735 void cutInternal();
736
741 void pasteInternal();
742
747 void undoInternal();
748
753 void redoInternal();
754
759 void selectAllInternal();
760
765 void deletePreviousWord();
766
771 void deleteNextWord();
772
777 void previousLine();
778
783 void nextLine();
784
789 void previousPage();
790
795 void nextPage();
796
801 void scrollTop();
802
807 void scrollBottom();
808
813 void search();
814
819 void scrollToLastReadLine();
820
825 void sendPlain();
826
831 void sendKvs();
832
837 void homeInternal();
838
843 void endInternal();
844
849 void homeInternalSelection();
850
855 void endInternalSelection();
856
861 void historyPrev();
862
867 void historyNext();
868
873 void returnHit();
874
879 void backspaceHit();
880
885 void deleteHit();
886
891 void escapeHit();
892
897 void toggleCommandMode();
898
904 void dummy();
905
910 void zoomIn();
911
916 void zoomOut();
917
922 void zoomDefault();
923
927 void popupTextIconWindow();
928
932 void showContextPopup(const QPoint & pos);
933
937 void showContextPopupHere();
938
942 void showSpellCheckerCorrectionsPopup();
943
947 void spellCheckerPopupCorrectionActionTriggered();
948
952 void addToHistory(const QString & szString);
953
954protected:
955 void insertIconCode(const QString & szCode);
956 void completionEscapeUnsafeToken(QString & szToken);
957 void installShortcuts();
958 virtual void drawContents(QPainter *);
959 //void resizeEvent(QResizeEvent * e) override;
960 void timerEvent(QTimerEvent * e) override;
961 void focusInEvent(QFocusEvent * e) override;
962 void focusOutEvent(QFocusEvent * e) override;
963 void keyPressEvent(QKeyEvent * e) override;
964 void keyReleaseEvent(QKeyEvent * e) override;
965 void mousePressEvent(QMouseEvent * e) override;
966 void mouseReleaseEvent(QMouseEvent * e) override;
967 void mouseDoubleClickEvent(QMouseEvent * e) override;
968 void dragEnterEvent(QDragEnterEvent * e) override;
969 void dropEvent(QDropEvent * e) override;
970 void inputMethodEvent(QInputMethodEvent * e) override;
971 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
972 void paintEvent(QPaintEvent * e) override;
973 bool checkWordSpelling(const QString & szWord);
974 void splitTextIntoSpellCheckerBlocks(const QString & szText, std::vector<KviInputEditorSpellCheckerBlock> & lBuffer);
975 KviInputEditorSpellCheckerBlock * findSpellCheckerBlockAtCursor(std::vector<KviInputEditorSpellCheckerBlock> & lBlocks);
976 void fillSpellCheckerCorrectionsPopup();
977
978 void rebuildTextBlocks();
979
980signals:
986
992};
993
994#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:137
Definition KviInputEditor.h:68
QString szText
Definition KviInputEditor.h:70
bool bCorrect
Definition KviInputEditor.h:74
qsizetype iLength
Definition KviInputEditor.h:72
qsizetype iStart
Definition KviInputEditor.h:71
bool bSpellCheckable
Definition KviInputEditor.h:73
Holds the command used in the {un,re}do operations.
Definition KviInputEditor.h:161
QString m_szText
The text of the command.
Definition KviInputEditor.h:184
void setText(const QString &szText)
Sets the text of the command.
Definition KviInputEditor.h:222
Type
Defines the type of the command.
Definition KviInputEditor.h:168
@ InsertText
Definition KviInputEditor.h:169
void setStartPosition(int iStartPosition)
Sets the start position.
Definition KviInputEditor.h:210
const Type & type() const
Returns the type of the command.
Definition KviInputEditor.h:241
Type m_eType
The type of the command.
Definition KviInputEditor.h:178
void setType(const Type &eType)
Sets the type of the command.
Definition KviInputEditor.h:235
int m_iStartPosition
The start position.
Definition KviInputEditor.h:190
EditCommand(Type eType, const QString &szText, int iStartPosition)
Constructs the command object.
Definition KviInputEditor.h:200
int startPosition() const
Returns the start position.
Definition KviInputEditor.h:216
const QString & text() const
Returns the text of the command.
Definition KviInputEditor.h:228
Input editor class.
Definition KviInputEditor.h:84
QString m_szLastCompletionBuffer
Definition KviInputEditor.h:144
bool m_bUpdatesEnabled
Definition KviInputEditor.h:148
int m_iCursorWidth
Definition KviInputEditor.h:118
int m_iIMStart
Definition KviInputEditor.h:122
std::vector< std::unique_ptr< EditCommand > > m_UndoStack
The undo stack.
Definition KviInputEditor.h:251
int m_iLastCompletionCursorPosition
Definition KviInputEditor.h:145
QMenu m_SpellCheckerPopup
Definition KviInputEditor.h:153
KviWindow * m_pKviWindow
Definition KviInputEditor.h:150
int m_iIMLength
Definition KviInputEditor.h:123
void enterPressed()
Called when the user press enter/return.
QString m_szTextBuffer
Definition KviInputEditor.h:111
bool isUndoAvailable() const
Returns true is there are some action in the undo stack.
Definition KviInputEditor.h:503
bool isReadOnly() const
Returns true if the input line is in read only state.
Definition KviInputEditor.h:327
int m_iMaxBufferSize
Definition KviInputEditor.h:116
int m_iCurHistoryIdx
Definition KviInputEditor.h:137
int m_iSelectionEnd
Definition KviInputEditor.h:115
bool m_bLastCompletionFinished
Definition KviInputEditor.h:146
static int g_iCachedHeight
Definition KviInputEditor.h:110
void setMaxBufferSize(int iSize)
Sets the maximum buffer size.
Definition KviInputEditor.h:314
static QFontMetrics * g_pLastFontMetrics
Definition KviInputEditor.h:108
int m_iCursorPosition
Definition KviInputEditor.h:112
bool m_bReadOnly
Definition KviInputEditor.h:154
int m_iCursorTimer
Definition KviInputEditor.h:130
void setReadOnly(bool bReadOnly)
Sets the read only state for the input line.
Definition KviInputEditor.h:321
QString m_szIMText
Definition KviInputEditor.h:121
int m_iSelectionBegin
Definition KviInputEditor.h:114
KviInputEditorPrivate * m_p
Definition KviInputEditor.h:262
QString text() const
Returns the text in the buffer.
Definition KviInputEditor.h:282
int m_iSpellCheckPosition
Definition KviInputEditor.h:113
bool m_bCursorOn
Definition KviInputEditor.h:128
QString m_szLastCompletedNick
Definition KviInputEditor.h:143
int m_iSelectionAnchorChar
Definition KviInputEditor.h:133
bool isRedoAvailable() const
Returns true is there are some action in the redo stack.
Definition KviInputEditor.h:509
int m_iDragTimer
Definition KviInputEditor.h:131
KviCString m_szSaveTextBuffer
Definition KviInputEditor.h:139
QWidget * m_pInputParent
Definition KviInputEditor.h:151
KviCString m_szAltKeyCode
Definition KviInputEditor.h:149
bool m_bSpSlowFlag
Definition KviInputEditor.h:117
static int g_iInputInstances
Definition KviInputEditor.h:109
std::vector< std::unique_ptr< EditCommand > > m_RedoStack
The redo stack.
Definition KviInputEditor.h:260
int m_iIMSelectionLength
Definition KviInputEditor.h:125
bool m_bIMComposing
Definition KviInputEditor.h:126
void escapePressed()
Called when the user press escape.
std::vector< QString > m_History
Definition KviInputEditor.h:136
int m_iIMSelectionBegin
Definition KviInputEditor.h:124
KviUserListView * m_pUserListView
Definition KviInputEditor.h:142
QMenu * m_pIconMenu
Definition KviInputEditor.h:152
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