VirtualBox

Changeset 57551 in vbox


Ignore:
Timestamp:
Aug 26, 2015 4:04:27 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: About-VirtualBox Dialog: Rework/Cleanup and coding style improvements.

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

Legend:

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

    r57511 r57551  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Global includes */
     22/* Qt includes: */
    2323# include <QDir>
    2424# include <QEvent>
     25# include <QLabel>
    2526# include <QPainter>
    26 # include <QLabel>
     27
     28/* GUI includes: */
     29# include "UIConverter.h"
     30# include "UIExtraDataManager.h"
     31# include "UIIconPool.h"
     32# include "VBoxAboutDlg.h"
     33# include "VBoxGlobal.h"
     34
     35/* Other VBox includes: */
    2736# include <iprt/path.h>
    2837# include <VBox/version.h> /* VBOX_VENDOR */
    2938
    30 /* Local includes */
    31 # include "VBoxAboutDlg.h"
    32 # include "VBoxGlobal.h"
    33 # include "UIConverter.h"
    34 # include "UIExtraDataManager.h"
    35 # include "UIIconPool.h"
    36 
    3739#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    38 
    3940
    4041VBoxAboutDlg::VBoxAboutDlg(QWidget *pParent, const QString &strVersion)
     
    4243    , m_strVersion(strVersion)
    4344{
    44     /* Delete dialog on close: */
    45     setAttribute(Qt::WA_DeleteOnClose);
    46 
    47     /* Choose default image: */
    48     QString strPath(":/about.png");
    49 
    50     /* Branding: Use a custom about splash picture if set: */
    51     QString strSplash = vboxGlobal().brandingGetKey("UI/AboutSplash");
    52     if (vboxGlobal().brandingIsActive() && !strSplash.isEmpty())
    53     {
    54         char szExecPath[1024];
    55         RTPathExecDir(szExecPath, 1024);
    56         QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
    57         if (QFile::exists(strTmpPath))
    58             strPath = strTmpPath;
    59     }
    60 
    61     /* Load image: */
    62     QIcon icon = UIIconPool::iconSet(strPath);
    63     m_size = icon.availableSizes().first();
    64     m_pixmap = icon.pixmap(m_size);
    65 
    66     /* Create main layout: */
    67     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    68 
    69     /* Create label for version text: */
    70     m_pLabel = new QLabel();
    71     pMainLayout->addWidget(m_pLabel);
    72 
    73     QPalette palette;
    74     /* Branding: Set a different text color (because splash also could be white),
    75      * otherwise use white as default color: */
    76     QString strColor = vboxGlobal().brandingGetKey("UI/AboutTextColor");
    77     if (!strColor.isEmpty())
    78         palette.setColor(QPalette::WindowText, QColor(strColor).name());
    79     else
    80         palette.setColor(QPalette::WindowText, Qt::black);
    81     m_pLabel->setPalette(palette);
    82     m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
    83     m_pLabel->setFont(font());
    84 
    85     pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
    86 
    87     /* Translate: */
    88     retranslateUi();
     45    /* Prepare: */
     46    prepare();
    8947}
    9048
     
    12179}
    12280
     81void VBoxAboutDlg::prepare()
     82{
     83    /* Delete dialog on close: */
     84    setAttribute(Qt::WA_DeleteOnClose);
     85
     86    /* Choose default image: */
     87    QString strPath(":/about.png");
     88
     89    /* Branding: Use a custom about splash picture if set: */
     90    QString strSplash = vboxGlobal().brandingGetKey("UI/AboutSplash");
     91    if (vboxGlobal().brandingIsActive() && !strSplash.isEmpty())
     92    {
     93        char szExecPath[1024];
     94        RTPathExecDir(szExecPath, 1024);
     95        QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
     96        if (QFile::exists(strTmpPath))
     97            strPath = strTmpPath;
     98    }
     99
     100    /* Load image: */
     101    QIcon icon = UIIconPool::iconSet(strPath);
     102    m_size = icon.availableSizes().first();
     103    m_pixmap = icon.pixmap(m_size);
     104
     105    /* Prepare main-layout: */
     106    prepareMainLayout();
     107
     108    /* Translate: */
     109    retranslateUi();
     110}
     111
     112void VBoxAboutDlg::prepareMainLayout()
     113{
     114    /* Create main-layout: */
     115    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     116    AssertPtrReturnVoid(pMainLayout);
     117    {
     118        /* Create label for version text: */
     119        m_pLabel = new QLabel;
     120        AssertPtrReturnVoid(m_pLabel);
     121        {
     122            /* Prepare label for version text: */
     123
     124            QPalette palette;
     125            /* Branding: Set a different text color (because splash also could be white),
     126             * otherwise use white as default color: */
     127            QString strColor = vboxGlobal().brandingGetKey("UI/AboutTextColor");
     128            if (!strColor.isEmpty())
     129                palette.setColor(QPalette::WindowText, QColor(strColor).name());
     130            else
     131                palette.setColor(QPalette::WindowText, Qt::black);
     132            m_pLabel->setPalette(palette);
     133            m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
     134            m_pLabel->setFont(font());
     135
     136            /* Add label to the main-layout: */
     137            pMainLayout->addWidget(m_pLabel);
     138            pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
     139        }
     140    }
     141}
     142
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxAboutDlg.h

    r57511 r57551  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __VBoxAboutDlg_h__
    19 #define __VBoxAboutDlg_h__
     18#ifndef ___VBoxAboutDlg_h___
     19#define ___VBoxAboutDlg_h___
    2020
    21 /* Global includes */
     21/* Qt includes: */
    2222#include <QPixmap>
    2323
    24 /* Local includes */
     24/* GUI includes: */
     25#include "QIDialog.h"
    2526#include "QIWithRetranslateUI.h"
    26 #include "QIDialog.h"
    2727
    28 /* Forward declarations */
     28/* Forward declarations: */
    2929class QEvent;
    3030class QLabel;
    3131
    32 /* VBox about dialog */
    33 class VBoxAboutDlg: public QIWithRetranslateUI2<QIDialog>
     32/** QIDialog extension
     33  * used to show the About-VirtualBox dialog. */
     34class VBoxAboutDlg : public QIWithRetranslateUI2<QIDialog>
    3435{
    3536    Q_OBJECT;
     
    3738public:
    3839
    39     /* Constructor: */
     40    /** Constructs dialog passing @a pParent to the QWidget base-class constructor.
     41      * @param strVersion is used to specify the version number of VirtualBox. */
    4042    VBoxAboutDlg(QWidget* pParent, const QString &strVersion);
    4143
    4244protected:
    4345
    44     /* Event handlers: */
     46    /** Handles Qt polish event. */
    4547    bool event(QEvent *pEvent);
     48
     49    /** Handles Qt paint-event to draw About-VirtualBox image. */
    4650    void paintEvent(QPaintEvent *pEvent);
    4751
    48     /* Language stuff: */
     52    /** Handles translation event. */
    4953    void retranslateUi();
    5054
    5155private:
    5256
    53     /* Variables: */
     57    /** Prepare About-VirtualBox dialog. */
     58    void prepare();
     59
     60    /** Prepare main-layout routine. */
     61    void prepareMainLayout();
     62
     63    /** Holds the About-VirtualBox text. */
    5464    QString m_strAboutText;
     65
     66    /** Holds the VirtualBox version number. */
    5567    QString m_strVersion;
     68
     69    /** Holds the About-VirtualBox image. */
    5670    QPixmap m_pixmap;
     71
     72    /** Holds the About-VirtualBox dialog size. */
    5773    QSize   m_size;
     74
     75    /** Holds the instance of label we create for About-VirtualBox text. */
    5876    QLabel *m_pLabel;
    5977};
    6078
    61 #endif /* __VBoxAboutDlg_h__ */
     79#endif /* !___VBoxAboutDlg_h___ */
    6280
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