VirtualBox

Changeset 71552 in vbox


Ignore:
Timestamp:
Mar 28, 2018 5:01:46 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for VBoxLicenseViewer.

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

Legend:

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

    r69726 r71552  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
     22/* Qt includes: */
     23# include <QFile>
     24# include <QPushButton>
     25# include <QScrollBar>
     26# include <QTextBrowser>
     27# include <QVBoxLayout>
     28
     29/* GUI includes: */
     30# include "QIDialogButtonBox.h"
    2231# include "VBoxLicenseViewer.h"
    23 # include "QIDialogButtonBox.h"
    2432# include "UIMessageCenter.h"
    25 
    26 /* Qt includes */
    27 # include <QTextBrowser>
    28 # include <QPushButton>
    29 # include <QVBoxLayout>
    30 # include <QScrollBar>
    31 # include <QFile>
    3233
    3334#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3637VBoxLicenseViewer::VBoxLicenseViewer(QWidget *pParent /* = 0 */)
    3738    : QIWithRetranslateUI2<QDialog>(pParent)
    38     , mLicenseText (0)
    39     , mAgreeButton (0)
    40     , mDisagreeButton (0)
     39    , m_pLicenseBrowser(0)
     40    , m_pButtonAgree(0)
     41    , m_pButtonDisagree(0)
    4142{
    42 #ifndef VBOX_WS_WIN
    43     /* Application icon. On Win32, it's built-in to the executable. */
    44     setWindowIcon (QIcon (":/VirtualBox_48px.png"));
     43#if !(defined(VBOX_WS_WIN) || defined(VBOX_WS_MAC))
     44    /* Assign application icon: */
     45    setWindowIcon(QIcon(":/VirtualBox_48px.png"));
    4546#endif
    4647
    47     mLicenseText = new QTextBrowser (this);
    48     mAgreeButton = new QPushButton (this);
    49     mDisagreeButton = new QPushButton (this);
    50     QDialogButtonBox *dbb = new QIDialogButtonBox (this);
    51     dbb->addButton (mAgreeButton, QDialogButtonBox::AcceptRole);
    52     dbb->addButton (mDisagreeButton, QDialogButtonBox::RejectRole);
     48    /* Create main layout: */
     49    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     50    if (pMainLayout)
     51    {
     52        /* Create license browser: */
     53        m_pLicenseBrowser = new QTextBrowser(this);
     54        if (m_pLicenseBrowser)
     55        {
     56            /* Configure license browser: */
     57            m_pLicenseBrowser->verticalScrollBar()->installEventFilter(this);
     58            connect(m_pLicenseBrowser->verticalScrollBar(), &QScrollBar::valueChanged,
     59                    this, &VBoxLicenseViewer::sltHandleScrollBarMoved);
    5360
    54     connect (mLicenseText->verticalScrollBar(), SIGNAL (valueChanged (int)),
    55              SLOT (onScrollBarMoving (int)));
    56     connect (mAgreeButton, SIGNAL (clicked()), SLOT (accept()));
    57     connect (mDisagreeButton, SIGNAL (clicked()), SLOT (reject()));
     61            /* Add into layout: */
     62            pMainLayout->addWidget(m_pLicenseBrowser);
     63        }
    5864
    59     QVBoxLayout *mainLayout = new QVBoxLayout (this);
    60     mainLayout->addWidget (mLicenseText);
    61     mainLayout->addWidget (dbb);
     65        /* Create agree button: */
     66        /** todo rework buttons to be a part of button-box itself */
     67        QDialogButtonBox *pDialogButtonBox = new QIDialogButtonBox;
     68        if (pDialogButtonBox)
     69        {
     70            /* Create agree button: */
     71            m_pButtonAgree = new QPushButton;
     72            if (m_pButtonAgree)
     73            {
     74                /* Configure button: */
     75                connect(m_pButtonAgree, &QPushButton::clicked, this, &QDialog::accept);
    6276
    63     mLicenseText->verticalScrollBar()->installEventFilter (this);
     77                /* Add into button-box: */
     78                pDialogButtonBox->addButton(m_pButtonAgree, QDialogButtonBox::AcceptRole);
     79            }
    6480
    65     resize (600, 450);
     81            /* Create agree button: */
     82            m_pButtonDisagree = new QPushButton;
     83            if (m_pButtonDisagree)
     84            {
     85                /* Configure button: */
     86                connect(m_pButtonDisagree, &QPushButton::clicked, this, &QDialog::reject);
    6687
     88                /* Add into button-box: */
     89                pDialogButtonBox->addButton(m_pButtonDisagree, QDialogButtonBox::RejectRole);
     90            }
     91        }
     92
     93        /* Add into layout: */
     94        pMainLayout->addWidget(pDialogButtonBox);
     95    }
     96
     97    /* Configure self: */
     98    resize(600, 450);
     99
     100    /* Apply language settings: */
    67101    retranslateUi();
     102}
     103
     104int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)
     105{
     106    /* Set license text: */
     107    m_pLicenseBrowser->setText(strLicenseText);
     108    return exec();
    68109}
    69110
     
    73114    QFile file(strLicenseFileName);
    74115    if (file.open(QIODevice::ReadOnly))
    75     {
    76116        return showLicenseFromString(file.readAll());
    77     }
    78117    else
    79118    {
     
    83122}
    84123
    85 int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)
     124bool VBoxLicenseViewer::eventFilter(QObject *pObject, QEvent *pEvent)
    86125{
    87     /* Set license text: */
    88     mLicenseText->setText(strLicenseText);
    89     return exec();
     126    /* Handle known event types: */
     127    switch (pEvent->type())
     128    {
     129        case QEvent::Hide:
     130            if (pObject == m_pLicenseBrowser->verticalScrollBar())
     131                /* Doesn't work on wm's like ion3 where the window starts maximized: isActiveWindow() */
     132                sltUnlockButtons();
     133        default:
     134            break;
     135    }
     136
     137    /* Call to base-class: */
     138    return QDialog::eventFilter(pObject, pEvent);
     139}
     140
     141void VBoxLicenseViewer::showEvent(QShowEvent *pEvent)
     142{
     143    /* Call to base-class: */
     144    QDialog::showEvent(pEvent);
     145
     146    /* Enable/disable buttons accordingly: */
     147    bool fScrollBarHidden =    !m_pLicenseBrowser->verticalScrollBar()->isVisible()
     148                            && !(windowState() & Qt::WindowMinimized);
     149    m_pButtonAgree->setEnabled(fScrollBarHidden);
     150    m_pButtonDisagree->setEnabled(fScrollBarHidden);
    90151}
    91152
    92153void VBoxLicenseViewer::retranslateUi()
    93154{
    94     setWindowTitle (tr ("VirtualBox License"));
     155    /* Translate dialog title: */
     156    setWindowTitle(tr("VirtualBox License"));
    95157
    96     mAgreeButton->setText (tr ("I &Agree"));
    97     mDisagreeButton->setText (tr ("I &Disagree"));
     158    /* Translate buttons: */
     159    m_pButtonAgree->setText(tr("I &Agree"));
     160    m_pButtonDisagree->setText(tr("I &Disagree"));
    98161}
    99162
    100163int VBoxLicenseViewer::exec()
    101164{
     165    /* Nothing wrong with that, just hiding slot: */
    102166    return QDialog::exec();
    103167}
    104168
    105 void VBoxLicenseViewer::onScrollBarMoving (int aValue)
     169void VBoxLicenseViewer::sltHandleScrollBarMoved(int iValue)
    106170{
    107     if (aValue == mLicenseText->verticalScrollBar()->maximum())
    108         unlockButtons();
     171    if (iValue == m_pLicenseBrowser->verticalScrollBar()->maximum())
     172        sltUnlockButtons();
    109173}
    110174
    111 void VBoxLicenseViewer::unlockButtons()
     175void VBoxLicenseViewer::sltUnlockButtons()
    112176{
    113     mAgreeButton->setEnabled (true);
    114     mDisagreeButton->setEnabled (true);
     177    m_pButtonAgree->setEnabled(true);
     178    m_pButtonDisagree->setEnabled(true);
    115179}
    116180
    117 void VBoxLicenseViewer::showEvent (QShowEvent *aEvent)
    118 {
    119     QDialog::showEvent (aEvent);
    120     bool isScrollBarHidden = !mLicenseText->verticalScrollBar()->isVisible()
    121         && !(windowState() & Qt::WindowMinimized);
    122     mAgreeButton->setEnabled (isScrollBarHidden);
    123     mDisagreeButton->setEnabled (isScrollBarHidden);
    124 }
    125 
    126 bool VBoxLicenseViewer::eventFilter (QObject *aObject, QEvent *aEvent)
    127 {
    128     switch (aEvent->type())
    129     {
    130         case QEvent::Hide:
    131             if (aObject == mLicenseText->verticalScrollBar())
    132                 /* Doesn't work on wm's like ion3 where the window starts
    133                  * maximized: isActiveWindow() */
    134                 unlockButtons();
    135         default:
    136             break;
    137     }
    138     return QDialog::eventFilter (aObject, aEvent);
    139 }
    140 
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxLicenseViewer.h

    r69500 r71552  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __VBoxLicenseViewer__
    19 #define __VBoxLicenseViewer__
     18#ifndef ___VBoxLicenseViewer___
     19#define ___VBoxLicenseViewer___
    2020
     21/* Qt includes: */
     22#include <QDialog>
     23
     24/* GUI includes: */
    2125#include "QIWithRetranslateUI.h"
    2226
    23 /* Qt includes */
    24 #include <QDialog>
    25 
     27/* Forward declarations: */
    2628class QTextBrowser;
    2729class QPushButton;
    2830
    29 /**
    30  *  This class is used to show a user license under linux.
    31  */
     31/** QDialog subclass used to show a user license under linux. */
    3232class VBoxLicenseViewer : public QIWithRetranslateUI2<QDialog>
    3333{
     
    3636public:
    3737
     38    /** Constructs license viewer passing @a pParent to the base-class. */
    3839    VBoxLicenseViewer(QWidget *pParent = 0);
    3940
     41    /** Shows license from passed @a strLicenseText. */
     42    int showLicenseFromString(const QString &strLicenseText);
     43    /** Shows license from file with passed @a strLicenseFileName. */
    4044    int showLicenseFromFile(const QString &strLicenseFileName);
    41     int showLicenseFromString(const QString &strLicenseText);
    4245
    4346protected:
    4447
    45     void retranslateUi();
     48    /** Preprocesses Qt @a pEvent for passed @a pObject. */
     49    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     50
     51    /** Handles Qt show @a pEvent. */
     52    virtual void showEvent(QShowEvent *pEvent) /* override */;
     53
     54    /** Handles translation event. */
     55    virtual void retranslateUi() /* override */;
    4656
    4757private slots:
    4858
     59    /** Executes the dialog. */
    4960    int exec();
    5061
    51     void onScrollBarMoving (int aValue);
     62    /** Handles scroll-bar moving by a certain @a iValue. */
     63    void sltHandleScrollBarMoved(int iValue);
    5264
    53     void unlockButtons();
     65    /** Uplocks buttons. */
     66    void sltUnlockButtons();
    5467
    5568private:
    5669
    57     void showEvent (QShowEvent *aEvent);
     70    /** Holds the licence text browser instance. */
     71    QTextBrowser *m_pLicenseBrowser;
    5872
    59     bool eventFilter (QObject *aObject, QEvent *aEvent);
    60 
    61     /* Private member vars */
    62     QTextBrowser *mLicenseText;
    63     QPushButton  *mAgreeButton;
    64     QPushButton  *mDisagreeButton;
     73    /** Holds the licence agree button instance. */
     74    QPushButton *m_pButtonAgree;
     75    /** Holds the licence disagree button instance. */
     76    QPushButton *m_pButtonDisagree;
    6577};
    6678
    67 #endif /* __VBoxLicenseViewer__ */
     79#endif /* !___VBoxLicenseViewer___ */
    6880
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