From fa3a9b75aa3ef288487cd78dd2647212c22ee396 Mon Sep 17 00:00:00 2001 From: samamou Date: Mon, 3 Jun 2024 14:58:07 -0400 Subject: [PATCH 1/4] Change layout from QGridLayout to QHBoxLayout to add QSplitter --- .../Explorer/Widgets/DeviceEditDialog.cpp | 95 +++++++++++-------- 1 file changed, 54 insertions(+), 41 deletions(-) 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..bcf5c83c27 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,76 @@ DeviceEditDialog::DeviceEditDialog( }; setWindowTitle(tr("Add device")); - auto gridLayout = new QGridLayout{}; - setLayout(gridLayout); + auto base_layout = new QVBoxLayout{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); + auto splitter = new QSplitter{this}; + base_layout->addWidget(splitter); + auto column1 = new QWidget; + auto column1_layout = new QVBoxLayout{column1}; + auto protocolsLabel = new QLabel{tr("Protocols"), this}; + setHeaderTextFormat(protocolsLabel); + column1_layout->addWidget(protocolsLabel); + protocolsLabel->setAlignment(Qt::AlignTop); + 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); + splitter->addWidget(column1); + if(m_mode == Mode::Editing) { - m_protocols->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); + column1->setVisible(false); } + // Column 2: Devices + auto column2 = new QWidget; + auto column2_layout = new QVBoxLayout{column2}; + auto devicesLabel = new QLabel{tr("Devices"), this}; + setHeaderTextFormat(devicesLabel); + column2_layout->addWidget(devicesLabel); + devicesLabel->setAlignment(Qt::AlignTop); + 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); - } + qDebug() << "m_devices initialized : " << m_devices; + 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}; + auto settingsLabel = new QLabel{tr("Settings"), this}; + setHeaderTextFormat(settingsLabel); + column3_layout->addWidget(settingsLabel); + settingsLabel->setAlignment(Qt::AlignTop); + settingsLabel->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); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); initAvailableProtocols(); @@ -201,7 +213,6 @@ void DeviceEditDialog::selectedDeviceChanged() { if(!m_devices->isVisible()) return; - if(m_devices->selectedItems().isEmpty()) return; @@ -211,6 +222,7 @@ void DeviceEditDialog::selectedDeviceChanged() auto name = item->text(0); auto data = item->data(0, Qt::UserRole).value(); + if(m_protocolWidget) m_protocolWidget->setSettings(data); @@ -302,6 +314,7 @@ void DeviceEditDialog::selectedProtocolChanged() } else { + qDebug() << "m_devices is not initialized!"; m_devices->setVisible(false); m_devicesLabel->setVisible(false); } From ded0550aa110a1c01adf3085f910417aac8d7ef1 Mon Sep 17 00:00:00 2001 From: samamou Date: Wed, 4 Sep 2024 14:41:10 -0500 Subject: [PATCH 2/4] remove debug statements --- .../Explorer/Explorer/Widgets/DeviceEditDialog.cpp | 2 -- 1 file changed, 2 deletions(-) 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 bcf5c83c27..47ac0d73af 100644 --- a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp +++ b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp @@ -96,7 +96,6 @@ DeviceEditDialog::DeviceEditDialog( m_devices = new QTreeWidget{this}; m_devices->header()->hide(); m_devices->setSelectionMode(QAbstractItemView::SingleSelection); - qDebug() << "m_devices initialized : " << m_devices; column2_layout->addWidget(m_devices); column2->setLayout(column2_layout); splitter->addWidget(column2); @@ -314,7 +313,6 @@ void DeviceEditDialog::selectedProtocolChanged() } else { - qDebug() << "m_devices is not initialized!"; m_devices->setVisible(false); m_devicesLabel->setVisible(false); } From 438e614fde983c99f345a9ac67b8b86f2e217c53 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 9 Sep 2024 17:10:23 -0400 Subject: [PATCH 3/4] use existing QLabel member variables --- .../Explorer/Widgets/DeviceEditDialog.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 47ac0d73af..54b96e5256 100644 --- a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp +++ b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp @@ -68,11 +68,11 @@ DeviceEditDialog::DeviceEditDialog( auto column1 = new QWidget; auto column1_layout = new QVBoxLayout{column1}; - auto protocolsLabel = new QLabel{tr("Protocols"), this}; - setHeaderTextFormat(protocolsLabel); - column1_layout->addWidget(protocolsLabel); - protocolsLabel->setAlignment(Qt::AlignTop); - protocolsLabel->setAlignment(Qt::AlignHCenter); + 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); @@ -88,11 +88,11 @@ DeviceEditDialog::DeviceEditDialog( // Column 2: Devices auto column2 = new QWidget; auto column2_layout = new QVBoxLayout{column2}; - auto devicesLabel = new QLabel{tr("Devices"), this}; - setHeaderTextFormat(devicesLabel); - column2_layout->addWidget(devicesLabel); - devicesLabel->setAlignment(Qt::AlignTop); - devicesLabel->setAlignment(Qt::AlignHCenter); + 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); @@ -103,11 +103,11 @@ DeviceEditDialog::DeviceEditDialog( // Column 3: Settings auto column3 = new QWidget; auto column3_layout = new QVBoxLayout{column3}; - auto settingsLabel = new QLabel{tr("Settings"), this}; - setHeaderTextFormat(settingsLabel); - column3_layout->addWidget(settingsLabel); - settingsLabel->setAlignment(Qt::AlignTop); - settingsLabel->setAlignment(Qt::AlignHCenter); + 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}; m_layout = new QFormLayout; m_layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); From d915b3f516ab88bbdeadcedde8fd7affb8843d75 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 11 Sep 2024 17:13:49 -0400 Subject: [PATCH 4/4] improve splitter logic --- .../Explorer/Widgets/DeviceEditDialog.cpp | 31 +++++++++++++------ .../Explorer/Widgets/DeviceEditDialog.hpp | 2 ++ 2 files changed, 23 insertions(+), 10 deletions(-) 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 54b96e5256..17560623b2 100644 --- a/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp +++ b/src/plugins/score-plugin-deviceexplorer/Explorer/Explorer/Widgets/DeviceEditDialog.cpp @@ -59,11 +59,11 @@ DeviceEditDialog::DeviceEditDialog( }; setWindowTitle(tr("Add device")); - auto base_layout = new QVBoxLayout{this}; + auto base_layout = new QHBoxLayout{this}; setLayout(base_layout); setModal(true); - auto splitter = new QSplitter{this}; + splitter = new QSplitter{this}; base_layout->addWidget(splitter); auto column1 = new QWidget; @@ -78,13 +78,16 @@ DeviceEditDialog::DeviceEditDialog( m_protocols->setSelectionMode(QAbstractItemView::SingleSelection); column1_layout->addWidget(m_protocols); column1->setLayout(column1_layout); - splitter->addWidget(column1); + column1->setFixedWidth(200); + base_layout->addWidget(column1); if(m_mode == Mode::Editing) { column1->setVisible(false); } + base_layout->addWidget(splitter); + // Column 2: Devices auto column2 = new QWidget; auto column2_layout = new QVBoxLayout{column2}; @@ -126,6 +129,16 @@ DeviceEditDialog::DeviceEditDialog( 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); @@ -137,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); } @@ -237,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(); @@ -257,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; @@ -272,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) { @@ -315,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; }; }