VirtualBox

Changeset 45223 in vbox for trunk/src


Ignore:
Timestamp:
Mar 28, 2013 9:01:39 AM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM selector: Preview-frame experimental rework.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc

    r45221 r45223  
    192192        <file alias="previous_16px.png">images/previous_16px.png</file>
    193193        <file alias="expanding_collapsing_16px.png">images/expanding_collapsing_16px.png</file>
     194        <file alias="preview_empty_228x168px.png">images/preview_empty_228x168px.png</file>
     195        <file alias="preview_full_228x168px.png">images/preview_full_228x168px.png</file>
    194196    </qresource>
    195197</RCC>
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.cpp

    r44528 r45223  
    5252    , m_pUpdateTimer(new QTimer(this))
    5353    , m_pUpdateTimerMenu(0)
    54     , m_vMargin(10)
    55     , m_pbgImage(0)
     54    , m_iMargin(0)
     55    , m_pbgEmptyImage(0)
     56    , m_pbgFullImage(0)
    5657    , m_pPreviewImg(0)
    57     , m_pGlossyImg(0)
    5858{
    5959    /* Setup contents: */
     
    6262    /* Create session instance: */
    6363    m_session.createInstance(CLSID_Session);
     64
     65    /* Create bg images: */
     66    m_pbgEmptyImage = new QPixmap(":/preview_empty_228x168px.png");
     67    m_pbgFullImage = new QPixmap(":/preview_full_228x168px.png");
    6468
    6569    /* Create the context menu: */
     
    99103    if (m_session.GetState() == KSessionState_Locked)
    100104        m_session.UnlockMachine();
    101     if (m_pbgImage)
    102         delete m_pbgImage;
    103     if (m_pGlossyImg)
    104         delete m_pGlossyImg;
     105    delete m_pbgEmptyImage;
     106    delete m_pbgFullImage;
    105107    if (m_pPreviewImg)
    106108        delete m_pPreviewImg;
     
    226228void UIGMachinePreview::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
    227229{
    228     repaintBGImages();
     230    recalculatePreviewRectangle();
    229231    sltRecreatePreview();
    230232    QIGraphicsWidget::resizeEvent(pEvent);
     
    267269{
    268270    if (which == Qt::MinimumSize)
    269         return QSize(220, (int)(220 * 3.0/4.0));
     271        return QSize(228 /* pixmap width */ + 2 * m_iMargin,
     272                     168 /* pixmap height */ + 2 * m_iMargin);
    270273    return QIGraphicsWidget::sizeHint(which, constraint);
    271274}
     
    277280    if (!cr.isValid())
    278281        return;
    279     /* Draw the background with the monitor and the shadow: */
    280     if (m_pbgImage)
    281         pPainter->drawImage(cr.x(), cr.y(), *m_pbgImage);
    282282
    283283    /* If there is a preview image available: */
    284284    if (m_pPreviewImg)
    285285    {
     286        /* Draw empty background: */
     287        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_pbgEmptyImage);
     288
    286289        /* Draw that image: */
    287290        pPainter->drawImage(0, 0, *m_pPreviewImg);
     
    289292    else
    290293    {
    291         /* Fill rectangle with black color: */
    292         pPainter->fillRect(m_vRect, Qt::black);
     294        /* Draw full background: */
     295        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_pbgFullImage);
    293296
    294297        /* Compose name: */
     
    317320        pPainter->drawText(m_vRect, fFlags, strName);
    318321    }
    319 
    320     /* Draw the glossy overlay last: */
    321     if (m_pGlossyImg)
    322         pPainter->drawImage(m_vRect.x(), m_vRect.y(), *m_pGlossyImg);
    323322}
    324323
     
    370369}
    371370
    372 void UIGMachinePreview::repaintBGImages()
    373 {
    374     /* Delete the old images: */
    375     if (m_pbgImage)
    376     {
    377         delete m_pbgImage;
    378         m_pbgImage = 0;
    379     }
    380     if (m_pGlossyImg)
    381     {
    382         delete m_pGlossyImg;
    383         m_pGlossyImg = 0;
    384     }
    385 
    386     /* Check that there is enough room for our fancy stuff.
    387      * If not we just draw nothing (the border and the blur radius). */
     371void UIGMachinePreview::recalculatePreviewRectangle()
     372{
     373    /* Contents rectangle: */
    388374    QRect cr = contentsRect().toRect();
    389     if (cr.width()  < 41 || cr.height() < 41)
    390         return;
    391 
    392     QPalette pal = palette();
    393     m_wRect = cr.adjusted(10, 10, -10, -10);
    394     m_vRect = m_wRect.adjusted(m_vMargin, m_vMargin, -m_vMargin, -m_vMargin).adjusted(-3, -3, 3, 3);
    395 
    396     /* First draw the shadow. Its a rounded rectangle which get blurred: */
    397     QImage imageW(cr.size(), QImage::Format_ARGB32);
    398     QColor bg = pal.color(QPalette::Base);
    399     bg.setAlpha(0); /* We want blur to transparent _and_ whatever the base color is. */
    400     imageW.fill(bg.rgba());
    401     QPainter pW(&imageW);
    402     pW.setBrush(QColor(30, 30, 30)); /* Dark gray */
    403     pW.setPen(Qt::NoPen);
    404     pW.drawRoundedRect(QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10), m_vMargin, m_vMargin);
    405     pW.end();
    406     /* Blur the rectangle */
    407     QImage imageO(cr.size(), QImage::Format_ARGB32);
    408     blurImage(imageW, imageO, 10);
    409     QPainter pO(&imageO);
    410 
    411     /* Now paint the border with a gradient to get a look of a monitor: */
    412     QRect rr = QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10);
    413     QLinearGradient lg(0, rr.y(), 0, rr.height());
    414     QColor base(200, 200, 200); /* light variant */
    415     // QColor base(80, 80, 80); /* Dark variant */
    416     lg.setColorAt(0, base);
    417     lg.setColorAt(0.4, base.darker(300));
    418     lg.setColorAt(0.5, base.darker(400));
    419     lg.setColorAt(0.7, base.darker(300));
    420     lg.setColorAt(1, base);
    421     pO.setBrush(lg);
    422     pO.setPen(QPen(base.darker(150), 1));
    423     pO.drawRoundedRect(rr, m_vMargin, m_vMargin);
    424     pO.end();
    425 
    426     /* Make a copy of the new bg image: */
    427     m_pbgImage = new QImage(imageO);
    428 
    429     /* Now the glossy overlay has to be created.
    430      * Start with defining a nice looking painter path. */
    431     QRect gRect = QRect(QPoint(0, 0), m_vRect.size());
    432     QPainterPath glossyPath(QPointF(gRect.x(), gRect.y()));
    433     glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y());
    434     glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y() + gRect.height() * 1.0/3.0);
    435     glossyPath.cubicTo(gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 1.0/3.0,
    436                        gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 2.0/3.0,
    437                        gRect.x(), gRect.y() + gRect.height() * 2.0/3.0);
    438     glossyPath.closeSubpath();
    439 
    440     /* Paint the glossy path on a QImage: */
    441     QImage image(m_vRect.size(), QImage::Format_ARGB32);
    442     QColor bg1(Qt::white); /* We want blur to transparent _and_ white. */
    443     bg1.setAlpha(0);
    444     image.fill(bg1.rgba());
    445     QPainter painter(&image);
    446     painter.fillPath(glossyPath, QColor(255, 255, 255, 80));
    447     painter.end();
    448     /* Blur the image to get a much more smooth feeling */
    449     QImage image1(m_vRect.size(), QImage::Format_ARGB32);
    450     blurImage(image, image1, 7);
    451     m_pGlossyImg = new QImage(image1);
    452 
    453     /* Repaint: */
    454     update();
     375    m_vRect = cr.adjusted(21 + m_iMargin, 17 + m_iMargin, -21 - m_iMargin, -20 - m_iMargin);
    455376}
    456377
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.h

    r44528 r45223  
    3535class QAction;
    3636class QImage;
     37class QPixmap;
    3738class QMenu;
    3839class QTimer;
     
    9798    /* Helpers: Update stuff: */
    9899    void setUpdateInterval(UpdateInterval interval, bool fSave);
    99     void repaintBGImages();
     100    void recalculatePreviewRectangle();
    100101    void restart();
    101102    void stop();
     
    108109    QMenu *m_pUpdateTimerMenu;
    109110    QHash<UpdateInterval, QAction*> m_actions;
    110     const int m_vMargin;
    111     QRect m_wRect;
     111    const int m_iMargin;
    112112    QRect m_vRect;
    113     QImage *m_pbgImage;
     113    QPixmap *m_pbgEmptyImage;
     114    QPixmap *m_pbgFullImage;
    114115    QImage *m_pPreviewImg;
    115     QImage *m_pGlossyImg;
    116116    static UpdateIntervalMap m_intervals;
    117117};
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