QBalloonTip Class Reference

#include <qsystemtrayicon_p.h>

Inheritance diagram for QBalloonTip:

Inheritance graph
[legend]
Collaboration diagram for QBalloonTip:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 75 of file qsystemtrayicon_p.h.

Static Public Member Functions

static void showBalloon (QSystemTrayIcon::MessageIcon icon, const QString &title, const QString &msg, QSystemTrayIcon *trayIcon, const QPoint &pos, int timeout, bool showArrow=true)
static void hideBalloon ()

Protected Member Functions

void paintEvent (QPaintEvent *)
void resizeEvent (QResizeEvent *)
void mousePressEvent (QMouseEvent *e)
void timerEvent (QTimerEvent *e)

Private Member Functions

 QBalloonTip (QSystemTrayIcon::MessageIcon icon, const QString &title, const QString &msg, QSystemTrayIcon *trayIcon)
 ~QBalloonTip ()
void balloon (const QPoint &, int, bool)

Private Attributes

QSystemTrayIcontrayIcon
QPixmap pixmap
int timerId


Constructor & Destructor Documentation

QBalloonTip::QBalloonTip ( QSystemTrayIcon::MessageIcon  icon,
const QString title,
const QString msg,
QSystemTrayIcon trayIcon 
) [private]

Definition at line 384 of file qsystemtrayicon.cpp.

References QLayout::addWidget(), Qt::AlignLeft, Qt::AlignTop, QWidget::close(), QObject::connect(), QSystemTrayIcon::Critical, QObject::destroyed(), QSizePolicy::Fixed, QWidget::font(), QSystemTrayIcon::Information, QObject::installEventFilter(), QIcon::isNull(), QWidget::layout(), message, QSystemTrayIcon::NoIcon, QWidget::palette(), QIcon::pixmap(), Qt::PlainText, QLabel::setAlignment(), QWidget::setAttribute(), QFont::setBold(), QPalette::setColor(), QWidget::setFixedSize(), QLayout::SetFixedSize, QWidget::setFont(), QAbstractButton::setIcon(), QAbstractButton::setIconSize(), QWidget::setLayout(), QLayout::setMargin(), QWidget::setPalette(), QLayout::setSizeConstraint(), QWidget::setSizePolicy(), QLayout::setSpacing(), QLabel::setText(), QLabel::setTextFormat(), SIGNAL, SLOT, QStyle::SP_DockWidgetCloseButton, QStyle::SP_MessageBoxCritical, QStyle::SP_MessageBoxInformation, QStyle::SP_MessageBoxWarning, QStyle::standardIcon(), QWidget::style(), Qt::WA_DeleteOnClose, QSystemTrayIcon::Warning, and QPalette::Window.

Referenced by showBalloon().

00386     : QWidget(0, Qt::ToolTip), trayIcon(ti), timerId(-1)
00387 {
00388     setAttribute(Qt::WA_DeleteOnClose);
00389     QObject::connect(ti, SIGNAL(destroyed()), this, SLOT(close()));
00390 
00391     QLabel *titleLabel = new QLabel;
00392     titleLabel->installEventFilter(this);
00393     titleLabel->setText(title);
00394     QFont f = titleLabel->font();
00395     f.setBold(true);
00396     titleLabel->setFont(f);
00397     titleLabel->setTextFormat(Qt::PlainText); // to maintain compat with windows
00398 
00399     QPushButton *closeButton = new QPushButton;
00400     closeButton->setIcon(style()->standardIcon(QStyle::SP_DockWidgetCloseButton));
00401     closeButton->setIconSize(QSize(18, 18));
00402     closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00403     closeButton->setFixedSize(18, 18);
00404     QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00405 
00406     QLabel *msgLabel = new QLabel;
00407     msgLabel->installEventFilter(this);
00408     msgLabel->setText(message);
00409     msgLabel->setTextFormat(Qt::PlainText);
00410     msgLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
00411 
00412     QIcon si;
00413     switch (icon) {
00414     case QSystemTrayIcon::Warning:
00415         si = style()->standardIcon(QStyle::SP_MessageBoxWarning);
00416         break;
00417     case QSystemTrayIcon::Critical:
00418   si = style()->standardIcon(QStyle::SP_MessageBoxCritical);
00419         break;
00420     case QSystemTrayIcon::Information:
00421   si = style()->standardIcon(QStyle::SP_MessageBoxInformation);
00422         break;
00423     case QSystemTrayIcon::NoIcon:
00424     default:
00425         break;
00426     }
00427 
00428     QGridLayout *layout = new QGridLayout;
00429     if (!si.isNull()) {
00430         QLabel *iconLabel = new QLabel;
00431         iconLabel->setPixmap(si.pixmap(15, 15));
00432         iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00433         iconLabel->setMargin(2);
00434         layout->addWidget(iconLabel, 0, 0);
00435   layout->addWidget(titleLabel, 0, 1);
00436     } else {
00437   layout->addWidget(titleLabel, 0, 0, 1, 2);
00438     }
00439 
00440     layout->addWidget(closeButton, 0, 2);
00441     layout->addWidget(msgLabel, 1, 0, 1, 3);
00442     layout->setSizeConstraint(QLayout::SetFixedSize);
00443     layout->setMargin(3);
00444     layout->setSpacing(1);
00445     setLayout(layout);
00446 
00447     QPalette pal = palette();
00448     pal.setColor(QPalette::Window, QColor(0xff, 0xff, 0xe1));
00449     setPalette(pal);
00450 }

Here is the call graph for this function:

QBalloonTip::~QBalloonTip (  )  [private]

Definition at line 452 of file qsystemtrayicon.cpp.

References theSolitaryBalloonTip.

00453 {
00454     theSolitaryBalloonTip = 0;
00455 }


Member Function Documentation

void QBalloonTip::showBalloon ( QSystemTrayIcon::MessageIcon  icon,
const QString title,
const QString msg,
QSystemTrayIcon trayIcon,
const QPoint pos,
int  timeout,
bool  showArrow = true 
) [static]

Definition at line 364 of file qsystemtrayicon.cpp.

References balloon(), hideBalloon(), message, QWidget::pos(), QBalloonTip(), theSolitaryBalloonTip, and trayIcon.

Referenced by QSystemTrayIconPrivate::showMessage_sys().

00367 {
00368     hideBalloon();
00369     theSolitaryBalloonTip = new QBalloonTip(icon, title, message, trayIcon);
00370     if (timeout < 0)
00371         timeout = 10000; //10 s default
00372     theSolitaryBalloonTip->balloon(pos, timeout, showArrow);
00373 }

Here is the call graph for this function:

void QBalloonTip::hideBalloon (  )  [static]

Definition at line 375 of file qsystemtrayicon.cpp.

References QWidget::hide(), and theSolitaryBalloonTip.

Referenced by QSystemTrayIconPrivate::remove_sys(), and showBalloon().

00376 {
00377     if (!theSolitaryBalloonTip)
00378         return;
00379     theSolitaryBalloonTip->hide();
00380     delete theSolitaryBalloonTip;
00381     theSolitaryBalloonTip = 0;
00382 }

void QBalloonTip::balloon ( const QPoint ,
int  ,
bool   
) [private]

Definition at line 468 of file qsystemtrayicon.cpp.

References Qt::black, Qt::color0, Qt::color1, QApplication::desktop(), QPainter::drawPath(), QPixmap::fill(), QRect::height(), QSize::height(), QRect::left(), QWidget::move(), QWidget::palette(), path, pixmap, QWidget::pos(), qMax(), qMin(), QWidget::QPixmap, QRect::right(), QDesktopWidget::screenGeometry(), QPainter::setBrush(), QWidget::setContentsMargins(), QWidget::setMask(), QPainter::setPen(), QWidget::show(), QWidget::sizeHint(), QObject::startTimer(), timerId, QWidget::updateGeometry(), QRect::width(), QSize::width(), QPalette::Window, QRect::x(), QPoint::x(), and QPoint::y().

Referenced by showBalloon().

00469 {
00470     QRect scr = QApplication::desktop()->screenGeometry(pos);
00471     QSize sh = sizeHint();
00472     const int border = 1;
00473     const int ah = 18, ao = 18, aw = 18, rc = 7;
00474     bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height());
00475     bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width());
00476     setContentsMargins(border + 3,  border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2);
00477     updateGeometry();
00478     sh  = sizeHint();
00479 
00480     int ml, mr, mt, mb;
00481     QSize sz = sizeHint();
00482     if (!arrowAtTop) {
00483         ml = mt = 0;
00484         mr = sz.width() - 1;
00485         mb = sz.height() - ah - 1;
00486     } else {
00487         ml = 0;
00488         mt = ah;
00489         mr = sz.width() - 1;
00490         mb = sz.height() - 1;
00491     }
00492 
00493     QPainterPath path;
00494     path.moveTo(ml + rc, mt);
00495     if (arrowAtTop && arrowAtLeft) {
00496         if (showArrow) {
00497             path.lineTo(ml + ao, mt);
00498             path.lineTo(ml + ao, mt - ah);
00499             path.lineTo(ml + ao + aw, mt);
00500         }
00501         move(qMax(pos.x() - ao, scr.left() + 2), pos.y());
00502     } else if (arrowAtTop && !arrowAtLeft) {
00503         if (showArrow) {
00504             path.lineTo(mr - ao - aw, mt);
00505             path.lineTo(mr - ao, mt - ah);
00506             path.lineTo(mr - ao, mt);
00507         }
00508         move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y());
00509     }
00510     path.lineTo(mr - rc, mt);
00511     path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90);
00512     path.lineTo(mr, mb - rc);
00513     path.arcTo(QRect(mr - rc*2, mb - rc*2, rc*2, rc*2), 0, -90);
00514     if (!arrowAtTop && !arrowAtLeft) {
00515         if (showArrow) {
00516             path.lineTo(mr - ao, mb);
00517             path.lineTo(mr - ao, mb + ah);
00518             path.lineTo(mr - ao - aw, mb);
00519         }
00520         move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2),
00521              pos.y() - sh.height());
00522     } else if (!arrowAtTop && arrowAtLeft) {
00523         if (showArrow) {
00524             path.lineTo(ao + aw, mb);
00525             path.lineTo(ao, mb + ah);
00526             path.lineTo(ao, mb);
00527         }
00528         move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height());
00529     }
00530     path.lineTo(ml + rc, mb);
00531     path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90);
00532     path.lineTo(ml, mt + rc);
00533     path.arcTo(QRect(ml, mt, rc*2, rc*2), 180, -90);
00534 
00535     // Set the mask
00536     QBitmap bitmap = QBitmap(sizeHint());
00537     bitmap.fill(Qt::color0);
00538     QPainter painter1(&bitmap);
00539     painter1.setPen(QPen(Qt::color1, border));
00540     painter1.setBrush(QBrush(Qt::color1));
00541     painter1.drawPath(path);
00542     setMask(bitmap);
00543 
00544     // Draw the border
00545     pixmap = QPixmap(sz);
00546     QPainter painter2(&pixmap);
00547     painter2.setPen(QPen(Qt::black, border));
00548     painter2.setBrush(palette().color(QPalette::Window));
00549     painter2.drawPath(path);
00550 
00551     if (msecs > 0)
00552         timerId = startTimer(msecs);
00553     show();
00554 }

Here is the call graph for this function:

void QBalloonTip::paintEvent ( QPaintEvent  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

See also:
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock Example}

Reimplemented from QWidget.

Definition at line 457 of file qsystemtrayicon.cpp.

References QPainter::drawPixmap(), pixmap, and QWidget::rect().

00458 {
00459     QPainter painter(this);
00460     painter.drawPixmap(rect(), pixmap);
00461 }

Here is the call graph for this function:

void QBalloonTip::resizeEvent ( QResizeEvent ev  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.

See also:
moveEvent(), event(), resize(), QResizeEvent, paintEvent(), {Scribble Example}

Reimplemented from QWidget.

Definition at line 463 of file qsystemtrayicon.cpp.

References QWidget::resizeEvent().

00464 {
00465     QWidget::resizeEvent(ev);
00466 }

Here is the call graph for this function:

void QBalloonTip::mousePressEvent ( QMouseEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 556 of file qsystemtrayicon.cpp.

References QMouseEvent::button(), QWidget::close(), emit, Qt::LeftButton, QSystemTrayIcon::messageClicked(), and trayIcon.

00557 {
00558     close();
00559     if(e->button() == Qt::LeftButton)
00560         emit trayIcon->messageClicked();
00561 }

Here is the call graph for this function:

void QBalloonTip::timerEvent ( QTimerEvent e  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also:
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 563 of file qsystemtrayicon.cpp.

References QWidget::close(), QObject::killTimer(), QObject::timerEvent(), QTimerEvent::timerId(), timerId, and QWidget::underMouse().

00564 {
00565     if (e->timerId() == timerId) {
00566         killTimer(timerId);
00567         if (!underMouse())
00568             close();
00569         return;
00570     }
00571     QWidget::timerEvent(e);
00572 }

Here is the call graph for this function:


Member Data Documentation

QSystemTrayIcon* QBalloonTip::trayIcon [private]

Definition at line 96 of file qsystemtrayicon_p.h.

Referenced by mousePressEvent(), and showBalloon().

QPixmap QBalloonTip::pixmap [private]

Definition at line 97 of file qsystemtrayicon_p.h.

Referenced by balloon(), and paintEvent().

int QBalloonTip::timerId [private]

Definition at line 98 of file qsystemtrayicon_p.h.

Referenced by balloon(), and timerEvent().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:51:27 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1