Changeset 88816 in vbox
- Timestamp:
- May 3, 2021 10:01:31 AM (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
r88815 r88816 60 60 const ULONG uAllowedLogSize = _256M; 61 61 62 /********************************************************************************************************************************* 63 * UITabBar definition. * 64 *********************************************************************************************************************************/ 65 62 66 class UITabBar : public QTabBar 63 67 { 68 64 69 Q_OBJECT; 70 65 71 public: 66 UITabBar(QWidget *pParent = 0) 67 :QTabBar(pParent) 68 { 69 QStyleOptionTab opt; 70 m_alternateColors << opt.palette.color(QPalette::Button).lighter(125); 71 m_alternateColors << opt.palette.color(QPalette::Button).darker(125); 72 } 73 74 void paintEvent(QPaintEvent * /*event*/) { 75 76 QStylePainter painter(this); 77 QStyleOptionTab opt; 78 79 for (int i = 0; i < count(); i++) { 80 initStyleOption(&opt, i); 81 int iColorIndex = tabData(i).toInt(); 82 if (iColorIndex >= 0 && iColorIndex <= m_alternateColors.size()) 83 { 84 opt.palette.setColor(QPalette::Button, m_alternateColors[iColorIndex]); 85 } 86 87 painter.drawControl(QStyle::CE_TabBarTabShape, opt); 88 painter.drawControl(QStyle::CE_TabBarTabLabel, opt); 89 } 90 } 72 73 UITabBar(QWidget *pParent = 0); 74 protected: 75 76 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 77 91 78 private: 79 92 80 QVector<QColor> m_alternateColors; 93 81 }; 94 82 95 class UITabWidget : public QTabWidget 96 { 83 /********************************************************************************************************************************* 84 * UITabWidget definition. * 85 *********************************************************************************************************************************/ 86 87 class UITabWidget : public QITabWidget 88 { 89 97 90 Q_OBJECT; 91 98 92 public: 99 UITabWidget(QWidget *pParent = 0) 100 :QTabWidget(pParent) 101 { 102 setTabBar(new UITabBar(this)); 103 } 93 94 UITabWidget(QWidget *pParent = 0); 104 95 }; 105 96 106 class UIMachineListCheckBox : public QCheckBox 107 { 108 109 Q_OBJECT; 110 111 public: 112 113 UIMachineListCheckBox(const QString &strText, QWidget *pParent = 0); 114 void setId(const QUuid &id); 115 const QUuid &id() const; 116 private: 117 QUuid m_id; 118 }; 119 120 UIMachineListCheckBox::UIMachineListCheckBox(const QString &strText, QWidget *pParent /* = 0 */) 121 :QCheckBox(strText, pParent) 122 { 123 } 124 125 void UIMachineListCheckBox::setId(const QUuid &id) 126 { 127 m_id = id; 128 } 129 130 const QUuid &UIMachineListCheckBox::id() const 131 { 132 return m_id; 133 } 134 135 class UIMachineListMenu : public QWidget 136 { 137 138 Q_OBJECT; 139 140 public: 141 142 UIMachineListMenu(QWidget *pParent = 0); 143 /** Removes the actions and deletes them. */ 144 void clear(); 145 void addListItem(const QString &strText, const QUuid &id); 146 147 private: 148 149 void computeMinimumSize(); 150 QVector<UIMachineListCheckBox*> m_checkboxes; 151 QVBoxLayout *m_pLayout; 152 }; 153 154 UIMachineListMenu::UIMachineListMenu(QWidget *pParent /* = 0 */) 155 :QWidget(pParent, Qt::Popup) 156 , m_pLayout(0) 157 { 158 m_pLayout = new QVBoxLayout(this); 159 if (m_pLayout) 160 { 161 /* Configure layout: */ 162 const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 2; 163 const int iT = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) / 2; 164 const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) / 2; 165 const int iB = qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) / 2; 166 m_pLayout->setContentsMargins(iL, iT, iR, iB); 167 } 168 } 169 170 void UIMachineListMenu::clear() 171 { 172 qDeleteAll(m_checkboxes.begin(), m_checkboxes.end()); 173 m_checkboxes.clear(); 174 } 175 176 void UIMachineListMenu::addListItem(const QString &strText, const QUuid &id) 177 { 178 UIMachineListCheckBox *pCheckBox = new UIMachineListCheckBox(strText, this); 179 m_checkboxes << pCheckBox; 180 pCheckBox->setId(id); 181 m_pLayout->addWidget(pCheckBox); 182 } 97 /********************************************************************************************************************************* 98 * UITabBar implementation. * 99 *********************************************************************************************************************************/ 100 101 UITabBar::UITabBar(QWidget *pParent /* = 0 */) 102 :QTabBar(pParent) 103 { 104 QStyleOptionTab opt; 105 m_alternateColors << opt.palette.color(QPalette::Button).lighter(135); 106 m_alternateColors << opt.palette.color(QPalette::Button).darker(135); 107 } 108 109 void UITabBar::paintEvent(QPaintEvent *pEvent) 110 { 111 Q_UNUSED(pEvent); 112 QStylePainter painter(this); 113 QStyleOptionTab opt; 114 115 for (int i = 0; i < count(); i++) { 116 initStyleOption(&opt, i); 117 int iColorIndex = tabData(i).toInt(); 118 if (iColorIndex >= 0 && iColorIndex <= m_alternateColors.size()) 119 { 120 opt.palette.setColor(QPalette::Button, m_alternateColors[iColorIndex]); 121 } 122 123 painter.drawControl(QStyle::CE_TabBarTabShape, opt); 124 painter.drawControl(QStyle::CE_TabBarTabLabel, opt); 125 } 126 } 127 128 /********************************************************************************************************************************* 129 * UITabWidget implementation. * 130 *********************************************************************************************************************************/ 131 132 UITabWidget::UITabWidget(QWidget *pParent /* = 0 */) 133 :QITabWidget(pParent) 134 { 135 setTabBar(new UITabBar(this)); 136 } 137 138 139 /********************************************************************************************************************************* 140 * UIVMLogViewerWidget implementation. * 141 *********************************************************************************************************************************/ 183 142 184 143 UIVMLogViewerWidget::UIVMLogViewerWidget(EmbedTo enmEmbedding, … … 372 331 void UIVMLogViewerWidget::sltSave() 373 332 { 374 // if (m_comMachine.isNull()) 375 // return; 376 377 // UIVMLogPage *logPage = currentLogPage(); 378 // if (!logPage) 379 // return; 380 381 // const QString& fileName = logPage->logFileName(); 382 // if (fileName.isEmpty()) 383 // return; 384 // /* Prepare "save as" dialog: */ 385 // const QFileInfo fileInfo(fileName); 386 // /* Prepare default filename: */ 387 // const QDateTime dtInfo = fileInfo.lastModified(); 388 // const QString strDtString = dtInfo.toString("yyyy-MM-dd-hh-mm-ss"); 389 // const QString strDefaultFileName = QString("%1-%2.log").arg(m_comMachine.GetName()).arg(strDtString); 390 // const QString strDefaultFullName = QDir::toNativeSeparators(QDir::home().absolutePath() + "/" + strDefaultFileName); 391 392 // const QString strNewFileName = QIFileDialog::getSaveFileName(strDefaultFullName, 393 // "", 394 // this, 395 // tr("Save VirtualBox Log As"), 396 // 0 /* selected filter */, 397 // true /* resolve symlinks */, 398 // true /* confirm overwrite */); 399 // /* Make sure file-name is not empty: */ 400 // if (!strNewFileName.isEmpty()) 401 // { 402 // /* Delete the previous file if already exists as user already confirmed: */ 403 // if (QFile::exists(strNewFileName)) 404 // QFile::remove(strNewFileName); 405 // /* Copy log into the file: */ 406 // QFile::copy(m_comMachine.QueryLogFilename(m_pTabWidget->currentIndex()), strNewFileName); 407 // } 333 UIVMLogPage *pLogPage = currentLogPage(); 334 if (!pLogPage) 335 return; 336 337 CMachine comMachine = uiCommon().virtualBox().FindMachine(pLogPage->machineId().toString()); 338 if (comMachine.isNull()) 339 return; 340 341 const QString& fileName = pLogPage->logFileName(); 342 if (fileName.isEmpty()) 343 return; 344 /* Prepare "save as" dialog: */ 345 const QFileInfo fileInfo(fileName); 346 /* Prepare default filename: */ 347 const QDateTime dtInfo = fileInfo.lastModified(); 348 const QString strDtString = dtInfo.toString("yyyy-MM-dd-hh-mm-ss"); 349 const QString strDefaultFileName = QString("%1-%2.log").arg(comMachine.GetName()).arg(strDtString); 350 const QString strDefaultFullName = QDir::toNativeSeparators(QDir::home().absolutePath() + "/" + strDefaultFileName); 351 352 const QString strNewFileName = QIFileDialog::getSaveFileName(strDefaultFullName, 353 "", 354 this, 355 tr("Save VirtualBox Log As"), 356 0 /* selected filter */, 357 true /* resolve symlinks */, 358 true /* confirm overwrite */); 359 /* Make sure file-name is not empty: */ 360 if (!strNewFileName.isEmpty()) 361 { 362 /* Delete the previous file if already exists as user already confirmed: */ 363 if (QFile::exists(strNewFileName)) 364 QFile::remove(strNewFileName); 365 /* Copy log into the file: */ 366 QFile::copy(comMachine.QueryLogFilename(m_pTabWidget->currentIndex()), strNewFileName); 367 } 408 368 } 409 369 410 370 void UIVMLogViewerWidget::sltDeleteBookmark(int index) 411 371 { 412 UIVMLogPage* logPage = currentLogPage();413 if (! logPage)414 return; 415 logPage->deleteBookmark(index);372 UIVMLogPage* pLogPage = currentLogPage(); 373 if (!pLogPage) 374 return; 375 pLogPage->deleteBookmark(index); 416 376 if (m_pBookmarksPanel) 417 m_pBookmarksPanel->updateBookmarkList( logPage->bookmarkVector());377 m_pBookmarksPanel->updateBookmarkList(pLogPage->bookmarkVector()); 418 378 } 419 379 420 380 void UIVMLogViewerWidget::sltDeleteAllBookmarks() 421 381 { 422 UIVMLogPage* logPage = currentLogPage();423 if (! logPage)424 return; 425 logPage->deleteAllBookmarks();382 UIVMLogPage* pLogPage = currentLogPage(); 383 if (!pLogPage) 384 return; 385 pLogPage->deleteAllBookmarks(); 426 386 427 387 if (m_pBookmarksPanel) 428 m_pBookmarksPanel->updateBookmarkList( logPage->bookmarkVector());388 m_pBookmarksPanel->updateBookmarkList(pLogPage->bookmarkVector()); 429 389 } 430 390 … … 583 543 m_pOptionsPanel->setWrapLines(false); 584 544 m_pOptionsPanel->setFontSizeInPoints(m_font.pointSize()); 585 }586 }587 588 void UIVMLogViewerWidget::sltCornerButtonClicked()589 {590 if (m_pMachineSelectionMenu && m_pCornerButton)591 {592 m_pMachineSelectionMenu->adjustSize();593 m_pMachineSelectionMenu->move(m_pCornerButton->mapToGlobal(QPoint(-m_pMachineSelectionMenu->width(), 0)));594 m_pMachineSelectionMenu->show();595 545 } 596 546 } … … 664 614 m_pMainLayout->addWidget(m_pTabWidget); 665 615 connect(m_pTabWidget, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltCurrentTabChanged); 666 #if 0667 m_pCornerButton = new QIToolButton(m_pTabWidget);668 #endif669 if (m_pCornerButton)670 {671 m_pTabWidget->setCornerWidget(m_pCornerButton);//, Qt::TopLeftCorner);672 m_pCornerButton->setIcon(UIIconPool::iconSet(":/machine_16px.png"));673 m_pMachineSelectionMenu = new UIMachineListMenu(this);674 connect(m_pCornerButton, &QIToolButton::clicked, this, &UIVMLogViewerWidget::sltCornerButtonClicked);675 }676 677 616 } 678 617 … … 1096 1035 } 1097 1036 1098 void UIVMLogViewerWidget::updateMachineSelectionMenu()1099 {1100 if (!m_pMachineSelectionMenu)1101 return;1102 m_pMachineSelectionMenu->clear();1103 1104 // foreach (const Machine &machine, m_machines)1105 // {1106 1107 // m_pMachineSelectionMenu->addListItem(machine.m_strName, machine.m_id);1108 // }1109 }1110 1111 1037 #include "UIVMLogViewerWidget.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h
r88815 r88816 137 137 void sltResetOptionsToDefault(); 138 138 /** @} */ 139 void sltCornerButtonClicked(); 139 140 140 private: 141 141 … … 195 195 - assigned it to the most recently "unhidden" panel */ 196 196 void manageEscapeShortCut(); 197 void updateMachineSelectionMenu();198 197 void setMachines(const QVector<QUuid> &machineIDs); 199 198 /** Returns the content of the ith log file of @comMachine or possibly an empty string */
Note:
See TracChangeset
for help on using the changeset viewer.