Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes

QwtPicker::PickerWidget Class Reference

Collaboration diagram for QwtPicker::PickerWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Type { RubberBand, Text }

Public Member Functions

 PickerWidget (QwtPicker *, QWidget *, Type)
virtual void updateMask ()

Public Attributes

bool d_hasTextMask

Protected Member Functions

virtual void paintEvent (QPaintEvent *)

Protected Attributes

QwtPickerd_picker
Type d_type

Detailed Description

Definition at line 27 of file qwt_picker.cpp.


Member Enumeration Documentation

Enumerator:
RubberBand 
Text 

Definition at line 30 of file qwt_picker.cpp.


Constructor & Destructor Documentation

QwtPicker::PickerWidget::PickerWidget ( QwtPicker picker,
QWidget *  parent,
Type  type 
)

Definition at line 92 of file qwt_picker.cpp.

                                                      :
    QWidget(parent),
    d_hasTextMask(false),
    d_picker(picker),
    d_type(type)
{
#if QT_VERSION >= 0x040000
    setAttribute(Qt::WA_TransparentForMouseEvents);
    setAttribute(Qt::WA_NoSystemBackground);
    setFocusPolicy(Qt::NoFocus);
#else
    setBackgroundMode(Qt::NoBackground);
    setFocusPolicy(QWidget::NoFocus);
    setMouseTracking(true);
#endif
    hide();
}

Member Function Documentation

void QwtPicker::PickerWidget::paintEvent ( QPaintEvent *  e ) [protected, virtual]

Definition at line 205 of file qwt_picker.cpp.

{
    QPainter painter(this);
    painter.setClipRegion(e->region());

    if ( d_type == RubberBand )
    {
        painter.setPen(d_picker->rubberBandPen());
        d_picker->drawRubberBand(&painter);
    }

    if ( d_type == Text )
    {
        /*
           If we have a text mask we simply fill the region of
           the mask. This gives better results for antialiased fonts.
         */
        bool doDrawTracker = !d_hasTextMask;
#if QT_VERSION < 0x040000
        if ( !doDrawTracker && QPainter::redirect(this) )
        {
            // setMask + painter redirection doesn't work
            doDrawTracker = true;
        }
#endif
        if ( doDrawTracker )
        {
            painter.setPen(d_picker->trackerPen());
            d_picker->drawTracker(&painter);
        }
        else
            painter.fillRect(e->rect(), QBrush(d_picker->trackerPen().color()));
    }
}
void QwtPicker::PickerWidget::updateMask (  ) [virtual]

Definition at line 111 of file qwt_picker.cpp.

References QwtText::backgroundBrush(), QwtText::PaintBackground, QwtPicker::parentWidget(), and QwtText::testPaintAttribute().

{
    QRegion mask;

    if ( d_type == RubberBand )
    {
        QBitmap bm(width(), height());
        bm.fill(Qt::color0);

        QPainter painter(&bm);
        QPen pen = d_picker->rubberBandPen();
        pen.setColor(Qt::color1);
        painter.setPen(pen);

        d_picker->drawRubberBand(&painter);

        mask = QRegion(bm);
    }
    if ( d_type == Text )
    {
        d_hasTextMask = true;
#if QT_VERSION >= 0x040300
        if ( !parentWidget()->testAttribute(Qt::WA_PaintOnScreen) )
        {
#if 0
            if ( parentWidget()->paintEngine()->type() != QPaintEngine::OpenGL )
#endif
            {
                // With Qt >= 4.3 drawing of the tracker can be implemented in an
                // easier way, using the textRect as mask. 

                d_hasTextMask = false;
            }
        }
#endif
        
        if ( d_hasTextMask )
        {
            const QwtText label = d_picker->trackerText(
                d_picker->trackerPosition());
            if ( label.testPaintAttribute(QwtText::PaintBackground)
                && label.backgroundBrush().style() != Qt::NoBrush )
            {
#if QT_VERSION >= 0x040300
                if ( label.backgroundBrush().color().alpha() > 0 )
#endif
                // We don't need a text mask, when we have a background
                d_hasTextMask = false;
            }
        }

        if ( d_hasTextMask )
        {
            QBitmap bm(width(), height());
            bm.fill(Qt::color0);

            QPainter painter(&bm);
            painter.setFont(font());

            QPen pen = d_picker->trackerPen();
            pen.setColor(Qt::color1);
            painter.setPen(pen);

            d_picker->drawTracker(&painter);

            mask = QRegion(bm);
        }
        else
        {
            mask = d_picker->trackerRect(font());
        }
    }

#if QT_VERSION < 0x040000
    QWidget *w = parentWidget();
    const bool doUpdate = w->isUpdatesEnabled();
    const Qt::BackgroundMode bgMode = w->backgroundMode();
    w->setUpdatesEnabled(false);
    if ( bgMode != Qt::NoBackground )
        w->setBackgroundMode(Qt::NoBackground);
#endif

    setMask(mask);

#if QT_VERSION < 0x040000
    if ( bgMode != Qt::NoBackground )
        w->setBackgroundMode(bgMode);

    w->setUpdatesEnabled(doUpdate);
#endif

    setShown(!mask.isEmpty());
}

Member Data Documentation

Definition at line 44 of file qwt_picker.cpp.

Definition at line 49 of file qwt_picker.cpp.

Definition at line 50 of file qwt_picker.cpp.


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