Improve the control dialog experience

pull/7/head
reionwong 4 years ago
parent 48fc559e3a
commit 4d889b34ed

@ -31,9 +31,6 @@ import FishUI 1.0 as FishUI
ControlCenterDialog { ControlCenterDialog {
id: control id: control
width: 450
height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 3
property var margin: 4 * Screen.devicePixelRatio property var margin: 4 * Screen.devicePixelRatio
property point position: Qt.point(0, 0) property point position: Qt.point(0, 0)
@ -52,6 +49,11 @@ ControlCenterDialog {
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true LayoutMirroring.childrenInherit: true
onVisibleChanged: {
control.width = 450
control.height = _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 3
}
Appearance { Appearance {
id: appearance id: appearance
} }

@ -272,12 +272,12 @@ Item {
function toggleDialog() { function toggleDialog() {
if (controlCenter.visible) if (controlCenter.visible)
controlCenter.visible = false controlCenter.close()
else { else {
// Alt // Alt
controlCenter.position = Qt.point(0, 0) controlCenter.position = Qt.point(0, 0)
controlCenter.visible = true
controlCenter.position = mapToGlobal(0, 0) controlCenter.position = mapToGlobal(0, 0)
controlCenter.open()
} }
} }
@ -380,8 +380,8 @@ Item {
onActivatedChanged: { onActivatedChanged: {
// TODO // TODO
// if (activated) // if (activated)
// acticity.move() // acticity.move()
} }
onPressed: { onPressed: {

@ -20,24 +20,37 @@
#include "controlcenterdialog.h" #include "controlcenterdialog.h"
#include <KWindowSystem> #include <KWindowSystem>
ControlCenterDialog::ControlCenterDialog(QQuickView *parent) ControlCenterDialog::ControlCenterDialog(QQuickWindow *parent)
: QQuickView(parent) : QQuickWindow(parent)
{ {
setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setFlags(Qt::Popup);
setColor(Qt::transparent);
connect(this, &QQuickView::activeChanged, this, [=] { installEventFilter(this);
if (!isActive())
hide();
});
} }
void ControlCenterDialog::showEvent(QShowEvent *event) void ControlCenterDialog::open()
{ {
KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); setVisible(true);
QQuickView::showEvent(event); setMouseGrabEnabled(true);
setKeyboardGrabEnabled(true);
} }
void ControlCenterDialog::hideEvent(QHideEvent *event) bool ControlCenterDialog::eventFilter(QObject *object, QEvent *event)
{ {
QQuickView::hideEvent(event); if (event->type() == QEvent::MouseButtonPress) {
if (QWindow *w = qobject_cast<QWindow*>(object)) {
if (!w->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos())) {
ControlCenterDialog::setVisible(false);
}
}
} else if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape) {
ControlCenterDialog::setVisible(false);
}
} else if (event->type() == QEvent::Show) {
KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher);
}
return QObject::eventFilter(object, event);
} }

@ -20,19 +20,20 @@
#ifndef CONTROLCENTERDIALOG_H #ifndef CONTROLCENTERDIALOG_H
#define CONTROLCENTERDIALOG_H #define CONTROLCENTERDIALOG_H
#include <QQuickView> #include <QQuickWindow>
#include <QTimer> #include <QTimer>
class ControlCenterDialog : public QQuickView class ControlCenterDialog : public QQuickWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
ControlCenterDialog(QQuickView *view = nullptr); ControlCenterDialog(QQuickWindow *view = nullptr);
Q_INVOKABLE void open();
protected: protected:
void showEvent(QShowEvent *event) override; bool eventFilter(QObject *object, QEvent *event);
void hideEvent(QHideEvent *event) override;
}; };
#endif // CONTROLCENTERDIALOG_H #endif // CONTROLCENTERDIALOG_H

Loading…
Cancel
Save