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

View:Move expanded applets code to View::Interface

This commit is contained in:
Michail Vourlakos 2020-04-08 15:22:38 +03:00
parent fa65462dea
commit 0046c904d1
8 changed files with 220 additions and 200 deletions

View File

@ -260,11 +260,11 @@ void GlobalShortcuts::activateLauncherMenu()
//! delay the execution in order to show first the view
QTimer::singleShot(APPLETEXECUTIONDELAY, [this, highestPriorityView]() {
highestPriorityView->toggleAppletExpanded(highestPriorityView->extendedInterface()->applicationLauncherId());
highestPriorityView->extendedInterface()->toggleAppletExpanded(highestPriorityView->extendedInterface()->applicationLauncherId());
highestPriorityView->visibility()->removeBlockHidingEvent(SHORTCUTBLOCKHIDINGTYPE);
});
} else {
highestPriorityView->toggleAppletExpanded(highestPriorityView->extendedInterface()->applicationLauncherId());
highestPriorityView->extendedInterface()->toggleAppletExpanded(highestPriorityView->extendedInterface()->applicationLauncherId());
}
}
}
@ -300,7 +300,7 @@ bool GlobalShortcuts::activateLatteEntry(Latte::View *view, int index, Qt::Key m
bool newInstance{!activation};
int appletId = view->extendedInterface()->appletIdForIndex(index);
bool hasPopUp {(appletId>-1 && view->appletIsExpandable(appletId))};
bool hasPopUp {(appletId>-1 && view->extendedInterface()->appletIsExpandable(appletId))};
if (view->visibility()->isHidden() && hasPopUp) {
//! delay the execution in order to show first the view

View File

@ -22,6 +22,7 @@
// local
#include "view.h"
#include "../lattecorona.h"
#include "../layout/genericlayout.h"
#include "../settings/universalsettings.h"
// Qt
@ -44,6 +45,20 @@ ContainmentInterface::ContainmentInterface(Latte::View *parent)
m_view(parent)
{
m_corona = qobject_cast<Latte::Corona *>(m_view->corona());
m_appletsExpandedConnectionsTimer.setInterval(2000);
m_appletsExpandedConnectionsTimer.setSingleShot(true);
connect(&m_appletsExpandedConnectionsTimer, &QTimer::timeout, this, &ContainmentInterface::updateAppletIsExpandedTracking);
connect(m_view, &View::containmentChanged
, this, [&]() {
if (m_view->containment()) {
connect(m_view->containment(), &Plasma::Containment::appletAdded, this, &ContainmentInterface::updateAppletIsExpandedTracking);
m_appletsExpandedConnectionsTimer.start();
}
});
}
ContainmentInterface::~ContainmentInterface()
@ -385,5 +400,157 @@ void ContainmentInterface::deactivateApplets()
}
}
bool ContainmentInterface::appletIsExpandable(const int id)
{
if (!m_view->containment()) {
return false;
}
for (const auto applet : m_view->containment()->applets()) {
if (applet->id() == (uint)id) {
if (m_view->layout() && m_view->layout()->isInternalContainment(applet)) {
return true;
}
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai) {
return (ai->fullRepresentation() != nullptr
&& ai->preferredRepresentation() != ai->fullRepresentation());
}
}
}
return false;
}
bool ContainmentInterface::hasExpandedApplet() const
{
return m_expandedAppletIds.count() > 0;
}
void ContainmentInterface::addExpandedApplet(const int &id)
{
if (m_expandedAppletIds.contains(id) && appletIsExpandable(id)) {
return;
}
bool isExpanded = hasExpandedApplet();
m_expandedAppletIds << id;
if (isExpanded != hasExpandedApplet()) {
emit hasExpandedAppletChanged();
}
emit expandedAppletStateChanged();
}
void ContainmentInterface::removeExpandedApplet(const int &id)
{
if (!m_expandedAppletIds.contains(id)) {
return;
}
bool isExpanded = hasExpandedApplet();
m_expandedAppletIds.removeAll(id);
if (isExpanded != hasExpandedApplet()) {
emit hasExpandedAppletChanged();
}
emit expandedAppletStateChanged();
}
void ContainmentInterface::on_appletExpandedChanged()
{
PlasmaQuick::AppletQuickItem *appletItem = static_cast<PlasmaQuick::AppletQuickItem *>(QObject::sender());
if (appletItem) {
if (appletItem->isExpanded()) {
addExpandedApplet(appletItem->applet()->id());
} else {
removeExpandedApplet(appletItem->applet()->id());
}
}
}
bool ContainmentInterface::appletIsExpanded(const int id)
{
return m_expandedAppletIds.contains(id);
}
void ContainmentInterface::toggleAppletExpanded(const int id)
{
if (!m_view->containment()) {
return;
}
for (const auto applet : m_view->containment()->applets()) {
if (applet->id() == (uint)id) {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai) {
if (!ai->isActivationTogglesExpanded()) {
ai->setActivationTogglesExpanded(true);
}
emit applet->activated();
}
}
}
}
void ContainmentInterface::updateAppletIsExpandedTracking()
{
if (!m_view->containment()) {
return;
}
for (const auto applet : m_view->containment()->applets()) {
if (m_view->layout() && m_view->layout()->isInternalContainment(applet)) {
//! internal containment case
Plasma::Containment *internalC = m_view->layout()->internalContainmentOf(applet);
PlasmaQuick::AppletQuickItem *contAi = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (contAi && !m_appletsExpandedConnections.contains(contAi)) {
m_appletsExpandedConnections[contAi] = connect(contAi, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(contAi, &QObject::destroyed, this, [&, contAi](){
m_appletsExpandedConnections.remove(contAi);
removeExpandedApplet(contAi->applet()->id());
});
}
for (const auto internalApplet : internalC->applets()) {
PlasmaQuick::AppletQuickItem *ai = internalApplet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai && !m_appletsExpandedConnections.contains(ai) ){
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
} else {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai && !m_appletsExpandedConnections.contains(ai)) {
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
}
}
}
}

View File

@ -25,6 +25,7 @@
#include <QObject>
#include <QPointer>
#include <QQuickItem>
#include <QTimer>
namespace PlasmaQuick {
class AppletQuickItem;
@ -42,11 +43,14 @@ namespace ViewPart {
class ContainmentInterface: public QObject
{
Q_OBJECT
Q_PROPERTY(bool hasExpandedApplet READ hasExpandedApplet NOTIFY hasExpandedAppletChanged)
public:
ContainmentInterface(Latte::View *parent);
virtual ~ContainmentInterface();
bool hasExpandedApplet() const;
bool applicationLauncherInPopup() const;
bool applicationLauncherHasGlobalShortcut() const;
bool containsApplicationLauncher() const;
@ -70,11 +74,26 @@ public:
public slots:
Q_INVOKABLE void deactivateApplets();
Q_INVOKABLE void toggleAppletExpanded(const int id);
Q_INVOKABLE void updateAppletIsExpandedTracking();
Q_INVOKABLE bool appletIsExpandable(const int id);
Q_INVOKABLE bool appletIsExpanded(const int id);
signals:
void hasExpandedAppletChanged();
void expandedAppletStateChanged();
private slots:
void identifyMainItem();
void identifyMethods();
void on_appletExpandedChanged();
private:
void addExpandedApplet(const int &id);
void removeExpandedApplet(const int &id);
private:
QMetaMethod m_activateEntryMethod;
QMetaMethod m_appletIdForIndexMethod;
@ -84,6 +103,13 @@ private:
QPointer<Latte::Corona> m_corona;
QPointer<Latte::View> m_view;
QPointer<QQuickItem> m_mainItem;
//! startup timer to initialize
//! applets expanded tracking
QTimer m_appletsExpandedConnectionsTimer;
QHash<PlasmaQuick::AppletQuickItem *, QMetaObject::Connection> m_appletsExpandedConnections;
QList<int> m_expandedAppletIds;
};
}

View File

@ -104,10 +104,6 @@ View::View(Plasma::Corona *corona, QScreen *targetScreen, bool byPassWM)
m_releaseGrabTimer.setSingleShot(true);
connect(&m_releaseGrabTimer, &QTimer::timeout, this, &View::releaseGrab);
m_appletsExpandedConnectionsTimer.setInterval(2000);
m_appletsExpandedConnectionsTimer.setSingleShot(true);
connect(&m_appletsExpandedConnectionsTimer, &QTimer::timeout, this, &View::updateAppletIsExpandedTracking);
connect(m_contextMenu, &ViewPart::ContextMenu::menuChanged, this, &View::updateTransientWindowsTracking);
connect(this, &View::containmentChanged
@ -156,8 +152,6 @@ View::View(Plasma::Corona *corona, QScreen *targetScreen, bool byPassWM)
emit indicatorChanged();
}
m_appletsExpandedConnectionsTimer.start();
connect(this->containment(), SIGNAL(statusChanged(Plasma::Types::ItemStatus)), SLOT(statusChanged(Plasma::Types::ItemStatus)));
}, Qt::DirectConnection);
@ -1437,157 +1431,6 @@ void View::releaseGrab()
QCoreApplication::instance()->sendEvent(this, &e);
}
bool View::appletIsExpandable(const int id)
{
if (!containment()) {
return false;
}
for (const auto applet : containment()->applets()) {
if (applet->id() == (uint)id) {
if (layout() && layout()->isInternalContainment(applet)) {
return true;
}
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai) {
return (ai->fullRepresentation() != nullptr
&& ai->preferredRepresentation() != ai->fullRepresentation());
}
}
}
return false;
}
bool View::hasExpandedApplet() const
{
return m_expandedAppletIds.count() > 0;
}
void View::addExpandedApplet(const int &id)
{
if (m_expandedAppletIds.contains(id) && appletIsExpandable(id)) {
return;
}
bool isExpanded = hasExpandedApplet();
m_expandedAppletIds << id;
if (isExpanded != hasExpandedApplet()) {
emit hasExpandedAppletChanged();
}
emit expandedAppletStateChanged();
}
void View::removeExpandedApplet(const int &id)
{
if (!m_expandedAppletIds.contains(id)) {
return;
}
bool isExpanded = hasExpandedApplet();
m_expandedAppletIds.removeAll(id);
if (isExpanded != hasExpandedApplet()) {
emit hasExpandedAppletChanged();
}
emit expandedAppletStateChanged();
}
void View::on_appletExpandedChanged()
{
PlasmaQuick::AppletQuickItem *appletItem = static_cast<PlasmaQuick::AppletQuickItem *>(QObject::sender());
if (appletItem) {
if (appletItem->isExpanded()) {
addExpandedApplet(appletItem->applet()->id());
} else {
removeExpandedApplet(appletItem->applet()->id());
}
}
}
bool View::appletIsExpanded(const int id)
{
return m_expandedAppletIds.contains(id);
}
void View::toggleAppletExpanded(const int id)
{
if (!containment()) {
return;
}
for (const auto applet : containment()->applets()) {
if (applet->id() == (uint)id) {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai) {
if (!ai->isActivationTogglesExpanded()) {
ai->setActivationTogglesExpanded(true);
}
emit applet->activated();
}
}
}
}
void View::updateAppletIsExpandedTracking()
{
if (!containment()) {
return;
}
for (const auto applet : containment()->applets()) {
if (m_layout && m_layout->isInternalContainment(applet)) {
//! internal containment case
Plasma::Containment *internalC = layout()->internalContainmentOf(applet);
PlasmaQuick::AppletQuickItem *contAi = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (contAi && !m_appletsExpandedConnections.contains(contAi)) {
m_appletsExpandedConnections[contAi] = connect(contAi, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &View::on_appletExpandedChanged);
connect(contAi, &QObject::destroyed, this, [&, contAi](){
m_appletsExpandedConnections.remove(contAi);
removeExpandedApplet(contAi->applet()->id());
});
}
for (const auto internalApplet : internalC->applets()) {
PlasmaQuick::AppletQuickItem *ai = internalApplet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai && !m_appletsExpandedConnections.contains(ai) ){
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &View::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
} else {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai && !m_appletsExpandedConnections.contains(ai)) {
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &View::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
}
}
QVariantList View::containmentActions()
{
QVariantList actions;

View File

@ -86,7 +86,7 @@ class View : public PlasmaQuick::ContainmentView
Q_PROPERTY(bool byPassWM READ byPassWM WRITE setByPassWM NOTIFY byPassWMChanged)
Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged)
Q_PROPERTY(bool contextMenuIsShown READ contextMenuIsShown NOTIFY contextMenuIsShownChanged)
Q_PROPERTY(bool hasExpandedApplet READ hasExpandedApplet NOTIFY hasExpandedAppletChanged)
//! Because Latte uses animations, changing to edit mode it may be different than
//! when the isUserConfiguring changes value
Q_PROPERTY(bool inEditMode READ inEditMode WRITE setInEditMode NOTIFY inEditModeChanged)
@ -164,8 +164,6 @@ public:
bool isPreferredForShortcuts() const;
void setIsPreferredForShortcuts(bool preferred);
bool hasExpandedApplet() const;
bool latteTasksArePresent() const;
void setLatteTasksArePresent(bool present);
@ -253,15 +251,10 @@ public slots:
Q_INVOKABLE void moveToLayout(QString layoutName);
Q_INVOKABLE void removeTasksPlasmoid();
Q_INVOKABLE void toggleAppletExpanded(const int id);
Q_INVOKABLE bool appletIsExpandable(const int id);
Q_INVOKABLE bool appletIsExpanded(const int id);
Q_INVOKABLE bool mimeContainsPlasmoid(QMimeData *mimeData, QString name);
Q_INVOKABLE bool tasksPresent();
Q_INVOKABLE void updateAppletIsExpandedTracking();
void updateAbsoluteGeometry(bool bypassChecks = false);
Q_INVOKABLE bool isHighestPriorityView();
@ -293,8 +286,6 @@ signals:
void extendedInterfaceChanged();
void fontPixelSizeChanged();
void forcedShown(); //[workaround] forced shown to avoid a KWin issue that hides windows when closing activities
void hasExpandedAppletChanged();
void expandedAppletStateChanged();
void widthChanged();
void heightChanged();
void inEditModeChanged();
@ -345,8 +336,6 @@ private slots:
void addTransientWindow(QWindow *window);
void removeTransientWindow(const bool &visible);
void on_appletExpandedChanged();
void restoreConfig();
void saveConfig();
@ -355,9 +344,6 @@ private:
void setupWaylandIntegration();
void updateAppletContainsMethod();
void addExpandedApplet(const int &id);
void removeExpandedApplet(const int &id);
void setContainsDrag(bool contains);
private:
@ -408,10 +394,6 @@ private:
int m_releaseGrab_x;
int m_releaseGrab_y;
//! startup timer to initialize
//! applets expanded tracking
QTimer m_appletsExpandedConnectionsTimer;
Layout::GenericLayout *m_layout{nullptr};
QPointer<PlasmaQuick::ConfigView> m_configView;
@ -426,9 +408,6 @@ private:
//! Connections to release and bound for the assigned layout
QList<QMetaObject::Connection> connectionsLayout;
QHash<PlasmaQuick::AppletQuickItem *, QMetaObject::Connection> m_appletsExpandedConnections;
QList<int> m_expandedAppletIds;
//! track transientWindows
QList<QWindow *> m_transientWindows;

View File

@ -326,7 +326,7 @@ Item {
if (appletItemContainsMouse && !wrapperContainsMouse && appletNeutralAreaEnabled) {
//console.log("PASSED");
latteView.toggleAppletExpanded(applet.id);
latteView.extendedInterface.toggleAppletExpanded(applet.id);
} else {
//console.log("REJECTED");
}
@ -596,7 +596,7 @@ Item {
if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && appletItem.isLattePlasmoid) {
latteApplet.activateTaskAtIndex(entryIndex - latteApplet.tasksBaseIndex);
} else if (root.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) {
latteView.toggleAppletExpanded(applet.id);
latteView.extendedInterface.toggleAppletExpanded(applet.id);
}
}
@ -604,7 +604,7 @@ Item {
if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && appletItem.isLattePlasmoid) {
latteApplet.newInstanceForTaskAtIndex(entryIndex - latteApplet.tasksBaseIndex);
} else if (root.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) {
latteView.toggleAppletExpanded(applet.id);
latteView.extendedInterface.toggleAppletExpanded(applet.id);
}
}
}
@ -641,15 +641,6 @@ Item {
property bool pressed: false
property bool blockWheel: false
onExpandedAppletStateChanged: {
if (latteView.hasExpandedApplet && appletItem.applet) {
appletItem.isExpanded = appletItem.isExpanded = latteView.appletIsExpandable(appletItem.applet.id)
&& latteView.appletIsExpanded(appletItem.applet.id);
} else {
appletItem.isExpanded = false;
}
}
onMousePressed: {
if (appletItem.containsPos(pos)) {
viewSignalsConnector.pressed = true;
@ -680,17 +671,32 @@ Item {
blockWheel = true;
scrollDelayer.start();
if (appletItem.containsPos(pos) /*&& root.latteView.appletIsExpandable(applet.id)*/) {
if (appletItem.containsPos(pos) /*&& root.latteView.extendedInterface.appletIsExpandable(applet.id)*/) {
var angle = angleDelta.y / 8;
var expanded = root.latteView.appletIsExpanded(applet.id);
var expanded = root.latteView.extendedInterface.appletIsExpanded(applet.id);
if ((angle > 12 && !expanded) /*positive direction*/
|| (angle < -12 && expanded) /*negative direction*/) {
latteView.toggleAppletExpanded(applet.id);
latteView.extendedInterface.toggleAppletExpanded(applet.id);
}
}
}
}
Connections {
target: root.latteView ? root.latteView.extendedInterface : null
enabled: !appletItem.isLattePlasmoid && !appletItem.isSeparator && !appletItem.isSpacer && !appletItem.isHidden
onExpandedAppletStateChanged: {
if (latteView.extendedInterface.hasExpandedApplet && appletItem.applet) {
appletItem.isExpanded = latteView.extendedInterface.appletIsExpandable(appletItem.applet.id)
&& latteView.extendedInterface.appletIsExpanded(appletItem.applet.id);
} else {
appletItem.isExpanded = false;
}
}
}
///END connections
//! It is used for any communication needed with the underlying applet

View File

@ -477,7 +477,7 @@ Item{
&& !appletItem.acceptMouseEvents
sourceComponent: MouseArea{
onClicked: latteView.toggleAppletExpanded(applet.id);
onClicked: latteView.extendedInterface.toggleAppletExpanded(applet.id);
}
}

View File

@ -203,7 +203,7 @@ Item {
property bool plasmaBackgroundForPopups: plasmoid.configuration.plasmaBackgroundForPopups
readonly property bool hasExpandedApplet: latteView && latteView.hasExpandedApplet;
readonly property bool hasExpandedApplet: latteView && latteView.extendedInterface.hasExpandedApplet;
readonly property bool hasUserSpecifiedBackground: (latteView && latteView.layout && latteView.layout.background.startsWith("/")) ?
true : false
@ -857,7 +857,6 @@ Item {
console.log(applet.pluginName);
LayoutManager.save();
updateIndexes();
latteView.updateAppletIsExpandedTracking();
}
Containment.onAppletRemoved: {