Changeset 64689 in vbox for trunk/src/VBox
- Timestamp:
- Nov 17, 2016 1:40:40 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.cpp
r64688 r64689 21 21 22 22 /* Qt includes: */ 23 # include <QItemDelegate> 24 # include <QSortFilterProxyModel> 23 # include <QComboBox> 24 # include <QDir> 25 # include <QCheckBox> 25 26 # include <QHeaderView> 27 # include <QLabel> 26 28 # include <QLineEdit> 27 29 # include <QSpinBox> 28 # include <QComboBox> 29 # include <QDir> 30 # include <QTextEdit> 30 31 # include <QTreeView> 31 # include <QCheckBox>32 # include <QLabel>33 # include <QTextEdit>34 32 35 33 /* GUI includes: */ 34 # include "VBoxGlobal.h" 35 # include "VBoxOSTypeSelectorButton.h" 36 36 # include "UIApplianceEditorWidget.h" 37 # include "VBoxGlobal.h"38 # include "UIMessageCenter.h"39 # include "VBoxOSTypeSelectorButton.h"40 # include "UILineTextEdit.h"41 37 # include "UIConverter.h" 42 38 # include "UIIconPool.h" 39 # include "UILineTextEdit.h" 40 # include "UIMessageCenter.h" 43 41 44 42 /* COM includes: */ … … 59 57 virtual ~ModelItem(); 60 58 59 /** Returns the item type. */ 60 ApplianceModelItemType type() const { return m_type; } 61 61 62 /** Returns the parent of the item. */ 62 63 ModelItem *parent() const { return m_pParentItem; } … … 77 78 /** Returns the item flags for the given @a column. */ 78 79 virtual Qt::ItemFlags itemFlags(int /* column */) const { return 0; } 80 79 81 /** Defines the @a role data for the item at @a column to @a value. */ 80 82 virtual bool setData(int /* column */, const QVariant & /* value */, int /* role */) { return false; } 81 83 /** Returns the data stored under the given @a role for the item referred to by the @a column. */ 82 84 virtual QVariant data(int /* column */, int /* role */) const { return QVariant(); } 85 83 86 /** Returns the widget used to edit the item specified by @a idx for editing. 84 87 * @param pParent Brings the parent to be assigned for newly created editor. 85 88 * @param styleOption Bring the style option set for the newly created editor. */ 86 89 virtual QWidget *createEditor(QWidget * /* pParent */, const QStyleOptionViewItem & /* styleOption */, const QModelIndex & /* idx */) const { return NULL; } 90 87 91 /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */ 88 92 virtual bool setEditorData(QWidget * /* pEditor */, const QModelIndex & /* idx */) const { return false; } … … 92 96 /** Restores the default values. */ 93 97 virtual void restoreDefaults() {} 98 94 99 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */ 95 100 virtual void putBack(QVector<BOOL>& finalStates, QVector<QString>& finalValues, QVector<QString>& finalExtraValues); 96 97 /** Returns the item type. */98 ApplianceModelItemType type() const { return m_type; }99 101 100 102 protected: … … 138 140 { 139 141 friend class VirtualSystemSortProxyModel; 140 141 public:142 142 143 143 /** Data roles. */ … … 147 147 ModifiedRole 148 148 }; 149 150 public: 149 151 150 152 /** Constructs item passing @a number and @a pParent to the base-class. … … 162 164 ModelItem *pParent); 163 165 164 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */165 virtual void putBack(QVector<BOOL>& finalStates, QVector<QString>& finalValues, QVector<QString>& finalExtraValues);166 /** Returns the item flags for the given @a column. */ 167 virtual Qt::ItemFlags itemFlags(int column) const; 166 168 167 169 /** Defines the @a role data for the item at @a column to @a value. */ … … 170 172 virtual QVariant data(int column, int role) const; 171 173 172 /** Returns the item flags for the given @a column. */173 virtual Qt::ItemFlags itemFlags(int column) const;174 175 174 /** Returns the widget used to edit the item specified by @a idx for editing. 176 175 * @param pParent Brings the parent to be assigned for newly created editor. 177 176 * @param styleOption Bring the style option set for the newly created editor. */ 178 177 virtual QWidget *createEditor(QWidget *pParent, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const; 178 179 179 /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */ 180 180 virtual bool setEditorData(QWidget *pEditor, const QModelIndex &idx) const; … … 183 183 184 184 /** Restores the default values. */ 185 virtual void restoreDefaults() 186 { 187 m_strConfigValue = m_strConfigDefaultValue; 188 m_checkState = Qt::Checked; 189 } 185 virtual void restoreDefaults(); 186 187 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */ 188 virtual void putBack(QVector<BOOL>& finalStates, QVector<QString>& finalValues, QVector<QString>& finalExtraValues); 190 189 191 190 private: … … 312 311 , m_checkState(Qt::Checked) 313 312 , m_fModified(false) 314 {} 315 316 void HardwareItem::putBack(QVector<BOOL>& finalStates, QVector<QString>& finalValues, QVector<QString>& finalExtraValues) 317 { 318 finalStates[m_number] = m_checkState == Qt::Checked; 319 finalValues[m_number] = m_strConfigValue; 320 finalExtraValues[m_number] = m_strExtraConfigValue; 321 ModelItem::putBack(finalStates, finalValues, finalExtraValues); 322 } 323 324 bool HardwareItem::setData(int column, const QVariant &value, int role) 325 { 326 bool fDone = false; 327 switch (role) 328 { 329 case Qt::CheckStateRole: 330 { 331 if (column == ApplianceViewSection_ConfigValue && 332 (m_type == KVirtualSystemDescriptionType_Floppy || 333 m_type == KVirtualSystemDescriptionType_CDROM || 334 m_type == KVirtualSystemDescriptionType_USBController || 335 m_type == KVirtualSystemDescriptionType_SoundCard || 336 m_type == KVirtualSystemDescriptionType_NetworkAdapter)) 337 { 338 m_checkState = static_cast<Qt::CheckState>(value.toInt()); 339 fDone = true; 340 } 341 break; 342 } 343 case Qt::EditRole: 344 { 345 if (column == ApplianceViewSection_OriginalValue) 346 m_strOrigValue = value.toString(); 347 else if (column == ApplianceViewSection_ConfigValue) 348 m_strConfigValue = value.toString(); 349 break; 350 } 351 default: break; 352 } 353 return fDone; 354 } 355 356 QVariant HardwareItem::data(int column, int role) const 357 { 358 QVariant v; 359 switch (role) 360 { 361 case Qt::EditRole: 362 { 363 if (column == ApplianceViewSection_OriginalValue) 364 v = m_strOrigValue; 365 else if (column == ApplianceViewSection_ConfigValue) 366 v = m_strConfigValue; 367 break; 368 } 369 case Qt::DisplayRole: 370 { 371 if (column == ApplianceViewSection_Description) 372 { 373 switch (m_type) 374 { 375 case KVirtualSystemDescriptionType_Name: v = UIApplianceEditorWidget::tr("Name"); break; 376 case KVirtualSystemDescriptionType_Product: v = UIApplianceEditorWidget::tr("Product"); break; 377 case KVirtualSystemDescriptionType_ProductUrl: v = UIApplianceEditorWidget::tr("Product-URL"); break; 378 case KVirtualSystemDescriptionType_Vendor: v = UIApplianceEditorWidget::tr("Vendor"); break; 379 case KVirtualSystemDescriptionType_VendorUrl: v = UIApplianceEditorWidget::tr("Vendor-URL"); break; 380 case KVirtualSystemDescriptionType_Version: v = UIApplianceEditorWidget::tr("Version"); break; 381 case KVirtualSystemDescriptionType_Description: v = UIApplianceEditorWidget::tr("Description"); break; 382 case KVirtualSystemDescriptionType_License: v = UIApplianceEditorWidget::tr("License"); break; 383 case KVirtualSystemDescriptionType_OS: v = UIApplianceEditorWidget::tr("Guest OS Type"); break; 384 case KVirtualSystemDescriptionType_CPU: v = UIApplianceEditorWidget::tr("CPU"); break; 385 case KVirtualSystemDescriptionType_Memory: v = UIApplianceEditorWidget::tr("RAM"); break; 386 case KVirtualSystemDescriptionType_HardDiskControllerIDE: v = UIApplianceEditorWidget::tr("Storage Controller (IDE)"); break; 387 case KVirtualSystemDescriptionType_HardDiskControllerSATA: v = UIApplianceEditorWidget::tr("Storage Controller (SATA)"); break; 388 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: v = UIApplianceEditorWidget::tr("Storage Controller (SCSI)"); break; 389 case KVirtualSystemDescriptionType_HardDiskControllerSAS: v = UIApplianceEditorWidget::tr("Storage Controller (SAS)"); break; 390 case KVirtualSystemDescriptionType_CDROM: v = UIApplianceEditorWidget::tr("DVD"); break; 391 case KVirtualSystemDescriptionType_Floppy: v = UIApplianceEditorWidget::tr("Floppy"); break; 392 case KVirtualSystemDescriptionType_NetworkAdapter: v = UIApplianceEditorWidget::tr("Network Adapter"); break; 393 case KVirtualSystemDescriptionType_USBController: v = UIApplianceEditorWidget::tr("USB Controller"); break; 394 case KVirtualSystemDescriptionType_SoundCard: v = UIApplianceEditorWidget::tr("Sound Card"); break; 395 case KVirtualSystemDescriptionType_HardDiskImage: v = UIApplianceEditorWidget::tr("Virtual Disk Image"); break; 396 default: v = UIApplianceEditorWidget::tr("Unknown Hardware Item"); break; 397 } 398 } 399 else if (column == ApplianceViewSection_OriginalValue) 400 v = m_strOrigValue; 401 else if (column == ApplianceViewSection_ConfigValue) 402 { 403 switch (m_type) 404 { 405 case KVirtualSystemDescriptionType_Description: 406 case KVirtualSystemDescriptionType_License: 407 { 408 /* Shorten the big text if there is more than 409 * one line */ 410 QString tmp(m_strConfigValue); 411 int i = tmp.indexOf('\n'); 412 if (i > -1) 413 tmp.replace(i, tmp.length(), "..."); 414 v = tmp; break; 415 } 416 case KVirtualSystemDescriptionType_OS: v = vboxGlobal().vmGuestOSTypeDescription(m_strConfigValue); break; 417 case KVirtualSystemDescriptionType_Memory: v = m_strConfigValue + " " + VBoxGlobal::tr("MB", "size suffix MBytes=1024 KBytes"); break; 418 case KVirtualSystemDescriptionType_SoundCard: v = gpConverter->toString(static_cast<KAudioControllerType>(m_strConfigValue.toInt())); break; 419 case KVirtualSystemDescriptionType_NetworkAdapter: v = gpConverter->toString(static_cast<KNetworkAdapterType>(m_strConfigValue.toInt())); break; 420 default: v = m_strConfigValue; break; 421 } 422 } 423 break; 424 } 425 case Qt::ToolTipRole: 426 { 427 if (column == ApplianceViewSection_ConfigValue) 428 { 429 if (!m_strOrigValue.isEmpty()) 430 v = UIApplianceEditorWidget::tr("<b>Original Value:</b> %1").arg(m_strOrigValue); 431 } 432 break; 433 } 434 case Qt::DecorationRole: 435 { 436 if (column == ApplianceViewSection_Description) 437 { 438 switch (m_type) 439 { 440 case KVirtualSystemDescriptionType_Name: v = UIIconPool::iconSet(":/name_16px.png"); break; 441 case KVirtualSystemDescriptionType_Product: 442 case KVirtualSystemDescriptionType_ProductUrl: 443 case KVirtualSystemDescriptionType_Vendor: 444 case KVirtualSystemDescriptionType_VendorUrl: 445 case KVirtualSystemDescriptionType_Version: 446 case KVirtualSystemDescriptionType_Description: 447 case KVirtualSystemDescriptionType_License: v = UIIconPool::iconSet(":/description_16px.png"); break; 448 case KVirtualSystemDescriptionType_OS: v = UIIconPool::iconSet(":/os_type_16px.png"); break; 449 case KVirtualSystemDescriptionType_CPU: v = UIIconPool::iconSet(":/cpu_16px.png"); break; 450 case KVirtualSystemDescriptionType_Memory: v = UIIconPool::iconSet(":/ram_16px.png"); break; 451 case KVirtualSystemDescriptionType_HardDiskControllerIDE: v = UIIconPool::iconSet(":/ide_16px.png"); break; 452 case KVirtualSystemDescriptionType_HardDiskControllerSATA: v = UIIconPool::iconSet(":/sata_16px.png"); break; 453 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: v = UIIconPool::iconSet(":/scsi_16px.png"); break; 454 case KVirtualSystemDescriptionType_HardDiskControllerSAS: v = UIIconPool::iconSet(":/scsi_16px.png"); break; 455 case KVirtualSystemDescriptionType_HardDiskImage: v = UIIconPool::iconSet(":/hd_16px.png"); break; 456 case KVirtualSystemDescriptionType_CDROM: v = UIIconPool::iconSet(":/cd_16px.png"); break; 457 case KVirtualSystemDescriptionType_Floppy: v = UIIconPool::iconSet(":/fd_16px.png"); break; 458 case KVirtualSystemDescriptionType_NetworkAdapter: v = UIIconPool::iconSet(":/nw_16px.png"); break; 459 case KVirtualSystemDescriptionType_USBController: v = UIIconPool::iconSet(":/usb_16px.png"); break; 460 case KVirtualSystemDescriptionType_SoundCard: v = UIIconPool::iconSet(":/sound_16px.png"); break; 461 default: break; 462 } 463 } 464 else if (column == ApplianceViewSection_ConfigValue && 465 m_type == KVirtualSystemDescriptionType_OS) 466 { 467 const QStyle *pStyle = QApplication::style(); 468 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 469 v = vboxGlobal().vmGuestOSTypeIcon(m_strConfigValue).scaledToHeight(iIconMetric, Qt::SmoothTransformation); 470 } 471 break; 472 } 473 case Qt::FontRole: 474 { 475 /* If the item is unchecked mark it with italic text. */ 476 if (column == ApplianceViewSection_ConfigValue && 477 m_checkState == Qt::Unchecked) 478 { 479 QFont font = qApp->font(); 480 font.setItalic(true); 481 v = font; 482 } 483 break; 484 } 485 case Qt::ForegroundRole: 486 { 487 /* If the item is unchecked mark it with gray text. */ 488 if (column == ApplianceViewSection_ConfigValue && 489 m_checkState == Qt::Unchecked) 490 { 491 QPalette pal = qApp->palette(); 492 v = pal.brush(QPalette::Disabled, QPalette::WindowText); 493 } 494 break; 495 } 496 case Qt::CheckStateRole: 497 { 498 if (column == ApplianceViewSection_ConfigValue && 499 (m_type == KVirtualSystemDescriptionType_Floppy || 500 m_type == KVirtualSystemDescriptionType_CDROM || 501 m_type == KVirtualSystemDescriptionType_USBController || 502 m_type == KVirtualSystemDescriptionType_SoundCard || 503 m_type == KVirtualSystemDescriptionType_NetworkAdapter)) 504 v = m_checkState; 505 break; 506 } 507 case HardwareItem::TypeRole: 508 { 509 v = m_type; 510 break; 511 } 512 case HardwareItem::ModifiedRole: 513 { 514 if (column == ApplianceViewSection_ConfigValue) 515 v = m_fModified; 516 break; 517 } 518 } 519 return v; 313 { 520 314 } 521 315 … … 554 348 } 555 349 350 bool HardwareItem::setData(int column, const QVariant &value, int role) 351 { 352 bool fDone = false; 353 switch (role) 354 { 355 case Qt::CheckStateRole: 356 { 357 if (column == ApplianceViewSection_ConfigValue && 358 (m_type == KVirtualSystemDescriptionType_Floppy || 359 m_type == KVirtualSystemDescriptionType_CDROM || 360 m_type == KVirtualSystemDescriptionType_USBController || 361 m_type == KVirtualSystemDescriptionType_SoundCard || 362 m_type == KVirtualSystemDescriptionType_NetworkAdapter)) 363 { 364 m_checkState = static_cast<Qt::CheckState>(value.toInt()); 365 fDone = true; 366 } 367 break; 368 } 369 case Qt::EditRole: 370 { 371 if (column == ApplianceViewSection_OriginalValue) 372 m_strOrigValue = value.toString(); 373 else if (column == ApplianceViewSection_ConfigValue) 374 m_strConfigValue = value.toString(); 375 break; 376 } 377 default: break; 378 } 379 return fDone; 380 } 381 382 QVariant HardwareItem::data(int column, int role) const 383 { 384 QVariant v; 385 switch (role) 386 { 387 case Qt::EditRole: 388 { 389 if (column == ApplianceViewSection_OriginalValue) 390 v = m_strOrigValue; 391 else if (column == ApplianceViewSection_ConfigValue) 392 v = m_strConfigValue; 393 break; 394 } 395 case Qt::DisplayRole: 396 { 397 if (column == ApplianceViewSection_Description) 398 { 399 switch (m_type) 400 { 401 case KVirtualSystemDescriptionType_Name: v = UIApplianceEditorWidget::tr("Name"); break; 402 case KVirtualSystemDescriptionType_Product: v = UIApplianceEditorWidget::tr("Product"); break; 403 case KVirtualSystemDescriptionType_ProductUrl: v = UIApplianceEditorWidget::tr("Product-URL"); break; 404 case KVirtualSystemDescriptionType_Vendor: v = UIApplianceEditorWidget::tr("Vendor"); break; 405 case KVirtualSystemDescriptionType_VendorUrl: v = UIApplianceEditorWidget::tr("Vendor-URL"); break; 406 case KVirtualSystemDescriptionType_Version: v = UIApplianceEditorWidget::tr("Version"); break; 407 case KVirtualSystemDescriptionType_Description: v = UIApplianceEditorWidget::tr("Description"); break; 408 case KVirtualSystemDescriptionType_License: v = UIApplianceEditorWidget::tr("License"); break; 409 case KVirtualSystemDescriptionType_OS: v = UIApplianceEditorWidget::tr("Guest OS Type"); break; 410 case KVirtualSystemDescriptionType_CPU: v = UIApplianceEditorWidget::tr("CPU"); break; 411 case KVirtualSystemDescriptionType_Memory: v = UIApplianceEditorWidget::tr("RAM"); break; 412 case KVirtualSystemDescriptionType_HardDiskControllerIDE: v = UIApplianceEditorWidget::tr("Storage Controller (IDE)"); break; 413 case KVirtualSystemDescriptionType_HardDiskControllerSATA: v = UIApplianceEditorWidget::tr("Storage Controller (SATA)"); break; 414 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: v = UIApplianceEditorWidget::tr("Storage Controller (SCSI)"); break; 415 case KVirtualSystemDescriptionType_HardDiskControllerSAS: v = UIApplianceEditorWidget::tr("Storage Controller (SAS)"); break; 416 case KVirtualSystemDescriptionType_CDROM: v = UIApplianceEditorWidget::tr("DVD"); break; 417 case KVirtualSystemDescriptionType_Floppy: v = UIApplianceEditorWidget::tr("Floppy"); break; 418 case KVirtualSystemDescriptionType_NetworkAdapter: v = UIApplianceEditorWidget::tr("Network Adapter"); break; 419 case KVirtualSystemDescriptionType_USBController: v = UIApplianceEditorWidget::tr("USB Controller"); break; 420 case KVirtualSystemDescriptionType_SoundCard: v = UIApplianceEditorWidget::tr("Sound Card"); break; 421 case KVirtualSystemDescriptionType_HardDiskImage: v = UIApplianceEditorWidget::tr("Virtual Disk Image"); break; 422 default: v = UIApplianceEditorWidget::tr("Unknown Hardware Item"); break; 423 } 424 } 425 else if (column == ApplianceViewSection_OriginalValue) 426 v = m_strOrigValue; 427 else if (column == ApplianceViewSection_ConfigValue) 428 { 429 switch (m_type) 430 { 431 case KVirtualSystemDescriptionType_Description: 432 case KVirtualSystemDescriptionType_License: 433 { 434 /* Shorten the big text if there is more than 435 * one line */ 436 QString tmp(m_strConfigValue); 437 int i = tmp.indexOf('\n'); 438 if (i > -1) 439 tmp.replace(i, tmp.length(), "..."); 440 v = tmp; break; 441 } 442 case KVirtualSystemDescriptionType_OS: v = vboxGlobal().vmGuestOSTypeDescription(m_strConfigValue); break; 443 case KVirtualSystemDescriptionType_Memory: v = m_strConfigValue + " " + VBoxGlobal::tr("MB", "size suffix MBytes=1024 KBytes"); break; 444 case KVirtualSystemDescriptionType_SoundCard: v = gpConverter->toString(static_cast<KAudioControllerType>(m_strConfigValue.toInt())); break; 445 case KVirtualSystemDescriptionType_NetworkAdapter: v = gpConverter->toString(static_cast<KNetworkAdapterType>(m_strConfigValue.toInt())); break; 446 default: v = m_strConfigValue; break; 447 } 448 } 449 break; 450 } 451 case Qt::ToolTipRole: 452 { 453 if (column == ApplianceViewSection_ConfigValue) 454 { 455 if (!m_strOrigValue.isEmpty()) 456 v = UIApplianceEditorWidget::tr("<b>Original Value:</b> %1").arg(m_strOrigValue); 457 } 458 break; 459 } 460 case Qt::DecorationRole: 461 { 462 if (column == ApplianceViewSection_Description) 463 { 464 switch (m_type) 465 { 466 case KVirtualSystemDescriptionType_Name: v = UIIconPool::iconSet(":/name_16px.png"); break; 467 case KVirtualSystemDescriptionType_Product: 468 case KVirtualSystemDescriptionType_ProductUrl: 469 case KVirtualSystemDescriptionType_Vendor: 470 case KVirtualSystemDescriptionType_VendorUrl: 471 case KVirtualSystemDescriptionType_Version: 472 case KVirtualSystemDescriptionType_Description: 473 case KVirtualSystemDescriptionType_License: v = UIIconPool::iconSet(":/description_16px.png"); break; 474 case KVirtualSystemDescriptionType_OS: v = UIIconPool::iconSet(":/os_type_16px.png"); break; 475 case KVirtualSystemDescriptionType_CPU: v = UIIconPool::iconSet(":/cpu_16px.png"); break; 476 case KVirtualSystemDescriptionType_Memory: v = UIIconPool::iconSet(":/ram_16px.png"); break; 477 case KVirtualSystemDescriptionType_HardDiskControllerIDE: v = UIIconPool::iconSet(":/ide_16px.png"); break; 478 case KVirtualSystemDescriptionType_HardDiskControllerSATA: v = UIIconPool::iconSet(":/sata_16px.png"); break; 479 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: v = UIIconPool::iconSet(":/scsi_16px.png"); break; 480 case KVirtualSystemDescriptionType_HardDiskControllerSAS: v = UIIconPool::iconSet(":/scsi_16px.png"); break; 481 case KVirtualSystemDescriptionType_HardDiskImage: v = UIIconPool::iconSet(":/hd_16px.png"); break; 482 case KVirtualSystemDescriptionType_CDROM: v = UIIconPool::iconSet(":/cd_16px.png"); break; 483 case KVirtualSystemDescriptionType_Floppy: v = UIIconPool::iconSet(":/fd_16px.png"); break; 484 case KVirtualSystemDescriptionType_NetworkAdapter: v = UIIconPool::iconSet(":/nw_16px.png"); break; 485 case KVirtualSystemDescriptionType_USBController: v = UIIconPool::iconSet(":/usb_16px.png"); break; 486 case KVirtualSystemDescriptionType_SoundCard: v = UIIconPool::iconSet(":/sound_16px.png"); break; 487 default: break; 488 } 489 } 490 else if (column == ApplianceViewSection_ConfigValue && 491 m_type == KVirtualSystemDescriptionType_OS) 492 { 493 const QStyle *pStyle = QApplication::style(); 494 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 495 v = vboxGlobal().vmGuestOSTypeIcon(m_strConfigValue).scaledToHeight(iIconMetric, Qt::SmoothTransformation); 496 } 497 break; 498 } 499 case Qt::FontRole: 500 { 501 /* If the item is unchecked mark it with italic text. */ 502 if (column == ApplianceViewSection_ConfigValue && 503 m_checkState == Qt::Unchecked) 504 { 505 QFont font = qApp->font(); 506 font.setItalic(true); 507 v = font; 508 } 509 break; 510 } 511 case Qt::ForegroundRole: 512 { 513 /* If the item is unchecked mark it with gray text. */ 514 if (column == ApplianceViewSection_ConfigValue && 515 m_checkState == Qt::Unchecked) 516 { 517 QPalette pal = qApp->palette(); 518 v = pal.brush(QPalette::Disabled, QPalette::WindowText); 519 } 520 break; 521 } 522 case Qt::CheckStateRole: 523 { 524 if (column == ApplianceViewSection_ConfigValue && 525 (m_type == KVirtualSystemDescriptionType_Floppy || 526 m_type == KVirtualSystemDescriptionType_CDROM || 527 m_type == KVirtualSystemDescriptionType_USBController || 528 m_type == KVirtualSystemDescriptionType_SoundCard || 529 m_type == KVirtualSystemDescriptionType_NetworkAdapter)) 530 v = m_checkState; 531 break; 532 } 533 case HardwareItem::TypeRole: 534 { 535 v = m_type; 536 break; 537 } 538 case HardwareItem::ModifiedRole: 539 { 540 if (column == ApplianceViewSection_ConfigValue) 541 v = m_fModified; 542 break; 543 } 544 } 545 return v; 546 } 547 556 548 QWidget *HardwareItem::createEditor(QWidget *pParent, const QStyleOptionViewItem & /* styleOption */, const QModelIndex &idx) const 557 549 { … … 890 882 } 891 883 884 void HardwareItem::restoreDefaults() 885 { 886 m_strConfigValue = m_strConfigDefaultValue; 887 m_checkState = Qt::Checked; 888 } 889 890 void HardwareItem::putBack(QVector<BOOL>& finalStates, QVector<QString>& finalValues, QVector<QString>& finalExtraValues) 891 { 892 finalStates[m_number] = m_checkState == Qt::Checked; 893 finalValues[m_number] = m_strConfigValue; 894 finalExtraValues[m_number] = m_strExtraConfigValue; 895 ModelItem::putBack(finalStates, finalValues, finalExtraValues); 896 } 897 892 898 893 899 /********************************************************************************************************************************* … … 1019 1025 } 1020 1026 1021 bool VirtualSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role)1022 {1023 if (!idx.isValid())1024 return false;1025 1026 ModelItem *item = static_cast<ModelItem*>(idx.internalPointer());1027 1028 return item->setData(idx.column(), value, role);1029 }1030 1031 QVariant VirtualSystemModel::data(const QModelIndex &idx, int role /* = Qt::DisplayRole */) const1032 {1033 if (!idx.isValid())1034 return QVariant();1035 1036 ModelItem *item = static_cast<ModelItem*>(idx.internalPointer());1037 1038 return item->data(idx.column(), role);1039 }1040 1041 1027 Qt::ItemFlags VirtualSystemModel::flags(const QModelIndex &idx) const 1042 1028 { … … 1062 1048 } 1063 1049 return title; 1050 } 1051 1052 bool VirtualSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role) 1053 { 1054 if (!idx.isValid()) 1055 return false; 1056 1057 ModelItem *item = static_cast<ModelItem*>(idx.internalPointer()); 1058 1059 return item->setData(idx.column(), value, role); 1060 } 1061 1062 QVariant VirtualSystemModel::data(const QModelIndex &idx, int role /* = Qt::DisplayRole */) const 1063 { 1064 if (!idx.isValid()) 1065 return QVariant(); 1066 1067 ModelItem *item = static_cast<ModelItem*>(idx.internalPointer()); 1068 1069 return item->data(idx.column(), role); 1064 1070 } 1065 1071 … … 1171 1177 if (pEditor) 1172 1178 pEditor->setGeometry(styleOption.rect); 1179 } 1180 1181 QSize VirtualSystemDelegate::sizeHint(const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const 1182 { 1183 QSize size = QItemDelegate::sizeHint(styleOption, idx); 1184 #ifdef VBOX_WS_MAC 1185 int h = 28; 1186 #else 1187 int h = 24; 1188 #endif 1189 size.setHeight(RT_MAX(h, size.height())); 1190 return size; 1173 1191 } 1174 1192 … … 1199 1217 *********************************************************************************************************************************/ 1200 1218 1201 /* How to sort the items in the tree view*/1219 /* static */ 1202 1220 KVirtualSystemDescriptionType VirtualSystemSortProxyModel::m_sortList[] = 1203 1221 { … … 1284 1302 *********************************************************************************************************************************/ 1285 1303 1304 /* static */ 1286 1305 int UIApplianceEditorWidget::m_minGuestRAM = -1; 1287 1306 int UIApplianceEditorWidget::m_maxGuestRAM = -1; -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.h
r64688 r64689 20 20 21 21 /* Qt includes: */ 22 #include <QAbstractItemModel> 23 #include <QItemDelegate> 22 24 #include <QSortFilterProxyModel> 23 #include <Q ItemDelegate>25 #include <QWidget> 24 26 25 27 /* GUI includes: */ … … 32 34 /* Forward declarations: */ 33 35 class ModelItem; 34 class QWidget;35 class QTreeView;36 36 class QCheckBox; 37 37 class QLabel; 38 38 class QTextEdit; 39 class QTreeView; 39 40 40 41 … … 72 73 /** Returns the parent of the model item with the given @a idx. */ 73 74 QModelIndex parent(const QModelIndex &idx) const; 75 74 76 /** Returns the number of rows for the children of the given @a parentIdx. */ 75 77 int rowCount(const QModelIndex &parentIdx = QModelIndex()) const; 76 78 /** Returns the number of columns for the children of the given @a parentIdx. */ 77 79 int columnCount(const QModelIndex &parentIdx = QModelIndex()) const; 80 81 /** Returns the item flags for the given @a idx. */ 82 Qt::ItemFlags flags(const QModelIndex &idx) const; 83 /** Returns the data for the given @a role and @a section in the header with the specified @a orientation. */ 84 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 85 78 86 /** Defines the @a role data for the item at @a idx to @a value. */ 79 87 bool setData(const QModelIndex &idx, const QVariant &value, int role); 80 88 /** Returns the data stored under the given @a role for the item referred to by the @a idx. */ 81 89 QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const; 82 /** Returns the item flags for the given @a idx. */83 Qt::ItemFlags flags(const QModelIndex &idx) const;84 /** Returns the data for the given @a role and @a section in the header with the specified @a orientation. */85 QVariant headerData(int section, Qt::Orientation orientation, int role) const;86 90 87 91 /** Returns a model index for the buddy of the item represented by @a idx. */ … … 90 94 /** Restores the default values for the item with the given @a parentIdx. */ 91 95 void restoreDefaults(const QModelIndex &parentIdx = QModelIndex()); 96 92 97 /** Cache currently stored values. */ 93 98 void putBack(); … … 113 118 * @param styleOption Bring the style option set for the newly created editor. */ 114 119 QWidget *createEditor(QWidget *pParent, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const; 120 115 121 /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */ 116 122 void setEditorData(QWidget *pEditor, const QModelIndex &idx) const; 117 123 /** Defines the data for the item at the given @a idx in the @a pModel to the contents of the given @a pEditor. */ 118 124 void setModelData(QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex &idx) const; 125 119 126 /** Updates the geometry of the @a pEditor for the item with the given @a idx, according to the rectangle specified in the @a styleOption. */ 120 127 void updateEditorGeometry(QWidget *pEditor, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const; 121 128 122 129 /** Returns the size hint for the item at the given @a idx and specified @a styleOption. */ 123 QSize sizeHint(const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const 124 { 125 QSize size = QItemDelegate::sizeHint(styleOption, idx); 126 #ifdef VBOX_WS_MAC 127 int h = 28; 128 #else /* VBOX_WS_MAC */ 129 int h = 24; 130 #endif /* VBOX_WS_MAC */ 131 size.setHeight(RT_MAX(h, size.height())); 132 return size; 133 } 130 QSize sizeHint(const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const; 134 131 135 132 protected: … … 138 135 /** Filters @a pEvent if this object has been installed as an event filter for the watched @a pObject. */ 139 136 bool eventFilter(QObject *pObject, QEvent *pEvent); 140 #endif /* VBOX_WS_MAC */137 #endif 141 138 142 139 private: … … 159 156 /** Returns whether item in the row indicated by the given @a srcRow and @a srcParenIdx should be included in the model. */ 160 157 bool filterAcceptsRow(int srcRow, const QModelIndex & srcParenIdx) const; 158 161 159 /** Returns whether value of the item referred to by the given index @a leftIdx is less 162 160 * than the value of the item referred to by the given index @a rightIdx. */ … … 182 180 183 181 /** Returns whether the Appliance Editor has valid state. */ 184 bool isValid() const 182 bool isValid() const { return m_pAppliance != NULL; } 185 183 /** Returns the currently set appliance reference. */ 186 184 CAppliance* appliance() const { return m_pAppliance; } 187 185 188 186 /** Returns the minimum guest RAM. */ 189 static int minGuestRAM() 187 static int minGuestRAM() { return m_minGuestRAM; } 190 188 /** Returns the maximum guest RAM. */ 191 static int maxGuestRAM() 189 static int maxGuestRAM() { return m_maxGuestRAM; } 192 190 /** Returns the minimum guest CPU count. */ 193 191 static int minGuestCPUCount() { return m_minGuestCPUCount; }
Note:
See TracChangeset
for help on using the changeset viewer.