1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-13 05:17:48 +03:00

layouts window:store column widths properly

This commit is contained in:
Michail Vourlakos 2021-02-28 14:49:11 +02:00
parent f39e46fd68
commit b49d5eb084
2 changed files with 30 additions and 12 deletions

View File

@ -68,9 +68,6 @@ Layouts::Layouts(Settings::Handler::TabLayouts *parent)
loadConfig(); loadConfig();
m_proxyModel->setSourceModel(m_model); m_proxyModel->setSourceModel(m_model);
connect(m_model, &Model::Layouts::inMultipleModeChanged, this, &Layouts::applyColumnWidths);
connect(m_handler->corona()->universalSettings(), &UniversalSettings::canDisableBordersChanged, this, &Layouts::applyColumnWidths);
connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::newLayoutAdded, this, &Layouts::onLayoutAddedExternally); connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::newLayoutAdded, this, &Layouts::onLayoutAddedExternally);
connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::layoutActivitiesChanged, this, &Layouts::onLayoutActivitiesChangedExternally); connect(m_handler->corona()->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::layoutActivitiesChanged, this, &Layouts::onLayoutActivitiesChangedExternally);
@ -87,6 +84,15 @@ Layouts::Layouts(Settings::Handler::TabLayouts *parent)
initView(); initView();
initLayouts(); initLayouts();
//! connect them after initialization of the view
connect(m_model, &Model::Layouts::inMultipleModeChanged, this, [&]() {
applyColumnWidths(true);
});
connect(m_handler->corona()->universalSettings(), &UniversalSettings::canDisableBordersChanged, this, [&]() {
applyColumnWidths(false);
});
} }
Layouts::~Layouts() Layouts::~Layouts()
@ -151,7 +157,9 @@ void Layouts::initView()
m_view->setItemDelegateForColumn(Model::Layouts::BORDERSCOLUMN, new Settings::Layout::Delegate::CheckBox(this)); m_view->setItemDelegateForColumn(Model::Layouts::BORDERSCOLUMN, new Settings::Layout::Delegate::CheckBox(this));
m_view->setItemDelegateForColumn(Model::Layouts::ACTIVITYCOLUMN, new Settings::Layout::Delegate::Activities(this)); m_view->setItemDelegateForColumn(Model::Layouts::ACTIVITYCOLUMN, new Settings::Layout::Delegate::Activities(this));
connect(m_view, &QObject::destroyed, this, &Controller::Layouts::storeColumnWidths); connect(m_view, &QObject::destroyed, this, [&]() {
storeColumnWidths(m_model->inMultipleMode());
});
} }
bool Layouts::hasChangedData() const bool Layouts::hasChangedData() const
@ -227,8 +235,15 @@ void Layouts::setInMultipleMode(bool inMultiple)
m_model->setInMultipleMode(inMultiple); m_model->setInMultipleMode(inMultiple);
} }
void Layouts::applyColumnWidths() void Layouts::applyColumnWidths(bool storeValues)
{ {
bool isLastModeMultiple = !m_model->inMultipleMode();
//! save previous values
if (storeValues) {
storeColumnWidths(isLastModeMultiple);
}
if (m_model->inMultipleMode()) { if (m_model->inMultipleMode()) {
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::ACTIVITYCOLUMN, QHeaderView::Stretch); m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::ACTIVITYCOLUMN, QHeaderView::Stretch);
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::NAMECOLUMN, QHeaderView::Interactive); m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::NAMECOLUMN, QHeaderView::Interactive);
@ -262,8 +277,9 @@ void Layouts::applyColumnWidths()
int currentColumn = Model::Layouts::BACKGROUNDCOLUMN+i; int currentColumn = Model::Layouts::BACKGROUNDCOLUMN+i;
if ((currentColumn == Model::Layouts::BORDERSCOLUMN && !m_handler->corona()->universalSettings()->canDisableBorders()) if ((currentColumn == Model::Layouts::BORDERSCOLUMN && !m_handler->corona()->universalSettings()->canDisableBorders())
|| (currentColumn == Model::Layouts::NAMECOLUMN && !m_model->inMultipleMode()) || (currentColumn == Model::Layouts::NAMECOLUMN && isLastModeMultiple)
|| (currentColumn == Model::Layouts::ACTIVITYCOLUMN && !m_model->inMultipleMode())) { || (currentColumn == Model::Layouts::MENUCOLUMN && !isLastModeMultiple)
|| (currentColumn == Model::Layouts::ACTIVITYCOLUMN)) {
continue; continue;
} }
@ -789,7 +805,7 @@ void Layouts::save()
emit dataChanged(); emit dataChanged();
} }
void Layouts::storeColumnWidths() void Layouts::storeColumnWidths(bool inMultipleMode)
{ {
if (m_viewColumnWidths.isEmpty()) { if (m_viewColumnWidths.isEmpty()) {
m_viewColumnWidths << "" << "" << "" << ""; m_viewColumnWidths << "" << "" << "" << "";
@ -797,11 +813,13 @@ void Layouts::storeColumnWidths()
m_viewColumnWidths[0] = QString::number(m_view->columnWidth(Model::Layouts::BACKGROUNDCOLUMN)); m_viewColumnWidths[0] = QString::number(m_view->columnWidth(Model::Layouts::BACKGROUNDCOLUMN));
if (m_model->inMultipleMode()) { if (inMultipleMode) {
m_viewColumnWidths[1] = QString::number(m_view->columnWidth(Model::Layouts::NAMECOLUMN)); m_viewColumnWidths[1] = QString::number(m_view->columnWidth(Model::Layouts::NAMECOLUMN));
} }
m_viewColumnWidths[2] = QString::number(m_view->columnWidth(Model::Layouts::MENUCOLUMN)); if (!inMultipleMode) {
m_viewColumnWidths[2] = QString::number(m_view->columnWidth(Model::Layouts::MENUCOLUMN));
}
if (m_handler->corona()->universalSettings()->canDisableBorders()) { if (m_handler->corona()->universalSettings()->canDisableBorders()) {
m_viewColumnWidths[3] = QString::number(m_view->columnWidth(Model::Layouts::BORDERSCOLUMN)); m_viewColumnWidths[3] = QString::number(m_view->columnWidth(Model::Layouts::BORDERSCOLUMN));

View File

@ -108,8 +108,8 @@ private slots:
void initLayouts(); void initLayouts();
void loadConfig(); void loadConfig();
void saveConfig(); void saveConfig();
void storeColumnWidths(); void storeColumnWidths(bool inMultipleMode);
void applyColumnWidths(); void applyColumnWidths(bool storeValues = false);
void onNameDuplicatedFrom(const QString &provenId, const QString &trialId); void onNameDuplicatedFrom(const QString &provenId, const QString &trialId);
void onLayoutAddedExternally(const Data::Layout &layout); void onLayoutAddedExternally(const Data::Layout &layout);