improve tooltips by only positioning the element once we know it's in… (#1693)

Things like tooltips now only sets its position once. The position used to be set twice and could cause some annoying flickering.
This commit is contained in:
Daniel Pasch 2020-05-24 11:51:16 +02:00 committed by GitHub
parent 56d09ac198
commit a230bc7c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View file

@ -224,7 +224,7 @@ void BaseWindow::setStayInScreenRect(bool value)
{ {
this->stayInScreenRect_ = value; this->stayInScreenRect_ = value;
this->moveIntoDesktopRect(this); this->moveIntoDesktopRect(this, this->pos());
} }
bool BaseWindow::getStayInScreenRect() const bool BaseWindow::getStayInScreenRect() const
@ -499,8 +499,7 @@ void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset)
point.ry() += 16; point.ry() += 16;
} }
this->move(point); this->moveIntoDesktopRect(parent, point);
this->moveIntoDesktopRect(parent);
} }
void BaseWindow::resizeEvent(QResizeEvent *) void BaseWindow::resizeEvent(QResizeEvent *)
@ -551,15 +550,15 @@ void BaseWindow::closeEvent(QCloseEvent *)
void BaseWindow::showEvent(QShowEvent *) void BaseWindow::showEvent(QShowEvent *)
{ {
this->moveIntoDesktopRect(this); this->moveIntoDesktopRect(this, this->pos());
if (this->frameless_) if (this->frameless_)
{ {
QTimer::singleShot(30, this, QTimer::singleShot(
[this] { this->moveIntoDesktopRect(this); }); 30, this, [this] { this->moveIntoDesktopRect(this, this->pos()); });
} }
} }
void BaseWindow::moveIntoDesktopRect(QWidget *parent) void BaseWindow::moveIntoDesktopRect(QWidget *parent, QPoint point)
{ {
if (!this->stayInScreenRect_) if (!this->stayInScreenRect_)
return; return;
@ -569,37 +568,35 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
QPoint globalCursorPos = QCursor::pos(); QPoint globalCursorPos = QCursor::pos();
QRect s = desktop->availableGeometry(parent); QRect s = desktop->availableGeometry(parent);
QPoint p = this->pos();
bool stickRight = false; bool stickRight = false;
bool stickBottom = false; bool stickBottom = false;
if (p.x() < s.left()) if (point.x() < s.left())
{ {
p.setX(s.left()); point.setX(s.left());
} }
if (p.y() < s.top()) if (point.y() < s.top())
{ {
p.setY(s.top()); point.setY(s.top());
} }
if (p.x() + this->width() > s.right()) if (point.x() + this->width() > s.right())
{ {
stickRight = true; stickRight = true;
p.setX(s.right() - this->width()); point.setX(s.right() - this->width());
} }
if (p.y() + this->height() > s.bottom()) if (point.y() + this->height() > s.bottom())
{ {
stickBottom = true; stickBottom = true;
p.setY(s.bottom() - this->height()); point.setY(s.bottom() - this->height());
} }
if (stickRight && stickBottom) if (stickRight && stickBottom)
{ {
p.setY(globalCursorPos.y() - this->height() - 16); point.setY(globalCursorPos.y() - this->height() - 16);
} }
if (p != this->pos()) this->move(point);
this->move(p);
} }
bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,

View file

@ -90,7 +90,7 @@ protected:
private: private:
void init(); void init();
void moveIntoDesktopRect(QWidget *parent); void moveIntoDesktopRect(QWidget *parent, QPoint point);
void calcButtonsSizes(); void calcButtonsSizes();
void drawCustomWindowFrame(QPainter &painter); void drawCustomWindowFrame(QPainter &painter);
void onFocusLost(); void onFocusLost();