From 7dae5e6f4128c037a9ffa58c3839413b2927746e Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 21 Mar 2018 19:18:39 +0200 Subject: [PATCH] fixes for update Switch and Remove Buttons -- changing name of layouts should have a visual indicator and at the same time the Switch and Remove buttons should update their states properly. A Switch or Remove action shouldnt be allowed after a layout rename until the user has confirmed the new name for the layout. --- app/settingsdialog.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/app/settingsdialog.cpp b/app/settingsdialog.cpp index a674dac3a..b802c1990 100644 --- a/app/settingsdialog.cpp +++ b/app/settingsdialog.cpp @@ -998,7 +998,23 @@ void SettingsDialog::itemChanged(QStandardItem *item) if (item->column() == ACTIVITYCOLUMN) { //! recalculate the available activities recalculateAvailableActivities(); + } else if (item->column() == NAMECOLUMN) { + int currentRow = ui->layoutsView->currentIndex().row(); + + QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString(); + QString name = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString(); + QFont font = qvariant_cast(m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::FontRole)); + + if (m_layouts[id]->name() != name) { + font.setItalic(true); + m_model->setData(m_model->index(currentRow, NAMECOLUMN), font, Qt::FontRole); + } else { + font.setItalic(false); + m_model->setData(m_model->index(currentRow, NAMECOLUMN), font, Qt::FontRole); + } } + + updateApplyButtonsState(); } void SettingsDialog::updateApplyButtonsState() @@ -1056,10 +1072,14 @@ void SettingsDialog::updateApplyButtonsState() void SettingsDialog::updatePerLayoutButtonsState() { - QString id = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), IDCOLUMN), Qt::DisplayRole).toString(); + int currentRow = ui->layoutsView->currentIndex().row(); + + QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString(); + QString nameInModel = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString(); + QString originalName = m_layouts.contains(id) ? m_layouts[id]->name() : ""; //! Switch Button - if (id.startsWith("/tmp/")) { + if (id.startsWith("/tmp/") || originalName != nameInModel) { ui->switchButton->setEnabled(false); } else { ui->switchButton->setEnabled(true); @@ -1071,7 +1091,7 @@ void SettingsDialog::updatePerLayoutButtonsState() } else if (m_corona->layoutManager()->memoryUsage() == Dock::MultipleLayouts) { ui->pauseButton->setVisible(true); - QStringList lActivities = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), ACTIVITYCOLUMN), Qt::UserRole).toStringList(); + QStringList lActivities = m_model->data(m_model->index(currentRow, ACTIVITYCOLUMN), Qt::UserRole).toStringList(); Layout *layout = m_layouts[id]; @@ -1083,9 +1103,9 @@ void SettingsDialog::updatePerLayoutButtonsState() } //! Remove Layout Button - QString name = m_layouts[id]->name(); - - if (name == m_corona->layoutManager()->currentLayoutName() || m_corona->layoutManager()->activeLayout(name)) { + if (originalName != nameInModel + || (originalName == m_corona->layoutManager()->currentLayoutName()) + || (m_corona->layoutManager()->activeLayout(originalName))) { ui->removeButton->setEnabled(false); } else { ui->removeButton->setEnabled(true);