fixed #177 user popup being off the screen

This commit is contained in:
fourtf 2018-01-22 20:52:32 +01:00
parent fc758846f6
commit 305191d4b3
7 changed files with 69 additions and 47 deletions

View file

@ -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();

View file

@ -6,6 +6,7 @@
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QIcon>
#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

View file

@ -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;

View file

@ -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();

View file

@ -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()

View file

@ -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

View file

@ -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();
};