mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-10 21:18:19 +03:00
improvements for applet isExpanded tracking
This commit is contained in:
parent
8c3ed88a2f
commit
f63a467b1e
@ -1470,71 +1470,61 @@ bool View::appletIsExpandable(const int id)
|
||||
return false;
|
||||
}
|
||||
|
||||
int View::expandedInternalContainment() const
|
||||
bool View::hasExpandedApplet() const
|
||||
{
|
||||
return m_expandedInternalContainemt;
|
||||
return m_expandedAppletIds.count() > 0;
|
||||
}
|
||||
|
||||
void View::on_internalContainmentExpandedChanged()
|
||||
void View::addExpandedApplet(const int &id)
|
||||
{
|
||||
PlasmaQuick::AppletQuickItem *internalContainmentAppletItem = static_cast<PlasmaQuick::AppletQuickItem *>(QObject::sender());
|
||||
if (m_expandedAppletIds.contains(id) && appletIsExpandable(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (internalContainmentAppletItem) {
|
||||
if (internalContainmentAppletItem->isExpanded()) {
|
||||
m_expandedInternalContainemt = internalContainmentAppletItem->applet()->id();
|
||||
emit expandedInternalContainmentChanged();
|
||||
} else if (m_expandedInternalContainemt == (int)internalContainmentAppletItem->applet()->id()){
|
||||
m_expandedInternalContainemt = -1;
|
||||
emit expandedInternalContainmentChanged();
|
||||
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)
|
||||
{
|
||||
if (!containment()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto applet : containment()->applets()) {
|
||||
if (applet->id() == (uint)id) {
|
||||
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_internalContainmentsConnections.contains(contAi)) {
|
||||
//! For some reason internal containments change their expanded state when showing their
|
||||
//! general popup with delay, we make sure to catch that signal correctly
|
||||
m_internalContainmentsConnections[contAi] = connect(contAi, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &View::on_internalContainmentExpandedChanged);
|
||||
|
||||
connect(contAi, &QObject::destroyed, this, [&, contAi](){
|
||||
m_internalContainmentsConnections.remove(contAi);
|
||||
});
|
||||
}
|
||||
|
||||
for (const auto internalApplet : internalC->applets()) {
|
||||
PlasmaQuick::AppletQuickItem *ai = internalApplet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
|
||||
|
||||
if (ai) {
|
||||
if (ai->isExpanded()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
|
||||
|
||||
if (ai) {
|
||||
return (ai->isExpanded());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return m_expandedAppletIds.contains(id);
|
||||
}
|
||||
|
||||
void View::toggleAppletExpanded(const int id)
|
||||
@ -1558,6 +1548,55 @@ void View::toggleAppletExpanded(const int id)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -86,6 +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)
|
||||
@ -99,7 +100,6 @@ class View : public PlasmaQuick::ContainmentView
|
||||
Q_PROPERTY(bool isTouchingTopViewAndIsBusy READ isTouchingTopViewAndIsBusy WRITE setIsTouchingTopViewAndIsBusy NOTIFY isTouchingTopViewAndIsBusyChanged)
|
||||
|
||||
Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(int expandedInternalContainment READ expandedInternalContainment NOTIFY expandedInternalContainmentChanged);
|
||||
Q_PROPERTY(int fontPixelSize READ fontPixelSize WRITE setFontPixelSize NOTIFY fontPixelSizeChanged)
|
||||
Q_PROPERTY(int x READ x NOTIFY xChanged)
|
||||
Q_PROPERTY(int y READ y NOTIFY yChanged)
|
||||
@ -163,6 +163,8 @@ public:
|
||||
bool isPreferredForShortcuts() const;
|
||||
void setIsPreferredForShortcuts(bool preferred);
|
||||
|
||||
bool hasExpandedApplet() const;
|
||||
|
||||
bool latteTasksArePresent() const;
|
||||
void setLatteTasksArePresent(bool present);
|
||||
|
||||
@ -181,8 +183,6 @@ public:
|
||||
int fontPixelSize() const;
|
||||
void setFontPixelSize(int size);
|
||||
|
||||
int expandedInternalContainment() const;
|
||||
|
||||
int editThickness() const;
|
||||
void setEditThickness(int thickness);
|
||||
|
||||
@ -260,6 +260,8 @@ public slots:
|
||||
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();
|
||||
@ -288,9 +290,10 @@ signals:
|
||||
void dockLocationChanged();
|
||||
void editThicknessChanged();
|
||||
void effectsChanged();
|
||||
void expandedInternalContainmentChanged();
|
||||
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();
|
||||
@ -341,7 +344,7 @@ private slots:
|
||||
void addTransientWindow(QWindow *window);
|
||||
void removeTransientWindow(const bool &visible);
|
||||
|
||||
void on_internalContainmentExpandedChanged();
|
||||
void on_appletExpandedChanged();
|
||||
|
||||
void restoreConfig();
|
||||
void saveConfig();
|
||||
@ -351,6 +354,9 @@ private:
|
||||
void setupWaylandIntegration();
|
||||
void updateAppletContainsMethod();
|
||||
|
||||
void addExpandedApplet(const int &id);
|
||||
void removeExpandedApplet(const int &id);
|
||||
|
||||
void setContainsDrag(bool contains);
|
||||
|
||||
private:
|
||||
@ -373,7 +379,6 @@ private:
|
||||
|
||||
int m_fontPixelSize{ -1};
|
||||
int m_editThickness{24};
|
||||
int m_expandedInternalContainemt{-1};
|
||||
int m_maxThickness{24};
|
||||
int m_normalThickness{24};
|
||||
int m_offset{0};
|
||||
@ -416,7 +421,8 @@ private:
|
||||
//! Connections to release and bound for the assigned layout
|
||||
QList<QMetaObject::Connection> connectionsLayout;
|
||||
|
||||
QHash<PlasmaQuick::AppletQuickItem *, QMetaObject::Connection> m_internalContainmentsConnections;
|
||||
QHash<PlasmaQuick::AppletQuickItem *, QMetaObject::Connection> m_appletsExpandedConnections;
|
||||
QList<int> m_expandedAppletIds;
|
||||
|
||||
//! track transientWindows
|
||||
QList<QWindow *> m_transientWindows;
|
||||
|
@ -633,11 +633,6 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: applet
|
||||
onStatusChanged: appletItem.isExpanded = (root.latteView.appletIsExpandable(applet.id) && root.latteView.appletIsExpanded(applet.id));
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: viewSignalsConnector
|
||||
target: root.latteView ? root.latteView : null
|
||||
@ -646,6 +641,15 @@ 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;
|
||||
|
@ -203,12 +203,7 @@ Item {
|
||||
|
||||
property bool plasmaBackgroundForPopups: plasmoid.configuration.plasmaBackgroundForPopups
|
||||
|
||||
readonly property bool hasExpandedApplet: (latteView && latteView.expandedInternalContainment>-1)
|
||||
|| plasmoid.applets.some(function (item) {
|
||||
var isExpanded = latteView.appletIsExpandable(item.id) && latteView.appletIsExpanded(item.id);
|
||||
return (latteView && item.status >= PlasmaCore.Types.UnknownStatus && isExpanded);
|
||||
});
|
||||
|
||||
readonly property bool hasExpandedApplet: latteView && latteView.hasExpandedApplet;
|
||||
readonly property bool hasUserSpecifiedBackground: (latteView && latteView.layout && latteView.layout.background.startsWith("/")) ?
|
||||
true : false
|
||||
|
||||
@ -862,6 +857,7 @@ Item {
|
||||
console.log(applet.pluginName);
|
||||
LayoutManager.save();
|
||||
updateIndexes();
|
||||
latteView.updateAppletIsExpandedTracking();
|
||||
}
|
||||
|
||||
Containment.onAppletRemoved: {
|
||||
@ -1942,6 +1938,8 @@ Item {
|
||||
if (inStartup) {
|
||||
visibilityManager.slotMustBeShown();
|
||||
}
|
||||
|
||||
latteView.updateAppletIsExpandedTracking();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user