diff --git a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp index 95d98371c9..17560623b2 100644 --- a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp +++ b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp @@ -48,6 +48,7 @@ DeviceEditDialog::DeviceEditDialog( , m_protocolWidget{nullptr} , m_index{-1} { + const auto& skin = score::Skin::instance(); const QColor textHeaderColor = QColor("#D5D5D5"); auto setHeaderTextFormat = [&](QLabel* label) { @@ -58,65 +59,88 @@ DeviceEditDialog::DeviceEditDialog( }; setWindowTitle(tr("Add device")); - auto gridLayout = new QGridLayout{}; - setLayout(gridLayout); + auto base_layout = new QHBoxLayout{this}; + setLayout(base_layout); setModal(true); - m_invalidLabel = new QLabel{ - tr("Cannot add device.\n Try changing the name to make it unique, \nor " - "check that the ports aren't already used")}; - m_invalidLabel->setAlignment(Qt::AlignRight); - m_invalidLabel->setTextFormat(Qt::PlainText); - m_buttonBox = new QDialogButtonBox(Qt::Horizontal, this); - m_okButton = m_buttonBox->addButton(tr("Add"), QDialogButtonBox::AcceptRole); - m_buttonBox->addButton(QDialogButtonBox::Cancel); - - connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + splitter = new QSplitter{this}; + base_layout->addWidget(splitter); + auto column1 = new QWidget; + auto column1_layout = new QVBoxLayout{column1}; + m_protocolsLabel = new QLabel{tr("Protocols"), this}; + setHeaderTextFormat(m_protocolsLabel); + column1_layout->addWidget(m_protocolsLabel); + m_protocolsLabel->setAlignment(Qt::AlignTop); + m_protocolsLabel->setAlignment(Qt::AlignHCenter); m_protocols = new QTreeWidget{this}; m_protocols->header()->hide(); m_protocols->setSelectionMode(QAbstractItemView::SingleSelection); + column1_layout->addWidget(m_protocols); + column1->setLayout(column1_layout); + column1->setFixedWidth(200); + base_layout->addWidget(column1); + if(m_mode == Mode::Editing) { - m_protocols->setVisible(false); + column1->setVisible(false); } - else - { - m_protocols->setFixedWidth(150); - { - m_protocolsLabel = new QLabel{tr("Protocols"), this}; - setHeaderTextFormat(m_protocolsLabel); - gridLayout->addWidget(m_protocolsLabel, 0, 0, Qt::AlignHCenter); - } - gridLayout->addWidget(m_protocols, 1, 0); - } + base_layout->addWidget(splitter); + // Column 2: Devices + auto column2 = new QWidget; + auto column2_layout = new QVBoxLayout{column2}; + m_devicesLabel = new QLabel{tr("Devices"), this}; + setHeaderTextFormat(m_devicesLabel); + column2_layout->addWidget(m_devicesLabel); + m_devicesLabel->setAlignment(Qt::AlignTop); + m_devicesLabel->setAlignment(Qt::AlignHCenter); m_devices = new QTreeWidget{this}; m_devices->header()->hide(); m_devices->setSelectionMode(QAbstractItemView::SingleSelection); - // m_devices->setFixedWidth(140); - gridLayout->addWidget(m_devices, 1, 1); - { - m_devicesLabel = new QLabel{tr("Devices"), this}; - setHeaderTextFormat(m_devicesLabel); - gridLayout->addWidget(m_devicesLabel, 0, 1, Qt::AlignHCenter); - } - - { - m_protocolNameLabel = new QLabel{tr("Settings"), this}; - setHeaderTextFormat(m_protocolNameLabel); - gridLayout->addWidget( - m_protocolNameLabel, 0, 2, -1, -1, Qt::AlignLeft | Qt::AlignTop); - } + column2_layout->addWidget(m_devices); + column2->setLayout(column2_layout); + splitter->addWidget(column2); + + // Column 3: Settings + auto column3 = new QWidget; + auto column3_layout = new QVBoxLayout{column3}; + m_protocolNameLabel = new QLabel{tr("Settings"), this}; + setHeaderTextFormat(m_protocolNameLabel); + column3_layout->addWidget(m_protocolNameLabel); + m_protocolNameLabel->setAlignment(Qt::AlignTop); + m_protocolNameLabel->setAlignment(Qt::AlignHCenter); m_main = new QWidget{this}; - gridLayout->addWidget(m_main, 1, 2, -1, -1); m_layout = new QFormLayout; m_layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); m_main->setLayout(m_layout); + column3_layout->addWidget(m_main); + m_invalidLabel = new QLabel{ + tr("Cannot add device.\n Try changing the name to make it unique, \nor " + "check that the ports aren't already used")}; + m_invalidLabel->setAlignment(Qt::AlignRight); + m_invalidLabel->setTextFormat(Qt::PlainText); + m_buttonBox = new QDialogButtonBox(Qt::Horizontal, this); + m_okButton = m_buttonBox->addButton(tr("Add"), QDialogButtonBox::AcceptRole); + m_buttonBox->addButton(QDialogButtonBox::Cancel); m_layout->addRow(m_invalidLabel); m_layout->addRow(m_buttonBox); + column3->setLayout(column3_layout); + splitter->addWidget(column3); + + m_devices->setMinimumWidth(40); + m_main->setMinimumWidth(100); + + splitter->setCollapsible(0, false); + splitter->setCollapsible(1, false); + + splitter->setStretchFactor(0, 1); + splitter->setStretchFactor(1, 2); + + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); initAvailableProtocols(); @@ -126,13 +150,11 @@ DeviceEditDialog::DeviceEditDialog( if(m_protocols->topLevelItemCount() > 0) { - // m_protocols->setCurrentItem(); - // m_index = m_protocols->currentRow(); selectedProtocolChanged(); } - setMinimumWidth(700); - setMinimumHeight(400); + setMinimumWidth(850); + setMinimumHeight(550); setAcceptEnabled(false); } @@ -201,7 +223,6 @@ void DeviceEditDialog::selectedDeviceChanged() { if(!m_devices->isVisible()) return; - if(m_devices->selectedItems().isEmpty()) return; @@ -211,6 +232,7 @@ void DeviceEditDialog::selectedDeviceChanged() auto name = item->text(0); auto data = item->data(0, Qt::UserRole).value(); + if(m_protocolWidget) m_protocolWidget->setSettings(data); @@ -226,8 +248,6 @@ void DeviceEditDialog::selectedProtocolChanged() // Recreate if(m_protocols->selectedItems().isEmpty()) { - //m_devices->setVisible(false); - //m_devicesLabel->setVisible(false); return; } auto selected_item = m_protocols->selectedItems().first(); @@ -246,7 +266,6 @@ void DeviceEditDialog::selectedProtocolChanged() if(m_protocolWidget) { SCORE_ASSERT(m_index < m_previousSettings.count()); - m_previousSettings[m_index] = m_protocolWidget->getSettings(); delete m_protocolWidget; m_protocolWidget = nullptr; @@ -261,6 +280,8 @@ void DeviceEditDialog::selectedProtocolChanged() m_devicesLabel->setVisible(true); m_devices->setRootIsDecorated(false); m_devices->setExpandsOnDoubleClick(false); + splitter->widget(0)->show(); + splitter->widget(0)->setMinimumWidth(200); for(auto& [name, e] : m_enumerators) { @@ -304,6 +325,7 @@ void DeviceEditDialog::selectedProtocolChanged() { m_devices->setVisible(false); m_devicesLabel->setVisible(false); + splitter->widget(0)->hide(); } m_protocolNameLabel->setText(tr("Settings (%1)").arg(protocol->prettyName())); m_protocolWidget = protocol->makeSettingsWidget(); diff --git a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.hpp b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.hpp index 0cda5fc959..d4a108e102 100644 --- a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.hpp +++ b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.hpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -82,5 +83,6 @@ class SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceEditDialog final : public QDialog QString m_originalName{}; int m_index{}; + QSplitter* splitter; }; }