1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

improve button states at Layouts Editor

--dont select active layout in each layoutsChanged
signal
--improve the buttons states at layouts editor based
on what the user can do or not
This commit is contained in:
Michail Vourlakos 2018-03-21 18:41:01 +02:00
parent b8a2a7ff38
commit fecd61ea06
2 changed files with 29 additions and 30 deletions

View File

@ -135,7 +135,10 @@ SettingsDialog::SettingsDialog(QWidget *parent, DockCorona *corona)
//! SIGNALS
connect(m_model, &QStandardItemModel::itemChanged, this, &SettingsDialog::itemChanged);
connect(ui->layoutsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &SettingsDialog::currentRowChanged);
connect(ui->layoutsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [&]() {
updatePerLayoutButtonsState();
updateApplyButtonsState();
});
connect(m_inMemoryButtons, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
[ = ](int id, bool checked) {
@ -636,7 +639,7 @@ void SettingsDialog::apply()
o_settingsLayouts = currentLayoutsSettings();
updateApplyButtonsState();
updatePauseButtonState();
updatePerLayoutButtonsState();
}
void SettingsDialog::restoreDefaults()
@ -784,7 +787,7 @@ void SettingsDialog::loadSettings()
ui->multipleToolBtn->setChecked(true);
}
updatePauseButtonState();
updatePerLayoutButtonsState();
ui->autostartChkBox->setChecked(m_corona->universalSettings()->autostart());
ui->infoWindowChkBox->setChecked(m_corona->universalSettings()->showInfoWindow());
@ -941,7 +944,7 @@ void SettingsDialog::on_switchButton_clicked()
}
}
updatePauseButtonState();
updatePerLayoutButtonsState();
}
void SettingsDialog::on_pauseButton_clicked()
@ -986,7 +989,7 @@ void SettingsDialog::layoutsChanged()
void SettingsDialog::itemChanged(QStandardItem *item)
{
updateApplyButtonsState();
updatePerLayoutButtonsState();
if (item->column() == ACTIVITYCOLUMN) {
//! recalculate the available activities
@ -994,27 +997,6 @@ void SettingsDialog::itemChanged(QStandardItem *item)
}
}
void SettingsDialog::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
QString id = m_model->data(m_model->index(current.row(), IDCOLUMN), Qt::DisplayRole).toString();
QString name = m_layouts[id]->name();
QStringList activities = m_model->data(m_model->index(current.row(), ACTIVITYCOLUMN), Qt::UserRole).toStringList();
if (name == m_corona->layoutManager()->currentLayoutName() || m_corona->layoutManager()->activeLayout(name)) {
ui->removeButton->setEnabled(false);
} else {
ui->removeButton->setEnabled(true);
}
if (id.startsWith("/tmp/")) {
ui->switchButton->setEnabled(false);
} else {
ui->switchButton->setEnabled(true);
}
updatePauseButtonState();
}
void SettingsDialog::updateApplyButtonsState()
{
bool changed{false};
@ -1033,14 +1015,23 @@ void SettingsDialog::updateApplyButtonsState()
}
}
void SettingsDialog::updatePauseButtonState()
void SettingsDialog::updatePerLayoutButtonsState()
{
QString id = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), IDCOLUMN), Qt::DisplayRole).toString();
//! Switch Button
if (id.startsWith("/tmp/")) {
ui->switchButton->setEnabled(false);
} else {
ui->switchButton->setEnabled(true);
}
//! Pause Button
if (m_corona->layoutManager()->memoryUsage() == Dock::SingleLayout) {
ui->pauseButton->setVisible(false);
} else if (m_corona->layoutManager()->memoryUsage() == Dock::MultipleLayouts) {
ui->pauseButton->setVisible(true);
QString id = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), IDCOLUMN), Qt::DisplayRole).toString();
QStringList lActivities = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), ACTIVITYCOLUMN), Qt::UserRole).toStringList();
Layout *layout = m_layouts[id];
@ -1051,6 +1042,15 @@ void SettingsDialog::updatePauseButtonState()
ui->pauseButton->setEnabled(false);
}
}
//! Remove Layout Button
QString name = m_layouts[id]->name();
if (name == m_corona->layoutManager()->currentLayoutName() || m_corona->layoutManager()->activeLayout(name)) {
ui->removeButton->setEnabled(false);
} else {
ui->removeButton->setEnabled(true);
}
}
void SettingsDialog::recalculateAvailableActivities()

View File

@ -75,9 +75,9 @@ private slots:
void reject() override;
void apply();
void restoreDefaults();
void updatePerLayoutButtonsState();
void layoutsChanged();
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void itemChanged(QStandardItem *item);
private:
@ -90,7 +90,6 @@ private:
void recalculateAvailableActivities();
void insertLayoutInfoAtRow(int row, QString path, QString color, QString textColor, QString name, bool menu, QStringList activities);
void updateApplyButtonsState();
void updatePauseButtonState();
bool dataAreAccepted();
bool idExistsInModel(QString id);