mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixed #177 user popup being off the screen
This commit is contained in:
parent
fc758846f6
commit
305191d4b3
7 changed files with 69 additions and 47 deletions
|
@ -25,6 +25,8 @@ AccountPopupWidget::AccountPopupWidget(SharedChannel _channel)
|
||||||
{
|
{
|
||||||
this->ui->setupUi(this);
|
this->ui->setupUi(this);
|
||||||
|
|
||||||
|
this->setStayInScreenRect(true);
|
||||||
|
|
||||||
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||||
|
|
||||||
this->setWindowFlags(Qt::FramelessWindowHint);
|
this->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
@ -49,7 +51,6 @@ AccountPopupWidget::AccountPopupWidget(SharedChannel _channel)
|
||||||
this->loggedInUser.userID = currentTwitchUser->getUserId();
|
this->loggedInUser.userID = currentTwitchUser->getUserId();
|
||||||
|
|
||||||
this->loggedInUser.refreshUserType(this->channel, true);
|
this->loggedInUser.refreshUserType(this->channel, true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
#ifdef USEWINSDK
|
#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()
|
QWidget *BaseWindow::getLayoutContainer()
|
||||||
{
|
{
|
||||||
if (this->hasCustomWindowFrame()) {
|
if (this->hasCustomWindowFrame()) {
|
||||||
|
@ -150,12 +161,54 @@ void BaseWindow::addTitleBarButton(const QString &text)
|
||||||
|
|
||||||
void BaseWindow::changeEvent(QEvent *)
|
void BaseWindow::changeEvent(QEvent *)
|
||||||
{
|
{
|
||||||
// TooltipWidget::getInstance()->hide();
|
TooltipWidget::getInstance()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::leaveEvent(QEvent *)
|
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
|
#ifdef USEWINSDK
|
||||||
|
|
|
@ -19,6 +19,11 @@ public:
|
||||||
bool hasCustomWindowFrame();
|
bool hasCustomWindowFrame();
|
||||||
void addTitleBarButton(const QString &text);
|
void addTitleBarButton(const QString &text);
|
||||||
|
|
||||||
|
void setStayInScreenRect(bool value);
|
||||||
|
bool getStayInScreenRect() const;
|
||||||
|
|
||||||
|
void moveTo(QWidget *widget, QPoint point);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
virtual void showEvent(QShowEvent *);
|
virtual void showEvent(QShowEvent *);
|
||||||
|
@ -28,13 +33,16 @@ protected:
|
||||||
|
|
||||||
virtual void changeEvent(QEvent *) override;
|
virtual void changeEvent(QEvent *) override;
|
||||||
virtual void leaveEvent(QEvent *) override;
|
virtual void leaveEvent(QEvent *) override;
|
||||||
|
virtual void resizeEvent(QResizeEvent *) override;
|
||||||
|
|
||||||
virtual void refreshTheme() override;
|
virtual void refreshTheme() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
void moveIntoDesktopRect(QWidget *parent);
|
||||||
|
|
||||||
bool enableCustomFrame;
|
bool enableCustomFrame;
|
||||||
|
bool stayInScreenRect = false;
|
||||||
|
|
||||||
QHBoxLayout *titlebarBox;
|
QHBoxLayout *titlebarBox;
|
||||||
QWidget *titleLabel;
|
QWidget *titleLabel;
|
||||||
|
|
|
@ -787,7 +787,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
case messages::Link::UserInfo: {
|
case messages::Link::UserInfo: {
|
||||||
auto user = link.getValue();
|
auto user = link.getValue();
|
||||||
this->userPopupWidget.setName(user);
|
this->userPopupWidget.setName(user);
|
||||||
this->userPopupWidget.move(event->screenPos().toPoint());
|
this->userPopupWidget.moveTo(this, event->screenPos().toPoint());
|
||||||
this->userPopupWidget.show();
|
this->userPopupWidget.show();
|
||||||
this->userPopupWidget.setFocus();
|
this->userPopupWidget.setFocus();
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,7 @@ void Split::doOpenViewerList()
|
||||||
viewerDock->move(0, this->header.height());
|
viewerDock->move(0, this->header.height());
|
||||||
|
|
||||||
auto accountPopup = new AccountPopupWidget(this->channel);
|
auto accountPopup = new AccountPopupWidget(this->channel);
|
||||||
|
accountPopup->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
auto multiWidget = new QWidget(viewerDock);
|
auto multiWidget = new QWidget(viewerDock);
|
||||||
auto dockVbox = new QVBoxLayout(viewerDock);
|
auto dockVbox = new QVBoxLayout(viewerDock);
|
||||||
auto searchBar = new QLineEdit(viewerDock);
|
auto searchBar = new QLineEdit(viewerDock);
|
||||||
|
@ -538,9 +539,9 @@ void Split::doOpenViewerList()
|
||||||
void Split::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user)
|
void Split::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user)
|
||||||
{
|
{
|
||||||
widget->setName(user);
|
widget->setName(user);
|
||||||
widget->move(QCursor::pos());
|
|
||||||
widget->show();
|
widget->show();
|
||||||
widget->setFocus();
|
widget->setFocus();
|
||||||
|
widget->moveTo(this, QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Split::doCopy()
|
void Split::doCopy()
|
||||||
|
|
|
@ -17,6 +17,7 @@ TooltipWidget::TooltipWidget(BaseWidget *parent)
|
||||||
this->setStyleSheet("color: #fff; background: #000");
|
this->setStyleSheet("color: #fff; background: #000");
|
||||||
this->setWindowOpacity(0.8);
|
this->setWindowOpacity(0.8);
|
||||||
this->updateFont();
|
this->updateFont();
|
||||||
|
this->setStayInScreenRect(true);
|
||||||
|
|
||||||
this->setAttribute(Qt::WA_ShowWithoutActivating);
|
this->setAttribute(Qt::WA_ShowWithoutActivating);
|
||||||
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
|
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
|
||||||
|
@ -55,45 +56,6 @@ void TooltipWidget::setText(QString text)
|
||||||
this->displayText->setText(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 *)
|
void TooltipWidget::changeEvent(QEvent *)
|
||||||
{
|
{
|
||||||
// clear parents event
|
// clear parents event
|
||||||
|
|
|
@ -16,7 +16,6 @@ public:
|
||||||
~TooltipWidget();
|
~TooltipWidget();
|
||||||
|
|
||||||
void setText(QString text);
|
void setText(QString text);
|
||||||
void moveTo(QWidget *widget, QPoint point);
|
|
||||||
|
|
||||||
static TooltipWidget *getInstance()
|
static TooltipWidget *getInstance()
|
||||||
{
|
{
|
||||||
|
@ -28,7 +27,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void resizeEvent(QResizeEvent *) override;
|
|
||||||
virtual void changeEvent(QEvent *) override;
|
virtual void changeEvent(QEvent *) override;
|
||||||
virtual void leaveEvent(QEvent *) override;
|
virtual void leaveEvent(QEvent *) override;
|
||||||
virtual void dpiMultiplierChanged(float, float) override;
|
virtual void dpiMultiplierChanged(float, float) override;
|
||||||
|
@ -37,7 +35,6 @@ private:
|
||||||
QLabel *displayText;
|
QLabel *displayText;
|
||||||
pajlada::Signals::Connection fontChangedConnection;
|
pajlada::Signals::Connection fontChangedConnection;
|
||||||
|
|
||||||
void moveIntoDesktopRect(QWidget *parent);
|
|
||||||
void updateFont();
|
void updateFont();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue