Add new style

This commit is contained in:
reionwong 2021-10-16 19:53:52 +08:00
parent 1194e01512
commit a1761b3ddb
7 changed files with 107 additions and 21 deletions

View file

@ -37,6 +37,10 @@ Item {
mainWindow.updateSize() mainWindow.updateSize()
} }
Component.onCompleted: {
console.log(Settings.style)
}
DropArea { DropArea {
anchors.fill: parent anchors.fill: parent
enabled: true enabled: true
@ -46,9 +50,9 @@ Item {
Rectangle { Rectangle {
id: _background id: _background
anchors.fill: parent anchors.fill: parent
radius: root.compositing ? windowRadius : 0 radius: root.compositing && Settings.style === 0 ? windowRadius : 0
color: FishUI.Theme.darkMode ? "#666666" : "#E6E6E6" color: FishUI.Theme.darkMode ? "#666666" : "#E6E6E6"
opacity: root.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.4 : 0.9 opacity: root.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.5 : 0.9
border.width: 0 border.width: 0
Behavior on color { Behavior on color {
@ -67,13 +71,13 @@ Item {
view: mainWindow view: mainWindow
geometry: Qt.rect(root.x, root.y, root.width, root.height) geometry: Qt.rect(root.x, root.y, root.width, root.height)
strength: 1 strength: 1
radius: root.windowRadius radius: _background.radius
} }
FishUI.WindowBlur { FishUI.WindowBlur {
view: mainWindow view: mainWindow
geometry: Qt.rect(root.x, root.y, root.width, root.height) geometry: Qt.rect(root.x, root.y, root.width, root.height)
windowRadius: root.windowRadius windowRadius: _background.radius
enabled: true enabled: true
} }
@ -86,6 +90,9 @@ Item {
GridLayout { GridLayout {
id: mainLayout id: mainLayout
anchors.fill: parent anchors.fill: parent
anchors.topMargin: Settings.style === 1
&& (Settings.direction === 0 || Settings.direction === 2)
? 28 : 0
flow: isHorizontal ? Grid.LeftToRight : Grid.TopToBottom flow: isHorizontal ? Grid.LeftToRight : Grid.TopToBottom
columnSpacing: 0 columnSpacing: 0
rowSpacing: 0 rowSpacing: 0

View file

@ -11,6 +11,7 @@
<method name="setDirection"><arg name="direction" type="i" direction="in"/></method> <method name="setDirection"><arg name="direction" type="i" direction="in"/></method>
<method name="setIconSize"><arg name="iconSize" type="i" direction="in"/></method> <method name="setIconSize"><arg name="iconSize" type="i" direction="in"/></method>
<method name="setVisibility"><arg name="visibility" type="i" direction="in"/></method> <method name="setVisibility"><arg name="visibility" type="i" direction="in"/></method>
<method name="setStyle"><arg name="style" type="i" direction="in"/></method>
<property name="primaryGeometry" type="(iiii)" access="read"> <property name="primaryGeometry" type="(iiii)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QRect"/> <annotation name="org.qtproject.QtDBus.QtTypeName" value="QRect"/>
@ -18,9 +19,12 @@
<property name="direction" type="i" access="read"></property> <property name="direction" type="i" access="read"></property>
<property name="visibility" type="i" access="read"></property> <property name="visibility" type="i" access="read"></property>
<property name="style" type="i" access="read"></property>
<signal name="primaryGeometryChanged"></signal> <signal name="primaryGeometryChanged"></signal>
<signal name="directionChanged"></signal> <signal name="directionChanged"></signal>
<signal name="visibilityChanged"></signal> <signal name="visibilityChanged"></signal>
<signal name="styleChanged"></signal>
</interface> </interface>
</node> </node>

View file

@ -53,6 +53,8 @@ DockSettings::DockSettings(QObject *parent)
m_settings->setValue("Visibility", AlwaysShow); m_settings->setValue("Visibility", AlwaysShow);
if (!m_settings->contains("RoundedWindow")) if (!m_settings->contains("RoundedWindow"))
m_settings->setValue("RoundedWindow", true); m_settings->setValue("RoundedWindow", true);
if (!m_settings->contains("Style"))
m_settings->setValue("Style", Straight);
m_settings->sync(); m_settings->sync();
@ -60,6 +62,7 @@ DockSettings::DockSettings(QObject *parent)
m_direction = static_cast<Direction>(m_settings->value("Direction").toInt()); m_direction = static_cast<Direction>(m_settings->value("Direction").toInt());
m_visibility = static_cast<Visibility>(m_settings->value("Visibility").toInt()); m_visibility = static_cast<Visibility>(m_settings->value("Visibility").toInt());
m_roundedWindowEnabled = m_settings->value("RoundedWindow").toBool(); m_roundedWindowEnabled = m_settings->value("RoundedWindow").toBool();
m_style = static_cast<Style>(m_settings->value("Style").toInt());
} }
int DockSettings::iconSize() const int DockSettings::iconSize() const
@ -126,3 +129,17 @@ void DockSettings::setRoundedWindowEnabled(bool enabled)
emit roundedWindowEnabledChanged(); emit roundedWindowEnabledChanged();
} }
} }
DockSettings::Style DockSettings::style() const
{
return m_style;
}
void DockSettings::setStyle(const DockSettings::Style &style)
{
if (m_style != style) {
m_style = style;
m_settings->setValue("Style", style);
emit styleChanged();
}
}

View file

@ -30,6 +30,7 @@ class DockSettings : public QObject
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) Q_PROPERTY(bool roundedWindowEnabled READ roundedWindowEnabled WRITE setRoundedWindowEnabled NOTIFY roundedWindowEnabledChanged)
Q_PROPERTY(Style style READ style WRITE setStyle NOTIFY styleChanged)
public: public:
enum Direction { enum Direction {
@ -47,6 +48,12 @@ public:
}; };
Q_ENUMS(Visibility) Q_ENUMS(Visibility)
enum Style {
Round = 0,
Straight
};
Q_ENUMS(Style)
static DockSettings *self(); static DockSettings *self();
explicit DockSettings(QObject *parent = nullptr); explicit DockSettings(QObject *parent = nullptr);
@ -65,11 +72,15 @@ public:
bool roundedWindowEnabled() const; bool roundedWindowEnabled() const;
void setRoundedWindowEnabled(bool enabled); void setRoundedWindowEnabled(bool enabled);
Style style() const;
void setStyle(const Style &style);
signals: signals:
void iconSizeChanged(); void iconSizeChanged();
void directionChanged(); void directionChanged();
void visibilityChanged(); void visibilityChanged();
void roundedWindowEnabledChanged(); void roundedWindowEnabledChanged();
void styleChanged();
private: private:
int m_iconSize; int m_iconSize;
@ -77,6 +88,7 @@ private:
bool m_roundedWindowEnabled; bool m_roundedWindowEnabled;
Direction m_direction; Direction m_direction;
Visibility m_visibility; Visibility m_visibility;
Style m_style;
QSettings *m_settings; QSettings *m_settings;
}; };

View file

@ -92,6 +92,7 @@ MainWindow::MainWindow(QQuickView *parent)
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);
connect(m_settings, &DockSettings::styleChanged, this, &MainWindow::resizeWindow);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -143,6 +144,16 @@ void MainWindow::setVisibility(int visibility)
DockSettings::self()->setVisibility(static_cast<DockSettings::Visibility>(visibility)); DockSettings::self()->setVisibility(static_cast<DockSettings::Visibility>(visibility));
} }
int MainWindow::style() const
{
return DockSettings::self()->style();
}
void MainWindow::setStyle(int style)
{
DockSettings::self()->setStyle(static_cast<DockSettings::Style>(style));
}
void MainWindow::updateSize() void MainWindow::updateSize()
{ {
resizeWindow(); resizeWindow();
@ -171,31 +182,60 @@ QRect MainWindow::windowRect() const
int iconSize = m_settings->iconSize(); int iconSize = m_settings->iconSize();
iconSize += iconSize * 0.1; iconSize += iconSize * 0.1;
int length = appCount * iconSize; int length = appCount * iconSize;
int margins = compositing ? DockSettings::self()->edgeMargins() / 2 : 0;
if (length >= maxLength) { if (length >= maxLength) {
iconSize = (maxLength - (maxLength % appCount)) / appCount; iconSize = (maxLength - (maxLength % appCount)) / appCount;
length = appCount * iconSize; length = appCount * iconSize;
} }
int margins = compositing ? DockSettings::self()->edgeMargins() / 2 : 0; switch (m_settings->style()) {
case DockSettings::Round: {
switch (m_settings->direction()) {
case DockSettings::Left:
newSize = QSize(iconSize, length);
position.setX(screenGeometry.x() + margins);
// Handle the top statusbar.
position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2);
break;
case DockSettings::Bottom:
newSize = QSize(length, iconSize);
position.setX(screenGeometry.x() + (screenGeometry.width() - newSize.width()) / 2);
position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height() - margins);
break;
case DockSettings::Right:
newSize = QSize(iconSize, length);
position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width() - margins);
position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2);
break;
default:
break;
}
switch (m_settings->direction()) {
case DockSettings::Left:
newSize = QSize(iconSize, length);
position.setX(screenGeometry.x() + margins);
// Handle the top statusbar.
position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2);
break; break;
case DockSettings::Bottom: }
newSize = QSize(length, iconSize); case DockSettings::Straight: {
position.setX(screenGeometry.x() + (screenGeometry.width() - newSize.width()) / 2); switch (m_settings->direction()) {
position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height() - margins); case DockSettings::Left:
break; newSize = QSize(iconSize, screenGeometry.height());
case DockSettings::Right: position.setX(screenGeometry.x());
newSize = QSize(iconSize, length); position.setY(screenGeometry.y());
position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width() - margins); break;
position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2); case DockSettings::Bottom:
newSize = QSize(screenGeometry.width(), iconSize);
position.setX(screenGeometry.x());
position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height());
break;
case DockSettings::Right:
newSize = QSize(iconSize, screenGeometry.height());
position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width());
position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height());
break;
default:
break;
}
break; break;
}
default: default:
break; break;
} }

View file

@ -35,6 +35,7 @@ class MainWindow : public QQuickView
Q_PROPERTY(QRect primaryGeometry READ primaryGeometry NOTIFY primaryGeometryChanged) Q_PROPERTY(QRect primaryGeometry READ primaryGeometry NOTIFY primaryGeometryChanged)
Q_PROPERTY(int direction READ direction NOTIFY directionChanged) Q_PROPERTY(int direction READ direction NOTIFY directionChanged)
Q_PROPERTY(int visibility READ visibility NOTIFY visibilityChanged) Q_PROPERTY(int visibility READ visibility NOTIFY visibilityChanged)
Q_PROPERTY(int style READ style NOTIFY styleChanged)
public: public:
explicit MainWindow(QQuickView *parent = nullptr); explicit MainWindow(QQuickView *parent = nullptr);
@ -54,6 +55,9 @@ public:
void setIconSize(int iconSize); void setIconSize(int iconSize);
void setVisibility(int visibility); void setVisibility(int visibility);
int style() const;
void setStyle(int style);
Q_INVOKABLE void updateSize(); Q_INVOKABLE void updateSize();
signals: signals:
@ -62,6 +66,7 @@ signals:
void directionChanged(); void directionChanged();
void primaryGeometryChanged(); void primaryGeometryChanged();
void visibilityChanged(); void visibilityChanged();
void styleChanged();
private: private:
QRect windowRect() const; QRect windowRect() const;

View file

@ -151,7 +151,8 @@ 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() };
const int edgeMargins = compositing ? DockSettings::self()->edgeMargins() : 0; bool isRound = DockSettings::self()->style() == DockSettings::Round;
const int edgeMargins = compositing && isRound? DockSettings::self()->edgeMargins() : 0;
switch (direction) { switch (direction) {
case DockSettings::Left: { case DockSettings::Left: {