Support setting to enable rounded corners

This commit is contained in:
cutefishd 2021-03-21 23:07:03 +08:00
parent 11e247d075
commit 3d53224ebb
8 changed files with 72 additions and 40 deletions

View file

@ -11,8 +11,8 @@ StandardItem {
Layout.preferredWidth: isHorizontal ? controlLayout.implicitWidth + root.largeSpacing * 2 : mainLayout.width * 0.7 Layout.preferredWidth: isHorizontal ? controlLayout.implicitWidth + root.largeSpacing * 2 : mainLayout.width * 0.7
Layout.preferredHeight: isHorizontal ? mainLayout.height * 0.7 : controlLayout.implicitHeight + root.largeSpacing * 2 Layout.preferredHeight: isHorizontal ? mainLayout.height * 0.7 : controlLayout.implicitHeight + root.largeSpacing * 2
Layout.rightMargin: isHorizontal ? root.windowRadius / 2 : 0 Layout.rightMargin: isHorizontal ? root.windowRadius ? root.windowRadius / 2 : root.largeSpacing : 0
Layout.bottomMargin: isHorizontal ? 0 : root.windowRadius / 2 Layout.bottomMargin: isHorizontal ? 0 : root.windowRadius ? root.windowRadius / 2 : root.largeSpacing
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
onClicked: { onClicked: {

View file

@ -12,7 +12,8 @@ Item {
visible: true visible: true
property color borderColor: Meui.Theme.darkMode ? Qt.rgba(255, 255, 255, 0.1) : Qt.rgba(0, 0, 0, 0.05) property color borderColor: Meui.Theme.darkMode ? Qt.rgba(255, 255, 255, 0.1) : Qt.rgba(0, 0, 0, 0.05)
property real windowRadius: (Settings.direction === DockSettings.Left) ? root.width * 0.25 : root.height * 0.25 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.Left
property var appViewLength: isHorizontal ? appItemView.width : appItemView.height property var appViewLength: isHorizontal ? appItemView.width : appItemView.height
property var appViewHeight: isHorizontal ? appItemView.height : appItemView.width property var appViewHeight: isHorizontal ? appItemView.height : appItemView.width
@ -91,6 +92,7 @@ Item {
anchors.fill: parent anchors.fill: parent
color: "transparent" color: "transparent"
radius: windowRadius radius: windowRadius
visible: windowRadius
border.width: 1 border.width: 1
border.color: Qt.rgba(0, 0, 0, 0.5) border.color: Qt.rgba(0, 0, 0, 0.5)
antialiasing: true antialiasing: true
@ -101,6 +103,7 @@ Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: 1 anchors.margins: 1
radius: windowRadius - 1 radius: windowRadius - 1
visible: windowRadius
color: "transparent" color: "transparent"
border.width: 1 border.width: 1
border.color: Qt.rgba(255, 255, 255, 0.3) border.color: Qt.rgba(255, 255, 255, 0.3)

View file

@ -40,7 +40,7 @@ DockSettings::DockSettings(QObject *parent)
: QObject(parent) : QObject(parent)
, m_iconSize(0) , m_iconSize(0)
, m_edgeMargins(10) , m_edgeMargins(10)
, m_statusBarHeight(30) , m_roundedWindowEnabled(true)
, m_direction(Left) , m_direction(Left)
, m_visibility(AlwaysVisible) , m_visibility(AlwaysVisible)
, m_settings(new QSettings(QSettings::UserScope, "cutefishos", "dock")) , m_settings(new QSettings(QSettings::UserScope, "cutefishos", "dock"))
@ -52,11 +52,14 @@ DockSettings::DockSettings(QObject *parent)
m_settings->setValue("Direction", Bottom); m_settings->setValue("Direction", Bottom);
if (!m_settings->contains("Visibility")) if (!m_settings->contains("Visibility"))
m_settings->setValue("Visibility", AlwaysVisible); m_settings->setValue("Visibility", AlwaysVisible);
if (!m_settings->contains("RoundedWindow"))
m_settings->setValue("RoundedWindow", true);
m_settings->sync(); m_settings->sync();
m_iconSize = m_settings->value("IconSize").toInt(); m_iconSize = m_settings->value("IconSize").toInt();
m_direction = static_cast<Direction>(m_settings->value("Direction").toInt()); m_direction = static_cast<Direction>(m_settings->value("Direction").toInt());
m_roundedWindowEnabled = m_settings->value("RoundedWindow").toBool();
m_fileWatcher->addPath(m_settings->fileName()); m_fileWatcher->addPath(m_settings->fileName());
connect(m_fileWatcher, &QFileSystemWatcher::fileChanged, this, &DockSettings::onConfigFileChanged); connect(m_fileWatcher, &QFileSystemWatcher::fileChanged, this, &DockSettings::onConfigFileChanged);
@ -107,14 +110,17 @@ void DockSettings::setEdgeMargins(int edgeMargins)
m_edgeMargins = edgeMargins; m_edgeMargins = edgeMargins;
} }
int DockSettings::statusBarHeight() const bool DockSettings::roundedWindowEnabled() const
{ {
return m_statusBarHeight; return m_roundedWindowEnabled;
} }
void DockSettings::setStatusBarHeight(int statusBarHeight) void DockSettings::setRoundedWindowEnabled(bool enabled)
{ {
m_statusBarHeight = statusBarHeight; if (m_roundedWindowEnabled != enabled) {
m_roundedWindowEnabled = enabled;
emit roundedWindowEnabledChanged();
}
} }
void DockSettings::onConfigFileChanged() void DockSettings::onConfigFileChanged()
@ -127,6 +133,7 @@ void DockSettings::onConfigFileChanged()
int iconSize = m_settings->value("IconSize").toInt(); int iconSize = m_settings->value("IconSize").toInt();
Direction direction = static_cast<Direction>(m_settings->value("Direction").toInt()); Direction direction = static_cast<Direction>(m_settings->value("Direction").toInt());
Visibility visibility = static_cast<Visibility>(m_settings->value("Visibility").toInt()); Visibility visibility = static_cast<Visibility>(m_settings->value("Visibility").toInt());
bool roundedWindow = m_settings->value("RoundedWindow").toBool();
if (m_iconSize != iconSize) if (m_iconSize != iconSize)
setIconSize(iconSize); setIconSize(iconSize);
@ -137,5 +144,8 @@ void DockSettings::onConfigFileChanged()
if (m_visibility != visibility) if (m_visibility != visibility)
setVisibility(visibility); setVisibility(visibility);
if (m_roundedWindowEnabled != roundedWindow)
setRoundedWindowEnabled(roundedWindow);
m_fileWatcher->addPath(m_settings->fileName()); m_fileWatcher->addPath(m_settings->fileName());
} }

View file

@ -30,6 +30,7 @@ class DockSettings : public QObject
Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged) Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged)
Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
Q_PROPERTY(int edgeMargins READ edgeMargins WRITE setEdgeMargins) Q_PROPERTY(int edgeMargins READ edgeMargins WRITE setEdgeMargins)
Q_PROPERTY(bool roundedWindowEnabled READ roundedWindowEnabled WRITE setRoundedWindowEnabled NOTIFY roundedWindowEnabledChanged)
public: public:
enum Direction { enum Direction {
@ -60,8 +61,8 @@ public:
int edgeMargins() const; int edgeMargins() const;
void setEdgeMargins(int edgeMargins); void setEdgeMargins(int edgeMargins);
int statusBarHeight() const; bool roundedWindowEnabled() const;
void setStatusBarHeight(int statusBarHeight); void setRoundedWindowEnabled(bool enabled);
private slots: private slots:
void onConfigFileChanged(); void onConfigFileChanged();
@ -70,11 +71,12 @@ signals:
void iconSizeChanged(); void iconSizeChanged();
void directionChanged(); void directionChanged();
void visibilityChanged(); void visibilityChanged();
void roundedWindowEnabledChanged();
private: private:
int m_iconSize; int m_iconSize;
int m_edgeMargins; int m_edgeMargins;
int m_statusBarHeight; bool m_roundedWindowEnabled;
Direction m_direction; Direction m_direction;
Visibility m_visibility; Visibility m_visibility;
QSettings *m_settings; QSettings *m_settings;

View file

@ -67,6 +67,8 @@ MainWindow::MainWindow(QQuickView *parent)
}); });
connect(m_settings, &DockSettings::roundedWindowEnabledChanged, this, &MainWindow::resizeWindow);
connect(m_settings, &DockSettings::directionChanged, this, &MainWindow::onPositionChanged); connect(m_settings, &DockSettings::directionChanged, this, &MainWindow::onPositionChanged);
connect(m_settings, &DockSettings::iconSizeChanged, this, &MainWindow::onIconSizeChanged); connect(m_settings, &DockSettings::iconSizeChanged, this, &MainWindow::onIconSizeChanged);
connect(m_settings, &DockSettings::visibilityChanged, this, &MainWindow::onVisibilityChanged); connect(m_settings, &DockSettings::visibilityChanged, this, &MainWindow::onVisibilityChanged);
@ -85,17 +87,30 @@ QRect MainWindow::windowRect() const
switch (m_settings->direction()) { switch (m_settings->direction()) {
case DockSettings::Left: case DockSettings::Left:
newSize = QSize(m_settings->iconSize(), screenGeometry.height() - m_settings->edgeMargins()); if (m_settings->roundedWindowEnabled()) {
position = { screenGeometry.x() + DockSettings::self()->edgeMargins() / 2, newSize = QSize(m_settings->iconSize(), screenGeometry.height() - m_settings->edgeMargins());
(screenGeometry.height() - newSize.height()) / 2 position = { screenGeometry.x() + DockSettings::self()->edgeMargins() / 2,
}; (screenGeometry.height() - newSize.height()) / 2
};
} else {
newSize = QSize(m_settings->iconSize(), screenGeometry.height());
position = { screenGeometry.x(), (screenGeometry.height() - newSize.height()) / 2 };
}
break; break;
case DockSettings::Bottom: case DockSettings::Bottom:
newSize = QSize(screenGeometry.width() - DockSettings::self()->edgeMargins(), m_settings->iconSize()); if (m_settings->roundedWindowEnabled()) {
position = { (screenGeometry.width() - newSize.width()) / 2, newSize = QSize(screenGeometry.width() - DockSettings::self()->edgeMargins(), m_settings->iconSize());
screenGeometry.y() + screenGeometry.height() - newSize.height() position = { (screenGeometry.width() - newSize.width()) / 2,
- DockSettings::self()->edgeMargins() / 2 screenGeometry.y() + screenGeometry.height() - newSize.height()
}; - DockSettings::self()->edgeMargins() / 2
};
} else {
newSize = QSize(screenGeometry.width(), m_settings->iconSize());
position = { screenGeometry.x(),
screenGeometry.y() + screenGeometry.height() - newSize.height()
};
}
break; break;
default: default:
break; break;

View file

@ -152,17 +152,19 @@ void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction dire
const QRect currentScreen { screen->geometry() }; const QRect currentScreen { screen->geometry() };
const QRect wholeScreen { {0, 0}, screen->virtualSize() }; const QRect wholeScreen { {0, 0}, screen->virtualSize() };
bool roundedWindow = DockSettings::self()->roundedWindowEnabled();
switch (direction) { switch (direction) {
case DockSettings::Left: { case DockSettings::Left: {
const int leftOffset = { screen->geometry().left() }; const int leftOffset = { screen->geometry().left() };
strut.left_width = rect.width() + leftOffset + DockSettings::self()->edgeMargins(); strut.left_width = rect.width() + leftOffset + (roundedWindow ? DockSettings::self()->edgeMargins() : 0);
strut.left_start = rect.y(); strut.left_start = rect.y();
strut.left_end = rect.y() + rect.height() - 1; strut.left_end = rect.y() + rect.height() - 1;
break; break;
} }
case DockSettings::Bottom: { case DockSettings::Bottom: {
const int bottomOffset { wholeScreen.bottom() - currentScreen.bottom() }; const int bottomOffset { wholeScreen.bottom() - currentScreen.bottom() };
strut.bottom_width = rect.height() + bottomOffset + (isMax ? 0 : DockSettings::self()->edgeMargins()); strut.bottom_width = rect.height() + bottomOffset + (roundedWindow ? DockSettings::self()->edgeMargins() : 0);
strut.bottom_start = rect.x(); strut.bottom_start = rect.x();
strut.bottom_end = rect.x() + rect.width(); strut.bottom_end = rect.x() + rect.width();
break; break;

View file

@ -27,7 +27,7 @@
<context> <context>
<name>ApplicationModel</name> <name>ApplicationModel</name>
<message> <message>
<location filename="../src/applicationmodel.cpp" line="279"/> <location filename="../src/applicationmodel.cpp" line="282"/>
<source>Launcher</source> <source>Launcher</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -35,30 +35,30 @@
<context> <context>
<name>ControlDialog</name> <name>ControlDialog</name>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="177"/> <location filename="../qml/ControlDialog.qml" line="178"/>
<source>Wi-Fi</source> <source>Wi-Fi</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="180"/> <location filename="../qml/ControlDialog.qml" line="181"/>
<location filename="../qml/ControlDialog.qml" line="201"/> <location filename="../qml/ControlDialog.qml" line="204"/>
<source>On</source> <source>On</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="180"/> <location filename="../qml/ControlDialog.qml" line="181"/>
<location filename="../qml/ControlDialog.qml" line="191"/> <location filename="../qml/ControlDialog.qml" line="193"/>
<location filename="../qml/ControlDialog.qml" line="201"/> <location filename="../qml/ControlDialog.qml" line="204"/>
<source>Off</source> <source>Off</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="190"/> <location filename="../qml/ControlDialog.qml" line="192"/>
<source>Bluetooth</source> <source>Bluetooth</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="200"/> <location filename="../qml/ControlDialog.qml" line="203"/>
<source>Dark Mode</source> <source>Dark Mode</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View file

@ -27,7 +27,7 @@
<context> <context>
<name>ApplicationModel</name> <name>ApplicationModel</name>
<message> <message>
<location filename="../src/applicationmodel.cpp" line="279"/> <location filename="../src/applicationmodel.cpp" line="282"/>
<source>Launcher</source> <source>Launcher</source>
<translation></translation> <translation></translation>
</message> </message>
@ -35,30 +35,30 @@
<context> <context>
<name>ControlDialog</name> <name>ControlDialog</name>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="177"/> <location filename="../qml/ControlDialog.qml" line="178"/>
<source>Wi-Fi</source> <source>Wi-Fi</source>
<translation>线</translation> <translation>线</translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="180"/> <location filename="../qml/ControlDialog.qml" line="181"/>
<location filename="../qml/ControlDialog.qml" line="201"/> <location filename="../qml/ControlDialog.qml" line="204"/>
<source>On</source> <source>On</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="180"/> <location filename="../qml/ControlDialog.qml" line="181"/>
<location filename="../qml/ControlDialog.qml" line="191"/> <location filename="../qml/ControlDialog.qml" line="193"/>
<location filename="../qml/ControlDialog.qml" line="201"/> <location filename="../qml/ControlDialog.qml" line="204"/>
<source>Off</source> <source>Off</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="190"/> <location filename="../qml/ControlDialog.qml" line="192"/>
<source>Bluetooth</source> <source>Bluetooth</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/ControlDialog.qml" line="200"/> <location filename="../qml/ControlDialog.qml" line="203"/>
<source>Dark Mode</source> <source>Dark Mode</source>
<translation></translation> <translation></translation>
</message> </message>