mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +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;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
emit closing();
|
||||||
|
roomSearch_->clear();
|
||||||
|
}
|
||||||
|
|
||||||
// Current highlighted selection from the completer.
|
// Current highlighted selection from the completer.
|
||||||
int selection_ = -1;
|
int selection_ = -1;
|
||||||
|
|
||||||
|
|
|
@ -32,19 +32,17 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked(const QString &text);
|
void clicked(const QString &text);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
|
|
||||||
Avatar *avatar_;
|
Avatar *avatar_;
|
||||||
|
|
||||||
QColor hoverColor_;
|
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_;
|
bool hovering_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +54,9 @@ public:
|
||||||
UserItem(QWidget *parent, const QString &user_id);
|
UserItem(QWidget *parent, const QString &user_id);
|
||||||
QString selectedText() const { return userId_; }
|
QString selectedText() const { return userId_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *userName_;
|
QLabel *userName_;
|
||||||
QString userId_;
|
QString userId_;
|
||||||
|
@ -69,6 +70,9 @@ public:
|
||||||
RoomItem(QWidget *parent, const RoomSearchResult &res);
|
RoomItem(QWidget *parent, const RoomSearchResult &res);
|
||||||
QString selectedText() const { return roomId_; }
|
QString selectedText() const { return roomId_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *roomName_;
|
QLabel *roomName_;
|
||||||
QString roomId_;
|
QString roomId_;
|
||||||
|
|
|
@ -103,11 +103,13 @@ QuickSwitcher::QuickSwitcher(QSharedPointer<Cache> cache, QWidget *parent)
|
||||||
&RoomSearchInput::selectPreviousCompletion,
|
&RoomSearchInput::selectPreviousCompletion,
|
||||||
&popup_,
|
&popup_,
|
||||||
&SuggestionsPopup::selectPreviousSuggestion);
|
&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_, &RoomSearchInput::hiding, this, [this]() { popup_.hide(); });
|
||||||
connect(roomSearch_, &QLineEdit::returnPressed, this, [this]() {
|
connect(roomSearch_, &QLineEdit::returnPressed, this, [this]() {
|
||||||
emit closing();
|
reset();
|
||||||
roomSearch_->clear();
|
|
||||||
popup_.selectHoveredSuggestion<RoomItem>();
|
popup_.selectHoveredSuggestion<RoomItem>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -125,8 +127,7 @@ void
|
||||||
QuickSwitcher::keyPressEvent(QKeyEvent *event)
|
QuickSwitcher::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if (event->key() == Qt::Key_Escape) {
|
if (event->key() == Qt::Key_Escape) {
|
||||||
roomSearch_->clear();
|
|
||||||
event->accept();
|
event->accept();
|
||||||
emit closing();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,17 +38,6 @@ PopupItem::paintEvent(QPaintEvent *)
|
||||||
p.fillRect(rect(), hoverColor_);
|
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)
|
UserItem::UserItem(QWidget *parent, const QString &user_id)
|
||||||
: PopupItem(parent)
|
: PopupItem(parent)
|
||||||
, userId_{user_id}
|
, userId_{user_id}
|
||||||
|
@ -77,6 +66,16 @@ UserItem::UserItem(QWidget *parent, const QString &user_id)
|
||||||
[this](const QImage &img) { avatar_->setImage(img); });
|
[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)
|
RoomItem::RoomItem(QWidget *parent, const RoomSearchResult &res)
|
||||||
: PopupItem(parent)
|
: PopupItem(parent)
|
||||||
, roomId_{QString::fromStdString(res.room_id)}
|
, roomId_{QString::fromStdString(res.room_id)}
|
||||||
|
@ -97,6 +96,15 @@ RoomItem::RoomItem(QWidget *parent, const RoomSearchResult &res)
|
||||||
avatar_->setImage(res.img);
|
avatar_->setImage(res.img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RoomItem::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (event->buttons() != Qt::RightButton)
|
||||||
|
emit clicked(selectedText());
|
||||||
|
|
||||||
|
QWidget::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
SuggestionsPopup::SuggestionsPopup(QWidget *parent)
|
SuggestionsPopup::SuggestionsPopup(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue