1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-27 06:03:51 +03:00

layoutsmanager:take responsibility for layout icons

This commit is contained in:
Michail Vourlakos 2021-05-15 13:06:54 +03:00
parent 517b423bc6
commit cbd8d5d88c
5 changed files with 36 additions and 43 deletions

View File

@ -195,6 +195,37 @@ QStringList Manager::viewTemplateIds() const
return ids; return ids;
} }
Latte::Data::LayoutIcon Manager::iconForLayout(const Data::Layout &layout) const
{
Latte::Data::LayoutIcon _icon;
if (!layout.icon.isEmpty()) {
//! if there is specific icon set from the user for this layout we draw only that icon
_icon.name = layout.icon;
_icon.isBackgroundFile = false;
return _icon;
}
//! fallback icon: background image
if (_icon.isEmpty()) {
QString colorPath = m_corona->kPackage().path() + "../../shells/org.kde.latte.shell/contents/images/canvas/";
if (layout.backgroundStyle == Layout::PatternBackgroundStyle && layout.background.isEmpty()) {
colorPath += "defaultcustomprint.jpg";
} else {
colorPath = layout.background.startsWith("/") ? layout.background : colorPath + layout.color + "print.jpg";
}
if (QFileInfo(colorPath).exists()) {
_icon.isBackgroundFile = true;
_icon.name = colorPath;
return _icon;
}
}
return Latte::Data::LayoutIcon();
}
QList<CentralLayout *> Manager::currentLayouts() const QList<CentralLayout *> Manager::currentLayouts() const
{ {
return m_synchronizer->currentLayouts(); return m_synchronizer->currentLayouts();

View File

@ -25,6 +25,8 @@
#include "syncedlaunchers.h" #include "syncedlaunchers.h"
#include "synchronizer.h" #include "synchronizer.h"
#include "../apptypes.h" #include "../apptypes.h"
#include "../data/layoutdata.h"
#include "../data/layouticondata.h"
#include "../settings/settingsdialog/settingsdialog.h" #include "../settings/settingsdialog/settingsdialog.h"
// Qt // Qt
@ -87,6 +89,8 @@ public:
QStringList currentLayoutsNames() const; QStringList currentLayoutsNames() const;
Latte::Data::LayoutIcon iconForLayout(const Data::Layout &layout) const;
MemoryUsage::LayoutsMemory memoryUsage() const; MemoryUsage::LayoutsMemory memoryUsage() const;
void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage); void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage);

View File

@ -145,7 +145,6 @@ void Layouts::initView()
//!find the available colors //!find the available colors
m_iconsPath = m_handler->corona()->kPackage().path() + "../../shells/org.kde.latte.shell/contents/images/canvas/"; m_iconsPath = m_handler->corona()->kPackage().path() + "../../shells/org.kde.latte.shell/contents/images/canvas/";
m_model->setIconsPath(m_iconsPath);
QDir layoutDir(m_iconsPath); QDir layoutDir(m_iconsPath);
QStringList filter; QStringList filter;

View File

@ -404,45 +404,9 @@ Qt::ItemFlags Layouts::flags(const QModelIndex &index) const
return flags; return flags;
} }
void Layouts::setIconsPath(QString iconsPath)
{
m_iconsPath = iconsPath;
}
Latte::Data::LayoutIcon Layouts::iconForCentralLayout(const int &row) const
{
Latte::Data::LayoutIcon _icon;
if (!m_layoutsTable[row].icon.isEmpty()) {
//! if there is specific icon set from the user for this layout we draw only that icon
_icon.name = m_layoutsTable[row].icon;
_icon.isBackgroundFile = false;
return _icon;
}
//! fallback icon: background image
if (_icon.isEmpty()) {
QString colorPath;
if (m_layoutsTable[row].backgroundStyle == Layout::PatternBackgroundStyle && m_layoutsTable[row].background.isEmpty()) {
colorPath = m_iconsPath + "defaultcustomprint.jpg";
} else {
colorPath = m_layoutsTable[row].background.startsWith("/") ? m_layoutsTable[row].background : m_iconsPath + m_layoutsTable[row].color + "print.jpg";
}
if (QFileInfo(colorPath).exists()) {
_icon.isBackgroundFile = true;
_icon.name = colorPath;
return _icon;
}
}
return Latte::Data::LayoutIcon();
}
Latte::Data::LayoutIcon Layouts::icon(const int &row) const Latte::Data::LayoutIcon Layouts::icon(const int &row) const
{ {
return iconForCentralLayout(row); return m_corona->layoutsManager()->iconForLayout(m_layoutsTable[row]);
} }
const Latte::Data::LayoutIcon Layouts::currentLayoutIcon(const QString &id) const const Latte::Data::LayoutIcon Layouts::currentLayoutIcon(const QString &id) const

View File

@ -137,8 +137,6 @@ public:
void setCurrentLayoutForFreeActivities(const QString &id); void setCurrentLayoutForFreeActivities(const QString &id);
void setOriginalLayoutForFreeActivities(const QString &id); void setOriginalLayoutForFreeActivities(const QString &id);
void setIconsPath(QString iconsPath);
QList<Latte::Data::Layout> alteredLayouts() const; QList<Latte::Data::Layout> alteredLayouts() const;
const Latte::Data::LayoutsTable &currentLayoutsData(); const Latte::Data::LayoutsTable &currentLayoutsData();
@ -180,11 +178,8 @@ private:
QStringList cleanStrings(const QStringList &original, const QStringList &occupied); QStringList cleanStrings(const QStringList &original, const QStringList &occupied);
Latte::Data::LayoutIcon icon(const int &row) const; Latte::Data::LayoutIcon icon(const int &row) const;
Latte::Data::LayoutIcon iconForCentralLayout(const int &row) const;
private: private:
QString m_iconsPath;
Latte::Data::ActivitiesTable m_activitiesTable; Latte::Data::ActivitiesTable m_activitiesTable;
QHash<QString, KActivities::Info *> m_activitiesInfo; QHash<QString, KActivities::Info *> m_activitiesInfo;