Changeset 75222 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 2, 2018 12:37:05 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r75220 r75222 764 764 src/extensions/QIFileDialog.h \ 765 765 src/extensions/QIFlowLayout.h \ 766 src/extensions/QIInputDialog.h \ 766 767 src/extensions/QILabel.h \ 767 768 src/extensions/QILabelSeparator.h \ … … 1051 1052 src/extensions/QIFileDialog.h \ 1052 1053 src/extensions/QIFlowLayout.h \ 1054 src/extensions/QIInputDialog.h \ 1053 1055 src/extensions/QILabel.h \ 1054 1056 src/extensions/QILabelSeparator.h \ … … 1464 1466 src/extensions/QIFileDialog.cpp \ 1465 1467 src/extensions/QIFlowLayout.cpp \ 1468 src/extensions/QIInputDialog.cpp \ 1466 1469 src/extensions/QILabel.cpp \ 1467 1470 src/extensions/QILabelSeparator.cpp \ … … 1803 1806 src/extensions/QIFileDialog.cpp \ 1804 1807 src/extensions/QIFlowLayout.cpp \ 1808 src/extensions/QIInputDialog.cpp \ 1805 1809 src/extensions/QILabel.cpp \ 1806 1810 src/extensions/QILabelSeparator.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIInputDialog.cpp
r75215 r75222 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - Qt extensions: QI Dialog class implementation.3 * VBox Qt GUI - Qt extensions: QIInputDialog class implementation. 4 4 */ 5 5 … … 21 21 22 22 /* Qt includes: */ 23 # include <QEventLoop> 23 #include <QLabel> 24 #include <QLineEdit> 25 #include <QPushButton> 26 #include <QVBoxLayout> 24 27 25 28 /* GUI includes: */ 26 # include "QIDialog .h"27 # include " VBoxGlobal.h"29 # include "QIDialogButtonBox.h" 30 # include "QIInputDialog.h" 28 31 29 32 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 30 33 31 34 32 QI Dialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */)35 QIInputDialog::QIInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */) 33 36 : QDialog(pParent, enmFlags) 34 , m_fPolished(false) 37 , m_fDefaultLabelTextRedefined(false) 38 , m_pLabel(0) 39 , m_pTextValueEditor(0) 40 , m_pButtonBox(0) 41 { 42 /* Prepare: */ 43 prepare(); 44 } 45 46 QString QIInputDialog::labelText() const 47 { 48 return m_pLabel ? m_pLabel->text() : QString(); 49 } 50 51 void QIInputDialog::resetLabelText() 52 { 53 m_fDefaultLabelTextRedefined = false; 54 retranslateUi(); 55 } 56 57 void QIInputDialog::setLabelText(const QString &strText) 58 { 59 m_fDefaultLabelTextRedefined = true; 60 if (m_pLabel) 61 m_pLabel->setText(strText); 62 } 63 64 QString QIInputDialog::textValue() const 65 { 66 return m_pTextValueEditor ? m_pTextValueEditor->text() : QString(); 67 } 68 69 void QIInputDialog::setTextValue(const QString &strText) 70 { 71 if (m_pTextValueEditor) 72 m_pTextValueEditor->setText(strText); 73 } 74 75 void QIInputDialog::retranslateUi() 76 { 77 if (m_pLabel && !m_fDefaultLabelTextRedefined) 78 m_pLabel->setText(tr("Name:")); 79 } 80 81 void QIInputDialog::sltTextChanged() 82 { 83 if (m_pButtonBox) 84 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!textValue().isEmpty()); 85 } 86 87 void QIInputDialog::prepare() 35 88 { 36 89 /* Do not count that window as important for application, 37 * it will NOT be taken into account when other top-level windows will be closed: */ 90 * it will NOT be taken into account when other 91 * top-level windows will be closed: */ 38 92 setAttribute(Qt::WA_QuitOnClose, false); 39 }40 93 41 void QIDialog::setVisible(bool fVisible) 42 { 43 /* Call to base-class: */ 44 QDialog::setVisible(fVisible); 94 /* Create main layout: */ 95 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 96 if (pMainLayout) 97 { 98 /* Create label: */ 99 m_pLabel = new QLabel(this); 100 if (m_pLabel) 101 pMainLayout->addWidget(m_pLabel); 45 102 46 /* Exit from the event-loop if there is any and 47 * we are changing our state from visible to hidden. */ 48 if (m_pEventLoop && !fVisible) 49 m_pEventLoop->exit(); 50 } 103 /* Create text value editor: */ 104 m_pTextValueEditor = new QLineEdit(this); 105 if (m_pTextValueEditor) 106 { 107 connect(m_pTextValueEditor, &QLineEdit::textChanged, this, &QIInputDialog::sltTextChanged); 108 pMainLayout->addWidget(m_pTextValueEditor); 109 } 51 110 52 int QIDialog::execute(bool fShow /* = true */, bool fApplicationModal /* = false */) 53 { 54 /* Check for the recursive run: */ 55 AssertMsgReturn(!m_pEventLoop, ("QIDialog::execute() is called recursively!\n"), QDialog::Rejected); 56 57 /* Reset the result-code: */ 58 setResult(QDialog::Rejected); 59 60 /* Should we delete ourself on close in theory? */ 61 const bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose); 62 /* For the exec() time, set this attribute to 'false': */ 63 setAttribute(Qt::WA_DeleteOnClose, false); 64 65 /* Which is the current window-modality? */ 66 const Qt::WindowModality oldModality = windowModality(); 67 /* For the exec() time, set this attribute to 'window-modal' or 'application-modal': */ 68 setWindowModality(!fApplicationModal ? Qt::WindowModal : Qt::ApplicationModal); 69 70 /* Show ourself if requested: */ 71 if (fShow) 72 show(); 73 74 /* Create a local event-loop: */ 75 { 76 QEventLoop eventLoop; 77 m_pEventLoop = &eventLoop; 78 79 /* Guard ourself for the case 80 * we destroyed ourself in our event-loop: */ 81 QPointer<QIDialog> guard = this; 82 83 /* Start the blocking event-loop: */ 84 eventLoop.exec(); 85 86 /* Are we still valid? */ 87 if (guard.isNull()) 88 return QDialog::Rejected; 89 90 m_pEventLoop = 0; 111 /* Create button-box: */ 112 m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 113 if (m_pButtonBox) 114 { 115 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &QIInputDialog::accept); 116 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &QIInputDialog::reject); 117 pMainLayout->addWidget(m_pButtonBox); 118 } 91 119 } 92 120 93 /* Save the result-code early (we can delete ourself on close): */94 const int iResultCode = result();121 /* Apply language settings: */ 122 retranslateUi(); 95 123 96 /* Return old modality: */ 97 setWindowModality(oldModality); 98 99 /* Reset attribute to previous value: */ 100 setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose); 101 /* Delete ourself if we should do that on close: */ 102 if (fOldDeleteOnClose) 103 delete this; 104 105 /* Return the result-code: */ 106 return iResultCode; 124 /* Initialize editors: */ 125 sltTextChanged(); 107 126 } 108 109 void QIDialog::showEvent(QShowEvent *pEvent)110 {111 /* Make sure we should polish dialog: */112 if (m_fPolished)113 return;114 115 /* Call to polish-event: */116 polishEvent(pEvent);117 118 /* Mark dialog as polished: */119 m_fPolished = true;120 }121 122 void QIDialog::polishEvent(QShowEvent *)123 {124 /* Make sure layout is polished: */125 adjustSize();126 #ifdef VBOX_WS_MAC127 /* And dialog have fixed size: */128 setFixedSize(size());129 #endif /* VBOX_WS_MAC */130 131 /* Explicit centering according to our parent: */132 VBoxGlobal::centerWidget(this, parentWidget(), false);133 } -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIInputDialog.h
r75215 r75222 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - Qt extensions: QI Dialog class declaration.3 * VBox Qt GUI - Qt extensions: QIInputDialog class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ___QI Dialog_h___19 #define ___QI Dialog_h___18 #ifndef ___QIInputDialog_h___ 19 #define ___QIInputDialog_h___ 20 20 21 21 /* Qt includes: */ … … 24 24 25 25 /* GUI includes: */ 26 #include "QIWithRetranslateUI.h" 26 27 #include "UILibraryDefs.h" 27 28 28 29 /* Forward declarations: */ 29 class QEventLoop; 30 class QLabel; 31 class QLineEdit; 32 class QIDialogButtonBox; 30 33 31 34 /** QDialog extension providing the GUI with 32 * the advanced capabilities like delayed show. */33 class SHARED_LIBRARY_STUFF QI Dialog : public QDialog35 * the advanced input dialog capabilities. */ 36 class SHARED_LIBRARY_STUFF QIInputDialog : public QDialog 34 37 { 35 38 Q_OBJECT; … … 38 41 39 42 /** Constructs the dialog passing @a pParent and @a enmFlags to the base-class. */ 40 QI Dialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0);43 QIInputDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0); 41 44 42 /** Defines whether the dialog is @a fVisible. */ 43 void setVisible(bool fVisible); 45 /** Returns label text. */ 46 QString labelText() const; 47 /** Undefines label text. */ 48 void resetLabelText(); 49 /** Defines label @a strText. */ 50 void setLabelText(const QString &strText); 44 51 45 public slots: 46 47 /** Shows the dialog as a modal one, blocking until the user closes it. 48 * @param fShow Brings whether the dialog should be shown instantly. 49 * @param fApplicationModal Brings whether the dialog should be application-modal. */ 50 virtual int execute(bool fShow = true, bool fApplicationModal = false); 51 52 /** Shows the dialog as a modal one, blocking until the user closes it. */ 53 virtual int exec() /* override */ { return execute(); } 52 /** Returns text value. */ 53 QString textValue() const; 54 /** Defines @a strText value. */ 55 void setTextValue(const QString &strText); 54 56 55 57 protected: 56 58 57 /** Handles show @a pEvent. */ 58 virtual void showEvent(QShowEvent *pEvent) /* override */; 59 /** Handles show @a pEvent sent for the first time. */ 60 virtual void polishEvent(QShowEvent *pEvent); 59 /** Handles translation event. */ 60 virtual void retranslateUi() /* override */; 61 62 private slots: 63 64 /** Handles text value change. */ 65 void sltTextChanged(); 61 66 62 67 private: 63 68 64 /** Holds whether the dialog is polished. */65 bool m_fPolished;69 /** Prepared all. */ 70 void prepare(); 66 71 67 /** Holds the separate event-loop instance. 68 * @note This event-loop is only used when the dialog being executed via the execute() 69 * functionality, allowing for the delayed show and advanced modality flag. */ 70 QPointer<QEventLoop> m_pEventLoop; 72 /** Holds whether label text redefined. */ 73 bool m_fDefaultLabelTextRedefined; 74 75 /** Holds the label instance. */ 76 QLabel *m_pLabel; 77 /** Holds the text value editor instance. */ 78 QLineEdit *m_pTextValueEditor; 79 /** Holds the button-box instance. */ 80 QIDialogButtonBox *m_pButtonBox; 71 81 }; 72 82 73 /** Safe pointer to the QI Dialog class. */74 typedef QPointer<QI Dialog> UISafePointerDialog;83 /** Safe pointer to the QIInputDialog class. */ 84 typedef QPointer<QIInputDialog> QISafePointerInputDialog; 75 85 76 #endif /* !___QI Dialog_h___ */86 #endif /* !___QIInputDialog_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.