diff --git a/include/QuickSwitcher.h b/include/QuickSwitcher.h index ce0ed00b..ce3c4f25 100644 --- a/include/QuickSwitcher.h +++ b/include/QuickSwitcher.h @@ -63,6 +63,12 @@ protected: void paintEvent(QPaintEvent *event) override; private: + void reset() + { + emit closing(); + roomSearch_->clear(); + } + // Current highlighted selection from the completer. int selection_ = -1; diff --git a/include/SuggestionsPopup.hpp b/include/SuggestionsPopup.hpp index e949ce7c..ba3aebe5 100644 --- a/include/SuggestionsPopup.hpp +++ b/include/SuggestionsPopup.hpp @@ -32,19 +32,17 @@ public: protected: void paintEvent(QPaintEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; signals: void clicked(const QString &text); protected: QHBoxLayout *topLayout_; - Avatar *avatar_; - QColor hoverColor_; - //! Set if the item is currently being hovered during tab completion (cycling). + //! Set if the item is currently being + //! hovered during tab completion (cycling). bool hovering_; }; @@ -56,6 +54,9 @@ public: UserItem(QWidget *parent, const QString &user_id); QString selectedText() const { return userId_; } +protected: + void mousePressEvent(QMouseEvent *event) override; + private: QLabel *userName_; QString userId_; @@ -69,6 +70,9 @@ public: RoomItem(QWidget *parent, const RoomSearchResult &res); QString selectedText() const { return roomId_; } +protected: + void mousePressEvent(QMouseEvent *event) override; + private: QLabel *roomName_; QString roomId_; diff --git a/src/QuickSwitcher.cc b/src/QuickSwitcher.cc index d406a6de..3596a8c4 100644 --- a/src/QuickSwitcher.cc +++ b/src/QuickSwitcher.cc @@ -103,11 +103,13 @@ QuickSwitcher::QuickSwitcher(QSharedPointer cache, QWidget *parent) &RoomSearchInput::selectPreviousCompletion, &popup_, &SuggestionsPopup::selectPreviousSuggestion); - connect(&popup_, &SuggestionsPopup::itemSelected, this, &QuickSwitcher::roomSelected); + connect(&popup_, &SuggestionsPopup::itemSelected, this, [this](const QString &room_id) { + reset(); + emit roomSelected(room_id); + }); connect(roomSearch_, &RoomSearchInput::hiding, this, [this]() { popup_.hide(); }); connect(roomSearch_, &QLineEdit::returnPressed, this, [this]() { - emit closing(); - roomSearch_->clear(); + reset(); popup_.selectHoveredSuggestion(); }); } @@ -125,8 +127,7 @@ void QuickSwitcher::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) { - roomSearch_->clear(); event->accept(); - emit closing(); + reset(); } } diff --git a/src/SuggestionsPopup.cpp b/src/SuggestionsPopup.cpp index cb569ddf..86586c92 100644 --- a/src/SuggestionsPopup.cpp +++ b/src/SuggestionsPopup.cpp @@ -38,17 +38,6 @@ PopupItem::paintEvent(QPaintEvent *) p.fillRect(rect(), hoverColor_); } -void -PopupItem::mousePressEvent(QMouseEvent *event) -{ - if (event->buttons() != Qt::RightButton) - // TODO: should be abstracted. - emit clicked( - Cache::displayName(ChatPage::instance()->currentRoom(), selectedText())); - - QWidget::mousePressEvent(event); -} - UserItem::UserItem(QWidget *parent, const QString &user_id) : PopupItem(parent) , userId_{user_id} @@ -77,6 +66,16 @@ UserItem::UserItem(QWidget *parent, const QString &user_id) [this](const QImage &img) { avatar_->setImage(img); }); } +void +UserItem::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() != Qt::RightButton) + emit clicked( + Cache::displayName(ChatPage::instance()->currentRoom(), selectedText())); + + QWidget::mousePressEvent(event); +} + RoomItem::RoomItem(QWidget *parent, const RoomSearchResult &res) : PopupItem(parent) , roomId_{QString::fromStdString(res.room_id)} @@ -97,6 +96,15 @@ RoomItem::RoomItem(QWidget *parent, const RoomSearchResult &res) avatar_->setImage(res.img); } +void +RoomItem::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() != Qt::RightButton) + emit clicked(selectedText()); + + QWidget::mousePressEvent(event); +} + SuggestionsPopup::SuggestionsPopup(QWidget *parent) : QWidget(parent) {