diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index d6ca5a4f5..6341dea5e 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -169,24 +169,12 @@ GenericChatForm::GenericChatForm(QWidget *parent) connect(emoteButton, &QPushButton::clicked, this, &GenericChatForm::onEmoteButtonClicked); connect(chatWidget, &ChatLog::customContextMenuRequested, this, &GenericChatForm::onChatContextMenuRequested); - new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact())); - new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact())); new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L, this, SLOT(clearChatArea())); chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css")); headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css")); } -void GenericChatForm::previousContact() -{ - parent->previousContact(); -} - -void GenericChatForm::nextContact() -{ - parent->nextContact(); -} - bool GenericChatForm::isEmpty() { return chatWidget->isEmpty(); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 00eb06cf2..34da7957e 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -76,8 +76,6 @@ protected slots: void clearChatArea(bool); void clearChatArea(); void onSelectAllClicked(); - void previousContact(); - void nextContact(); protected: QString resolveToxID(const ToxID &id); diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index 5a5e481bb..0ccfa656e 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -87,6 +87,32 @@ void FriendListWidget::onGroupchatPositionChanged(bool top) } } +QList FriendListWidget::getAllFriends() +{ + QList friends; + + for (int i = 0; i < mainLayout->count(); ++i) + { + QLayout* subLayout = mainLayout->itemAt(i)->layout(); + + if(!subLayout) + continue; + + for (int j = 0; j < subLayout->count(); ++j) + { + GenericChatroomWidget* widget = + reinterpret_cast(subLayout->itemAt(j)->widget()); + + if(!widget) + continue; + + friends.append(widget); + } + } + + return friends; +} + void FriendListWidget::moveWidget(QWidget *w, Status s) { QVBoxLayout* l = getFriendLayout(s); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index ff098ce44..bbc299bbe 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -19,7 +19,9 @@ #include #include +#include #include "src/core/corestructs.h" +#include "src/widget/genericchatroomwidget.h" class QVBoxLayout; class QGridLayout; @@ -33,6 +35,8 @@ public: QVBoxLayout* getGroupLayout(); QVBoxLayout* getFriendLayout(Status s); + QList getAllFriends(); + signals: public slots: diff --git a/src/widget/tool/chattextedit.cpp b/src/widget/tool/chattextedit.cpp index 08526fc5b..46cd72ff2 100644 --- a/src/widget/tool/chattextedit.cpp +++ b/src/widget/tool/chattextedit.cpp @@ -25,12 +25,17 @@ 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)) emit enterPressed(); else if (key == Qt::Key_Tab) - emit tabPressed(); + { + if (event->modifiers()) + event->ignore(); + else + emit tabPressed(); + } else if (key == Qt::Key_Up && this->toPlainText().isEmpty()) { this->setText(lastMessage); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 218694ecb..57a133746 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -200,6 +200,10 @@ void Widget::init() // keyboard shortcuts new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); + new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab, this, SLOT(previousContact())); + new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact())); + new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact())); + new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact())); addFriendForm->show(*ui); setWindowTitle(tr("Add friend")); @@ -1235,6 +1239,23 @@ void Widget::onSplitterMoved(int pos, int index) saveSplitterGeometry(); } +void Widget::cycleContacts(int offset) +{ + if (!activeChatroomWidget) + return; + + FriendListWidget* friendList = static_cast(ui->friendList->widget()); + QList friends = friendList->getAllFriends(); + + int activeIndex = friends.indexOf(activeChatroomWidget); + int bounded = (activeIndex + offset) % friends.length(); + + if(bounded < 0) + bounded += friends.length(); + + emit friends[bounded]->chatroomWidgetClicked(friends[bounded]); +} + void Widget::processOfflineMsgs() { if (OfflineMsgEngine::globalMutex.tryLock()) @@ -1271,13 +1292,12 @@ void Widget::reloadTheme() void Widget::nextContact() { - // dont know how to get current/previous/next contact from friendlistwidget - qDebug() << "next contact"; + cycleContacts(1); } void Widget::previousContact() { - qDebug() << "previous contact"; + cycleContacts(-1); } QString Widget::getStatusIconPath(Status status) diff --git a/src/widget/widget.h b/src/widget/widget.h index 62ad53b4b..a8736e1ba 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -158,6 +158,7 @@ private: void removeGroup(Group* g, bool fake = false); void saveWindowGeometry(); void saveSplitterGeometry(); + void cycleContacts(int offset); SystemTrayIcon *icon; QMenu *trayMenu; QAction *statusOnline,