mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
ADD FORGOTTEN FILES WHY DO THESE THINGS HAPPEN (and fix outbound actions)
This commit is contained in:
parent
aa55dcae1e
commit
995e86aad9
@ -87,7 +87,7 @@ void ChatForm::onSendTriggered()
|
||||
if (msg.isEmpty())
|
||||
return;
|
||||
QString name = Widget::getInstance()->getUsername();
|
||||
if (msg.startsWith("/me "))
|
||||
if (msg.startsWith("/me"))
|
||||
{
|
||||
msg = msg.right(msg.length() - 4);
|
||||
addMessage(name, msg, true);
|
||||
|
122
src/widget/form/tabcompleter.cpp
Normal file
122
src/widget/form/tabcompleter.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
Copyright (C) 2005-2014 by the Quassel Project and Project Tox
|
||||
devel@quassel-irc.org and https://tox.im
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/* This file was taken from the Quassel IRC client source (src/uisupport), and
|
||||
was greatly simplified for use in qTox. */
|
||||
|
||||
#include "tabcompleter.h"
|
||||
#include "src/core.h"
|
||||
#include "src/group.h"
|
||||
#include "src/widget/tool/chattextedit.h"
|
||||
#include <QRegExp>
|
||||
#include <QKeyEvent>
|
||||
|
||||
const QString TabCompleter::nickSuffix = QString(": ");
|
||||
|
||||
TabCompleter::TabCompleter(ChatTextEdit* msgEdit, Group* group)
|
||||
: QObject(msgEdit), msgEdit(msgEdit), group(group), enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
/* from quassel/src/uisupport/multilineedit.h
|
||||
// Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
|
||||
inline QString text() const { return toPlainText(); }
|
||||
inline QString html() const { return toHtml(); }
|
||||
inline int cursorPosition() const { return textCursor().position(); }
|
||||
inline void insert(const QString &newText) { insertPlainText(newText); }
|
||||
inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
|
||||
*/
|
||||
|
||||
void TabCompleter::buildCompletionList()
|
||||
{
|
||||
// ensure a safe state in case we return early.
|
||||
completionMap.clear();
|
||||
nextCompletion = completionMap.begin();
|
||||
|
||||
// split the string on the given RE (not chars, nums or braces/brackets) and take the last section
|
||||
QString tabAbbrev = msgEdit->toPlainText().left(msgEdit->textCursor().position()).section(QRegExp("[^\\w\\d-_\\[\\]{}|`^.\\\\]"), -1, -1);
|
||||
// that section is then used as the completion regex
|
||||
QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)), Qt::CaseInsensitive);
|
||||
|
||||
for(auto name : group->peers.values())
|
||||
if (regex.indexIn(name) > -1)
|
||||
completionMap[name.toLower()] = name;
|
||||
|
||||
nextCompletion = completionMap.begin();
|
||||
lastCompletionLength = tabAbbrev.length();
|
||||
}
|
||||
|
||||
|
||||
void TabCompleter::complete()
|
||||
{
|
||||
if (!enabled) {
|
||||
buildCompletionList();
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
if (nextCompletion != completionMap.end()) {
|
||||
// clear previous completion
|
||||
for (int i = 0; i < lastCompletionLength; i++) {
|
||||
msgEdit->keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
|
||||
}
|
||||
|
||||
// insert completion
|
||||
msgEdit->insertPlainText(*nextCompletion);
|
||||
|
||||
// remember charcount to delete next time and advance to next completion
|
||||
lastCompletionLength = nextCompletion->length();
|
||||
nextCompletion++;
|
||||
|
||||
// we're completing the first word of the line
|
||||
if (msgEdit->textCursor().position() == lastCompletionLength) {
|
||||
msgEdit->insertPlainText(nickSuffix);
|
||||
lastCompletionLength += nickSuffix.length();
|
||||
}
|
||||
}
|
||||
else { // we're at the end of the list -> start over again
|
||||
if (!completionMap.isEmpty()) {
|
||||
nextCompletion = completionMap.begin();
|
||||
complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TabCompleter::reset()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
// this determines the sort order
|
||||
bool TabCompleter::SortableString::operator<(const SortableString &other) const
|
||||
{
|
||||
QString name = Core::getInstance()->getUsername();
|
||||
if (this->contents == name)
|
||||
return false;
|
||||
else if (other.contents == name)
|
||||
return true;
|
||||
|
||||
/* QDateTime thisTime = thisUser->lastChannelActivity(_currentBufferId);
|
||||
QDateTime thatTime = thatUser->lastChannelActivity(_currentBufferId);
|
||||
|
||||
|
||||
if (thisTime.isValid() || thatTime.isValid())
|
||||
return thisTime > thatTime;
|
||||
*/ // this could be a useful feature at some point
|
||||
|
||||
return QString::localeAwareCompare(this->contents, other.contents) < 0;
|
||||
}
|
61
src/widget/form/tabcompleter.h
Normal file
61
src/widget/form/tabcompleter.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (C) 2005-2014 by the Quassel Project and Project Tox
|
||||
devel@quassel-irc.org and https://tox.im
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/* This file was taken from the Quassel IRC client source (src/uisupport), and
|
||||
was greatly simplified for use in qTox. */
|
||||
|
||||
#ifndef TABCOMPLETER_H
|
||||
#define TABCOMPLETER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QObject> // I'm really confused why I need this
|
||||
|
||||
class ChatTextEdit;
|
||||
class Group;
|
||||
|
||||
class TabCompleter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TabCompleter(ChatTextEdit* msgEdit, Group* group);
|
||||
|
||||
public slots:
|
||||
void complete();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
struct SortableString {
|
||||
inline SortableString(const QString &n) { contents = n; }
|
||||
bool operator<(const SortableString &other) const;
|
||||
QString contents;
|
||||
};
|
||||
|
||||
ChatTextEdit* msgEdit;
|
||||
Group* group;
|
||||
bool enabled;
|
||||
const static QString nickSuffix;
|
||||
|
||||
QMap<SortableString, QString> completionMap;
|
||||
QMap<SortableString, QString>::Iterator nextCompletion;
|
||||
int lastCompletionLength;
|
||||
|
||||
void buildCompletionList();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user