mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Implement basic user popup
What needs more work: - Make sure popup is gone if you click away - Add timeouts etc and make them work (relies on Channel being able to send messages)
This commit is contained in:
parent
8ef492d7ae
commit
b010d90689
6 changed files with 285 additions and 7 deletions
|
@ -55,7 +55,8 @@ SOURCES += main.cpp\
|
||||||
windows.cpp \
|
windows.cpp \
|
||||||
messages/messageref.cpp \
|
messages/messageref.cpp \
|
||||||
logging/loggingmanager.cpp \
|
logging/loggingmanager.cpp \
|
||||||
logging/loggingchannel.cpp
|
logging/loggingchannel.cpp \
|
||||||
|
widgets/userpopupwidget.cpp
|
||||||
|
|
||||||
HEADERS += account.h \
|
HEADERS += account.h \
|
||||||
asyncexec.h \
|
asyncexec.h \
|
||||||
|
@ -101,7 +102,8 @@ HEADERS += account.h \
|
||||||
messages/limitedqueuesnapshot.h \
|
messages/limitedqueuesnapshot.h \
|
||||||
messages/messageref.h \
|
messages/messageref.h \
|
||||||
logging/loggingmanager.h \
|
logging/loggingmanager.h \
|
||||||
logging/loggingchannel.h
|
logging/loggingchannel.h \
|
||||||
|
widgets/userpopupwidget.h
|
||||||
|
|
||||||
PRECOMPILED_HEADER =
|
PRECOMPILED_HEADER =
|
||||||
|
|
||||||
|
@ -118,3 +120,6 @@ win32 {
|
||||||
macx {
|
macx {
|
||||||
INCLUDEPATH += /usr/local/include
|
INCLUDEPATH += /usr/local/include
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
forms/userpopup.ui
|
||||||
|
|
124
forms/userpopup.ui
Normal file
124
forms/userpopup.ui
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>UserPopup</class>
|
||||||
|
<widget class="QWidget" name="UserPopup">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>131</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>UserPopup</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QPushButton" name="btnPurge">
|
||||||
|
<property name="text">
|
||||||
|
<string>Purge</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" rowspan="2" colspan="2">
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Views</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="lblViews">
|
||||||
|
<property name="text">
|
||||||
|
<string>420</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Followers</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="lblFollowers">
|
||||||
|
<property name="text">
|
||||||
|
<string>69</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Account Age</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLabel" name="lblAccountAge">
|
||||||
|
<property name="text">
|
||||||
|
<string>6 years</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lblUsername">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>14</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>USERNAME</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnClose">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" rowspan="3">
|
||||||
|
<widget class="QLabel" name="lblAvatar">
|
||||||
|
<property name="text">
|
||||||
|
<string>AVATAR</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -4,6 +4,7 @@
|
||||||
#include "messages/message.h"
|
#include "messages/message.h"
|
||||||
#include "messages/wordpart.h"
|
#include "messages/wordpart.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "ui_userpopup.h"
|
||||||
#include "widgets/chatwidget.h"
|
#include "widgets/chatwidget.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -20,7 +21,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
||||||
: QWidget()
|
: QWidget()
|
||||||
, chatWidget(parent)
|
, chatWidget(parent)
|
||||||
, scrollbar(this)
|
, scrollbar(this)
|
||||||
, onlyUpdateEmotes(false)
|
, userPopupWidget(this->chatWidget->getChannel())
|
||||||
{
|
{
|
||||||
this->setAttribute(Qt::WA_OpaquePaintEvent);
|
this->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
this->scrollbar.setSmallChange(5);
|
this->scrollbar.setSmallChange(5);
|
||||||
|
@ -311,16 +312,78 @@ ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
|
||||||
int index = message->getSelectionIndex(relativePos);
|
int index = message->getSelectionIndex(relativePos);
|
||||||
|
|
||||||
qDebug() << index;
|
|
||||||
|
|
||||||
if (hoverWord.getLink().getIsValid()) {
|
if (hoverWord.getLink().getIsValid()) {
|
||||||
this->setCursor(Qt::PointingHandCursor);
|
this->setCursor(Qt::PointingHandCursor);
|
||||||
qDebug() << hoverWord.getLink().getValue();
|
|
||||||
} else {
|
} else {
|
||||||
this->setCursor(Qt::ArrowCursor);
|
this->setCursor(Qt::ArrowCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidgetView::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
this->mouseDown = true;
|
||||||
|
this->latestPressPosition = event->screenPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
static float
|
||||||
|
distanceBetweenPoints(const QPointF &p1, const QPointF &p2)
|
||||||
|
{
|
||||||
|
QPointF tmp = p1 - p2;
|
||||||
|
|
||||||
|
float distance = 0.f;
|
||||||
|
distance += tmp.x() * tmp.x();
|
||||||
|
distance += tmp.y() * tmp.y();
|
||||||
|
|
||||||
|
return std::sqrt(distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (!this->mouseDown) {
|
||||||
|
// We didn't grab the mouse press, so we shouldn't be handling the mouse
|
||||||
|
// release
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->mouseDown = false;
|
||||||
|
|
||||||
|
float distance =
|
||||||
|
distanceBetweenPoints(this->latestPressPosition, event->screenPos());
|
||||||
|
|
||||||
|
qDebug() << "Distance: " << distance;
|
||||||
|
|
||||||
|
if (std::fabsf(distance) > 15.f) {
|
||||||
|
// It wasn't a proper click, so we don't care about that here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you clicked and released less than X pixels away, it counts
|
||||||
|
// as a click!
|
||||||
|
|
||||||
|
// show user thing pajaW
|
||||||
|
|
||||||
|
std::shared_ptr<messages::MessageRef> message;
|
||||||
|
QPoint relativePos;
|
||||||
|
|
||||||
|
if (!tryGetMessageAt(event->pos(), message, relativePos)) {
|
||||||
|
// No message at clicked position
|
||||||
|
this->userPopupWidget.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto _message = message->getMessage();
|
||||||
|
auto user = _message->getUserName();
|
||||||
|
|
||||||
|
qDebug() << "Clicked " << user << "s message";
|
||||||
|
|
||||||
|
this->userPopupWidget.setName(user);
|
||||||
|
this->userPopupWidget.move(event->screenPos().toPoint());
|
||||||
|
this->userPopupWidget.show();
|
||||||
|
this->userPopupWidget.setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ChatWidgetView::tryGetMessageAt(QPoint p,
|
ChatWidgetView::tryGetMessageAt(QPoint p,
|
||||||
std::shared_ptr<messages::MessageRef> &_message,
|
std::shared_ptr<messages::MessageRef> &_message,
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "messages/messageref.h"
|
#include "messages/messageref.h"
|
||||||
#include "messages/word.h"
|
#include "messages/word.h"
|
||||||
#include "widgets/scrollbar.h"
|
#include "widgets/scrollbar.h"
|
||||||
|
#include "widgets/userpopupwidget.h"
|
||||||
|
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
|
@ -40,6 +41,8 @@ protected:
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
bool tryGetMessageAt(QPoint p,
|
bool tryGetMessageAt(QPoint p,
|
||||||
std::shared_ptr<messages::MessageRef> &message,
|
std::shared_ptr<messages::MessageRef> &message,
|
||||||
|
@ -56,7 +59,13 @@ private:
|
||||||
ChatWidget *chatWidget;
|
ChatWidget *chatWidget;
|
||||||
|
|
||||||
ScrollBar scrollbar;
|
ScrollBar scrollbar;
|
||||||
bool onlyUpdateEmotes;
|
|
||||||
|
UserPopupWidget userPopupWidget;
|
||||||
|
bool onlyUpdateEmotes = false;
|
||||||
|
|
||||||
|
// Mouse event variables
|
||||||
|
bool mouseDown = false;
|
||||||
|
QPointF latestPressPosition;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void
|
void
|
||||||
|
|
42
widgets/userpopupwidget.cpp
Normal file
42
widgets/userpopupwidget.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include "userpopupwidget.h"
|
||||||
|
#include "channel.h"
|
||||||
|
#include "ui_userpopup.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace widgets {
|
||||||
|
|
||||||
|
UserPopupWidget::UserPopupWidget(std::shared_ptr<Channel> &&_channel)
|
||||||
|
: QWidget(nullptr)
|
||||||
|
, ui(new Ui::UserPopup)
|
||||||
|
, channel(std::move(_channel))
|
||||||
|
{
|
||||||
|
this->ui->setupUi(this);
|
||||||
|
|
||||||
|
this->resize(0, 0);
|
||||||
|
|
||||||
|
this->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
|
||||||
|
// Close button
|
||||||
|
connect(this->ui->btnClose, &QPushButton::clicked, [=]() {
|
||||||
|
this->hide(); //
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(this->ui->btnPurge, &QPushButton::clicked, [=]() {
|
||||||
|
qDebug() << "xD: " << this->channel->getName();
|
||||||
|
/*
|
||||||
|
this->channel->sendMessage(
|
||||||
|
QString(".timeout %1 0").arg(this->ui->lblUsername->text()));
|
||||||
|
*/
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserPopupWidget::setName(const QString &name)
|
||||||
|
{
|
||||||
|
this->ui->lblUsername->setText(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
35
widgets/userpopupwidget.h
Normal file
35
widgets/userpopupwidget.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef USERPOPUPWIDGET_H
|
||||||
|
#define USERPOPUPWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class UserPopup;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class Channel;
|
||||||
|
|
||||||
|
namespace widgets {
|
||||||
|
|
||||||
|
class UserPopupWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UserPopupWidget(std::shared_ptr<Channel> &&_channel);
|
||||||
|
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::UserPopup *ui;
|
||||||
|
|
||||||
|
std::shared_ptr<Channel> channel;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
||||||
|
|
||||||
|
#endif // USERPOPUPWIDGET_H
|
Loading…
Reference in a new issue