Changeset 88658 in vbox
- Timestamp:
- Apr 22, 2021 3:25:31 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/logviewer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
r88647 r88658 17 17 18 18 /* Qt includes: */ 19 #include <QCheckBox> 19 20 #include <QDateTime> 20 21 #include <QDir> … … 55 56 const ULONG uAllowedLogSize = _256M; 56 57 58 class UIMachineListCheckBox : public QCheckBox 59 { 60 61 Q_OBJECT; 62 63 public: 64 65 UIMachineListCheckBox(const QString &strText, QWidget *pParent = 0); 66 void setId(const QUuid &id); 67 const QUuid &id() const; 68 private: 69 QUuid m_id; 70 }; 71 72 UIMachineListCheckBox::UIMachineListCheckBox(const QString &strText, QWidget *pParent /* = 0 */) 73 :QCheckBox(strText, pParent) 74 { 75 } 76 77 void UIMachineListCheckBox::setId(const QUuid &id) 78 { 79 m_id = id; 80 } 81 82 const QUuid &UIMachineListCheckBox::id() const 83 { 84 return m_id; 85 } 86 57 87 class UIMachineListMenu : public QWidget 58 88 { … … 65 95 /** Removes the actions and deletes them. */ 66 96 void clear(); 67 QAction *addAction(const QString &strText); 97 void addListItem(const QString &strText, const QUuid &id); 98 99 private: 100 101 void computeMinimumSize(); 102 QVector<UIMachineListCheckBox*> m_checkboxes; 103 QVBoxLayout *m_pLayout; 68 104 }; 69 105 70 106 UIMachineListMenu::UIMachineListMenu(QWidget *pParent /* = 0 */) 71 107 :QWidget(pParent) 72 { 108 , m_pLayout(0) 109 { 110 m_pLayout = new QVBoxLayout(this); 73 111 } 74 112 75 113 void UIMachineListMenu::clear() 76 114 { 77 QList<QAction*> actionList = actions(); 78 for (int i = 0; i < actionList.size(); ++i) 79 { 80 removeAction(actionList[i]); 81 delete actionList[i]; 82 } 83 } 84 85 QAction *UIMachineListMenu::addAction(const QString &strText) 86 { 87 QAction *pAction = new QAction(strText, this); 88 QWidget::addAction(pAction); 89 return pAction; 90 } 115 qDeleteAll(m_checkboxes.begin(), m_checkboxes.end()); 116 m_checkboxes.clear(); 117 } 118 119 void UIMachineListMenu::addListItem(const QString &strText, const QUuid &id) 120 { 121 UIMachineListCheckBox *pCheckBox = new UIMachineListCheckBox(strText, this); 122 m_checkboxes << pCheckBox; 123 pCheckBox->setId(id); 124 m_pLayout->addWidget(pCheckBox); 125 computeMinimumSize(); 126 } 127 128 void UIMachineListMenu::computeMinimumSize() 129 { 130 int iMaxTextLen = 0; 131 foreach(const UIMachineListCheckBox *pCheckBox, m_checkboxes) 132 { 133 if (!pCheckBox) 134 continue; 135 //iMaxTextLen = qMax(iMaxTextLen, fontMetrics().horizontalAdvance(pCheckBox->text())); 136 iMaxTextLen = qMax(iMaxTextLen, pCheckBox->width()); 137 } 138 int iWidth = iMaxTextLen + 2 * qApp->style()->pixelMetric(QStyle::PM_ButtonIconSize); 139 int iHeight = m_checkboxes.size() * fontMetrics().height() + 140 qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) + 141 qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin); 142 //printf("%d %d\n", iWidth, iHeight); 143 setMinimumSize(iWidth, iHeight); 144 update(); 145 } 146 91 147 92 148 UIVMLogViewerWidget::Machine::Machine(const QUuid &id, const QString &strName) … … 192 248 } 193 249 250 void UIVMLogViewerWidget::resizeEvent(QResizeEvent *pEvent) 251 { 252 QIWithRetranslateUI<QWidget>::resizeEvent(pEvent); 253 if (m_pMachineSelectionMenu) 254 m_pMachineSelectionMenu->move(0, 40); 255 } 256 194 257 void UIVMLogViewerWidget::sltRefresh() 195 258 { … … 486 549 void UIVMLogViewerWidget::sltCornerButtonToggled(bool fToggle) 487 550 { 488 printf("%d\n", fToggle); 551 if (m_pMachineSelectionMenu) 552 m_pMachineSelectionMenu->setVisible(fToggle); 489 553 } 490 554 … … 561 625 if (m_pCornerButton) 562 626 { 563 m_pTabWidget->setCornerWidget(m_pCornerButton, Qt::TopLeftCorner); 627 m_pTabWidget->setCornerWidget(m_pCornerButton);//, Qt::TopLeftCorner); 628 m_pCornerButton->setCheckable(true); 564 629 m_pCornerButton->setIcon(UIIconPool::iconSet(":/machine_16px.png")); 565 630 m_pCornerButton->setCheckable(true); 566 631 m_pMachineSelectionMenu = new UIMachineListMenu(this); 632 m_pMachineSelectionMenu->setAutoFillBackground(true); 633 m_pMachineSelectionMenu->setVisible(false); 567 634 connect(m_pCornerButton, &QIToolButton::toggled, this, &UIVMLogViewerWidget::sltCornerButtonToggled); 568 635 //m_pCornerButton->setMenu(m_pMachineSelectionMenu); … … 1008 1075 foreach (const Machine &machine, m_machines) 1009 1076 { 1010 QAction *pAction = m_pMachineSelectionMenu->addAction(machine.m_strName); 1011 pAction->setCheckable(true); 1012 pAction->setData(machine.m_id); 1077 1078 m_pMachineSelectionMenu->addListItem(machine.m_strName, machine.m_id); 1013 1079 } 1014 1080 } -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h
r88647 r88658 95 95 /** Returns whether the window should be maximized when geometry being restored. */ 96 96 virtual bool shouldBeMaximized() const /* override */; 97 void resizeEvent(QResizeEvent *pEvent) /* override */; 97 98 98 99 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.