diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index 78020a8cf..1c053653d 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -25,6 +25,8 @@ AccountPopupWidget::AccountPopupWidget(SharedChannel _channel) { this->ui->setupUi(this); + this->setStayInScreenRect(true); + this->layout()->setSizeConstraint(QLayout::SetFixedSize); this->setWindowFlags(Qt::FramelessWindowHint); @@ -49,7 +51,6 @@ AccountPopupWidget::AccountPopupWidget(SharedChannel _channel) this->loggedInUser.userID = currentTwitchUser->getUserId(); this->loggedInUser.refreshUserType(this->channel, true); - }); singletons::SettingManager &settings = singletons::SettingManager::getInstance(); diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 54fbb780e..f27f5a8bf 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #ifdef USEWINSDK @@ -113,6 +114,16 @@ void BaseWindow::init() } } +void BaseWindow::setStayInScreenRect(bool value) +{ + this->stayInScreenRect = value; +} + +bool BaseWindow::getStayInScreenRect() const +{ + return this->stayInScreenRect; +} + QWidget *BaseWindow::getLayoutContainer() { if (this->hasCustomWindowFrame()) { @@ -150,12 +161,54 @@ void BaseWindow::addTitleBarButton(const QString &text) void BaseWindow::changeEvent(QEvent *) { - // TooltipWidget::getInstance()->hide(); + TooltipWidget::getInstance()->hide(); } void BaseWindow::leaveEvent(QEvent *) { - // TooltipWidget::getInstance()->hide(); + TooltipWidget::getInstance()->hide(); +} + +void BaseWindow::moveTo(QWidget *parent, QPoint point) +{ + point.rx() += 16; + point.ry() += 16; + + this->move(point); + this->moveIntoDesktopRect(parent); +} + +void BaseWindow::resizeEvent(QResizeEvent *) +{ + this->moveIntoDesktopRect(this); +} + +void BaseWindow::moveIntoDesktopRect(QWidget *parent) +{ + if (!this->stayInScreenRect) + return; + + // move the widget into the screen geometry if it's not already in there + QDesktopWidget *desktop = QApplication::desktop(); + + QRect s = desktop->screenGeometry(parent); + QPoint p = this->pos(); + + if (p.x() < s.left()) { + p.setX(s.left()); + } + if (p.y() < s.top()) { + p.setY(s.top()); + } + if (p.x() + this->width() > s.right()) { + p.setX(s.right() - this->width()); + } + if (p.y() + this->height() > s.bottom()) { + p.setY(s.bottom() - this->height()); + } + + if (p != this->pos()) + this->move(p); } #ifdef USEWINSDK diff --git a/src/widgets/basewindow.hpp b/src/widgets/basewindow.hpp index 5e1374f9b..a0024b7f1 100644 --- a/src/widgets/basewindow.hpp +++ b/src/widgets/basewindow.hpp @@ -19,6 +19,11 @@ public: bool hasCustomWindowFrame(); void addTitleBarButton(const QString &text); + void setStayInScreenRect(bool value); + bool getStayInScreenRect() const; + + void moveTo(QWidget *widget, QPoint point); + protected: #ifdef USEWINSDK virtual void showEvent(QShowEvent *); @@ -28,13 +33,16 @@ protected: virtual void changeEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override; + virtual void resizeEvent(QResizeEvent *) override; virtual void refreshTheme() override; private: void init(); + void moveIntoDesktopRect(QWidget *parent); bool enableCustomFrame; + bool stayInScreenRect = false; QHBoxLayout *titlebarBox; QWidget *titleLabel; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 586415d86..888254c88 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -787,7 +787,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) case messages::Link::UserInfo: { auto user = link.getValue(); this->userPopupWidget.setName(user); - this->userPopupWidget.move(event->screenPos().toPoint()); + this->userPopupWidget.moveTo(this, event->screenPos().toPoint()); this->userPopupWidget.show(); this->userPopupWidget.setFocus(); diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 30085eae3..6f90a597a 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -460,6 +460,7 @@ void Split::doOpenViewerList() viewerDock->move(0, this->header.height()); auto accountPopup = new AccountPopupWidget(this->channel); + accountPopup->setAttribute(Qt::WA_DeleteOnClose); auto multiWidget = new QWidget(viewerDock); auto dockVbox = new QVBoxLayout(viewerDock); auto searchBar = new QLineEdit(viewerDock); @@ -538,9 +539,9 @@ void Split::doOpenViewerList() void Split::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user) { widget->setName(user); - widget->move(QCursor::pos()); widget->show(); widget->setFocus(); + widget->moveTo(this, QCursor::pos()); } void Split::doCopy() diff --git a/src/widgets/tooltipwidget.cpp b/src/widgets/tooltipwidget.cpp index dafe6511b..fa7e9c5dc 100644 --- a/src/widgets/tooltipwidget.cpp +++ b/src/widgets/tooltipwidget.cpp @@ -17,6 +17,7 @@ TooltipWidget::TooltipWidget(BaseWidget *parent) this->setStyleSheet("color: #fff; background: #000"); this->setWindowOpacity(0.8); this->updateFont(); + this->setStayInScreenRect(true); this->setAttribute(Qt::WA_ShowWithoutActivating); this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | @@ -55,45 +56,6 @@ void TooltipWidget::setText(QString text) this->displayText->setText(text); } -void TooltipWidget::moveTo(QWidget *parent, QPoint point) -{ - point.rx() += 16; - point.ry() += 16; - - this->move(point); - this->moveIntoDesktopRect(parent); -} - -void TooltipWidget::resizeEvent(QResizeEvent *) -{ - this->moveIntoDesktopRect(this); -} - -void TooltipWidget::moveIntoDesktopRect(QWidget *parent) -{ - QDesktopWidget *desktop = QApplication::desktop(); - - QRect s = desktop->screenGeometry(parent); - QPoint p = this->pos(); - - if (p.x() < s.left()) { - p.setX(s.left()); - } - if (p.y() < s.top()) { - p.setY(s.top()); - } - if (p.x() + this->width() > s.right()) { - p.setX(s.right() - this->width()); - } - if (p.y() + this->height() > s.bottom()) { - p.setY(s.bottom() - this->height()); - } - - if (p != this->pos()) { - this->move(p); - } -} - void TooltipWidget::changeEvent(QEvent *) { // clear parents event diff --git a/src/widgets/tooltipwidget.hpp b/src/widgets/tooltipwidget.hpp index 3b440dd3d..46fabbccb 100644 --- a/src/widgets/tooltipwidget.hpp +++ b/src/widgets/tooltipwidget.hpp @@ -16,7 +16,6 @@ public: ~TooltipWidget(); void setText(QString text); - void moveTo(QWidget *widget, QPoint point); static TooltipWidget *getInstance() { @@ -28,7 +27,6 @@ public: } protected: - virtual void resizeEvent(QResizeEvent *) override; virtual void changeEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override; virtual void dpiMultiplierChanged(float, float) override; @@ -37,7 +35,6 @@ private: QLabel *displayText; pajlada::Signals::Connection fontChangedConnection; - void moveIntoDesktopRect(QWidget *parent); void updateFont(); };