diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 0a3287da4..7912333d2 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -21,6 +21,7 @@ #include "layoutscontroller.h" // local +#include "../settingsdialog.h" #include "../universalsettings.h" #include "../delegates/activitiesdelegate.h" #include "../delegates/backgroundcmbdelegate.h" @@ -49,6 +50,7 @@ #include #include #include +#include #include @@ -56,7 +58,7 @@ namespace Latte { namespace Settings { namespace Controller { -Layouts::Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view) +Layouts::Layouts(Latte::SettingsDialog *parent, Latte::Corona *corona, QTableView *view) : QObject(parent), m_parentDialog(parent), m_corona(corona), @@ -847,7 +849,7 @@ void Layouts::saveColumnWidths() void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &trialId) { //! duplicated layout name - auto msg = new QMessageBox(m_parentDialog); + /*auto msg = new QMessageBox(m_parentDialog); msg->setIcon(QMessageBox::Warning); msg->setWindowTitle(i18n("Layout Warning")); msg->setText(i18n("There are layouts with the same name, that is not permitted!!! Please update these names to re-apply the changes...")); @@ -874,7 +876,33 @@ void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &tria }); - msg->open(); + msg->open();*/ + + int pRow = rowForId(provenId); + int tRow = rowForId(trialId); + + if (pRow >= 0) { + QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect; + QItemSelection rowSelection; + + QModelIndex pIndexS = m_proxyModel->index(pRow, Model::Layouts::BACKGROUNDCOLUMN); + QModelIndex pIndexE = m_proxyModel->index(pRow, Model::Layouts::SHAREDCOLUMN); + + rowSelection.select(pIndexS, pIndexE); + + m_view->selectionModel()->select(rowSelection, flags); + } + + m_parentDialog->showInlineMessage(i18n("Layouts with same name are not permitted! Please provide unique names to proceed..."), KMessageWidget::Error, 4000); + + QModelIndex tIndex = m_proxyModel->index(tRow, Model::Layouts::NAMECOLUMN); + + //! avoid losing focuse + QTimer::singleShot(0, [this, tIndex]() { + m_view->edit(tIndex); + }); + + } } diff --git a/app/settings/controllers/layoutscontroller.h b/app/settings/controllers/layoutscontroller.h index be55fd476..b3fb991ea 100644 --- a/app/settings/controllers/layoutscontroller.h +++ b/app/settings/controllers/layoutscontroller.h @@ -38,6 +38,7 @@ namespace Latte { class Corona; class CentralLayout; +class SettingsDialog; } namespace Latte { @@ -49,7 +50,7 @@ class Layouts : public QObject Q_OBJECT public: - explicit Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view); + explicit Layouts(Latte::SettingsDialog *parent, Latte::Corona *corona, QTableView *view); ~Layouts(); QAbstractItemModel *model() const; @@ -100,7 +101,7 @@ private: QString uniqueLayoutName(QString name); private: - QDialog *m_parentDialog{nullptr}; + Latte::SettingsDialog *m_parentDialog{nullptr}; Latte::Corona *m_corona{nullptr}; QTableView *m_view{nullptr}; Settings::Layouts::HeaderView *m_headerView{nullptr}; diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 72d463dc4..cea09b1a9 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -95,6 +95,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona) ui->screenTrackerSpinBox->setValue(m_corona->universalSettings()->screenTrackerInterval()); ui->outlineSpinBox->setValue(m_corona->themeExtended()->outlineWidth()); + ui->messageWidget->setVisible(false); //! About Menu QMenuBar *menuBar = new QMenuBar(this); @@ -216,6 +217,12 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona) m_activitiesTimer.setInterval(750); connect(&m_activitiesTimer, &QTimer::timeout, this, &SettingsDialog::updateWindowActivities); m_activitiesTimer.start(); + + m_hideInlineMessageTimer.setSingleShot(true); + m_hideInlineMessageTimer.setInterval(2000); + connect(&m_hideInlineMessageTimer, &QTimer::timeout, this, [&]() { + ui->messageWidget->animatedHide(); + }); } SettingsDialog::~SettingsDialog() @@ -638,6 +645,13 @@ void SettingsDialog::on_switchButton_clicked() { Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout(); + bool hasChanges = (selectedLayout.nameWasEdited() || m_layoutsController->dataAreChanged()); + + if (hasChanges) { + showInlineMessage(i18n("You need to save your changes before switching to other layout."), KMessageWidget::Warning); + return; + } + if (!m_layoutsController->selectedLayoutIsCurrentActive()) { bool appliedShared = m_layoutsController->inMultipleMode() && selectedLayout.isShared(); bool freeActivitiesLayoutUpdated{false}; @@ -726,9 +740,7 @@ void SettingsDialog::updatePerLayoutButtonsState() Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout(); //! Switch Button - if (selectedLayout.nameWasEdited() - || m_layoutsController->dataAreChanged() - || (m_layoutsController->inMultipleMode() && selectedLayout.isShared()) + if ((m_layoutsController->inMultipleMode() && selectedLayout.isShared()) || m_layoutsController->selectedLayoutIsCurrentActive()) { ui->switchButton->setEnabled(false); } else { @@ -857,5 +869,36 @@ void SettingsDialog::saveAllChanges() m_layoutsController->save(); } +void SettingsDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval) +{ + if (msg.isEmpty()) { + return; + } + + m_hideInlineMessageTimer.stop(); + + if (ui->messageWidget->isVisible()) { + ui->messageWidget->animatedHide(); + } + + ui->messageWidget->setText(msg); + + // TODO: wrap at arbitrary character positions once QLabel can do this + // https://bugreports.qt.io/browse/QTBUG-1276 + ui->messageWidget->setWordWrap(true); + ui->messageWidget->setMessageType(type); + ui->messageWidget->setWordWrap(false); + + const int unwrappedWidth = ui->messageWidget->sizeHint().width(); + ui->messageWidget->setWordWrap(unwrappedWidth > size().width()); + + ui->messageWidget->animatedShow(); + + if (hideInterval > 0) { + m_hideInlineMessageTimer.setInterval(hideInterval); + m_hideInlineMessageTimer.start(); + } +} + }//end of namespace diff --git a/app/settings/settingsdialog.h b/app/settings/settingsdialog.h index 4d35c70ea..2d637954e 100644 --- a/app/settings/settingsdialog.h +++ b/app/settings/settingsdialog.h @@ -36,6 +36,7 @@ // KDE #include +#include namespace Ui { class SettingsDialog; @@ -65,6 +66,8 @@ public: void requestImagesDialog(int row); void requestColorsDialog(int row); + void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0); + private slots: // auto connections void on_newButton_clicked(); @@ -111,6 +114,8 @@ private: //! workaround to assign ALLACTIVITIES during startup QTimer m_activitiesTimer; + //! Timer to hide the inline message widget + QTimer m_hideInlineMessageTimer; //! original data QList o_settingsOriginalData; diff --git a/app/settings/settingsdialog.ui b/app/settings/settingsdialog.ui index 839de717c..b1b854a40 100644 --- a/app/settings/settingsdialog.ui +++ b/app/settings/settingsdialog.ui @@ -1185,6 +1185,9 @@ This tracker is used in order to not lose any screen related update. + + + @@ -1197,6 +1200,13 @@ This tracker is used in order to not lose any screen related update. + + + KMessageWidget + QFrame +
kmessagewidget.h
+
+