Changeset 71552 in vbox
- Timestamp:
- Mar 28, 2018 5:01:46 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/VBoxLicenseViewer.cpp
r69726 r71552 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 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" 22 31 # include "VBoxLicenseViewer.h" 23 # include "QIDialogButtonBox.h"24 32 # include "UIMessageCenter.h" 25 26 /* Qt includes */27 # include <QTextBrowser>28 # include <QPushButton>29 # include <QVBoxLayout>30 # include <QScrollBar>31 # include <QFile>32 33 33 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 36 37 VBoxLicenseViewer::VBoxLicenseViewer(QWidget *pParent /* = 0 */) 37 38 : QIWithRetranslateUI2<QDialog>(pParent) 38 , m LicenseText(0)39 , m AgreeButton(0)40 , m DisagreeButton(0)39 , m_pLicenseBrowser(0) 40 , m_pButtonAgree(0) 41 , m_pButtonDisagree(0) 41 42 { 42 #if ndef VBOX_WS_WIN43 /* A pplication 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")); 45 46 #endif 46 47 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); 53 60 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 } 58 64 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); 62 76 63 mLicenseText->verticalScrollBar()->installEventFilter (this); 77 /* Add into button-box: */ 78 pDialogButtonBox->addButton(m_pButtonAgree, QDialogButtonBox::AcceptRole); 79 } 64 80 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); 66 87 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: */ 67 101 retranslateUi(); 102 } 103 104 int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText) 105 { 106 /* Set license text: */ 107 m_pLicenseBrowser->setText(strLicenseText); 108 return exec(); 68 109 } 69 110 … … 73 114 QFile file(strLicenseFileName); 74 115 if (file.open(QIODevice::ReadOnly)) 75 {76 116 return showLicenseFromString(file.readAll()); 77 }78 117 else 79 118 { … … 83 122 } 84 123 85 int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)124 bool VBoxLicenseViewer::eventFilter(QObject *pObject, QEvent *pEvent) 86 125 { 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 141 void 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); 90 151 } 91 152 92 153 void VBoxLicenseViewer::retranslateUi() 93 154 { 94 setWindowTitle (tr ("VirtualBox License")); 155 /* Translate dialog title: */ 156 setWindowTitle(tr("VirtualBox License")); 95 157 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")); 98 161 } 99 162 100 163 int VBoxLicenseViewer::exec() 101 164 { 165 /* Nothing wrong with that, just hiding slot: */ 102 166 return QDialog::exec(); 103 167 } 104 168 105 void VBoxLicenseViewer:: onScrollBarMoving (int aValue)169 void VBoxLicenseViewer::sltHandleScrollBarMoved(int iValue) 106 170 { 107 if ( aValue == mLicenseText->verticalScrollBar()->maximum())108 unlockButtons();171 if (iValue == m_pLicenseBrowser->verticalScrollBar()->maximum()) 172 sltUnlockButtons(); 109 173 } 110 174 111 void VBoxLicenseViewer:: unlockButtons()175 void VBoxLicenseViewer::sltUnlockButtons() 112 176 { 113 m AgreeButton->setEnabled(true);114 m DisagreeButton->setEnabled(true);177 m_pButtonAgree->setEnabled(true); 178 m_pButtonDisagree->setEnabled(true); 115 179 } 116 180 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 starts133 * 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 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ VBoxLicenseViewer__19 #define __ VBoxLicenseViewer__18 #ifndef ___VBoxLicenseViewer___ 19 #define ___VBoxLicenseViewer___ 20 20 21 /* Qt includes: */ 22 #include <QDialog> 23 24 /* GUI includes: */ 21 25 #include "QIWithRetranslateUI.h" 22 26 23 /* Qt includes */ 24 #include <QDialog> 25 27 /* Forward declarations: */ 26 28 class QTextBrowser; 27 29 class QPushButton; 28 30 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. */ 32 32 class VBoxLicenseViewer : public QIWithRetranslateUI2<QDialog> 33 33 { … … 36 36 public: 37 37 38 /** Constructs license viewer passing @a pParent to the base-class. */ 38 39 VBoxLicenseViewer(QWidget *pParent = 0); 39 40 41 /** Shows license from passed @a strLicenseText. */ 42 int showLicenseFromString(const QString &strLicenseText); 43 /** Shows license from file with passed @a strLicenseFileName. */ 40 44 int showLicenseFromFile(const QString &strLicenseFileName); 41 int showLicenseFromString(const QString &strLicenseText);42 45 43 46 protected: 44 47 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 */; 46 56 47 57 private slots: 48 58 59 /** Executes the dialog. */ 49 60 int exec(); 50 61 51 void onScrollBarMoving (int aValue); 62 /** Handles scroll-bar moving by a certain @a iValue. */ 63 void sltHandleScrollBarMoved(int iValue); 52 64 53 void unlockButtons(); 65 /** Uplocks buttons. */ 66 void sltUnlockButtons(); 54 67 55 68 private: 56 69 57 void showEvent (QShowEvent *aEvent); 70 /** Holds the licence text browser instance. */ 71 QTextBrowser *m_pLicenseBrowser; 58 72 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; 65 77 }; 66 78 67 #endif /* __VBoxLicenseViewer__ */79 #endif /* !___VBoxLicenseViewer___ */ 68 80
Note:
See TracChangeset
for help on using the changeset viewer.