Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Larger user card drag area #3508

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/widgets/dialogs/UserInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent)
{
this->setWindowTitle("Usercard");
this->setStayInScreenRect(true);
this->setMouseTracking(true);

if (closeAutomatically)
this->setActionOnFocusLoss(BaseWindow::Delete);
Expand Down Expand Up @@ -453,6 +454,34 @@ void UserInfoPopup::scaleChangedEvent(float /*scale*/)
});
}

void UserInfoPopup::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MouseButton::LeftButton)
{
this->isDragging_ = true;
this->startPosDrag_ = event->pos();
}
}

void UserInfoPopup::mouseReleaseEvent(QMouseEvent *event)
{
this->isDragging_ = false;
this->isMoving_ = false;
}

void UserInfoPopup::mouseMoveEvent(QMouseEvent *event)
{
// Drag the window by the amount changed from inital position
// Note that we provide a few *units* of deadzone so people don't
// start dragging the window if they are slow at clicking.
auto movePos = event->pos() - this->startPosDrag_;
if (this->isMoving_ || movePos.manhattanLength() > 10.0)
{
move(window()->pos() + movePos);
this->isMoving_ = true;
}
}

void UserInfoPopup::installEvents()
{
std::shared_ptr<bool> ignoreNext = std::make_shared<bool>(false);
Expand Down
7 changes: 7 additions & 0 deletions src/widgets/dialogs/UserInfoPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class UserInfoPopup final : public BaseWindow
protected:
virtual void themeChangedEvent() override;
virtual void scaleChangedEvent(float scale) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;

private:
void installEvents();
Expand All @@ -41,6 +44,10 @@ class UserInfoPopup final : public BaseWindow
QString avatarUrl_;
ChannelPtr channel_;

bool isDragging_ = false;
bool isMoving_ = false;
QPoint startPosDrag_;

pajlada::Signals::NoArgSignal userStateChanged_;

std::unique_ptr<pajlada::Signals::ScopedConnection> refreshConnection_;
Expand Down