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

QxtItemDelegatePrivate Class Reference

#include <qxtitemdelegate_p.h>

Inheritance diagram for QxtItemDelegatePrivate:
Inheritance graph
[legend]
Collaboration diagram for QxtItemDelegatePrivate:
Collaboration graph
[legend]

List of all members.

Public Types

typedef QPointer< QWidget > QWidgetPointer

Public Member Functions

 QxtItemDelegatePrivate ()
void paintButton (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QTreeView *view) const
void paintMenu (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QTreeView *view) const
void paintProgress (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setCurrentEditor (QWidget *editor, const QModelIndex &index) const

Public Attributes

bool textVisible
QString progressFormat
Qt::TextElideMode elide
Qxt::DecorationStyle style
QWidgetPointer currentEditor
QPersistentModelIndex currentEdited
QMultiHash< QWidget
*, QPersistentModelIndex > 
updatedItems
QBasicTimer updateTimer

Protected Member Functions

void timerEvent (QTimerEvent *event)

Friends

class QxtItemDelegate

Detailed Description

Definition at line 38 of file qxtitemdelegate_p.h.


Member Typedef Documentation

typedef QPointer<QWidget> QxtItemDelegatePrivate::QWidgetPointer

Definition at line 55 of file qxtitemdelegate_p.h.


Constructor & Destructor Documentation

QxtItemDelegatePrivate::QxtItemDelegatePrivate (  )

Definition at line 34 of file qxtitemdelegate.cpp.

                                               :
        textVisible(true),
        progressFormat("%1%"),
        elide(Qt::ElideMiddle),
        style(Qxt::NoDecoration)
{
}

Member Function Documentation

void QxtItemDelegatePrivate::paintButton ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index,
const QTreeView *  view 
) const

Definition at line 42 of file qxtitemdelegate.cpp.

References elide.

{
    // draw the button
    QStyleOptionButton buttonOption;
    buttonOption.state = option.state;
#ifdef Q_WS_MAC
    buttonOption.state |= QStyle::State_Raised;
#endif
    buttonOption.state &= ~QStyle::State_HasFocus;
    if (view->isExpanded(index))
        buttonOption.state |= QStyle::State_Sunken;
    buttonOption.rect = option.rect;
    buttonOption.palette = option.palette;
    buttonOption.features = QStyleOptionButton::None;
    view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, view);

    // draw the branch indicator
    static const int i = 9;
    const QRect& r = option.rect;
    if (index.model()->hasChildren(index))
    {
        QStyleOption branchOption;
        branchOption.initFrom(view);
        if (branchOption.direction == Qt::LeftToRight)
            branchOption.rect = QRect(r.left() + i / 2, r.top() + (r.height() - i) / 2, i, i);
        else
            branchOption.rect = QRect(r.right() - i / 2 - i, r.top() + (r.height() - i) / 2, i, i);
        branchOption.palette = option.palette;
        branchOption.state = QStyle::State_Children;
        if (view->isExpanded(index))
            branchOption.state |= QStyle::State_Open;
        view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, view);
    }

    // draw the text
    QRect textrect = QRect(r.left() + i * 2, r.top(), r.width() - ((5 * i) / 2), r.height());
#if QT_VERSION < 0x040200
    QString text = QItemDelegate::elidedText(option.fontMetrics, textrect.width(), elide, index.data().toString());
#else // QT_VERSION >= 0x040200
    QString text = option.fontMetrics.elidedText(index.data().toString(), elide, textrect.width());
#endif // QT_VERSION
    view->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, view->isEnabled(), text);
}
void QxtItemDelegatePrivate::paintMenu ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index,
const QTreeView *  view 
) const

Definition at line 86 of file qxtitemdelegate.cpp.

{
    // draw the menu bar item
    QStyleOptionMenuItem menuOption;
    menuOption.palette = view->palette();
    menuOption.fontMetrics = view->fontMetrics();
    menuOption.state = QStyle::State_None;
    // QModelIndex::flags() was introduced in 4.2
    // => therefore "index.model()->flags(index)"
    if (view->isEnabled() && index.model()->flags(index) & Qt::ItemIsEnabled)
        menuOption.state |= QStyle::State_Enabled;
    else
        menuOption.palette.setCurrentColorGroup(QPalette::Disabled);
    menuOption.state |= QStyle::State_Selected;
    menuOption.state |= QStyle::State_Sunken;
    menuOption.state |= QStyle::State_HasFocus;
    menuOption.rect = option.rect;
    menuOption.text = index.data().toString();
    menuOption.icon = QIcon(index.data(Qt::DecorationRole).value<QPixmap>());
    view->style()->drawControl(QStyle::CE_MenuBarItem, &menuOption, painter, view);

    // draw the an arrow as a branch indicator
    if (index.model()->hasChildren(index))
    {
        QStyle::PrimitiveElement arrow;
        if (view->isExpanded(index))
            arrow = QStyle::PE_IndicatorArrowUp;
        else
            arrow = QStyle::PE_IndicatorArrowDown;
        static const int i = 9;
        const QRect& r = option.rect;
        menuOption.rect = QRect(r.left() + i / 2, r.top() + (r.height() - i) / 2, i, i);
        view->style()->drawPrimitive(arrow, &menuOption, painter, view);
    }
}
void QxtItemDelegatePrivate::paintProgress ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const

Definition at line 122 of file qxtitemdelegate.cpp.

References QuadProgPP::max(), min, progressFormat, QxtItemDelegate::ProgressMaximumRole, QxtItemDelegate::ProgressMinimumRole, QxtItemDelegate::ProgressValueRole, style, textVisible, updatedItems, and updateTimer.

{
    QVariant min = index.data(QxtItemDelegate::ProgressMinimumRole);
    QVariant max = index.data(QxtItemDelegate::ProgressMaximumRole);

    QStyleOptionProgressBar opt;
    opt.minimum = (min.isValid() && min.canConvert(QVariant::Int)) ? min.toInt() : 0;
    opt.maximum = (max.isValid() && max.canConvert(QVariant::Int)) ? max.toInt() : 100;
    opt.progress = index.data(QxtItemDelegate::ProgressValueRole).toInt();
    opt.rect = option.rect;
    opt.textVisible = textVisible;
    opt.text = progressFormat.arg(opt.progress);
    QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0);

    QWidget* viewport = dynamic_cast<QWidget*>(painter->device());
    if (viewport)
    {
        if (opt.minimum == 0 && opt.maximum == 0)
        {
            if (!updatedItems.contains(viewport))
                connect(viewport, SIGNAL(destroyed()), this, SLOT(viewDestroyed()));
            updatedItems.replace(viewport, index);
        }
        else
        {
            updatedItems.remove(viewport, index);
            if (!updatedItems.contains(viewport))
                disconnect(viewport, SIGNAL(destroyed()), this, SLOT(viewDestroyed()));
        }
    }

    if (updatedItems.isEmpty())
    {
        if (updateTimer.isActive())
            updateTimer.stop();
    }
    else
    {
        if (!updateTimer.isActive())
            updateTimer.start(1000 / 25, const_cast<QxtItemDelegatePrivate*>(this));
    }
}
void QxtItemDelegatePrivate::setCurrentEditor ( QWidget *  editor,
const QModelIndex &  index 
) const

Definition at line 165 of file qxtitemdelegate.cpp.

References currentEdited, and currentEditor.

{
    currentEditor = editor;
    currentEdited = index;
}
void QxtItemDelegatePrivate::timerEvent ( QTimerEvent *  event ) [protected]

Definition at line 171 of file qxtitemdelegate.cpp.

References updatedItems, and updateTimer.

{
    if (event->timerId() == updateTimer.timerId())
    {
        QMutableHashIterator<QWidget*, QPersistentModelIndex> it(updatedItems);
        while (it.hasNext())
        {
            it.next();
            if (!it.key())
            {
                it.remove();
                continue;
            }

            // try to update the specific view item instead of the whole view if possible
            if (QAbstractItemView* view = qobject_cast<QAbstractItemView*>(it.key()->parentWidget()))
                view->update(it.value());
            else
                it.key()->update();
        }
    }
}

Friends And Related Function Documentation

friend class QxtItemDelegate [friend]

Definition at line 43 of file qxtitemdelegate_p.h.


Member Data Documentation

QPersistentModelIndex QxtItemDelegatePrivate::currentEdited [mutable]

Definition at line 57 of file qxtitemdelegate_p.h.

Referenced by setCurrentEditor().

Definition at line 56 of file qxtitemdelegate_p.h.

Referenced by setCurrentEditor().

Qt::TextElideMode QxtItemDelegatePrivate::elide

Definition at line 53 of file qxtitemdelegate_p.h.

Referenced by paintButton().

Definition at line 52 of file qxtitemdelegate_p.h.

Referenced by paintProgress().

Definition at line 54 of file qxtitemdelegate_p.h.

Referenced by paintProgress().

Definition at line 51 of file qxtitemdelegate_p.h.

Referenced by paintProgress().

QMultiHash<QWidget*, QPersistentModelIndex> QxtItemDelegatePrivate::updatedItems [mutable]

Definition at line 58 of file qxtitemdelegate_p.h.

Referenced by paintProgress(), and timerEvent().

QBasicTimer QxtItemDelegatePrivate::updateTimer [mutable]

Definition at line 59 of file qxtitemdelegate_p.h.

Referenced by paintProgress(), and timerEvent().


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