Changeset 51455 in vbox
- Timestamp:
- May 28, 2014 5:53:18 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r51449 r51455 18 18 /* Qt includes: */ 19 19 #include <QMutex> 20 #include <QDesktopWidget> 20 21 21 22 /* GUI includes: */ … … 315 316 } 316 317 318 QRect UIExtraDataManager::selectorWindowGeometry(QWidget *pHintWidget /* = 0 */) 319 { 320 /* Load corresponding extra-data: */ 321 const QStringList data = extraDataStringList(GUI_LastSelectorWindowPosition); 322 323 /* Parse loaded data: */ 324 int iX = 0, iY = 0, iW = 0, iH = 0; 325 bool fOk = data.size() >= 4; 326 do 327 { 328 if (!fOk) break; 329 iX = data[0].toInt(&fOk); 330 if (!fOk) break; 331 iY = data[1].toInt(&fOk); 332 if (!fOk) break; 333 iW = data[2].toInt(&fOk); 334 if (!fOk) break; 335 iH = data[3].toInt(&fOk); 336 } 337 while (0); 338 339 /* Use geometry (loaded or default): */ 340 QRect geometry = fOk ? QRect(iX, iY, iW, iH) : QRect(0, 0, 770, 550); 341 342 /* Take hint-widget into account: */ 343 if (pHintWidget) 344 geometry.setSize(geometry.size().expandedTo(pHintWidget->minimumSizeHint())); 345 346 /* Get screen-geometry [of screen with point (iX, iY) if possible]: */ 347 const QRect screenGeometry = fOk ? QApplication::desktop()->availableGeometry(QPoint(iX, iY)) : 348 QApplication::desktop()->availableGeometry(); 349 350 /* Make sure resulting geometry is within current bounds: */ 351 geometry = geometry.intersected(screenGeometry); 352 353 /* Move default-geometry to screen-geometry' center: */ 354 if (!fOk) 355 geometry.moveCenter(screenGeometry.center()); 356 357 /* Return result: */ 358 return geometry; 359 } 360 361 bool UIExtraDataManager::isSelectorWindowShouldBeMaximized() 362 { 363 /* Load corresponding extra-data: */ 364 const QStringList data = extraDataStringList(GUI_LastSelectorWindowPosition); 365 366 /* Make sure 5th item has required value: */ 367 return data.size() == 5 && data[4] == GUI_LastWindowState_Max; 368 } 369 370 void UIExtraDataManager::setSelectorWindowGeometry(const QRect &geometry, bool fMaximized) 371 { 372 /* Serialize passed values: */ 373 QStringList data; 374 data << QString::number(geometry.x()); 375 data << QString::number(geometry.y()); 376 data << QString::number(geometry.width()); 377 data << QString::number(geometry.height()); 378 if (fMaximized) 379 data << GUI_LastWindowState_Max; 380 381 /* Re-cache corresponding extra-data: */ 382 setExtraDataStringList(GUI_LastSelectorWindowPosition, data); 383 } 384 317 385 bool UIExtraDataManager::isFirstRun(const QString &strId) const 318 386 { -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h
r51449 r51455 130 130 /** Defines @a mode (basic/expert) for wizard of @a type. */ 131 131 void setModeForWizard(WizardType type, WizardMode mode); 132 133 /** Returns selector-window geometry using @a pHintWidget as the hint. */ 134 QRect selectorWindowGeometry(QWidget *pHintWidget = 0); 135 /** Returns whether selector-window should be maximized or not. */ 136 bool isSelectorWindowShouldBeMaximized(); 137 /** Defines selector-window geometry to passed @a geometry which is @a fMaximized. */ 138 void setSelectorWindowGeometry(const QRect &geometry, bool fMaximized); 132 139 133 140 /** Returns render-mode for machine with passed @a strId. */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r51454 r51455 23 23 24 24 /* Qt includes: */ 25 #include <QDesktopWidget>26 25 #include <QDesktopServices> 27 26 #include <QMenuBar> … … 1526 1525 /* Restore window position: */ 1527 1526 { 1528 /* Loading geometry: */ 1529 QString strWinPos = vbox.GetExtraData(GUI_LastSelectorWindowPosition); 1530 LogRelFlow(("UISelectorWindow: Loading geometry settings: {%s}\n", strWinPos.toAscii().constData())); 1531 1532 bool ok = false, max = false; 1533 int x = 0, y = 0, w = 0, h = 0; 1534 x = strWinPos.section(',', 0, 0).toInt(&ok); 1535 if (ok) 1536 y = strWinPos.section(',', 1, 1).toInt(&ok); 1537 if (ok) 1538 w = strWinPos.section(',', 2, 2).toInt(&ok); 1539 if (ok) 1540 h = strWinPos.section(',', 3, 3).toInt(&ok); 1541 if (ok) 1542 max = strWinPos.section(',', 4, 4) == GUI_LastWindowState_Max; 1543 1544 QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) : 1545 QApplication::desktop()->availableGeometry(this); 1546 1547 if (ok /* previous parameters were read correctly */ 1548 && (y > 0) && (y < ar.bottom()) /* check vertical bounds */ 1549 && (x + w > ar.left()) && (x < ar.right()) /* & horizontal bounds */) 1550 { 1551 /* Apply loaded geometry: */ 1552 m_normalGeo.moveTo(x, y); 1553 m_normalGeo.setSize(QSize(w, h).expandedTo(minimumSizeHint()).boundedTo(ar.size())); 1527 /* Load geometry: */ 1528 m_normalGeo = gEDataManager->selectorWindowGeometry(this); 1554 1529 #ifdef Q_WS_MAC 1555 1556 1530 move(m_normalGeo.topLeft()); 1531 resize(m_normalGeo.size()); 1557 1532 #else /* Q_WS_MAC */ 1558 1533 setGeometry(m_normalGeo); 1559 1534 #endif /* !Q_WS_MAC */ 1560 LogRelFlow(("UISelectorWindow: Geometry set to: %dx%d @ %dx%d.\n", 1561 m_normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height())); 1562 if (max) /* maximize if needed */ 1563 showMaximized(); 1564 } 1565 else 1566 { 1567 /* Apply default geometry: */ 1568 m_normalGeo.setSize(QSize(770, 550).expandedTo(minimumSizeHint()).boundedTo(ar.size())); 1569 m_normalGeo.moveCenter(ar.center()); 1570 setGeometry(m_normalGeo); 1571 LogRelFlow(("UISelectorWindow: Geometry set to default because something was wrong: " 1572 "(loaded correctly = '%s', x = %d, y = %d, w = %d, h = %d)!\n", 1573 ok ? "true" : "false", x, y, w, h)); 1574 } 1535 LogRel(("UISelectorWindow: Geometry loaded to: %dx%d @ %dx%d.\n", 1536 m_normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height())); 1537 1538 /* Maximize (if necessary): */ 1539 if (gEDataManager->isSelectorWindowShouldBeMaximized()) 1540 showMaximized(); 1575 1541 } 1576 1542 … … 1609 1575 /* Save window position: */ 1610 1576 { 1611 QRect save(m_normalGeo);1612 LogRelFlow(("UISelectorWindow: Saving geometry as %dx%d @ %dx%d.\n",1613 save.x(), save.y(), save.width(), save.height()));1614 QString strWinPos = QString("%1,%2,%3,%4").arg(save.x()).arg(save.y()).arg(save.width()).arg(save.height());1615 1577 #ifdef Q_WS_MAC 1616 if (::darwinIsWindowMaximized(this))1578 gEDataManager->setSelectorWindowGeometry(m_normalGeo, ::darwinIsWindowMaximized(this)); 1617 1579 #else /* Q_WS_MAC */ 1618 if (isMaximized())1580 gEDataManager->setSelectorWindowGeometry(m_normalGeo, isMaximized()); 1619 1581 #endif /* !Q_WS_MAC */ 1620 strWinPos += QString(",%1").arg(GUI_LastWindowState_Max); 1621 1622 vbox.SetExtraData(GUI_LastSelectorWindowPosition, strWinPos); 1582 LogRel(("UISelectorWindow: Geometry saved as: %dx%d @ %dx%d.\n", 1583 m_normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height())); 1623 1584 } 1624 1585 }
Note:
See TracChangeset
for help on using the changeset viewer.