From 05fe25412127a54ede8e1ffb7ad2e57bc72a767a Mon Sep 17 00:00:00 2001 From: cutefishd Date: Thu, 25 Mar 2021 00:14:48 +0800 Subject: [PATCH] Support right position display --- qml/DockItem.qml | 34 ++++++++++++++++++++++++---------- qml/main.qml | 5 ++--- src/docksettings.h | 3 ++- src/mainwindow.cpp | 8 +++++++- src/xwindowinterface.cpp | 7 +++++++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/qml/DockItem.qml b/qml/DockItem.qml index 30790b7..19ffe6b 100644 --- a/qml/DockItem.qml +++ b/qml/DockItem.qml @@ -8,8 +8,11 @@ Item { id: control property bool isLeft: Settings.direction === DockSettings.Left + property bool isRight: Settings.direction === DockSettings.Right + property bool isBottom: Settings.direction === DockSettings.Bottom - property var iconSize: (isLeft ? control.height : control.width) * iconSizeRatio + property var iconSize: root.isHorizontal ? control.height * iconSizeRatio + : control.width * iconSizeRatio property bool draggable: false property int dragItemIndex @@ -121,6 +124,9 @@ Item { if (Settings.direction === DockSettings.Left) popupTips.position = Qt.point(root.width + Meui.Units.largeSpacing, control.mapToGlobal(0, 0).y + (control.height / 2 - popupTips.height / 2)) + else if (Settings.direction === DockSettings.Right) + popupTips.position = Qt.point(control.mapToGlobal(0, 0).x - popupTips.width - Meui.Units.smallSpacing / 2, + control.mapToGlobal(0, 0).y + (control.height / 2 - popupTips.height / 2)) else popupTips.position = Qt.point(control.mapToGlobal(0, 0).x + (control.width / 2 - popupTips.width / 2), control.mapToGlobal(0, 0).y - popupTips.height - Meui.Units.smallSpacing / 2) @@ -134,13 +140,25 @@ Item { Rectangle { id: activeLine - width: isLeft ? parent.width * 0.06 : (isActive ? parent.height * 0.4 : parent.height * 0.06) - height: isLeft ? (isActive ? parent.height * 0.4 : parent.height * 0.06) : parent.height * 0.06 + width: !isBottom ? parent.width * 0.06 : (isActive ? parent.height * 0.4 : parent.height * 0.06) + height: !isBottom ? (isActive ? parent.height * 0.4 : parent.height * 0.06) : parent.height * 0.06 color: Meui.Theme.textColor - radius: isLeft ? width / 2 : height / 2 + radius: !isBottom ? width / 2 : height / 2 visible: enableActivateDot && !dragStarted opacity: isActive ? 1 : 0.6 + property var leftX: 3 + property var leftY: (parent.height - height) / 2 + + property var bottomX: (parent.width - width) / 2 + property var bottomY: icon.y + icon.height + activeLine.height / 2 - 2 + + property var rightX: icon.x + icon.width + activeLine.width / 2 - 2 + property var rightY: (parent.height - height) / 2 + + x: isLeft ? leftX : isBottom ? bottomX : rightX + y: isLeft ? leftY : isBottom ? bottomY : rightY + Behavior on opacity { NumberAnimation { duration: 125 @@ -150,20 +168,16 @@ Item { Behavior on width { NumberAnimation { - duration: !isLeft ? 125 : 0 + duration: isBottom ? 125 : 0 easing.type: Easing.InOutCubic } } Behavior on height { NumberAnimation { - duration: isLeft ? 125 : 0 + duration: !isBottom ? 125 : 0 easing.type: Easing.InOutCubic } } - - x: isLeft ? 3 : (parent.width - width) / 2 - y: isLeft ? (parent.height - height) / 2 : icon.y + icon.height + activeLine.height / 2 - 2 - // 1 is the window border } } diff --git a/qml/main.qml b/qml/main.qml index af6e5e4..de96b28 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -11,9 +11,8 @@ Item { visible: true property color borderColor: Meui.Theme.darkMode ? Qt.rgba(255, 255, 255, 0.1) : Qt.rgba(0, 0, 0, 0.05) - property real windowRadius: Settings.roundedWindowEnabled ? (Settings.direction === DockSettings.Left) ? root.width * 0.25 : root.height * 0.25 - : 0 - property bool isHorizontal: Settings.direction !== DockSettings.Left + property bool isHorizontal: Settings.direction === DockSettings.Bottom + property real windowRadius: isHorizontal ? root.height * 0.25 : root.width * 0.25 DropArea { anchors.fill: parent diff --git a/src/docksettings.h b/src/docksettings.h index 3ac2729..64cb327 100644 --- a/src/docksettings.h +++ b/src/docksettings.h @@ -35,7 +35,8 @@ class DockSettings : public QObject public: enum Direction { Left = 0, - Bottom + Bottom, + Right }; Q_ENUMS(Direction) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 781d99b..48d6fc1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -103,7 +103,6 @@ QRect MainWindow::windowRect() const case DockSettings::Left: newSize = QSize(iconSize, length); position.setX(screenGeometry.x() + DockSettings::self()->edgeMargins() / 2); - // Handle the top statusbar. position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2); break; @@ -112,6 +111,11 @@ QRect MainWindow::windowRect() const position.setX(screenGeometry.x() + (screenGeometry.width() - newSize.width()) / 2); position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height() - DockSettings::self()->edgeMargins() / 2); break; + case DockSettings::Right: + newSize = QSize(iconSize, length); + position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width() - DockSettings::self()->edgeMargins() / 2); + position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2); + break; default: break; } @@ -133,6 +137,8 @@ void MainWindow::initSlideWindow() if (m_settings->direction() == DockSettings::Left) location = KWindowEffects::LeftEdge; + else if (m_settings->direction() == DockSettings::Right) + location = KWindowEffects::RightEdge; else if (m_settings->direction() == DockSettings::Bottom) location = KWindowEffects::BottomEdge; diff --git a/src/xwindowinterface.cpp b/src/xwindowinterface.cpp index 8093e43..d494e8e 100644 --- a/src/xwindowinterface.cpp +++ b/src/xwindowinterface.cpp @@ -167,6 +167,13 @@ void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction dire strut.bottom_end = rect.x() + rect.width(); break; } + case DockSettings::Right: { + const int rightOffset = {wholeScreen.right() - currentScreen.right()}; + strut.right_width = rect.width() + rightOffset + DockSettings::self()->edgeMargins(); + strut.right_start = rect.y(); + strut.right_end = rect.y() + rect.height() - 1; + break; + } default: break; }