mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Fix clicking on room list suggestions
This commit is contained in:
parent
b72e48cbab
commit
2c6192d08f
4 changed files with 39 additions and 20 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -103,11 +103,13 @@ QuickSwitcher::QuickSwitcher(QSharedPointer<Cache> 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<RoomItem>();
|
||||
});
|
||||
}
|
||||
|
@ -125,8 +127,7 @@ void
|
|||
QuickSwitcher::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape) {
|
||||
roomSearch_->clear();
|
||||
event->accept();
|
||||
emit closing();
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue