VirtualBox

Changeset 72026 in vbox


Ignore:
Timestamp:
Apr 25, 2018 5:17:52 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122289
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for UIStatusBarEditorWindow and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r72025 r72026  
    466466        src/runtime/UISession.h \
    467467        src/runtime/UISlidingToolBar.h \
    468         src/runtime/UIStatusBarEditorWindow.h \
    469468        src/runtime/UIVMCloseDialog.h \
    470469        src/runtime/fullscreen/UIKeyboardHandlerFullscreen.h \
     
    688687        src/widgets/UIProgressDialog.h \
    689688        src/widgets/UISpecialControls.h \
     689        src/widgets/UIStatusBarEditorWindow.h \
    690690        src/widgets/UIToolBar.h \
    691691        src/widgets/UIWarningPane.h \
     
    796796        src/widgets/UIProgressDialog.h \
    797797        src/widgets/UISpecialControls.h \
     798        src/widgets/UIStatusBarEditorWindow.h \
    798799        src/widgets/UIToolBar.h \
    799800        src/widgets/UIWarningPane.h \
     
    838839        src/runtime/UIFrameBuffer.cpp \
    839840        src/runtime/UIIndicatorsPool.cpp \
    840         src/runtime/UIStatusBarEditorWindow.cpp \
    841841        src/runtime/guestctrl/UIGuestControlFileManager.cpp \
    842842        src/runtime/guestctrl/UIGuestControlFileTable.cpp \
     
    876876        src/widgets/UIHotKeyEditor.cpp \
    877877        src/widgets/UIPortForwardingTable.cpp \
    878         src/widgets/UIProgressDialog.cpp
     878        src/widgets/UIProgressDialog.cpp \
     879        src/widgets/UIStatusBarEditorWindow.cpp
    879880
    880881 VirtualBox_QT_MOCSRCS.linux += \
     
    917918        src/widgets/UIHotKeyEditor.cpp \
    918919        src/widgets/UIPortForwardingTable.cpp \
    919         src/widgets/UIProgressDialog.cpp
     920        src/widgets/UIProgressDialog.cpp \
     921        src/widgets/UIStatusBarEditorWindow.cpp
    920922
    921923VBoxGlobal_QT_MOCSRCS.linux += \
     
    974976        src/runtime/UISession.cpp \
    975977        src/runtime/UISlidingToolBar.cpp \
    976         src/runtime/UIStatusBarEditorWindow.cpp \
    977978        src/runtime/UIVMCloseDialog.cpp \
    978979        src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp \
     
    12351236        src/widgets/UIProgressDialog.cpp \
    12361237        src/widgets/UISpecialControls.cpp \
     1238        src/widgets/UIStatusBarEditorWindow.cpp \
    12371239        src/widgets/UIToolBar.cpp \
    12381240        src/widgets/UIWarningPane.cpp \
     
    13691371        src/widgets/UIProgressDialog.cpp \
    13701372        src/widgets/UISpecialControls.cpp \
     1373        src/widgets/UIStatusBarEditorWindow.cpp \
    13711374        src/widgets/UIToolBar.cpp \
    13721375        src/widgets/UIWarningPane.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIStatusBarEditorWindow.cpp

    r72025 r72026  
    55
    66/*
    7  * Copyright (C) 2014-2017 Oracle Corporation
     7 * Copyright (C) 2014-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222/* Qt includes: */
    2323# include <QAccessibleWidget>
     24# include <QCheckBox>
     25# include <QDrag>
     26# include <QHBoxLayout>
     27# include <QMimeData>
     28# include <QMouseEvent>
     29# include <QPainter>
     30# include <QPaintEvent>
     31# include <QPixmap>
     32# include <QStatusBar>
     33# include <QStyleOption>
    2434# include <QStylePainter>
    25 # include <QStyleOption>
    26 # include <QHBoxLayout>
    27 # include <QPaintEvent>
    28 # include <QMouseEvent>
    29 # include <QStatusBar>
    30 # include <QCheckBox>
    31 # include <QMimeData>
    32 # include <QPainter>
    33 # include <QPixmap>
    34 # include <QDrag>
    3535
    3636/* GUI includes: */
    37 # include "UIStatusBarEditorWindow.h"
    38 # include "UIExtraDataManager.h"
    39 # include "UIMachineWindow.h"
    40 # include "UIConverter.h"
    41 # include "UIIconPool.h"
    4237# include "QIToolButton.h"
    4338# include "VBoxGlobal.h"
     39# include "UIConverter.h"
     40# include "UIExtraDataManager.h"
     41# include "UIIconPool.h"
     42# include "UIMachineWindow.h"
     43# include "UIStatusBarEditorWindow.h"
    4444
    4545#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4646
    47 
    48 /** QWidget extension
    49   * used as status-bar editor button. */
     47/* Forward declarations: */
     48class QAccessibleInterface;
     49class QMouseEvent;
     50class QObject;
     51class QPixmap;
     52class QPoint;
     53class QSize;
     54
     55
     56/** QWidget subclass used as status-bar editor button. */
    5057class UIStatusBarEditorButton : public QIWithRetranslateUI<QWidget>
    5158{
     
    6572    static const QString MimeType;
    6673
    67     /** Constructor for the button of passed @a type. */
    68     UIStatusBarEditorButton(IndicatorType type);
     74    /** Constructs the button of passed @a enmType. */
     75    UIStatusBarEditorButton(IndicatorType enmType);
    6976
    7077    /** Returns button type. */
    71     IndicatorType type() const { return m_type; }
     78    IndicatorType type() const { return m_enmType; }
    7279
    7380    /** Returns button size-hint. */
     
    7986    void setChecked(bool fChecked);
    8087
     88protected:
     89
     90    /** Handles translation event. */
     91    virtual void retranslateUi() /* override */;
     92
     93    /** Handles paint @a pEvent. */
     94    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     95
     96    /** Handles mouse-press @a pEvent. */
     97    virtual void mousePressEvent(QMouseEvent *pEvent);
     98    /** Handles mouse-release @a pEvent. */
     99    virtual void mouseReleaseEvent(QMouseEvent *pEvent);
     100    /** Handles mouse-enter @a pEvent. */
     101    virtual void enterEvent(QEvent *pEvent);
     102    /** Handles mouse-leave @a pEvent. */
     103    virtual void leaveEvent(QEvent *pEvent);
     104    /** Handles mouse-move @a pEvent. */
     105    virtual void mouseMoveEvent(QMouseEvent *pEvent);
     106
    81107private:
    82108
    83     /** Retranslation routine. */
    84     virtual void retranslateUi();
    85 
    86     /** Paint-event handler. */
    87     virtual void paintEvent(QPaintEvent *pEvent);
    88 
    89     /** Mouse-press event handler. */
    90     virtual void mousePressEvent(QMouseEvent *pEvent);
    91     /** Mouse-release event handler. */
    92     virtual void mouseReleaseEvent(QMouseEvent *pEvent);
    93     /** Mouse-enter event handler. */
    94     virtual void enterEvent(QEvent *pEvent);
    95     /** Mouse-leave event handler. */
    96     virtual void leaveEvent(QEvent *pEvent);
    97     /** Mouse-move event handler. */
    98     virtual void mouseMoveEvent(QMouseEvent *pEvent);
    99 
    100109    /** Holds the button type. */
    101     IndicatorType m_type;
     110    IndicatorType  m_enmType;
    102111    /** Holds the button size. */
    103     QSize m_size;
     112    QSize          m_size;
    104113    /** Holds the button pixmap. */
    105     QPixmap m_pixmap;
     114    QPixmap        m_pixmap;
    106115    /** Holds the button pixmap size. */
    107     QSize m_pixmapSize;
     116    QSize          m_pixmapSize;
    108117    /** Holds whether button is checked. */
    109     bool m_fChecked;
     118    bool           m_fChecked;
    110119    /** Holds whether button is hovered. */
    111     bool m_fHovered;
     120    bool           m_fHovered;
    112121    /** Holds the last mouse-press position. */
    113     QPoint m_mousePressPosition;
     122    QPoint         m_mousePressPosition;
    114123};
    115124
     
    186195
    187196
    188 
    189197/*********************************************************************************************************************************
    190198*   Class UIStatusBarEditorButton implementation.                                                                                *
     
    194202const QString UIStatusBarEditorButton::MimeType = QString("application/virtualbox;value=IndicatorType");
    195203
    196 UIStatusBarEditorButton::UIStatusBarEditorButton(IndicatorType type)
    197     : m_type(type)
     204UIStatusBarEditorButton::UIStatusBarEditorButton(IndicatorType enmType)
     205    : m_enmType(enmType)
    198206    , m_fChecked(false)
    199207    , m_fHovered(false)
     
    203211
    204212    /* Prepare icon for assigned type: */
    205     const QIcon icon = gpConverter->toIcon(m_type);
     213    const QIcon icon = gpConverter->toIcon(m_enmType);
    206214    const QStyle *pStyle = QApplication::style();
    207215    const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
     
    239247}
    240248
    241 void UIStatusBarEditorButton::paintEvent(QPaintEvent*)
     249void UIStatusBarEditorButton::paintEvent(QPaintEvent *)
    242250{
    243251    /* Create style-painter: */
     
    290298}
    291299
    292 void UIStatusBarEditorButton::enterEvent(QEvent*)
     300void UIStatusBarEditorButton::enterEvent(QEvent *)
    293301{
    294302    /* Make sure button isn't hovered: */
     
    302310}
    303311
    304 void UIStatusBarEditorButton::leaveEvent(QEvent*)
     312void UIStatusBarEditorButton::leaveEvent(QEvent *)
    305313{
    306314    /* Make sure button is hovered: */
     
    335343    connect(pDrag, SIGNAL(destroyed(QObject*)), this, SIGNAL(sigDragObjectDestroy()));
    336344    QMimeData *pMimeData = new QMimeData;
    337     pMimeData->setData(MimeType, gpConverter->toInternalString(m_type).toLatin1());
     345    pMimeData->setData(MimeType, gpConverter->toInternalString(m_enmType).toLatin1());
    338346    pDrag->setMimeData(pMimeData);
    339347    pDrag->setPixmap(m_pixmap);
     
    341349}
    342350
     351
     352/*********************************************************************************************************************************
     353*   Class UIStatusBarEditorWindow implementation.                                                                                *
     354*********************************************************************************************************************************/
     355
     356UIStatusBarEditorWindow::UIStatusBarEditorWindow(UIMachineWindow *pParent)
     357    : UISlidingToolBar(pParent, pParent->statusBar(), new UIStatusBarEditorWidget(0, false, vboxGlobal().managedVMUuid()), UISlidingToolBar::Position_Bottom)
     358{
     359}
     360
     361
     362/*********************************************************************************************************************************
     363*   Class UIStatusBarEditorWidget implementation.                                                                                *
     364*********************************************************************************************************************************/
    343365
    344366UIStatusBarEditorWidget::UIStatusBarEditorWidget(QWidget *pParent,
     
    402424
    403425    /* Update configuration for all existing buttons: */
    404     foreach (const IndicatorType &type, m_order)
     426    foreach (const IndicatorType &enmType, m_order)
    405427    {
    406428        /* Get button: */
    407         UIStatusBarEditorButton *pButton = m_buttons.value(type);
     429        UIStatusBarEditorButton *pButton = m_buttons.value(enmType);
    408430        /* Make sure button exists: */
    409431        if (!pButton)
    410432            continue;
    411433        /* Update button 'checked' state: */
    412         pButton->setChecked(!m_restrictions.contains(type));
     434        pButton->setChecked(!m_restrictions.contains(enmType));
    413435        /* Make sure it have valid position: */
    414         const int iWantedIndex = position(type);
     436        const int iWantedIndex = position(enmType);
    415437        const int iActualIndex = m_pButtonLayout->indexOf(pButton);
    416438        if (iActualIndex != iWantedIndex)
     
    423445}
    424446
     447void UIStatusBarEditorWidget::retranslateUi()
     448{
     449    /* Translate close-button if necessary: */
     450    if (!m_fStartedFromVMSettings && m_pButtonClose)
     451        m_pButtonClose->setToolTip(tr("Close"));
     452    /* Translate enable-checkbox if necessary: */
     453    if (m_fStartedFromVMSettings && m_pCheckBoxEnable)
     454        m_pCheckBoxEnable->setToolTip(tr("Enable Status Bar"));
     455}
     456
     457void UIStatusBarEditorWidget::paintEvent(QPaintEvent *)
     458{
     459    /* Prepare painter: */
     460    QPainter painter(this);
     461
     462    /* Prepare palette colors: */
     463    const QPalette pal = palette();
     464    QColor color0 = pal.color(QPalette::Window);
     465    QColor color1 = pal.color(QPalette::Window).lighter(110);
     466    color1.setAlpha(0);
     467    QColor color2 = pal.color(QPalette::Window).darker(200);
     468#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
     469    QColor color3 = pal.color(QPalette::Window).darker(120);
     470#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
     471
     472    /* Acquire metric: */
     473    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     474
     475    /* Left corner: */
     476    QRadialGradient grad1(QPointF(iMetric, iMetric), iMetric);
     477    {
     478        grad1.setColorAt(0, color2);
     479        grad1.setColorAt(1, color1);
     480    }
     481    /* Right corner: */
     482    QRadialGradient grad2(QPointF(width() - iMetric, iMetric), iMetric);
     483    {
     484        grad2.setColorAt(0, color2);
     485        grad2.setColorAt(1, color1);
     486    }
     487    /* Top line: */
     488    QLinearGradient grad3(QPointF(iMetric, 0), QPointF(iMetric, iMetric));
     489    {
     490        grad3.setColorAt(0, color1);
     491        grad3.setColorAt(1, color2);
     492    }
     493    /* Left line: */
     494    QLinearGradient grad4(QPointF(0, iMetric), QPointF(iMetric, iMetric));
     495    {
     496        grad4.setColorAt(0, color1);
     497        grad4.setColorAt(1, color2);
     498    }
     499    /* Right line: */
     500    QLinearGradient grad5(QPointF(width(), iMetric), QPointF(width() - iMetric, iMetric));
     501    {
     502        grad5.setColorAt(0, color1);
     503        grad5.setColorAt(1, color2);
     504    }
     505
     506    /* Paint shape/shadow: */
     507    painter.fillRect(QRect(iMetric, iMetric, width() - iMetric * 2, height() - iMetric), color0); // background
     508    painter.fillRect(QRect(0,                 0, iMetric, iMetric), grad1); // left corner
     509    painter.fillRect(QRect(width() - iMetric, 0, iMetric, iMetric), grad2); // right corner
     510    painter.fillRect(QRect(iMetric,           0, width() - iMetric * 2, iMetric), grad3); // bottom line
     511    painter.fillRect(QRect(0,                 iMetric, iMetric, height() - iMetric), grad4); // left line
     512    painter.fillRect(QRect(width() - iMetric, iMetric, iMetric, height() - iMetric), grad5); // right line
     513
     514#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
     515    /* Paint frames: */
     516    painter.save();
     517    painter.setPen(color3);
     518    painter.drawLine(QLine(QPoint(iMetric + 1,               iMetric + 1),
     519                           QPoint(width() - 1 - iMetric - 1, iMetric + 1)));
     520    painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, iMetric + 1),
     521                           QPoint(width() - 1 - iMetric - 1, height() - 1)));
     522    painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1),
     523                           QPoint(iMetric + 1,               height() - 1)));
     524    painter.drawLine(QLine(QPoint(iMetric + 1,               height() - 1),
     525                           QPoint(iMetric + 1,               iMetric + 1)));
     526    painter.restore();
     527#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
     528
     529    /* Paint drop token: */
     530    if (m_pButtonDropToken)
     531    {
     532        QStyleOption option;
     533        option.state |= QStyle::State_Horizontal;
     534        const QRect geo = m_pButtonDropToken->geometry();
     535        option.rect = !m_fDropAfterTokenButton ?
     536                      QRect(geo.topLeft() - QPoint(iMetric, iMetric),
     537                            geo.bottomLeft() + QPoint(0, iMetric)) :
     538                      QRect(geo.topRight() - QPoint(0, iMetric),
     539                            geo.bottomRight() + QPoint(iMetric, iMetric));
     540        QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator,
     541                                             &option, &painter);
     542    }
     543}
     544
     545void UIStatusBarEditorWidget::dragEnterEvent(QDragEnterEvent *pEvent)
     546{
     547    /* Make sure event is valid: */
     548    AssertPtrReturnVoid(pEvent);
     549    /* And mime-data is set: */
     550    const QMimeData *pMimeData = pEvent->mimeData();
     551    AssertPtrReturnVoid(pMimeData);
     552    /* Make sure mime-data format is valid: */
     553    if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
     554        return;
     555
     556    /* Accept drag-enter event: */
     557    pEvent->acceptProposedAction();
     558}
     559
     560void UIStatusBarEditorWidget::dragMoveEvent(QDragMoveEvent *pEvent)
     561{
     562    /* Make sure event is valid: */
     563    AssertPtrReturnVoid(pEvent);
     564    /* And mime-data is set: */
     565    const QMimeData *pMimeData = pEvent->mimeData();
     566    AssertPtrReturnVoid(pMimeData);
     567    /* Make sure mime-data format is valid: */
     568    if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
     569        return;
     570
     571    /* Reset token: */
     572    m_pButtonDropToken = 0;
     573    m_fDropAfterTokenButton = true;
     574
     575    /* Get event position: */
     576    const QPoint pos = pEvent->pos();
     577    /* Search for most suitable button: */
     578    foreach (const IndicatorType &enmType, m_order)
     579    {
     580        m_pButtonDropToken = m_buttons.value(enmType);
     581        const QRect geo = m_pButtonDropToken->geometry();
     582        if (pos.x() < geo.center().x())
     583        {
     584            m_fDropAfterTokenButton = false;
     585            break;
     586        }
     587    }
     588    /* Update: */
     589    update();
     590}
     591
     592void UIStatusBarEditorWidget::dragLeaveEvent(QDragLeaveEvent *)
     593{
     594    /* Reset token: */
     595    m_pButtonDropToken = 0;
     596    m_fDropAfterTokenButton = true;
     597    /* Update: */
     598    update();
     599}
     600
     601void UIStatusBarEditorWidget::dropEvent(QDropEvent *pEvent)
     602{
     603    /* Make sure event is valid: */
     604    AssertPtrReturnVoid(pEvent);
     605    /* And mime-data is set: */
     606    const QMimeData *pMimeData = pEvent->mimeData();
     607    AssertPtrReturnVoid(pMimeData);
     608    /* Make sure mime-data format is valid: */
     609    if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
     610        return;
     611
     612    /* Make sure token-button set: */
     613    if (!m_pButtonDropToken)
     614        return;
     615
     616    /* Determine type of token-button: */
     617    const IndicatorType tokenType = m_pButtonDropToken->type();
     618    /* Determine type of dropped-button: */
     619    const QString strDroppedType =
     620        QString::fromLatin1(pMimeData->data(UIStatusBarEditorButton::MimeType));
     621    const IndicatorType droppedType =
     622        gpConverter->fromInternalString<IndicatorType>(strDroppedType);
     623
     624    /* Make sure these types are different: */
     625    if (droppedType == tokenType)
     626        return;
     627
     628    /* Remove type of dropped-button: */
     629    m_order.removeAll(droppedType);
     630    /* Insert type of dropped-button into position of token-button: */
     631    int iPosition = m_order.indexOf(tokenType);
     632    if (m_fDropAfterTokenButton)
     633        ++iPosition;
     634    m_order.insert(iPosition, droppedType);
     635
     636    if (m_fStartedFromVMSettings)
     637    {
     638        /* Reapply status-bar configuration from cache: */
     639        setStatusBarConfiguration(m_restrictions, m_order);
     640    }
     641    else
     642    {
     643        /* Save updated status-bar indicator order: */
     644        gEDataManager->setStatusBarIndicatorOrder(m_order, machineID());
     645    }
     646}
     647
    425648void UIStatusBarEditorWidget::sltHandleConfigurationChange(const QString &strMachineID)
    426649{
     
    441664
    442665    /* Get sender type: */
    443     const IndicatorType type = pButton->type();
     666    const IndicatorType enmType = pButton->type();
    444667
    445668    /* Invert restriction for sender type: */
    446     if (m_restrictions.contains(type))
    447         m_restrictions.removeAll(type);
     669    if (m_restrictions.contains(enmType))
     670        m_restrictions.removeAll(enmType);
    448671    else
    449         m_restrictions.append(type);
     672        m_restrictions.append(enmType);
    450673
    451674    if (m_fStartedFromVMSettings)
     
    570793    {
    571794        /* Get current type: */
    572         const IndicatorType type = (IndicatorType)i;
     795        const IndicatorType enmType = (IndicatorType)i;
    573796        /* Skip inappropriate types: */
    574         if (type == IndicatorType_Invalid || type == IndicatorType_KeyboardExtension)
     797        if (enmType == IndicatorType_Invalid || enmType == IndicatorType_KeyboardExtension)
    575798            continue;
    576799        /* Create status button: */
    577         prepareStatusButton(type);
     800        prepareStatusButton(enmType);
    578801    }
    579802
     
    589812}
    590813
    591 void UIStatusBarEditorWidget::prepareStatusButton(IndicatorType type)
     814void UIStatusBarEditorWidget::prepareStatusButton(IndicatorType enmType)
    592815{
    593816    /* Create status button: */
    594     UIStatusBarEditorButton *pButton = new UIStatusBarEditorButton(type);
     817    UIStatusBarEditorButton *pButton = new UIStatusBarEditorButton(enmType);
    595818    AssertPtrReturnVoid(pButton);
    596819    {
     
    601824        m_pButtonLayout->addWidget(pButton);
    602825        /* Insert status button into map: */
    603         m_buttons.insert(type, pButton);
    604     }
    605 }
    606 
    607 void UIStatusBarEditorWidget::retranslateUi()
    608 {
    609     /* Translate close-button if necessary: */
    610     if (!m_fStartedFromVMSettings && m_pButtonClose)
    611         m_pButtonClose->setToolTip(tr("Close"));
    612     /* Translate enable-checkbox if necessary: */
    613     if (m_fStartedFromVMSettings && m_pCheckBoxEnable)
    614         m_pCheckBoxEnable->setToolTip(tr("Enable Status Bar"));
    615 }
    616 
    617 void UIStatusBarEditorWidget::paintEvent(QPaintEvent*)
    618 {
    619     /* Prepare painter: */
    620     QPainter painter(this);
    621 
    622     /* Prepare palette colors: */
    623     const QPalette pal = palette();
    624     QColor color0 = pal.color(QPalette::Window);
    625     QColor color1 = pal.color(QPalette::Window).lighter(110);
    626     color1.setAlpha(0);
    627     QColor color2 = pal.color(QPalette::Window).darker(200);
    628 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
    629     QColor color3 = pal.color(QPalette::Window).darker(120);
    630 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    631 
    632     /* Acquire metric: */
    633     const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
    634 
    635     /* Left corner: */
    636     QRadialGradient grad1(QPointF(iMetric, iMetric), iMetric);
    637     {
    638         grad1.setColorAt(0, color2);
    639         grad1.setColorAt(1, color1);
    640     }
    641     /* Right corner: */
    642     QRadialGradient grad2(QPointF(width() - iMetric, iMetric), iMetric);
    643     {
    644         grad2.setColorAt(0, color2);
    645         grad2.setColorAt(1, color1);
    646     }
    647     /* Top line: */
    648     QLinearGradient grad3(QPointF(iMetric, 0), QPointF(iMetric, iMetric));
    649     {
    650         grad3.setColorAt(0, color1);
    651         grad3.setColorAt(1, color2);
    652     }
    653     /* Left line: */
    654     QLinearGradient grad4(QPointF(0, iMetric), QPointF(iMetric, iMetric));
    655     {
    656         grad4.setColorAt(0, color1);
    657         grad4.setColorAt(1, color2);
    658     }
    659     /* Right line: */
    660     QLinearGradient grad5(QPointF(width(), iMetric), QPointF(width() - iMetric, iMetric));
    661     {
    662         grad5.setColorAt(0, color1);
    663         grad5.setColorAt(1, color2);
    664     }
    665 
    666     /* Paint shape/shadow: */
    667     painter.fillRect(QRect(iMetric, iMetric, width() - iMetric * 2, height() - iMetric), color0); // background
    668     painter.fillRect(QRect(0,                 0, iMetric, iMetric), grad1); // left corner
    669     painter.fillRect(QRect(width() - iMetric, 0, iMetric, iMetric), grad2); // right corner
    670     painter.fillRect(QRect(iMetric,           0, width() - iMetric * 2, iMetric), grad3); // bottom line
    671     painter.fillRect(QRect(0,                 iMetric, iMetric, height() - iMetric), grad4); // left line
    672     painter.fillRect(QRect(width() - iMetric, iMetric, iMetric, height() - iMetric), grad5); // right line
    673 
    674 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
    675     /* Paint frames: */
    676     painter.save();
    677     painter.setPen(color3);
    678     painter.drawLine(QLine(QPoint(iMetric + 1,               iMetric + 1),
    679                            QPoint(width() - 1 - iMetric - 1, iMetric + 1)));
    680     painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, iMetric + 1),
    681                            QPoint(width() - 1 - iMetric - 1, height() - 1)));
    682     painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1),
    683                            QPoint(iMetric + 1,               height() - 1)));
    684     painter.drawLine(QLine(QPoint(iMetric + 1,               height() - 1),
    685                            QPoint(iMetric + 1,               iMetric + 1)));
    686     painter.restore();
    687 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    688 
    689     /* Paint drop token: */
    690     if (m_pButtonDropToken)
    691     {
    692         QStyleOption option;
    693         option.state |= QStyle::State_Horizontal;
    694         const QRect geo = m_pButtonDropToken->geometry();
    695         option.rect = !m_fDropAfterTokenButton ?
    696                       QRect(geo.topLeft() - QPoint(iMetric, iMetric),
    697                             geo.bottomLeft() + QPoint(0, iMetric)) :
    698                       QRect(geo.topRight() - QPoint(0, iMetric),
    699                             geo.bottomRight() + QPoint(iMetric, iMetric));
    700         QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator,
    701                                              &option, &painter);
    702     }
    703 }
    704 
    705 void UIStatusBarEditorWidget::dragEnterEvent(QDragEnterEvent *pEvent)
    706 {
    707     /* Make sure event is valid: */
    708     AssertPtrReturnVoid(pEvent);
    709     /* And mime-data is set: */
    710     const QMimeData *pMimeData = pEvent->mimeData();
    711     AssertPtrReturnVoid(pMimeData);
    712     /* Make sure mime-data format is valid: */
    713     if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
    714         return;
    715 
    716     /* Accept drag-enter event: */
    717     pEvent->acceptProposedAction();
    718 }
    719 
    720 void UIStatusBarEditorWidget::dragMoveEvent(QDragMoveEvent *pEvent)
    721 {
    722     /* Make sure event is valid: */
    723     AssertPtrReturnVoid(pEvent);
    724     /* And mime-data is set: */
    725     const QMimeData *pMimeData = pEvent->mimeData();
    726     AssertPtrReturnVoid(pMimeData);
    727     /* Make sure mime-data format is valid: */
    728     if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
    729         return;
    730 
    731     /* Reset token: */
    732     m_pButtonDropToken = 0;
    733     m_fDropAfterTokenButton = true;
    734 
    735     /* Get event position: */
    736     const QPoint pos = pEvent->pos();
    737     /* Search for most suitable button: */
    738     foreach (const IndicatorType &type, m_order)
    739     {
    740         m_pButtonDropToken = m_buttons.value(type);
    741         const QRect geo = m_pButtonDropToken->geometry();
    742         if (pos.x() < geo.center().x())
    743         {
    744             m_fDropAfterTokenButton = false;
    745             break;
    746         }
    747     }
    748     /* Update: */
    749     update();
    750 }
    751 
    752 void UIStatusBarEditorWidget::dragLeaveEvent(QDragLeaveEvent*)
    753 {
    754     /* Reset token: */
    755     m_pButtonDropToken = 0;
    756     m_fDropAfterTokenButton = true;
    757     /* Update: */
    758     update();
    759 }
    760 
    761 void UIStatusBarEditorWidget::dropEvent(QDropEvent *pEvent)
    762 {
    763     /* Make sure event is valid: */
    764     AssertPtrReturnVoid(pEvent);
    765     /* And mime-data is set: */
    766     const QMimeData *pMimeData = pEvent->mimeData();
    767     AssertPtrReturnVoid(pMimeData);
    768     /* Make sure mime-data format is valid: */
    769     if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType))
    770         return;
    771 
    772     /* Make sure token-button set: */
    773     if (!m_pButtonDropToken)
    774         return;
    775 
    776     /* Determine type of token-button: */
    777     const IndicatorType tokenType = m_pButtonDropToken->type();
    778     /* Determine type of dropped-button: */
    779     const QString strDroppedType =
    780         QString::fromLatin1(pMimeData->data(UIStatusBarEditorButton::MimeType));
    781     const IndicatorType droppedType =
    782         gpConverter->fromInternalString<IndicatorType>(strDroppedType);
    783 
    784     /* Make sure these types are different: */
    785     if (droppedType == tokenType)
    786         return;
    787 
    788     /* Remove type of dropped-button: */
    789     m_order.removeAll(droppedType);
    790     /* Insert type of dropped-button into position of token-button: */
    791     int iPosition = m_order.indexOf(tokenType);
    792     if (m_fDropAfterTokenButton)
    793         ++iPosition;
    794     m_order.insert(iPosition, droppedType);
    795 
    796     if (m_fStartedFromVMSettings)
    797     {
    798         /* Reapply status-bar configuration from cache: */
    799         setStatusBarConfiguration(m_restrictions, m_order);
    800     }
    801     else
    802     {
    803         /* Save updated status-bar indicator order: */
    804         gEDataManager->setStatusBarIndicatorOrder(m_order, machineID());
    805     }
    806 }
    807 
    808 int UIStatusBarEditorWidget::position(IndicatorType type) const
     826        m_buttons.insert(enmType, pButton);
     827    }
     828}
     829
     830int UIStatusBarEditorWidget::position(IndicatorType enmType) const
    809831{
    810832    int iPosition = 0;
    811833    foreach (const IndicatorType &iteratedType, m_order)
    812         if (iteratedType == type)
     834        if (iteratedType == enmType)
    813835            return iPosition;
    814836        else
     
    818840
    819841
    820 UIStatusBarEditorWindow::UIStatusBarEditorWindow(UIMachineWindow *pParent)
    821     : UISlidingToolBar(pParent, pParent->statusBar(), new UIStatusBarEditorWidget(0, false, vboxGlobal().managedVMUuid()), UISlidingToolBar::Position_Bottom)
    822 {
    823 }
    824 
    825842#include "UIStatusBarEditorWindow.moc"
    826 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIStatusBarEditorWindow.h

    r72025 r72026  
    55
    66/*
    7  * Copyright (C) 2014-2017 Oracle Corporation
     7 * Copyright (C) 2014-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020
    2121/* Qt includes: */
     22#include <QList>
    2223#include <QMap>
    23 #include <QList>
    2424
    2525/* GUI includes: */
     26#include "QIWithRetranslateUI.h"
    2627#include "UIExtraDataDefs.h"
     28#include "UILibraryDefs.h"
    2729#include "UISlidingToolBar.h"
    28 #include "QIWithRetranslateUI.h"
    2930
    3031/* Forward declarations: */
     32class QCheckBox;
     33class QDragEnterEvent;
     34class QDragLeaveEvent;
     35class QDragMoveEvent;
     36class QDropEvent;
     37class QHBoxLayout;
     38class QPaintEvent;
     39class QString;
     40class QWidget;
     41class QIToolButton;
     42class UIMachineWindow;
    3143class UIStatusBarEditorButton;
    32 class UIMachineWindow;
    33 class QIToolButton;
    34 class QHBoxLayout;
    35 class QCheckBox;
    3644
    37 /** UISlidingToolBar wrapper
     45
     46/** UISlidingToolBar subclass
    3847  * providing user with possibility to edit status-bar layout. */
    39 class UIStatusBarEditorWindow : public UISlidingToolBar
     48class SHARED_LIBRARY_STUFF UIStatusBarEditorWindow : public UISlidingToolBar
    4049{
    4150    Q_OBJECT;
     
    4352public:
    4453
    45     /** Constructor, passes @a pParent to the UISlidingToolBar constructor. */
     54    /** Constructs sliding toolbar passing @a pParent to the base-class. */
    4655    UIStatusBarEditorWindow(UIMachineWindow *pParent);
    4756};
    4857
    49 /** QWidget reimplementation
     58
     59/** QWidget subclass
    5060  * used as status-bar editor widget. */
    51 class UIStatusBarEditorWidget : public QIWithRetranslateUI2<QWidget>
     61class SHARED_LIBRARY_STUFF UIStatusBarEditorWidget : public QIWithRetranslateUI2<QWidget>
    5262{
    5363    Q_OBJECT;
     
    6070public:
    6171
    62     /** Constructor,
    63       * @param pParent                is passed to QWidget constructor,
    64       * @param fStartedFromVMSettings determines whether 'this' is a part of VM settings,
    65       * @param strMachineID           brings the machine ID to be used by the editor. */
     72    /** Constructs status-bar editor widget passing @a pParent to the base-class.
     73      * @param  fStartedFromVMSettings  Brings whether 'this' is a part of VM settings.
     74      * @param  strMachineID            Brings the machine ID to be used by the editor. */
    6675    UIStatusBarEditorWidget(QWidget *pParent,
    6776                            bool fStartedFromVMSettings = true,
     
    6978
    7079    /** Returns the machine ID instance. */
    71     const QString& machineID() const { return m_strMachineID; }
     80    const QString &machineID() const { return m_strMachineID; }
    7281    /** Defines the @a strMachineID instance. */
    7382    void setMachineID(const QString &strMachineID);
     
    7988
    8089    /** Returns status-bar indicator restrictions. */
    81     const QList<IndicatorType>& statusBarIndicatorRestrictions() const { return m_restrictions; }
     90    const QList<IndicatorType> &statusBarIndicatorRestrictions() const { return m_restrictions; }
    8291    /** Returns status-bar indicator order. */
    83     const QList<IndicatorType>& statusBarIndicatorOrder() const { return m_order; }
     92    const QList<IndicatorType> &statusBarIndicatorOrder() const { return m_order; }
    8493    /** Defines status-bar indicator @a restrictions and @a order. */
    8594    void setStatusBarConfiguration(const QList<IndicatorType> &restrictions, const QList<IndicatorType> &order);
     95
     96protected:
     97
     98    /** Handles translation event. */
     99    virtual void retranslateUi() /* override */;
     100
     101    /** Handles paint @a pEvent. */
     102    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     103
     104    /** Handles drag-enter @a pEvent. */
     105    virtual void dragEnterEvent(QDragEnterEvent *pEvent) /* override */;
     106    /** Handles drag-move @a pEvent. */
     107    virtual void dragMoveEvent(QDragMoveEvent *pEvent) /* override */;
     108    /** Handles drag-leave @a pEvent. */
     109    virtual void dragLeaveEvent(QDragLeaveEvent *pEvent) /* override */;
     110    /** Handles drop @a pEvent. */
     111    virtual void dropEvent(QDropEvent *pEvent) /* override */;
    86112
    87113private slots:
     
    98124private:
    99125
    100     /** Prepare routine. */
     126    /** Prepares all. */
    101127    void prepare();
    102     /** Prepare status buttons routine. */
     128    /** Prepares status-buttons. */
    103129    void prepareStatusButtons();
    104     /** Prepare status button routine. */
    105     void prepareStatusButton(IndicatorType type);
     130    /** Prepares status-button of certain @a enmType. */
     131    void prepareStatusButton(IndicatorType enmType);
    106132
    107     /** Retranslation routine. */
    108     virtual void retranslateUi();
    109 
    110     /** Paint event handler. */
    111     virtual void paintEvent(QPaintEvent *pEvent);
    112 
    113     /** Drag-enter event handler. */
    114     virtual void dragEnterEvent(QDragEnterEvent *pEvent);
    115     /** Drag-move event handler. */
    116     virtual void dragMoveEvent(QDragMoveEvent *pEvent);
    117     /** Drag-leave event handler. */
    118     virtual void dragLeaveEvent(QDragLeaveEvent *pEvent);
    119     /** Drop event handler. */
    120     virtual void dropEvent(QDropEvent *pEvent);
    121 
    122     /** Returns position for passed @a type. */
    123     int position(IndicatorType type) const;
     133    /** Returns position for passed @a enmType. */
     134    int position(IndicatorType enmType) const;
    124135
    125136    /** @name General
    126137      * @{ */
    127138        /** Holds whether 'this' is prepared. */
    128         bool m_fPrepared;
     139        bool     m_fPrepared;
    129140        /** Holds whether 'this' is a part of VM settings. */
    130         bool m_fStartedFromVMSettings;
     141        bool     m_fStartedFromVMSettings;
    131142        /** Holds the machine ID instance. */
    132         QString m_strMachineID;
     143        QString  m_strMachineID;
    133144    /** @} */
    134145
     
    136147      * @{ */
    137148        /** Holds the main-layout instance. */
    138         QHBoxLayout *m_pMainLayout;
     149        QHBoxLayout                                   *m_pMainLayout;
    139150        /** Holds the button-layout instance. */
    140         QHBoxLayout *m_pButtonLayout;
     151        QHBoxLayout                                   *m_pButtonLayout;
    141152        /** Holds the close-button instance. */
    142         QIToolButton *m_pButtonClose;
     153        QIToolButton                                  *m_pButtonClose;
    143154        /** Holds the enable-checkbox instance. */
    144         QCheckBox *m_pCheckBoxEnable;
     155        QCheckBox                                     *m_pCheckBoxEnable;
    145156        /** Holds status-bar buttons. */
    146         QMap<IndicatorType, UIStatusBarEditorButton*> m_buttons;
     157        QMap<IndicatorType, UIStatusBarEditorButton*>  m_buttons;
    147158    /** @} */
    148159
     
    150161      * @{ */
    151162        /** Holds the cached status-bar button restrictions. */
    152         QList<IndicatorType> m_restrictions;
     163        QList<IndicatorType>  m_restrictions;
    153164    /** @} */
    154165
     
    156167      * @{ */
    157168        /** Holds the cached status-bar button order. */
    158         QList<IndicatorType> m_order;
     169        QList<IndicatorType>     m_order;
    159170        /** Holds the token-button to drop dragged-button nearby. */
    160171        UIStatusBarEditorButton *m_pButtonDropToken;
    161172        /** Holds whether dragged-button should be dropped <b>after</b> the token-button. */
    162         bool m_fDropAfterTokenButton;
     173        bool                     m_fDropAfterTokenButton;
    163174    /** @} */
    164175};
    165176
     177
    166178#endif /* !___UIStatusBarEditorWindow_h___ */
Note: See TracChangeset for help on using the changeset viewer.

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