diff --git a/qtox.pro b/qtox.pro index fe826b158..88ca5339e 100644 --- a/qtox.pro +++ b/qtox.pro @@ -138,7 +138,8 @@ HEADERS += src/widget/form/addfriendform.h \ src/widget/maskablepixmapwidget.h \ src/videosource.h \ src/cameraworker.h \ - src/widget/videosurface.h + src/widget/videosurface.h \ + src/widget/form/tabcompleter.h SOURCES += \ src/widget/form/addfriendform.cpp \ @@ -186,4 +187,5 @@ SOURCES += \ src/widget/maskablepixmapwidget.cpp \ src/cameraworker.cpp \ src/widget/videosurface.cpp \ - src/netvideosource.cpp + src/netvideosource.cpp \ + src/widget/form/tabcompleter.cpp diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 0baa4f315..3f05639bc 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -22,7 +22,7 @@ #include // Spacing in px inserted when the author of the last message changes -#define AUTHOR_CHANGE_SPACING 5 +#define AUTHOR_CHANGE_SPACING 5 // why the hell is this a thing? surely the different font is enough? class QLabel; class QVBoxLayout; diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 0c5b4c9e1..11a32a71a 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -15,6 +15,7 @@ */ #include "groupchatform.h" +#include "tabcompleter.h" #include "src/group.h" #include "src/widget/groupwidget.h" #include "src/widget/tool/chattextedit.h" @@ -33,6 +34,8 @@ GroupChatForm::GroupChatForm(Group* chatGroup) namesList = new QLabel(); namesList->setObjectName("peersLabel"); + tabber = new TabCompleter(msgEdit, group); + fileButton->setEnabled(false); callButton->setVisible(false); videoButton->setVisible(false); @@ -59,6 +62,8 @@ GroupChatForm::GroupChatForm(Group* chatGroup) connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered())); connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered())); + connect(msgEdit, &ChatTextEdit::tabPressed, tabber, &TabCompleter::complete); + connect(msgEdit, &ChatTextEdit::keyPressed, tabber, &TabCompleter::reset); setAcceptDrops(true); } diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index 6b3984b06..f715768e8 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -21,6 +21,7 @@ namespace Ui {class MainWindow;} class Group; +class TabCompleter; class GroupChatForm : public GenericChatForm { @@ -41,6 +42,7 @@ protected: private: Group* group; QLabel *nusersLabel, *namesList; + TabCompleter* tabber; }; #endif // GROUPCHATFORM_H diff --git a/src/widget/tool/chattextedit.cpp b/src/widget/tool/chattextedit.cpp index 9b51b8fba..d9ba2ee46 100644 --- a/src/widget/tool/chattextedit.cpp +++ b/src/widget/tool/chattextedit.cpp @@ -27,11 +27,15 @@ ChatTextEdit::ChatTextEdit(QWidget *parent) : void ChatTextEdit::keyPressEvent(QKeyEvent * event) { int key = event->key(); - if ((key == Qt::Key_Enter || key == Qt::Key_Return) - && !(event->modifiers() && Qt::ShiftModifier)) - { + if ((key == Qt::Key_Enter || key == Qt::Key_Return) && !(event->modifiers() && Qt::ShiftModifier)) emit enterPressed(); - return; + else if (key == Qt::Key_Tab) + emit tabPressed(); + else if (key == Qt::Key_Backspace) // because of the backspace() hack in tabber, we can't emit on these + QTextEdit::keyPressEvent(event); + else + { + emit keyPressed(); + QTextEdit::keyPressEvent(event); } - QTextEdit::keyPressEvent(event); } diff --git a/src/widget/tool/chattextedit.h b/src/widget/tool/chattextedit.h index f8a1cb73a..6bab07cda 100644 --- a/src/widget/tool/chattextedit.h +++ b/src/widget/tool/chattextedit.h @@ -28,6 +28,8 @@ public: signals: void enterPressed(); + void tabPressed(); + void keyPressed(); public slots: