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

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

@ -20,24 +20,37 @@
#include "controlcenterdialog.h"
#include <KWindowSystem>
ControlCenterDialog::ControlCenterDialog(QQuickView *parent)
: QQuickView(parent)
ControlCenterDialog::ControlCenterDialog(QQuickWindow *parent)
: QQuickWindow(parent)
{
setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
connect(this, &QQuickView::activeChanged, this, [=] {
if (!isActive())
hide();
});
setFlags(Qt::Popup);
setColor(Qt::transparent);
installEventFilter(this);
}
void ControlCenterDialog::showEvent(QShowEvent *event)
void ControlCenterDialog::open()
{
KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher);
QQuickView::showEvent(event);
setVisible(true);
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
#define CONTROLCENTERDIALOG_H
#include <QQuickView>
#include <QQuickWindow>
#include <QTimer>
class ControlCenterDialog : public QQuickView
class ControlCenterDialog : public QQuickWindow
{
Q_OBJECT
public:
ControlCenterDialog(QQuickView *view = nullptr);
ControlCenterDialog(QQuickWindow *view = nullptr);
Q_INVOKABLE void open();
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
bool eventFilter(QObject *object, QEvent *event);
};
#endif // CONTROLCENTERDIALOG_H

Loading…
Cancel
Save