- Timestamp:
- Jun 6, 2008 1:37:09 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
r9079 r9480 57 57 void mediaUpdated (const VBoxMedia &); 58 58 void mediaRemoved (VBoxDefs::DiskType, const QUuid &); 59 void processOnItem ( Q3ListBoxItem *);59 void processOnItem (const QModelIndex&); 60 60 void processActivated (int); 61 61 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxMediaComboBox.cpp
r9287 r9480 24 24 #include "VBoxDiskImageManagerDlg.h" 25 25 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> 33 28 #include <QPixmap> 34 #include <QMessageBox>35 29 36 30 VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, int aType /* = -1 */, 37 31 bool aUseEmptyItem /* = false */) 38 : QComboBox (aParent) ,39 mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem)32 : QComboBox (aParent) 33 , mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem) 40 34 { 41 35 init(); … … 44 38 void VBoxMediaComboBox::init() 45 39 { 40 /* Setup default size policy */ 46 41 setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed); 47 /* setup enumeration handlers */ 42 43 /* Setup enumeration handlers */ 48 44 connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()), 49 45 this, SLOT (mediaEnumStarted())); … … 51 47 this, SLOT (mediaEnumerated (const VBoxMedia &, int))); 52 48 53 /* setup update handlers */49 /* Setup update handlers */ 54 50 connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)), 55 51 this, SLOT (mediaAdded (const VBoxMedia &))); … … 59 55 this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &))); 60 56 57 /* Setup connections */ 61 58 connect (this, SIGNAL (activated (int)), 62 59 this, SLOT (processActivated (int))); 63 60 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&))); 71 68 72 69 /* cache pixmaps as class members */ … … 74 71 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning, this); 75 72 if (!icon.isNull()) 76 mPmInacc = icon.pixmap (14, 14);73 mPmInacc = icon.pixmap (14, 14); 77 74 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxCritical, this); 78 75 if (!icon.isNull()) 79 mPmError = icon.pixmap (14, 14);76 mPmError = icon.pixmap (14, 14); 80 77 } 81 78 82 79 void VBoxMediaComboBox::refresh() 83 80 { 84 /* clearing lists */81 /* Clearing lists */ 85 82 clear(), mUuidList.clear(), mTipList.clear(); 86 /* prepend empty item if used */83 /* Prepend empty item if used */ 87 84 if (mUseEmptyItem) 88 85 appendItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"), 0); 89 /* load current media list */86 /* Load current media list */ 90 87 VBoxMediaList list = vboxGlobal().currentMediaList(); 91 88 VBoxMediaList::const_iterator it; 92 89 for (it = list.begin(); it != list.end(); ++ it) 93 90 mediaEnumerated (*it, 0); 94 /* activate item selected during current list loading */95 processActivated (currentI tem());91 /* Activate item selected during current list loading */ 92 processActivated (currentIndex()); 96 93 } 97 94 … … 124 121 return; 125 122 126 /* search & remove media */127 int index = mUuidList. findIndex(aId);123 /* Search & remove media */ 124 int index = mUuidList.indexOf (aId); 128 125 if (index != -1) 129 126 { 130 127 removeItem (index); 131 mUuidList.remove (mUuidList.at (index));132 mTipList.remove (mTipList.at (index));128 mUuidList.removeAt (index); 129 mTipList.removeAt (index); 133 130 /* emit signal to ensure parent dialog process selection changes */ 134 emit activated (currentI tem());131 emit activated (currentIndex()); 135 132 } 136 133 } … … 146 143 case VBoxDefs::HD: 147 144 { 148 /* ignoring non-root disks */145 /* Ignoring non-root disks */ 149 146 CHardDisk hd = aMedia.disk; 150 147 if (hd.GetParent().isNull()) … … 170 167 QString src = hd.GetLocation(); 171 168 QUuid machineId = hd.GetMachineId(); 172 /* append list only with free hd */169 /* Append list only with free hd */ 173 170 if (machineId.isNull() || machineId == mMachineId) 174 171 { … … 203 200 VBoxMedia::Status aStatus) 204 201 { 205 /* compose item's name */202 /* Compose item's name */ 206 203 QFileInfo fi (aSrc); 207 204 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 */ 210 207 QPixmap *pixmap = 0; 211 208 if (aStatus == VBoxMedia::Inaccessible) … … 214 211 pixmap = &mPmError; 215 212 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 */ 219 216 if (index == -1) 220 217 appendItem (name, aId, aTip, pixmap); … … 222 219 replaceItem (index, name, aTip, pixmap); 223 220 224 /* activate required item if it was updated */221 /* Activate required item if it was updated */ 225 222 if (aId == mRequiredId) 226 223 setCurrentItem (aId); 227 /* select last added item if there is no item selected */224 /* Select last added item if there is no item selected */ 228 225 else if (currentText().isEmpty()) 229 QComboBox::setCurrentI tem(index == -1 ? count() - 1 : index);226 QComboBox::setCurrentIndex (index == -1 ? count() - 1 : index); 230 227 } 231 228 … … 238 235 void VBoxMediaComboBox::updateToolTip (int aItem) 239 236 { 240 /* combobox tooltipattaching */241 QToolTip::remove (this);237 /* Combobox tooltip re-attaching */ 238 setToolTip (QString::null); 242 239 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 243 void 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]); 253 249 } 254 250 … … 256 252 { 257 253 return mUuidList.isEmpty() ? QUuid() : 258 aId == -1 ? QUuid (mUuidList [currentI tem()]) :254 aId == -1 ? QUuid (mUuidList [currentIndex()]) : 259 255 QUuid (mUuidList [aId]); 260 256 } … … 265 261 QPixmap *aPixmap) 266 262 { 267 int currentInd ex = currentItem();263 int currentInd = currentIndex(); 268 264 269 265 int insertPosition = -1; … … 272 268 which have name greater than the item to be inserted. 273 269 This is necessary for sorting items alphabetically. */ 274 if ( text (i).localeAwareCompare (aName) > 0 &&270 if (itemText (i).localeAwareCompare (aName) > 0 && 275 271 !getId (i).isNull()) 276 272 { … … 282 278 mUuidList.insert (insertPosition, aId); 283 279 284 insertPosition == -1 ? mTipList.append (a Id) :280 insertPosition == -1 ? mTipList.append (aTip) : 285 281 mTipList.insert (insertPosition, aTip); 286 282 287 aPixmap ? insertItem ( *aPixmap, aName, insertPosition) :288 insertItem ( aName, insertPosition);289 290 if (insertPosition != -1 && currentInd ex>= insertPosition)291 QComboBox::setCurrentI tem (currentIndex+ 1);283 aPixmap ? insertItem (insertPosition, *aPixmap, aName) : 284 insertItem (insertPosition, aName); 285 286 if (insertPosition != -1 && currentInd >= insertPosition) 287 QComboBox::setCurrentIndex (currentInd + 1); 292 288 } 293 289 … … 297 293 QPixmap *aPixmap) 298 294 { 299 aPixmap ? changeItem (*aPixmap, aName, aNumber) : changeItem (aName, aNumber); 295 setItemText (aNumber, aName); 296 if (aPixmap) 297 setItemIcon (aNumber, *aPixmap); 300 298 mTipList [aNumber] = aTip; 301 299 } … … 319 317 { 320 318 mRequiredId = aId; 321 int index = mUuidList. findIndex(mRequiredId);319 int index = mUuidList.indexOf (mRequiredId); 322 320 if (index != -1) 323 321 { 324 QComboBox::setCurrentI tem(index);322 QComboBox::setCurrentIndex (index); 325 323 emit activated (index); 326 324 } … … 331 329 mType = aType; 332 330 } 331
Note:
See TracChangeset
for help on using the changeset viewer.