Balloon tip must follow systemtray icon
If the a message notification is created at the same time as the system tray icon is embedded it may start at a wrong location, since the icon location it bases its own location is not yet final. This patch adds code to update the balloon tip location when the system tray icon is moved or resized. The bug and fix can be tested by the systray example by disabling the icon and letting show message trigger both showing it and the message. Change-Id: Ie1dc10489ad420e581e32afeb757c236fb5129ab Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
568c26227d
commit
cc3875c2e4
@ -144,6 +144,7 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
//! [5]
|
||||
void Window::showMessage()
|
||||
{
|
||||
showIconCheckBox->setChecked(true);
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(
|
||||
typeComboBox->itemData(typeComboBox->currentIndex()).toInt());
|
||||
trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon,
|
||||
|
@ -416,6 +416,14 @@ void QBalloonTip::hideBalloon()
|
||||
theSolitaryBalloonTip = 0;
|
||||
}
|
||||
|
||||
void QBalloonTip::updateBalloonPosition(const QPoint& pos)
|
||||
{
|
||||
if (!theSolitaryBalloonTip)
|
||||
return;
|
||||
theSolitaryBalloonTip->hide();
|
||||
theSolitaryBalloonTip->balloon(pos, 0, theSolitaryBalloonTip->showArrow);
|
||||
}
|
||||
|
||||
bool QBalloonTip::isBalloonVisible()
|
||||
{
|
||||
return theSolitaryBalloonTip;
|
||||
@ -549,6 +557,7 @@ void QBalloonTip::resizeEvent(QResizeEvent *ev)
|
||||
|
||||
void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow)
|
||||
{
|
||||
this->showArrow = showArrow;
|
||||
QRect scr = QApplication::desktop()->screenGeometry(pos);
|
||||
QSize sh = sizeHint();
|
||||
const int border = 1;
|
||||
|
@ -110,6 +110,7 @@ public:
|
||||
const QPoint& pos, int timeout, bool showArrow = true);
|
||||
static void hideBalloon();
|
||||
static bool isBalloonVisible();
|
||||
static void updateBalloonPosition(const QPoint& pos);
|
||||
|
||||
private:
|
||||
QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title,
|
||||
@ -127,6 +128,7 @@ private:
|
||||
QSystemTrayIcon *trayIcon;
|
||||
QPixmap pixmap;
|
||||
int timerId;
|
||||
bool showArrow;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -79,6 +79,7 @@ protected:
|
||||
virtual bool event(QEvent *);
|
||||
virtual void paintEvent(QPaintEvent *);
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
virtual void moveEvent(QMoveEvent *);
|
||||
|
||||
private slots:
|
||||
void systemTrayWindowChanged(QScreen *screen);
|
||||
@ -223,11 +224,20 @@ void QSystemTrayIconSys::paintEvent(QPaintEvent *)
|
||||
q->icon().paint(&painter, rect);
|
||||
}
|
||||
|
||||
void QSystemTrayIconSys::resizeEvent(QResizeEvent *)
|
||||
void QSystemTrayIconSys::moveEvent(QMoveEvent *event)
|
||||
{
|
||||
update();
|
||||
QWidget::moveEvent(event);
|
||||
if (QBalloonTip::isBalloonVisible())
|
||||
QBalloonTip::updateBalloonPosition(globalGeometry().center());
|
||||
}
|
||||
|
||||
void QSystemTrayIconSys::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
update();
|
||||
QWidget::resizeEvent(event);
|
||||
if (QBalloonTip::isBalloonVisible())
|
||||
QBalloonTip::updateBalloonPosition(globalGeometry().center());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QSystemTrayIconPrivate::QSystemTrayIconPrivate()
|
||||
@ -340,9 +350,8 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QStri
|
||||
}
|
||||
if (!sys)
|
||||
return;
|
||||
const QPoint g = sys->globalGeometry().topLeft();
|
||||
QBalloonTip::showBalloon(icon, message, title, sys->systemTrayIcon(),
|
||||
QPoint(g.x() + sys->width()/2, g.y() + sys->height()/2),
|
||||
sys->globalGeometry().center(),
|
||||
msecs);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user