VirtualBox

Changeset 69669 in vbox for trunk


Ignore:
Timestamp:
Nov 13, 2017 11:22:25 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8694: HiDPI support for menu-bar & status-bar editors.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMenuBarEditorWindow.cpp

    r69500 r69669  
    874874        int iLeft, iTop, iRight, iBottom;
    875875        m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    876         /* Standard margins should not be too big: */
    877         iLeft   = qMin(iLeft,   10);
    878         iTop    = qMin(iTop,    10);
    879         iRight  = qMin(iRight,  10);
    880         iBottom = qMin(iBottom, 10);
     876        /* Acquire metric: */
     877        const int iStandardMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
     878        const int iMinimumMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     879        /* Standard margins should not be too small: */
     880        iLeft   = qMax(iLeft,   iStandardMetric);
     881        iTop    = qMax(iTop,    iStandardMetric);
     882        iRight  = qMax(iRight,  iStandardMetric);
     883        iBottom = qMax(iBottom, iStandardMetric);
    881884        /* Top margin should be smaller for the common case: */
    882         if (iTop >= 5)
    883             iTop -= 5;
     885        if (iTop >= iMinimumMetric)
     886            iTop -= iMinimumMetric;
    884887#ifndef VBOX_WS_MAC
    885888        /* Right margin should be bigger for the settings case: */
    886889        if (m_fStartedFromVMSettings)
    887             iRight += 5;
     890            iRight += iMinimumMetric;
    888891#endif /* !VBOX_WS_MAC */
    889892        /* Apply margins/spacing finally: */
     
    13251328#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    13261329
     1330    /* Acquire metric: */
     1331    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     1332
    13271333    /* Left corner: */
    1328     QRadialGradient grad1(QPointF(5, height() - 5), 5);
     1334    QRadialGradient grad1(QPointF(iMetric, height() - iMetric), iMetric);
    13291335    {
    13301336        grad1.setColorAt(0, color2);
     
    13321338    }
    13331339    /* Right corner: */
    1334     QRadialGradient grad2(QPointF(width() - 5, height() - 5), 5);
     1340    QRadialGradient grad2(QPointF(width() - iMetric, height() - iMetric), iMetric);
    13351341    {
    13361342        grad2.setColorAt(0, color2);
     
    13381344    }
    13391345    /* Bottom line: */
    1340     QLinearGradient grad3(QPointF(5, height()), QPointF(5, height() - 5));
     1346    QLinearGradient grad3(QPointF(iMetric, height()), QPointF(iMetric, height() - iMetric));
    13411347    {
    13421348        grad3.setColorAt(0, color1);
     
    13441350    }
    13451351    /* Left line: */
    1346     QLinearGradient grad4(QPointF(0, height() - 5), QPointF(5, height() - 5));
     1352    QLinearGradient grad4(QPointF(0, height() - iMetric), QPointF(iMetric, height() - iMetric));
    13471353    {
    13481354        grad4.setColorAt(0, color1);
     
    13501356    }
    13511357    /* Right line: */
    1352     QLinearGradient grad5(QPointF(width(), height() - 5), QPointF(width() - 5, height() - 5));
     1358    QLinearGradient grad5(QPointF(width(), height() - iMetric), QPointF(width() - iMetric, height() - iMetric));
    13531359    {
    13541360        grad5.setColorAt(0, color1);
     
    13571363
    13581364    /* Paint shape/shadow: */
    1359     painter.fillRect(QRect(5, 0, width() - 5 * 2, height() - 5), color0); // background
    1360     painter.fillRect(QRect(0,           height() - 5, 5, 5), grad1); // left corner
    1361     painter.fillRect(QRect(width() - 5, height() - 5, 5, 5), grad2); // right corner
    1362     painter.fillRect(QRect(5, height() - 5, width() - 5 * 2, 5), grad3); // bottom line
    1363     painter.fillRect(QRect(0,           0, 5, height() - 5), grad4); // left line
    1364     painter.fillRect(QRect(width() - 5, 0, 5, height() - 5), grad5); // right line
     1365    painter.fillRect(QRect(iMetric, 0, width() - iMetric * 2, height() - iMetric), color0); // background
     1366    painter.fillRect(QRect(0,                 height() - iMetric, iMetric, iMetric), grad1); // left corner
     1367    painter.fillRect(QRect(width() - iMetric, height() - iMetric, iMetric, iMetric), grad2); // right corner
     1368    painter.fillRect(QRect(iMetric,           height() - iMetric, width() - iMetric * 2, iMetric), grad3); // bottom line
     1369    painter.fillRect(QRect(0,                 0, iMetric, height() - iMetric), grad4); // left line
     1370    painter.fillRect(QRect(width() - iMetric, 0, iMetric, height() - iMetric), grad5); // right line
    13651371
    13661372#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
     
    13681374    painter.save();
    13691375    painter.setPen(color3);
    1370     painter.drawLine(QLine(QPoint(5 + 1, 0),                                  QPoint(5 + 1, height() - 1 - 5 - 1)));
    1371     painter.drawLine(QLine(QPoint(5 + 1, height() - 1 - 5 - 1),               QPoint(width() - 1 - 5 - 1, height() - 1 - 5 - 1)));
    1372     painter.drawLine(QLine(QPoint(width() - 1 - 5 - 1, height() - 1 - 5 - 1), QPoint(width() - 1 - 5 - 1, 0)));
     1376    painter.drawLine(QLine(QPoint(iMetric + 1,               0),
     1377                           QPoint(iMetric + 1,               height() - 1 - iMetric - 1)));
     1378    painter.drawLine(QLine(QPoint(iMetric + 1,               height() - 1 - iMetric - 1),
     1379                           QPoint(width() - 1 - iMetric - 1, height() - 1 - iMetric - 1)));
     1380    painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1 - iMetric - 1),
     1381                           QPoint(width() - 1 - iMetric - 1, 0)));
    13731382    if (m_fStartedFromVMSettings)
    1374         painter.drawLine(QLine(QPoint(width() - 1 - 5 - 1, 0), QPoint(5 + 1, 0)));
     1383        painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, 0), QPoint(iMetric + 1, 0)));
    13751384    painter.restore();
    13761385#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIStatusBarEditorWindow.cpp

    r69500 r69669  
    493493        int iLeft, iTop, iRight, iBottom;
    494494        m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    495         /* Standard margins should not be too big: */
    496         iLeft   = qMin(iLeft,   10);
    497         iTop    = qMin(iTop,    10);
    498         iRight  = qMin(iRight,  10);
    499         iBottom = qMin(iBottom, 10);
     495        /* Acquire metric: */
     496        const int iStandardMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
     497        const int iMinimumMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     498        /* Standard margins should not be too small: */
     499        iLeft   = qMax(iLeft,   iStandardMetric);
     500        iTop    = qMax(iTop,    iStandardMetric);
     501        iRight  = qMax(iRight,  iStandardMetric);
     502        iBottom = qMax(iBottom, iStandardMetric);
    500503        /* Bottom margin should be smaller for the common case: */
    501         if (iBottom >= 5)
    502             iBottom -= 5;
     504        if (iBottom >= iMinimumMetric)
     505            iBottom -= iMinimumMetric;
    503506        /* Left margin should be bigger for the settings case: */
    504507        if (m_fStartedFromVMSettings)
    505             iLeft += 5;
     508            iLeft += iMinimumMetric;
    506509        /* Apply margins/spacing finally: */
    507510        m_pMainLayout->setContentsMargins(iLeft, iTop, iRight, iBottom);
     
    623626#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    624627
     628    /* Acquire metric: */
     629    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     630
    625631    /* Left corner: */
    626     QRadialGradient grad1(QPointF(5, 5), 5);
     632    QRadialGradient grad1(QPointF(iMetric, iMetric), iMetric);
    627633    {
    628634        grad1.setColorAt(0, color2);
     
    630636    }
    631637    /* Right corner: */
    632     QRadialGradient grad2(QPointF(width() - 5, 5), 5);
     638    QRadialGradient grad2(QPointF(width() - iMetric, iMetric), iMetric);
    633639    {
    634640        grad2.setColorAt(0, color2);
     
    636642    }
    637643    /* Top line: */
    638     QLinearGradient grad3(QPointF(5, 0), QPointF(5, 5));
     644    QLinearGradient grad3(QPointF(iMetric, 0), QPointF(iMetric, iMetric));
    639645    {
    640646        grad3.setColorAt(0, color1);
     
    642648    }
    643649    /* Left line: */
    644     QLinearGradient grad4(QPointF(0, 5), QPointF(5, 5));
     650    QLinearGradient grad4(QPointF(0, iMetric), QPointF(iMetric, iMetric));
    645651    {
    646652        grad4.setColorAt(0, color1);
     
    648654    }
    649655    /* Right line: */
    650     QLinearGradient grad5(QPointF(width(), 5), QPointF(width() - 5, 5));
     656    QLinearGradient grad5(QPointF(width(), iMetric), QPointF(width() - iMetric, iMetric));
    651657    {
    652658        grad5.setColorAt(0, color1);
     
    655661
    656662    /* Paint shape/shadow: */
    657     painter.fillRect(QRect(5, 5, width() - 5 * 2, height() - 5), color0); // background
    658     painter.fillRect(QRect(0,           0, 5, 5), grad1); // left corner
    659     painter.fillRect(QRect(width() - 5, 0, 5, 5), grad2); // right corner
    660     painter.fillRect(QRect(5, 0, width() - 5 * 2, 5), grad3); // bottom line
    661     painter.fillRect(QRect(0,           5, 5, height() - 5), grad4); // left line
    662     painter.fillRect(QRect(width() - 5, 5, 5, height() - 5), grad5); // right line
     663    painter.fillRect(QRect(iMetric, iMetric, width() - iMetric * 2, height() - iMetric), color0); // background
     664    painter.fillRect(QRect(0,                 0, iMetric, iMetric), grad1); // left corner
     665    painter.fillRect(QRect(width() - iMetric, 0, iMetric, iMetric), grad2); // right corner
     666    painter.fillRect(QRect(iMetric,           0, width() - iMetric * 2, iMetric), grad3); // bottom line
     667    painter.fillRect(QRect(0,                 iMetric, iMetric, height() - iMetric), grad4); // left line
     668    painter.fillRect(QRect(width() - iMetric, iMetric, iMetric, height() - iMetric), grad5); // right line
    663669
    664670#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
     
    666672    painter.save();
    667673    painter.setPen(color3);
    668     painter.drawLine(QLine(QPoint(5 + 1, 5 + 1),                      QPoint(width() - 1 - 5 - 1, 5 + 1)));
    669     painter.drawLine(QLine(QPoint(width() - 1 - 5 - 1, 5 + 1),        QPoint(width() - 1 - 5 - 1, height() - 1)));
    670     painter.drawLine(QLine(QPoint(width() - 1 - 5 - 1, height() - 1), QPoint(5 + 1, height() - 1)));
    671     painter.drawLine(QLine(QPoint(5 + 1, height() - 1),               QPoint(5 + 1, 5 + 1)));
     674    painter.drawLine(QLine(QPoint(iMetric + 1,               iMetric + 1),
     675                           QPoint(width() - 1 - iMetric - 1, iMetric + 1)));
     676    painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, iMetric + 1),
     677                           QPoint(width() - 1 - iMetric - 1, height() - 1)));
     678    painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1),
     679                           QPoint(iMetric + 1,               height() - 1)));
     680    painter.drawLine(QLine(QPoint(iMetric + 1,               height() - 1),
     681                           QPoint(iMetric + 1,               iMetric + 1)));
    672682    painter.restore();
    673683#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
     
    680690        const QRect geo = m_pButtonDropToken->geometry();
    681691        option.rect = !m_fDropAfterTokenButton ?
    682                       QRect(geo.topLeft() - QPoint(5, 5),
    683                             geo.bottomLeft() + QPoint(0, 5)) :
    684                       QRect(geo.topRight() - QPoint(0, 5),
    685                             geo.bottomRight() + QPoint(5, 5));
     692                      QRect(geo.topLeft() - QPoint(iMetric, iMetric),
     693                            geo.bottomLeft() + QPoint(0, iMetric)) :
     694                      QRect(geo.topRight() - QPoint(0, iMetric),
     695                            geo.bottomRight() + QPoint(iMetric, iMetric));
    686696        QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator,
    687697                                             &option, &painter);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette