VirtualBox

Changeset 9480 in vbox for trunk/src


Ignore:
Timestamp:
Jun 6, 2008 1:37:09 PM (17 years ago)
Author:
vboxsync
Message:

Fe/Qt4: VBoxMediaComboBox ported to qt4.

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

Legend:

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

    r9079 r9480  
    5757    void mediaUpdated (const VBoxMedia &);
    5858    void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
    59     void processOnItem (Q3ListBoxItem *);
     59    void processOnItem (const QModelIndex&);
    6060    void processActivated (int);
    6161
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxMediaComboBox.cpp

    r9287 r9480  
    2424#include "VBoxDiskImageManagerDlg.h"
    2525
    26 #include <qfileinfo.h>
    27 #include <qimage.h>
    28 #include <qdir.h>
    29 #include <qfile.h>
    30 #include <qtooltip.h>
    31 #include <q3listbox.h>
    32 //Added by qt3to4:
     26#include <QFileInfo>
     27#include <QDir>
    3328#include <QPixmap>
    34 #include <QMessageBox>
    3529
    3630VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, int aType /* = -1 */,
    3731                                      bool aUseEmptyItem /* = false */)
    38     : QComboBox (aParent),
    39     mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem)
     32    : QComboBox (aParent)
     33    , mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem)
    4034{
    4135    init();
     
    4438void VBoxMediaComboBox::init()
    4539{
     40    /* Setup default size policy */
    4641    setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
    47     /* setup enumeration handlers */
     42
     43    /* Setup enumeration handlers */
    4844    connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()),
    4945             this, SLOT (mediaEnumStarted()));
     
    5147             this, SLOT (mediaEnumerated (const VBoxMedia &, int)));
    5248
    53     /* setup update handlers */
     49    /* Setup update handlers */
    5450    connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)),
    5551             this, SLOT (mediaAdded (const VBoxMedia &)));
     
    5955             this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &)));
    6056
     57    /* Setup connections */
    6158    connect (this, SIGNAL (activated (int)),
    6259             this, SLOT (processActivated (int)));
    6360
    64     /* in some qt themes embedded list-box is not used by default, so create it */
    65 #warning port me
    66 //    if (!listBox())
    67 //        setListBox (new Q3ListBox (this));
    68 //    if (listBox())
    69 //        connect (listBox(), SIGNAL (onItem (Q3ListBoxItem*)),
    70 //                 this, SLOT (processOnItem (Q3ListBoxItem*)));
     61    /* In some qt themes embedded list-box is not used by default, so create it */
     62    // @todo (dsen): check it for qt4
     63    // if (!listBox())
     64    //     setListBox (new Q3ListBox (this));
     65    if (view())
     66        connect (view(), SIGNAL (entered (const QModelIndex&)),
     67                 this, SLOT (processOnItem (const QModelIndex&)));
    7168
    7269    /* cache pixmaps as class members */
     
    7471    icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning, this);
    7572    if (!icon.isNull())
    76        mPmInacc = icon.pixmap (14, 14);
     73        mPmInacc = icon.pixmap (14, 14);
    7774    icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxCritical, this);
    7875    if (!icon.isNull())
    79        mPmError = icon.pixmap (14, 14);
     76        mPmError = icon.pixmap (14, 14);
    8077}
    8178
    8279void VBoxMediaComboBox::refresh()
    8380{
    84     /* clearing lists */
     81    /* Clearing lists */
    8582    clear(), mUuidList.clear(), mTipList.clear();
    86     /* prepend empty item if used */
     83    /* Prepend empty item if used */
    8784    if (mUseEmptyItem)
    8885        appendItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"), 0);
    89     /* load current media list */
     86    /* Load current media list */
    9087    VBoxMediaList list = vboxGlobal().currentMediaList();
    9188    VBoxMediaList::const_iterator it;
    9289    for (it = list.begin(); it != list.end(); ++ it)
    9390        mediaEnumerated (*it, 0);
    94     /* activate item selected during current list loading */
    95     processActivated (currentItem());
     91    /* Activate item selected during current list loading */
     92    processActivated (currentIndex());
    9693}
    9794
     
    124121        return;
    125122
    126     /* search & remove media */
    127     int index = mUuidList.findIndex (aId);
     123    /* Search & remove media */
     124    int index = mUuidList.indexOf (aId);
    128125    if (index != -1)
    129126    {
    130127        removeItem (index);
    131         mUuidList.remove (mUuidList.at (index));
    132         mTipList.remove (mTipList.at (index));
     128        mUuidList.removeAt (index);
     129        mTipList.removeAt (index);
    133130        /* emit signal to ensure parent dialog process selection changes */
    134         emit activated (currentItem());
     131        emit activated (currentIndex());
    135132    }
    136133}
     
    146143        case VBoxDefs::HD:
    147144        {
    148             /* ignoring non-root disks */
     145            /* Ignoring non-root disks */
    149146            CHardDisk hd = aMedia.disk;
    150147            if (hd.GetParent().isNull())
     
    170167    QString src = hd.GetLocation();
    171168    QUuid machineId = hd.GetMachineId();
    172     /* append list only with free hd */
     169    /* Append list only with free hd */
    173170    if (machineId.isNull() || machineId == mMachineId)
    174171    {
     
    203200                                        VBoxMedia::Status aStatus)
    204201{
    205     /* compose item's name */
     202    /* Compose item's name */
    206203    QFileInfo fi (aSrc);
    207204    QString name = QString ("%1 (%2)").arg (fi.fileName())
    208                    .arg (QDir::convertSeparators (fi.dirPath()));
    209     /* update warning/error icons */
     205                   .arg (QDir::convertSeparators (fi.absolutePath()));
     206    /* Update warning/error icons */
    210207    QPixmap *pixmap = 0;
    211208    if (aStatus == VBoxMedia::Inaccessible)
     
    214211        pixmap = &mPmError;
    215212
    216     /* search media */
    217     int index = mUuidList.findIndex (aId);
    218     /* create or update media */
     213    /* Search media */
     214    int index = mUuidList.indexOf (aId);
     215    /* Create or update media */
    219216    if (index == -1)
    220217        appendItem (name, aId, aTip, pixmap);
     
    222219        replaceItem (index, name, aTip, pixmap);
    223220
    224     /* activate required item if it was updated */
     221    /* Activate required item if it was updated */
    225222    if (aId == mRequiredId)
    226223        setCurrentItem (aId);
    227     /* select last added item if there is no item selected */
     224    /* Select last added item if there is no item selected */
    228225    else if (currentText().isEmpty())
    229         QComboBox::setCurrentItem (index == -1 ? count() - 1 : index);
     226        QComboBox::setCurrentIndex (index == -1 ? count() - 1 : index);
    230227}
    231228
     
    238235void VBoxMediaComboBox::updateToolTip (int aItem)
    239236{
    240     /* combobox tooltip attaching */
    241     QToolTip::remove (this);
     237    /* Combobox tooltip re-attaching */
     238    setToolTip (QString::null);
    242239    if (!mTipList.isEmpty() && aItem >= 0)
    243         QToolTip::add (this, mTipList [aItem]);
    244 }
    245 
    246 void VBoxMediaComboBox::processOnItem (Q3ListBoxItem* aItem)
    247 {
    248     /* combobox item's tooltip attaching */
    249 #warning port me
    250 //    int index = listBox()->index (aItem);
    251 //    QToolTip::remove (listBox()->viewport());
    252 //    QToolTip::add (listBox()->viewport(), mTipList [index]);
     240        setToolTip (mTipList [aItem]);
     241}
     242
     243void VBoxMediaComboBox::processOnItem (const QModelIndex &aIndex)
     244{
     245    /* Combobox item's tooltip attaching */
     246    int index = aIndex.row();
     247    view()->viewport()->setToolTip (QString::null);
     248    view()->viewport()->setToolTip (mTipList [index]);
    253249}
    254250
     
    256252{
    257253    return mUuidList.isEmpty() ? QUuid() :
    258            aId == -1 ? QUuid (mUuidList [currentItem()]) :
     254           aId == -1 ? QUuid (mUuidList [currentIndex()]) :
    259255           QUuid (mUuidList [aId]);
    260256}
     
    265261                                    QPixmap       *aPixmap)
    266262{
    267     int currentIndex = currentItem();
     263    int currentInd = currentIndex();
    268264
    269265    int insertPosition = -1;
     
    272268           which have name greater than the item to be inserted.
    273269           This is necessary for sorting items alphabetically. */
    274         if (text (i).localeAwareCompare (aName) > 0 &&
     270        if (itemText (i).localeAwareCompare (aName) > 0 &&
    275271            !getId (i).isNull())
    276272        {
     
    282278        mUuidList.insert (insertPosition, aId);
    283279
    284     insertPosition == -1 ? mTipList.append (aId) :
     280    insertPosition == -1 ? mTipList.append (aTip) :
    285281        mTipList.insert (insertPosition, aTip);
    286282
    287     aPixmap ? insertItem (*aPixmap, aName, insertPosition) :
    288               insertItem (aName, insertPosition);
    289 
    290     if (insertPosition != -1 && currentIndex >= insertPosition)
    291         QComboBox::setCurrentItem (currentIndex + 1);
     283    aPixmap ? insertItem (insertPosition, *aPixmap, aName) :
     284              insertItem (insertPosition, aName);
     285
     286    if (insertPosition != -1 && currentInd >= insertPosition)
     287        QComboBox::setCurrentIndex (currentInd + 1);
    292288}
    293289
     
    297293                                     QPixmap       *aPixmap)
    298294{
    299     aPixmap ? changeItem (*aPixmap, aName, aNumber) : changeItem (aName, aNumber);
     295    setItemText (aNumber, aName);
     296    if (aPixmap)
     297        setItemIcon (aNumber, *aPixmap);
    300298    mTipList [aNumber] = aTip;
    301299}
     
    319317{
    320318    mRequiredId = aId;
    321     int index = mUuidList.findIndex (mRequiredId);
     319    int index = mUuidList.indexOf (mRequiredId);
    322320    if (index != -1)
    323321    {
    324         QComboBox::setCurrentItem (index);
     322        QComboBox::setCurrentIndex (index);
    325323        emit activated (index);
    326324    }
     
    331329    mType = aType;
    332330}
     331
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