diff options
| author | 2010-05-19 02:32:19 +0000 | |
|---|---|---|
| committer | 2010-05-19 02:32:19 +0000 | |
| commit | cb8c6720b0ed61020c191884fde8833bc867f1b9 (patch) | |
| tree | 2bc1a97b5829e4debdc83edad162d236bdc43db8 /src | |
| parent | updated spanish translations; translated by and thanks to egns (@freenode) (diff) | |
| download | KVIrc-cb8c6720b0ed61020c191884fde8833bc867f1b9.tar.gz KVIrc-cb8c6720b0ed61020c191884fde8833bc867f1b9.tar.bz2 KVIrc-cb8c6720b0ed61020c191884fde8833bc867f1b9.zip | |
more work on global shortcuts;
fixed the selection with home/end buttons;
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4342 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/config/kvi_shortcuts.h | 31 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_input_editor.cpp | 229 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_input_editor.h | 42 |
3 files changed, 196 insertions, 106 deletions
diff --git a/src/kvilib/config/kvi_shortcuts.h b/src/kvilib/config/kvi_shortcuts.h index 6abac74b6..39fb268a9 100644 --- a/src/kvilib/config/kvi_shortcuts.h +++ b/src/kvilib/config/kvi_shortcuts.h @@ -34,7 +34,7 @@ * \brief Keyboard shortcuts * * \def KVI_SHORTCUTS_HELP Help Index (Window) -* \def KVI_SHORTCUTS_EDITOR_SELECTALL Select all +* \def KVI_SHORTCUTS_EDITOR_SELECT_ALL Select all * \def KVI_SHORTCUTS_EDITOR_BOLD Insert the 'bold' mIRC text control character * \def KVI_SHORTCUTS_EDITOR_COPY Copy the selected text to clipboard * \def KVI_SHORTCUTS_WIN_SEARCH Open "Find Text" dialog @@ -48,7 +48,7 @@ * \def KVI_SHORTCUTS_SERVERS Open "Servers" dialog * \def KVI_SHORTCUTS_EDITOR_UNDERLINE Insert the 'underline' mIRC text control character * \def KVI_SHORTCUTS_EDITOR_PASTE Paste the clipboard contents (same as middle mouse click) -* \def KVI_SHORTCUTS_EDITOR_PASTE2 Paste the clipboard contents (same as middle mouse click) +* \def KVI_SHORTCUTS_EDITOR_PASTE_2 Paste the clipboard contents (same as middle mouse click) Ctrl+W:[/b] Close current window * \def KVI_SHORTCUTS_EDITOR_CUT Cut the selected text and copy the text to clipboard * \def KVI_SHORTCUTS_EDITOR_UNDO Undo last action @@ -87,16 +87,22 @@ * \def KVI_SHORTCUTS_EDITOR_NEXT_WORD_SELECT Select up to the end of the next word Ctrl+<digit>:[/b] Script accelerators (see OnAccelKeyPressed) F2-F12, Shift+(F1-F12):[/b] Script accelerators (see OnAccelKeyPressed) - CursorUp:[/b] Move backward in the command history +* \def KVI_SHORTCUTS_EDITOR_HISTORY_PREV Move backward in the command history CursorDown:[/b] Move forward in the command history * \def KVI_SHORTCUTS_EDITOR_HISTORY Open the history popup * \def KVI_SHORTCUTS_EDITOR_PREV_CHAR Move the cursor to the left * \def KVI_SHORTCUTS_EDITOR_NEXT_CHAR Move the cursor to the right * \def KVI_SHORTCUTS_EDITOR_PREV_CHAR_SELECT Move the selection to the left * \def KVI_SHORTCUTS_EDITOR_NEXT_CHAR_SELECT Move the selection to the right -* \def KVI_SHORTCUTS_EDITOR_DELETEWORD Delete last word +* \def KVI_SHORTCUTS_EDITOR_DELETE_WORD Delete last word * \def KVI_SHORTCUTS_MULTILINE_OPEN Show/hide the multiline editor - Ctrl+Enter:[/b] Send message as plain text, ignoring / commands[br] +* \def KVI_SHORTCUTS_EDITOR_SEND_PLAIN Send message as plain text, ignoring / commands +* \def KVI_SHORTCUTS_EDITOR_SEND_PLAIN_2 Send message as plain text, ignoring / commands +* \def KVI_SHORTCUTS_EDITOR_HOME Move the cursos at the beginning +* \def KVI_SHORTCUTS_EDITOR_END Move the cursos at the end +* \def KVI_SHORTCUTS_EDITOR_HOME_SELECT Select until the beginning +* \def KVI_SHORTCUTS_EDITOR_END_SELECT Select until the end + Alt+<numeric_sequence>:[/b] Insert the character by ASCII/Unicode code[br] [example] Alt+32:[/b] Inserts ASCII/Unicode character 32: ' ' (a space) @@ -112,7 +118,7 @@ Shift+Tab after the first word of input:[/b] Complete nicknames with full mask in the current channel or query */ #define KVI_SHORTCUTS_HELP "F1" -#define KVI_SHORTCUTS_EDITOR_SELECTALL "Ctrl+A" +#define KVI_SHORTCUTS_EDITOR_SELECT_ALL "Ctrl+A" #define KVI_SHORTCUTS_EDITOR_BOLD "Ctrl+B" #define KVI_SHORTCUTS_EDITOR_COPY "Ctrl+C" #define KVI_SHORTCUTS_WIN_SEARCH "Ctrl+F" @@ -153,7 +159,7 @@ #define KVI_SHORTCUTS_WIN_NEXT_HIGHLIGHT Qt::AltModifier + Qt::Key_PageDown #define KVI_SHORTCUTS_WIN_MAXIMIZE Qt::ControlModifier + Qt::Key_Up #define KVI_SHORTCUTS_WIN_MINIMIZE Qt::ControlModifier + Qt::Key_Down -#define KVI_SHORTCUTS_EDITOR_PASTE2 Qt::ShiftModifier + Qt::Key_Insert +#define KVI_SHORTCUTS_EDITOR_PASTE_2 Qt::ShiftModifier + Qt::Key_Insert // Shift+<F1-F12>:[/b] window switch[br] #define KVI_SHORTCUTS_WIN_PREV_PAGE Qt::Key_PageUp #define KVI_SHORTCUTS_WIN_NEXT_PAGE Qt::Key_PageDown @@ -172,9 +178,16 @@ #define KVI_SHORTCUTS_EDITOR_NEXT_CHAR Qt::Key_Right #define KVI_SHORTCUTS_EDITOR_PREV_CHAR_SELECT Qt::ShiftModifier + Qt::Key_Left #define KVI_SHORTCUTS_EDITOR_NEXT_CHAR_SELECT Qt::ShiftModifier + Qt::Key_Right -#define KVI_SHORTCUTS_EDITOR_DELETEWORD Qt::ControlModifier + Qt::Key_Backspace +#define KVI_SHORTCUTS_EDITOR_DELETE_WORD Qt::ControlModifier + Qt::Key_Backspace #define KVI_SHORTCUTS_MULTILINE_OPEN Qt::AltModifier + Qt::Key_Return -// Ctrl+Enter:[/b] Send message as plain text, ignoring / commands[br] +#define KVI_SHORTCUTS_EDITOR_SEND_PLAIN Qt::ControlModifier + Qt::Key_Return +#define KVI_SHORTCUTS_EDITOR_SEND_PLAIN_2 Qt::ControlModifier + Qt::Key_Enter +#define KVI_SHORTCUTS_EDITOR_HOME Qt::Key_Home +#define KVI_SHORTCUTS_EDITOR_END Qt::Key_End +#define KVI_SHORTCUTS_EDITOR_HOME_SELECT Qt::ShiftModifier + Qt::Key_Home +#define KVI_SHORTCUTS_EDITOR_END_SELECT Qt::ShiftModifier + Qt::Key_End + + // Alt+<numeric_sequence>:[/b] Insert the character by ASCII/Unicode code[br] // [example] // Alt+32:[/b] Inserts ASCII/Unicode character 32: ' ' (a space) diff --git a/src/kvirc/ui/kvi_input_editor.cpp b/src/kvirc/ui/kvi_input_editor.cpp index 3e7ca8c43..ae9aa6867 100644 --- a/src/kvirc/ui/kvi_input_editor.cpp +++ b/src/kvirc/ui/kvi_input_editor.cpp @@ -1282,16 +1282,22 @@ void KviInputEditor::installShortcuts() new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_COPY),this,SLOT(copyInternal()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_CUT),this,SLOT(cutInternal()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_PASTE),this,SLOT(pasteInternal()),0,Qt::WidgetShortcut); - new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_PASTE2),this,SLOT(pasteInternal()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_PASTE_2),this,SLOT(pasteInternal()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_UNDO),this,SLOT(undoInternal()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_REDO),this,SLOT(redoInternal()),0,Qt::WidgetShortcut); - new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_SELECTALL),this,SLOT(selectAllInternal()),0,Qt::WidgetShortcut); - new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_DELETEWORD),this,SLOT(deleteWord()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_SELECT_ALL),this,SLOT(selectAllInternal()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_DELETE_WORD),this,SLOT(deleteWord()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_WIN_PREV_LINE),this,SLOT(previousLine()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_WIN_NEXT_LINE),this,SLOT(nextLine()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_WIN_PREV_PAGE),this,SLOT(previousPage()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_WIN_NEXT_PAGE),this,SLOT(nextPage()),0,Qt::WidgetShortcut); new QShortcut(QKeySequence(KVI_SHORTCUTS_WIN_SEARCH),this,SLOT(search()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_SEND_PLAIN),this,SLOT(sendPlain()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_SEND_PLAIN_2),this,SLOT(sendPlain()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_HOME),this,SLOT(homeInternal()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_END),this,SLOT(endInternal()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_HOME_SELECT),this,SLOT(homeInternalSelection()),0,Qt::WidgetShortcut); + new QShortcut(QKeySequence(KVI_SHORTCUTS_EDITOR_END_SELECT),this,SLOT(endInternalSelection()),0,Qt::WidgetShortcut); } void KviInputEditor::keyPressEvent(QKeyEvent * e) @@ -1337,29 +1343,6 @@ void KviInputEditor::keyPressEvent(QKeyEvent * e) //avoid Ctrl+J from inserting a linefeed break; } - case Qt::Key_Return: - case Qt::Key_Enter: - if(m_pInputParent->inherits("KviInput")) - { - QString szBuffer(m_szTextBuffer); - m_szTextBuffer=""; - selectOneChar(-1); - m_iCursorPosition = 0; - m_iFirstVisibleChar = 0; - repaintWithCursorOn(); - KviUserInput::parseNonCommand(szBuffer,m_pKviWindow); - if (!szBuffer.isEmpty()) - { - KviInputHistory::instance()->add(new QString(szBuffer)); - m_pHistory->insert(0,new QString(szBuffer)); - } - - __range_valid(KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES > 1); //ABSOLUTELY NEEDED, if not, pHist will be destroyed... - if(m_pHistory->count() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES)m_pHistory->removeLast(); - - m_iCurHistoryIdx = -1; - } - break; default: if(!m_bReadOnly) insertText(e->text()); break; @@ -1419,77 +1402,6 @@ void KviInputEditor::keyPressEvent(QKeyEvent * e) } } break; - case Qt::Key_Home: - if(m_iCursorPosition > 0) - { - if(e->modifiers() & Qt::ShiftModifier) - { - if((m_iSelectionBegin == -1)&&(m_iSelectionEnd == -1))m_iSelectionEnd = m_iCursorPosition - 1; - m_iSelectionBegin = 0; - } else { - selectOneChar(-1); - } - home(); - } - break; - case Qt::Key_End://we should call it even the cursor is at the end for deselecting - if(e->modifiers() & Qt::ShiftModifier) - { - if((m_iSelectionBegin == -1)&&(m_iSelectionEnd == -1))m_iSelectionBegin = m_iCursorPosition; - m_iSelectionEnd = m_szTextBuffer.length()-1; - } else { - selectOneChar(-1); - } - end(); - break; - case Qt::Key_Up: - if(!m_bReadOnly) - { - if(m_pHistory->count() > 0) - { - if(m_iCurHistoryIdx < 0) - { - m_szSaveTextBuffer = m_szTextBuffer; - m_szTextBuffer = *(m_pHistory->at(0)); - m_iCurHistoryIdx = 0; - } else if(m_iCurHistoryIdx >= (int)(m_pHistory->count()-1)) - { - m_szTextBuffer=m_szSaveTextBuffer; - m_iCurHistoryIdx = -1; - } else { - m_iCurHistoryIdx++; - m_szTextBuffer = *(m_pHistory->at(m_iCurHistoryIdx)); - } - selectOneChar(-1); - if(KVI_OPTION_BOOL(KviOption_boolInputHistoryCursorAtEnd))end(); - else home(); - } - } - break; - case Qt::Key_Down: - if(!m_bReadOnly) - { - if(m_pHistory->count() > 0) - { - if(m_iCurHistoryIdx < 0) - { - m_szSaveTextBuffer = m_szTextBuffer; - m_szTextBuffer = *(m_pHistory->at(m_pHistory->count()-1)); - m_iCurHistoryIdx =m_pHistory->count()-1; - } else if(m_iCurHistoryIdx == 0) - { - m_szTextBuffer=m_szSaveTextBuffer; - m_iCurHistoryIdx = -1; - } else { - m_iCurHistoryIdx--; - m_szTextBuffer = *(m_pHistory->at(m_iCurHistoryIdx)); - } - selectOneChar(-1); - if(KVI_OPTION_BOOL(KviOption_boolInputHistoryCursorAtEnd))end(); - else home(); - } - } - break; case Qt::Key_Return: case Qt::Key_Enter: returnPressed(); @@ -2355,6 +2267,129 @@ void KviInputEditor::search() if(m_pKviWindow->view()) m_pKviWindow->view()->toggleToolWidget(); } +void KviInputEditor::sendPlain() +{ + if(m_pInputParent->inherits("KviInput")) + { + QString szBuffer(m_szTextBuffer); + m_szTextBuffer=""; + selectOneChar(-1); + m_iCursorPosition = 0; + m_iFirstVisibleChar = 0; + repaintWithCursorOn(); + KviUserInput::parseNonCommand(szBuffer,m_pKviWindow); + if (!szBuffer.isEmpty()) + { + KviInputHistory::instance()->add(new QString(szBuffer)); + m_pHistory->insert(0,new QString(szBuffer)); + } + + __range_valid(KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES > 1); //ABSOLUTELY NEEDED, if not, pHist will be destroyed... + if(m_pHistory->count() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES)m_pHistory->removeLast(); + + m_iCurHistoryIdx = -1; + } +} + +void KviInputEditor::homeInternal() +{ + if(m_iCursorPosition > 0) + { + selectOneChar(-1); + home(); + } +} + +void KviInputEditor::homeInternalSelection() +{ + if(m_iCursorPosition > 0) + { + if((m_iSelectionBegin == -1) && (m_iSelectionEnd == -1)) + { + // There is no selection + m_iSelectionEnd = m_iCursorPosition - 1; + } else { + // There is selection + m_iSelectionEnd = m_iSelectionBegin - 1; + } + + m_iSelectionBegin = 0; + home(); + } +} + +void KviInputEditor::endInternal() +{ + selectOneChar(-1); + end(); +} + +void KviInputEditor::endInternalSelection() +{ + if((m_iSelectionBegin == -1) && (m_iSelectionEnd == -1)) + { + // There is no selection + m_iSelectionBegin = m_iCursorPosition; + } else { + // There is selection + m_iSelectionBegin = m_iSelectionEnd+1; + } + + m_iSelectionEnd = m_szTextBuffer.length()-1; + end(); +} + +void KviInputEditor::historyPrev() +{ + if(!m_bReadOnly) + { + if(m_pHistory->count() > 0) + { + if(m_iCurHistoryIdx < 0) + { + m_szSaveTextBuffer = m_szTextBuffer; + m_szTextBuffer = *(m_pHistory->at(0)); + m_iCurHistoryIdx = 0; + } else if(m_iCurHistoryIdx >= (int)(m_pHistory->count()-1)) + { + m_szTextBuffer=m_szSaveTextBuffer; + m_iCurHistoryIdx = -1; + } else { + m_iCurHistoryIdx++; + m_szTextBuffer = *(m_pHistory->at(m_iCurHistoryIdx)); + } + selectOneChar(-1); + if(KVI_OPTION_BOOL(KviOption_boolInputHistoryCursorAtEnd))end(); + else home(); + } + } +} + +void KviInputEditor::historyNext() +{ + if(!m_bReadOnly) + { + if(m_pHistory->count() > 0) + { + if(m_iCurHistoryIdx < 0) + { + m_szSaveTextBuffer = m_szTextBuffer; + m_szTextBuffer = *(m_pHistory->at(m_pHistory->count()-1)); + m_iCurHistoryIdx =m_pHistory->count()-1; + } else if(m_iCurHistoryIdx == 0) + { + m_szTextBuffer=m_szSaveTextBuffer; + m_iCurHistoryIdx = -1; + } else { + m_iCurHistoryIdx--; + m_szTextBuffer = *(m_pHistory->at(m_iCurHistoryIdx)); + } + selectOneChar(-1); + if(KVI_OPTION_BOOL(KviOption_boolInputHistoryCursorAtEnd))end(); + else home(); + } + } +} #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "kvi_input_editor.moc" diff --git a/src/kvirc/ui/kvi_input_editor.h b/src/kvirc/ui/kvi_input_editor.h index 5d35bc644..1a6e039ce 100644 --- a/src/kvirc/ui/kvi_input_editor.h +++ b/src/kvirc/ui/kvi_input_editor.h @@ -729,6 +729,48 @@ private slots: * \return void */ void search(); + + /** + * \brief Sends plain text, ignoring initial token starting with / (a command) + * \return void + */ + void sendPlain(); + + /** + * \brief Moves the cursor at the beginning + * \return void + */ + void homeInternal(); + + /** + * \brief Moves the cursor at the end + * \return void + */ + void endInternal(); + + /** + * \brief Selects until the beginning + * \return void + */ + void homeInternalSelection(); + + /** + * \brief Selects until the end + * \return void + */ + void endInternalSelection(); + + /** + * \brief Moves backward in the command history + * \return void + */ + void historyPrev(); + + /** + * \brief Moves forward in the command history + * \return void + */ + void historyNext(); protected: void installShortcuts(); |
