- Timestamp:
- Sep 2, 2020 1:12:28 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/UIGlobalSettingsNetwork.cpp
r85808 r85998 217 217 218 218 UIGlobalSettingsNetwork::UIGlobalSettingsNetwork() 219 : m_pActionAddNATNetwork(0), m_pActionRemoveNATNetwork(0), m_pActionEditNATNetwork(0) 220 , m_pCache(0) 221 , m_pTreeNetworkNAT(0) 222 , m_pNetworkLabel(0) 223 , m_pLayoutNAT(0) 219 : m_pCache(0) 220 , m_pLabelSeparator(0) 221 , m_pLayoutNATNetwork(0) 222 , m_pTreeWidgetNATNetwork(0) 224 223 , m_pToolbarNetworkNAT(0) 224 , m_pActionAddNATNetwork(0) 225 , m_pActionRemoveNATNetwork(0) 226 , m_pActionEditNATNetwork(0) 225 227 { 226 228 /* Prepare: */ … … 261 263 for (int i = 0; i < m_pCache->childCount(); ++i) 262 264 createTreeWidgetItemForNATNetwork(m_pCache->child(i)); 263 m_pTree NetworkNAT->sortByColumn(1, Qt::AscendingOrder);264 m_pTree NetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0));265 m_pTreeWidgetNATNetwork->sortByColumn(1, Qt::AscendingOrder); 266 m_pTreeWidgetNATNetwork->setCurrentItem(m_pTreeWidgetNATNetwork->topLevelItem(0)); 265 267 sltHandleCurrentItemChangeNATNetwork(); 266 268 … … 275 277 276 278 /* Gather new network data: */ 277 for (int i = 0; i < m_pTree NetworkNAT->topLevelItemCount(); ++i)278 { 279 const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->topLevelItem(i));279 for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i) 280 { 281 const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i)); 280 282 m_pCache->child(pItem->m_strName).cacheCurrentData(*pItem); 281 283 foreach (const UIDataPortForwardingRule &rule, pItem->ipv4rules()) … … 312 314 313 315 /* Validate items first: */ 314 for (int i = 0; i < m_pTree NetworkNAT->topLevelItemCount(); ++i)316 for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i) 315 317 { 316 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->topLevelItem(i));318 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i)); 317 319 if (!pItem->validate(message)) 318 320 fPass = false; … … 321 323 /* And make sure item names are unique: */ 322 324 QList<QString> names; 323 for (int iItemIndex = 0; iItemIndex < m_pTree NetworkNAT->topLevelItemCount(); ++iItemIndex)325 for (int iItemIndex = 0; iItemIndex < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++iItemIndex) 324 326 { 325 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->topLevelItem(iItemIndex));327 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(iItemIndex)); 326 328 const QString strItemName(pItem->newName()); 327 329 if (strItemName.isEmpty()) … … 348 350 void UIGlobalSettingsNetwork::retranslateUi() 349 351 { 350 m_p NetworkLabel->setText(tr("&NAT Networks"));351 m_pTree NetworkNAT->setWhatsThis(tr("Lists all available NAT networks."));352 m_pLabelSeparator->setText(tr("&NAT Networks")); 353 m_pTreeWidgetNATNetwork->setWhatsThis(tr("Lists all available NAT networks.")); 352 354 353 355 /* Translate tree-widget columns: */ 354 m_pTree NetworkNAT->setHeaderLabels(QStringList()356 m_pTreeWidgetNATNetwork->setHeaderLabels(QStringList() 355 357 << tr("Active", "NAT network") 356 358 << tr("Name")); … … 374 376 /* Compose a set of busy names: */ 375 377 QSet<QString> names; 376 for (int i = 0; i < m_pTree NetworkNAT->topLevelItemCount(); ++i)377 names << static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->topLevelItem(i))->name();378 for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i) 379 names << static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i))->name(); 378 380 /* Compose a map of busy indexes: */ 379 381 QMap<int, bool> presence; … … 406 408 /* Create tree-widget item: */ 407 409 createTreeWidgetItemForNATNetwork(data, UIPortForwardingDataList(), UIPortForwardingDataList(), true); 408 m_pTree NetworkNAT->sortByColumn(1, Qt::AscendingOrder);410 m_pTreeWidgetNATNetwork->sortByColumn(1, Qt::AscendingOrder); 409 411 } 410 412 … … 412 414 { 413 415 /* Get network item: */ 414 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->currentItem());416 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem()); 415 417 AssertPtrReturnVoid(pItem); 416 418 … … 426 428 { 427 429 /* Get network item: */ 428 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->currentItem());430 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem()); 429 431 AssertPtrReturnVoid(pItem); 430 432 … … 460 462 { 461 463 /* Get current item: */ 462 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTree NetworkNAT->currentItem());464 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem()); 463 465 464 466 /* Update availability: */ … … 471 473 /* Compose temporary context-menu: */ 472 474 QMenu menu; 473 if (m_pTree NetworkNAT->itemAt(position))475 if (m_pTreeWidgetNATNetwork->itemAt(position)) 474 476 { 475 477 menu.addAction(m_pActionEditNATNetwork); … … 481 483 } 482 484 /* And show it: */ 483 menu.exec(m_pTree NetworkNAT->mapToGlobal(position));485 menu.exec(m_pTreeWidgetNATNetwork->mapToGlobal(position)); 484 486 } 485 487 486 488 void UIGlobalSettingsNetwork::prepare() 487 489 { 488 prepareWidgets();489 490 490 /* Prepare cache: */ 491 491 m_pCache = new UISettingsCacheGlobalNetwork; 492 492 AssertPtrReturnVoid(m_pCache); 493 493 494 /* NAT Network layout created in the .ui file. */ 495 AssertPtrReturnVoid(m_pLayoutNAT); 496 { 497 /* Prepare network tree: */ 498 prepareNATNetworkTree(); 499 /* Prepare network toolbar: */ 500 prepareNATNetworkToolbar(); 501 /* Prepare connections: */ 502 prepareConnections(); 503 } 494 /* Prepare everything: */ 495 prepareWidgets(); 496 prepareConnections(); 504 497 505 498 /* Apply language settings: */ … … 509 502 void UIGlobalSettingsNetwork::prepareWidgets() 510 503 { 511 if (objectName().isEmpty()) 512 setObjectName(QStringLiteral("UIGlobalSettingsNetwork")); 513 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 514 pMainLayout->setContentsMargins(0, 0, 0, 0); 515 pMainLayout->setObjectName(QStringLiteral("pMainLayout")); 516 m_pNetworkLabel = new QILabelSeparator(); 517 m_pNetworkLabel->setObjectName(QStringLiteral("m_pNetworkLabel")); 518 pMainLayout->addWidget(m_pNetworkLabel); 519 520 m_pLayoutNAT = new QHBoxLayout(); 521 m_pLayoutNAT->setSpacing(3); 522 m_pLayoutNAT->setObjectName(QStringLiteral("m_pLayoutNAT")); 523 m_pTreeNetworkNAT = new QITreeWidget(); 524 m_pTreeNetworkNAT->setObjectName(QStringLiteral("m_pTreeNetworkNAT")); 525 QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 526 sizePolicy.setHorizontalStretch(0); 527 sizePolicy.setVerticalStretch(0); 528 sizePolicy.setHeightForWidth(m_pTreeNetworkNAT->sizePolicy().hasHeightForWidth()); 529 m_pTreeNetworkNAT->setSizePolicy(sizePolicy); 530 m_pTreeNetworkNAT->setMinimumSize(QSize(0, 150)); 531 m_pTreeNetworkNAT->setRootIsDecorated(false); 532 m_pLayoutNAT->addWidget(m_pTreeNetworkNAT); 533 534 m_pToolbarNetworkNAT = new UIToolBar(); 535 m_pToolbarNetworkNAT->setObjectName(QStringLiteral("m_pToolbarNetworkNAT")); 536 m_pLayoutNAT->addWidget(m_pToolbarNetworkNAT); 537 538 pMainLayout->addLayout(m_pLayoutNAT); 539 m_pNetworkLabel->setBuddy(m_pTreeNetworkNAT); 540 } 541 542 void UIGlobalSettingsNetwork::prepareNATNetworkTree() 543 { 544 /* NAT Network tree-widget created in the .ui file. */ 545 AssertPtrReturnVoid(m_pTreeNetworkNAT); 546 { 547 /* Configure tree-widget: */ 548 m_pTreeNetworkNAT->setColumnCount(2); 549 m_pTreeNetworkNAT->header()->setStretchLastSection(false); 550 m_pTreeNetworkNAT->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); 551 m_pTreeNetworkNAT->header()->setSectionResizeMode(1, QHeaderView::Stretch); 552 m_pTreeNetworkNAT->setContextMenuPolicy(Qt::CustomContextMenu); 504 /* Prepare main layout: */ 505 QVBoxLayout *pLayoutMain = new QVBoxLayout(this); 506 if (pLayoutMain) 507 { 508 pLayoutMain->setContentsMargins(0, 0, 0, 0); 509 510 /* Prepare separator: */ 511 m_pLabelSeparator = new QILabelSeparator(this); 512 if (m_pLabelSeparator) 513 pLayoutMain->addWidget(m_pLabelSeparator); 514 515 /* Prepare NAT network layout: */ 516 m_pLayoutNATNetwork = new QHBoxLayout(this); 517 if (m_pLayoutNATNetwork) 518 { 519 m_pLayoutNATNetwork->setSpacing(3); 520 521 /* Prepare NAT network tree-widget: */ 522 prepareNATNetworkTreeWidget(); 523 /* Prepare NAT network toolbar: */ 524 prepareNATNetworkToolbar(); 525 526 pLayoutMain->addLayout(m_pLayoutNATNetwork); 527 } 528 } 529 } 530 531 void UIGlobalSettingsNetwork::prepareNATNetworkTreeWidget() 532 { 533 /* Prepare NAT network tree-widget: */ 534 m_pTreeWidgetNATNetwork = new QITreeWidget(this); 535 if (m_pTreeWidgetNATNetwork) 536 { 537 if (m_pLabelSeparator) 538 m_pLabelSeparator->setBuddy(m_pTreeWidgetNATNetwork); 539 m_pTreeWidgetNATNetwork->setColumnCount(2); 540 m_pTreeWidgetNATNetwork->setRootIsDecorated(false); 541 m_pTreeWidgetNATNetwork->header()->setStretchLastSection(false); 542 m_pTreeWidgetNATNetwork->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); 543 m_pTreeWidgetNATNetwork->header()->setSectionResizeMode(1, QHeaderView::Stretch); 544 m_pTreeWidgetNATNetwork->setContextMenuPolicy(Qt::CustomContextMenu); 545 546 m_pLayoutNATNetwork->addWidget(m_pTreeWidgetNATNetwork); 553 547 } 554 548 } … … 556 550 void UIGlobalSettingsNetwork::prepareNATNetworkToolbar() 557 551 { 558 /* NAT Network toolbar created in the .ui file.*/559 AssertPtrReturnVoid(m_pToolbarNetworkNAT);560 {561 /* Configure toolbar: */552 /* Prepare NAT network toolbar: */ 553 m_pToolbarNetworkNAT = new UIToolBar(this); 554 if (m_pToolbarNetworkNAT) 555 { 562 556 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 563 557 m_pToolbarNetworkNAT->setIconSize(QSize(iIconMetric, iIconMetric)); 564 558 m_pToolbarNetworkNAT->setOrientation(Qt::Vertical); 565 559 566 /* Create'Add NAT Network' action: */560 /* Prepare 'Add NAT Network' action: */ 567 561 m_pActionAddNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_add_16px.png", 568 562 ":/host_iface_add_disabled_16px.png"), 569 563 QString(), this, SLOT(sltAddNATNetwork())); 570 AssertPtrReturnVoid(m_pActionAddNATNetwork); 571 { 572 /* Configure action: */ 564 if (m_pActionAddNATNetwork) 573 565 m_pActionAddNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Ins") << QKeySequence("Ctrl+N")); 574 } 575 576 /* Create 'Remove NAT Network' action: */ 566 567 /* Prepare 'Remove NAT Network' action: */ 577 568 m_pActionRemoveNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_remove_16px.png", 578 569 ":/host_iface_remove_disabled_16px.png"), 579 570 QString(), this, SLOT(sltRemoveNATNetwork())); 580 AssertPtrReturnVoid(m_pActionRemoveNATNetwork); 581 { 582 /* Configure action: */ 571 if (m_pActionRemoveNATNetwork) 583 572 m_pActionRemoveNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Ctrl+R")); 584 } 585 586 /* Create 'Edit NAT Network' action: */ 573 574 /* Prepare 'Edit NAT Network' action: */ 587 575 m_pActionEditNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_edit_16px.png", 588 576 ":/host_iface_edit_disabled_16px.png"), 589 577 QString(), this, SLOT(sltEditNATNetwork())); 590 AssertPtrReturnVoid(m_pActionEditNATNetwork); 591 { 592 /* Configure action: */ 578 if (m_pActionEditNATNetwork) 593 579 m_pActionEditNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Space") << QKeySequence("F2")); 594 } 580 581 m_pLayoutNATNetwork->addWidget(m_pToolbarNetworkNAT); 595 582 } 596 583 } … … 598 585 void UIGlobalSettingsNetwork::prepareConnections() 599 586 { 600 /* Configure 'NAT Network'connections: */601 connect(m_pTree NetworkNAT, &QITreeWidget::currentItemChanged,587 /* Configure NAT network connections: */ 588 connect(m_pTreeWidgetNATNetwork, &QITreeWidget::currentItemChanged, 602 589 this, &UIGlobalSettingsNetwork::sltHandleCurrentItemChangeNATNetwork); 603 connect(m_pTree NetworkNAT, &QITreeWidget::customContextMenuRequested,590 connect(m_pTreeWidgetNATNetwork, &QITreeWidget::customContextMenuRequested, 604 591 this, &UIGlobalSettingsNetwork::sltHandleContextMenuRequestNATNetwork); 605 connect(m_pTree NetworkNAT, &QITreeWidget::itemDoubleClicked,592 connect(m_pTreeWidgetNATNetwork, &QITreeWidget::itemDoubleClicked, 606 593 this, &UIGlobalSettingsNetwork::sltEditNATNetwork); 607 connect(m_pTree NetworkNAT, &QITreeWidget::itemChanged,594 connect(m_pTreeWidgetNATNetwork, &QITreeWidget::itemChanged, 608 595 this, &UIGlobalSettingsNetwork::sltHandleItemChangeNATNetwork); 609 596 } … … 1018 1005 1019 1006 /* Add item to the tree-widget: */ 1020 m_pTree NetworkNAT->addTopLevelItem(pItem);1007 m_pTreeWidgetNATNetwork->addTopLevelItem(pItem); 1021 1008 } 1022 1009 1023 1010 /* And choose it as current if necessary: */ 1024 1011 if (fChooseItem) 1025 m_pTree NetworkNAT->setCurrentItem(pItem);1012 m_pTreeWidgetNATNetwork->setCurrentItem(pItem); 1026 1013 } 1027 1014 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h
r85808 r85998 94 94 /** Prepares widgets. */ 95 95 void prepareWidgets(); 96 /** Prepares NAT network tree . */97 void prepareNATNetworkTree ();96 /** Prepares NAT network tree-widget. */ 97 void prepareNATNetworkTreeWidget(); 98 98 /** Prepares NAT network toolbar. */ 99 99 void prepareNATNetworkToolbar(); … … 127 127 bool isNetworkCouldBeUpdated(const UISettingsCacheGlobalNetworkNAT &cache) const; 128 128 129 /** Holds the Add NAT network action instance. */130 QAction *m_pActionAddNATNetwork;131 /** Holds the Remove NAT network action instance. */132 QAction *m_pActionRemoveNATNetwork;133 /** Holds the Edit NAT network action instance. */134 QAction *m_pActionEditNATNetwork;135 136 129 /** Holds the page data cache instance. */ 137 130 UISettingsCacheGlobalNetwork *m_pCache; … … 139 132 /** @name Widgets 140 133 * @{ */ 141 QITreeWidget *m_pTreeNetworkNAT; 142 QILabelSeparator *m_pNetworkLabel; 143 QHBoxLayout *m_pLayoutNAT; 144 UIToolBar *m_pToolbarNetworkNAT; 134 /** Holds the separator label instance. */ 135 QILabelSeparator *m_pLabelSeparator; 136 /** Holds the NAT networt layout instance. */ 137 QHBoxLayout *m_pLayoutNATNetwork; 138 /** Holds the NAT networt tree-widget instance. */ 139 QITreeWidget *m_pTreeWidgetNATNetwork; 140 /** Holds the NAT networt toolbar instance. */ 141 UIToolBar *m_pToolbarNetworkNAT; 142 /** Holds the Add NAT network action instance. */ 143 QAction *m_pActionAddNATNetwork; 144 /** Holds the Remove NAT network action instance. */ 145 QAction *m_pActionRemoveNATNetwork; 146 /** Holds the Edit NAT network action instance. */ 147 QAction *m_pActionEditNATNetwork; 145 148 /** @} */ 146 149 };
Note:
See TracChangeset
for help on using the changeset viewer.