New bool to use activated signal as toggle of expanded

The launcher applets couldn't be closed with Meta alone and on Wayland
in general by any global shortcut, since we used for that the focusOutEvent
triggered only on X and only on global shortcuts (on default Alt+F1).

This patch introduces the new bool activationTogglesExpanded, which allowes
QML applets to decide if they wish to use the activated signal also to end
their expanded state.

The default value is false, in order to not break any legacy applets.

REVIEW: 129204
BUG: 367685
This commit is contained in:
Roman Gilg 2016-10-19 18:51:15 +02:00
parent 91eb0749ed
commit 65706d3878
4 changed files with 34 additions and 3 deletions

View File

@ -48,7 +48,8 @@ AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickIte
switchWidth(-1), switchWidth(-1),
switchHeight(-1), switchHeight(-1),
applet(a), applet(a),
expanded(false) expanded(false),
activationTogglesExpanded(false)
{ {
} }
@ -727,6 +728,20 @@ void AppletQuickItem::setExpanded(bool expanded)
emit expandedChanged(expanded); emit expandedChanged(expanded);
} }
bool AppletQuickItem::isActivationTogglesExpanded() const
{
return d->activationTogglesExpanded;
}
void AppletQuickItem::setActivationTogglesExpanded(bool activationTogglesExpanded)
{
if (d->activationTogglesExpanded == activationTogglesExpanded) {
return;
}
d->activationTogglesExpanded = activationTogglesExpanded;
emit activationTogglesExpandedChanged(activationTogglesExpanded);
}
////////////Internals ////////////Internals
KDeclarative::QmlObject *AppletQuickItem::qmlObject() KDeclarative::QmlObject *AppletQuickItem::qmlObject()

View File

@ -80,6 +80,12 @@ class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem
*/ */
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
/**
* True when the applet wants the activation signal act in toggle mode, i.e. while being expanded
* the signal shrinks the applet to its not exanded state instead of reexpanding it.
*/
Q_PROPERTY(bool activationTogglesExpanded WRITE setActivationTogglesExpanded READ isActivationTogglesExpanded NOTIFY activationTogglesExpandedChanged)
/** /**
* the applet root QML item: sometimes is the same as fullRepresentationItem * the applet root QML item: sometimes is the same as fullRepresentationItem
* if a fullrepresentation was not declared explicitly * if a fullrepresentation was not declared explicitly
@ -126,6 +132,9 @@ public:
bool isExpanded() const; bool isExpanded() const;
void setExpanded(bool expanded); void setExpanded(bool expanded);
bool isActivationTogglesExpanded() const;
void setActivationTogglesExpanded(bool activationTogglesExpanded);
////NEEDED BY QML TO CREATE ATTACHED PROPERTIES ////NEEDED BY QML TO CREATE ATTACHED PROPERTIES
static AppletQuickItem *qmlAttachedProperties(QObject *object); static AppletQuickItem *qmlAttachedProperties(QObject *object);
@ -135,6 +144,7 @@ Q_SIGNALS:
void switchHeightChanged(int height); void switchHeightChanged(int height);
void expandedChanged(bool expanded); void expandedChanged(bool expanded);
void activationTogglesExpandedChanged(bool activationTogglesExpanded);
void compactRepresentationChanged(QQmlComponent *compactRepresentation); void compactRepresentationChanged(QQmlComponent *compactRepresentation);
void fullRepresentationChanged(QQmlComponent *fullRepresentation); void fullRepresentationChanged(QQmlComponent *fullRepresentation);

View File

@ -104,6 +104,7 @@ public:
Plasma::Package containmentPackage; Plasma::Package containmentPackage;
bool expanded : 1; bool expanded : 1;
bool activationTogglesExpanded : 1;
static QHash<QObject *, AppletQuickItem *> s_rootObjects; static QHash<QObject *, AppletQuickItem *> s_rootObjects;
}; };

View File

@ -142,11 +142,16 @@ void AppletInterface::init()
emit busyChanged(); emit busyChanged();
applet()->updateConstraints(Plasma::Types::UiReadyConstraint); applet()->updateConstraints(Plasma::Types::UiReadyConstraint);
connect(applet(), &Plasma::Applet::activated, connect(applet(), &Plasma::Applet::activated,
[ = ]() { [ = ]() {
setExpanded(true); // in case the applet doesn't want to get shrinked on reactivation,
// we always expand it again (only in order to conform with legacy behaviour)
bool activate = !( isExpanded() && isActivationTogglesExpanded() );
setExpanded(activate);
if (QQuickItem *i = qobject_cast<QQuickItem *>(fullRepresentationItem())) { if (QQuickItem *i = qobject_cast<QQuickItem *>(fullRepresentationItem())) {
i->setFocus(true, Qt::ShortcutFocusReason); i->setFocus(activate, Qt::ShortcutFocusReason);
} }
}); });