Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions

QxtToolTipPrivate Class Reference

#include <qxttooltip_p.h>

Collaboration diagram for QxtToolTipPrivate:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QxtToolTipPrivate ()
 ~QxtToolTipPrivate ()
void show (const QPoint &pos, QWidget *tooltip, QWidget *parent=0, const QRect &rect=QRect())
void setToolTip (QWidget *tooltip)
bool eventFilter (QObject *parent, QEvent *event)
void hideLater ()
QPoint calculatePos (int scr, const QPoint &eventPos) const

Static Public Member Functions

static QxtToolTipPrivateinstance ()

Public Attributes

QHash< WidgetPtr, WidgetAreatooltips
QVBoxLayout * vbox

Protected Member Functions

void enterEvent (QEvent *event)
void paintEvent (QPaintEvent *event)

Detailed Description

Definition at line 38 of file qxttooltip_p.h.


Constructor & Destructor Documentation

QxtToolTipPrivate::QxtToolTipPrivate (  )

Definition at line 52 of file qxttooltip.cpp.

References FLAGS, and vbox.

Referenced by instance().

                                     : QWidget(qApp->desktop(), FLAGS)
{
    setWindowFlags(FLAGS);
    vbox = new QVBoxLayout(this);
    setPalette(QToolTip::palette());
    setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0);
    layout()->setMargin(style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
    qApp->installEventFilter(this);
}
QxtToolTipPrivate::~QxtToolTipPrivate (  )

Definition at line 62 of file qxttooltip.cpp.

{
    qApp->removeEventFilter(this); // not really necessary but rather for completeness :)
    self = 0;
}

Member Function Documentation

QPoint QxtToolTipPrivate::calculatePos ( int  scr,
const QPoint &  eventPos 
) const

Definition at line 182 of file qxttooltip.cpp.

Referenced by show().

{
#ifdef Q_WS_MAC
    QRect screen = QApplication::desktop()->availableGeometry(scr);
#else
    QRect screen = QApplication::desktop()->screenGeometry(scr);
#endif

    QPoint p = eventPos;
    p += QPoint(2,
#ifdef Q_WS_WIN
                24
#else
                16
#endif
               );
    QSize s = sizeHint();
    if (p.x() + s.width() > screen.x() + screen.width())
        p.rx() -= 4 + s.width();
    if (p.y() + s.height() > screen.y() + screen.height())
        p.ry() -= 24 + s.height();
    if (p.y() < screen.y())
        p.setY(screen.y());
    if (p.x() + s.width() > screen.x() + screen.width())
        p.setX(screen.x() + screen.width() - s.width());
    if (p.x() < screen.x())
        p.setX(screen.x());
    if (p.y() + s.height() > screen.y() + screen.height())
        p.setY(screen.y() + screen.height() - s.height());
    return p;
}
void QxtToolTipPrivate::enterEvent ( QEvent *  event ) [protected]

Definition at line 100 of file qxttooltip.cpp.

References hideLater().

{
    Q_UNUSED(event);
    hideLater();
}
bool QxtToolTipPrivate::eventFilter ( QObject *  parent,
QEvent *  event 
)

Definition at line 115 of file qxttooltip.cpp.

References hideLater(), mitk::Key_Alt, mitk::Key_Control, mitk::Key_Meta, mitk::Key_Shift, show(), and tooltips.

{
    switch (event->type())
    {
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
    {
        // accept only modifiers
        const QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        const int key = keyEvent->key();
        const Qt::KeyboardModifiers mods = keyEvent->modifiers();
        if ((mods & Qt::KeyboardModifierMask) ||
                (key == Qt::Key_Shift || key == Qt::Key_Control ||
                 key == Qt::Key_Alt || key == Qt::Key_Meta))
            break;
    }
    case QEvent::Leave:
    case QEvent::WindowActivate:
    case QEvent::WindowDeactivate:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
    case QEvent::FocusIn:
    case QEvent::FocusOut:
    case QEvent::Wheel:
        hideLater();
        break;

    case QEvent::MouseMove:
    {
        const QPoint pos = static_cast<QMouseEvent*>(event)->pos();
        if (!currentRect.isNull() && !currentRect.contains(pos))
        {
            hideLater();
        }
        break;
    }

    case QEvent::ToolTip:
    {
        // eat appropriate tooltip events
        QWidget* widget = static_cast<QWidget*>(object);
        if (tooltips.contains(widget))
        {
            QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
            const QRect area = tooltips.value(widget).second;
            if (area.isNull() || area.contains(helpEvent->pos()))
            {
                show(helpEvent->globalPos(), tooltips.value(widget).first, widget, area);
                return true;
            }
        }
    }

    default:
        break;
    }
    return false;
}
void QxtToolTipPrivate::hideLater (  )

Definition at line 175 of file qxttooltip.cpp.

Referenced by enterEvent(), and eventFilter().

{
    currentRect = QRect();
    if (isVisible())
        QTimer::singleShot(0, this, SLOT(hide()));
}
QxtToolTipPrivate * QxtToolTipPrivate::instance (  ) [static]
void QxtToolTipPrivate::paintEvent ( QPaintEvent *  event ) [protected]

Definition at line 106 of file qxttooltip.cpp.

{
    Q_UNUSED(event);
    QStylePainter painter(this);
    QStyleOptionFrame opt;
    opt.initFrom(this);
    painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
}
void QxtToolTipPrivate::setToolTip ( QWidget *  tooltip )

Definition at line 88 of file qxttooltip.cpp.

References vbox.

Referenced by show().

{
    for (int i = 0; i < vbox->count(); ++i)
    {
        QLayoutItem* item = layout()->takeAt(i);
        if (item->widget())
            item->widget()->hide();
    }
    vbox->addWidget(tooltip);
    tooltip->show();
}
void QxtToolTipPrivate::show ( const QPoint &  pos,
QWidget *  tooltip,
QWidget *  parent = 0,
const QRect &  rect = QRect() 
)

Definition at line 68 of file qxttooltip.cpp.

References calculatePos(), FLAGS, and setToolTip().

Referenced by eventFilter(), and QxtToolTip::show().

{
    Q_ASSERT(tooltip && parent);
    if (!isVisible())
    {
        int scr = 0;
        if (QApplication::desktop()->isVirtualDesktop())
            scr = QApplication::desktop()->screenNumber(pos);
        else
            scr = QApplication::desktop()->screenNumber(this);
        setParent(QApplication::desktop()->screen(scr));
        setWindowFlags(FLAGS);
        setToolTip(tooltip);
        currentParent = parent;
        currentRect = rect;
        move(calculatePos(scr, pos));
        QWidget::show();
    }
}

Member Data Documentation

Definition at line 53 of file qxttooltip_p.h.

Referenced by QxtToolTipPrivate(), and setToolTip().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines