- Timestamp:
- Jan 20, 2021 10:17:56 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIToolBox.cpp
r87301 r87318 17 17 18 18 /* Qt includes: */ 19 #include <QCheckBox> 19 20 #include <QLabel> 20 21 #include <QStyle> … … 39 40 }; 40 41 41 /*********************************************************************************************************************************42 * UIToolTitleWidget definition. *43 *********************************************************************************************************************************/44 45 class UIToolBoxTitleWidget : public QWidget46 {47 48 Q_OBJECT;49 50 signals:51 52 void sigShowPageWidget();53 54 public:55 56 UIToolBoxTitleWidget(QWidget *pParent = 0);57 void setText(const QString &strText);58 59 private:60 61 void prepare();62 QHBoxLayout *m_pLayout;63 QLabel *m_pTitleLabel;64 };65 42 66 43 /********************************************************************************************************************************* … … 79 56 public: 80 57 81 UIToolBoxPage( QWidget *pParent = 0);58 UIToolBoxPage(bool fEnableCheckBoxEnabled = false, QWidget *pParent = 0); 82 59 void setTitle(const QString &strTitle); 83 60 /* @p pWidget's ownership is transferred to the page. */ … … 87 64 int index() const; 88 65 void setIndex(int iIndex); 66 int totalHeight() const; 67 int titleHeight() const; 68 int pageWidgetHeight() const; 89 69 90 70 protected: … … 92 72 virtual bool eventFilter(QObject *pWatched, QEvent *pEvent) /* override */; 93 73 74 private slots: 75 76 void sltHandleEnableToggle(int iState); 77 94 78 private: 95 79 96 void prepare(); 80 void prepare(bool fEnableCheckBoxEnabled); 81 97 82 QVBoxLayout *m_pLayout; 98 UIToolBoxTitleWidget *m_pTitleWidget; 83 QWidget *m_pTitleContainerWidget; 84 QLabel *m_pTitleLabel; 85 QCheckBox *m_pEnableCheckBox; 86 99 87 QWidget *m_pWidget; 100 88 int m_iIndex; … … 102 90 103 91 /********************************************************************************************************************************* 104 * UIToolTitleWidget implementation. *105 *********************************************************************************************************************************/106 107 UIToolBoxTitleWidget::UIToolBoxTitleWidget(QWidget *pParent /* = 0 */)108 :QWidget(pParent)109 {110 prepare();111 }112 113 void UIToolBoxTitleWidget::setText(const QString &strText)114 {115 if (m_pTitleLabel)116 m_pTitleLabel->setText(strText);117 }118 119 void UIToolBoxTitleWidget::prepare()120 {121 m_pLayout = new QHBoxLayout(this);122 m_pLayout->setContentsMargins(1.f * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin),123 .4f * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin),124 1.f * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin),125 .4f * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin));126 127 m_pTitleLabel = new QLabel;128 m_pLayout->addWidget(m_pTitleLabel);129 }130 131 /*********************************************************************************************************************************132 92 * UIToolBoxPage implementation. * 133 93 *********************************************************************************************************************************/ 134 94 135 UIToolBoxPage::UIToolBoxPage( QWidget *pParent /* = 0 */)95 UIToolBoxPage::UIToolBoxPage(bool fEnableCheckBoxEnabled /* = false */, QWidget *pParent /* = 0 */) 136 96 :QWidget(pParent) 137 97 , m_pLayout(0) 138 , m_pTitleWidget(0) 98 , m_pTitleContainerWidget(0) 99 , m_pTitleLabel(0) 100 , m_pEnableCheckBox(0) 139 101 , m_pWidget(0) 140 102 , m_iIndex(0) 141 142 { 143 prepare(); 103 { 104 prepare(fEnableCheckBoxEnabled); 144 105 } 145 106 146 107 void UIToolBoxPage::setTitle(const QString &strTitle) 147 108 { 148 if (!m_pTitle Widget)149 return; 150 m_pTitle Widget->setText(strTitle);151 } 152 153 void UIToolBoxPage::prepare( )109 if (!m_pTitleLabel) 110 return; 111 m_pTitleLabel->setText(strTitle); 112 } 113 114 void UIToolBoxPage::prepare(bool fEnableCheckBoxEnabled) 154 115 { 155 116 m_pLayout = new QVBoxLayout(this); 156 117 m_pLayout->setContentsMargins(0, 0, 0, 0); 157 m_pTitleWidget = new UIToolBoxTitleWidget; 158 m_pTitleWidget->installEventFilter(this); 159 m_pLayout->addWidget(m_pTitleWidget); 118 119 m_pTitleContainerWidget = new QWidget; 120 QHBoxLayout *pTitleLayout = new QHBoxLayout(m_pTitleContainerWidget); 121 pTitleLayout->setContentsMargins(qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 122 .4f * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin), 123 qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin), 124 .4f * qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); 125 if (fEnableCheckBoxEnabled) 126 { 127 m_pEnableCheckBox = new QCheckBox; 128 pTitleLayout->addWidget(m_pEnableCheckBox); 129 connect(m_pEnableCheckBox, &QCheckBox::stateChanged, this, &UIToolBoxPage::sltHandleEnableToggle); 130 } 131 132 m_pTitleLabel = new QLabel; 133 m_pTitleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 134 135 m_pTitleLabel->installEventFilter(this); 136 pTitleLayout->addWidget(m_pTitleLabel); 137 m_pTitleContainerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 138 m_pLayout->addWidget(m_pTitleContainerWidget); 160 139 } 161 140 … … 166 145 m_pWidget = pWidget; 167 146 m_pLayout->addWidget(m_pWidget); 147 148 if (m_pEnableCheckBox) 149 m_pWidget->setEnabled(m_pEnableCheckBox->checkState() == Qt::Checked); 150 168 151 m_pWidget->hide(); 169 152 } … … 171 154 void UIToolBoxPage::setTitleBackgroundColor(const QColor &color) 172 155 { 173 if (!m_pTitle Widget)174 return; 175 QPalette palette = m_pTitle Widget->palette();156 if (!m_pTitleLabel) 157 return; 158 QPalette palette = m_pTitleContainerWidget->palette(); 176 159 palette.setColor(QPalette::Window, color); 177 m_pTitle Widget->setPalette(palette);178 m_pTitle Widget->setAutoFillBackground(true);160 m_pTitleContainerWidget->setPalette(palette); 161 m_pTitleContainerWidget->setAutoFillBackground(true); 179 162 } 180 163 … … 195 178 } 196 179 180 int UIToolBoxPage::totalHeight() const 181 { 182 return pageWidgetHeight() + titleHeight(); 183 } 184 185 int UIToolBoxPage::titleHeight() const 186 { 187 if (m_pTitleContainerWidget && m_pTitleContainerWidget->sizeHint().isValid()) 188 return m_pTitleContainerWidget->sizeHint().height(); 189 return 0; 190 } 191 192 int UIToolBoxPage::pageWidgetHeight() const 193 { 194 if (m_pWidget && m_pWidget->isVisible() && m_pWidget->sizeHint().isValid()) 195 return m_pWidget->sizeHint().height(); 196 return 0; 197 } 198 197 199 bool UIToolBoxPage::eventFilter(QObject *pWatched, QEvent *pEvent) 198 200 { 199 if (pWatched == m_pTitle Widget&& pEvent->type() == QEvent::MouseButtonPress)201 if (pWatched == m_pTitleLabel && pEvent->type() == QEvent::MouseButtonPress) 200 202 emit sigShowPageWidget(); 201 203 return QWidget::eventFilter(pWatched, pEvent); 202 204 203 205 } 206 207 void UIToolBoxPage::sltHandleEnableToggle(int iState) 208 { 209 if (m_pWidget) 210 m_pWidget->setEnabled(iState == Qt::Checked); 211 } 212 204 213 205 214 /********************************************************************************************************************************* … … 209 218 UIToolBox::UIToolBox(QWidget *pParent /* = 0 */) 210 219 : QIWithRetranslateUI<QFrame>(pParent) 220 , m_iCurrentPageIndex(-1) 221 , m_iPageCount(0) 211 222 { 212 223 prepare(); 213 } 214 215 bool UIToolBox::insertItem(int iIndex, QWidget *pWidget, const QString &strTitle) 224 //setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 225 } 226 227 bool UIToolBox::insertItem(int iIndex, QWidget *pWidget, const QString &strTitle, bool fAddEnableCheckBox /* = false */) 216 228 { 217 229 if (m_pages.contains(iIndex)) 218 230 return false; 219 UIToolBoxPage *pNewPage = new UIToolBoxPage; 231 ++m_iPageCount; 232 UIToolBoxPage *pNewPage = new UIToolBoxPage(fAddEnableCheckBox, 0);; 220 233 221 234 pNewPage->setWidget(pWidget); … … 233 246 this, &UIToolBox::sltHandleShowPageWidget); 234 247 248 static int iMaxPageHeight = 0; 249 int iTotalTitleHeight = 0; 250 foreach(UIToolBoxPage *pPage, m_pages) 251 { 252 if (pWidget && pWidget->sizeHint().isValid()) 253 iMaxPageHeight = qMax(iMaxPageHeight, pWidget->sizeHint().height()); 254 iTotalTitleHeight += pPage->titleHeight(); 255 } 256 setMinimumHeight(m_iPageCount * (qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) + 257 qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)) + 258 iTotalTitleHeight + 259 iMaxPageHeight); 260 235 261 return iIndex; 236 262 } … … 256 282 } 257 283 258 void UIToolBox::setPageVisible(int iIndex) 259 { 284 void UIToolBox::setCurrentPage(int iIndex) 285 { 286 m_iCurrentPageIndex = iIndex; 260 287 QMap<int, UIToolBoxPage*>::iterator iterator = m_pages.find(iIndex); 261 288 if (iterator == m_pages.end()) … … 274 301 { 275 302 m_pMainLayout = new QVBoxLayout(this); 303 m_pMainLayout->addStretch(); 276 304 //m_pMainLayout->setContentsMargins(0, 0, 0, 0); 277 305 … … 284 312 if (!pPage) 285 313 return; 286 setPageVisible(pPage->index()); 314 setCurrentPage(pPage->index()); 315 update(); 287 316 } 288 317 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIToolBox.h
r87301 r87318 45 45 46 46 UIToolBox(QWidget *pParent = 0); 47 bool insertItem(int iIndex, QWidget *pWidget, const QString &strTitle );47 bool insertItem(int iIndex, QWidget *pWidget, const QString &strTitle, bool fAddEnableCheckBox = false); 48 48 void setItemEnabled(int iIndex, bool fEnabled); 49 49 void setItemText(int iIndex, const QString &strTitle); 50 50 void setItemIcon(int iIndex, const QIcon &icon); 51 void set PageVisible(int iIndex);51 void setCurrentPage(int iIndex); 52 52 53 53 protected: 54 54 55 void retranslateUi(); 55 virtual void retranslateUi() /* override */; 56 //virtual QSize sizeHint() const /* override */; 57 //virtual QSize minimumSizeHint() const /* override */; 56 58 57 59 private slots: … … 65 67 QVBoxLayout *m_pMainLayout; 66 68 QMap<int, UIToolBoxPage*> m_pages; 69 int m_iCurrentPageIndex; 70 int m_iPageCount; 67 71 }; 68 72 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp
r87294 r87318 268 268 bool UIWizardNewVMPage1::checkISOFile() const 269 269 { 270 if ( m_pEnableUnattendedInstallCheckBox && m_pEnableUnattendedInstallCheckBox->isChecked())270 if (isUnattendedEnabled()) 271 271 { 272 272 QString strISOFilePath = m_pISOFilePathSelector ? m_pISOFilePathSelector->path() : QString(); … … 285 285 } 286 286 287 QWidget *UIWizardNewVMPage1::createNameOSTypeWidgets(bool fIncreaseLeftIndent, bool fCreateLabels /* = true */) 287 QWidget *UIWizardNewVMPage1::createNameOSTypeWidgets(bool fIncreaseLeftIndent, 288 bool fCreateUnattendedWidgets, 289 bool fCreateLabels) 288 290 { 289 291 Q_UNUSED(fIncreaseLeftIndent); … … 314 316 } 315 317 316 m_pEnableUnattendedInstallCheckBox = new QCheckBox; 317 pLayout->addWidget(m_pEnableUnattendedInstallCheckBox, iRow++, 0, 1, 1); 318 319 m_pISOSelectorLabel = new QLabel; 320 if (m_pISOSelectorLabel) 321 { 322 m_pISOSelectorLabel->setAlignment(Qt::AlignRight); 323 m_pISOSelectorLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); 324 m_pISOSelectorLabel->setEnabled(false); 325 pLayout->addWidget(m_pISOSelectorLabel, iRow, 1, 1, 1); 326 } 327 m_pISOFilePathSelector = new UIFilePathSelector; 328 if (m_pISOFilePathSelector) 329 { 330 m_pISOFilePathSelector->setResetEnabled(false); 331 m_pISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open); 332 m_pISOFilePathSelector->setFileDialogFilters("*.iso *.ISO"); 333 m_pISOFilePathSelector->setEnabled(false); 334 pLayout->addWidget(m_pISOFilePathSelector, iRow++, 2, 1, 4); 335 } 336 337 m_pStartHeadlessCheckBox = new QCheckBox; 338 if (m_pStartHeadlessCheckBox) 339 { 340 m_pStartHeadlessCheckBox->setEnabled(false); 341 pLayout->addWidget(m_pStartHeadlessCheckBox, iRow++, 1, 1, 5); 342 } 343 344 pLayout->addWidget(horizontalLine(), iRow++, 0, 1, 4); 345 318 if (fCreateUnattendedWidgets) 319 { 320 m_pEnableUnattendedInstallCheckBox = new QCheckBox; 321 pLayout->addWidget(m_pEnableUnattendedInstallCheckBox, iRow++, 0, 1, 1); 322 323 m_pISOSelectorLabel = new QLabel; 324 if (m_pISOSelectorLabel) 325 { 326 m_pISOSelectorLabel->setAlignment(Qt::AlignRight); 327 m_pISOSelectorLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); 328 m_pISOSelectorLabel->setEnabled(false); 329 pLayout->addWidget(m_pISOSelectorLabel, iRow, 1, 1, 1); 330 } 331 m_pISOFilePathSelector = new UIFilePathSelector; 332 if (m_pISOFilePathSelector) 333 { 334 m_pISOFilePathSelector->setResetEnabled(false); 335 m_pISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open); 336 m_pISOFilePathSelector->setFileDialogFilters("*.iso *.ISO"); 337 m_pISOFilePathSelector->setEnabled(false); 338 pLayout->addWidget(m_pISOFilePathSelector, iRow++, 2, 1, 4); 339 } 340 341 m_pStartHeadlessCheckBox = new QCheckBox; 342 if (m_pStartHeadlessCheckBox) 343 { 344 m_pStartHeadlessCheckBox->setEnabled(false); 345 pLayout->addWidget(m_pStartHeadlessCheckBox, iRow++, 1, 1, 5); 346 } 347 348 pLayout->addWidget(horizontalLine(), iRow++, 0, 1, 4); 349 } 346 350 return pContainer; 347 351 } … … 518 522 { 519 523 QVBoxLayout *pPageLayout = new QVBoxLayout(this); 520 pPageLayout->addWidget(createNameOSTypeWidgets(/* fIncreaseLeftIndent */ false, /* fCreateLabels */false)); 524 pPageLayout->addWidget(createNameOSTypeWidgets(/* fIncreaseLeftIndent */ false, 525 /* fCreateUnattendedWidget */ false, 526 /* fCreateLabels */false)); 521 527 pPageLayout->addStretch(); 522 528 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.h
r87294 r87318 78 78 void composeMachineFilePath(); 79 79 80 QWidget *createNameOSTypeWidgets(bool fIncreaseLeftIndent, bool fCreateLabels = true);80 QWidget *createNameOSTypeWidgets(bool fIncreaseLeftIndent, bool fCreateUnattendedWidgets, bool fCreateLabels); 81 81 int createNameOSTypeWidgets(QGridLayout *pLayout, bool fCreateLabels = true); 82 82 void setTypeByISODetectedOSType(const QString &strDetectedOSType); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp
r87301 r87318 51 51 m_pToolBox = new UIToolBox; 52 52 m_pToolBox->insertItem(ExpertToolboxItems_NameAndOSType, createNameOSTypeWidgets(/* fIncreaseLeftIndent */ true, 53 /* fCreateUnattendedWidgets */ false, 53 54 /* fCreateLabels */ false), ""); 55 m_pToolBox->insertItem(ExpertToolboxItems_Unattended, createUnattendedWidgets(), "", false); 54 56 m_pToolBox->insertItem(ExpertToolboxItems_Disk, createDiskWidgets(/* fIncreaseLeftIndent */ true), ""); 55 57 m_pToolBox->insertItem(ExpertToolboxItems_Hardware, createHardwareWidgets(/* fIncreaseLeftIndent */ true), ""); 56 m_pToolBox->insertItem(ExpertToolboxItems_UsernameHostname, createUserNameHostNameWidgets(/* fIncreaseLeftIndent */ true), "");57 m_pToolBox->insertItem(ExpertToolboxItems_GAInstall, createGAInstallWidgets(/* fIncreaseLeftIndent */ true), "");58 m_pToolBox->insertItem(ExpertToolboxItems_ProductKey, createProductKeyWidgets(/* fIncreaseLeftIndent */ true), "");59 60 m_pToolBox->set PageVisible(ExpertToolboxItems_NameAndOSType);58 // m_pToolBox->insertItem(ExpertToolboxItems_UsernameHostname, createUserNameHostNameWidgets(/* fIncreaseLeftIndent */ true), ""); 59 // m_pToolBox->insertItem(ExpertToolboxItems_GAInstall, createGAInstallWidgets(/* fIncreaseLeftIndent */ true), ""); 60 // m_pToolBox->insertItem(ExpertToolboxItems_ProductKey, createProductKeyWidgets(/* fIncreaseLeftIndent */ true), ""); 61 62 m_pToolBox->setCurrentPage(ExpertToolboxItems_NameAndOSType); 61 63 pMainLayout->addWidget(m_pToolBox); 62 64 … … 209 211 m_pToolBox->setItemText(ExpertToolboxItems_NameAndOSType, QString(UIWizardNewVM::tr("Name and operating system"))); 210 212 m_pToolBox->setItemText(ExpertToolboxItems_UsernameHostname, UIWizardNewVM::tr("Username and hostname")); 213 m_pToolBox->setItemText(ExpertToolboxItems_Unattended, UIWizardNewVM::tr("Unattended Install")); 211 214 m_pToolBox->setItemText(ExpertToolboxItems_GAInstall, UIWizardNewVM::tr("Guest additions install")); 212 215 m_pToolBox->setItemText(ExpertToolboxItems_ProductKey, UIWizardNewVM::tr("Product key")); … … 303 306 if (m_pEnableUnattendedInstallCheckBox) 304 307 disableEnableUnattendedRelatedWidgets(m_pEnableUnattendedInstallCheckBox->isChecked()); 305 m_pProductKeyLabel->setEnabled(isProductKeyWidgetEnabled()); 306 m_pProductKeyLineEdit->setEnabled(isProductKeyWidgetEnabled()); 308 if (m_pProductKeyLabel) 309 m_pProductKeyLabel->setEnabled(isProductKeyWidgetEnabled()); 310 if (m_pProductKeyLineEdit) 311 m_pProductKeyLineEdit->setEnabled(isProductKeyWidgetEnabled()); 307 312 } 308 313 … … 320 325 if (m_pGAISOFilePathSelector) 321 326 m_pGAISOFilePathSelector->mark(isUnattendedEnabled() && !checkGAISOFile()); 327 } 328 329 QWidget *UIWizardNewVMPageExpert::createUnattendedWidgets() 330 { 331 QWidget *pContainerWidget = new QWidget; 332 QGridLayout *pLayout = new QGridLayout(pContainerWidget); 333 int iRow = 0; 334 335 m_pISOSelectorLabel = new QLabel; 336 if (m_pISOSelectorLabel) 337 { 338 m_pISOSelectorLabel->setAlignment(Qt::AlignRight); 339 m_pISOSelectorLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); 340 pLayout->addWidget(m_pISOSelectorLabel, iRow, 0, 1, 1); 341 } 342 343 m_pISOFilePathSelector = new UIFilePathSelector; 344 if (m_pISOFilePathSelector) 345 { 346 m_pISOFilePathSelector->setResetEnabled(false); 347 m_pISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open); 348 m_pISOFilePathSelector->setFileDialogFilters("*.iso *.ISO"); 349 pLayout->addWidget(m_pISOFilePathSelector, iRow++, 1, 1, 4); 350 } 351 352 m_pStartHeadlessCheckBox = new QCheckBox; 353 if (m_pStartHeadlessCheckBox) 354 pLayout->addWidget(m_pStartHeadlessCheckBox, iRow++, 0, 1, 5); 355 356 pLayout->addWidget(createUserNameHostNameWidgets(/* fIncreaseLeftIndent */ false), iRow, 0, 4, 5); 357 iRow += 4; 358 pLayout->addWidget(createGAInstallWidgets(/* fIncreaseLeftIndent */ false), iRow, 0, 2, 5); 359 iRow += 2; 360 pLayout->addWidget(createProductKeyWidgets(/* fIncreaseLeftIndent */ false), iRow, 0, 1, 5); 361 362 363 return pContainerWidget; 322 364 } 323 365 … … 333 375 m_pToolBox->setItemIcon(ExpertToolboxItems_ProductKey, QIcon()); 334 376 335 336 377 if (!UIWizardPage::isComplete()) 337 378 { -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.h
r87301 r87318 86 86 87 87 private: 88 88 89 enum ExpertToolboxItems 89 90 { 90 91 ExpertToolboxItems_NameAndOSType, 92 ExpertToolboxItems_Unattended, 91 93 ExpertToolboxItems_Disk, 92 94 ExpertToolboxItems_Hardware, … … 110 112 void disableEnableUnattendedRelatedWidgets(bool fEnabled); 111 113 void markWidgets() const; 114 QWidget *createUnattendedWidgets(); 115 112 116 113 117 UIToolBox *m_pToolBox;
Note:
See TracChangeset
for help on using the changeset viewer.