Changeset 68722 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Sep 12, 2017 11:45:58 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117954
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotDetailsWidget.cpp
r68490 r68722 30 30 # include <QPushButton> 31 31 # include <QScrollArea> 32 # include <QStackedLayout>33 32 # include <QTabWidget> 34 33 # include <QTextBrowser> … … 515 514 UISnapshotDetailsWidget::UISnapshotDetailsWidget(QWidget *pParent /* = 0 */) 516 515 : QIWithRetranslateUI<QWidget>(pParent) 517 , m_pStackedLayout(0)518 , m_pEmptyWidget(0)519 , m_pEmptyWidgetLabel(0)520 516 , m_pTabWidget(0) 521 517 , m_pLayoutOptions(0) … … 525 521 , m_pLayoutDetails(0) 526 522 , m_pScrollAreaDetails(0) 523 , m_fSnapshotNameEdited(false) 527 524 { 528 525 /* Prepare: */ … … 530 527 } 531 528 529 void UISnapshotDetailsWidget::setData(const CMachine &comMachine) 530 { 531 /* Reset defaults: */ 532 m_fSnapshotNameEdited = false; 533 534 /* Cache old/new data: */ 535 m_oldData = UIDataSnapshot(); 536 m_newData = m_oldData; 537 538 /* Cache machine/snapshot: */ 539 m_comMachine = comMachine; 540 m_comSnapshot = CSnapshot(); 541 542 /* Retranslate buttons: */ 543 retranslateButtons(); 544 /* Load snapshot data: */ 545 loadSnapshotData(); 546 } 547 532 548 void UISnapshotDetailsWidget::setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot) 533 549 { 550 /* Reset defaults: */ 551 m_fSnapshotNameEdited = false; 552 534 553 /* Cache old/new data: */ 535 554 m_oldData = data; 536 555 m_newData = m_oldData; 537 556 538 /* Cache snapshot: */ 557 /* Cache machine/snapshot: */ 558 m_comMachine = CMachine(); 539 559 m_comSnapshot = comSnapshot; 540 560 561 /* Retranslate buttons: */ 562 retranslateButtons(); 541 563 /* Load snapshot data: */ 542 564 loadSnapshotData(); … … 545 567 void UISnapshotDetailsWidget::clearData() 546 568 { 569 /* Reset defaults: */ 570 m_fSnapshotNameEdited = false; 571 547 572 /* Reset old/new data: */ 548 573 m_oldData = UIDataSnapshot(); 549 574 m_newData = m_oldData; 550 575 551 /* Reset snapshot: */ 576 /* Reset machine/snapshot: */ 577 m_comMachine = CMachine(); 552 578 m_comSnapshot = CSnapshot(); 553 579 580 /* Retranslate buttons: */ 581 retranslateButtons(); 554 582 /* Load snapshot data: */ 555 583 loadSnapshotData(); … … 559 587 { 560 588 /* Translate labels: */ 561 m_pEmptyWidgetLabel->setText(tr("<p>You have the <b>Current State</b> item selected.<br>"562 "Press the <b>Take</b> button if you wish to take a new snapshot.</p>"));563 589 m_pTabWidget->setTabText(0, tr("&Attributes")); 564 590 m_pTabWidget->setTabText(1, tr("&Information")); … … 567 593 m_pEditorName->setToolTip(tr("Holds the snapshot name.")); 568 594 m_pBrowserDescription->setToolTip(tr("Holds the snapshot description.")); 569 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Apply")); 570 m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Reset")); 595 596 /* Translate placeholders: */ 597 m_pEditorName->setPlaceholderText( m_comMachine.isNotNull() 598 ? tr("Enter a name for the new snapshot...") 599 : m_comSnapshot.isNotNull() 600 ? tr("Enter a name for this snapshot...") 601 : QString()); 602 603 /* Translate buttons: */ 571 604 m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return")); 572 605 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape); 573 m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Apply changes in current snapshot details")); 574 m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Reset changes in current snapshot details")); 575 m_pButtonBox->button(QDialogButtonBox::Ok)-> 576 setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString())); 577 m_pButtonBox->button(QDialogButtonBox::Cancel)-> 578 setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString())); 579 580 /* And if snapshot is valid: */ 581 if (!m_comSnapshot.isNull()) 582 { 583 /* Get the machine: */ 584 const CMachine comMachine = m_comSnapshot.GetMachine(); 585 586 /* Update the picture tool-tip and visibility: */ 587 m_details.value(DetailsElementType_Preview)->setToolTip(tr("Click to enlarge the screenshot.")); 588 if (!m_pixmapScreenshot.isNull() && m_details.value(DetailsElementType_Preview)->isHidden()) 589 m_details.value(DetailsElementType_Preview)->setHidden(false); 590 else if (m_pixmapScreenshot.isNull() && !m_details.value(DetailsElementType_Preview)->isHidden()) 591 m_details.value(DetailsElementType_Preview)->setHidden(true); 592 606 retranslateButtons(); 607 608 /* Update the picture tool-tip and visibility: */ 609 m_details.value(DetailsElementType_Preview)->setToolTip(tr("Click to enlarge the screenshot.")); 610 if (!m_pixmapScreenshot.isNull() && m_details.value(DetailsElementType_Preview)->isHidden()) 611 m_details.value(DetailsElementType_Preview)->setHidden(false); 612 else if (m_pixmapScreenshot.isNull() && !m_details.value(DetailsElementType_Preview)->isHidden()) 613 m_details.value(DetailsElementType_Preview)->setHidden(true); 614 615 /* Prepare machine: */ 616 const CMachine &comMachine = m_comMachine.isNotNull() 617 ? m_comMachine 618 : m_comSnapshot.isNotNull() 619 ? m_comSnapshot.GetMachine() 620 : CMachine(); 621 622 /* Make sure machine is valid: */ 623 if (comMachine.isNotNull()) 624 { 593 625 /* Update USB details visibility: */ 594 626 const CUSBDeviceFilters &comFilters = comMachine.GetUSBDeviceFilters(); … … 601 633 m_details.value(enmType)->setText(detailsReport(comMachine, enmType)); 602 634 } 603 else604 {605 /* Clear the details report: */606 // WORKAROUND:607 // How stupid Qt *is* to wipe out registered icons not just on clear()608 // call but on setText(QString()) and even setText("") as well.609 // Nice way to oversmart itself..610 foreach (const DetailsElementType &enmType, m_details.keys())611 m_details.value(enmType)->setText("<empty>");612 }613 635 614 636 /* Retranslate validation: */ 615 637 retranslateValidation(); 638 } 639 640 void UISnapshotDetailsWidget::retranslateButtons() 641 { 642 /* Common: 'Reset' button: */ 643 m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Reset")); 644 m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Reset changes in current snapshot details")); 645 m_pButtonBox->button(QDialogButtonBox::Cancel)-> 646 setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString())); 647 /* Common: 'Apply' button: */ 648 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Apply")); 649 m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Apply changes in current snapshot details")); 650 m_pButtonBox->button(QDialogButtonBox::Ok)-> 651 setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString())); 652 653 if (m_comMachine.isNotNull()) 654 { 655 /* Machine: 'Take' button: */ 656 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Take")); 657 m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Take snapshot on the basis of current machine state")); 658 m_pButtonBox->button(QDialogButtonBox::Ok)-> 659 setToolTip(tr("Take Snapshot (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString())); 660 } 661 } 662 663 void UISnapshotDetailsWidget::sltHandleNameEdit() 664 { 665 m_fSnapshotNameEdited = true; 616 666 } 617 667 … … 667 717 void UISnapshotDetailsWidget::prepare() 668 718 { 669 /* Create stacked layout: */ 670 m_pStackedLayout = new QStackedLayout(this); 671 AssertPtrReturnVoid(m_pStackedLayout); 672 { 673 /* Prepare empty-widget: */ 674 prepareEmptyWidget(); 675 /* Prepare tab-widget: */ 676 prepareTabWidget(); 677 } 678 } 679 680 void UISnapshotDetailsWidget::prepareEmptyWidget() 681 { 682 /* Create empty-widget: */ 683 m_pEmptyWidget = new QWidget; 684 AssertPtrReturnVoid(m_pEmptyWidget); 685 { 686 /* Create empty-widget layout: */ 687 new QVBoxLayout(m_pEmptyWidget); 688 AssertPtrReturnVoid(m_pEmptyWidget->layout()); 719 /* Create layout: */ 720 QVBoxLayout *pLayout = new QVBoxLayout(this); 721 AssertPtrReturnVoid(pLayout); 722 { 723 /* Configure layout: */ 724 pLayout->setContentsMargins(0, 0, 0, 0); 725 726 /* Create tab-widget: */ 727 m_pTabWidget = new QTabWidget; 728 AssertPtrReturnVoid(m_pTabWidget); 689 729 { 690 /* Create empty-widget label: */ 691 m_pEmptyWidgetLabel = new QLabel; 692 { 693 /* Configure label: */ 694 QFont font = m_pEmptyWidgetLabel->font(); 695 font.setPointSize(font.pointSize() * 1.5); 696 m_pEmptyWidgetLabel->setAlignment(Qt::AlignCenter); 697 m_pEmptyWidgetLabel->setFont(font); 698 699 /* Add into layout: */ 700 m_pEmptyWidget->layout()->addWidget(m_pEmptyWidgetLabel); 701 } 730 /* Prepare 'Options' tab: */ 731 prepareTabOptions(); 732 /* Prepare 'Details' tab: */ 733 prepareTabDetails(); 734 735 /* Add into layout: */ 736 pLayout->addWidget(m_pTabWidget); 702 737 } 703 704 /* Add into layout: */705 m_pStackedLayout->addWidget(m_pEmptyWidget);706 }707 }708 709 void UISnapshotDetailsWidget::prepareTabWidget()710 {711 /* Create tab-widget: */712 m_pTabWidget = new QTabWidget;713 AssertPtrReturnVoid(m_pTabWidget);714 {715 /* Prepare 'Options' tab: */716 prepareTabOptions();717 /* Prepare 'Details' tab: */718 prepareTabDetails();719 720 /* Add into layout: */721 m_pStackedLayout->addWidget(m_pTabWidget);722 738 } 723 739 } … … 765 781 policy.setHorizontalStretch(1); 766 782 m_pEditorName->setSizePolicy(policy); 783 connect(m_pEditorName, &QLineEdit::textEdited, 784 this, &UISnapshotDetailsWidget::sltHandleNameEdit); 767 785 connect(m_pEditorName, &QLineEdit::textChanged, 768 786 this, &UISnapshotDetailsWidget::sltHandleNameChange); … … 1025 1043 m_pEditorName->setText(m_newData.m_strName); 1026 1044 m_pBrowserDescription->setText(m_newData.m_strDescription); 1027 1045 revalidate(); 1046 1047 /* If there is a machine: */ 1048 if (m_comMachine.isNotNull()) 1049 { 1050 /* No screenshot: */ 1051 m_pixmapScreenshot = QPixmap(); 1052 } 1028 1053 /* If there is a snapshot: */ 1029 if (m_comSnapshot.isNotNull()) 1030 { 1031 /* Choose the tab-widget as current one: */ 1032 m_pStackedLayout->setCurrentWidget(m_pTabWidget); 1033 1054 else if (m_comSnapshot.isNotNull()) 1055 { 1034 1056 /* Read snapshot display contents: */ 1035 1057 CMachine comMachine = m_comSnapshot.GetMachine(); … … 1054 1076 QTextDocument::ImageResource, QUrl("details://thumbnail"), QVariant(pixThumbnail)); 1055 1077 } 1056 else1057 {1058 /* Choose the empty-widget as current one: */1059 m_pStackedLayout->setCurrentWidget(m_pEmptyWidget);1060 }1061 1078 1062 1079 /* Retranslate: */ … … 1072 1089 { 1073 1090 const bool fError = m_newData.m_strName.isEmpty(); 1074 m_pErrorPaneName->setVisible(fError );1091 m_pErrorPaneName->setVisible(fError && m_fSnapshotNameEdited); 1075 1092 } 1076 1093 if (!pWidget || pWidget == m_pErrorPaneDescription) -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotDetailsWidget.h
r68365 r68722 27 27 28 28 /* COM includes: */ 29 #include "COMEnums.h" 30 #include "CMachine.h" 29 31 #include "CSnapshot.h" 30 32 … … 35 37 class QLineEdit; 36 38 class QScrollArea; 37 class QStackedLayout;38 39 class QTabWidget; 39 40 class QTextEdit; … … 91 92 /** Returns the snapshot data. */ 92 93 const UIDataSnapshot &data() const { return m_newData; } 93 /** Defines the snapshot @a data. */ 94 /** Defines the @a comMachine. */ 95 void setData(const CMachine &comMachine); 96 /** Defines the @a comSnapshot and it's @a data. */ 94 97 void setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot); 95 98 /** Clears the snapshot data. */ … … 100 103 /** Handles translation event. */ 101 104 virtual void retranslateUi() /* override */; 105 /** Handles buttons translation. */ 106 void retranslateButtons(); 102 107 103 108 private slots: 104 109 110 /** Handles snapshot name edit. */ 111 void sltHandleNameEdit(); 105 112 /** Handles snapshot name change. */ 106 113 void sltHandleNameChange(); … … 120 127 /** Prepares all. */ 121 128 void prepare(); 122 /** Prepares empty-widget. */123 void prepareEmptyWidget();124 129 /** Prepares tab-widget. */ 125 130 void prepareTabWidget(); … … 148 153 static QString summarizeGenericProperties(const CNetworkAdapter &adapter); 149 154 155 /** Holds the machine object to load data from. */ 156 CMachine m_comMachine; 150 157 /** Holds the snapshot object to load data from. */ 151 158 CSnapshot m_comSnapshot; … … 158 165 /** Holds the cached screenshot. */ 159 166 QPixmap m_pixmapScreenshot; 160 161 /** Holds the stacked layout instance. */162 QStackedLayout *m_pStackedLayout;163 164 /** Holds the empty-widget instance. */165 QWidget *m_pEmptyWidget;166 /** Holds the empty-widget label instance. */167 QLabel *m_pEmptyWidgetLabel;168 167 169 168 /** Holds the tab-widget instance. */ … … 198 197 /** Holds the details element map. */ 199 198 QMap<DetailsElementType, UISnapshotDetailsElement*> m_details; 199 200 /** Holds whether the snapshot name was edited. */ 201 bool m_fSnapshotNameEdited; 200 202 }; 201 203 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r68721 r68722 917 917 if (m_pDetailsWidget->isVisible()) 918 918 { 919 /* Acquire "current snapshot"item: */919 /* Acquire selected item: */ 920 920 const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); 921 AssertPtrReturnVoid(pSnapshotItem); 921 922 /* Update details-widget: */ 922 m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot()); 923 if (pSnapshotItem->isCurrentStateItem()) 924 m_pDetailsWidget->setData(m_comMachine); 925 else 926 m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot()); 923 927 } 924 928 } … … 930 934 AssertPtrReturnVoid(pSnapshotItem); 931 935 936 /* For current state item: */ 937 if (pSnapshotItem->isCurrentStateItem()) 938 { 939 /* Get item data: */ 940 UIDataSnapshot newData = m_pDetailsWidget->data(); 941 942 /* Open a session (this call will handle all errors): */ 943 CSession comSession; 944 if (m_enmSessionState != KSessionState_Unlocked) 945 comSession = vboxGlobal().openExistingSession(m_strMachineId); 946 else 947 comSession = vboxGlobal().openSession(m_strMachineId); 948 if (comSession.isNotNull()) 949 { 950 /* Get corresponding machine object: */ 951 CMachine comMachine = comSession.GetMachine(); 952 953 /* Perform separate linked steps: */ 954 do 955 { 956 /* Take snapshot: */ 957 QString strSnapshotId; 958 CProgress comProgress = comMachine.TakeSnapshot(newData.m_strName, 959 newData.m_strDescription, 960 true, strSnapshotId); 961 if (!comMachine.isOk()) 962 { 963 msgCenter().cannotTakeSnapshot(comMachine, comMachine.GetName()); 964 break; 965 } 966 967 /* Show snapshot taking progress: */ 968 msgCenter().showModalProgressDialog(comProgress, comMachine.GetName(), 969 ":/progress_snapshot_create_90px.png"); 970 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 971 { 972 msgCenter().cannotTakeSnapshot(comProgress, comMachine.GetName()); 973 break; 974 } 975 } 976 while (0); 977 978 /* Cleanup session: */ 979 comSession.UnlockMachine(); 980 } 981 } 932 982 /* For snapshot items: */ 933 if (!pSnapshotItem->isCurrentStateItem())983 else 934 984 { 935 985 /* Make sure nothing being edited in the meantime: */ … … 1014 1064 /* Update details-widget if it's visible: */ 1015 1065 if (pSnapshotItem && m_pDetailsWidget->isVisible()) 1016 m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot()); 1066 { 1067 if (pSnapshotItem->isCurrentStateItem()) 1068 m_pDetailsWidget->setData(m_comMachine); 1069 else 1070 m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot()); 1071 } 1017 1072 } 1018 1073
Note:
See TracChangeset
for help on using the changeset viewer.