Changeset 9626 in vbox
- Timestamp:
- Jun 11, 2008 7:45:47 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxMediaComboBox.h
r9600 r9626 26 26 #include "VBoxGlobal.h" 27 27 28 #include <qcombobox.h> 29 //Added by qt3to4: 28 #include <QComboBox> 30 29 #include <QPixmap> 31 32 class Q3ListBoxItem;33 30 34 31 class VBoxMediaComboBox : public QComboBox … … 38 35 public: 39 36 37 static QString fullItemName (const QString &aSrc); 38 40 39 VBoxMediaComboBox (QWidget *aParent, int aType = -1, 41 40 bool aUseEmptyItem = false); 42 ~VBoxMediaComboBox() {}43 44 static QString fullItemName (const QString &aSrc);45 41 46 42 void refresh(); 47 void setUseEmptyItem (bool); 48 void setBelongsTo (const QUuid &); 43 44 void setUseEmptyItem (bool aUse); 45 void setBelongsTo (const QUuid &aMachineId); 46 void setCurrentItem (const QUuid &aId); 47 void setType (int aImageType); 48 49 49 QUuid getId (int aId = -1) const; 50 QUuid getBelongsTo();51 void setCurrentItem (const QUuid &);52 void setType (int);53 50 54 51 protected slots: … … 56 53 void mediaEnumStarted(); 57 54 void mediaEnumerated (const VBoxMedia &, int); 55 58 56 void mediaAdded (const VBoxMedia &); 59 57 void mediaUpdated (const VBoxMedia &); 60 58 void mediaRemoved (VBoxDefs::DiskType, const QUuid &); 61 void processOnItem (const QModelIndex&); 62 void processActivated (int); 59 60 void processActivated (int aIndex); 61 void processIndexChanged (int aIndex); 62 63 void processOnItem (const QModelIndex &aIndex); 63 64 64 65 protected: 65 66 66 void init();67 void updateToolTip (int);68 67 void processMedia (const VBoxMedia &); 69 68 void processHdMedia (const VBoxMedia &); 70 69 void processCdMedia (const VBoxMedia &); 71 70 void processFdMedia (const VBoxMedia &); 72 void appendItem (const QString &, const QUuid &, 73 const QString &, QPixmap *); 74 void replaceItem (int, const QString &, 75 const QString &, QPixmap *); 76 void updateShortcut (const QString &, const QUuid &, const QString &, 77 VBoxMedia::Status); 71 72 void updateShortcut (const QString &aSrc, const QUuid &aId, 73 const QString &aToolTip, VBoxMedia::Status aStatus); 74 75 void newItem (const QString &aName, const QUuid &aId, 76 const QString &aToolTip, QPixmap *aPixmap); 77 void updItem (int aIndex, const QString &aNewName, 78 const QString &aNewTip, QPixmap *aNewPix); 79 80 QList<QUuid> mUuidList; 81 QList<QString> mTipList; 78 82 79 83 int mType; 80 QStringList mUuidList;81 QStringList mTipList;82 84 QUuid mMachineId; 83 85 QUuid mRequiredId; -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxMediaComboBox.cpp
r9600 r9626 28 28 #include <QPixmap> 29 29 30 /* static // compose item name */ 31 QString VBoxMediaComboBox::fullItemName (const QString &aSrc) 32 { 33 QFileInfo fi (aSrc); 34 return QString ("%1 (%2)").arg (fi.fileName()) 35 .arg (QDir::convertSeparators (fi.absolutePath())); 36 } 37 38 30 39 VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, int aType /* = -1 */, 31 40 bool aUseEmptyItem /* = false */) 32 41 : QComboBox (aParent) 33 , mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem) 34 { 35 init(); 36 } 37 38 void VBoxMediaComboBox::init() 42 , mType (aType), mUseEmptyItem (aUseEmptyItem) 39 43 { 40 44 /* Setup default size policy */ … … 55 59 this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &))); 56 60 57 /* Setup connections */61 /* Setup other connections */ 58 62 connect (this, SIGNAL (activated (int)), 59 63 this, SLOT (processActivated (int))); 64 connect (this, SIGNAL (currentIndexChanged (int)), 65 this, SLOT (processIndexChanged (int))); 60 66 61 67 /* In some qt themes embedded list-box is not used by default, so create it */ … … 67 73 this, SLOT (processOnItem (const QModelIndex&))); 68 74 69 /* cache pixmaps as class members */75 /* Cache pixmaps as class members */ 70 76 QIcon icon; 71 77 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning, this); … … 77 83 } 78 84 79 QString VBoxMediaComboBox::fullItemName (const QString &aSrc)80 {81 /* Compose item's name */82 QFileInfo fi (aSrc);83 return QString ("%1 (%2)").arg (fi.fileName())84 .arg (QDir::convertSeparators (fi.absolutePath()));85 }86 87 85 void VBoxMediaComboBox::refresh() 88 86 { … … 91 89 /* Prepend empty item if used */ 92 90 if (mUseEmptyItem) 93 appendItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"), 0);91 newItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"), 0); 94 92 /* Load current media list */ 95 93 VBoxMediaList list = vboxGlobal().currentMediaList(); … … 98 96 mediaEnumerated (*it, 0); 99 97 /* Activate item selected during current list loading */ 100 processActivated (currentIndex()); 98 processIndexChanged (currentIndex()); 99 } 100 101 102 void VBoxMediaComboBox::setUseEmptyItem (bool aUseEmptyItem) 103 { 104 mUseEmptyItem = aUseEmptyItem; 105 } 106 107 void VBoxMediaComboBox::setBelongsTo (const QUuid &aMachineId) 108 { 109 mMachineId = aMachineId; 110 } 111 112 void VBoxMediaComboBox::setCurrentItem (const QUuid &aId) 113 { 114 mRequiredId = aId; 115 int index = mUuidList.indexOf (mRequiredId); 116 if (index != -1) 117 setCurrentIndex (index); 118 } 119 120 void VBoxMediaComboBox::setType (int aType) 121 { 122 mType = aType; 123 } 124 125 126 QUuid VBoxMediaComboBox::getId (int aId /* = -1 */) const 127 { 128 return aId == -1 && currentIndex() >= 0 && currentIndex() < mUuidList.size() ? 129 mUuidList [currentIndex()] : 130 aId < 0 || aId >= mUuidList.size() ? QUuid() : 131 mUuidList [aId]; 101 132 } 102 133 … … 136 167 mUuidList.removeAt (index); 137 168 mTipList.removeAt (index); 138 /* emit signal to ensure parent dialog process selection changes */139 emit activated (currentIndex());140 169 } 170 } 171 172 173 void VBoxMediaComboBox::processActivated (int aIndex) 174 { 175 mRequiredId = aIndex < 0 || aIndex >= mUuidList.size() ? 176 QUuid() : mUuidList [aIndex]; 177 } 178 179 void VBoxMediaComboBox::processIndexChanged (int aIndex) 180 { 181 /* Combobox tooltip re-attaching */ 182 setToolTip (QString::null); 183 if (aIndex >= 0 && aIndex < mTipList.size()) 184 setToolTip (mTipList [aIndex]); 185 } 186 187 void VBoxMediaComboBox::processOnItem (const QModelIndex &aIndex) 188 { 189 /* Combobox item's tooltip attaching */ 190 int index = aIndex.row(); 191 view()->viewport()->setToolTip (QString::null); 192 view()->viewport()->setToolTip (mTipList [index]); 141 193 } 142 194 … … 151 203 case VBoxDefs::HD: 152 204 { 205 CHardDisk hd = aMedia.disk; 153 206 /* Ignoring non-root disks */ 154 CHardDisk hd = aMedia.disk;155 207 if (hd.GetParent().isNull()) 156 208 processHdMedia (aMedia); … … 187 239 void VBoxMediaComboBox::processCdMedia (const VBoxMedia &aMedia) 188 240 { 189 CDVDImage dvd = aMedia.disk;190 QString src = dvd.GetFilePath();191 QUuid mediaId = dvd.GetId();192 QString toolTip = VBoxDiskImageManagerDlg::composeCdToolTip ( dvd, aMedia.status);241 CDVDImage cd = aMedia.disk; 242 QString src = cd.GetFilePath(); 243 QUuid mediaId = cd.GetId(); 244 QString toolTip = VBoxDiskImageManagerDlg::composeCdToolTip (cd, aMedia.status); 193 245 updateShortcut (src, mediaId, toolTip, aMedia.status); 194 246 } … … 196 248 void VBoxMediaComboBox::processFdMedia (const VBoxMedia &aMedia) 197 249 { 198 CFloppyImage f loppy= aMedia.disk;199 QString src = f loppy.GetFilePath();200 QUuid mediaId = f loppy.GetId();201 QString toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (f loppy, aMedia.status);250 CFloppyImage fd = aMedia.disk; 251 QString src = fd.GetFilePath(); 252 QUuid mediaId = fd.GetId(); 253 QString toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (fd, aMedia.status); 202 254 updateShortcut (src, mediaId, toolTip, aMedia.status); 203 255 } 256 204 257 205 258 void VBoxMediaComboBox::updateShortcut (const QString &aSrc, … … 220 273 int index = mUuidList.indexOf (aId); 221 274 /* Create or update media */ 222 if (index == -1) 223 appendItem (name, aId, aTip, pixmap); 224 else 225 replaceItem (index, name, aTip, pixmap); 275 index == -1 ? newItem (name, aId, aTip, pixmap) : 276 updItem (index, name, aTip, pixmap); 226 277 227 278 /* Activate required item if it was updated */ 228 279 if (aId == mRequiredId) 229 280 setCurrentItem (aId); 230 /* Select last added item if there is no item selected */ 231 else if (currentText().isEmpty()) 232 QComboBox::setCurrentIndex (index == -1 ? count() - 1 : index); 233 } 234 235 void VBoxMediaComboBox::processActivated (int aItem) 236 { 237 mRequiredId = mUuidList.isEmpty() || aItem < 0 ? QUuid() : QUuid (mUuidList [aItem]); 238 updateToolTip (aItem); 239 } 240 241 void VBoxMediaComboBox::updateToolTip (int aItem) 242 { 243 /* Combobox tooltip re-attaching */ 244 setToolTip (QString::null); 245 if (!mTipList.isEmpty() && aItem >= 0) 246 setToolTip (mTipList [aItem]); 247 } 248 249 void VBoxMediaComboBox::processOnItem (const QModelIndex &aIndex) 250 { 251 /* Combobox item's tooltip attaching */ 252 int index = aIndex.row(); 253 view()->viewport()->setToolTip (QString::null); 254 view()->viewport()->setToolTip (mTipList [index]); 255 } 256 257 QUuid VBoxMediaComboBox::getId (int aId) const 258 { 259 return mUuidList.isEmpty() ? QUuid() : 260 aId == -1 ? QUuid (mUuidList [currentIndex()]) : 261 QUuid (mUuidList [aId]); 262 } 263 264 void VBoxMediaComboBox::appendItem (const QString &aName, 265 const QUuid &aId, 266 const QString &aTip, 267 QPixmap *aPixmap) 268 { 269 int currentInd = currentIndex(); 270 271 int insertPosition = count(); 272 for (int i = 0; i < count(); ++ i) 281 /* Activate first item in list if current is not required */ 282 else if (getId() != mRequiredId) 283 setCurrentIndex (0); 284 /* Update current item if it was not really changed */ 285 processIndexChanged (currentIndex()); 286 } 287 288 void VBoxMediaComboBox::newItem (const QString &aName, 289 const QUuid &aId, 290 const QString &aTip, 291 QPixmap *aPixmap) 292 { 293 int initCount = count(); 294 295 int insertPosition = initCount; 296 for (int i = 0; i < initCount; ++ i) 273 297 /* Searching for the first real (non-null) vdi item 274 298 which have name greater than the item to be inserted. … … 281 305 } 282 306 283 insertPosition == count()? mUuidList.append (aId) :307 insertPosition == initCount ? mUuidList.append (aId) : 284 308 mUuidList.insert (insertPosition, aId); 285 309 286 insertPosition == count()? mTipList.append (aTip) :310 insertPosition == initCount ? mTipList.append (aTip) : 287 311 mTipList.insert (insertPosition, aTip); 288 312 289 313 aPixmap ? insertItem (insertPosition, *aPixmap, aName) : 290 314 insertItem (insertPosition, aName); 291 292 if (insertPosition != count() && currentInd >= insertPosition) 293 QComboBox::setCurrentIndex (currentInd + 1); 294 } 295 296 void VBoxMediaComboBox::replaceItem (int aNumber, 297 const QString &aName, 298 const QString &aTip, 299 QPixmap *aPixmap) 300 { 301 setItemText (aNumber, aName); 302 if (aPixmap) 303 setItemIcon (aNumber, *aPixmap); 304 mTipList [aNumber] = aTip; 305 } 306 307 void VBoxMediaComboBox::setUseEmptyItem (bool aUseEmptyItem) 308 { 309 mUseEmptyItem = aUseEmptyItem; 310 } 311 312 void VBoxMediaComboBox::setBelongsTo (const QUuid &aMachineId) 313 { 314 mMachineId = aMachineId; 315 } 316 317 QUuid VBoxMediaComboBox::getBelongsTo() 318 { 319 return mMachineId; 320 } 321 322 void VBoxMediaComboBox::setCurrentItem (const QUuid &aId) 323 { 324 mRequiredId = aId; 325 int index = mUuidList.indexOf (mRequiredId); 326 if (index != -1) 327 { 328 QComboBox::setCurrentIndex (index); 329 emit activated (index); 330 } 331 } 332 333 void VBoxMediaComboBox::setType (int aType) 334 { 335 mType = aType; 336 } 337 315 } 316 317 void VBoxMediaComboBox::updItem (int aIndex, 318 const QString &aNewName, 319 const QString &aNewTip, 320 QPixmap *aNewPix) 321 { 322 setItemText (aIndex, aNewName); 323 if (aNewPix) 324 setItemIcon (aIndex, *aNewPix); 325 mTipList [aIndex] = aNewTip; 326 } 327
Note:
See TracChangeset
for help on using the changeset viewer.