From 47b5c6eeb46fd288fa695b766179e5cebd82f13d Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 20 Nov 2015 14:49:37 +0100 Subject: [PATCH] Use ReplaceWidget in ChoicePage. --- src/modules/partition/gui/ChoicePage.cpp | 129 +++++++++++++++-------- src/modules/partition/gui/ChoicePage.h | 5 +- 2 files changed, 91 insertions(+), 43 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 4aaf23e14..a253f60d8 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -25,6 +25,7 @@ #include "core/PartitionModel.h" #include "core/OsproberEntry.h" +#include "ReplaceWidget.h" #include "PrettyRadioButton.h" #include "ExpandableRadioButton.h" #include "PartitionPreview.h" @@ -213,7 +214,8 @@ ChoicePage::setupChoices() iconSize ) ); grp->addButton( m_eraseButton->buttonWidget() ); - m_replaceButton = new PrettyRadioButton; + m_replaceButton = createReplaceButton(); + m_replaceButton->setIconSize( iconSize ); m_replaceButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionReplaceOs, CalamaresUtils::Original, @@ -307,6 +309,55 @@ ChoicePage::setupChoices() } +QComboBox* +ChoicePage::createBootloaderComboBox( ExpandableRadioButton* parentButton ) +{ + QComboBox* bcb = new QComboBox; + bcb->setModel( m_core->bootLoaderModel() ); + + // When the chosen bootloader device changes, we update the choice in the PCM + connect( bcb, static_cast< void (QComboBox::*)(int) >( &QComboBox::currentIndexChanged ), + [=]( int newIndex ) + { + QVariant var = bcb->itemData( newIndex, BootLoaderModel::BootLoaderPathRole ); + if ( !var.isValid() ) + return; + m_core->setBootLoaderInstallPath( var.toString() ); + } ); + + // If the user picks a new device, we update the bootloader choice to that + // same device automatically. + auto updateBootloaderDevice = [bcb]( Device* currd ) + { + if ( !currd ) + return; + QString devPath = currd->deviceNode(); + for ( int i = 0; i < bcb->count(); ++i ) + { + QVariant var = bcb->itemData( i , BootLoaderModel::BootLoaderPathRole ); + if ( !var.isValid() ) + continue; + if ( var.toString() == devPath ) + { + bcb->setCurrentIndex( i ); + return; + } + } + }; + connect( this, &ChoicePage::deviceChosen, + this, updateBootloaderDevice ); + connect( parentButton, &ExpandableRadioButton::expanded, + this, [=]( bool expanded ) + { + if ( expanded ) + updateBootloaderDevice( selectedDevice() ); + }, Qt::QueuedConnection ); + // ^ Must be Queued so it's sure to run when the widget is already visible. + + return bcb; +} + + ExpandableRadioButton* ChoicePage::createEraseButton() { @@ -321,57 +372,51 @@ ChoicePage::createEraseButton() QLabel* eraseBootloaderLabel = new QLabel( eraseWidget ); eraseLayout->addWidget( eraseBootloaderLabel ); eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); - QComboBox* eraseBootloaderCombo = new QComboBox; + + QComboBox* eraseBootloaderCombo = createBootloaderComboBox( eraseButton ); eraseLayout->addWidget( eraseBootloaderCombo ); eraseBootloaderLabel->setBuddy( eraseBootloaderCombo ); - eraseBootloaderCombo->setModel( m_core->bootLoaderModel() ); eraseLayout->addStretch(); - // When the chosen bootloader device changes, we update the choice in the PCM - connect( eraseBootloaderCombo, static_cast< void (QComboBox::*)(int) >( &QComboBox::currentIndexChanged ), - [=]( int newIndex ) - { - QVariant var = eraseBootloaderCombo->itemData( newIndex, BootLoaderModel::BootLoaderPathRole ); - if ( !var.isValid() ) - return; - m_core->setBootLoaderInstallPath( var.toString() ); - } ); - - // If the user picks a new device, we update the bootloader choice to that - // same device automatically. - auto updateBootloaderDevice = [eraseBootloaderCombo]( Device* currd ) - { - if ( !currd ) - return; - QString devPath = currd->deviceNode(); - for ( int i = 0; i < eraseBootloaderCombo->count(); ++i ) - { - QVariant var = eraseBootloaderCombo->itemData( i , BootLoaderModel::BootLoaderPathRole ); - if ( !var.isValid() ) - continue; - if ( var.toString() == devPath ) - { - eraseBootloaderCombo->setCurrentIndex( i ); - return; - } - } - }; - connect( this, &ChoicePage::deviceChosen, - this, updateBootloaderDevice ); - connect( eraseButton, &ExpandableRadioButton::expanded, - this, [=]( bool expanded ) - { - if ( expanded ) - updateBootloaderDevice( selectedDevice() ); - }, Qt::QueuedConnection ); - // ^ Must be Queued so it's sure to run when the widget is already visible. - eraseButton->setExpandableWidget( eraseWidget ); } return eraseButton; } +ExpandableRadioButton* +ChoicePage::createReplaceButton() +{ + ExpandableRadioButton* replaceButton = new ExpandableRadioButton; + QWidget* replaceContainer = new QWidget; + QVBoxLayout* mainReplaceLayout = new QVBoxLayout; + replaceContainer->setLayout( mainReplaceLayout ); + CalamaresUtils::unmarginLayout( mainReplaceLayout ); + ReplaceWidget* replaceWidget = new ReplaceWidget( m_core, drivesCombo ); + mainReplaceLayout->addWidget( replaceWidget ); + + if ( !m_isEfi ) + { + QHBoxLayout* bootloaderLayout = new QHBoxLayout; + bootloaderLayout->setContentsMargins( 0, 0, 0, 0 ); + QLabel* eraseBootloaderLabel = new QLabel( replaceButton ); + bootloaderLayout->addWidget( eraseBootloaderLabel ); + eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); + + QComboBox* eraseBootloaderCombo = createBootloaderComboBox( replaceButton ); + bootloaderLayout->addWidget( eraseBootloaderCombo ); + eraseBootloaderLabel->setBuddy( eraseBootloaderCombo ); + bootloaderLayout->addStretch(); + + mainReplaceLayout->addLayout( bootloaderLayout ); + } + + replaceButton->setExpandableWidget( replaceContainer ); + + return replaceButton; +} + + /** * @brief ChoicePage::selectedDevice queries the device picker (which may be a combo or * a list view) to get a pointer to the currently selected Device. diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 512f86201..8c98ed5e6 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -28,6 +28,7 @@ #include class QBoxLayout; +class QComboBox; class QLabel; class QListView; @@ -69,7 +70,9 @@ private: bool compact(); void setNextEnabled( bool enabled ); void setupChoices(); + QComboBox* createBootloaderComboBox( ExpandableRadioButton* parentButton ); ExpandableRadioButton* createEraseButton(); + ExpandableRadioButton* createReplaceButton(); Device* selectedDevice(); void applyDeviceChoice(); void updateDeviceStatePreview( Device* currentDevice ); @@ -91,7 +94,7 @@ private: PrettyRadioButton* m_alongsideButton; ExpandableRadioButton* m_eraseButton; - PrettyRadioButton* m_replaceButton; + ExpandableRadioButton* m_replaceButton; PrettyRadioButton* m_somethingElseButton; int m_lastSelectedDeviceIndex;