Add DockBackground class
This commit is contained in:
parent
6b0b576afd
commit
bc32f34ed5
5 changed files with 177 additions and 41 deletions
|
@ -28,6 +28,7 @@ set(SRCS
|
|||
src/trashmanager.cpp
|
||||
src/utils.cpp
|
||||
src/xwindowinterface.cpp
|
||||
src/dockbackground.cpp
|
||||
|
||||
src/fakewindow.cpp
|
||||
)
|
||||
|
|
55
qml/main.qml
55
qml/main.qml
|
@ -11,34 +11,18 @@ Item {
|
|||
visible: true
|
||||
|
||||
property bool isHorizontal: Settings.direction === DockSettings.Bottom
|
||||
property real windowRadius: isHorizontal ? root.height * 0.3 : root.width * 0.3
|
||||
property real windowRadius: isHorizontal ? root.height * 0.35 : root.width * 0.35
|
||||
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
enabled: true
|
||||
}
|
||||
|
||||
FishUI.WindowShadow {
|
||||
view: mainWindow
|
||||
geometry: Qt.rect(root.x, root.y, root.width, root.height)
|
||||
strength: 0.5
|
||||
radius: _background.radius
|
||||
}
|
||||
|
||||
FishUI.WindowBlur {
|
||||
view: mainWindow
|
||||
geometry: Qt.rect(root.x, root.y, root.width, root.height)
|
||||
windowRadius: _background.radius
|
||||
enabled: true
|
||||
}
|
||||
|
||||
// Background
|
||||
Rectangle {
|
||||
id: _background
|
||||
DockBackground {
|
||||
anchors.fill: parent
|
||||
radius: windowRadius
|
||||
color: FishUI.Theme.backgroundColor
|
||||
radius: root.windowRadius
|
||||
opacity: FishUI.Theme.darkMode ? 0.3 : 0.4
|
||||
color: FishUI.Theme.backgroundColor
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
|
@ -55,29 +39,18 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "transparent"
|
||||
radius: windowRadius
|
||||
visible: windowRadius
|
||||
border.width: 1
|
||||
border.color: Qt.rgba(0, 0, 0, 1)
|
||||
opacity: FishUI.Theme.darkMode ? 0.3 : 0.1
|
||||
antialiasing: true
|
||||
smooth: true
|
||||
FishUI.WindowShadow {
|
||||
view: mainWindow
|
||||
geometry: Qt.rect(root.x, root.y, root.width, root.height)
|
||||
strength: 1
|
||||
radius: root.windowRadius
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 1
|
||||
radius: windowRadius - 1
|
||||
visible: windowRadius
|
||||
color: "transparent"
|
||||
border.width: 1
|
||||
border.color: Qt.rgba(255, 255, 255, 1)
|
||||
opacity: FishUI.Theme.darkMode ? 0.3 : 0.1
|
||||
antialiasing: true
|
||||
smooth: true
|
||||
FishUI.WindowBlur {
|
||||
view: mainWindow
|
||||
geometry: Qt.rect(root.x, root.y, root.width, root.height)
|
||||
windowRadius: root.windowRadius
|
||||
enabled: true
|
||||
}
|
||||
|
||||
FishUI.PopupTips {
|
||||
|
|
107
src/dockbackground.cpp
Normal file
107
src/dockbackground.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: rekols <revenmartin@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dockbackground.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainterPath>
|
||||
#include <QPainter>
|
||||
|
||||
DockBackground::DockBackground()
|
||||
: m_radius(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QColor DockBackground::color() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void DockBackground::setColor(QColor color)
|
||||
{
|
||||
if (m_color != color) {
|
||||
m_color = color;
|
||||
update();
|
||||
emit colorChanged();
|
||||
}
|
||||
}
|
||||
|
||||
qreal DockBackground::radius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
void DockBackground::setRadius(qreal radius)
|
||||
{
|
||||
if (m_radius != radius) {
|
||||
m_radius = radius;
|
||||
update();
|
||||
emit radiusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DockBackground::paint(QPainter *painter)
|
||||
{
|
||||
if (!qApp)
|
||||
return;
|
||||
|
||||
// Enable antialiasing.
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QRectF rect = boundingRect();
|
||||
QPainterPath path;
|
||||
QPen pen;
|
||||
|
||||
// Draw background.
|
||||
path.addRoundedRect(rect.x(), rect.y(), rect.width(), rect.height(), m_radius, m_radius);
|
||||
painter->setBrush(m_color);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawPath(path);
|
||||
|
||||
// Draw border line.
|
||||
path.clear();
|
||||
path.addRoundedRect(rect.adjusted(0.5, 0.5, -0.5, -0.5),
|
||||
m_radius - 0.5,
|
||||
m_radius - 0.5);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
pen.setColor(QColor(0, 0, 0, 255));
|
||||
pen.setWidthF(0.5);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawPath(path);
|
||||
|
||||
path.clear();
|
||||
path.addRoundedRect(rect.adjusted(1, 1, -1, -1),
|
||||
m_radius - 1,
|
||||
m_radius - 1);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
pen.setColor(QColor(255, 255, 255, 255));
|
||||
pen.setWidthF(0.5);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawPath(path);
|
||||
}
|
||||
|
||||
void DockBackground::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
{
|
||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||
|
||||
update();
|
||||
}
|
53
src/dockbackground.h
Normal file
53
src/dockbackground.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: rekols <revenmartin@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DOCKBACKGROUND_H
|
||||
#define DOCKBACKGROUND_H
|
||||
|
||||
#include <QQuickPaintedItem>
|
||||
|
||||
class DockBackground : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
|
||||
|
||||
public:
|
||||
DockBackground();
|
||||
|
||||
QColor color() const;
|
||||
void setColor(QColor color);
|
||||
|
||||
qreal radius() const;
|
||||
void setRadius(qreal radius);
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
|
||||
|
||||
signals:
|
||||
void colorChanged();
|
||||
void radiusChanged();
|
||||
|
||||
private:
|
||||
qreal m_radius;
|
||||
|
||||
QColor m_color;
|
||||
};
|
||||
|
||||
#endif // DOCKBACKGROUND_H
|
|
@ -24,6 +24,7 @@
|
|||
#include <QLocale>
|
||||
|
||||
#include "applicationmodel.h"
|
||||
#include "dockbackground.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -32,6 +33,7 @@ int main(int argc, char *argv[])
|
|||
QApplication app(argc, argv);
|
||||
|
||||
qmlRegisterType<DockSettings>("Cutefish.Dock", 1, 0, "DockSettings");
|
||||
qmlRegisterType<DockBackground>("Cutefish.Dock", 1, 0, "DockBackground");
|
||||
|
||||
QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-dock/translations/").arg(QLocale::system().name());
|
||||
if (QFile::exists(qmFilePath)) {
|
||||
|
|
Loading…
Reference in a new issue