VirtualBox

Ignore:
Timestamp:
Jun 23, 2008 1:26:35 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: Extend QITreeWidget api to let it's complex items have separate painting routines.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/QITreeWidget.h

    r9867 r9872  
    2424#define __QITreeWidget_h__
    2525
    26 /* Qt includes */
    2726#include <QTreeWidget>
    2827
     28/*
     29 * QTreeWidget class which extends standard QTreeWidget's functionality.
     30 */
    2931class QITreeWidget: public QTreeWidget
    3032{
     
    3234
    3335public:
     36
     37    /*
     38     * There are two allowed QTreeWidgetItem types which may be used with
     39     * QITreeWidget: basic and complex.
     40     * Complex type used in every place where the particular item have to
     41     * be separately repainted with it's own content.
     42     * Basic are used in all other places.
     43     */
     44    enum
     45    {
     46        BasicItemType   = QTreeWidgetItem::UserType + 1,
     47        ComplexItemType = QTreeWidgetItem::UserType + 2
     48    };
    3449
    3550    QITreeWidget (QWidget *aParent = 0);
     
    4156    virtual Qt::DropActions supportedDropActions () const;
    4257
     58    void paintEvent (QPaintEvent *);
     59
    4360    /* Protected member vars */
    4461    Qt::DropActions mSupportedDropActions;
    4562};
    4663
     64/*
     65 * Interface for more complex items which requires special repainting
     66 * routine inside QITreeWidget's viewport.
     67 */
     68class ComplexTreeWidgetItem : public QTreeWidgetItem
     69{
     70public:
     71
     72    ComplexTreeWidgetItem (QTreeWidget *aParent)
     73        : QTreeWidgetItem  (aParent, QITreeWidget::ComplexItemType) {}
     74
     75    virtual void paintItem (QPainter *aPainter) = 0;
     76};
     77
    4778#endif /* __QITreeWidget_h__ */
    4879
  • trunk/src/VBox/Frontends/VirtualBox4/src/QITreeWidget.cpp

    r9867 r9872  
    2323#include "QITreeWidget.h"
    2424
    25 /* Qt includes */
    26 #include <QMouseEvent>
     25#include <QPainter>
    2726
    2827QITreeWidget::QITreeWidget (QWidget *aParent)
     
    4140}
    4241
     42void QITreeWidget::paintEvent (QPaintEvent *aEvent)
     43{
     44    /* Painter for items */
     45    QPainter painter (viewport());
     46
     47    /* Here we let the items make some painting inside the viewport. */
     48    QTreeWidgetItemIterator it (this);
     49    while (*it)
     50    {
     51        switch ((*it)->type())
     52        {
     53            case ComplexItemType:
     54            {
     55                /* Let the ComplexItem paint itself */
     56                ComplexTreeWidgetItem *i = static_cast<ComplexTreeWidgetItem*> (*it);
     57                i->paintItem (&painter);
     58                break;
     59            }
     60            case BasicItemType:
     61            {
     62                /* Do nothing for BasicItem */
     63                break;
     64            }
     65            default:
     66            {
     67                /* Wrong item is used */
     68                break;
     69            }
     70        }
     71        ++ it;
     72    }
     73
     74    QTreeWidget::paintEvent (aEvent);
     75}
     76
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDiskImageManagerDlg.cpp

    r9867 r9872  
    5757public:
    5858
    59     enum { TypeId = QTreeWidgetItem::UserType + 1 };
    60 
    6159    DiskImageItem (DiskImageItem *aParent) :
    62         QTreeWidgetItem (aParent, TypeId), mStatus (VBoxMedia::Unknown) {}
     60        QTreeWidgetItem (aParent, QITreeWidget::BasicItemType), mStatus (VBoxMedia::Unknown) {}
    6361
    6462    DiskImageItem (QTreeWidget *aParent) :
    65         QTreeWidgetItem (aParent, TypeId), mStatus (VBoxMedia::Unknown) {}
     63        QTreeWidgetItem (aParent, QITreeWidget::BasicItemType), mStatus (VBoxMedia::Unknown) {}
    6664
    6765    void setMedia (const VBoxMedia &aMedia) { mMedia = aMedia; }
     
    182180    {
    183181        QTreeWidgetItem *item = QTreeWidgetItemIterator::operator*();
    184         return item && item->type() == DiskImageItem::TypeId ?
     182        return item && item->type() == QITreeWidget::BasicItemType ?
    185183            static_cast<DiskImageItem*> (item) : NULL;
    186184    }
     
    14571455    DiskImageItem *item = NULL;
    14581456    if (aItem &&
    1459         aItem->type() == DiskImageItem::TypeId)
     1457        aItem->type() == QITreeWidget::BasicItemType)
    14601458        item = static_cast <DiskImageItem *> (aItem);
    14611459
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette