Changeset 63851 in vbox
- Timestamp:
- Sep 15, 2016 11:00:39 AM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r63804 r63851 565 565 src/selector/UIVirtualBoxEventHandler.cpp \ 566 566 src/selector/UIVMDesktop.cpp \ 567 src/selector/UISnapshotPane.cpp \ 567 568 src/settings/machine/UIMachineSettingsStorage.cpp \ 568 569 src/settings/machine/UIMachineSettingsUSB.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r63838 r63851 148 148 /** Holds the cached machine state. */ 149 149 KMachineState m_enmMachineState; 150 }; 151 152 153 /** QTreeWidget subclass for snapshots items. */ 154 class UISnapshotTree : public QTreeWidget 155 { 156 Q_OBJECT; 157 158 public: 159 160 /** Constructs snapshot tree passing @a pParent to the base-class. */ 161 UISnapshotTree(QWidget *pParent); 150 162 }; 151 163 … … 455 467 456 468 /********************************************************************************************************************************* 469 * Class UISnapshotTree implementation. * 470 *********************************************************************************************************************************/ 471 472 UISnapshotTree::UISnapshotTree(QWidget *pParent) 473 : QTreeWidget(pParent) 474 { 475 /* No header: */ 476 header()->hide(); 477 /* All columns as one: */ 478 setAllColumnsShowFocus(true); 479 /* Our own context menu: */ 480 setContextMenuPolicy(Qt::CustomContextMenu); 481 482 #if QT_VERSION < 0x050000 483 // WORKAROUND: 484 // The snapshots widget is not very useful if there are a lot 485 // of snapshots in a tree and the current Qt style decides not 486 // to draw lines (branches) between the snapshot nodes; it is 487 // then often unclear which snapshot is a child of another. 488 // So on platforms whose styles do not normally draw branches, 489 // we use QWindowsStyle which is present on every platform and 490 // draws required thing like we want. */ 491 // #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 492 QWindowsStyle *pTreeWidgetStyle = new QWindowsStyle; 493 setStyle(pTreeWidgetStyle); 494 connect(this, SIGNAL(destroyed(QObject *)), pTreeWidgetStyle, SLOT(deleteLater())); 495 // #endif 496 #endif /* QT_VERSION < 0x050000 */ 497 } 498 499 500 /********************************************************************************************************************************* 457 501 * Class UISnapshotPane implementation. * 458 502 *********************************************************************************************************************************/ … … 469 513 , m_pActionCloneSnapshot(new QAction(m_pCurrentStateItemActionGroup)) 470 514 , m_fShapshotOperationsAllowed(false) 471 , m_p TreeWidget(0)515 , m_pSnapshotTree(0) 472 516 { 473 517 /* Cache pixmaps: */ … … 521 565 m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C")); 522 566 523 /* Create tree-widget: */ 524 m_pTreeWidget = new QTreeWidget(this); 525 m_pTreeWidget->header()->hide(); 526 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); 527 m_pTreeWidget->setAllColumnsShowFocus(true); 528 /* Add tree-widget into layout: */ 529 pLayout->addWidget(m_pTreeWidget); 530 531 #if QT_VERSION < 0x050000 532 // WORKAROUND: 533 // The snapshots widget is not very useful if there are a lot 534 // of snapshots in a tree and the current Qt style decides not 535 // to draw lines (branches) between the snapshot nodes; it is 536 // then often unclear which snapshot is a child of another. 537 // So on platforms whose styles do not normally draw branches, 538 // we use QWindowsStyle which is present on every platform and 539 // draws required thing like we want. */ 540 // #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 541 QWindowsStyle *pTreeWidgetStyle = new QWindowsStyle; 542 m_pTreeWidget->setStyle(pTreeWidgetStyle); 543 connect(m_pTreeWidget, SIGNAL(destroyed(QObject *)), pTreeWidgetStyle, SLOT(deleteLater())); 544 // #endif 545 #endif /* QT_VERSION < 0x050000 */ 567 /* Create snapshot tree: */ 568 m_pSnapshotTree = new UISnapshotTree(this); 569 /* Add snapshot tree into layout: */ 570 pLayout->addWidget(m_pSnapshotTree); 546 571 547 572 /* Setup timer: */ 548 573 m_ageUpdateTimer.setSingleShot(true); 549 574 550 /* Setup tree-widgetconnections: */551 connect(m_p TreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),575 /* Setup snapshot tree connections: */ 576 connect(m_pSnapshotTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 552 577 this, SLOT(sltCurrentItemChanged(QTreeWidgetItem *))); 553 connect(m_p TreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)),578 connect(m_pSnapshotTree, SIGNAL(customContextMenuRequested(const QPoint &)), 554 579 this, SLOT(sltContextMenuRequested(const QPoint &))); 555 connect(m_p TreeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)),580 connect(m_pSnapshotTree, SIGNAL(itemChanged(QTreeWidgetItem *, int)), 556 581 this, SLOT(sltItemChanged(QTreeWidgetItem *))); 557 connect(m_p TreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),582 connect(m_pSnapshotTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), 558 583 this, SLOT(sltItemDoubleClicked(QTreeWidgetItem *))); 559 584 /* Setup snapshot operation connections: */ … … 624 649 if (pSnapshotItem) 625 650 { 626 m_p TreeWidget->horizontalScrollBar()->setValue(0);627 m_p TreeWidget->scrollToItem(pSnapshotItem);628 m_p TreeWidget->horizontalScrollBar()->setValue(m_pTreeWidget->indentation() * pSnapshotItem->level());651 m_pSnapshotTree->horizontalScrollBar()->setValue(0); 652 m_pSnapshotTree->scrollToItem(pSnapshotItem); 653 m_pSnapshotTree->horizontalScrollBar()->setValue(m_pSnapshotTree->indentation() * pSnapshotItem->level()); 629 654 } 630 655 … … 682 707 { 683 708 /* Search for corresponding item: */ 684 const QTreeWidgetItem *pItem = m_p TreeWidget->itemAt(point);709 const QTreeWidgetItem *pItem = m_pSnapshotTree->itemAt(point); 685 710 if (!pItem) 686 711 return; … … 710 735 711 736 /* Show menu: */ 712 menu.exec(m_p TreeWidget->viewport()->mapToGlobal(point));737 menu.exec(m_pSnapshotTree->viewport()->mapToGlobal(point)); 713 738 } 714 739 … … 784 809 /* Recache new session state: */ 785 810 m_enmSessionState = enmState; 786 sltCurrentItemChanged(m_p TreeWidget->currentItem());811 sltCurrentItemChanged(m_pSnapshotTree->currentItem()); 787 812 } 788 813 … … 794 819 795 820 /* Search for smallest snapshot age to optimize timer timeout: */ 796 const SnapshotAgeFormat age = traverseSnapshotAge(m_p TreeWidget->invisibleRootItem());821 const SnapshotAgeFormat age = traverseSnapshotAge(m_pSnapshotTree->invisibleRootItem()); 797 822 switch (age) 798 823 { … … 842 867 QString strSnapshotName = tr("Snapshot %1"); 843 868 QRegExp regExp(QString("^") + strSnapshotName.arg("([0-9]+)") + QString("$")); 844 QTreeWidgetItemIterator iterator(m_p TreeWidget);869 QTreeWidgetItemIterator iterator(m_pSnapshotTree); 845 870 while (*iterator) 846 871 { … … 908 933 { 909 934 /* Acquire currently chosen snapshot item: */ 910 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_p TreeWidget->currentItem());935 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem()); 911 936 AssertPtr(pSnapshotItem); 912 937 if (!pSnapshotItem) … … 931 956 { 932 957 /* Take snapshot of changed current state: */ 933 m_p TreeWidget->setCurrentItem(currentStateItem());958 m_pSnapshotTree->setCurrentItem(currentStateItem()); 934 959 if (!takeSnapshot()) 935 960 break; … … 983 1008 { 984 1009 /* Acquire currently chosen snapshot item: */ 985 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_p TreeWidget->currentItem());1010 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem()); 986 1011 AssertPtr(pSnapshotItem); 987 1012 if (!pSnapshotItem) … … 1053 1078 { 1054 1079 /* Acquire currently chosen snapshot item: */ 1055 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_p TreeWidget->currentItem());1080 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem()); 1056 1081 AssertReturnVoid(pSnapshotItem); 1057 1082 … … 1072 1097 { 1073 1098 /* Acquire currently chosen snapshot item: */ 1074 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_p TreeWidget->currentItem());1099 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem()); 1075 1100 AssertReturnVoid(pSnapshotItem); 1076 1101 … … 1110 1135 /* Remember the selected item and it's first child: */ 1111 1136 QString strSelectedItem, strFirstChildOfSelectedItem; 1112 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_p TreeWidget->currentItem());1137 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem()); 1113 1138 if (pSnapshotItem) 1114 1139 { … … 1119 1144 1120 1145 /* Clear the tree: */ 1121 m_p TreeWidget->clear();1146 m_pSnapshotTree->clear(); 1122 1147 1123 1148 /* If machine has snapshots: */ … … 1145 1170 1146 1171 /* Choose current item: */ 1147 m_p TreeWidget->scrollToItem(pCurrentItem);1148 m_p TreeWidget->setCurrentItem(pCurrentItem);1172 m_pSnapshotTree->scrollToItem(pCurrentItem); 1173 m_pSnapshotTree->setCurrentItem(pCurrentItem); 1149 1174 sltCurrentItemChanged(pCurrentItem); 1150 1175 } … … 1155 1180 m_pCurrentSnapshotItem = 0; 1156 1181 1157 /* Add the "current state" item as a child of tree-widget: */1158 SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_p TreeWidget, m_comMachine);1182 /* Add the "current state" item as a child of snapshot tree: */ 1183 SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_pSnapshotTree, m_comMachine); 1159 1184 pCsi->setBold(true); 1160 1185 pCsi->recache(); 1161 1186 1162 1187 /* Choose current item: */ 1163 m_p TreeWidget->setCurrentItem(pCsi);1188 m_pSnapshotTree->setCurrentItem(pCsi); 1164 1189 sltCurrentItemChanged(pCsi); 1165 1190 } … … 1168 1193 sltUpdateSnapshotsAge(); 1169 1194 1170 /* Adjust tree-widget: */1171 m_p TreeWidget->resizeColumnToContents(0);1195 /* Adjust snapshot tree: */ 1196 m_pSnapshotTree->resizeColumnToContents(0); 1172 1197 } 1173 1198 … … 1176 1201 /* Create a child of passed item: */ 1177 1202 SnapshotWgtItem *pSnapshotItem = pItem ? new SnapshotWgtItem(this, pItem, comSnapshot) : 1178 new SnapshotWgtItem(this, m_p TreeWidget, comSnapshot);1203 new SnapshotWgtItem(this, m_pSnapshotTree, comSnapshot); 1179 1204 /* And recache it's content: */ 1180 1205 pSnapshotItem->recache(); … … 1201 1226 { 1202 1227 /* Search for the first item with required ID: */ 1203 QTreeWidgetItemIterator it(m_p TreeWidget);1228 QTreeWidgetItemIterator it(m_pSnapshotTree); 1204 1229 while (*it) 1205 1230 { … … 1219 1244 QTreeWidgetItem *pCsi = m_pCurrentSnapshotItem ? 1220 1245 m_pCurrentSnapshotItem->child(m_pCurrentSnapshotItem->childCount() - 1) : 1221 m_p TreeWidget->invisibleRootItem()->child(0);1246 m_pSnapshotTree->invisibleRootItem()->child(0); 1222 1247 return static_cast<SnapshotWgtItem*>(pCsi); 1223 1248 } … … 1266 1291 } 1267 1292 1293 #include "UISnapshotPane.moc" 1294 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r63838 r63851 32 32 33 33 /* Forward declarations: */ 34 class QTreeWidget;34 class UISnapshotTree; 35 35 class QTreeWidgetItem; 36 36 class SnapshotWgtItem; … … 185 185 QIcon m_snapshotIconOnline; 186 186 187 /** Holds the tree-widgetinstance. */188 QTreeWidget *m_pTreeWidget;187 /** Holds the snapshot tree instance. */ 188 UISnapshotTree *m_pSnapshotTree; 189 189 }; 190 190
Note:
See TracChangeset
for help on using the changeset viewer.