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

contextmenu:expose layouts icon data

This commit is contained in:
Michail Vourlakos 2021-05-15 13:31:56 +03:00
parent cbd8d5d88c
commit 8e9de84e01
7 changed files with 53 additions and 7 deletions

View File

@ -27,6 +27,7 @@
#include "lattedockadaptor.h"
#include "screenpool.h"
#include "data/generictable.h"
#include "data/layouticondata.h"
#include "declarativeimports/interfaces.h"
#include "indicator/factory.h"
#include "layout/abstractlayout.h"
@ -1140,7 +1141,12 @@ QStringList Corona::contextMenuData(const uint &containmentId)
for(const auto &layoutName : m_layoutsManager->synchronizer()->menuLayouts()) {
if (m_layoutsManager->synchronizer()->centralLayout(layoutName)
|| m_layoutsManager->memoryUsage() == Latte::MemoryUsage::SingleLayout) {
layoutsmenu << layoutName;
QStringList layoutdata;
Data::LayoutIcon layouticon = m_layoutsManager->iconForLayout(layoutName);
layoutdata << layoutName;
layoutdata << QString::number(layouticon.isBackgroundFile);
layoutdata << layouticon.name;
layoutsmenu << layoutdata.join("**");
}
}

View File

@ -195,6 +195,12 @@ QStringList Manager::viewTemplateIds() const
return ids;
}
Latte::Data::LayoutIcon Manager::iconForLayout(const QString &storedLayoutName) const
{
Data::Layout l = m_synchronizer->data(storedLayoutName);
return iconForLayout(l);
}
Latte::Data::LayoutIcon Manager::iconForLayout(const Data::Layout &layout) const
{
Latte::Data::LayoutIcon _icon;

View File

@ -89,6 +89,7 @@ public:
QStringList currentLayoutsNames() const;
Latte::Data::LayoutIcon iconForLayout(const QString &storedLayoutName) const;
Latte::Data::LayoutIcon iconForLayout(const Data::Layout &layout) const;
MemoryUsage::LayoutsMemory memoryUsage() const;

View File

@ -248,6 +248,18 @@ void Synchronizer::setIsSingleLayoutInDeprecatedRenaming(const bool &enabled)
m_isSingleLayoutInDeprecatedRenaming = enabled;
}
Data::Layout Synchronizer::data(const QString &storedLayoutName) const
{
Data::Layout l;
if (m_layouts.containsName(storedLayoutName)) {
QString lid = m_layouts.idForName(storedLayoutName);
return m_layouts[lid];
}
return l;
}
Data::LayoutsTable Synchronizer::layoutsTable() const
{
return m_layouts;

View File

@ -119,6 +119,7 @@ public:
KActivities::Controller *activitiesController() const;
Data::Layout data(const QString &storedLayoutName) const;
Data::LayoutsTable layoutsTable() const;
void setLayoutsTable(const Data::LayoutsTable &table);

View File

@ -346,7 +346,21 @@ void Menu::populateLayouts()
LayoutsMemoryUsage memoryUsage = static_cast<LayoutsMemoryUsage>((m_data[MEMORYINDEX]).toInt());
QStringList activeNames = m_data[ACTIVELAYOUTSINDEX].split(";;");
QStringList currentNames = m_data[CURRENTLAYOUTSINDEX].split(";;");
QStringList layoutMenuNames = m_data[LAYOUTMENUINDEX].split(";;");
QList<LayoutInfo> layoutsmenulist;
QStringList layoutsdata = m_data[LAYOUTMENUINDEX].split(";;");
for (int i=0; i<layoutsdata.count(); ++i) {
QStringList cdata = layoutsdata[i].split("**");
LayoutInfo info;
info.layoutName = cdata[0];
info.isBackgroundFileIcon = cdata[1].toInt();
info.iconName = cdata[2];
layoutsmenulist << info;
}
bool hasActiveNoCurrentLayout{false};
@ -359,13 +373,13 @@ void Menu::populateLayouts()
}
}
for (int i = 0; i < layoutMenuNames.count(); ++i) {
bool isActive = activeNames.contains(layoutMenuNames[i]);
for (int i = 0; i < layoutsmenulist.count(); ++i) {
bool isActive = activeNames.contains(layoutsmenulist[i].layoutName);
QString layoutText = layoutMenuNames[i];
QString layoutText = layoutsmenulist[i].layoutName;
bool isCurrent = ((memoryUsage == SingleLayout && isActive)
|| (memoryUsage == MultipleLayouts && currentNames.contains(layoutMenuNames[i])));
|| (memoryUsage == MultipleLayouts && currentNames.contains(layoutsmenulist[i].layoutName)));
if (isCurrent && hasActiveNoCurrentLayout) {
layoutText += QString(" " + i18nc("current layout", "[Current]"));
@ -383,7 +397,7 @@ void Menu::populateLayouts()
}
}
layoutAction->setData(layoutMenuNames[i]);
layoutAction->setData(layoutsmenulist[i].layoutName);
if (isCurrent) {
QFont font = layoutAction->font();

View File

@ -29,6 +29,12 @@
class QAction;
class QMenu;
struct LayoutInfo {
QString layoutName;
bool isBackgroundFileIcon;
QString iconName;
};
class Menu : public Plasma::ContainmentActions
{
Q_OBJECT