VirtualBox

Changeset 24054 in vbox for trunk


Ignore:
Timestamp:
Oct 24, 2009 2:51:38 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53913
Message:

FE/Qt4: Cleaning QTreeWidget from garbage, reworking QTreeWidget painting mechanism, updating related stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited

Legend:

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

    r13580 r24054  
    66
    77/*
    8  * Copyright (C) 2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#define __QITreeWidget_h__
    2525
     26/* Global includes */
    2627#include <QTreeWidget>
    2728
     
    3536public:
    3637
    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     };
    49 
    5038    QITreeWidget (QWidget *aParent = 0);
    51 
    52     void setSupportedDropActions (Qt::DropActions aAction);
    5339
    5440    void addTopBottomMarginToItems (int aMargin);
     
    5642signals:
    5743
     44    void painted (QTreeWidgetItem *aItem, QPainter *aPainter);
    5845    void resized (const QSize &aSize, const QSize &aOldSize);
    5946
    6047protected:
    6148
    62     virtual Qt::DropActions supportedDropActions () const;
    63 
    64     void paintEvent (QPaintEvent *);
    65     void resizeEvent (QResizeEvent *);
    66 
    67     /* Protected member vars */
    68     Qt::DropActions mSupportedDropActions;
    69 };
    70 
    71 /*
    72  * Interface for more complex items which requires special repainting
    73  * routine inside QITreeWidget's viewport.
    74  */
    75 class ComplexTreeWidgetItem : public QTreeWidgetItem
    76 {
    77 public:
    78 
    79     ComplexTreeWidgetItem (QTreeWidget *aParent)
    80         : QTreeWidgetItem  (aParent, QITreeWidget::ComplexItemType) {}
    81 
    82     virtual void paintItem (QPainter *aPainter) = 0;
     49    void paintEvent (QPaintEvent *aEvent);
     50    void resizeEvent (QResizeEvent *aEvent);
    8351};
    8452
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGLSettingsLanguage.h

    r10212 r24054  
    5151private slots:
    5252
    53     void mTwLanguageChanged (QTreeWidgetItem *aCurr, QTreeWidgetItem *aPrev);
     53    void mTwItemPainted (QTreeWidgetItem *aItem, QPainter *aPainter);
     54    void mTwLanguageChanged (QTreeWidgetItem *aItem);
    5455
    5556private:
  • trunk/src/VBox/Frontends/VirtualBox/src/QITreeWidget.cpp

    r13580 r24054  
    66
    77/*
    8  * Copyright (C) 2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 #include "QITreeWidget.h"
    24 
     23/* Global includes */
    2524#include <QPainter>
    2625#include <QResizeEvent>
     26
     27/* Local includes */
     28#include "QITreeWidget.h"
    2729
    2830QITreeWidget::QITreeWidget (QWidget *aParent)
     
    3133}
    3234
    33 void QITreeWidget::setSupportedDropActions (Qt::DropActions aAction)
    34 {
    35     mSupportedDropActions = aAction;
    36 }
    37 
    38 Qt::DropActions QITreeWidget::supportedDropActions() const
    39 {
    40     return mSupportedDropActions;
    41 }
    42 
    4335void QITreeWidget::paintEvent (QPaintEvent *aEvent)
    4436{
    45     /* Painter for items */
    46     QPainter painter (viewport());
     37    /* Opens Items Painter */
     38    QPainter painter;
     39    painter.begin (viewport());
    4740
    48     /* Here we let the items make some painting inside the viewport. */
     41    /* Notify connected objects about painting */
    4942    QTreeWidgetItemIterator it (this);
    5043    while (*it)
    5144    {
    52         switch ((*it)->type())
    53         {
    54             case ComplexItemType:
    55             {
    56                 /* Let the ComplexItem paint itself */
    57                 ComplexTreeWidgetItem *i = static_cast<ComplexTreeWidgetItem*> (*it);
    58                 i->paintItem (&painter);
    59                 break;
    60             }
    61             case BasicItemType:
    62             {
    63                 /* Do nothing for BasicItem */
    64                 break;
    65             }
    66             default:
    67             {
    68                 /* Wrong item is used */
    69                 break;
    70             }
    71         }
     45        emit painted (*it, &painter);
    7246        ++ it;
    7347    }
     48
     49    /* Close Items Painter */
    7450    painter.end();
    7551
     52    /* Base-class paint-event */
    7653    QTreeWidget::paintEvent (aEvent);
    7754}
     
    7956void QITreeWidget::resizeEvent (QResizeEvent *aEvent)
    8057{
     58    /* Base-class resize-event */
    8159    QTreeWidget::resizeEvent (aEvent);
     60
     61    /* Notify connected objects about resize */
    8262    emit resized (aEvent->size(), aEvent->oldSize());
    8363}
     
    8565void QITreeWidget::addTopBottomMarginToItems (int aMargin)
    8666{
    87     for (int i=0; i < topLevelItemCount(); ++i)
     67    for (int i = 0; i < topLevelItemCount(); ++ i)
    8868    {
    8969        QTreeWidgetItem *item = topLevelItem (i);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGLSettingsLanguage.cpp

    r24002 r24054  
    4040extern const char *gVBoxBuiltInLangName;
    4141
    42 class LanguageItem : public ComplexTreeWidgetItem
     42class LanguageItem : public QTreeWidgetItem
    4343{
    4444public:
     45
     46    enum { LanguageItemType = QTreeWidgetItem::UserType + 1 };
    4547
    4648    LanguageItem (QTreeWidget *aParent, const QTranslator &aTranslator,
    4749                  const QString &aId, bool aBuiltIn = false)
    48         : ComplexTreeWidgetItem (aParent), mBuiltIn (aBuiltIn)
     50        : QTreeWidgetItem (aParent, LanguageItemType), mBuiltIn (aBuiltIn)
    4951    {
    5052        Assert (!aId.isEmpty());
     
    107109     * file is missing or corrupt). */
    108110    LanguageItem (QTreeWidget *aParent, const QString &aId)
    109         : ComplexTreeWidgetItem (aParent), mBuiltIn (false)
     111        : QTreeWidgetItem (aParent, LanguageItemType), mBuiltIn (false)
    110112    {
    111113        Assert (!aId.isEmpty());
     
    125127     * to QString::null) */
    126128    LanguageItem (QTreeWidget *aParent)
    127         : ComplexTreeWidgetItem (aParent), mBuiltIn (false)
     129        : QTreeWidgetItem (aParent, LanguageItemType), mBuiltIn (false)
    128130    {
    129131        setText (0, VBoxGLSettingsLanguage::tr ("Default", "Language"));
     
    134136        setText (3, "                ");
    135137    }
     138
     139    bool isBuiltIn() const { return mBuiltIn; }
    136140
    137141    bool operator< (const QTreeWidgetItem &aOther) const
     
    145149        if (mBuiltIn)
    146150            return true;
    147         if (aOther.type() == QITreeWidget::ComplexItemType &&
    148             ((LanguageItem*) &aOther)->mBuiltIn)
     151        if (aOther.type() == LanguageItemType && ((LanguageItem*) &aOther)->mBuiltIn)
    149152            return false;
    150         return ComplexTreeWidgetItem::operator< (aOther);
     153        return QTreeWidgetItem::operator< (aOther);
    151154    }
    152155
     
    163166    }
    164167
    165     void paintItem (QPainter *aPainter)
    166     {
    167         if (mBuiltIn)
    168         {
    169             QRect rect = treeWidget()->visualItemRect (this);
    170             aPainter->setPen (treeWidget()->palette().color (QPalette::Mid));
    171             aPainter->drawLine (rect.x(), rect.y() + rect.height() - 1,
    172                  rect.x() + rect.width(), rect.y() + rect.height() - 1);
    173         }
    174     }
    175 
    176168    bool mBuiltIn : 1;
    177169};
     
    190182
    191183    /* Setup Connections */
     184    connect (mTwLanguage, SIGNAL (painted (QTreeWidgetItem *, QPainter *)),
     185             this, SLOT (mTwItemPainted (QTreeWidgetItem *, QPainter *)));
    192186    connect (mTwLanguage, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
    193              this, SLOT (mTwLanguageChanged (QTreeWidgetItem *, QTreeWidgetItem *)));
     187             this, SLOT (mTwLanguageChanged (QTreeWidgetItem *)));
    194188
    195189    /* Applying language settings */
     
    197191}
    198192
    199 void VBoxGLSettingsLanguage::getFrom (const CSystemProperties &,
    200                                       const VBoxGlobalSettings &aGs)
     193void VBoxGLSettingsLanguage::getFrom (const CSystemProperties & /* aProps */, const VBoxGlobalSettings &aGs)
    201194{
    202195    reload (aGs.languageId());
     
    204197}
    205198
    206 void VBoxGLSettingsLanguage::putBackTo (CSystemProperties &,
    207                                         VBoxGlobalSettings &aGs)
     199void VBoxGLSettingsLanguage::putBackTo (CSystemProperties & /* aProps */, VBoxGlobalSettings &aGs)
    208200{
    209201    QTreeWidgetItem *curItem = mTwLanguage->currentItem();
     
    296288}
    297289
    298 void VBoxGLSettingsLanguage::mTwLanguageChanged (QTreeWidgetItem *aCurItem,
    299                                                  QTreeWidgetItem *)
    300 {
    301     if (!aCurItem) return;
     290void VBoxGLSettingsLanguage::mTwItemPainted (QTreeWidgetItem *aItem, QPainter *aPainter)
     291{
     292    if (aItem && aItem->type() == LanguageItem::LanguageItemType)
     293    {
     294        LanguageItem *item = static_cast <LanguageItem*> (aItem);
     295        if (item->isBuiltIn())
     296        {
     297            QRect rect = mTwLanguage->visualItemRect (item);
     298            aPainter->setPen (mTwLanguage->palette().color (QPalette::Mid));
     299            aPainter->drawLine (rect.x(), rect.y() + rect.height() - 1,
     300                                rect.x() + rect.width(), rect.y() + rect.height() - 1);
     301        }
     302    }
     303}
     304
     305void VBoxGLSettingsLanguage::mTwLanguageChanged (QTreeWidgetItem *aItem)
     306{
     307    if (!aItem) return;
    302308
    303309    /* Disable labels for the Default language item */
    304     bool enabled = !aCurItem->text (1).isNull();
     310    bool enabled = !aItem->text (1).isNull();
    305311
    306312    mTxName->setEnabled (enabled);
     
    310316                               "</table>")
    311317                      .arg (tr ("Language:"))
    312                       .arg (aCurItem->text (2))
     318                      .arg (aItem->text (2))
    313319                      .arg (tr ("Author(s):"))
    314                       .arg (aCurItem->text (3)));
     320                      .arg (aItem->text (3)));
    315321
    316322    mLanguageChanged = true;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r23982 r24054  
    6363public:
    6464
     65    enum { MediaItemType = QTreeWidgetItem::UserType + 1 };
     66
    6567    MediaItem (MediaItem *aParent, const VBoxMedium &aMedium, const VBoxMediaManagerDlg *aManager)
    66         : QTreeWidgetItem (aParent, QITreeWidget::BasicItemType)
     68        : QTreeWidgetItem (aParent, MediaItemType)
    6769        , mMedium (aMedium)
    6870        , mManager (aManager)
     
    7072
    7173    MediaItem (QTreeWidget *aParent, const VBoxMedium &aMedium, const VBoxMediaManagerDlg *aManager)
    72         : QTreeWidgetItem (aParent, QITreeWidget::BasicItemType)
     74        : QTreeWidgetItem (aParent, MediaItemType)
    7375        , mMedium (aMedium)
    7476        , mManager (aManager)
     
    145147    {
    146148        QTreeWidgetItem *item = QTreeWidgetItemIterator::operator*();
    147         return item && item->type() == QITreeWidget::BasicItemType ?
     149        return item && item->type() == MediaItem::MediaItemType ?
    148150            static_cast <MediaItem*> (item) : 0;
    149151    }
     
    227229    mTwHD->header()->setStretchLastSection (false);
    228230    mTwHD->setSortingEnabled (true);
    229     mTwHD->setSupportedDropActions (Qt::LinkAction);
    230231    mTwHD->installEventFilter (this);
    231232    connect (mTwHD, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
     
    245246    mTwCD->header()->setStretchLastSection (false);
    246247    mTwCD->setSortingEnabled (true);
    247     mTwCD->setSupportedDropActions (Qt::LinkAction);
    248248    mTwCD->installEventFilter (this);
    249249    connect (mTwCD, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
     
    263263    mTwFD->header()->setStretchLastSection (false);
    264264    mTwFD->setSortingEnabled (true);
    265     mTwFD->setSupportedDropActions (Qt::LinkAction);
    266265    mTwFD->installEventFilter (this);
    267266    connect (mTwFD, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
     
    13121311    /* Convert the QTreeWidgetItem to a MediaItem if it is valid. */
    13131312    MediaItem *item = 0;
    1314     if (aItem && aItem->type() == QITreeWidget::BasicItemType)
     1313    if (aItem && aItem->type() == MediaItem::MediaItemType)
    13151314        item = static_cast <MediaItem*> (aItem);
    13161315    return item;
Note: See TracChangeset for help on using the changeset viewer.

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