1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

update layouts table to support new approach

This commit is contained in:
Michail Vourlakos 2020-08-27 13:19:47 +03:00
parent 419886b2ea
commit 4d7e1dca83
6 changed files with 85 additions and 78 deletions

View File

@ -31,14 +31,12 @@ LayoutIcon::LayoutIcon()
LayoutIcon::LayoutIcon(LayoutIcon &&o)
: Generic(o),
isFreeActivities(o.isFreeActivities),
isBackgroundFile(o.isBackgroundFile)
{
}
LayoutIcon::LayoutIcon(const LayoutIcon &o)
: Generic(o),
isFreeActivities(o.isFreeActivities),
isBackgroundFile(o.isBackgroundFile)
{
}
@ -46,7 +44,6 @@ LayoutIcon::LayoutIcon(const LayoutIcon &o)
LayoutIcon &LayoutIcon::operator=(LayoutIcon &&rhs)
{
id = rhs.id;
isFreeActivities = rhs.isFreeActivities;
isBackgroundFile = rhs.isBackgroundFile;
name = rhs.name;
@ -56,7 +53,6 @@ LayoutIcon &LayoutIcon::operator=(LayoutIcon &&rhs)
LayoutIcon &LayoutIcon::operator=(const LayoutIcon &rhs)
{
id = rhs.id;
isFreeActivities = rhs.isFreeActivities;
isBackgroundFile = rhs.isBackgroundFile;
name = rhs.name;
@ -67,7 +63,6 @@ bool LayoutIcon::operator==(const LayoutIcon &rhs) const
{
return (id == rhs.id)
&& (name == rhs.name)
&& (isFreeActivities == rhs.isFreeActivities)
&& (isBackgroundFile == rhs.isBackgroundFile);
}

View File

@ -39,7 +39,6 @@ public:
LayoutIcon(const LayoutIcon &o);
//! Layout data
bool isFreeActivities{false};
bool isBackgroundFile{true};
//! Operators

View File

@ -68,7 +68,8 @@ Layouts::Layouts(Settings::Handler::TabLayouts *parent)
loadConfig();
m_proxyModel->setSourceModel(m_model);
connect(m_model, &Model::Layouts::inMultipleModeChanged, this, &Layouts::updateLastColumnWidth);
connect(m_model, &Model::Layouts::inMultipleModeChanged, this, &Layouts::applyColumnWidths);
connect(m_handler->corona()->universalSettings(), &UniversalSettings::canDisableBordersChanged, this, &Layouts::applyColumnWidths);
connect(m_model, &QAbstractItemModel::dataChanged, this, &Layouts::dataChanged);
connect(m_model, &Model::Layouts::rowsInserted, this, &Layouts::dataChanged);
@ -120,7 +121,6 @@ void Layouts::initView()
{
m_view->setModel(m_proxyModel);
m_view->setHorizontalHeader(m_headerView);
m_view->horizontalHeader()->setStretchLastSection(true);
m_view->verticalHeader()->setVisible(false);
m_view->setSortingEnabled(true);
@ -221,12 +221,45 @@ void Layouts::setInMultipleMode(bool inMultiple)
m_model->setInMultipleMode(inMultiple);
}
void Layouts::updateLastColumnWidth()
void Layouts::applyColumnWidths()
{
if (m_model->inMultipleMode()) {
//! column widths
if (m_viewColumnWidths.count()>=5) {
m_view->setColumnWidth(Model::Layouts::ACTIVITYCOLUMN, m_viewColumnWidths[4].toInt());
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::ACTIVITYCOLUMN, QHeaderView::Stretch);
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::NAMECOLUMN, QHeaderView::Interactive);
} else {
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::NAMECOLUMN, QHeaderView::Stretch);
m_view->horizontalHeader()->setSectionResizeMode(Model::Layouts::ACTIVITYCOLUMN, QHeaderView::Interactive);
}
//! this line should be commented for debugging layouts window functionality
m_view->setColumnHidden(Model::Layouts::IDCOLUMN, true);
m_view->setColumnHidden(Model::Layouts::HIDDENTEXTCOLUMN, true);
int maxColumns = Model::Layouts::ACTIVITYCOLUMN - Model::Layouts::BACKGROUNDCOLUMN; //4 - multiple
if (m_handler->corona()->universalSettings()->canDisableBorders()) {
m_view->setColumnHidden(Model::Layouts::BORDERSCOLUMN, false);
} else {
m_view->setColumnHidden(Model::Layouts::BORDERSCOLUMN, true);
}
if (m_model->inMultipleMode()) {
m_view->setColumnHidden(Model::Layouts::ACTIVITYCOLUMN, false);
} else {
m_view->setColumnHidden(Model::Layouts::ACTIVITYCOLUMN, true);
}
if (!m_viewColumnWidths.isEmpty()) {
for (int i=0; i<qMin(m_viewColumnWidths.count(), maxColumns); ++i) {
int currentColumn = Model::Layouts::BACKGROUNDCOLUMN+i;
if ((currentColumn == Model::Layouts::BORDERSCOLUMN && !m_handler->corona()->universalSettings()->canDisableBorders())
|| (currentColumn == Model::Layouts::NAMECOLUMN && !m_model->inMultipleMode())
|| (currentColumn == Model::Layouts::ACTIVITYCOLUMN && !m_model->inMultipleMode())) {
continue;
}
m_view->setColumnWidth(currentColumn, m_viewColumnWidths[i].toInt());
}
}
}
@ -392,28 +425,7 @@ void Layouts::loadLayouts()
m_view->selectRow(rowForName(m_handler->corona()->layoutsManager()->currentLayoutName()));
//! this line should be commented for debugging layouts window functionality
m_view->setColumnHidden(Model::Layouts::IDCOLUMN, true);
m_view->setColumnHidden(Model::Layouts::HIDDENTEXTCOLUMN, true);
if (m_handler->corona()->universalSettings()->canDisableBorders()) {
m_view->setColumnHidden(Model::Layouts::BORDERSCOLUMN, false);
} else {
m_view->setColumnHidden(Model::Layouts::BORDERSCOLUMN, true);
}
m_view->resizeColumnsToContents();
if (!m_viewColumnWidths.isEmpty()) {
int lastColumn = inMultiple ? 5 : 4;
for (int i=0; i<qMin(m_viewColumnWidths.count(),lastColumn); ++i) {
m_view->setColumnWidth(Model::Layouts::BACKGROUNDCOLUMN+i, m_viewColumnWidths[i].toInt());
}
}
updateLastColumnWidth();
applyColumnWidths();
//! there are broken layouts and the user must be informed!
if (brokenLayouts.count() > 0) {
@ -494,7 +506,7 @@ const Latte::Data::Layout Layouts::addLayoutByText(QString rawLayoutText)
/**Window has to be activated explicitely since the window where the drag
* started would otherwise be the active window. By activating the window
the user can immediately change the name by simply typing.*/
the user can immediately change the name by simply typing.*/
m_handler->dialog()->activateWindow();
return newLayout;
@ -662,7 +674,7 @@ void Layouts::save()
//! update only the Central-specific layout parts
CentralLayout *centralActive = isOriginalLayout ? m_handler->corona()->layoutsManager()->synchronizer()->centralLayout(iLayoutOriginalData.name) : nullptr;
CentralLayout *central = centralActive ? centralActive : m_layouts[iLayoutCurrentData.id];
CentralLayout *central = centralActive ? centralActive : m_layouts[iLayoutCurrentData.id];
central->setShowInMenu(iLayoutCurrentData.isShownInMenu);
central->setDisableBordersForMaximizedWindows(iLayoutCurrentData.hasDisabledBorders);
@ -778,21 +790,16 @@ void Layouts::save()
void Layouts::storeColumnWidths()
{
//! save column widths
m_viewColumnWidths.clear();
m_viewColumnWidths[0] = QString::number(m_view->columnWidth(Model::Layouts::BACKGROUNDCOLUMN));
m_viewColumnWidths << QString::number(m_view->columnWidth(Model::Layouts::BACKGROUNDCOLUMN));
m_viewColumnWidths << QString::number(m_view->columnWidth(Model::Layouts::NAMECOLUMN));
m_viewColumnWidths << QString::number(m_view->columnWidth(Model::Layouts::MENUCOLUMN));
m_viewColumnWidths << QString::number(m_view->columnWidth(Model::Layouts::BORDERSCOLUMN));
if (m_model->inMultipleMode()) {
m_viewColumnWidths[1] = QString::number(m_view->columnWidth(Model::Layouts::NAMECOLUMN));
}
if (inMultipleMode()) {
m_viewColumnWidths << QString::number(m_view->columnWidth(Model::Layouts::ACTIVITYCOLUMN));
} else {
//! In Single Mode, keed recorded value for ACTIVITYCOLUMN
if (m_viewColumnWidths.count()>=5) {
m_viewColumnWidths << m_viewColumnWidths[4];
}
m_viewColumnWidths[2] = QString::number(m_view->columnWidth(Model::Layouts::MENUCOLUMN));
if (m_handler->corona()->universalSettings()->canDisableBorders()) {
m_viewColumnWidths[3] = QString::number(m_view->columnWidth(Model::Layouts::BORDERSCOLUMN));
}
}

View File

@ -104,7 +104,7 @@ private slots:
void loadConfig();
void saveConfig();
void storeColumnWidths();
void updateLastColumnWidth();
void applyColumnWidths();
void onNameDuplicatedFrom(const QString &provenId, const QString &trialId);

View File

@ -274,6 +274,12 @@ bool TabLayouts::inDefaultValues() const
void TabLayouts::reset()
{
m_layoutsController->reset();
if (m_layoutsController->inMultipleMode()) {
m_ui->multipleToolBtn->setChecked(true);
} else {
m_ui->singleToolBtn->setChecked(true);
}
}
void TabLayouts::resetDefaults()

View File

@ -344,43 +344,44 @@ QList<Latte::Data::LayoutIcon> Layouts::iconsForCentralLayout(const int &row) co
{
QList<Latte::Data::LayoutIcon> icons;
QStringList activitiesIds = m_layoutsTable[row].activities;
int freeActivitiesPos = -1;
for(int i=0; i<activitiesIds.count(); ++i) {
QString id = activitiesIds[i];
if (m_activitiesMap.contains(id)) {
if (inMultipleMode()) {
if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::ALLACTIVITIESID)) {
Latte::Data::LayoutIcon icon;
icon.name = m_activitiesMap[Latte::Data::Layout::ALLACTIVITIESID].icon;
icon.isBackgroundFile = false;
icons << icon;
} else if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::FREEACTIVITIESID)) {
Latte::Data::LayoutIcon icon;
icon.name = m_activitiesMap[Latte::Data::Layout::FREEACTIVITIESID].icon;
icon.isBackgroundFile = false;
icons << icon;
} else {
QStringList activitiesIds = m_layoutsTable[row].activities;
if (id == Latte::Data::Layout::FREEACTIVITIESID) {
icon.isFreeActivities = true;
freeActivitiesPos = i;
} else {
icon.isFreeActivities = false;
for(int i=0; i<activitiesIds.count(); ++i) {
QString id = activitiesIds[i];
if (m_activitiesMap.contains(id)) {
Latte::Data::LayoutIcon icon;
icon.name = m_activitiesMap[id].icon;
icon.isBackgroundFile = false;
icons << icon;
}
}
icon.name = m_activitiesMap[id].icon;
}
} else {
if (m_layoutsTable[row].isActive) {
Latte::Data::LayoutIcon icon;
icon.name = m_activitiesMap[Latte::Data::Layout::ALLACTIVITIESID].icon;
icon.isBackgroundFile = false;
icons << icon;
}
}
if (freeActivitiesPos >= 0) {
Latte::Data::LayoutIcon freeActsData = icons.takeAt(freeActivitiesPos);
icons.clear();
icons << freeActsData;
return icons;
}
if (!m_layoutsTable[row].icon.isEmpty() && freeActivitiesPos<0) {
//! if there is specific icon set from the user for this layout
//! we draw only that icon
if (!m_layoutsTable[row].icon.isEmpty()) {
//! if there is specific icon set from the user for this layout we draw only that icon
icons.clear();
Latte::Data::LayoutIcon icon;
icon.name = m_layoutsTable[row].icon;
icon.isFreeActivities = false;
icon.isBackgroundFile = false;
icons << icon;
return icons;
@ -399,7 +400,6 @@ QList<Latte::Data::LayoutIcon> Layouts::iconsForCentralLayout(const int &row) co
if (QFileInfo(colorPath).exists()) {
Latte::Data::LayoutIcon icon;
icon.isBackgroundFile = true;
icon.isFreeActivities = false;
icon.name = colorPath;
icons << icon;
}
@ -565,7 +565,7 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::ALLACTIVITIESID)) {
return sortingPriority(HIGHESTPRIORITY, row);
} else if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::FREEACTIVITIESID)) {
return sortingPriority(HIGHPRIORITY, row);
return sortingPriority(HIGHPRIORITY, row);
} else {
return sortingPriority(MEDIUMPRIORITY, row) + m_layoutsTable[row].activities.count();
}