2018-03-25 00:16:15 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
class Avatar;
|
|
|
|
|
|
|
|
struct SearchResult
|
|
|
|
{
|
|
|
|
QString user_id;
|
|
|
|
QString display_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(SearchResult)
|
|
|
|
Q_DECLARE_METATYPE(QVector<SearchResult>)
|
|
|
|
|
|
|
|
class PopupItem : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QColor hoverColor READ hoverColor WRITE setHoverColor)
|
2018-04-10 11:47:23 +03:00
|
|
|
Q_PROPERTY(bool hovering READ hovering WRITE setHovering)
|
2018-03-25 00:16:15 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
PopupItem(QWidget *parent, const QString &user_id);
|
|
|
|
|
2018-04-10 11:47:23 +03:00
|
|
|
QString user() const { return user_id_; }
|
2018-03-25 00:16:15 +03:00
|
|
|
QColor hoverColor() const { return hoverColor_; }
|
|
|
|
void setHoverColor(QColor &color) { hoverColor_ = color; }
|
|
|
|
|
2018-04-10 11:47:23 +03:00
|
|
|
bool hovering() const { return hovering_; }
|
|
|
|
void setHovering(const bool hover) { hovering_ = hover; };
|
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void clicked(const QString &display_name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QHBoxLayout *topLayout_;
|
|
|
|
|
|
|
|
Avatar *avatar_;
|
|
|
|
QLabel *userName_;
|
|
|
|
QString user_id_;
|
|
|
|
|
|
|
|
QColor hoverColor_;
|
2018-04-10 11:47:23 +03:00
|
|
|
|
|
|
|
//! Set if the item is currently being hovered during tab completion (cycling).
|
|
|
|
bool hovering_;
|
2018-03-25 00:16:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class SuggestionsPopup : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SuggestionsPopup(QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void addUsers(const QVector<SearchResult> &users);
|
2018-04-10 11:47:23 +03:00
|
|
|
void cycleThroughSuggestions();
|
|
|
|
void selectHoveredSuggestion();
|
2018-03-25 00:16:15 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void itemSelected(const QString &user);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QVBoxLayout *layout_;
|
2018-04-10 11:47:23 +03:00
|
|
|
|
|
|
|
//! Counter for tab completion (cycling).
|
|
|
|
int tab_clicks_;
|
2018-03-25 00:16:15 +03:00
|
|
|
};
|