- Timestamp:
- Jun 19, 2014 12:28:48 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/UIVMInfoDialog.cpp
r51476 r51665 27 27 /* GUI includes: */ 28 28 #include "UIVMInfoDialog.h" 29 #include "UIExtraDataManager.h" 29 30 #include "UISession.h" 30 31 #include "UIMachineLogic.h" … … 33 34 #include "UIConverter.h" 34 35 #include "UIIconPool.h" 36 #include "QITabWidget.h" 37 #include "QIDialogButtonBox.h" 35 38 #include "VBoxGlobal.h" 36 #include "QITabWidget.h"37 39 #include "VBoxUtils.h" 38 #include "QIDialogButtonBox.h"39 40 40 41 /* COM includes: */ … … 81 82 : QIWithRetranslateUI<QMainWindow>(0) 82 83 , m_pMachineWindow(pMachineWindow) 83 , m_fIsPolished(false)84 , m_iWidth(0), m_iHeight(0), m_fMax(false)85 84 , m_pTabWidget(0) 86 85 , m_session(pMachineWindow->session()) … … 276 275 switch (pEvent->type()) 277 276 { 278 /* Store window state for this VM: */ 279 case QEvent::WindowStateChange: 280 { 281 if (m_fIsPolished) 282 m_fMax = isMaximized(); 277 /* Handle every Resize and Move we keep track of the geometry. */ 278 case QEvent::Resize: 279 { 280 if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0) 281 { 282 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 283 m_geometry.setSize(pResizeEvent->size()); 284 } 285 break; 286 } 287 case QEvent::Move: 288 { 289 if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0) 290 { 291 #ifdef Q_WS_MAC 292 QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent); 293 m_geometry.moveTo(pMoveEvent->pos()); 294 #else /* Q_WS_MAC */ 295 m_geometry.moveTo(geometry().x(), geometry().y()); 296 #endif /* !Q_WS_MAC */ 297 } 283 298 break; 284 299 } … … 289 304 /* Return result: */ 290 305 return fResult; 291 }292 293 void UIVMInfoDialog::resizeEvent(QResizeEvent *pEvent)294 {295 /* Pre-process through base-class: */296 QMainWindow::resizeEvent(pEvent);297 298 /* Store dialog size for this VM: */299 if (m_fIsPolished && !isMaximized())300 {301 m_iWidth = width();302 m_iHeight = height();303 }304 }305 306 void UIVMInfoDialog::showEvent(QShowEvent *pEvent)307 {308 /* One may think that QWidget::polish() is the right place to do things309 * below, but apparently, by the time when QWidget::polish() is called,310 * the widget style & layout are not fully done, at least the minimum311 * size hint is not properly calculated. Since this is sometimes necessary,312 * we provide our own "polish" implementation */313 if (!m_fIsPolished)314 {315 /* Mark as polished: */316 m_fIsPolished = true;317 318 /* Load window size, adjust position and load window state finally: */319 resize(m_iWidth, m_iHeight);320 vboxGlobal().centerWidget(this, m_pMachineWindow, false);321 if (m_fMax)322 QTimer::singleShot(0, this, SLOT(showMaximized()));323 }324 325 /* Post-process through base-class: */326 QMainWindow::showEvent(pEvent);327 306 } 328 307 … … 486 465 void UIVMInfoDialog::loadSettings() 487 466 { 488 /* Load dialog geometry: */ 489 QString strSize = m_session.GetMachine().GetExtraData(GUI_InfoDlgState); 490 if (strSize.isEmpty()) 491 { 492 m_iWidth = 400; 493 m_iHeight = 450; 494 m_fMax = false; 495 } 496 else 497 { 498 QStringList list = strSize.split(','); 499 m_iWidth = list[0].toInt(), m_iHeight = list[1].toInt(); 500 m_fMax = list[2] == "max"; 467 /* Restore window geometry: */ 468 { 469 /* Load geometry: */ 470 m_geometry = gEDataManager->informationWindowGeometry(this, m_pMachineWindow, vboxGlobal().managedVMUuid()); 471 #ifdef Q_WS_MAC 472 move(m_geometry.topLeft()); 473 resize(m_geometry.size()); 474 #else /* Q_WS_MAC */ 475 setGeometry(m_geometry); 476 #endif /* !Q_WS_MAC */ 477 LogRel(("UIVMInfoDialog: Geometry loaded to: %dx%d @ %dx%d.\n", 478 m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height())); 479 480 /* Maximize (if necessary): */ 481 if (gEDataManager->isInformationWindowShouldBeMaximized(vboxGlobal().managedVMUuid())) 482 showMaximized(); 501 483 } 502 484 } … … 504 486 void UIVMInfoDialog::saveSettings() 505 487 { 506 /* Save dialog geometry: */ 507 QString strSize("%1,%2,%3"); 508 m_session.GetMachine().SetExtraData(GUI_InfoDlgState, 509 strSize.arg(m_iWidth).arg(m_iHeight).arg(isMaximized() ? "max" : "normal")); 488 /* Save window geometry: */ 489 { 490 /* Save geometry: */ 491 #ifdef Q_WS_MAC 492 gEDataManager->setInformationWindowGeometry(m_geometry, ::darwinIsWindowMaximized(this), vboxGlobal().managedVMUuid()); 493 #else /* Q_WS_MAC */ 494 gEDataManager->setInformationWindowGeometry(m_geometry, isMaximized(), vboxGlobal().managedVMUuid()); 495 #endif /* !Q_WS_MAC */ 496 LogRel(("UIVMInfoDialog: Geometry saved as: %dx%d @ %dx%d.\n", 497 m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height())); 498 } 510 499 } 511 500 -
trunk/src/VBox/Frontends/VirtualBox/src/UIVMInfoDialog.h
r51410 r51665 65 65 /** Common event-handler. */ 66 66 bool event(QEvent *pEvent); 67 /** Resize event-handler. */68 void resizeEvent(QResizeEvent *pEvent);69 /** Show event-handler. */70 void showEvent(QShowEvent *pEvent);71 67 72 68 private slots: … … 127 123 /** Machine-window to center dialog according. */ 128 124 UIMachineWindow *m_pMachineWindow; 129 /** Whether dialog was polished. */ 130 bool m_fIsPolished; 131 /** @} */ 132 133 /** @name Geometry variables. 134 * @{ */ 135 /** Current dialog width. */ 136 int m_iWidth; 137 /** Current dialog height. */ 138 int m_iHeight; 139 /** Whether dialog maximized. */ 140 bool m_fMax; 125 /** Current dialog geometry. */ 126 QRect m_geometry; 141 127 /** @} */ 142 128 -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp
r51593 r51665 83 83 const char* UIExtraDataDefs::GUI_LastNormalWindowPosition = "GUI/LastNormalWindowPosition"; 84 84 const char* UIExtraDataDefs::GUI_LastScaleWindowPosition = "GUI/LastScaleWindowPosition"; 85 const char* UIExtraDataDefs::GUI_ LastWindowState_Max = "max";85 const char* UIExtraDataDefs::GUI_Geometry_State_Max = "max"; 86 86 const char* UIExtraDataDefs::GUI_LastGuestSizeHint = "GUI/LastGuestSizeHint"; 87 87 const char* UIExtraDataDefs::GUI_LastGuestSizeHintWasFullscreen = "GUI/LastGuestSizeHintWasFullscreen"; … … 125 125 const char* UIExtraDataDefs::GUI_CloseActionHook = "GUI/CloseActionHook"; 126 126 127 /* Runtime UI: Information- dialogdefinitions: */128 const char* UIExtraDataDefs::GUI_ InfoDlgState = "GUI/InfoDlgState";127 /* Runtime UI: Information-window definitions: */ 128 const char* UIExtraDataDefs::GUI_Geometry_InformationWindow = "GUI/Geometry/InformationWindow"; 129 129 130 130 #ifdef VBOX_WITH_DEBUGGER_GUI -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h
r51654 r51665 91 91 extern const char* GUI_LastNormalWindowPosition; 92 92 extern const char* GUI_LastScaleWindowPosition; 93 extern const char* GUI_ LastWindowState_Max;93 extern const char* GUI_Geometry_State_Max; 94 94 extern const char* GUI_LastGuestSizeHint; 95 95 extern const char* GUI_LastGuestSizeHintWasFullscreen; … … 133 133 extern const char* GUI_CloseActionHook; 134 134 135 /* Runtime UI: Information- dialogdeclarations: */136 extern const char* GUI_ InfoDlgState;135 /* Runtime UI: Information-window declarations: */ 136 extern const char* GUI_Geometry_InformationWindow; 137 137 138 138 #ifdef VBOX_WITH_DEBUGGER_GUI -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r51664 r51665 311 311 } 312 312 313 QRect UIExtraDataManager::selectorWindowGeometry(QWidget *p HintWidget /* = 0 */) const313 QRect UIExtraDataManager::selectorWindowGeometry(QWidget *pWidget) const 314 314 { 315 315 /* Load corresponding extra-data: */ … … 335 335 QRect geometry = fOk ? QRect(iX, iY, iW, iH) : QRect(0, 0, 770, 550); 336 336 337 /* Take hint-widget into account: */338 if (p HintWidget)339 geometry.setSize(geometry.size().expandedTo(p HintWidget->minimumSizeHint()));337 /* Take widget into account: */ 338 if (pWidget) 339 geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint())); 340 340 341 341 /* Get screen-geometry [of screen with point (iX, iY) if possible]: */ … … 360 360 361 361 /* Make sure 5th item has required value: */ 362 return data.size() == 5 && data[4] == GUI_ LastWindowState_Max;362 return data.size() == 5 && data[4] == GUI_Geometry_State_Max; 363 363 } 364 364 … … 372 372 data << QString::number(geometry.height()); 373 373 if (fMaximized) 374 data << GUI_ LastWindowState_Max;374 data << GUI_Geometry_State_Max; 375 375 376 376 /* Re-cache corresponding extra-data: */ … … 559 559 560 560 /* Make sure 5th item has required value: */ 561 return data.size() == 5 && data[4] == GUI_ LastWindowState_Max;561 return data.size() == 5 && data[4] == GUI_Geometry_State_Max; 562 562 } 563 563 … … 580 580 data << QString::number(geometry.height()); 581 581 if (fMaximized) 582 data << GUI_ LastWindowState_Max;582 data << GUI_Geometry_State_Max; 583 583 584 584 /* Re-cache corresponding extra-data: */ … … 912 912 } 913 913 #endif /* !Q_WS_MAC */ 914 915 QRect UIExtraDataManager::informationWindowGeometry(QWidget *pWidget, QWidget *pParentWidget, const QString &strID) const 916 { 917 /* Load corresponding extra-data: */ 918 const QStringList data = extraDataStringList(GUI_Geometry_InformationWindow, strID); 919 920 /* Parse loaded data: */ 921 int iX = 0, iY = 0, iW = 0, iH = 0; 922 bool fOk = data.size() >= 4; 923 do 924 { 925 if (!fOk) break; 926 iX = data[0].toInt(&fOk); 927 if (!fOk) break; 928 iY = data[1].toInt(&fOk); 929 if (!fOk) break; 930 iW = data[2].toInt(&fOk); 931 if (!fOk) break; 932 iH = data[3].toInt(&fOk); 933 } 934 while (0); 935 936 /* Use geometry (loaded or default): */ 937 QRect geometry = fOk ? QRect(iX, iY, iW, iH) : QRect(0, 0, 600, 450); 938 939 /* Take hint-widget into account: */ 940 if (pWidget) 941 geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint())); 942 943 /* Get screen-geometry [of screen with point (iX, iY) if possible]: */ 944 const QRect screenGeometry = fOk ? QApplication::desktop()->availableGeometry(QPoint(iX, iY)) : 945 QApplication::desktop()->availableGeometry(); 946 947 /* Make sure resulting geometry is within current bounds: */ 948 geometry = geometry.intersected(screenGeometry); 949 950 /* Move default-geometry to pParentWidget' geometry center: */ 951 if (!fOk && pParentWidget) 952 geometry.moveCenter(pParentWidget->geometry().center()); 953 954 /* Return result: */ 955 return geometry; 956 } 957 958 bool UIExtraDataManager::isInformationWindowShouldBeMaximized(const QString &strID) const 959 { 960 /* Load corresponding extra-data: */ 961 const QStringList data = extraDataStringList(GUI_Geometry_InformationWindow, strID); 962 963 /* Make sure 5th item has required value: */ 964 return data.size() == 5 && data[4] == GUI_Geometry_State_Max; 965 } 966 967 void UIExtraDataManager::setInformationWindowGeometry(const QRect &geometry, bool fMaximized, const QString &strID) 968 { 969 /* Serialize passed values: */ 970 QStringList data; 971 data << QString::number(geometry.x()); 972 data << QString::number(geometry.y()); 973 data << QString::number(geometry.width()); 974 data << QString::number(geometry.height()); 975 if (fMaximized) 976 data << GUI_Geometry_State_Max; 977 978 /* Re-cache corresponding extra-data: */ 979 setExtraDataStringList(GUI_Geometry_InformationWindow, data, strID); 980 } 914 981 915 982 GuruMeditationHandlerType UIExtraDataManager::guruMeditationHandlerType(const QString &strID) const -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h
r51664 r51665 131 131 void setModeForWizard(WizardType type, WizardMode mode); 132 132 133 /** Returns selector-window geometry using @a p HintWidget as the hint. */134 QRect selectorWindowGeometry(QWidget *p HintWidget = 0) const;133 /** Returns selector-window geometry using @a pWidget as the hint. */ 134 QRect selectorWindowGeometry(QWidget *pWidget) const; 135 135 /** Returns whether selector-window should be maximized or not. */ 136 136 bool isSelectorWindowShouldBeMaximized() const; … … 260 260 #endif /* !Q_WS_MAC */ 261 261 262 /** Returns information-window geometry using @a pWidget and @a pParentWidget as hints. */ 263 QRect informationWindowGeometry(QWidget *pWidget, QWidget *pParentWidget, const QString &strID) const; 264 /** Returns whether information-window should be maximized or not. */ 265 bool isInformationWindowShouldBeMaximized(const QString &strID) const; 266 /** Defines information-window geometry to passed @a geometry which is @a fMaximized. */ 267 void setInformationWindowGeometry(const QRect &geometry, bool fMaximized, const QString &strID); 268 262 269 /** Returns redefined guru-meditation handler type. */ 263 270 GuruMeditationHandlerType guruMeditationHandlerType(const QString &strID) const; -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r51540 r51665 972 972 switch (pEvent->type()) 973 973 { 974 /* By handling every Resize and Move we keep track of the normal 975 * (non-minimized and non-maximized) window geometry. Shame on Qt 976 * that it doesn't provide this geometry in its public APIs. */ 974 /* Handle every Resize and Move we keep track of the geometry. */ 977 975 case QEvent::Resize: 978 976 { … … 980 978 { 981 979 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 982 m_ normalGeo.setSize(pResizeEvent->size());980 m_geometry.setSize(pResizeEvent->size()); 983 981 } 984 982 break; … … 990 988 #ifdef Q_WS_MAC 991 989 QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent); 992 m_ normalGeo.moveTo(pMoveEvent->pos());990 m_geometry.moveTo(pMoveEvent->pos()); 993 991 #else /* Q_WS_MAC */ 994 m_ normalGeo.moveTo(geometry().x(), geometry().y());992 m_geometry.moveTo(geometry().x(), geometry().y()); 995 993 #endif /* !Q_WS_MAC */ 996 994 } … … 1501 1499 void UISelectorWindow::loadSettings() 1502 1500 { 1503 /* Restore window position: */1501 /* Restore window geometry: */ 1504 1502 { 1505 1503 /* Load geometry: */ 1506 m_ normalGeo= gEDataManager->selectorWindowGeometry(this);1507 #ifdef Q_WS_MAC 1508 move(m_ normalGeo.topLeft());1509 resize(m_ normalGeo.size());1504 m_geometry = gEDataManager->selectorWindowGeometry(this); 1505 #ifdef Q_WS_MAC 1506 move(m_geometry.topLeft()); 1507 resize(m_geometry.size()); 1510 1508 #else /* Q_WS_MAC */ 1511 setGeometry(m_ normalGeo);1509 setGeometry(m_geometry); 1512 1510 #endif /* !Q_WS_MAC */ 1513 1511 LogRel(("UISelectorWindow: Geometry loaded to: %dx%d @ %dx%d.\n", 1514 m_ normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height()));1512 m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height())); 1515 1513 1516 1514 /* Maximize (if necessary): */ … … 1562 1560 } 1563 1561 1564 /* Save window position: */1565 { 1566 #ifdef Q_WS_MAC 1567 gEDataManager->setSelectorWindowGeometry(m_ normalGeo, ::darwinIsWindowMaximized(this));1562 /* Save window geometry: */ 1563 { 1564 #ifdef Q_WS_MAC 1565 gEDataManager->setSelectorWindowGeometry(m_geometry, ::darwinIsWindowMaximized(this)); 1568 1566 #else /* Q_WS_MAC */ 1569 gEDataManager->setSelectorWindowGeometry(m_ normalGeo, isMaximized());1567 gEDataManager->setSelectorWindowGeometry(m_geometry, isMaximized()); 1570 1568 #endif /* !Q_WS_MAC */ 1571 1569 LogRel(("UISelectorWindow: Geometry saved as: %dx%d @ %dx%d.\n", 1572 m_ normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height()));1570 m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height())); 1573 1571 } 1574 1572 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h
r51453 r51665 238 238 239 239 /* Other variables: */ 240 QRect m_ normalGeo;240 QRect m_geometry; 241 241 }; 242 242
Note:
See TracChangeset
for help on using the changeset viewer.