- Timestamp:
- May 26, 2017 4:05:01 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r67119 r67120 523 523 , m_pCurrentSnapshotItem(0) 524 524 , m_pLockReadWrite(0) 525 , m_pToolBar(0) 525 526 , m_pActionTakeSnapshot(0) 526 527 , m_pActionRestoreSnapshot(0) … … 534 535 , m_pSnapshotTree(0) 535 536 { 536 /* Create locker: */ 537 m_pLockReadWrite = new QReadWriteLock; 538 539 /* Cache pixmaps: */ 540 m_pIconSnapshotOffline = new QIcon(UIIconPool::iconSet(":/snapshot_offline_16px.png")); 541 m_pIconSnapshotOnline = new QIcon(UIIconPool::iconSet(":/snapshot_online_16px.png")); 542 543 /* Create layout: */ 544 QVBoxLayout *pLayout = new QVBoxLayout(this); 545 { 546 /* Configure layout: */ 547 pLayout->setContentsMargins(0, 0, 0, 0); 548 #ifdef VBOX_WS_MAC 549 pLayout->setSpacing(10); 550 #else 551 pLayout->setSpacing(4); 552 #endif 553 554 /* Create snapshot toolbar: */ 555 UIToolBar *pToolBar = new UIToolBar(this); 556 { 557 /* Configure toolbar: */ 558 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375); 559 pToolBar->setIconSize(QSize(iIconMetric, iIconMetric)); 560 pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 561 pToolBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 562 563 /* Add Take Snapshot action: */ 564 m_pActionTakeSnapshot = pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_take_22px.png", 565 ":/snapshot_take_16px.png", 566 ":/snapshot_take_disabled_22px.png", 567 ":/snapshot_take_disabled_16px.png"), 568 QString(), this, &UISnapshotPane::sltTakeSnapshot); 569 { 570 m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S")); 571 } 572 573 pToolBar->addSeparator(); 574 575 /* Add Restore Snapshot action: */ 576 m_pActionRestoreSnapshot = pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_restore_22px.png", 577 ":/snapshot_restore_16px.png", 578 ":/snapshot_restore_disabled_22px.png", 579 ":/snapshot_restore_disabled_16px.png"), 580 QString(), this, &UISnapshotPane::sltRestoreSnapshot); 581 { 582 m_pActionRestoreSnapshot->setShortcut(QString("Ctrl+Shift+R")); 583 } 584 585 /* Add Delete Snapshot action: */ 586 m_pActionDeleteSnapshot = pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_delete_22px.png", 587 ":/snapshot_delete_16px.png", 588 ":/snapshot_delete_disabled_22px.png", 589 ":/snapshot_delete_disabled_16px.png"), 590 QString(), this, &UISnapshotPane::sltDeleteSnapshot); 591 { 592 m_pActionDeleteSnapshot->setShortcut(QString("Ctrl+Shift+D")); 593 } 594 595 /* Add Show Snapshot Details action: */ 596 m_pActionShowSnapshotDetails = pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_show_details_22px.png", 597 ":/snapshot_show_details_16px.png", 598 ":/snapshot_show_details_disabled_22px.png", 599 ":/snapshot_details_show_disabled_16px.png"), 600 QString(), this, &UISnapshotPane::sltShowSnapshotDetails); 601 { 602 m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space")); 603 } 604 605 pToolBar->addSeparator(); 606 607 /* Add Clone Snapshot action: */ 608 m_pActionCloneSnapshot = pToolBar->addAction(UIIconPool::iconSetFull(":/vm_clone_22px.png", 609 ":/vm_clone_16px.png", 610 ":/vm_clone_disabled_22px.png", 611 ":/vm_clone_disabled_16px.png"), 612 QString(), this, &UISnapshotPane::sltCloneSnapshot); 613 { 614 m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C")); 615 } 616 617 /* Add into layout: */ 618 pLayout->addWidget(pToolBar); 619 } 620 621 /* Create snapshot tree: */ 622 m_pSnapshotTree = new UISnapshotTree(this); 623 { 624 /* Configure snapshot tree: */ 625 connect(m_pSnapshotTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 626 this, SLOT(sltCurrentItemChanged(QTreeWidgetItem *))); 627 connect(m_pSnapshotTree, SIGNAL(customContextMenuRequested(const QPoint &)), 628 this, SLOT(sltContextMenuRequested(const QPoint &))); 629 connect(m_pSnapshotTree, SIGNAL(itemChanged(QTreeWidgetItem *, int)), 630 this, SLOT(sltItemChanged(QTreeWidgetItem *))); 631 connect(m_pSnapshotTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), 632 this, SLOT(sltItemDoubleClicked(QTreeWidgetItem *))); 633 634 /* Add into layout: */ 635 pLayout->addWidget(m_pSnapshotTree); 636 } 637 } 638 639 /* Setup timer: */ 640 m_pTimerUpdateAge = new QTimer; 641 m_pTimerUpdateAge->setSingleShot(true); 642 connect(m_pTimerUpdateAge, SIGNAL(timeout()), this, SLOT(sltUpdateSnapshotsAge())); 643 644 /* Setup Main event connections: */ 645 connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), 646 this, SLOT(sltMachineDataChange(QString))); 647 connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)), 648 this, SLOT(sltMachineStateChange(QString, KMachineState))); 649 connect(gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)), 650 this, SLOT(sltSessionStateChange(QString, KSessionState))); 651 652 /* Translate finally: */ 653 retranslateUi(); 537 /* Prepare: */ 538 prepare(); 654 539 } 655 540 656 541 UISnapshotPane::~UISnapshotPane() 657 542 { 658 /* Stop timer if active: */ 659 if (m_pTimerUpdateAge->isActive()) 660 m_pTimerUpdateAge->stop(); 661 /* Destroy timer: */ 662 delete m_pTimerUpdateAge; 663 m_pTimerUpdateAge = 0; 664 665 /* Destroy icons: */ 666 delete m_pIconSnapshotOffline; 667 delete m_pIconSnapshotOnline; 668 m_pIconSnapshotOffline = 0; 669 m_pIconSnapshotOnline = 0; 670 671 /* Destroy read-write locker: */ 672 delete m_pLockReadWrite; 673 m_pLockReadWrite = 0; 543 /* Cleanup: */ 544 cleanup(); 674 545 } 675 546 … … 725 596 m_pActionShowSnapshotDetails->setStatusTip(tr("Display a window with selected snapshot details")); 726 597 m_pActionCloneSnapshot->setStatusTip(tr("Clone selected virtual machine")); 598 599 /* Translate toolbar: */ 600 #ifdef VBOX_WS_MAC 601 // WORKAROUND: 602 // There is a bug in Qt Cocoa which result in showing a "more arrow" when 603 // the necessary size of the toolbar is increased. Also for some languages 604 // the with doesn't match if the text increase. So manually adjust the size 605 // after changing the text. */ 606 if (m_pToolBar) 607 m_pToolBar->updateLayout(); 608 #endif 727 609 } 728 610 … … 921 803 } 922 804 805 void UISnapshotPane::prepare() 806 { 807 /* Configure Main event connections: */ 808 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange, 809 this, &UISnapshotPane::sltMachineDataChange); 810 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, 811 this, &UISnapshotPane::sltMachineStateChange); 812 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSessionStateChange, 813 this, &UISnapshotPane::sltSessionStateChange); 814 815 /* Create read-write locker: */ 816 m_pLockReadWrite = new QReadWriteLock; 817 818 /* Create pixmaps: */ 819 m_pIconSnapshotOffline = new QIcon(UIIconPool::iconSet(":/snapshot_offline_16px.png")); 820 m_pIconSnapshotOnline = new QIcon(UIIconPool::iconSet(":/snapshot_online_16px.png")); 821 822 /* Create timer: */ 823 m_pTimerUpdateAge = new QTimer; 824 AssertPtrReturnVoid(m_pTimerUpdateAge); 825 { 826 /* Configure timer: */ 827 m_pTimerUpdateAge->setSingleShot(true); 828 connect(m_pTimerUpdateAge, &QTimer::timeout, this, &UISnapshotPane::sltUpdateSnapshotsAge); 829 } 830 831 /* Prepare widgets: */ 832 prepareWidgets(); 833 834 /* Apply language settings: */ 835 retranslateUi(); 836 } 837 838 void UISnapshotPane::prepareWidgets() 839 { 840 /* Create layout: */ 841 new QVBoxLayout(this); 842 AssertPtrReturnVoid(layout()); 843 { 844 /* Configure layout: */ 845 layout()->setContentsMargins(0, 0, 0, 0); 846 #ifdef VBOX_WS_MAC 847 layout()->setSpacing(10); 848 #else 849 layout()->setSpacing(4); 850 #endif 851 852 /* Prepare toolbar: */ 853 prepareToolbar(); 854 /* Prepare tree-widget: */ 855 prepareTreeWidget(); 856 } 857 } 858 859 void UISnapshotPane::prepareToolbar() 860 { 861 /* Create snapshot toolbar: */ 862 m_pToolBar = new UIToolBar(this); 863 { 864 /* Configure toolbar: */ 865 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375); 866 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric)); 867 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 868 869 /* Add Take Snapshot action: */ 870 m_pActionTakeSnapshot = m_pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_take_22px.png", 871 ":/snapshot_take_16px.png", 872 ":/snapshot_take_disabled_22px.png", 873 ":/snapshot_take_disabled_16px.png"), 874 QString(), this, &UISnapshotPane::sltTakeSnapshot); 875 { 876 m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S")); 877 } 878 879 /* Add Delete Snapshot action: */ 880 m_pActionDeleteSnapshot = m_pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_delete_22px.png", 881 ":/snapshot_delete_16px.png", 882 ":/snapshot_delete_disabled_22px.png", 883 ":/snapshot_delete_disabled_16px.png"), 884 QString(), this, &UISnapshotPane::sltDeleteSnapshot); 885 { 886 m_pActionDeleteSnapshot->setShortcut(QString("Ctrl+Shift+D")); 887 } 888 889 m_pToolBar->addSeparator(); 890 891 /* Add Restore Snapshot action: */ 892 m_pActionRestoreSnapshot = m_pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_restore_22px.png", 893 ":/snapshot_restore_16px.png", 894 ":/snapshot_restore_disabled_22px.png", 895 ":/snapshot_restore_disabled_16px.png"), 896 QString(), this, &UISnapshotPane::sltRestoreSnapshot); 897 { 898 m_pActionRestoreSnapshot->setShortcut(QString("Ctrl+Shift+R")); 899 } 900 901 /* Add Show Snapshot Details action: */ 902 m_pActionShowSnapshotDetails = m_pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_show_details_22px.png", 903 ":/snapshot_show_details_16px.png", 904 ":/snapshot_show_details_disabled_22px.png", 905 ":/snapshot_details_show_disabled_16px.png"), 906 QString(), this, &UISnapshotPane::sltShowSnapshotDetails); 907 { 908 m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space")); 909 } 910 911 m_pToolBar->addSeparator(); 912 913 /* Add Clone Snapshot action: */ 914 m_pActionCloneSnapshot = m_pToolBar->addAction(UIIconPool::iconSetFull(":/vm_clone_22px.png", 915 ":/vm_clone_16px.png", 916 ":/vm_clone_disabled_22px.png", 917 ":/vm_clone_disabled_16px.png"), 918 QString(), this, &UISnapshotPane::sltCloneSnapshot); 919 { 920 m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C")); 921 } 922 923 /* Add into layout: */ 924 layout()->addWidget(m_pToolBar); 925 } 926 } 927 928 void UISnapshotPane::prepareTreeWidget() 929 { 930 /* Create snapshot tree: */ 931 m_pSnapshotTree = new UISnapshotTree(this); 932 { 933 /* Configure tree: */ 934 connect(m_pSnapshotTree, &UISnapshotTree::currentItemChanged, 935 this, &UISnapshotPane::sltCurrentItemChanged); 936 connect(m_pSnapshotTree, &UISnapshotTree::customContextMenuRequested, 937 this, &UISnapshotPane::sltContextMenuRequested); 938 connect(m_pSnapshotTree, &UISnapshotTree::itemChanged, 939 this, &UISnapshotPane::sltItemChanged); 940 connect(m_pSnapshotTree, &UISnapshotTree::itemDoubleClicked, 941 this, &UISnapshotPane::sltItemDoubleClicked); 942 943 /* Add into layout: */ 944 layout()->addWidget(m_pSnapshotTree); 945 } 946 } 947 948 void UISnapshotPane::cleanup() 949 { 950 /* Stop timer if active: */ 951 if (m_pTimerUpdateAge->isActive()) 952 m_pTimerUpdateAge->stop(); 953 /* Destroy timer: */ 954 delete m_pTimerUpdateAge; 955 m_pTimerUpdateAge = 0; 956 957 /* Destroy icons: */ 958 delete m_pIconSnapshotOffline; 959 delete m_pIconSnapshotOnline; 960 m_pIconSnapshotOffline = 0; 961 m_pIconSnapshotOnline = 0; 962 963 /* Destroy read-write locker: */ 964 delete m_pLockReadWrite; 965 m_pLockReadWrite = 0; 966 } 967 923 968 bool UISnapshotPane::takeSnapshot() 924 969 { -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r67119 r67120 34 34 class UISnapshotTree; 35 35 class UISnapshotItem; 36 class UIToolBar; 36 37 37 38 … … 116 117 private: 117 118 119 /** @name Prepare/cleanup cascade. 120 * @{ */ 121 /** Prepares all. */ 122 void prepare(); 123 /** Prepares widgets. */ 124 void prepareWidgets(); 125 /** Prepares toolbar. */ 126 void prepareToolbar(); 127 /** Prepares tree-widget. */ 128 void prepareTreeWidget(); 129 130 /** Refreshes everything. */ 131 void refreshAll(); 132 /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */ 133 void populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem); 134 135 /** Cleanups all. */ 136 void cleanup(); 137 /** @} */ 138 118 139 /** @name Toolbar helpers. 119 140 * @{ */ … … 130 151 /** @} */ 131 152 132 /** Refreshes everything. */133 void refreshAll();134 /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */135 void populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem);136 137 153 /** @name Tree-widget helpers. 138 154 * @{ */ … … 162 178 /** @name Widget variables. 163 179 * @{ */ 180 /** Holds the toolbar instance. */ 181 UIToolBar *m_pToolBar; 164 182 /** Holds the Take Snapshot action instance. */ 165 183 QAction *m_pActionTakeSnapshot;
Note:
See TracChangeset
for help on using the changeset viewer.