Changeset 57496 in vbox for trunk/src/VBox
- Timestamp:
- Aug 21, 2015 1:17:10 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/UIVMLogViewer.cpp
r57484 r57496 29 29 # include <QScrollBar> 30 30 # include <QTextEdit> 31 # include <QDesktopWidget> 31 32 32 33 /* GUI includes: */ … … 38 39 # include "UIMessageCenter.h" 39 40 # include "VBoxUtils.h" 41 # include "UIExtraDataManager.h" 40 42 41 43 /* COM includes: */ … … 412 414 refresh(); 413 415 416 /* Load settings: */ 417 loadSettings(); 418 414 419 /* Loading language constants */ 415 420 retranslateUi(); … … 418 423 UIVMLogViewer::~UIVMLogViewer() 419 424 { 425 /* Save settings: */ 426 saveSettings(); 427 420 428 if (!m_machine.isNull()) 421 429 m_viewers.remove(m_machine.GetName()); … … 564 572 return; 565 573 566 m_fIsPolished = true; 567 568 /* Resize the whole log-viewer to fit 80 symbols in 569 * text-browser for the first time started: */ 570 QTextEdit *pFirstPage = currentLogPage(); 571 if (pFirstPage) 572 { 573 int fullWidth = pFirstPage->fontMetrics().width(QChar('x')) * 80 + 574 pFirstPage->verticalScrollBar()->width() + 575 pFirstPage->frameWidth() * 2 + 576 /* m_pViewerContainer margin */ 10 * 2 + 577 /* CentralWidget margin */ 10 * 2; 578 resize(fullWidth, height()); 579 } 574 m_fIsPolished = true; 580 575 581 576 /* Make sure the log view widget has the focus */ 582 577 QWidget *pCurrentLogPage = currentLogPage(); 583 578 if (pCurrentLogPage) 584 pCurrentLogPage->setFocus(); 585 586 /* Explicit widget centering relatively to it's parent: */ 587 VBoxGlobal::centerWidget(this, parentWidget(), false); 579 pCurrentLogPage->setFocus(); 588 580 } 589 581 … … 644 636 } 645 637 638 void UIVMLogViewer::loadSettings() 639 { 640 /* Restore window geometry: */ 641 { 642 /* Getting available geometry to calculate default geometry: */ 643 const QRect desktopRect = QApplication::desktop()->availableGeometry(this); 644 int iDefaultWidth = desktopRect.width() * 0.5; 645 int iDefaultHeight = desktopRect.height() * 0.75; 646 647 /* Calculate default width to fit 132 characters: */ 648 QTextEdit *pCurrentLogPage = currentLogPage(); 649 if (pCurrentLogPage) 650 { 651 iDefaultWidth = pCurrentLogPage->fontMetrics().width(QChar('x')) * 132 + 652 pCurrentLogPage->verticalScrollBar()->width() + 653 pCurrentLogPage->frameWidth() * 2 + 654 /* m_pViewerContainer margin */ 10 * 2 + 655 /* CentralWidget margin */ 10 * 2; 656 } 657 QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight); 658 defaultGeometry.moveCenter(parentWidget()->geometry().center()); 659 660 /* Load geometry: */ 661 m_geometry = gEDataManager->logWindowGeometry(this, defaultGeometry); 662 #ifdef Q_WS_MAC 663 move(m_geometry.topLeft()); 664 resize(m_geometry.size()); 665 #else /* Q_WS_MAC */ 666 setGeometry(m_geometry); 667 #endif /* !Q_WS_MAC */ 668 LogRel(("GUI: UIVMLogViewer: Geometry loaded to: %dx%d @ %dx%d\n", 669 m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height())); 670 671 /* Maximize (if necessary): */ 672 if (gEDataManager->logWindowShouldBeMaximized()) 673 showMaximized(); 674 } 675 } 676 677 void UIVMLogViewer::saveSettings() 678 { 679 /* Save window geometry: */ 680 { 681 /* Save geometry: */ 682 const QRect save_geometry = geometry(); 683 #ifdef Q_WS_MAC 684 gEDataManager->setLogWindowGeometry(save_geometry, ::darwinIsWindowMaximized(this)); 685 #else /* Q_WS_MAC */ 686 gEDataManager->setLogWindowGeometry(save_geometry, isMaximized()); 687 #endif /* !Q_WS_MAC */ 688 LogRel(("GUI: UIVMLogViewer: Geometry saved as: %dx%d @ %dx%d\n", 689 save_geometry.x(), save_geometry.y(), save_geometry.width(), save_geometry.height())); 690 } 691 } 692 646 693 #include "UIVMLogViewer.moc" 647 694 -
trunk/src/VBox/Frontends/VirtualBox/src/UIVMLogViewer.h
r55401 r57496 82 82 QTextEdit* createLogPage(const QString &strPage); 83 83 84 /** Load settings helper. */ 85 void loadSettings(); 86 87 /** Save settings helper. */ 88 void saveSettings(); 89 84 90 /* Array containing all VM Log Viewers: */ 85 91 static VMLogViewerMap m_viewers; … … 91 97 UIVMLogViewerSearchPanel *m_pSearchPanel; 92 98 LogBook m_book; 99 100 /** Current dialog geometry. */ 101 QRect m_geometry; 93 102 94 103 /* Buttons: */ -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp
r56704 r57496 165 165 #endif /* DEBUG */ 166 166 167 /* Virtual Machine: Logging dialog: */ 168 const char* UIExtraDataDefs::GUI_LogWindowGeometry = "GUI/LogWindowGeometry"; -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h
r56704 r57496 287 287 /** @} */ 288 288 #endif /* DEBUG */ 289 290 /** Holds log-window geometry. */ 291 extern const char* GUI_LogWindowGeometry; 289 292 } 290 293 -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r56704 r57496 1804 1804 << GUI_Dbg_Enabled << GUI_Dbg_AutoShow 1805 1805 #endif /* VBOX_WITH_DEBUGGER_GUI */ 1806 << GUI_ExtraDataManager_Geometry << GUI_ExtraDataManager_SplitterHints; 1806 << GUI_ExtraDataManager_Geometry << GUI_ExtraDataManager_SplitterHints 1807 << GUI_LogWindowGeometry; 1807 1808 } 1808 1809 #endif /* DEBUG */ … … 3620 3621 } 3621 3622 #endif /* DEBUG */ 3623 3624 QRect UIExtraDataManager::logWindowGeometry(QWidget *pWidget, const QRect &defaultGeometry) 3625 { 3626 /* Get corresponding extra-data: */ 3627 const QStringList data = extraDataStringList(GUI_LogWindowGeometry); 3628 3629 /* Parse loaded data: */ 3630 int iX = 0, iY = 0, iW = 0, iH = 0; 3631 bool fOk = data.size() >= 4; 3632 do 3633 { 3634 if (!fOk) break; 3635 iX = data[0].toInt(&fOk); 3636 if (!fOk) break; 3637 iY = data[1].toInt(&fOk); 3638 if (!fOk) break; 3639 iW = data[2].toInt(&fOk); 3640 if (!fOk) break; 3641 iH = data[3].toInt(&fOk); 3642 } 3643 while (0); 3644 3645 /* Use geometry (loaded or default): */ 3646 QRect geometry = fOk ? QRect(iX, iY, iW, iH) : defaultGeometry; 3647 3648 /* Take widget into account: */ 3649 if (pWidget) 3650 geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint())); 3651 3652 /* In Windows Qt fails to reposition out of screen window properly, so moving to centre: */ 3653 #ifdef Q_WS_WIN 3654 /* Get screen-geometry [of screen with point (iX, iY) if possible]: */ 3655 const QRect screenGeometry = QApplication::desktop()->availableGeometry(QPoint(iX, iY)); 3656 3657 /* Make sure resulting geometry is within current bounds: */ 3658 if (!screenGeometry.contains(geometry, true)) 3659 geometry.moveCenter(defaultGeometry.center()); 3660 #endif /* Q_WS_WIN */ 3661 3662 /* Return result: */ 3663 return geometry; 3664 } 3665 3666 bool UIExtraDataManager::logWindowShouldBeMaximized() 3667 { 3668 /* Get corresponding extra-data: */ 3669 const QStringList data = extraDataStringList(GUI_LogWindowGeometry); 3670 3671 /* Make sure 5th item has required value: */ 3672 return data.size() == 5 && data[4] == GUI_Geometry_State_Max; 3673 } 3674 3675 void UIExtraDataManager::setLogWindowGeometry(const QRect &geometry, bool fMaximized) 3676 { 3677 /* Serialize passed values: */ 3678 QStringList data; 3679 data << QString::number(geometry.x()); 3680 data << QString::number(geometry.y()); 3681 data << QString::number(geometry.width()); 3682 data << QString::number(geometry.height()); 3683 if (fMaximized) 3684 data << GUI_Geometry_State_Max; 3685 3686 /* Re-cache corresponding extra-data: */ 3687 setExtraDataStringList(GUI_LogWindowGeometry, data); 3688 } 3622 3689 3623 3690 void UIExtraDataManager::sltExtraDataChange(QString strMachineID, QString strKey, QString strValue) -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h
r56704 r57496 534 534 #endif /* DEBUG */ 535 535 536 /** @name Virtual Machine: Logwindow dialog 537 * @{ */ 538 /** Returns log-window geometry using @a pWidget and @a defaultGeometry as hints. */ 539 QRect logWindowGeometry(QWidget *pWidget, const QRect &defaultGeometry); 540 /** Returns whether log-window should be maximized or not. */ 541 bool logWindowShouldBeMaximized(); 542 /** Defines log-window @a geometry and @a fMaximized state. */ 543 void setLogWindowGeometry(const QRect &geometry, bool fMaximized); 544 /** @} */ 545 536 546 private slots: 537 547
Note:
See TracChangeset
for help on using the changeset viewer.