QTfrontend/ui/widget/SmartLineEdit.cpp
author sheepluva
Wed, 19 Oct 2011 02:10:27 +0200
changeset 6150 1d98752c1fba
parent 6149 0b92341adb6a
child 6151 9fd5b70acb1a
permissions -rw-r--r--
frontend chat input history, use arrow keys UP/DOWN
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     1
/*
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     3
 * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     4
 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     5
 *
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
     9
 *
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    13
 * GNU General Public License for more details.
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    14
 *
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    18
 */
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    19
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    20
#include <QStringList>
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    21
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    22
#include "SmartLineEdit.h"
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    23
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    24
SmartLineEdit::SmartLineEdit(QWidget * parent, int maxHistorySize)
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    25
: QLineEdit(parent)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    26
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    27
    m_curHistEntryIdx = 0;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    28
    m_maxHistorySize = maxHistorySize;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    29
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    30
    m_whitespace = QRegExp("\\s");
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    31
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    32
    m_cmds  = new QStringList();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    33
    m_nicks = new QStringList();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    34
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    35
    m_history = new QStringList();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    36
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    37
    resetAutoCompletionStatus();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    38
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    39
    // reset autocompletion status when cursor is moved or content is changed
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    40
    connect(this, SIGNAL(cursorPositionChanged(int, int)),
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    41
            this, SLOT(resetAutoCompletionStatus()));
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    42
    connect(this, SIGNAL(textChanged(const QString&)),
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
    43
            this, SLOT(resetAutoCompletionStatus()));
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    44
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    45
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    46
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    47
void SmartLineEdit::addCommands(const QStringList & commands)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    48
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    49
    m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    50
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    51
    m_cmds->append(commands);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    52
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    53
    m_keywordMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    54
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    55
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    56
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    57
void SmartLineEdit::removeCommands(const QStringList & commands)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    58
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    59
    m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    60
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    61
    foreach (const QString & cmd, commands)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    62
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    63
        m_cmds->removeAll(cmd);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    64
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    65
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    66
    m_keywordMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    67
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    68
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    69
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    70
void SmartLineEdit::addNickname(const QString & name)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    71
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    72
    m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    73
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    74
    m_nicks->append(name);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    75
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    76
    m_keywordMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    77
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    78
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    79
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    80
void SmartLineEdit::removeNickname(const QString & name)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    81
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    82
    m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    83
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    84
    m_nicks->removeAll(name);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
    85
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    86
    m_keywordMutex.unlock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    87
}
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    88
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    89
void SmartLineEdit::rememberCurrentText()
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    90
{
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    91
    m_historyMutex.lock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    92
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    93
    rememberCurrentTextUnsynced();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    94
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    95
    m_historyMutex.unlock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    96
}
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    97
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    98
void SmartLineEdit::rememberCurrentTextUnsynced()
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
    99
{
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   100
    QString newEntry = text();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   101
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   102
    // don't store whitespace-only/empty text
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   103
    if (newEntry.trimmed().isEmpty())
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   104
        return;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   105
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   106
    m_history->removeOne(newEntry); // no duplicates please
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   107
    m_history->append(newEntry);
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   108
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   109
    // do not keep more entries than allowed
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   110
    if (m_history->size() > m_maxHistorySize)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   111
        m_history->removeFirst();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   112
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   113
    // we're looking at the latest entry
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   114
    m_curHistEntryIdx = m_history->size() - 1;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   115
}
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   116
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   117
void SmartLineEdit::clear()
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   118
{
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   119
    m_historyMutex.lock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   120
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   121
    QLineEdit::clear();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   122
    m_curHistEntryIdx = m_history->size();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   123
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   124
    m_historyMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   125
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   126
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   127
void SmartLineEdit::forgetEverything()
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   128
{
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   129
    // forget keywords
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   130
    m_keywordMutex.lock();
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   131
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   132
    m_cmds->clear();
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   133
    m_nicks->clear();
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   134
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   135
    m_keywordMutex.unlock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   136
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   137
    // forget history
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   138
    m_historyMutex.lock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   139
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   140
    m_history->clear();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   141
    m_curHistEntryIdx = 0;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   142
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   143
    m_historyMutex.unlock();
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   144
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   145
    resetAutoCompletionStatus();
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   146
}
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   147
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   148
void SmartLineEdit::navigateHistory(bool isGoingUp)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   149
{
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   150
    m_historyMutex.lock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   151
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   152
    // save possible changes to new entry
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   153
    if ((m_curHistEntryIdx >= m_history->size() ||
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   154
        (text() != m_history->at(m_curHistEntryIdx))))
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   155
        {
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   156
            rememberCurrentTextUnsynced();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   157
        }
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   158
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   159
    if (isGoingUp)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   160
        m_curHistEntryIdx--;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   161
    else
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   162
        m_curHistEntryIdx++;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   163
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   164
    // if Idx higher than valid range
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   165
    if (m_curHistEntryIdx >= m_history->size())
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   166
    {
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   167
        QLineEdit::clear();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   168
        m_curHistEntryIdx = m_history->size();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   169
    }
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   170
    // if Idx in valid range
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   171
    else if (m_curHistEntryIdx >= 0)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   172
    {
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   173
        setText(m_history->at(m_curHistEntryIdx));
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   174
    }
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   175
    // if Idx below 0
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   176
    else
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   177
        m_curHistEntryIdx = 0;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   178
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   179
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   180
    m_historyMutex.unlock();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   181
}
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   182
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   183
bool SmartLineEdit::event(QEvent * event)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   184
{
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   185
    // we only want special treatment for key press events
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   186
    if (event->type() == QEvent::KeyPress)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   187
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   188
        QKeyEvent * keyEvent = static_cast<QKeyEvent*>(event);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   189
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   190
        // TAB key pressed and any useful chars in the matchMe -> let's process those
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   191
        if ((keyEvent->key() == Qt::Key_Tab) && (!text().trimmed().isEmpty()))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   192
        {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   193
            keyPressEvent(keyEvent);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   194
            if (event->isAccepted())
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   195
                return true;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   196
        }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   197
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   198
    return QLineEdit::event(event);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   199
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   200
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   201
void SmartLineEdit::keyPressEvent(QKeyEvent * event)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   202
{
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   203
    int key = event->key(); // retrieve pressed key
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   204
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   205
    // auto-complete on pressed TAB (except for whitespace-only contents)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   206
    if ((key == Qt::Key_Tab) && (!text().trimmed().isEmpty()))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   207
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   208
        autoComplete();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   209
        event->accept();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   210
    }
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   211
    // clear contents on pressed ESC, navigate history with arrow keys
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   212
    else if (event->modifiers() == Qt::NoModifier)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   213
        switch (key)
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   214
        {
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   215
            case Qt::Key_Escape:
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   216
                clear();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   217
                event->accept();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   218
                break;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   219
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   220
            case Qt::Key_Up:
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   221
                navigateHistory(true);
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   222
                event->accept();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   223
                break;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   224
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   225
            case Qt::Key_Down:
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   226
                navigateHistory(false);
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   227
                event->accept();
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   228
                break;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   229
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   230
            default:
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   231
                QLineEdit::keyPressEvent(event);
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   232
                break;
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   233
        }
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   234
    // otherwise forward keys to parent
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   235
    else
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   236
        QLineEdit::keyPressEvent(event);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   237
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   238
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   239
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   240
void SmartLineEdit::autoComplete()
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   241
{
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   242
    QString match = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   243
    bool isNick = false;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   244
    QString matchMe = text();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   245
    QString prefix = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   246
    QString postfix = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   247
    bool isFirstWord;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   248
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   249
    // we are trying to rematch, so use the data from earlier
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   250
    if (m_hasJustMatched)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   251
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   252
        // restore values from earlier auto-completion
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   253
        matchMe = m_beforeMatch;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   254
        prefix = m_prefix;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   255
        postfix = m_postfix;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   256
        isFirstWord = prefix.isEmpty();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   257
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   258
    else
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   259
    {
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   260
        m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   261
        m_cmds->sort();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   262
        m_nicks->sort();
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   263
        m_keywordMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   264
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   265
        int cp = cursorPosition();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   266
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   267
        // cursor is not in or at end/beginning of word
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   268
        if ((cp = matchMe.length()) || (QString(matchMe.at(cp)).contains(m_whitespace)))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   269
            if ((cp < 1) || (QString(matchMe.at(cp-1)).contains(m_whitespace)))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   270
                return;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   271
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   272
        // crop matchMe at cursor position
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   273
        prefix  = matchMe.left (cp);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   274
        postfix = matchMe.right(matchMe.length()-cp);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   275
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   276
        matchMe = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   277
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   278
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   279
        // use the whole word the curser is on for matching
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   280
        int prefixLen = prefix.lastIndexOf(m_whitespace) + 1;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   281
        int preWordLen = prefix.length() - prefixLen;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   282
        int postWordLen = postfix.indexOf(m_whitespace);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   283
        int postfixLen = 0;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   284
        if (postWordLen < 0)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   285
            postWordLen = postfix.length();
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   286
        else
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   287
            postfixLen = postfix.length() - (postWordLen + 1);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   288
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   289
        matchMe = prefix.right(preWordLen) + postfix.left(postWordLen);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   290
        prefix  = prefix.left(prefixLen);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   291
        postfix = postfix.right(postfixLen);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   292
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   293
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   294
        isFirstWord = prefix.isEmpty(); // true if first word
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   295
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   296
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   297
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   298
    m_keywordMutex.lock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   299
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   300
    if (isFirstWord)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   301
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   302
        // find matching commands
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   303
        foreach (const QString & cmd, *m_cmds)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   304
        {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   305
            if (cmd.startsWith(matchMe, Qt::CaseInsensitive))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   306
            {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   307
                match = cmd;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   308
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   309
                // move match to end so next time new matches will be prefered
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   310
                if (m_cmds->removeAll(cmd) > 0);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   311
                    m_cmds->append(cmd);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   312
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   313
                break;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   314
            }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   315
        }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   316
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   317
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   318
    if (match.isEmpty())
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   319
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   320
        // find matching nicks
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   321
        foreach (const QString & nick, *m_nicks)
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   322
        {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   323
            if (nick.startsWith(matchMe, Qt::CaseInsensitive))
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   324
            {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   325
                match = nick;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   326
                isNick = true;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   327
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   328
                // move match to end so next time new matches will be prefered
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   329
                if (m_nicks->removeAll(nick) > 0);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   330
                    m_nicks->append(nick);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   331
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   332
                break;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   333
            }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   334
        }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   335
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   336
6150
1d98752c1fba frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents: 6149
diff changeset
   337
    m_keywordMutex.unlock();
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   338
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   339
    // we found a single match?
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   340
    if (!match.isEmpty())
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   341
    {
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   342
        // replace last word with match
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   343
        // and append ':' if a name at the beginning of the matchMe got completed
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   344
        // also add a space at the very end to ease further typing
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   345
        QString addAfter = ((isNick && isFirstWord)?": ":" ");
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   346
        match = prefix + match + addAfter;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   347
        setText(match + postfix);
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   348
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   349
        setCursorPosition(match.length());
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   350
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   351
        // save values for for the case a rematch is requested
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   352
        m_beforeMatch = matchMe;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   353
        m_hasJustMatched = true;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   354
        m_prefix = prefix;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   355
        m_postfix = postfix;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   356
    }
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   357
}
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   358
6149
0b92341adb6a + don't suggest ignored nicknames
sheepluva
parents: 6147
diff changeset
   359
void SmartLineEdit::resetAutoCompletionStatus()
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   360
{
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   361
    m_beforeMatch = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   362
    m_hasJustMatched = false;
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   363
    m_prefix = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   364
    m_postfix = "";
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
diff changeset
   365
}