VirtualBox

Changeset 51873 in vbox for trunk/src


Ignore:
Timestamp:
Jul 4, 2014 4:22:24 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Message Center: Heavy QIMessageBox rework for advanced details formatting support.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 deleted
12 edited

Legend:

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

    r51770 r51873  
    268268        src/extensions/QITableView.h \
    269269        src/extensions/QIToolButton.h \
    270         src/extensions/QITextEdit.h \
    271270        src/extensions/QITreeView.h \
    272271        src/extensions/QITreeWidget.h \
     
    465464VirtualBox_QT_MOCSRCS = \
    466465        src/UIVMLogViewer.cpp \
     466        src/extensions/QIArrowSplitter.cpp \
    467467        src/extensions/QISplitter.cpp \
    468468        src/extensions/QIAdvancedToolBar.cpp \
     
    535535        src/extensions/QIStatusBar.cpp \
    536536        src/extensions/QITableView.cpp \
    537         src/extensions/QITextEdit.cpp \
    538537        src/extensions/QITreeView.cpp \
    539538        src/extensions/QITreeWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonPress.cpp

    r44528 r51873  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QIArrowButtonPress class implementation
     3 * VBox Qt GUI - QIArrowButtonPress class implementation.
    64 */
    75
    86/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1816 */
    1917
    20 /* VBox includes */
    21 #include "QIArrowButtonPress.h"
    22 #include "UIIconPool.h"
    23 
    24 /* Qt includes */
     18/* Qt includes: */
    2519#include <QKeyEvent>
    2620
     21/* GUI includes: */
     22#include "QIArrowButtonPress.h"
    2723
    28 /** @class QIArrowButtonPress
    29  *
    30  *  The QIArrowButtonPress class is an arrow tool-button with text-label,
    31  *  used as back/next buttons in QIMessageBox class.
    32  *
    33  */
    34 
    35 QIArrowButtonPress::QIArrowButtonPress (QWidget *aParent)
    36     : QIRichToolButton (aParent)
    37     , mNext (true)
     24QIArrowButtonPress::QIArrowButtonPress(QIArrowButtonPress::ButtonType buttonType,
     25                                       QWidget *pParent /* = 0 */)
     26    : QIWithRetranslateUI<QIRichToolButton>(pParent)
     27    , m_buttonType(buttonType)
    3828{
    39     updateIcon();
     29    /* Retranslate UI: */
     30    retranslateUi();
    4031}
    4132
    42 QIArrowButtonPress::QIArrowButtonPress (bool aNext, const QString &aName, QWidget *aParent)
    43     : QIRichToolButton (aName, aParent)
    44     , mNext (aNext)
     33void QIArrowButtonPress::retranslateUi()
    4534{
    46     updateIcon();
     35    /* Retranslate: */
     36    switch (m_buttonType)
     37    {
     38        case ButtonType_Back: setText(QApplication::translate("QIArrowSplitter", "&Back")); break;
     39        case ButtonType_Next: setText(QApplication::translate("QIArrowSplitter", "&Next")); break;
     40        default: break;
     41    }
    4742}
    4843
    49 void QIArrowButtonPress::updateIcon()
     44void QIArrowButtonPress::keyPressEvent(QKeyEvent *pEvent)
    5045{
    51     mButton->setIcon(UIIconPool::iconSet(mNext ?
    52                                          ":/arrow_right_10px.png" : ":/arrow_left_10px.png"));
     46    /* Handle different keys: */
     47    switch (pEvent->key())
     48    {
     49        /* Animate-click for the Space key: */
     50        case Qt::Key_PageUp: if (m_buttonType == ButtonType_Next) return animateClick(); break;
     51        case Qt::Key_PageDown: if (m_buttonType == ButtonType_Back) return animateClick(); break;
     52        default: break;
     53    }
     54    /* Call to base-class: */
     55    QIWithRetranslateUI<QIRichToolButton>::keyPressEvent(pEvent);
    5356}
    5457
    55 bool QIArrowButtonPress::eventFilter (QObject *aObject, QEvent *aEvent)
    56 {
    57     /* Process only QIArrowButtonPress or children */
    58     if (!(aObject == this || children().contains (aObject)))
    59         return QIRichToolButton::eventFilter (aObject, aEvent);
    60 
    61     /* Process keyboard events */
    62     if (aEvent->type() == QEvent::KeyPress)
    63     {
    64         QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
    65         if ((mNext && kEvent->key() == Qt::Key_PageUp) ||
    66             (!mNext && kEvent->key() == Qt::Key_PageDown))
    67             animateClick();
    68     }
    69 
    70     /* Default one handler */
    71     return QIRichToolButton::eventFilter (aObject, aEvent);
    72 }
    73 
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonPress.h

    r44528 r51873  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIArrowButtonPress class declaration
     2 * VBox Qt GUI - QIArrowButtonPress class declaration.
    53 */
    64
    75/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __QIArrowButtonPress_h__
    20 #define __QIArrowButtonPress_h__
     17#ifndef ___QIArrowButtonPress_h___
     18#define ___QIArrowButtonPress_h___
    2119
    22 /* VBox includes */
     20/* GUI includes: */
    2321#include "QIRichToolButton.h"
     22#include "QIWithRetranslateUI.h"
    2423
    25 /* VBox forwards */
    26 class QIRichToolButton;
    27 
    28 /** @class QIArrowButtonPress
    29  *
    30  *  The QIArrowButtonPress class is an arrow tool-button with text-label,
    31  *  used as back/next buttons in QIMessageBox class.
    32  *
    33  */
    34 class QIArrowButtonPress : public QIRichToolButton
     24/** QIRichToolButton extension
     25  * representing arrow tool-button with text-label,
     26  * can be used as back/next buttons in various places. */
     27class QIArrowButtonPress : public QIWithRetranslateUI<QIRichToolButton>
    3528{
    3629    Q_OBJECT;
     
    3831public:
    3932
    40     QIArrowButtonPress (QWidget *aParent = 0);
    41     QIArrowButtonPress (bool aNext, const QString &aName, QWidget *aParent = 0);
     33    /** Button types. */
     34    enum ButtonType { ButtonType_Back, ButtonType_Next };
    4235
    43     void setNext (bool aNext) { mNext = aNext; }
     36    /** Constructor, passes @a pParent to the QIRichToolButton constructor.
     37      * @param buttonType is used to define which type of the button it is. */
     38    QIArrowButtonPress(ButtonType buttonType, QWidget *pParent = 0);
     39
     40protected:
     41
     42    /** Retranslation routine.
     43      * @todo Fix translation context. */
     44    virtual void retranslateUi();
     45
     46    /** Key-press-event handler. */
     47    virtual void keyPressEvent(QKeyEvent *pEvent);
    4448
    4549private:
    4650
    47     void updateIcon();
    48     bool eventFilter (QObject *aObject, QEvent *aEvent);
    49 
    50     bool mNext;
     51    /** Holds the button-type. */
     52    ButtonType m_buttonType;
    5153};
    5254
    53 #endif
    54 
     55#endif /* !___QIArrowButtonPress_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonSwitch.cpp

    r51280 r51873  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QIArrowButtonSwitch class implementation
     3 * VBox Qt GUI - QIArrowButtonSwitch class implementation.
    64 */
    75
    86/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1816 */
    1917
    20 /* VBox includes */
    21 #include "QIArrowButtonSwitch.h"
    22 #include "UIIconPool.h"
    23 
    24 /* Qt includes */
     18/* Qt includes: */
    2519#include <QKeyEvent>
    2620
     21/* GUI includes: */
     22#include "QIArrowButtonSwitch.h"
    2723
    28 /** @class QIArrowButtonSwitch
    29  *
    30  *  The QIArrowButtonSwitch class is an arrow tool-button with text-label,
    31  *  used as collaps/expand switch in QIMessageBox class.
    32  *
    33  */
    34 
    35 QIArrowButtonSwitch::QIArrowButtonSwitch (QWidget *aParent)
    36     : QIRichToolButton (aParent)
    37     , mIsExpanded (false)
     24QIArrowButtonSwitch::QIArrowButtonSwitch(QWidget *pParent /* = 0 */)
     25    : QIRichToolButton(pParent)
     26    , m_buttonState(ButtonState_Collapsed)
    3827{
    39     init();
     28    /* Update icon: */
     29    updateIcon();
    4030}
    4131
    42 QIArrowButtonSwitch::QIArrowButtonSwitch (const QString &aName, QWidget *aParent)
    43     : QIRichToolButton (aName, aParent)
    44     , mIsExpanded (false)
     32void QIArrowButtonSwitch::setIconForButtonState(QIArrowButtonSwitch::ButtonState buttonState, const QIcon &icon)
    4533{
    46     init();
     34    /* Assign icon: */
     35    m_icons[buttonState] = icon;
     36    /* Update icon: */
     37    updateIcon();
    4738}
    4839
    49 void QIArrowButtonSwitch::buttonClicked()
     40void QIArrowButtonSwitch::sltButtonClicked()
    5041{
    51     mIsExpanded = !mIsExpanded;
     42    /* Toggle button-state: */
     43    m_buttonState = m_buttonState == ButtonState_Collapsed ?
     44                    ButtonState_Expanded : ButtonState_Collapsed;
     45    /* Update icon: */
    5246    updateIcon();
    53     QIRichToolButton::buttonClicked();
    5447}
    5548
    56 void QIArrowButtonSwitch::init()
     49void QIArrowButtonSwitch::keyPressEvent(QKeyEvent *pEvent)
    5750{
    58     /* Restrict icon size: */
    59     mButton->setIconSize(QSize(10, 10));
    60     /* And update icon finally: */
    61     updateIcon();
     51    /* Handle different keys: */
     52    switch (pEvent->key())
     53    {
     54        /* Animate-click for the Space key: */
     55        case Qt::Key_Minus: if (m_buttonState == ButtonState_Expanded) return animateClick(); break;
     56        case Qt::Key_Plus: if (m_buttonState == ButtonState_Collapsed) return animateClick(); break;
     57        default: break;
     58    }
     59    /* Call to base-class: */
     60    QIRichToolButton::keyPressEvent(pEvent);
    6261}
    6362
    6463void QIArrowButtonSwitch::updateIcon()
    6564{
    66     mButton->setIcon(UIIconPool::iconSet(mIsExpanded ?
    67                                          ":/arrow_down_10px.png" : ":/arrow_right_10px.png"));
     65    setIcon(m_icons.value(m_buttonState));
    6866}
    6967
    70 bool QIArrowButtonSwitch::eventFilter (QObject *aObject, QEvent *aEvent)
    71 {
    72     /* Process only QIArrowButtonSwitch or children */
    73     if (!(aObject == this || children().contains (aObject)))
    74         return QIRichToolButton::eventFilter (aObject, aEvent);
    75 
    76     /* Process keyboard events */
    77     if (aEvent->type() == QEvent::KeyPress)
    78     {
    79         QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
    80         if ((mIsExpanded && kEvent->key() == Qt::Key_Minus) ||
    81             (!mIsExpanded && kEvent->key() == Qt::Key_Plus))
    82             animateClick();
    83     }
    84 
    85     /* Default one handler */
    86     return QIRichToolButton::eventFilter (aObject, aEvent);
    87 }
    88 
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonSwitch.h

    r51280 r51873  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIArrowButtonSwitch class declaration
     2 * VBox Qt GUI - QIArrowButtonSwitch class declaration.
    53 */
    64
    75/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __QIArrowButtonSwitch_h__
    20 #define __QIArrowButtonSwitch_h__
     17#ifndef ___QIArrowButtonSwitch_h___
     18#define ___QIArrowButtonSwitch_h___
    2119
    22 /* VBox includes */
     20/* Qt includes: */
     21#include <QMap>
     22#include <QIcon>
     23
     24/* GUI includes: */
    2325#include "QIRichToolButton.h"
    2426
    25 /* VBox forwards */
    26 class QIRichToolButton;
    27 
    28 
    29 /** @class QIArrowButtonSwitch
    30  *
    31  *  The QIArrowButtonSwitch class is an arrow tool-button with text-label,
    32  *  used as collaps/expand switch in QIMessageBox class.
    33  *
    34  */
     27/** QIRichToolButton extension
     28  * representing arrow tool-button with text-label,
     29  * can be used as collaps/expand switch in various places. */
    3530class QIArrowButtonSwitch : public QIRichToolButton
    3631{
     
    3934public:
    4035
    41     QIArrowButtonSwitch (QWidget *aParent = 0);
    42     QIArrowButtonSwitch (const QString &aName, QWidget *aParent = 0);
     36    /** Button states. */
     37    enum ButtonState { ButtonState_Collapsed, ButtonState_Expanded };
    4338
    44     bool isExpanded() const { return mIsExpanded; }
     39    /** Constructor, passes @a pParent to the QIRichToolButton constructor. */
     40    QIArrowButtonSwitch(QWidget *pParent = 0);
    4541
    46 private slots:
     42    /** Defines the @a icon for the @a buttonState. */
     43    void setIconForButtonState(ButtonState buttonState, const QIcon &icon);
    4744
    48     void buttonClicked();
     45    /** Returns whether button-state is ButtonState_Expanded. */
     46    bool isExpanded() const { return m_buttonState == ButtonState_Expanded; }
     47
     48protected slots:
     49
     50    /** Button-click handler. */
     51    virtual void sltButtonClicked();
     52
     53protected:
     54
     55    /** Key-press-event handler. */
     56    virtual void keyPressEvent(QKeyEvent *pEvent);
    4957
    5058private:
    5159
    52     /** Performs initialization. */
    53     void init();
     60    /** Updates icon according button-state. */
    5461    void updateIcon();
    55     bool eventFilter (QObject *aObject, QEvent *aEvent);
    5662
    57     bool mIsExpanded;
     63    /** Holds the button-state. */
     64    ButtonState m_buttonState;
     65    /** Holds icons for button-states. */
     66    QMap<ButtonState, QIcon> m_icons;
    5867};
    5968
    60 #endif
    61 
     69#endif /* !___QIArrowButtonSwitch_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowSplitter.cpp

    r46831 r51873  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QIArrowSplitter class implementation
     3 * VBox Qt GUI - QIArrowSplitter class implementation.
    64 */
    75
    86/*
    9  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1816 */
    1917
    20 /* VBox includes */
     18/* Qt includes: */
     19#include <QApplication>
     20#include <QDesktopWidget>
     21#include <QStyle>
     22#include <QHBoxLayout>
     23#include <QTextEdit>
     24
     25/* GUI includes: */
    2126#include "QIArrowSplitter.h"
    22 
    23 /* Qt includes */
    24 #include <QApplication>
    25 #include <QHBoxLayout>
    26 #include <QKeyEvent>
    27 
    28 QIArrowSplitter::QIArrowSplitter (QWidget *aChild, QWidget *aParent)
    29     : QWidget (aParent)
    30     , mMainLayout (new QVBoxLayout (this))
    31     , mSwitchButton (new QIArrowButtonSwitch())
    32     , mBackButton (new QIArrowButtonPress (false, tr ("&Back")))
    33     , mNextButton (new QIArrowButtonPress (true,  tr ("&Next")))
    34     , mChild (aChild)
    35 {
    36     /* Setup main-layout */
    37     mMainLayout->setContentsMargins(0, 0, 0, 0);
    38     mMainLayout->setSpacing(3);
    39 
    40     /* Setup buttons */
    41     mBackButton->setVisible (false);
    42     mNextButton->setVisible (false);
    43 
    44     /* Setup connections */
    45     connect (mSwitchButton, SIGNAL (clicked()), this, SLOT (toggleWidget()));
    46     connect (mBackButton, SIGNAL (clicked()), this, SIGNAL (showBackDetails()));
    47     connect (mNextButton, SIGNAL (clicked()), this, SIGNAL (showNextDetails()));
    48 
    49     /* Setup button layout */
    50     QHBoxLayout *buttonLayout = new QHBoxLayout();
    51     buttonLayout->setContentsMargins(0, 0, 0, 0);
    52     buttonLayout->setSpacing (0);
    53     buttonLayout->addWidget (mSwitchButton);
    54     buttonLayout->addStretch();
    55     buttonLayout->addWidget (mBackButton);
    56     buttonLayout->addWidget (mNextButton);
    57 
    58     /* Append layout with children */
    59     mMainLayout->addLayout (buttonLayout);
    60     mMainLayout->addWidget (mChild);
    61 
    62     /* Install event-filter */
    63     qApp->installEventFilter (this);
    64 
    65     /* Hide child initially: */
    66     toggleWidget();
    67 }
    68 
    69 void QIArrowSplitter::setMultiPaging (bool aMultiPage)
    70 {
    71     mBackButton->setVisible (aMultiPage);
    72     mNextButton->setVisible (aMultiPage);
    73 }
    74 
    75 void QIArrowSplitter::setButtonEnabled (bool aNext, bool aEnabled)
    76 {
    77     aNext ? mNextButton->setEnabled (aEnabled)
    78           : mBackButton->setEnabled (aEnabled);
    79 }
    80 
    81 void QIArrowSplitter::setName (const QString &aName)
    82 {
    83     mSwitchButton->setText (aName);
    84     emit sigSizeChanged();
     27#include "QIArrowButtonSwitch.h"
     28#include "QIArrowButtonPress.h"
     29#include "UIIconPool.h"
     30
     31/* Other VBox includes: */
     32#include "iprt/assert.h"
     33
     34
     35/** QTextEdit extension
     36  * taking into account text-document size-hint.
     37  * @note Used with QIMessageBox class only.
     38  * @todo Should be moved/renamed accordingly. */
     39class QIDetailsBrowser : public QTextEdit
     40{
     41    Q_OBJECT;
     42
     43public:
     44
     45    /** Constructor, passes @a pParent to the QTextEdit constructor. */
     46    QIDetailsBrowser(QWidget *pParent = 0);
     47
     48    /** Returns minimum size-hint. */
     49    QSize minimumSizeHint() const;
     50    /** Returns size-hint. */
     51    QSize sizeHint() const;
     52
     53    /** Update scroll-bars. */
     54    void updateScrollBars();
     55};
     56
     57QIDetailsBrowser::QIDetailsBrowser(QWidget *pParent /* = 0 */)
     58    : QTextEdit(pParent)
     59{
     60    /* Prepare: */
     61    setReadOnly(true);
     62}
     63
     64QSize QIDetailsBrowser::minimumSizeHint() const
     65{
     66    /* Get document size as the basis: */
     67    QSize documentSize = document()->size().toSize();
     68    /* But only document ideal-width can advice wise width: */
     69    const int iDocumentIdealWidth = document()->idealWidth();
     70    /* Moreover we should take document margins into account: */
     71    const int iDocumentMargin = document()->documentMargin();
     72
     73    /* Compose minimum size-hint on the basis of values above: */
     74    documentSize.setWidth(iDocumentIdealWidth + iDocumentMargin);
     75    documentSize.setHeight(documentSize.height() + iDocumentMargin);
     76
     77    /* Get 40% of the screen-area to limit the resulting hint: */
     78    const QSize screenGeometryDot4 = QApplication::desktop()->screenGeometry(this).size() * .4;
     79
     80    /* Calculate minimum size-hint which is document-size limited by screen-area: */
     81    QSize mSizeHint = documentSize.boundedTo(screenGeometryDot4);
     82
     83    /* If there is not enough of vertical space: */
     84    if (mSizeHint.height() < documentSize.height())
     85    {
     86        /* We should also take into account vertical scroll-bar extent: */
     87        int iExtent = QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent);
     88        mSizeHint.setWidth(mSizeHint.width() + iExtent);
     89    }
     90
     91    /* Always bound cached hint by 40% of current screen-area: */
     92    return mSizeHint;
     93}
     94
     95QSize QIDetailsBrowser::sizeHint() const
     96{
     97    /* Return minimum size-hint: */
     98    return minimumSizeHint();
     99}
     100
     101void QIDetailsBrowser::updateScrollBars()
     102{
     103    /* Some Qt issue prevents scroll-bars from update.. */
     104    Qt::ScrollBarPolicy horizontalPolicy = horizontalScrollBarPolicy();
     105    Qt::ScrollBarPolicy verticalPolicy = verticalScrollBarPolicy();
     106    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     107    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     108    setHorizontalScrollBarPolicy(horizontalPolicy);
     109    setVerticalScrollBarPolicy(verticalPolicy);
     110}
     111
     112
     113QIArrowSplitter::QIArrowSplitter(QWidget *pParent /* = 0 */)
     114    : QIWithRetranslateUI<QWidget>(pParent)
     115    , m_pMainLayout(0)
     116    , m_pSwitchButton(0)
     117    , m_pBackButton(0)
     118    , m_pNextButton(0)
     119    , m_pDetailsBrowser(0)
     120    , m_iDetailsIndex(-1)
     121{
     122    /* Prepare: */
     123    prepare();
    85124}
    86125
    87126QSize QIArrowSplitter::minimumSizeHint() const
    88127{
    89     /* Get size-hints: */
    90     QSize switchButtonHint = mSwitchButton->minimumSizeHint();
    91     QSize backButtonHint = mBackButton->minimumSizeHint();
    92     QSize nextButtonHint = mNextButton->minimumSizeHint();
    93     int iChildWidthHint = 0;
    94     int iChildHeightHint = 0;
    95     if (mChild)
    96     {
    97         QSize childHint = mChild->minimumSize();
    98         if (childHint.isNull())
    99             childHint = mChild->minimumSizeHint();
    100         iChildWidthHint = childHint.width();
    101         iChildHeightHint = childHint.height();
    102     }
     128    /* Get minimum size-hints: */
     129    const QSize switchButtonHint = m_pSwitchButton->minimumSizeHint();
     130    const QSize backButtonHint = m_pBackButton->minimumSizeHint();
     131    const QSize nextButtonHint = m_pNextButton->minimumSizeHint();
     132    const QSize detailsBrowserHint = m_pDetailsBrowser->minimumSizeHint();
    103133
    104134    /* Calculate width-hint: */
    105135    int iWidthHint = 0;
    106136    iWidthHint += switchButtonHint.width();
     137    iWidthHint += 100 /* button spacing */;
    107138    iWidthHint += backButtonHint.width();
    108139    iWidthHint += nextButtonHint.width();
    109     if (mChild)
    110         iWidthHint = qMax(iWidthHint, iChildWidthHint);
     140    iWidthHint = qMax(iWidthHint, detailsBrowserHint.width());
    111141
    112142    /* Calculate height-hint: */
     
    115145    iHeightHint = qMax(iHeightHint, backButtonHint.height());
    116146    iHeightHint = qMax(iHeightHint, nextButtonHint.height());
    117     if (mChild && mChild->isVisible())
    118         iHeightHint += mMainLayout->spacing() + iChildHeightHint;
     147    if (m_pDetailsBrowser->isVisible())
     148        iHeightHint += m_pMainLayout->spacing() + detailsBrowserHint.height();
    119149
    120150    /* Return result: */
     
    122152}
    123153
    124 void QIArrowSplitter::toggleWidget()
    125 {
    126     mChild->setVisible (mSwitchButton->isExpanded());
    127     emit sigSizeChanged();
    128 }
    129 
    130 bool QIArrowSplitter::eventFilter (QObject *aObject, QEvent *aEvent)
    131 {
    132     /* Process only parent window children */
    133     if (!(aObject == window() || window()->children().contains (aObject)))
    134         return QWidget::eventFilter (aObject, aEvent);
    135 
    136     /* Do not process QIArrowButtonSwitch & QIArrowButtonPress children */
    137     if (aObject == mSwitchButton ||
    138         aObject == mBackButton ||
    139         aObject == mNextButton ||
    140         mSwitchButton->children().contains (aObject) ||
    141         mBackButton->children().contains (aObject) ||
    142         mNextButton->children().contains (aObject))
    143         return QWidget::eventFilter (aObject, aEvent);
    144 
    145     /* Process some keyboard events */
    146     if (aEvent->type() == QEvent::KeyPress)
     154void QIArrowSplitter::setName(const QString &strName)
     155{
     156    /* Assign name for the switch-button: */
     157    m_pSwitchButton->setText(strName);
     158    /* Update size-hints: */
     159    sltUpdateSizeHints();
     160}
     161
     162void QIArrowSplitter::setDetails(const QStringPairList &details)
     163{
     164    /* Assign new details: */
     165    m_details = details;
     166    /* Reset the details-list index: */
     167    m_iDetailsIndex = m_details.isEmpty() ? -1 : 0;
     168    /* Update navigation-buttons visibility: */
     169    sltUpdateNavigationButtonsVisibility();
     170    /* Update details-browser visibility: */
     171    sltUpdateDetailsBrowserVisibility();
     172    /* Update details: */
     173    updateDetails();
     174}
     175
     176void QIArrowSplitter::sltUpdateSizeHints()
     177{
     178    /* Let parent layout know our size-hint changed: */
     179    updateGeometry();
     180    /* Notify parent about our size-hint changed: */
     181    emit sigSizeHintChange();
     182    /* Update details-browser scroll-bars: */
     183    m_pDetailsBrowser->updateScrollBars();
     184}
     185
     186void QIArrowSplitter::sltUpdateNavigationButtonsVisibility()
     187{
     188    /* Depending on switch-button state: */
     189    const bool fExpanded = m_pSwitchButton->isExpanded();
     190    /* Update back/next button visibility: */
     191    m_pBackButton->setVisible(m_details.size() > 1 && fExpanded);
     192    m_pNextButton->setVisible(m_details.size() > 1 && fExpanded);
     193}
     194
     195void QIArrowSplitter::sltUpdateDetailsBrowserVisibility()
     196{
     197    /* Update details-browser visibility according switch-button state: */
     198    m_pDetailsBrowser->setVisible(m_details.size() > 0 && m_pSwitchButton->isExpanded());
     199    /* Update size-hints: */
     200    sltUpdateSizeHints();
     201}
     202
     203void QIArrowSplitter::sltSwitchDetailsPageBack()
     204{
     205    /* Make sure details-page index feats the bounds: */
     206    AssertReturnVoid(m_iDetailsIndex > 0);
     207    /* Decrease details-list index: */
     208    --m_iDetailsIndex;
     209    /* Update details: */
     210    updateDetails();
     211}
     212
     213void QIArrowSplitter::sltSwitchDetailsPageNext()
     214{
     215    /* Make sure details-page index feats the bounds: */
     216    AssertReturnVoid(m_iDetailsIndex < m_details.size() - 1);
     217    /* Increase details-list index: */
     218    ++m_iDetailsIndex;
     219    /* Update details: */
     220    updateDetails();
     221}
     222
     223void QIArrowSplitter::prepare()
     224{
     225    /* Create main-layout: */
     226    m_pMainLayout = new QVBoxLayout(this);
     227    AssertPtrReturnVoid(m_pMainLayout);
    147228    {
    148         QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
    149         switch (kEvent->key())
     229        /* Configure main-layout: */
     230        m_pMainLayout->setContentsMargins(0, 0, 0, 0);
     231        m_pMainLayout->setSpacing(3);
     232        /* Create button-layout: */
     233        QHBoxLayout *pButtonLayout = new QHBoxLayout;
     234        AssertPtrReturnVoid(pButtonLayout);
    150235        {
    151             case Qt::Key_Plus:
     236            /* Configure button-layout: */
     237            pButtonLayout->setContentsMargins(0, 0, 0, 0);
     238            pButtonLayout->setSpacing(0);
     239            /* Create switch-button: */
     240            m_pSwitchButton = new QIArrowButtonSwitch;
     241            AssertPtrReturnVoid(m_pSwitchButton);
    152242            {
    153                 if (!mSwitchButton->isExpanded())
    154                     mSwitchButton->animateClick();
    155                 break;
     243                /* Configure switch-button: */
     244                m_pSwitchButton->setIconSize(QSize(10, 10));
     245                m_pSwitchButton->setIconForButtonState(QIArrowButtonSwitch::ButtonState_Collapsed,
     246                                                       UIIconPool::iconSet(":/arrow_right_10px.png"));
     247                m_pSwitchButton->setIconForButtonState(QIArrowButtonSwitch::ButtonState_Expanded,
     248                                                       UIIconPool::iconSet(":/arrow_down_10px.png"));
     249                connect(m_pSwitchButton, SIGNAL(sigClicked()), this, SLOT(sltUpdateNavigationButtonsVisibility()));
     250                connect(m_pSwitchButton, SIGNAL(sigClicked()), this, SLOT(sltUpdateDetailsBrowserVisibility()));
     251                /* Add switch-button into button-layout: */
     252                pButtonLayout->addWidget(m_pSwitchButton);
    156253            }
    157             case Qt::Key_Minus:
     254            /* Add stretch: */
     255            pButtonLayout->addStretch();
     256            /* Create back-button: */
     257            m_pBackButton = new QIArrowButtonPress(QIArrowButtonPress::ButtonType_Back);
     258            AssertPtrReturnVoid(m_pBackButton);
    158259            {
    159                 if (mSwitchButton->isExpanded())
    160                     mSwitchButton->animateClick();
    161                 break;
     260                /* Configure back-button: */
     261                m_pBackButton->setIconSize(QSize(10, 10));
     262                m_pBackButton->setIcon(UIIconPool::iconSet(":/arrow_left_10px.png"));
     263                connect(m_pBackButton, SIGNAL(sigClicked()), this, SLOT(sltSwitchDetailsPageBack()));
     264                /* Add back-button into button-layout: */
     265                pButtonLayout->addWidget(m_pBackButton);
    162266            }
    163             case Qt::Key_PageUp:
     267            /* Create next-button: */
     268            m_pNextButton = new QIArrowButtonPress(QIArrowButtonPress::ButtonType_Next);
     269            AssertPtrReturnVoid(m_pNextButton);
    164270            {
    165                 if (mNextButton->isEnabled())
    166                     mNextButton->animateClick();
    167                 break;
     271                /* Configure next-button: */
     272                m_pNextButton->setIconSize(QSize(10, 10));
     273                m_pNextButton->setIcon(UIIconPool::iconSet(":/arrow_right_10px.png"));
     274                connect(m_pNextButton, SIGNAL(sigClicked()), this, SLOT(sltSwitchDetailsPageNext()));
     275                /* Add next-button into button-layout: */
     276                pButtonLayout->addWidget(m_pNextButton);
    168277            }
    169             case Qt::Key_PageDown:
    170             {
    171                 if (mBackButton->isEnabled())
    172                     mBackButton->animateClick();
    173                 break;
    174             }
     278            /* Add button layout into main-layout: */
     279            m_pMainLayout->addLayout(pButtonLayout);
     280            /* Update navigation-buttons visibility: */
     281            sltUpdateNavigationButtonsVisibility();
     282        }
     283        /* Create details-browser: */
     284        m_pDetailsBrowser = new QIDetailsBrowser;
     285        AssertPtrReturnVoid(m_pDetailsBrowser);
     286        {
     287            /* Add details-browser into main-layout: */
     288            m_pMainLayout->addWidget(m_pDetailsBrowser);
     289            /* Update details-browser visibility: */
     290            sltUpdateDetailsBrowserVisibility();
     291            /* Update details: */
     292            updateDetails();
    175293        }
    176294    }
    177295
    178     /* Default one handler */
    179     return QWidget::eventFilter (aObject, aEvent);
    180 }
    181 
     296    /* Apply size-policy finally: */
     297    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
     298}
     299
     300void QIArrowSplitter::retranslateUi()
     301{
     302    /* Update details: */
     303    updateDetails();
     304}
     305
     306void QIArrowSplitter::updateDetails()
     307{
     308    /* If details are empty: */
     309    if (m_details.isEmpty())
     310    {
     311        /* Make sure details-list index is invalid: */
     312        AssertReturnVoid(m_iDetailsIndex == -1);
     313
     314        /* Reset name: */
     315        setName(QString());
     316    }
     317    /* If details are NOT empty: */
     318    else
     319    {
     320        /* Make sure details-list index feats the bounds: */
     321        AssertReturnVoid(m_iDetailsIndex >= 0 && m_iDetailsIndex < m_details.size());
     322
     323        /* Single page: */
     324        if (m_details.size() == 1)
     325        {
     326            setName(QApplication::translate("QIMessageBox", "&Details"));
     327            m_pBackButton->setEnabled(false);
     328            m_pNextButton->setEnabled(false);
     329        }
     330        /* Multi-paging: */
     331        else if (m_details.size() > 1)
     332        {
     333            setName(QApplication::translate("QIMessageBox", "&Details (%1 of %2)").arg(m_iDetailsIndex + 1).arg(m_details.size()));
     334            m_pBackButton->setEnabled(m_iDetailsIndex > 0);
     335            m_pNextButton->setEnabled(m_iDetailsIndex < m_details.size() - 1);
     336        }
     337
     338        /* Update details-browser: */
     339        const QString strFirstPart = m_details[m_iDetailsIndex].first;
     340        const QString strSecondPart = m_details[m_iDetailsIndex].second;
     341        if (strFirstPart.isEmpty())
     342            m_pDetailsBrowser->setText(strSecondPart);
     343        else
     344            m_pDetailsBrowser->setText(QString("%1<br>%2").arg(strFirstPart, strSecondPart));
     345    }
     346    /* Update size-hints: */
     347    sltUpdateSizeHints();
     348}
     349
     350#include "QIArrowSplitter.moc"
     351
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowSplitter.h

    r45307 r51873  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIArrowSplitter class declaration
     2 * VBox Qt GUI - QIArrowSplitter class declaration.
    53 */
    64
    75/*
    8  * Copyright (C) 2006-2012 Oracle Corporation
     6 * Copyright (C) 2006-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __QIArrowSplitter_h__
    20 #define __QIArrowSplitter_h__
     17#ifndef ___QIArrowSplitter_h___
     18#define ___QIArrowSplitter_h___
    2119
    22 /* VBox includes */
    23 #include "QIArrowButtonPress.h"
    24 #include "QIArrowButtonSwitch.h"
     20/* Qt includes: */
     21#include <QWidget>
    2522
    26 /* Qt includes */
    27 #include <QWidget>
    28 #include <QHBoxLayout>
     23/* GUI includes: */
     24#include "QIWithRetranslateUI.h"
    2925
    30 /* VBox forwards */
     26/* Forward declarations: */
     27class QVBoxLayout;
     28class QIArrowButtonSwitch;
    3129class QIArrowButtonPress;
    32 class QIArrowButtonSwitch;
     30class QIDetailsBrowser;
    3331
    34 /* Qt forwards */
    35 class QVBoxLayout;
     32/* Type definitions: */
     33typedef QPair<QString, QString> QStringPair;
     34typedef QList<QStringPair> QStringPairList;
    3635
    37 /** @class QIArrowSplitter
    38  *
    39  *  The QIArrowSplitter class is a folding widget placeholder.
    40  *
    41  */
    42 class QIArrowSplitter : public QWidget
     36/** QWidget extension
     37  * allowing to toggle visibility for any other child widget. */
     38class QIArrowSplitter : public QIWithRetranslateUI<QWidget>
    4339{
    4440    Q_OBJECT;
    4541
     42signals:
     43
     44    /** Notifies listeners about size-hint change: */
     45    void sigSizeHintChange();
     46
    4647public:
    4748
    48     QIArrowSplitter (QWidget *aChild, QWidget *aParent = 0);
     49    /** Constructor, passes @a pParent to the QWidget constructor. */
     50    QIArrowSplitter(QWidget *pParent = 0);
    4951
    50     void setMultiPaging (bool aMultiPage);
     52    /** Returns minimum size-hint. */
     53    QSize minimumSizeHint() const;
    5154
    52     void setButtonEnabled (bool aNext, bool aEnabled);
     55    /** Defines the @a strName for the switch-button. */
     56    void setName(const QString &strName);
    5357
    54     void setName (const QString &aName);
    55 
    56     QSize minimumSizeHint() const;
     58    /** Returns splitter details. */
     59    const QStringPairList& details() const { return m_details; }
     60    /** Defines splitter @a details. */
     61    void setDetails(const QStringPairList &details);
    5762
    5863public slots:
    5964
    60     void toggleWidget();
     65    /** Updates size-hints. */
     66    void sltUpdateSizeHints();
    6167
    62 signals:
     68    /** Updates navigation-buttons visibility. */
     69    void sltUpdateNavigationButtonsVisibility();
     70    /** Updates details-browser visibility. */
     71    void sltUpdateDetailsBrowserVisibility();
    6372
    64     void showBackDetails();
    65     void showNextDetails();
    66     void sigSizeChanged();
     73    /** Navigates through details-list backward. */
     74    void sltSwitchDetailsPageBack();
     75    /** Navigates through details-list forward. */
     76    void sltSwitchDetailsPageNext();
    6777
    6878private:
    6979
    70     bool eventFilter (QObject *aObject, QEvent *aEvent);
     80    /** Prepare routine. */
     81    void prepare();
    7182
    72     QVBoxLayout *mMainLayout;
    73     QIArrowButtonSwitch *mSwitchButton;
    74     QIArrowButtonPress *mBackButton;
    75     QIArrowButtonPress *mNextButton;
    76     QWidget *mChild;
     83    /** Retranslation routine.
     84      * @todo Fix translation context. */
     85    void retranslateUi();
     86
     87    /** Updates details. */
     88    void updateDetails();
     89
     90    /** Holds the main-layout. */
     91    QVBoxLayout *m_pMainLayout;
     92
     93    /** Holds the switch-button. */
     94    QIArrowButtonSwitch *m_pSwitchButton;
     95    /** Holds the back-button. */
     96    QIArrowButtonPress *m_pBackButton;
     97    /** Holds the next-button. */
     98    QIArrowButtonPress *m_pNextButton;
     99
     100    /** Holds the details-browser. */
     101    QIDetailsBrowser *m_pDetailsBrowser;
     102    /** Holds details-list. */
     103    QStringPairList m_details;
     104    /** Holds details-list index. */
     105    int m_iDetailsIndex;
    77106};
    78107
    79 #endif
    80 
     108#endif /* !___QIArrowSplitter_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.cpp

    r50931 r51873  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QIMessageBox class implementation
     3 * VBox Qt GUI - QIMessageBox class implementation.
    64 */
    75
    86/*
    9  * Copyright (C) 2006-2013 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1917
    2018/* Qt includes: */
     19#include <QVBoxLayout>
    2120#include <QHBoxLayout>
    22 #include <QVBoxLayout>
    2321#include <QClipboard>
    2422#include <QLabel>
    25 #include <QTextEdit>
    2623#include <QCheckBox>
    2724#include <QPushButton>
     
    3027/* GUI includes: */
    3128#include "QIMessageBox.h"
    32 #include "UIIconPool.h"
    3329#include "QILabel.h"
    3430#include "QIArrowSplitter.h"
    3531#include "QIDialogButtonBox.h"
     32#include "UIIconPool.h"
    3633
    3734/* Other VBox includes: */
    38 #include <VBox/sup.h>
    39 
    40 QIMessageBox::QIMessageBox(const QString &strCaption, const QString &strMessage, AlertIconType iconType,
     35#include <iprt/assert.h>
     36
     37QIMessageBox::QIMessageBox(const QString &strTitle, const QString &strMessage, AlertIconType iconType,
    4138                           int iButton1 /* = 0*/, int iButton2 /* = 0*/, int iButton3 /* = 0*/, QWidget *pParent /* = 0*/)
    4239    : QIDialog(pParent)
     40    , m_strTitle(strTitle)
     41    , m_iconType(iconType)
     42    , m_pLabelIcon(0)
     43    , m_strMessage(strMessage)
     44    , m_pLabelText(0)
     45    , m_pFlagCheckBox(0)
     46    , m_pDetailsContainer(0)
    4347    , m_iButton1(iButton1)
    4448    , m_iButton2(iButton2)
    4549    , m_iButton3(iButton3)
    4650    , m_iButtonEsc(0)
    47     , m_iconType(iconType)
    48     , m_strMessage(strMessage)
    49     , m_iDetailsIndex(-1)
     51    , m_pButton1(0)
     52    , m_pButton2(0)
     53    , m_pButton3(0)
     54    , m_pButtonBox(0)
    5055    , m_fDone(false)
    5156{
    52     /* Set caption: */
    53     setWindowTitle(strCaption);
    54 
    55     /* Prepare content: */
    56     prepareContent();
    57 }
    58 
    59 QString QIMessageBox::detailsText() const
    60 {
    61     /* Return in html format: */
    62     return m_pDetailsTextView->toHtml();
     57    /* Prepare: */
     58    prepare();
    6359}
    6460
    6561void QIMessageBox::setDetailsText(const QString &strText)
    6662{
     63    /* Make sure details-text is NOT empty: */
     64    AssertReturnVoid(!strText.isEmpty());
     65
    6766    /* Split details into paragraphs: */
    68     AssertMsg(!strText.isEmpty(), ("Details text should NOT be empty!"));
    6967    QStringList paragraphs(strText.split("<!--EOP-->", QString::SkipEmptyParts));
    70     AssertMsg(paragraphs.size() != 0, ("There should be at least one paragraph."));
    71     /* Populate details list: */
     68    /* Make sure details-text has at least one paragraph: */
     69    AssertReturnVoid(!paragraphs.isEmpty());
     70
     71    /* Enumerate all the paragraphs: */
     72    QStringPairList details;
    7273    foreach (const QString &strParagraph, paragraphs)
    7374    {
     75        /* Split each paragraph into pairs: */
    7476        QStringList parts(strParagraph.split("<!--EOM-->", QString::KeepEmptyParts));
    75         AssertMsg(parts.size() == 2, ("Each paragraph should consist of 2 parts."));
    76         m_details << QPair<QString, QString>(parts[0], parts[1]);
    77     }
    78     /* Update details container: */
     77        /* Make sure each paragraph consist of 2 parts: */
     78        AssertReturnVoid(parts.size() == 2);
     79        /* Append each pair into details-list: */
     80        details << QStringPair(parts[0], parts[1]);
     81    }
     82
     83    /* Pass details-list to details-container: */
     84    m_pDetailsContainer->setDetails(details);
     85    /* Update details-container finally: */
    7986    updateDetailsContainer();
    8087}
     
    9097}
    9198
    92 QString QIMessageBox::flagText() const
    93 {
    94     return m_pFlagCheckBox->text();
    95 }
    96 
    97 void QIMessageBox::setFlagText(const QString &strText)
    98 {
    99     /* Set check-box text: */
    100     m_pFlagCheckBox->setText(strText);
    101     /* And update check-box finally: */
     99void QIMessageBox::setFlagText(const QString &strFlagText)
     100{
     101    /* Pass text to flag check-box: */
     102    m_pFlagCheckBox->setText(strFlagText);
     103    /* Update flag check-box finally: */
    102104    updateCheckBox();
    103 }
    104 
    105 QString QIMessageBox::buttonText(int iButton) const
    106 {
    107     switch (iButton)
    108     {
    109         case 0: if (m_pButton1) return m_pButton1->text(); break;
    110         case 1: if (m_pButton2) return m_pButton2->text(); break;
    111         case 2: if (m_pButton3) return m_pButton3->text(); break;
    112         default: break;
    113     }
    114     return QString();
    115105}
    116106
     
    126116}
    127117
    128 void QIMessageBox::reject()
    129 {
    130     if (m_iButtonEsc)
    131     {
    132         QDialog::reject();
    133         setResult(m_iButtonEsc & AlertButtonMask);
    134     }
    135 }
    136 
    137 void QIMessageBox::copy() const
     118void QIMessageBox::sltUpdateSize()
     119{
     120    /* Fix minimum possible size: */
     121    setFixedSize(minimumSizeHint());
     122}
     123
     124void QIMessageBox::sltCopy() const
    138125{
    139126    /* Create the error string with all errors. First the html version. */
    140127    QString strError = "<html><body><p>" + m_strMessage + "</p>";
    141     for (int i = 0; i < m_details.size(); ++i)
    142         strError += m_details.at(i).first + m_details.at(i).second + "<br>";
     128    foreach (const QStringPair &pair, m_pDetailsContainer->details())
     129        strError += pair.first + pair.second + "<br>";
    143130    strError += "</body></html>";
    144131    strError.remove(QRegExp("</+qt>"));
    145132    strError = strError.replace(QRegExp("&nbsp;"), " ");
    146133    /* Create a new mime data object holding both the html and the plain text version. */
    147     QMimeData *pMd = new QMimeData();
    148     pMd->setHtml(strError);
     134    QMimeData *pMimeData = new QMimeData();
     135    pMimeData->setHtml(strError);
    149136    /* Replace all the html entities. */
    150137    strError = strError.replace(QRegExp("<br>|</tr>"), "\n");
    151138    strError = strError.replace(QRegExp("</p>"), "\n\n");
    152139    strError = strError.remove(QRegExp("<[^>]*>"));
    153     pMd->setText(strError);
     140    pMimeData->setText(strError);
    154141    /* Add the mime data to the global clipboard. */
    155142    QClipboard *pClipboard = QApplication::clipboard();
    156     pClipboard->setMimeData(pMd);
    157 }
    158 
    159 void QIMessageBox::detailsBack()
    160 {
    161     /* Make sure details-page index feats the bounds: */
    162     if (m_iDetailsIndex <= 0)
    163         return;
    164 
    165     /* Advance the page index: */
    166     --m_iDetailsIndex;
    167     /* Update details-page: */
    168     updateDetailsPage();
    169 }
    170 
    171 void QIMessageBox::detailsNext()
    172 {
    173     /* Make sure details-page index feats the bounds: */
    174     if (m_iDetailsIndex >= m_details.size() - 1)
    175         return;
    176 
    177     /* Advance the page index: */
    178     ++m_iDetailsIndex;
    179     /* Update details-page: */
    180     updateDetailsPage();
    181 }
    182 
    183 void QIMessageBox::sltUpdateSize()
    184 {
    185     /* Reactivate all the layouts: */
    186     QList<QLayout*> layouts = findChildren<QLayout*>();
    187     foreach (QLayout *pLayout, layouts)
    188     {
    189         pLayout->update();
    190         pLayout->activate();
    191     }
    192     QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);
    193     /* And fix the size to the minimum possible: */
    194     setFixedSize(minimumSizeHint());
    195 }
    196 
    197 void QIMessageBox::prepareContent()
    198 {
     143    pClipboard->setMimeData(pMimeData);
     144}
     145
     146void QIMessageBox::reject()
     147{
     148    if (m_iButtonEsc)
     149    {
     150        QDialog::reject();
     151        setResult(m_iButtonEsc & AlertButtonMask);
     152    }
     153}
     154
     155void QIMessageBox::prepare()
     156{
     157    /* Set caption: */
     158    setWindowTitle(m_strTitle);
     159
    199160    /* Create main-layout: */
    200161    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    201     {
    202         /* Configure layout: */
     162    AssertPtrReturnVoid(pMainLayout);
     163    {
     164        /* Configure main-layout: */
    203165#ifdef Q_WS_MAC
    204166        pMainLayout->setContentsMargins(40, 11, 40, 11);
     
    210172        /* Create top-layout: */
    211173        QHBoxLayout *pTopLayout = new QHBoxLayout;
     174        AssertPtrReturnVoid(pTopLayout);
    212175        {
    213             /* Insert into parent layout: */
    214             pMainLayout->addLayout(pTopLayout);
    215             /* Configure layout: */
     176            /* Configure top-layout: */
    216177            pTopLayout->setContentsMargins(0, 0, 0, 0);
    217178            pTopLayout->setSpacing(10);
    218179            /* Create icon-label: */
    219             m_pIconLabel = new QLabel;
     180            m_pLabelIcon = new QLabel;
     181            AssertPtrReturnVoid(m_pLabelIcon);
    220182            {
    221                 /* Insert into parent layout: */
    222                 pTopLayout->addWidget(m_pIconLabel);
    223                 /* Configure label: */
    224                 m_pIconLabel->setPixmap(standardPixmap(m_iconType, this));
    225                 m_pIconLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
    226                 m_pIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
     183                /* Configure icon-label: */
     184                m_pLabelIcon->setPixmap(standardPixmap(m_iconType, this));
     185                m_pLabelIcon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
     186                m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
     187                /* Add icon-label into top-layout: */
     188                pTopLayout->addWidget(m_pLabelIcon);
    227189            }
    228190            /* Create text-label: */
    229             m_pTextLabel = new QILabel(m_strMessage);
     191            m_pLabelText = new QILabel(m_strMessage);
     192            AssertPtrReturnVoid(m_pLabelText);
    230193            {
    231                 /* Insert into parent layout: */
    232                 pTopLayout->addWidget(m_pTextLabel);
    233                 /* Configure label: */
    234                 m_pTextLabel->setWordWrap(true);
    235                 m_pTextLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
     194                /* Configure text-label: */
     195                m_pLabelText->setWordWrap(true);
     196                m_pLabelText->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    236197                QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    237198                sizePolicy.setHeightForWidth(true);
    238                 m_pTextLabel->setSizePolicy(sizePolicy);
     199                m_pLabelText->setSizePolicy(sizePolicy);
     200                /* Add text-label into top-layout: */
     201                pTopLayout->addWidget(m_pLabelText);
    239202            }
    240         }
    241         /* Create details text-view: */
    242         m_pDetailsTextView = new QTextEdit;
    243         {
    244             /* Configure text-view: */
    245             m_pDetailsTextView->setReadOnly(true);
    246             m_pDetailsTextView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
    247             /* Calculate the minimum size dynamically, approx. for 40 chars, 4 lines & 2 <table> margins: */
    248             QFontMetrics fm = m_pDetailsTextView->fontMetrics();
    249             m_pDetailsTextView->setMinimumSize(fm.width ('m') * 40, fm.lineSpacing() * 4 + 4 * 2);
     203            /* Add top-layout into main-layout: */
     204            pMainLayout->addLayout(pTopLayout);
    250205        }
    251206        /* Create details-container: */
    252         m_pDetailsContainer = new QIArrowSplitter(m_pDetailsTextView);
     207        m_pDetailsContainer = new QIArrowSplitter;
     208        AssertPtrReturnVoid(m_pDetailsContainer);
    253209        {
    254             /* Insert into parent layout: */
     210            /* Configure container: */
     211            connect(m_pDetailsContainer, SIGNAL(sigSizeHintChange()), this, SLOT(sltUpdateSize()));
     212            /* Add details-container into main-layout: */
    255213            pMainLayout->addWidget(m_pDetailsContainer);
    256             /* Configure container: */
    257             connect(m_pDetailsContainer, SIGNAL(showBackDetails()), this, SLOT(detailsBack()));
    258             connect(m_pDetailsContainer, SIGNAL(showNextDetails()), this, SLOT(detailsNext()));
    259             connect(m_pDetailsContainer, SIGNAL(sigSizeChanged()), this, SLOT(sltUpdateSize()));
    260             /* And update container finally: */
     214            /* Update details-container finally: */
    261215            updateDetailsContainer();
    262216        }
    263         /* Create details check-box: */
     217        /* Create flag check-box: */
    264218        m_pFlagCheckBox = new QCheckBox;
     219        AssertPtrReturnVoid(m_pFlagCheckBox);
    265220        {
    266             /* Insert into parent layout: */
     221            /* Configure flag check-box: */
     222            m_pFlagCheckBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     223            /* Add flag check-box into main-layout: */
    267224            pMainLayout->addWidget(m_pFlagCheckBox, 0, Qt::AlignHCenter | Qt::AlignVCenter);
    268             /* Configure check-box: */
    269             m_pFlagCheckBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    270             /* And update check-box finally: */
     225            /* Update flag check-box finally: */
    271226            updateCheckBox();
    272227        }
    273228        /* Create button-box: */
    274229        m_pButtonBox = new QIDialogButtonBox;
     230        AssertPtrReturnVoid(m_pButtonBox);
    275231        {
    276             /* Insert into parent layout: */
    277             pMainLayout->addWidget(m_pButtonBox);
    278232            /* Configure button-box: */
    279233            m_pButtonBox->setCenterButtons(true);
    280234            m_pButton1 = createButton(m_iButton1);
    281235            if (m_pButton1)
    282                 connect(m_pButton1, SIGNAL(clicked()), SLOT(done1()));
     236                connect(m_pButton1, SIGNAL(clicked()), SLOT(sltDone1()));
    283237            m_pButton2 = createButton(m_iButton2);
    284238            if (m_pButton2)
    285                 connect(m_pButton2, SIGNAL(clicked()), SLOT(done2()));
     239                connect(m_pButton2, SIGNAL(clicked()), SLOT(sltDone2()));
    286240            m_pButton3 = createButton(m_iButton3);
    287241            if (m_pButton3)
    288                 connect(m_pButton3, SIGNAL(clicked()), SLOT(done3()));
     242                connect(m_pButton3, SIGNAL(clicked()), SLOT(sltDone3()));
    289243            /* If this is a critical message add a "Copy to clipboard" button: */
    290244            if (m_iconType == AlertIconType_Critical)
     
    292246                QPushButton *pCopyButton = createButton(AlertButton_Copy);
    293247                pCopyButton->setToolTip(tr("Copy all errors to the clipboard"));
    294                 connect(pCopyButton, SIGNAL(clicked()), SLOT(copy()));
     248                connect(pCopyButton, SIGNAL(clicked()), SLOT(sltCopy()));
    295249            }
     250            /* Add button-box into main-layout: */
     251            pMainLayout->addWidget(m_pButtonBox);
    296252        }
    297253    }
     
    338294void QIMessageBox::polishEvent(QShowEvent *pPolishEvent)
    339295{
    340     /* Tune our size: */
    341     m_pTextLabel->useSizeHintForWidth(m_pTextLabel->width());
    342     m_pTextLabel->updateGeometry();
     296    /* Tune text-label size: */
     297    m_pLabelText->useSizeHintForWidth(m_pLabelText->width());
     298    m_pLabelText->updateGeometry();
    343299
    344300    /* Call to base-class: */
    345301    QIDialog::polishEvent(pPolishEvent);
    346302
    347     /* Make the size fixed: */
    348     setFixedSize(size());
     303    /* Update size finally: */
     304    sltUpdateSize();
    349305}
    350306
     
    359315void QIMessageBox::updateDetailsContainer()
    360316{
    361     /* Do we have details to show? */
    362     m_pDetailsContainer->setVisible(!m_details.isEmpty());
    363 
    364     /* Reset the details page index: */
    365     m_iDetailsIndex = m_details.isEmpty() ? -1 : 0;
    366 
    367     /* Do we have any details? */
    368     if (m_details.isEmpty())
    369         m_pDetailsContainer->setName(QString());
    370     else if (m_details.size() == 1)
    371         m_pDetailsContainer->setName(tr("&Details"));
    372     else
    373         m_pDetailsContainer->setMultiPaging(true);
    374 
    375     /* Do we have any details? */
    376     if (!m_details.isEmpty())
    377         updateDetailsPage();
    378 }
    379 
    380 void QIMessageBox::updateDetailsPage()
    381 {
    382     /* Make sure details-page index feats the bounds: */
    383     if (m_iDetailsIndex < 0 || m_iDetailsIndex >= m_details.size())
    384         return;
    385 
    386     /* Update message text-label: */
    387     m_pTextLabel->setText(m_strMessage + m_details[m_iDetailsIndex].first);
    388 
    389     /* Update details text-view: */
    390     m_pDetailsTextView->setText(m_details[m_iDetailsIndex].second);
    391 
    392     /* Update details-container: */
    393     if (m_details.size() > 1)
    394     {
    395         m_pDetailsContainer->setName(tr("&Details (%1 of %2)").arg(m_iDetailsIndex + 1).arg(m_details.size()));
    396         m_pDetailsContainer->setButtonEnabled(true, m_iDetailsIndex < m_details.size() - 1);
    397         m_pDetailsContainer->setButtonEnabled(false, m_iDetailsIndex > 0);
    398     }
     317    /* Details-container with details is always visible: */
     318    m_pDetailsContainer->setVisible(!m_pDetailsContainer->details().isEmpty());
     319    /* Update size: */
     320    sltUpdateSize();
    399321}
    400322
     
    403325    /* Flag check-box with text is always visible: */
    404326    m_pFlagCheckBox->setVisible(!m_pFlagCheckBox->text().isEmpty());
     327    /* Update size: */
     328    sltUpdateSize();
    405329}
    406330
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h

    r45690 r51873  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIMessageBox class declaration
     2 * VBox Qt GUI - QIMessageBox class declaration.
    53 */
    64
    75/*
    8  * Copyright (C) 2006-2013 Oracle Corporation
     6 * Copyright (C) 2006-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __QIMessageBox_h__
    20 #define __QIMessageBox_h__
     17#ifndef ___QIMessageBox_h___
     18#define ___QIMessageBox_h___
    2119
    2220/* Qt includes: */
     
    2725
    2826/* Forward declarations: */
    29 class QShowEvent;
    30 class QCloseEvent;
    3127class QLabel;
    32 class QTextEdit;
     28class QILabel;
     29class QPushButton;
    3330class QCheckBox;
    34 class QPushButton;
    35 class QILabel;
    3631class QIArrowSplitter;
    3732class QIDialogButtonBox;
    3833
    39 /* Button type enumerator: */
     34/** Button types. */
    4035enum AlertButton
    4136{
     
    4944};
    5045
    51 /* Button option enumerator: */
     46/** Button options. */
    5247enum AlertButtonOption
    5348{
     
    5752};
    5853
    59 /* Alert option enumerator: */
     54/** Alert options. */
    6055enum AlertOption
    6156{
     
    6560};
    6661
    67 /* Icon type enumerator: */
     62/** Icon types. */
    6863enum AlertIconType
    6964{
    70     AlertIconType_NoIcon = QMessageBox::NoIcon,
    71     AlertIconType_Information = QMessageBox::Information,
    72     AlertIconType_Warning = QMessageBox::Warning,
    73     AlertIconType_Critical = QMessageBox::Critical,
    74     AlertIconType_Question = QMessageBox::Question,
     65    AlertIconType_NoIcon         = QMessageBox::NoIcon,
     66    AlertIconType_Information    = QMessageBox::Information,
     67    AlertIconType_Warning        = QMessageBox::Warning,
     68    AlertIconType_Critical       = QMessageBox::Critical,
     69    AlertIconType_Question       = QMessageBox::Question,
    7570    AlertIconType_GuruMeditation
    7671};
    7772
    78 /* QIDialog extension representing GUI alerts: */
     73/** QIDialog extension
     74  * representing GUI alerts. */
    7975class QIMessageBox : public QIDialog
    8076{
     
    8379public:
    8480
    85     /* Constructor: */
    86     QIMessageBox(const QString &strCaption, const QString &strMessage, AlertIconType iconType,
     81    /** Constructor, passes @a pParent to the QIDialog constructor.
     82      * @param strTitle   defines title,
     83      * @param strMessage defines message,
     84      * @param iconType   defines icon-type,
     85      * @param iButton1   specifies integer-code for the 1st button,
     86      * @param iButton2   specifies integer-code for the 2nd button,
     87      * @param iButton3   specifies integer-code for the 3rd button. */
     88    QIMessageBox(const QString &strTitle, const QString &strMessage, AlertIconType iconType,
    8789                 int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, QWidget *pParent = 0);
    8890
    89     /* API: Details stuff: */
    90     QString detailsText() const;
     91    /** Defines details-text. */
    9192    void setDetailsText(const QString &strText);
    9293
    93     /* API: Flag stuff: */
     94    /** Returns whether flag is checked. */
    9495    bool flagChecked() const;
     96    /** Defines whether flag is @a fChecked. */
    9597    void setFlagChecked(bool fChecked);
    96     QString flagText() const;
    97     void setFlagText(const QString &strText);
     98    /** Defines @a strFlagText. */
     99    void setFlagText(const QString &strFlagText);
    98100
    99     /* API: Button stuff: */
    100     QString buttonText(int iButton) const;
     101    /** Defines @a iButton @a strText. */
    101102    void setButtonText(int iButton, const QString &strText);
    102103
    103104private slots:
    104105
    105     /* Handler: Reject slot reimplementation: */
    106     void reject();
     106    /** Updates dialog size: */
     107    void sltUpdateSize();
    107108
    108     /* Handlers: Done slot variants for up to three buttons: */
    109     void done1() { m_fDone = true; done(m_iButton1 & AlertButtonMask); }
    110     void done2() { m_fDone = true; done(m_iButton2 & AlertButtonMask); }
    111     void done3() { m_fDone = true; done(m_iButton3 & AlertButtonMask); }
     109    /** Copy details-text. */
     110    void sltCopy() const;
    112111
    113     /* Handler: Copy button stuff: */
    114     void copy() const;
     112    /** Closes dialog like user would press the Cancel button. */
     113    virtual void reject();
    115114
    116     /* Handlers: Details navigation stuff: */
    117     void detailsBack();
    118     void detailsNext();
    119 
    120     /* Handler: Update stuff: */
    121     void sltUpdateSize();
     115    /** Closes dialog like user would press the 1st button. */
     116    void sltDone1() { m_fDone = true; done(m_iButton1 & AlertButtonMask); }
     117    /** Closes dialog like user would press the 2nd button. */
     118    void sltDone2() { m_fDone = true; done(m_iButton2 & AlertButtonMask); }
     119    /** Closes dialog like user would press the 3rd button. */
     120    void sltDone3() { m_fDone = true; done(m_iButton3 & AlertButtonMask); }
    122121
    123122private:
    124123
    125     /* Helpers: Prepare stuff: */
    126     void prepareContent();
     124    /** Prepare routine. */
     125    void prepare();
     126
     127    /** Push-button factory. */
    127128    QPushButton* createButton(int iButton);
    128129
    129     /* Handler: Event-processing stuff: */
     130    /** Polish-event handler. */
    130131    void polishEvent(QShowEvent *pPolishEvent);
     132    /** Close-event handler. */
    131133    void closeEvent(QCloseEvent *pCloseEvent);
    132134
    133     /* Helpers: Update stuff: */
     135    /** Visibility update routine for details-container. */
    134136    void updateDetailsContainer();
    135     void updateDetailsPage();
     137    /** Visibility update routine for check-box. */
    136138    void updateCheckBox();
    137139
    138     /* Static helper: Standard pixmap stuff: */
     140    /** Generates standard pixmap for passed @a iconType using @a pWidget as hint. */
    139141    static QPixmap standardPixmap(AlertIconType iconType, QWidget *pWidget = 0);
    140142
    141     /* Variables: */
    142     int m_iButton1, m_iButton2, m_iButton3, m_iButtonEsc;
     143    /** Holds the title. */
     144    QString m_strTitle;
     145
     146    /** Holds the icon-type. */
    143147    AlertIconType m_iconType;
    144     QLabel *m_pIconLabel;
    145     QILabel *m_pTextLabel;
    146     QPushButton *m_pButton1, *m_pButton2, *m_pButton3;
     148    /** Holds the icon-label instance. */
     149    QLabel *m_pLabelIcon;
     150
     151    /** Holds the message. */
     152    QString m_strMessage;
     153    /** Holds the message-label instance. */
     154    QILabel *m_pLabelText;
     155
     156    /** Holds the flag check-box instance. */
    147157    QCheckBox *m_pFlagCheckBox;
     158
     159    /** Holds the flag details-container instance. */
    148160    QIArrowSplitter *m_pDetailsContainer;
    149     QTextEdit *m_pDetailsTextView;
     161
     162    /** Holds the integer-code for the 1st button. */
     163    int m_iButton1;
     164    /** Holds the integer-code for the 2nd button. */
     165    int m_iButton2;
     166    /** Holds the integer-code for the 3rd button. */
     167    int m_iButton3;
     168    /** Holds the integer-code of the cancel-button. */
     169    int m_iButtonEsc;
     170    /** Holds the 1st button instance. */
     171    QPushButton *m_pButton1;
     172    /** Holds the 2nd button instance. */
     173    QPushButton *m_pButton2;
     174    /** Holds the 3rd button instance. */
     175    QPushButton *m_pButton3;
     176    /** Holds the button-box instance. */
    150177    QIDialogButtonBox *m_pButtonBox;
    151     QString m_strMessage;
    152     QList<QPair<QString, QString> > m_details;
    153     int m_iDetailsIndex;
     178
     179    /** Defines whether message was accepted. */
    154180    bool m_fDone : 1;
    155181};
    156182
    157 #endif
    158 
     183#endif /* !___QIMessageBox_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichToolButton.cpp

    r51279 r51873  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QIRichToolButton class implementation
     3 * VBox Qt GUI - QIRichToolButton class declaration.
    64 */
    75
    86/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1816 */
    1917
    20 /* VBox includes */
    21 #include "QIRichToolButton.h"
    22 
    23 /* Qt includes */
    24 #include <QApplication>
     18/* Qt includes: */
     19#include <QHBoxLayout>
    2520#include <QLabel>
    26 #include <QHBoxLayout>
    27 #include <QToolButton>
    28 #include <QKeyEvent>
    2921#include <QStylePainter>
    3022#include <QStyleOptionFocusRect>
     23#include <QKeyEvent>
    3124
    32 QIRichToolButton::QIRichToolButton (QWidget *aParent)
    33     : QWidget(aParent)
    34     , mButton(new QIToolButton)
    35     , mLabel(new QLabel)
     25/* GUI includes: */
     26#include "QIRichToolButton.h"
     27#include "QIToolButton.h"
     28
     29/* Other VBox includes: */
     30#include "iprt/assert.h"
     31
     32QIRichToolButton::QIRichToolButton(QWidget *pParent)
     33    : QWidget(pParent)
     34    , m_pButton(0)
     35    , m_pLabel(0)
    3636{
    37     init();
     37    /* Prepare: */
     38    prepare();
    3839}
    3940
    40 QIRichToolButton::QIRichToolButton (const QString &aName, QWidget *aParent)
    41     : QWidget(aParent)
    42     , mButton(new QIToolButton)
    43     , mLabel(new QLabel(aName))
     41void QIRichToolButton::setIconSize(const QSize &iconSize)
    4442{
    45     init();
     43    m_pButton->setIconSize(iconSize);
    4644}
    4745
    48 void QIRichToolButton::init()
     46void QIRichToolButton::setIcon(const QIcon &icon)
    4947{
    50     /* Setup itself */
    51     setFocusPolicy (Qt::StrongFocus);
    52 
    53     /* Setup tool-button */
    54     mButton->removeBorder();
    55     mButton->setFocusPolicy (Qt::NoFocus);
    56     connect (mButton, SIGNAL (clicked (bool)), this, SLOT (buttonClicked()));
    57 
    58     /* Setup text-label */
    59     mLabel->setBuddy (mButton);
    60     mLabel->setStyleSheet ("QLabel {padding: 2px 0px 2px 0px;}");
    61 
    62     /* Setup main-layout */
    63     QHBoxLayout *mainLayout = new QHBoxLayout (this);
    64     mainLayout->setContentsMargins(0, 0, 0, 0);
    65     mainLayout->setSpacing (0);
    66     mainLayout->addWidget (mButton);
    67     mainLayout->addWidget (mLabel);
    68 
    69     /* Install event-filter */
    70     qApp->installEventFilter (this);
     48    m_pButton->setIcon(icon);
    7149}
    7250
    73 bool QIRichToolButton::eventFilter (QObject *aObject, QEvent *aEvent)
     51void QIRichToolButton::animateClick()
    7452{
    75     /* Process only QIRichToolButton or children */
    76     if (!(aObject == this || children().contains (aObject)))
    77         return QWidget::eventFilter (aObject, aEvent);
     53    m_pButton->animateClick();
     54}
    7855
    79     /* Process keyboard events */
    80     if (aEvent->type() == QEvent::KeyPress)
     56void QIRichToolButton::setText(const QString &strText)
     57{
     58    m_pLabel->setText(strText);
     59}
     60
     61void QIRichToolButton::paintEvent(QPaintEvent *pEvent)
     62{
     63    /* Draw focus around whole button if focused: */
     64    if (hasFocus())
    8165    {
    82         QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
    83         if (kEvent->key() == Qt::Key_Space)
    84             animateClick();
     66        QStylePainter painter(this);
     67        QStyleOptionFocusRect option;
     68        option.initFrom(this);
     69        option.rect = geometry();
     70        painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
    8571    }
    8672
    87     /* Process mouse events */
    88     if ((aEvent->type() == QEvent::MouseButtonPress ||
    89          aEvent->type() == QEvent::MouseButtonDblClick)
    90         && aObject == mLabel)
    91     {
    92         /* Label click as toggle */
    93         animateClick();
    94     }
    95 
    96     /* Default one handler */
    97     return QWidget::eventFilter (aObject, aEvent);
     73    /* Call to base-class: */
     74    QWidget::paintEvent(pEvent);
    9875}
    9976
    100 void QIRichToolButton::paintEvent (QPaintEvent *aEvent)
     77void QIRichToolButton::keyPressEvent(QKeyEvent *pEvent)
    10178{
    102     /* Draw focus around mLabel if focused */
    103     if (hasFocus())
     79    /* Handle different keys: */
     80    switch (pEvent->key())
    10481    {
    105         QStylePainter painter (this);
    106         QStyleOptionFocusRect option;
    107         option.initFrom (this);
    108         option.rect = mLabel->frameGeometry();
    109         painter.drawPrimitive (QStyle::PE_FrameFocusRect, option);
     82        /* Animate-click for the Space key: */
     83        case Qt::Key_Space: return animateClick();
     84        default: break;
    11085    }
    111     QWidget::paintEvent (aEvent);
     86    /* Call to base-class: */
     87    QWidget::keyPressEvent(pEvent);
    11288}
    11389
     90void QIRichToolButton::mousePressEvent(QMouseEvent *pEvent)
     91{
     92    /* Animate-click: */
     93    animateClick();
     94}
     95
     96void QIRichToolButton::prepare()
     97{
     98    /* Enable string focus: */
     99    setFocusPolicy(Qt::StrongFocus);
     100
     101    /* Create main-layout: */
     102    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
     103    AssertPtrReturnVoid(pMainLayout);
     104    {
     105        /* Configure main-layout: */
     106        pMainLayout->setContentsMargins(0, 0, 0, 0);
     107        pMainLayout->setSpacing(0);
     108        /* Create tool-button: */
     109        m_pButton = new QIToolButton;
     110        AssertPtrReturnVoid(m_pButton);
     111        {
     112            /* Configure tool-button: */
     113            m_pButton->removeBorder();
     114            m_pButton->setFocusPolicy(Qt::NoFocus);
     115            connect(m_pButton, SIGNAL(clicked(bool)), this, SLOT(sltButtonClicked()));
     116            connect(m_pButton, SIGNAL(clicked(bool)), this, SIGNAL(sigClicked()));
     117            /* Add tool-button into main-layout: */
     118            pMainLayout->addWidget(m_pButton);
     119        }
     120        /* Create text-label: */
     121        m_pLabel = new QLabel;
     122        AssertPtrReturnVoid(m_pLabel);
     123        {
     124            /* Configure text-label: */
     125            m_pLabel->setBuddy(m_pButton);
     126            m_pLabel->setStyleSheet("QLabel {padding: 2px 0px 2px 0px;}");
     127            /* Add text-label into main-layout: */
     128            pMainLayout->addWidget(m_pLabel);
     129        }
     130    }
     131}
     132
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichToolButton.h

    r51279 r51873  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIRichToolButton class declaration
     2 * VBox Qt GUI - QIRichToolButton class declaration.
    53 */
    64
    75/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __QIRichToolButton_h__
    20 #define __QIRichToolButton_h__
     17#ifndef ___QIRichToolButton_h___
     18#define ___QIRichToolButton_h___
    2119
    2220/* Qt includes: */
    23 #include <QLabel>
    2421#include <QWidget>
    2522
    26 /* GUI includes: */
    27 #include "QIToolButton.h"
     23/* Forward declarations: */
     24class QIToolButton;
     25class QLabel;
    2826
    29 /** @class QIRichToolButton
    30  *
    31  *  The QIRichToolButton class is a tool-button with separate text-label.
    32  *
    33  */
     27/** QWidget extension
     28  * representing tool-button with separate text-label. */
    3429class QIRichToolButton : public QWidget
    3530{
    3631    Q_OBJECT;
    3732
     33signals:
     34
     35    /** Notifies listeners about button click. */
     36    void sigClicked();
     37
    3838public:
    3939
    40     QIRichToolButton (QWidget *aParent = 0);
    41     QIRichToolButton (const QString &aName, QWidget *aParent = 0);
     40    /** Constructor, passes @a pParent to the QWidget constructor. */
     41    QIRichToolButton(QWidget *pParent = 0);
    4242
    43     void animateClick() { mButton->animateClick(); }
    44     void setText (const QString &aName) { mLabel->setText (aName); }
    45     QString text() const { return mLabel->text(); }
     43    /** Defines tool-button @a iconSize. */
     44    void setIconSize(const QSize &iconSize);
     45    /** Defines tool-button @a icon. */
     46    void setIcon(const QIcon &icon);
     47    /** Animates tool-button click: */
     48    void animateClick();
    4649
    47 signals:
    48 
    49     void clicked();
     50    /** Defines text-label @a strText. */
     51    void setText(const QString &strText);
    5052
    5153protected slots:
    5254
    53     virtual void buttonClicked() { emit clicked(); }
     55    /** Button-click handler. */
     56    virtual void sltButtonClicked() {}
    5457
    5558protected:
    5659
    57     void init();
    58     bool eventFilter (QObject *aObject, QEvent *aEvent);
    59     void paintEvent (QPaintEvent *aEvent);
     60    /** Paint-event handler. */
     61    virtual void paintEvent(QPaintEvent *pEvent);
     62    /** Key-press-event handler. */
     63    virtual void keyPressEvent(QKeyEvent *pEvent);
     64    /** Mouse-press-event handler. */
     65    virtual void mousePressEvent(QMouseEvent *pEvent);
    6066
    61     QIToolButton *mButton;
    62     QLabel *mLabel;
     67private:
     68
     69    /** Prepare routine. */
     70    void prepare();
     71
     72    /** Holds the tool-button instance. */
     73    QIToolButton *m_pButton;
     74    /** Holds the text-label instance. */
     75    QLabel *m_pLabel;
     76    /** Holds the text for text-label instance. */
     77    QString m_strName;
    6378};
    6479
    65 #endif
    66 
     80#endif /* !___QIRichToolButton_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp

    r51280 r51873  
    6060    m_pMACEditor->setMinimumWidthByText(QString().fill('0', 12));
    6161    m_pMACButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
     62    m_pAdvancedArrow->setIconSize(QSize(10, 10));
     63    m_pAdvancedArrow->setIconForButtonState(QIArrowButtonSwitch::ButtonState_Collapsed,
     64                                            UIIconPool::iconSet(":/arrow_right_10px.png"));
     65    m_pAdvancedArrow->setIconForButtonState(QIArrowButtonSwitch::ButtonState_Expanded,
     66                                            UIIconPool::iconSet(":/arrow_down_10px.png"));
    6267
    6368    /* Setup connections: */
     
    6671    connect(m_pAdapterNameCombo, SIGNAL(activated(int)), this, SLOT(sltHandleAlternativeNameChange()));
    6772    connect(m_pAdapterNameCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(sltHandleAlternativeNameChange()));
    68     connect(m_pAdvancedArrow, SIGNAL(clicked()), this, SLOT(sltHandleAdvancedButtonStateChange()));
     73    connect(m_pAdvancedArrow, SIGNAL(sigClicked()), this, SLOT(sltHandleAdvancedButtonStateChange()));
    6974    connect(m_pMACButton, SIGNAL(clicked()), this, SLOT(sltGenerateMac()));
    7075    connect(m_pPortForwardingButton, SIGNAL(clicked()), this, SLOT(sltOpenPortForwardingDlg()));
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