Commit c9c0f070 authored by Marco Martin's avatar Marco Martin
Browse files

edit mode action and dbus

Summary:
edit mode menu action
edit mode dbus property for systemsettings
containmentlayoutmanager goes out of edit mode only when the whole
plasma app loses focus, so the panel controlled doesn't make it go out
of it

Test Plan:
iaction shows in context menu, works
property exposed on dbus works

Reviewers: #plasma, #vdg, ngraham, GB_2, davidedmundson

Reviewed By: #plasma, #vdg, ngraham, GB_2, davidedmundson

Subscribers: GB_2, ngraham, davidedmundson, plasma-devel

Tags: #plasma

Maniphest Tasks: T10190, T11094, T10402

Differential Revision: https://phabricator.kde.org/D24264
parent 7673a6a0
......@@ -93,28 +93,6 @@ AppletsLayout::AppletsLayout(QQuickItem *parent)
polish();
}
});
m_window = window();
if (m_window) {
connect(m_window, &QWindow::activeChanged, this, [this]() {
if (!m_window->isActive()) {
setEditMode(false);
}
});
}
connect(this, &QQuickItem::windowChanged, this, [this]() {
if (m_window) {
disconnect(m_window, &QWindow::activeChanged, this, nullptr);
}
m_window = window();
if (m_window) {
connect(m_window, &QWindow::activeChanged, this, [this]() {
if (!m_window->isActive()) {
setEditMode(false);
}
});
}
});
}
AppletsLayout::~AppletsLayout()
......@@ -367,6 +345,23 @@ void AppletsLayout::setPlaceHolder(ItemContainer *placeHolder)
emit placeHolderChanged();
}
QQuickItem *AppletsLayout::eventManagerToFilter() const
{
return m_eventManagerToFilter;
}
void AppletsLayout::setEventManagerToFilter(QQuickItem *item)
{
if (m_eventManagerToFilter == item) {
return;
}
m_eventManagerToFilter = item;
setFiltersChildMouseEvents(m_eventManagerToFilter);
emit eventManagerToFilterChanged();
}
void AppletsLayout::save()
{
m_saveLayoutTimer->start();
......@@ -527,6 +522,39 @@ void AppletsLayout::componentComplete()
}
bool AppletsLayout::childMouseEventFilter(QQuickItem *item, QEvent *event)
{
if (item != m_eventManagerToFilter) {
return QQuickItem::childMouseEventFilter(item, event);
}
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (me->buttons() & Qt::LeftButton) {
mousePressEvent(me);
}
break;
}
case QEvent::MouseMove: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
mouseMoveEvent(me);
break;
}
case QEvent::MouseButtonRelease: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
mouseReleaseEvent(me);
break;
}
case QEvent::UngrabMouse:
mouseUngrabEvent();
break;
default:
break;
}
return QQuickItem::childMouseEventFilter(item, event);
}
void AppletsLayout::mousePressEvent(QMouseEvent *event)
{
......@@ -562,6 +590,12 @@ void AppletsLayout::mouseReleaseEvent(QMouseEvent *event)
{
if (m_editMode
&& m_mouseDownWasEditMode
// By only accepting synthetyzed events, this makes the
// close by tapping in any empty area only work with real
// touch events, as we want a different behavior between desktop
// and tablet mode
&& (event->source() == Qt::MouseEventSynthesizedBySystem
|| event->source() == Qt::MouseEventSynthesizedByQt)
&& QPointF(event->windowPos() - m_mouseDownPosition).manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
setEditMode(false);
}
......@@ -578,6 +612,11 @@ void AppletsLayout::mouseReleaseEvent(QMouseEvent *event)
}
}
void AppletsLayout::mouseUngrabEvent()
{
m_pressAndHoldTimer->stop();
}
void AppletsLayout::appletAdded(QObject *applet, int x, int y)
{
PlasmaQuick::AppletQuickItem *appletItem = qobject_cast<PlasmaQuick::AppletQuickItem *>(applet);
......
......@@ -66,6 +66,13 @@ class AppletsLayout: public QQuickItem
Q_PROPERTY(ItemContainer *placeHolder READ placeHolder WRITE setPlaceHolder NOTIFY placeHolderChanged);
/**
* if the applets layout contains some kind of main MouseArea,
* MouseEventListener or Flickable, we want to filter its events to make the
* long mouse press work
*/
Q_PROPERTY(QQuickItem *eventManagerToFilter READ eventManagerToFilter WRITE setEventManagerToFilter NOTIFY eventManagerToFilterChanged);
Q_PROPERTY(AppletsLayout::EditModeCondition editModeCondition READ editModeCondition WRITE setEditModeCondition NOTIFY editModeConditionChanged)
Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
......@@ -123,6 +130,9 @@ public:
ItemContainer *placeHolder() const;
void setPlaceHolder(ItemContainer *placeHolder);
QQuickItem *eventManagerToFilter() const;
void setEventManagerToFilter(QQuickItem *item);
EditModeCondition editModeCondition() const;
void setEditModeCondition(EditModeCondition condition);
......@@ -158,10 +168,12 @@ Q_SIGNALS:
void acceptsAppletCallbackChanged();
void appletContainerComponentChanged();
void placeHolderChanged();
void eventManagerToFilterChanged();
void editModeConditionChanged();
void editModeChanged();
protected:
bool childMouseEventFilter(QQuickItem *item, QEvent *event) override;
void updatePolish() override;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
......@@ -170,6 +182,7 @@ protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseUngrabEvent() override;
private Q_SLOTS:
void appletAdded(QObject *applet, int x, int y);
......@@ -190,6 +203,7 @@ private:
AbstractLayoutManager *m_layoutManager = nullptr;
QPointer<ItemContainer> m_placeHolder;
QPointer<QQuickItem> m_eventManagerToFilter;
QTimer *m_pressAndHoldTimer;
QTimer *m_sizeSyncTimer;
......@@ -200,7 +214,6 @@ private:
QHash <PlasmaQuick::AppletQuickItem *, AppletContainer*> m_containerForApplet;
QPointer<QQuickWindow> m_window;
QSizeF m_minimumItemSize;
QSizeF m_defaultItemSize;
QSizeF m_savedSize;
......
......@@ -106,8 +106,7 @@ void ItemContainer::setEditMode(bool editMode)
m_editMode = editMode;
// Leave this decision to QML?
if (m_editModeCondition != AfterMouseOver || m_layout->editMode()) {
if (m_editModeCondition != AfterMouseOver || (m_layout && m_layout->editMode())) {
m_contentItem->setEnabled(!editMode);
}
......@@ -153,7 +152,7 @@ void ItemContainer::setEditModeCondition(EditModeCondition condition)
m_editModeCondition = condition;
setAcceptHoverEvents(condition == AfterMouseOver);
setAcceptHoverEvents(condition == AfterMouseOver || (m_layout && m_layout->editMode()));
emit editModeConditionChanged();
}
......@@ -182,6 +181,7 @@ void ItemContainer::setLayout(AppletsLayout *layout)
if (m_layout) {
disconnect(m_layout, &AppletsLayout::editModeConditionChanged, this, nullptr);
disconnect(m_layout, &AppletsLayout::editModeChanged, this, nullptr);
if (m_editMode) {
m_layout->hidePlaceHolder();
......@@ -208,6 +208,9 @@ void ItemContainer::setLayout(AppletsLayout *layout)
emit editModeConditionChanged();
}
});
connect(m_layout, &AppletsLayout::editModeChanged, this, [this]() {
setAcceptHoverEvents(m_editModeCondition == AfterMouseOver || m_layout->editMode());
});
emit layoutChanged();
}
......@@ -625,7 +628,7 @@ void ItemContainer::hoverEnterEvent(QHoverEvent *event)
{
Q_UNUSED(event);
if (m_editModeCondition != AfterMouseOver) {
if (m_editModeCondition != AfterMouseOver && !m_layout->editMode()) {
return;
}
......@@ -633,14 +636,18 @@ void ItemContainer::hoverEnterEvent(QHoverEvent *event)
m_closeEditModeTimer->stop();
}
m_editModeTimer->start(QGuiApplication::styleHints()->mousePressAndHoldInterval());
if (m_layout->editMode()) {
setEditMode(true);
} else {
m_editModeTimer->start(QGuiApplication::styleHints()->mousePressAndHoldInterval());
}
}
void ItemContainer::hoverLeaveEvent(QHoverEvent *event)
{
Q_UNUSED(event);
if (m_editModeCondition != AfterMouseOver) {
if (m_editModeCondition != AfterMouseOver && !m_layout->editMode()) {
return;
}
......
......@@ -71,11 +71,11 @@ void ContextMenu::restore(const KConfigGroup &config)
if (c->containmentType() == Plasma::Types::PanelContainment ||
c->containmentType() == Plasma::Types::CustomPanelContainment) {
m_actionOrder << QStringLiteral("add widgets") << QStringLiteral("_add panel") << QStringLiteral("lock widgets") << QStringLiteral("_context") << QStringLiteral("configure") << QStringLiteral("remove");
m_actionOrder << QStringLiteral("add widgets") << QStringLiteral("_add panel") << QStringLiteral("lock widgets") << QStringLiteral("edit mode") << QStringLiteral("_context") << QStringLiteral("configure") << QStringLiteral("remove");
} else {
actions.insert(QStringLiteral("configure shortcuts"), false);
m_actionOrder << QStringLiteral("_context") << QStringLiteral("_run_command") << QStringLiteral("add widgets") << QStringLiteral("_add panel")
<< QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("_sep1")
<< QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("edit mode") << QStringLiteral("_sep1")
<<QStringLiteral("_lock_screen") << QStringLiteral("_logout") << QStringLiteral("_sep2") << QStringLiteral("run associated application") << QStringLiteral("configure")
<< QStringLiteral("configure shortcuts") << QStringLiteral("_sep3") << QStringLiteral("_wallpaper");
disabled.insert(QStringLiteral("configure shortcuts"));
......@@ -180,6 +180,10 @@ QAction *ContextMenu::action(const QString &name)
if (c->corona()) {
return c->corona()->actions()->action(QStringLiteral("lock widgets"));
}
} else if (name == QLatin1String("edit mode")) {
if (c->corona()) {
return c->corona()->actions()->action(QStringLiteral("edit mode"));
}
} else if (name == QLatin1String("manage activities")) {
if (c->corona()) {
return c->corona()->actions()->action(QStringLiteral("manage activities"));
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.PlasmaShell">
<property name="editMode" type="b" access="readwrite"/>
<method name="toggleDashboard">
</method>
<method name="toggleActivityManager">
......
......@@ -228,6 +228,19 @@ ShellCorona::ShellCorona(QObject *parent)
KDirWatch::self()->addFile(m_configPath);
connect(KDirWatch::self(), &KDirWatch::dirty, this, &ShellCorona::configurationChanged);
connect(KDirWatch::self(), &KDirWatch::created, this, &ShellCorona::configurationChanged);
connect(qApp, &QGuiApplication::focusWindowChanged,
this, [this] (QWindow *focusWindow) {
if (!focusWindow) {
setEditMode(false);
}
}
);
connect(this, &ShellCorona::editModeChanged,
this, [this](bool edit) {
setDashboardShown(edit);
}
);
}
ShellCorona::~ShellCorona()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment