KVIrc  4.9.2
DeveloperAPIs
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 // This file was originally part of KviInput.h
27 //============================================================================
28 
43 #include "kvi_settings.h"
44 #include "KviPointerList.h"
45 #include "KviCString.h"
46 #include "KviWindow.h"
47 
48 #include <QMenu>
49 #include <QString>
50 #include <QWidget>
51 
52 class QKeyEvent;
53 class QDragEnterEvent;
54 class QFontMetricsF;
55 class KviUserListView;
56 
57 #define KVI_INPUT_MAX_BUFFER_SIZE 400
58 #define KVI_INPUT_XTRAPADDING 1
59 #define KVI_INPUT_MARGIN 4
60 #define KVI_INPUT_BLINK_TIME 800
61 #define KVI_INPUT_DRAG_TIMEOUT 80
62 #define KVI_INPUT_DEF_BACK 100
63 #define KVI_INPUT_DEF_FORE 101
64 
65 #ifndef ACCEL_KEY
66 #define ACCEL_KEY(k) "\t" + QKeySequence(Qt::ControlModifier | Qt::Key_##k).toString()
67 #endif
68 
70 {
71 public:
72  QString szText;
73  int iStart;
74  int iLength;
76  bool bCorrect;
77 };
78 
80 
85 class KVIRC_API KviInputEditor : public QWidget
86 {
87  //Q_PROPERTY(int KviProperty_FocusOwner READ heightHint)
88  Q_PROPERTY(int TransparencyCapable READ heightHint)
89  Q_OBJECT
90  friend class KviTextIconWindow; // it uses insetIconCode(const QString &)
91  friend class KviTopicWidget; // it uses home()
92 public:
100  KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView * pView = 0);
101 
105  ~KviInputEditor();
106 
107 protected:
108  static int g_iInputFontCharWidth[256];
109  static QFontMetricsF * g_pLastFontMetrics;
110  static int g_iInputInstances;
111  static int g_iCachedHeight;
112  QString m_szTextBuffer; // original buffer
117  bool m_bSpSlowFlag; // <-- what is this ?
119 
120  // members for supporting input methods
121  QString m_szIMText;
127 
129 
132 
134 
135  // History stuff
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 
252 
261 
263 
264 public:
269  int heightHint() const;
270 
276  void setText(const QString szText);
277 
282  QString text() { return m_szTextBuffer; };
283 
287  QString textBeforeCursor();
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 
334 private:
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 
452  void completion(bool bShift);
453 
462  void standardNickCompletion(bool bAddMask, QString & szWord, bool bFirstWordInLine, bool bInCommand);
463 
472  void standardNickCompletionInsertCompletedText(const QString & szReplacedWord, const QString & szCompletedText, bool bFirstWordInLine, bool bInCommand);
473 
479  void internalCursorRight(bool bShift);
480 
486  void internalCursorLeft(bool bShift);
487 
492  inline bool isUndoAvailable() const { return !m_bReadOnly && m_pUndoStack; }
493 
498  inline bool isRedoAvailable() const { return !m_bReadOnly && m_pRedoStack; }
499 
505  void addUndo(EditCommand * pCommand);
506 
512  QFontMetricsF * getLastFontMetrics(const QFont & font);
513 
514 public slots:
520  void iconPopupActivated(QAction * pAction);
521 
530  void copyToSelection(bool bDonNotCopyToClipboard = true);
531 
536  void copyToClipboard();
537 
542  void removeSelected();
543 
548  void cut();
549 
554  void undo();
555 
560  void redo();
561 
566  void pasteClipboardWithConfirmation();
567 
575  void pasteSelectionWithConfirmation();
576 
581  void pasteSlow();
582 
587  void stopPasteSlow();
588 
593  void pasteFile();
594 
599  void selectAll();
600 
605  void clear();
606 private slots:
611  void openHistory();
612 
617  void toggleMultiLineEditor();
618 
623  void previousChar();
624 
629  void nextChar();
630 
635  void previousCharSelection();
636 
641  void nextCharSelection();
642 
647  void previousWord();
648 
653  void nextWord();
654 
659  void previousWordSelection();
660 
665  void nextWordSelection();
666 
671  void insertBold();
672 
677  void insertReset();
678 
683  void insertUnderline();
684 
689  void insertReverse();
690 
695  void insertPlainText();
696 
701  void insertIcon();
702 
707  void insertColor();
708 
713  void copyInternal();
714 
719  void cutInternal();
720 
725  void pasteInternal();
726 
731  void undoInternal();
732 
737  void redoInternal();
738 
743  void selectAllInternal();
744 
749  void deletePreviousWord();
750 
755  void deleteNextWord();
756 
761  void previousLine();
762 
767  void nextLine();
768 
773  void previousPage();
774 
779  void nextPage();
780 
785  void search();
786 
791  void scrollToLastReadLine();
792 
797  void sendPlain();
798 
803  void sendKvs();
804 
809  void homeInternal();
810 
815  void endInternal();
816 
821  void homeInternalSelection();
822 
827  void endInternalSelection();
828 
833  void historyPrev();
834 
839  void historyNext();
840 
845  void returnHit();
846 
851  void backspaceHit();
852 
857  void deleteHit();
858 
863  void escapeHit();
864 
869  void toggleCommandMode();
870 
876  void dummy();
877 
882  void zoomIn();
883 
888  void zoomOut();
889 
894  void zoomDefault();
895 
899  void popupTextIconWindow();
900 
904  void showContextPopup(const QPoint & pos);
905 
909  void showContextPopupHere();
910 
914  void showSpellCheckerCorrectionsPopup();
915 
919  void spellCheckerPopupCorrectionActionTriggered();
920 
921 protected:
922  void insertIconCode(const QString & szCode);
923  void completionEscapeUnsafeToken(QString & szToken);
924  void installShortcuts();
925  virtual void drawContents(QPainter *);
926  //virtual void resizeEvent(QResizeEvent * e);
927  virtual void timerEvent(QTimerEvent * e);
928  virtual void focusInEvent(QFocusEvent * e);
929  virtual void focusOutEvent(QFocusEvent * e);
930  virtual void keyPressEvent(QKeyEvent * e);
931  virtual void keyReleaseEvent(QKeyEvent * e);
932  virtual void mousePressEvent(QMouseEvent * e);
933  virtual void mouseReleaseEvent(QMouseEvent * e);
934  virtual void mouseDoubleClickEvent(QMouseEvent * e);
935  virtual void dragEnterEvent(QDragEnterEvent * e);
936  virtual void dropEvent(QDropEvent * e);
937  virtual void inputMethodEvent(QInputMethodEvent * e);
938  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
939  virtual void paintEvent(QPaintEvent * e);
940  bool checkWordSpelling(const QString & szWord);
941  void splitTextIntoSpellCheckerBlocks(const QString & szText, KviPointerList<KviInputEditorSpellCheckerBlock> & lBuffer);
942  KviInputEditorSpellCheckerBlock * findSpellCheckerBlockAtCursor(KviPointerList<KviInputEditorSpellCheckerBlock> & lBlocks);
943  void fillSpellCheckerCorrectionsPopup();
944 
945  void rebuildTextBlocks();
946 
947 signals:
952  void escapePressed();
953 
958  void enterPressed();
959 };
960 
961 #endif //_KVI_INPUT_EDITOR_H_
bool bSpellCheckable
Definition: KviInputEditor.h:75
int iLength
Definition: KviInputEditor.h:74
QString m_szIMText
Definition: KviInputEditor.h:121
int m_iIMSelectionBegin
Definition: KviInputEditor.h:124
Definition: KviCString.h:105
void setReadOnly(bool bReadOnly)
Sets the read only state for the input line.
Definition: KviInputEditor.h:321
int m_iIMSelectionLength
Definition: KviInputEditor.h:125
#define KVIRC_API
Definition: kvi_settings.h:128
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
const QString & text() const
Returns the text of the command.
Definition: KviInputEditor.h:228
KviPointerList< EditCommand > * m_pUndoStack
The undo stack.
Definition: KviInputEditor.h:251
Input editor class.
Definition: KviInputEditor.h:85
void setMaxBufferSize(int iSize)
Sets the maximum buffer size.
Definition: KviInputEditor.h:314
static int g_iCachedHeight
Definition: KviInputEditor.h:111
int m_iSelectionEnd
Definition: KviInputEditor.h:115
static QFontMetricsF * g_pLastFontMetrics
Definition: KviInputEditor.h:109
QString m_szText
The text of the command.
Definition: KviInputEditor.h:184
QString m_szLastCompletionBuffer
Definition: KviInputEditor.h:144
QString m_szTextBuffer
Definition: KviInputEditor.h:112
int m_iMaxBufferSize
Definition: KviInputEditor.h:116
Holds the command used in the {un,re}do operations.
Definition: KviInputEditor.h:160
static int g_iInputInstances
Definition: KviInputEditor.h:110
QString text()
Returns the text in the buffer.
Definition: KviInputEditor.h:282
int m_iIMLength
Definition: KviInputEditor.h:123
int m_iCursorPosition
Definition: KviInputEditor.h:113
#define e
Definition: detector.cpp:69
bool m_bLastCompletionFinished
Definition: KviInputEditor.h:146
Definition: KviInputEditor.h:69
KviInputEditorPrivate * m_p
Definition: KviInputEditor.h:262
bool isUndoAvailable() const
Returns true is there are some action in the undo stack.
Definition: KviInputEditor.h:492
int m_iCurHistoryIdx
Definition: KviInputEditor.h:137
void setType(const Type &eType)
Sets the type of the command.
Definition: KviInputEditor.h:235
bool m_bIMComposing
Definition: KviInputEditor.h:126
btnDict clear()
int m_iDragTimer
Definition: KviInputEditor.h:131
void setStartPosition(int iStartPosition)
Sets the start position.
Definition: KviInputEditor.h:210
int m_iLastCompletionCursorPosition
Definition: KviInputEditor.h:145
Definition: KviInputEditor.cpp:124
Text icon window class.
Definition: KviTextIconWindow.h:50
bool m_bUpdatesEnabled
Definition: KviInputEditor.h:148
KviCString m_szSaveTextBuffer
Definition: KviInputEditor.h:139
KviPointerList< EditCommand > * m_pRedoStack
The redo stack.
Definition: KviInputEditor.h:260
KviCString m_szAltKeyCode
Definition: KviInputEditor.h:149
bool m_bSpSlowFlag
Definition: KviInputEditor.h:117
EditCommand(Type eType, const QString &szText, int iStartPosition)
Contructs the command object.
Definition: KviInputEditor.h:200
Definition: KviInputEditor.h:169
void setText(const QString &szText)
Sets the text of the command.
Definition: KviInputEditor.h:222
bool isRedoAvailable() const
Returns true is there are some action in the redo stack.
Definition: KviInputEditor.h:498
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
QString szText
Definition: KviInputEditor.h:72
bool isReadOnly() const
Returns true if the input line is in read only state.
Definition: KviInputEditor.h:327
KviUserListView * m_pUserListView
Definition: KviInputEditor.h:142
int startPosition() const
Returns the start position.
Definition: KviInputEditor.h:216
KviPointerList< QString > * m_pHistory
Definition: KviInputEditor.h:136
QWidget * m_pInputParent
Definition: KviInputEditor.h:151
KviWindow * m_pKviWindow
Definition: KviInputEditor.h:150
QMenu * m_pIconMenu
Definition: KviInputEditor.h:152
const Type & type() const
Returns the type of the command.
Definition: KviInputEditor.h:241
QMenu m_SpellCheckerPopup
Definition: KviInputEditor.h:153
Contains the KviWindow class.
char szBuffer[4096]
Definition: winamp.cpp:77
Type
Defines the type of the command.
Definition: KviInputEditor.h:167
QString m_szLastCompletedNick
Definition: KviInputEditor.h:143
int m_iCursorTimer
Definition: KviInputEditor.h:130
Definition: KviTopicWidget.h:65
int m_iCursorWidth
Definition: KviInputEditor.h:118
This file contains compile time settings.
int m_iStartPosition
The start position.
Definition: KviInputEditor.h:190
User list view management class.
Definition: KviUserListView.h:226
int m_iIMStart
Definition: KviInputEditor.h:122
int iStart
Definition: KviInputEditor.h:73
bool m_bReadOnly
Definition: KviInputEditor.h:154
int m_iSelectionBegin
Definition: KviInputEditor.h:114
bool bCorrect
Definition: KviInputEditor.h:76
int m_iSelectionAnchorChar
Definition: KviInputEditor.h:133
Type m_eType
The type of the command.
Definition: KviInputEditor.h:178
bool m_bCursorOn
Definition: KviInputEditor.h:128