- Timestamp:
- Sep 2, 2020 3:46:14 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/global
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.cpp
r85973 r86005 18 18 /* Qt includes: */ 19 19 #include <QHeaderView> 20 #include <QGridLayout>21 20 #include <QMenu> 21 #include <QVBoxLayout> 22 22 #ifdef VBOX_WS_WIN 23 23 # include <QTextStream> … … 173 173 174 174 UIGlobalSettingsExtension::UIGlobalSettingsExtension() 175 : m_pActionAdd(0), m_pActionRemove(0) 176 , m_pCache(0) 177 , m_pPackagesTree(0) 178 , m_pEntensionLabel(0) 179 , m_pPackagesToolbar(0) 175 : m_pCache(0) 176 , m_pLabelSeparator(0) 177 , m_pLayoutPackages(0) 178 , m_pTreeWidget(0) 179 , m_pToolbar(0) 180 , m_pActionAdd(0) 181 , m_pActionRemove(0) 180 182 { 181 183 /* Prepare: */ … … 224 226 /* Load old extension data from the cache: */ 225 227 foreach (const UIDataSettingsGlobalExtensionItem &item, oldExtensionData.m_items) 226 new UIExtensionPackageItem(m_p PackagesTree, item);228 new UIExtensionPackageItem(m_pTreeWidget, item); 227 229 /* If at least one item present: */ 228 if (m_p PackagesTree->topLevelItemCount())229 m_p PackagesTree->setCurrentItem(m_pPackagesTree->topLevelItem(0));230 if (m_pTreeWidget->topLevelItemCount()) 231 m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0)); 230 232 /* Update action's availability: */ 231 sltHandleCurrentItemChange(m_p PackagesTree->currentItem());233 sltHandleCurrentItemChange(m_pTreeWidget->currentItem()); 232 234 } 233 235 … … 250 252 void UIGlobalSettingsExtension::retranslateUi() 251 253 { 252 m_p EntensionLabel->setText(tr("&Extension Packages"));253 QTreeWidgetItem *pTreeWidgetItem = m_p PackagesTree->headerItem();254 m_pLabelSeparator->setText(tr("&Extension Packages")); 255 QTreeWidgetItem *pTreeWidgetItem = m_pTreeWidget->headerItem(); 254 256 if (pTreeWidgetItem) 255 257 { … … 258 260 pTreeWidgetItem->setText(0, tr("Active")); 259 261 } 260 m_p PackagesTree->setWhatsThis(tr("Lists all installed packages."));262 m_pTreeWidget->setWhatsThis(tr("Lists all installed packages.")); 261 263 262 264 /* Translate actions: */ … … 280 282 { 281 283 QMenu menu; 282 if (m_p PackagesTree->itemAt(position))284 if (m_pTreeWidget->itemAt(position)) 283 285 { 284 286 menu.addAction(m_pActionAdd); … … 289 291 menu.addAction(m_pActionAdd); 290 292 } 291 menu.exec(m_p PackagesTree->viewport()->mapToGlobal(position));293 menu.exec(m_pTreeWidget->viewport()->mapToGlobal(position)); 292 294 } 293 295 … … 337 339 338 340 /* Remove it from the tree: */ 339 const int cItems = m_p PackagesTree->topLevelItemCount();341 const int cItems = m_pTreeWidget->topLevelItemCount(); 340 342 for (int i = 0; i < cItems; i++) 341 343 { 342 UIExtensionPackageItem *pItem = static_cast<UIExtensionPackageItem*>(m_p PackagesTree->topLevelItem(i));344 UIExtensionPackageItem *pItem = static_cast<UIExtensionPackageItem*>(m_pTreeWidget->topLevelItem(i)); 343 345 if (!strExtPackName.compare(pItem->name(), Qt::CaseInsensitive)) 344 346 { … … 357 359 m_pCache->data().m_items << item; 358 360 359 UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_p PackagesTree, m_pCache->data().m_items.last());360 m_p PackagesTree->setCurrentItem(pItem);361 m_p PackagesTree->sortByColumn(1, Qt::AscendingOrder);361 UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pTreeWidget, m_pCache->data().m_items.last()); 362 m_pTreeWidget->setCurrentItem(pItem); 363 m_pTreeWidget->sortByColumn(1, Qt::AscendingOrder); 362 364 } 363 365 } … … 368 370 { 369 371 /* Get current item: */ 370 UIExtensionPackageItem *pItem = m_p PackagesTree&&371 m_p PackagesTree->currentItem() ?372 static_cast<UIExtensionPackageItem*>(m_p PackagesTree->currentItem()) : 0;372 UIExtensionPackageItem *pItem = m_pTreeWidget && 373 m_pTreeWidget->currentItem() ? 374 static_cast<UIExtensionPackageItem*>(m_pTreeWidget->currentItem()) : 0; 373 375 374 376 /* Uninstall chosen package: */ … … 422 424 void UIGlobalSettingsExtension::prepare() 423 425 { 424 prepareWidgets();425 426 426 /* Prepare cache: */ 427 427 m_pCache = new UISettingsCacheGlobalExtension; 428 428 AssertPtrReturnVoid(m_pCache); 429 429 430 /* Layout created in the .ui file. */ 431 { 432 /* Tree-widget created in the .ui file. */ 433 AssertPtrReturnVoid(m_pPackagesTree); 434 { 435 /* Configure tree-widget: */ 436 m_pPackagesTree->header()->setStretchLastSection(false); 437 m_pPackagesTree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); 438 m_pPackagesTree->header()->setSectionResizeMode(1, QHeaderView::Stretch); 439 m_pPackagesTree->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents); 440 m_pPackagesTree->setContextMenuPolicy(Qt::CustomContextMenu); 441 connect(m_pPackagesTree, &QITreeWidget::currentItemChanged, 442 this, &UIGlobalSettingsExtension::sltHandleCurrentItemChange); 443 connect(m_pPackagesTree, &QITreeWidget::customContextMenuRequested, 444 this, &UIGlobalSettingsExtension::sltHandleContextMenuRequest); 445 } 446 447 /* Tool-bar created in the .ui file. */ 448 AssertPtrReturnVoid(m_pPackagesToolbar); 449 { 450 /* Configure toolbar: */ 451 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 452 m_pPackagesToolbar->setOrientation(Qt::Vertical); 453 m_pPackagesToolbar->setIconSize(QSize(iIconMetric, iIconMetric)); 454 455 /* Create 'Add Package' action: */ 456 m_pActionAdd = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/extension_pack_install_16px.png", 457 ":/extension_pack_install_disabled_16px.png"), 458 QString(), this, SLOT(sltAddPackage())); 459 460 /* Create 'Remove Package' action: */ 461 m_pActionRemove = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/extension_pack_uninstall_16px.png", 462 ":/extension_pack_uninstall_disabled_16px.png"), 463 QString(), this, SLOT(sltRemovePackage())); 464 } 465 } 430 /* Prepare everything: */ 431 prepareWidgets(); 432 prepareConnections(); 466 433 467 434 /* Apply language settings: */ … … 471 438 void UIGlobalSettingsExtension::prepareWidgets() 472 439 { 473 if (objectName().isEmpty()) 474 setObjectName(QStringLiteral("UIGlobalSettingsExtension")); 475 QGridLayout *pMainLayout = new QGridLayout(this); 476 pMainLayout->setContentsMargins(0, 0, 0, 0); 477 pMainLayout->setObjectName(QStringLiteral("pMainLayout")); 478 m_pEntensionLabel = new QILabelSeparator(); 479 m_pEntensionLabel->setObjectName(QStringLiteral("m_pEntensionLabel")); 480 pMainLayout->addWidget(m_pEntensionLabel, 0, 0, 1, 1); 481 482 QWidget *pExtensionPackContainer = new QWidget(); 483 pExtensionPackContainer->setObjectName(QStringLiteral("pExtensionPackContainer")); 484 QHBoxLayout *pLayout1 = new QHBoxLayout(pExtensionPackContainer); 485 pLayout1->setSpacing(3); 486 pLayout1->setContentsMargins(0, 0, 0, 0); 487 pLayout1->setObjectName(QStringLiteral("pLayout1")); 488 m_pPackagesTree = new QITreeWidget(pExtensionPackContainer); 489 m_pPackagesTree->setObjectName(QStringLiteral("m_pPackagesTree")); 490 m_pPackagesTree->setColumnCount(3); 491 QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 492 sizePolicy.setHorizontalStretch(0); 493 sizePolicy.setVerticalStretch(0); 494 sizePolicy.setHeightForWidth(m_pPackagesTree->sizePolicy().hasHeightForWidth()); 495 m_pPackagesTree->setSizePolicy(sizePolicy); 496 m_pPackagesTree->setMinimumSize(QSize(0, 150)); 497 m_pPackagesTree->setRootIsDecorated(false); 498 pLayout1->addWidget(m_pPackagesTree); 499 500 m_pPackagesToolbar = new UIToolBar(pExtensionPackContainer); 501 m_pPackagesToolbar->setObjectName(QStringLiteral("m_pPackagesToolbar")); 502 pLayout1->addWidget(m_pPackagesToolbar); 503 504 pMainLayout->addWidget(pExtensionPackContainer, 1, 0, 1, 1); 505 m_pEntensionLabel->setBuddy(m_pPackagesTree); 440 /* Prepare main layout: */ 441 QVBoxLayout *pLayoutMain = new QVBoxLayout(this); 442 if (pLayoutMain) 443 { 444 pLayoutMain->setContentsMargins(0, 0, 0, 0); 445 446 /* Prepare separator: */ 447 m_pLabelSeparator = new QILabelSeparator(this); 448 if (m_pLabelSeparator) 449 pLayoutMain->addWidget(m_pLabelSeparator); 450 451 /* Prepare packages layout: */ 452 m_pLayoutPackages = new QHBoxLayout; 453 if (m_pLayoutPackages) 454 { 455 m_pLayoutPackages->setSpacing(3); 456 457 /* Prepare tree-widget: */ 458 prepareTreeWidget(); 459 /* Prepare toolbar: */ 460 prepareToolbar(); 461 462 pLayoutMain->addLayout(m_pLayoutPackages); 463 } 464 } 465 } 466 467 void UIGlobalSettingsExtension::prepareTreeWidget() 468 { 469 /* Prepare tree-widget: */ 470 m_pTreeWidget = new QITreeWidget(this); 471 if (m_pTreeWidget) 472 { 473 if (m_pLabelSeparator) 474 m_pLabelSeparator->setBuddy(m_pTreeWidget); 475 m_pTreeWidget->setColumnCount(3); 476 m_pTreeWidget->setRootIsDecorated(false); 477 m_pTreeWidget->header()->setStretchLastSection(false); 478 m_pTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); 479 m_pTreeWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch); 480 m_pTreeWidget->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents); 481 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); 482 483 m_pLayoutPackages->addWidget(m_pTreeWidget); 484 } 485 } 486 487 void UIGlobalSettingsExtension::prepareToolbar() 488 { 489 /* Prepare toolbar: */ 490 m_pToolbar = new UIToolBar(this); 491 if (m_pToolbar) 492 { 493 /* Configure toolbar: */ 494 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 495 m_pToolbar->setIconSize(QSize(iIconMetric, iIconMetric)); 496 m_pToolbar->setOrientation(Qt::Vertical); 497 498 /* Prepare 'Add Package' action: */ 499 m_pActionAdd = m_pToolbar->addAction(UIIconPool::iconSet(":/extension_pack_install_16px.png", 500 ":/extension_pack_install_disabled_16px.png"), 501 QString(), this, SLOT(sltAddPackage())); 502 503 /* Prepare 'Remove Package' action: */ 504 m_pActionRemove = m_pToolbar->addAction(UIIconPool::iconSet(":/extension_pack_uninstall_16px.png", 505 ":/extension_pack_uninstall_disabled_16px.png"), 506 QString(), this, SLOT(sltRemovePackage())); 507 508 m_pLayoutPackages->addWidget(m_pToolbar); 509 } 510 } 511 512 void UIGlobalSettingsExtension::prepareConnections() 513 { 514 connect(m_pTreeWidget, &QITreeWidget::currentItemChanged, 515 this, &UIGlobalSettingsExtension::sltHandleCurrentItemChange); 516 connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested, 517 this, &UIGlobalSettingsExtension::sltHandleContextMenuRequest); 506 518 } 507 519 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.h
r85822 r86005 26 26 27 27 /* Forward declarations: */ 28 class QHBoxLayout; 28 29 class QITreeWidget; 29 30 class QTreeWidgetItem; … … 83 84 /** Prepares widgets. */ 84 85 void prepareWidgets(); 86 /** Prepares tree-widget. */ 87 void prepareTreeWidget(); 88 /** Prepares toolbar. */ 89 void prepareToolbar(); 90 /** Prepares connections. */ 91 void prepareConnections(); 85 92 /** Cleanups all. */ 86 93 void cleanup(); … … 89 96 void loadData(const CExtPack &package, UIDataSettingsGlobalExtensionItem &item) const; 90 97 91 /** Holds the Add action instance. */92 QAction *m_pActionAdd;93 /** Holds the Remove action instance. */94 QAction *m_pActionRemove;95 96 98 /** Holds the page data cache instance. */ 97 99 UISettingsCacheGlobalExtension *m_pCache; 100 98 101 /** @name Widgets 99 102 * @{ */ 100 QITreeWidget *m_pPackagesTree; 101 QILabelSeparator *m_pEntensionLabel; 102 UIToolBar *m_pPackagesToolbar; 103 /** Holds the separator label instance. */ 104 QILabelSeparator *m_pLabelSeparator; 105 /** Holds the packages layout instance. */ 106 QHBoxLayout *m_pLayoutPackages; 107 /** Holds the tree-widget instance. */ 108 QITreeWidget *m_pTreeWidget; 109 /** Holds the toolbar instance. */ 110 UIToolBar *m_pToolbar; 111 /** Holds the Add action instance. */ 112 QAction *m_pActionAdd; 113 /** Holds the Remove action instance. */ 114 QAction *m_pActionRemove; 103 115 /** @} */ 104 116 };
Note:
See TracChangeset
for help on using the changeset viewer.