VirtualBox

Changeset 35424 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 7, 2011 1:05:41 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4: change the layout of the beta label and add it to the VM window

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIImageTools.cpp

    r35417 r35424  
    204204}
    205205
    206 QPixmap betaLabel()
     206static QImage betaLabelImage(const QSize& ls)
    207207{
    208208    /* Beta label */
    209     QSize ls(80, 16);
    210209    QColor bgc(246, 179, 0);
    211210    QImage i(ls, QImage::Format_ARGB32);
     
    218217    p.drawRect(0, 0, ls.width(), ls.height());
    219218    /* The black stripes */
    220     p.setPen(QPen(QColor(70, 70, 70), 3));
    221     int c = 6;
     219    p.setPen(QPen(QColor(70, 70, 70), 5));
     220    float c = ((float)ls.width() / ls.height()) + 1;
    222221    float g = (ls.width() / (c - 1));
    223222    for (int i = 0; i < c; ++i)
     
    239238    p.drawPath(tp);
    240239    p.end();
     240
     241    /* Smoothing */
     242    QImage i1(ls, QImage::Format_ARGB32);
     243    i1.fill(Qt::transparent);
     244    QPainter p1(&i1);
     245    p1.setCompositionMode(QPainter::CompositionMode_Source);
     246    p1.drawImage(0, 0, i);
     247    p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
     248    QLinearGradient lg(0, 0, ls.width(), 0);
     249    lg.setColorAt(0, QColor(Qt::transparent));
     250    lg.setColorAt(0.20, QColor(Qt::white));
     251    lg.setColorAt(0.80, QColor(Qt::white));
     252    lg.setColorAt(1, QColor(Qt::transparent));
     253    p1.fillRect(0, 0, ls.width(), ls.height(), lg);
     254    p1.end();
     255
     256    return i1;
     257}
     258
     259QPixmap betaLabel(const QSize &ls /* = QSize(80, 16) */)
     260{
     261    return QPixmap::fromImage(betaLabelImage(ls));
     262}
     263
     264QPixmap betaLabelSleeve(const QSize &ls /* = QSize(80, 16) */)
     265{
     266    const QImage &i = betaLabelImage(ls);
    241267    /* Create a secondary image which will contain the rotated banner. */
    242268    int w = sqrtf(powf(ls.width(), 2) / 2);
     
    245271    QPainter p1(&i1);
    246272    p1.setRenderHints(QPainter::SmoothPixmapTransform);
    247     p1.translate(0, w);
    248     p1.rotate(-45);
    249     p1.drawImage(0, 0, i);
     273    p1.rotate(45);
     274    p1.drawImage(0, -ls.height(), i);
    250275    p1.end();
    251276
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIImageTools.h

    r35415 r35424  
    2929void blurImageVertical(const QImage &source, QImage &dest, int r);
    3030
    31 QPixmap betaLabel();
     31QPixmap betaLabel(const QSize &ls = QSize(80, 16));
     32QPixmap betaLabelSleeve(const QSize &ls = QSize(80, 16));
    3233
    3334#endif /* !__UIImageTools_h__ */
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/VBoxUtils-darwin-cocoa.mm

    r35415 r35424  
    9696}
    9797
    98 void darwinLabelToolbar(NativeNSWindowRef pWindow, NativeNSImageRef pImage)
    99 {
    100     NSToolbar *tb = [pWindow toolbar];
    101     if ([tb respondsToSelector:@selector(_toolbarView)])
    102     {
    103         NSView *tbv = [tb performSelector:@selector(_toolbarView)];
    104         if (tbv)
    105         {
    106             NSSize s = [pImage size];
    107             NSSize s1 = [tbv frame].size;
    108             NSImageView *iv = [[NSImageView alloc] initWithFrame:NSMakeRect(s1.width - s.width, s1.height - s.height - 1, s.width, s.height)];
    109             [iv setImage:pImage];
    110             [iv setAutoresizesSubviews:true];
    111             [iv setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
    112             [tbv addSubview:iv positioned:NSWindowBelow relativeTo:nil];
    113         }
     98void darwinLabelWindow(NativeNSWindowRef pWindow, NativeNSImageRef pImage, bool fCenter)
     99{
     100    /* Get the parent view of the close button. */
     101    NSView *wv = [[pWindow standardWindowButton:NSWindowCloseButton] superview];
     102    if (wv)
     103    {
     104        /* We have to calculate the size of the title bar for the center case. */
     105        NSSize s = [pImage size];
     106        NSSize s1 = [wv frame].size;
     107        NSSize s2 = [[pWindow contentView] frame].size;
     108        /* Correctly position the label. */
     109        NSImageView *iv = [[NSImageView alloc] initWithFrame:NSMakeRect(s1.width - s.width - (fCenter ? 10 : 0),
     110                                                                        fCenter ? s2.height + (s1.height - s2.height - s.height) / 2 : s1.height - s.height - 1,
     111                                                                        s.width, s.height)];
     112        /* Configure the NSImageView for auto moving. */
     113        [iv setImage:pImage];
     114        [iv setAutoresizesSubviews:true];
     115        [iv setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
     116        /* Add it to the parent of the close button. */
     117        [wv addSubview:iv positioned:NSWindowBelow relativeTo:nil];
    114118    }
    115119}
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/VBoxUtils-darwin.cpp

    r35415 r35424  
    6767}
    6868
    69 void darwinLabelToolbar(QWidget *pWidget, QPixmap *pPixmap)
    70 {
    71     ::darwinLabelToolbar(::darwinToNativeWindow(pWidget), ::darwinToNSImageRef(pPixmap));
     69void darwinLabelWindow(QWidget *pWidget, QPixmap *pPixmap, bool fCenter)
     70{
     71    ::darwinLabelWindow(::darwinToNativeWindow(pWidget), ::darwinToNSImageRef(pPixmap), fCenter);
    7272}
    7373
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/VBoxUtils-darwin.h

    r35415 r35424  
    5959void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled);
    6060void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow);
    61 void darwinLabelToolbar(NativeNSWindowRef pWindow, NativeNSImageRef pImage);
     61void darwinLabelWindow(NativeNSWindowRef pWindow, NativeNSImageRef pImage, bool fCenter);
    6262void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled);
    6363void darwinSetMouseCoalescingEnabled(bool fEnabled);
     
    175175 ********************************************************************************/
    176176void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled);
    177 void darwinLabelToolbar(QWidget *pWidget, QPixmap *pPixmap);
     177void darwinLabelWindow(QWidget *pWidget, QPixmap *pPixmap, bool fCenter);
    178178void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled);
    179179void darwinSetHidesAllTitleButtons(QWidget *pWidget);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineMenuBar.cpp

    r34158 r35424  
    2525#include "VBoxProblemReporter.h"
    2626#include "UIExtraDataEventHandler.h"
     27#include "UIImageTools.h"
    2728
    2829/* Global includes */
    2930#include <QMenuBar>
     31#include <QPainter>
     32#include <QPaintEvent>
     33#include <QPixmapCache>
    3034
    3135/* Helper QMenu reimplementation which allows
     
    4852        QMenu::focusNextChild();
    4953    }
     54};
     55
     56class UIMenuBar: public QMenuBar
     57{
     58public:
     59
     60    UIMenuBar(QWidget *pParent = 0)
     61      : QMenuBar(pParent)
     62      , m_fShowBetaLabel(false)
     63    {
     64        /* Check for beta versions */
     65        if (vboxGlobal().isBeta())
     66            m_fShowBetaLabel = true;
     67    }
     68
     69protected:
     70
     71    void paintEvent(QPaintEvent *pEvent)
     72    {
     73        QMenuBar::paintEvent(pEvent);
     74        if (m_fShowBetaLabel)
     75        {
     76            QPixmap betaLabel;
     77            const QString key("vbox:betaLabel");
     78            if (!QPixmapCache::find(key, betaLabel))
     79            {
     80                betaLabel = ::betaLabel();
     81                QPixmapCache::insert(key, betaLabel);
     82            }
     83            QSize s = size();
     84            QPainter painter(this);
     85            painter.setClipRect(pEvent->rect());
     86            painter.drawPixmap(s.width() - betaLabel.width() - 10, (height() - betaLabel.height()) / 2, betaLabel);
     87        }
     88    }
     89
     90private:
     91
     92    /* Private member vars */
     93    bool m_fShowBetaLabel;
    5094};
    5195
     
    73117{
    74118    /* Create empty menubar: */
    75     QMenuBar *pMenuBar = new QMenuBar;
     119    QMenuBar *pMenuBar = new UIMenuBar;
    76120
    77121    /* Fill menubar with prepared items: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

    r30930 r35424  
    3939#include "UIDownloaderAdditions.h"
    4040#include "UIDownloaderUserManual.h"
     41#ifdef Q_WS_MAC
     42# include "UIImageTools.h"
     43#endif /* Q_WS_MAC */
    4144
    4245#include "QIStatusBar.h"
     
    8992    /* Update all the elements: */
    9093    updateAppearanceOf(UIVisualElement_AllStuff);
     94
     95#ifdef Q_WS_MAC
     96    /* Beta label? */
     97    if (vboxGlobal().isBeta())
     98    {
     99        QPixmap betaLabel = ::betaLabel(QSize(100, 16));
     100        ::darwinLabelWindow(this, &betaLabel, true);
     101    }
     102#endif /* Q_WS_MAC */
    91103
    92104    /* Show window: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp

    r35247 r35424  
    3434#include "UIMachineView.h"
    3535#include "UIMachineWindowScale.h"
     36#ifdef Q_WS_MAC
     37# include "UIImageTools.h"
     38#endif /* Q_WS_MAC */
    3639
    3740UIMachineWindowScale::UIMachineWindowScale(UIMachineLogic *pMachineLogic, ulong uScreenId)
     
    7376    /* Update all the elements: */
    7477    updateAppearanceOf(UIVisualElement_AllStuff);
     78
     79#ifdef Q_WS_MAC
     80    /* Beta label? */
     81    if (vboxGlobal().isBeta())
     82    {
     83        QPixmap betaLabel = ::betaLabel(QSize(100, 16));
     84        ::darwinLabelWindow(this, &betaLabel, true);
     85    }
     86#endif /* Q_WS_MAC */
     87
    7588
    7689    /* Show window: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBar.cpp

    r35416 r35424  
    122122{
    123123    UIBar::paintEvent(pEvent);
    124     QPainter painter(this);
    125     painter.setClipRect(pEvent->rect());
    126 
    127124    if (m_fShowBetaLabel)
    128125    {
    129126        QPixmap betaLabel;
    130         const QString key("vbox:betaLabel");
     127        const QString key("vbox:betaLabelSleeve");
    131128        if (!QPixmapCache::find(key, betaLabel))
    132129        {
    133             betaLabel = ::betaLabel();
     130            betaLabel = ::betaLabelSleeve();
    134131            QPixmapCache::insert(key, betaLabel);
    135132        }
    136133        QSize s = size();
    137         painter.drawPixmap(s.width() - betaLabel.width(), s.height() - betaLabel.height() - 1, betaLabel);
     134        QPainter painter(this);
     135        painter.setClipRect(pEvent->rect());
     136        painter.drawPixmap(s.width() - betaLabel.width(), 0, betaLabel);
    138137    }
    139138}
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