!6 添加qml模块代码

This commit is contained in:
xibowen 2022-06-18 12:35:09 +00:00 committed by handsome_feng
parent 7dcb1f8441
commit 12aea3dce6
34 changed files with 3598 additions and 3 deletions

11
debian/changelog vendored
View File

@ -1,3 +1,14 @@
qt5-ukui-platformtheme (3.1.4.1~0509-ok2) yangtze; urgency=medium
* 改动:
BUG号修复非焦点和焦点状态下icon颜色会变化的问题
添加qml主题框架模块
需求号:无
其他改:无
影响域icon颜色qml主题样式
-- xibowen <xibowen@kylinos.cn> Sat, 18 Jun 2022 18:42:00 +0800
qt5-ukui-platformtheme (3.1.4.1~0509-ok1) yangtze; urgency=medium
* Initial for openkylin.

24
debian/control vendored
View File

@ -19,7 +19,14 @@ Build-Depends: debhelper-compat (=12),
qttools5-dev-tools,
libqt5xdgiconloader-dev,
qtquickcontrols2-5-dev,
qtdeclarative5-dev
qtdeclarative5-dev,
dbus-x11,
kirigami2-dev (>= 5.68.0~),
libkf5iconthemes-dev (>= 5.68.0~),
libqt5x11extras5-dev (>= 5.8.0~),
qtdeclarative5-dev (>= 5.8.0~),
qtquickcontrols2-5-dev (>= 5.8.0~),
libqt5svg5-dev (>= 5.8.0~)
Standards-Version: 4.5.1
Rules-Requires-Root: no
Homepage: https://www.ukui.org
@ -90,3 +97,18 @@ Description: Development files of libqt5-ukui-style1
animation, etc.
.
This package provides the development files of libqt5-ukui-style1.
Package: qml-module-org-ukui-qqc2desktopstyle
Architecture: any
Depends: qml-module-qtgraphicaleffects,
qml-module-qtqml-models2,
qml-module-qtquick-controls2,
qml-module-qtquick-layouts,
qml-module-qtquick-templates2,
qml-module-qtquick-window2,
qml-module-qtquick2,
${misc:Depends},
${shlibs:Depends},
Description: Qt Quick Controls 2: Kylin Style
Small style written in QML for QtQuickControls2 intended to be used
by default in QQC2-based apps when used in the Kylin tablet desktop

View File

@ -0,0 +1,3 @@
usr/lib/*/qt5/qml/org/kylin/qqc2style/*
usr/lib/*/qt5/qml/QtQuick/Controls.2/*

View File

@ -0,0 +1,28 @@
# kylin-qqc2-style
kylin qquick control 2
## Description
kylin-qqc2-style 是参考 qqc2-desktop-style 实现的一个 qml 主题,主要包括以下几部分:
> 1. org.kylin.style: 提供 qml style org.kylin.style可以通过 QQuickStyle::setStyle 或其他方式设置 qml 应用使用次样式
> 2. qqc2-style-plugin: 提供一个自定义的 QQuickItem 供 org.kylin.style 使用
## Depends
qtbase
qquick
kirigami2-dev
KIconLoader
KColorScheme
KSharedConfig
KConfigGroup
## build & install
mkdir build
cd build
qmake ..
make
sudo make install

View File

@ -0,0 +1,13 @@
TEMPLATE = subdirs
SUBDIRS += \
qqc2-style-plugin
DISTFILES += org.kylin.style/*
unix {
installPath = $$[QT_INSTALL_LIBS]/qt5/qml/QtQuick/Controls.2/org.kylin.style/
template.files = org.kylin.style/*
template.path = $$installPath
INSTALLS += template
}

View File

@ -0,0 +1,22 @@
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.impl 2.12
import QtQuick.Templates 2.12 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.ApplicationWindow {
id: window
color: palette.window
palette: StylePrivate.StyleHelper.palette
overlay.modal: Rectangle {
color: Color.transparent(window.palette.shadow, 0.5)
}
overlay.modeless: Rectangle {
color: Color.transparent(window.palette.shadow, 0.12)
}
}

View File

@ -0,0 +1,41 @@
import QtQuick 2.6
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.Button {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
/* The value type of buttonType are "CloseButton","MaxButton","MinButton","Default". */
property string buttonType
buttonType: "Default"
implicitWidth: background.implicitWidth
implicitHeight: background.implicitHeight
hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7?
contentItem: Item {}
background: StylePrivate.StyleItem {
id: styleitem
anchors.fill: parent
control: controlRoot
elementType: "button"
sunken: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
raised: !(controlRoot.pressed || (controlRoot.checkable && controlRoot.checked))
hover: controlRoot.hovered
text: controlRoot.text
hasFocus: controlRoot.activeFocus
activeControl: controlRoot.isDefault ? "default" : "f"
properties: {
"icon": controlRoot.icon && controlRoot.display !== T.AbstractButton.TextOnly ? (controlRoot.icon.name || controlRoot.icon.source) : "",
"iconWidth": controlRoot.icon && controlRoot.icon.width ? controlRoot.icon.width : 0,
"iconHeight": controlRoot.icon && controlRoot.icon.height ? controlRoot.icon.height : 0,
"flat": controlRoot.flat
}
}
}

View File

@ -0,0 +1,17 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.impl 2.12
import QtQuick.Templates 2.12 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.Label {
id:control
color:StylePrivate.StyleHelper.windowtextcolorrole
linkColor: control.palette.link
font: StylePrivate.StyleHelper.font
}

View File

@ -0,0 +1,97 @@
import QtQuick 2.7
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.5
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.Menu {
id: control
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
implicitWidth: Math.max(background ? background.implicitWidth : 0,
contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
contentItem ? contentItem.implicitHeight : 0) + topPadding + bottomPadding
margins: 0
delegate: MenuItem { onImplicitWidthChanged: control.contentItem.contentItem.childrenChanged() }
contentItem: ListView {
implicitHeight: contentHeight
property bool hasCheckables: false
property bool hasIcons: false
model: control.contentModel
implicitWidth: {
var maxWidth = 0;
for (var i = 0; i < contentItem.children.length; ++i) {
maxWidth = Math.max(maxWidth, contentItem.children[i].implicitWidth);
}
return maxWidth;
}
interactive: ApplicationWindow.window ? contentHeight > ApplicationWindow.window.height : false
clip: true
currentIndex: control.currentIndex || 0
keyNavigationEnabled: true
keyNavigationWraps: true
ScrollBar.vertical: ScrollBar {}
}
Connections {
target: control.contentItem.contentItem
onChildrenChanged: {
for (var i in control.contentItem.contentItem.children) {
var child = control.contentItem.contentItem.children[i];
if (child.checkable) {
control.contentItem.hasCheckables = true;
}
if (child.icon && child.icon.hasOwnProperty("name") && (child.icon.name.length > 0 || child.icon.source.length > 0)) {
control.contentItem.hasIcons = true;
}
}
}
}
enter: Transition {
NumberAnimation {
property: "opacity"
from: 0
to: 1
easing.type: Easing.InOutQuad
duration: 150
}
}
exit: Transition {
NumberAnimation {
property: "opacity"
from: 1
to: 0
easing.type: Easing.InOutQuad
duration: 150
}
}
background: Rectangle {
radius: 2
color: control.palette.window
layer.enabled: true
layer.effect: DropShadow {
transparentBorder: true
radius: 8
samples: 8
horizontalOffset: 0
verticalOffset: 2
color: Qt.rgba(0, 0, 0, 0.3)
}
}
}

View File

@ -0,0 +1,125 @@
import QtQuick 2.6
import QtQuick.Layouts 1.2
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
import QtQuick.Controls 2.5
T.MenuItem {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
implicitWidth: Math.max(background ? background.implicitWidth : 0,
contentItem.implicitWidth + leftPadding + rightPadding + (arrow ? arrow.implicitWidth : 0))
implicitHeight: visible ? Math.max(background ? background.implicitHeight : 0,
Math.max(contentItem.implicitHeight,
indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) : 0
baselineOffset: contentItem.y + contentItem.baselineOffset
width: parent ? parent.width : implicitWidth
Layout.fillWidth: true
padding: 6
property int gridUnit: fontMetrics.height
property string icontype: "default"
leftPadding: Math.floor(gridUnit/4)*2
rightPadding: Math.floor(gridUnit/4)*2
hoverEnabled: true
Shortcut {
//in case of explicit & the button manages it by itself
enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text))
onActivated: {
if (controlRoot.checkable) {
controlRoot.toggle();
} else {
controlRoot.clicked();
}
}
}
contentItem: RowLayout {
Item {
Layout.preferredWidth: (controlRoot.ListView.view && controlRoot.ListView.view.hasCheckables) || controlRoot.checkable ? controlRoot.indicator.width : Math.floor(gridUnit/4)
}
StylePrivate.KyIcon {
iconName: controlRoot.icon.name
width: controlRoot.icon.width
height: controlRoot.icon.height
sunken: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
hover: controlRoot.hovered
hasFocus: controlRoot.activeFocus
icontype: controlRoot.icontype
}
Label {
id: label
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
text: controlRoot.text
font: controlRoot.font
elide: Text.ElideRight
visible: controlRoot.text
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
Label {
id: shortcut
Layout.alignment: Qt.AlignVCenter
visible: controlRoot.action && controlRoot.action.hasOwnProperty("shortcut") && controlRoot.action.shortcut !== undefined
text: visible ? controlRoot.action.shortcut : ""
font: controlRoot.font
color: label.color
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
}
Item {
Layout.preferredWidth: Math.floor(gridUnit/4)
}
}
background: Item {
anchors.fill: parent
implicitWidth: gridUnit * 8
Rectangle {
anchors.fill: parent
opacity: (controlRoot.highlighted || controlRoot.hovered) ? 1 : 0
color: controlRoot.palette.highlight
}
}
property variant fontMetrics: TextMetrics {
text: "M"
function roundedIconSize(size) {
if (size < 16) {
return size;
} else if (size < 22) {
return 16;
} else if (size < 32) {
return 22;
} else if (size < 48) {
return 32;
} else if (size < 64) {
return 48;
} else {
return size;
}
}
}
}

View File

@ -0,0 +1,61 @@
import QtQuick 2.6
import QtGraphicalEffects 1.0
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.Popup {
id: control
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
implicitWidth: Math.max(background ? background.implicitWidth : 0,
contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
contentWidth > 0 ? contentHeight + topPadding + bottomPadding : 0)
contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
padding: 12
clip: true
enter: Transition {
NumberAnimation {
property: "opacity"
from: 0
to: 1
easing.type: Easing.InOutQuad
duration: 250
}
}
exit: Transition {
NumberAnimation {
property: "opacity"
from: 1
to: 0
easing.type: Easing.InOutQuad
duration: 250
}
}
contentItem: Item { }
background: Rectangle {
radius: 2
color: control.palette.window
border.color: control.palette.dark
layer.enabled: true
layer.effect: DropShadow {
transparentBorder: true
radius: 8
samples: 16
horizontalOffset: 0
verticalOffset: 4
color: Qt.rgba(0, 0, 0, 0.3)
}
}
}

View File

@ -0,0 +1,56 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.impl 2.12
import QtQuick.Templates 2.12 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.ScrollBar {
id: control
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding)
hoverEnabled: true
padding: 2
visible: control.policy !== T.ScrollBar.AlwaysOff
contentItem: Rectangle {
implicitWidth: control.interactive ? 6 : 2
implicitHeight: control.interactive ? 6 : 2
radius: width / 2
color: control.palette.shadow
opacity: 0.3
states: State {
name: "active"
when: control.policy === T.ScrollBar.AlwaysOn || (control.active && control.size < 1.0)
PropertyChanges { target: control.contentItem; implicitWidth:8.5; implicitHeight:8.5; opacity:0.5}
}
transitions: Transition {
from: "active"
SequentialAnimation {
PauseAnimation { duration: 200 }
NumberAnimation { target: control.contentItem; duration: 80; property: "opacity"; to: 0.3}
}
}
}
}

View File

@ -0,0 +1,38 @@
import QtQuick 2.9
import QtQuick.Controls 2.5
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.ScrollView {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
contentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
contentHeight + topPadding + bottomPadding)
ScrollBar.vertical: ScrollBar {
parent: controlRoot
x: controlRoot.mirrored ? 0 : controlRoot.width - width
y: controlRoot.topPadding
height: controlRoot.availableHeight
active: controlRoot.ScrollBar.horizontal || controlRoot.ScrollBar.horizontal.active
}
ScrollBar.horizontal: ScrollBar {
parent: controlRoot
x: controlRoot.leftPadding
y: controlRoot.height - height
width: controlRoot.availableWidth
active: controlRoot.ScrollBar.vertical || controlRoot.ScrollBar.vertical.active
}
}

View File

@ -0,0 +1,58 @@
import QtQuick 2.6
import QtQml.Models 2.1
import QtQuick.Controls 2.5
import org.kylin.qqc2style.private 1.0 as StylePrivate
import QtQuick.Templates 2.5 as T
T.TabButton {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
//Some qstyles like fusion don't have correct pixel metrics here and just return 0
implicitWidth: Math.max(styleitem.implicitWidth, textMetrics.width + textMetrics.height * 2)
implicitHeight: styleitem.implicitHeight || textMetrics.height * 2
baselineOffset: contentItem.y + contentItem.baselineOffset
//This width: is important to make the tabbar internals not assume
//all tabs have the same width
width: implicitWidth
padding: 0
hoverEnabled: true
contentItem: Item {}
background: StylePrivate.StyleItem {
id: styleitem
TextMetrics {
id: textMetrics
text: controlRoot.text
}
control: controlRoot
anchors.fill: parent
elementType: "tab"
paintMargins: 0
properties: {
"hasFrame" : true,
"icon": control.icon ? (control.icon.name || control.icon.source) : "",
"iconWidth": controlRoot.icon && controlRoot.icon.width ? controlRoot.icon.width : 0,
"iconHeight": controlRoot.icon && controlRoot.icon.height ? controlRoot.icon.height : 0,
"flat": controlRoot.flat
}
enabled: controlRoot.enabled
selected: controlRoot.checked
text: controlRoot.text
hover: controlRoot.hovered
hasFocus: controlRoot.activeFocus
}
}

View File

@ -0,0 +1,45 @@
import QtQuick.Controls 2.5
import QtQuick 2.6
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.ToolButton {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
property string icontype: "default"
implicitWidth: text.length > 0 ? background.implicitWidth : implicitHeight
implicitHeight: background.implicitHeight
hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7?
flat: true
contentItem: Item {}
StylePrivate.KyIcon {
id:icon
iconName: controlRoot.icon.name
anchors.verticalCenter: parent.verticalCenter
width: controlRoot.icon.width
height: controlRoot.icon.height
sunken: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
hover: controlRoot.hovered
hasFocus: controlRoot.activeFocus
icontype: controlRoot.icontype
}
background: StylePrivate.StyleItem {
id: styleitem
anchors.fill: parent
control: controlRoot
elementType: controlRoot.flat ? "toolbutton" : "button"
on: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
hover: controlRoot.hovered
text: controlRoot.text
hasFocus: false
activeControl: controlRoot.isDefault ? "default" : "f"
}
}

View File

@ -0,0 +1,60 @@
import QtQuick 2.6
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.5 as Controls
import QtQuick.Templates 2.5 as T
import org.kylin.qqc2style.private 1.0 as StylePrivate
T.ToolTip {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
font: StylePrivate.StyleHelper.font
x: parent ? Math.round((parent.width - implicitWidth) / 2) : 0
y: -implicitHeight - 3
// Always show the tooltip on top of everything else
z: 999
implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
margins: 6
padding: 6
// Timeout based on text length, from QTipLabel::restartExpireTimer
timeout: 10000 + 40 * Math.max(0, text.length - 100)
closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutsideParent | T.Popup.CloseOnReleaseOutsideParent
contentItem: Controls.Label {
text: controlRoot.text
wrapMode: Text.WordWrap
font: controlRoot.font
color: controlRoot.palette.windowText
}
background: Rectangle {
radius: 3
//border.color: controlRoot.palette.dark
color: controlRoot.palette.toolTipBase
layer.enabled: true
layer.effect: DropShadow {
transparentBorder: true
radius: 4
samples: 8
horizontalOffset: 0
verticalOffset: 0
color: Qt.rgba(0, 0, 0, 0.3)
}
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2017 Marco Martin <mart@kde.org>
* Copyright 2017 The Qt Company Ltd.
*
* GNU Lesser General Public License Usage
* Alternatively, this file may be used under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.LGPLv3 included in the
* packaging of this file. Please review the following information to
* ensure the GNU Lesser General Public License version 3 requirements
* will be met: https://www.gnu.org/licenses/lgpl.html.
*
* GNU General Public License Usage
* Alternatively, this file may be used under the terms of the GNU
* General Public License version 2.0 or later as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information to
* ensure the GNU General Public License version 2.0 requirements will be
* met: http://www.gnu.org/licenses/gpl-2.0.html.
*/
import QtQuick 2.1
import org.kde.kirigami 2.4 as Kirigami
Rectangle {
id: background
color: highlighted || (controlRoot.pressed && !controlRoot.checked && !controlRoot.sectionDelegate) ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor
visible: controlRoot.ListView.view ? controlRoot.ListView.view.highlight === null : true
Rectangle {
anchors.fill: parent
color: Kirigami.Theme.highlightColor
opacity: controlRoot.hovered && !controlRoot.pressed ? 0.2 : 0
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2018 Kai Uwe Broulik <kde@privat.broulik.de>
* Copyright 2017 The Qt Company Ltd.
*
* GNU Lesser General Public License Usage
* Alternatively, this file may be used under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.LGPLv3 included in the
* packaging of this file. Please review the following information to
* ensure the GNU Lesser General Public License version 3 requirements
* will be met: https://www.gnu.org/licenses/lgpl.html.
*
* GNU General Public License Usage
* Alternatively, this file may be used under the terms of the GNU
* General Public License version 2.0 or later as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information to
* ensure the GNU General Public License version 2.0 requirements will be
* met: http://www.gnu.org/licenses/gpl-2.0.html.
*/
import QtQuick 2.6
import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
StylePrivate.StyleItem {
elementType: "focusrect"
// those random numbers come from QQC1 desktop style
anchors {
top: parent.top
bottom: parent.bottom
topMargin: parent.topPadding - 1
bottomMargin: parent.bottomPadding - 1
}
// this is explicitly not using left anchor for auto mirroring
// since the label's leftPadding/rightPadding already accounts for that
x: parent.leftPadding - 2
width: parent.implicitWidth - parent.leftPadding - parent.rightPadding + 3
visible: control.activeFocus
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2018 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.1
import org.kde.kirigami 2.5 as Kirigami
Item {
id: root
width: 1 //<-important that this is actually a single device pixel
height: Kirigami.Units.gridUnit
property Item target
property bool selectionStartHandle: false
visible: Kirigami.Settings.tabletMode && ((target.activeFocus && !selectionStartHandle) || target.selectedText.length > 0)
Rectangle {
width: Math.round(Kirigami.Units.devicePixelRatio * 3)
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
bottom: parent.bottom
}
color: Qt.tint(Kirigami.Theme.highlightColor, Qt.rgba(1,1,1,0.4))
radius: width
Rectangle {
width: Math.round(Kirigami.Units.gridUnit/1.5)
height: width
visible: MobileTextActionsToolBar.shouldBeVisible
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.bottom
}
radius: width
color: Qt.tint(Kirigami.Theme.highlightColor, Qt.rgba(1,1,1,0.4))
}
MouseArea {
anchors {
fill: parent
margins: -Kirigami.Units.gridUnit
}
preventStealing: true
onPositionChanged: {
var pos = mapToItem(target, mouse.x, mouse.y);
pos = target.positionAt(pos.x, pos.y);
if (target.selectedText.length > 0) {
if (selectionStartHandle) {
target.select(Math.min(pos, target.selectionEnd - 1), target.selectionEnd);
} else {
target.select(target.selectionStart, Math.max(pos, target.selectionStart + 1));
}
} else {
target.cursorPosition = pos;
}
}
}
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2018 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
pragma Singleton
import QtQuick 2.1
import QtQuick.Layouts 1.2
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import org.kde.kirigami 2.5 as Kirigami
Popup {
id: root
property Item controlRoot
parent: controlRoot ? controlRoot.Window.contentItem : undefined
modal: false
focus: false
closePolicy: Popup.NoAutoClose
property bool shouldBeVisible: false
x: {
if (!controlRoot || !controlRoot.Window.contentItem) {
return 0;
}
return Math.min(Math.max(0, controlRoot.mapToItem(root.parent, controlRoot.positionToRectangle(controlRoot.selectionStart).x, 0).x - root.width/2), controlRoot.Window.contentItem.width - root.width);
}
y: {
if (!controlRoot || !controlRoot.Window.contentItem) {
return 0;
}
var desiredY = controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionStart).y).y - root.height;
if (desiredY >= 0) {
return Math.min(desiredY, controlRoot.Window.contentItem.height - root.height);
} else {
return Math.min(Math.max(0, controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionEnd).y + Math.round(Kirigami.Units.gridUnit*1.5)).y), controlRoot.Window.contentItem.height - root.height);
}
}
visible: controlRoot ? shouldBeVisible && Kirigami.Settings.tabletMode && (controlRoot.selectedText.length > 0 || controlRoot.canPaste) : false
width: contentItem.implicitWidth + leftPadding + rightPadding
contentItem: RowLayout {
ToolButton {
focusPolicy: Qt.NoFocus
icon.name: "edit-cut"
visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal)
onClicked: {
controlRoot.cut();
}
}
ToolButton {
focusPolicy: Qt.NoFocus
icon.name: "edit-copy"
visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal)
onClicked: {
controlRoot.copy();
}
}
ToolButton {
focusPolicy: Qt.NoFocus
icon.name: "edit-paste"
visible: controlRoot && controlRoot.canPaste
onClicked: {
controlRoot.paste();
}
}
}
}

View File

@ -0,0 +1,5 @@
singleton MobileTextActionsToolBar 1.0 MobileTextActionsToolBar.qml
DefaultListItemBackground 1.0 DefaultListItemBackground.qml
MobileCursor 1.0 MobileCursor.qml
FocusRect 1.0 FocusRect.qml

View File

@ -0,0 +1,105 @@
#include "KyIcon.h"
#include <QStyleOption>
#include <QStyle>
#include <QPainter>
#include <QApplication>
#include "highlight-effect.h"
#include <QGSettings/QGSettings>
QStyle *KyIcon::style()
{
return qApp->style();
}
KyIcon::KyIcon(QQuickPaintedItem *parent)
: QQuickPaintedItem(parent),
m_hover(false),
m_selected(false),
m_focus(false),
m_active(true),
m_sunken(false),
m_on(false),
m_icontype("default")
{
if (QGSettings::isSchemaInstalled("org.ukui.style")) {
QGSettings* styleSettings = new QGSettings("org.ukui.style", QByteArray(), this);
connect(styleSettings, &QGSettings::changed, this, [&](){
emit hoverChanged();
emit selectedChanged();
emit hasFocusChanged();
emit activeChanged();
emit sunkenChanged();
emit onChanged();
emit icontypeChanged();
update();
});
}
connect(this, &KyIcon::hoverChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::selectedChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::hasFocusChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::activeChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::sunkenChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::onChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::icontypeChanged, this, &KyIcon::updateItem);
}
void KyIcon::setIcon(const QIcon &icon)
{
m_icon = icon;
}
void KyIcon::setIconName(const QString &iconName)
{
if(!QIcon::hasThemeIcon(iconName))
{
m_icon = QIcon();
qWarning() << "未找到名为 " << iconName << " 的图标!";
return;
}
m_icon = QIcon::fromTheme(iconName);
}
void KyIcon::paint(QPainter *painter)
{
if(m_icon.isNull())
return;
QWidget wid;
QStyleOption opt;
opt.state = {};
if (isEnabled()) {
opt.state |= QStyle::State_Enabled;
}
if (m_hover)
opt.state |= QStyle::State_MouseOver;
if (m_selected)
opt.state |= QStyle::State_Selected;
if (m_focus)
opt.state |= QStyle::State_HasFocus;
if (m_active)
opt.state |= QStyle::State_Active;
if (m_sunken)
opt.state |= QStyle::State_Sunken;
if (m_on)
opt.state |= QStyle::State_On;
QPixmap pixmap = m_icon.pixmap(QSize(width(), height()));
if (m_icontype == "ordinary") {
pixmap = HighLightEffect::ordinaryGeneratePixmap(pixmap, &opt, &wid); /* 主题切换做处理*/
}
if (m_icontype == "hover") {
pixmap = HighLightEffect::hoverGeneratePixmap(pixmap, &opt, &wid); /* 选中点击做处理*/
}
if (m_icontype == "filledSymbolicColor") {
pixmap = HighLightEffect::filledSymbolicColoredGeneratePixmap(pixmap, &opt, &wid); /* 非纯色图标主题切换且选中点击做处理*/
}
else if (m_icontype == "default") {
pixmap = HighLightEffect::bothOrdinaryAndHoverGeneratePixmap(pixmap, &opt, &wid); /* 主题切换且选中点击做处理*/
}
KyIcon::style()->drawItemPixmap(painter, boundingRect().toRect(), Qt::AlignCenter,pixmap);
}

View File

@ -0,0 +1,90 @@
#ifndef KYICON_H
#define KYICON_H
#include <QQuickPaintedItem>
#include <QIcon>
#include <QStyle>
#include <QPointer>
class QStyle;
class KyIcon : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QString iconName WRITE setIconName)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged)
Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
Q_PROPERTY( bool hasFocus READ hasFocus WRITE sethasFocus NOTIFY hasFocusChanged)
Q_PROPERTY( bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY( bool sunken READ sunken WRITE setSunken NOTIFY sunkenChanged)
Q_PROPERTY( bool on READ on WRITE setOn NOTIFY onChanged)
Q_PROPERTY( QString icontype READ icontype WRITE seticontype NOTIFY icontypeChanged)
public:
KyIcon(QQuickPaintedItem *parent = nullptr);
QIcon icon() { return m_icon; }
void setIcon(const QIcon &icon);
void setIconName(const QString &iconName);
bool hover() const { return m_hover; }
void setHover(bool hover) { if (m_hover != hover) {m_hover = hover ; emit hoverChanged();}}
bool selected() const { return m_selected; }
void setSelected(bool selected) {
if (m_selected!= selected) {
m_selected = selected;
emit selectedChanged();
}
}
bool hasFocus() const { return m_focus; }
void sethasFocus(bool focus) { if (m_focus != focus) {m_focus = focus; emit hasFocusChanged();}}
bool active() const { return m_active; }
void setActive(bool active) { if (m_active!= active) {m_active = active; emit activeChanged();}}
bool sunken() const { return m_sunken; }
void setSunken(bool sunken) { if (m_sunken != sunken) {m_sunken = sunken; emit sunkenChanged();}}
bool on() const { return m_on; }
void setOn(bool on) { if (m_on != on) {m_on = on ; emit onChanged();}}
QString icontype() const { return m_icontype;}
void seticontype(QString icontype) {
m_icontype = icontype ;
emit icontypeChanged();
}
void paint(QPainter *painter);
static QStyle *style();
public Q_SLOTS:
void updateItem(){update();}
Q_SIGNALS:
void hoverChanged();
void selectedChanged();
void hasFocusChanged();
void activeChanged();
void sunkenChanged();
void onChanged();
void icontypeChanged();
protected:
bool m_hover;
bool m_selected;
bool m_focus;
bool m_active;
bool m_sunken;
bool m_on;
QString m_icontype;
private:
QIcon m_icon;
};
#endif // KYICON_H

View File

@ -0,0 +1,47 @@
#ifndef KYQUICKPADDING_P_H
#define KYQUICKPADDING_P_H
#include <qobject.h>
class KyQuickPadding : public QObject
{
Q_OBJECT
Q_PROPERTY(int left READ left WRITE setLeft NOTIFY leftChanged)
Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged)
Q_PROPERTY(int right READ right WRITE setRight NOTIFY rightChanged)
Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
int m_left;
int m_top;
int m_right;
int m_bottom;
public:
KyQuickPadding(QObject *parent = nullptr) :
QObject(parent),
m_left(0),
m_top(0),
m_right(0),
m_bottom(0) {}
int left() const { return m_left; }
int top() const { return m_top; }
int right() const { return m_right; }
int bottom() const { return m_bottom; }
public Q_SLOTS:
void setLeft(int arg) { if (m_left != arg) {m_left = arg; emit leftChanged();}}
void setTop(int arg) { if (m_top != arg) {m_top = arg; emit topChanged();}}
void setRight(int arg) { if (m_right != arg) {m_right = arg; emit rightChanged();}}
void setBottom(int arg) {if (m_bottom != arg) {m_bottom = arg; emit bottomChanged();}}
Q_SIGNALS:
void leftChanged();
void topChanged();
void rightChanged();
void bottomChanged();
};
#endif // KYQUICKPADDING_P_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,298 @@
#ifndef KYQUICKSTYLEITEM_H
#define KYQUICKSTYLEITEM_H
#include "kyquickpadding_p.h"
#include <PlatformTheme>
#include <QQuickItem>
#include <QQuickImageProvider>
#include <QPixmap>
#include <QPointer>
#include <QImage>
class QStyle;
class QStyleOption;
class QQuickTableRowImageProvider1 : public QQuickImageProvider
{
public:
QQuickTableRowImageProvider1()
: QQuickImageProvider(QQuickImageProvider::Pixmap) {}
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;
};
class KyQuickStyleItem: public QQuickItem
{
Q_OBJECT
Q_PROPERTY(KyQuickPadding* border READ border CONSTANT)
Q_PROPERTY( bool sunken READ sunken WRITE setSunken NOTIFY sunkenChanged)
Q_PROPERTY( bool raised READ raised WRITE setRaised NOTIFY raisedChanged)
Q_PROPERTY( bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
Q_PROPERTY( bool hasFocus READ hasFocus WRITE sethasFocus NOTIFY hasFocusChanged)
Q_PROPERTY( bool on READ on WRITE setOn NOTIFY onChanged)
Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged)
Q_PROPERTY( bool horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged)
Q_PROPERTY( bool isTransient READ isTransient WRITE setTransient NOTIFY transientChanged)
Q_PROPERTY( QString elementType READ elementType WRITE setElementType NOTIFY elementTypeChanged)
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY( QString activeControl READ activeControl WRITE setActiveControl NOTIFY activeControlChanged)
Q_PROPERTY( QString styleName READ styleName NOTIFY styleNameChanged)
Q_PROPERTY( QVariantMap hints READ hints WRITE setHints NOTIFY hintChanged RESET resetHints)
Q_PROPERTY( QVariantMap properties READ properties WRITE setProperties NOTIFY propertiesChanged)
Q_PROPERTY( QFont font READ font NOTIFY fontChanged)
// For range controls
Q_PROPERTY( int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
Q_PROPERTY( int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
Q_PROPERTY( int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY( int step READ step WRITE setStep NOTIFY stepChanged)
Q_PROPERTY( int paintMargins READ paintMargins WRITE setPaintMargins NOTIFY paintMarginsChanged)
Q_PROPERTY( int contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
Q_PROPERTY( int contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
Q_PROPERTY( int textureWidth READ textureWidth WRITE setTextureWidth NOTIFY textureWidthChanged)
Q_PROPERTY( int textureHeight READ textureHeight WRITE setTextureHeight NOTIFY textureHeightChanged)
Q_PROPERTY( int leftPadding READ leftPadding NOTIFY leftPaddingChanged)
Q_PROPERTY( int topPadding READ topPadding NOTIFY topPaddingChanged)
Q_PROPERTY( int rightPadding READ rightPadding NOTIFY rightPaddingChanged)
Q_PROPERTY( int bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged)
Q_PROPERTY( QQuickItem *control READ control WRITE setControl NOTIFY controlChanged)
KyQuickPadding* border() { return &m_border; }
public:
KyQuickStyleItem(QQuickItem *parent = nullptr);
~KyQuickStyleItem() override;
enum MenuItemType {
SeparatorType = 0,
ItemType,
MenuType,
ScrollIndicatorType
};
enum Type {
Undefined,
Button,
RadioButton,
CheckBox,
ComboBox,
ComboBoxItem,
Dial,
ToolBar,
ToolButton,
Tab,
TabFrame,
Frame,
FocusFrame,
FocusRect,
SpinBox,
Slider,
ScrollBar,
ProgressBar,
Edit,
GroupBox,
Header,
Item,
ItemRow,
ItemBranchIndicator,
Splitter,
Menu,
MenuItem,
Widget,
StatusBar,
ScrollAreaCorner,
MacHelpButton,
MenuBar,
MenuBarItem
};
void paint(QPainter *);
bool sunken() const { return m_sunken; }
bool raised() const { return m_raised; }
bool active() const { return m_active; }
bool selected() const { return m_selected; }
bool hasFocus() const { return m_focus; }
bool on() const { return m_on; }
bool hover() const { return m_hover; }
bool horizontal() const { return m_horizontal; }
bool isTransient() const { return m_transient; }
int minimum() const { return m_minimum; }
int maximum() const { return m_maximum; }
int step() const { return m_step; }
int value() const { return m_value; }
int paintMargins() const { return m_paintMargins; }
QString elementType() const { return m_type; }
QString text() const { return m_text; }
QString activeControl() const { return m_activeControl; }
QVariantMap hints() const { return m_hints; }
QVariantMap properties() const { return m_properties; }
QFont font() const { return m_font;}
QString styleName() const;
void setSunken(bool sunken) { if (m_sunken != sunken) {m_sunken = sunken; emit sunkenChanged();}}
void setRaised(bool raised) { if (m_raised!= raised) {m_raised = raised; emit raisedChanged();}}
void setActive(bool active) { if (m_active!= active) {m_active = active; emit activeChanged();}}
void setSelected(bool selected) { if (m_selected!= selected) {m_selected = selected; emit selectedChanged();}}
void sethasFocus(bool focus) { if (m_focus != focus) {m_focus = focus; emit hasFocusChanged();}}
void setOn(bool on) { if (m_on != on) {m_on = on ; emit onChanged();}}
void setHover(bool hover) { if (m_hover != hover) {m_hover = hover ; emit hoverChanged();}}
void setHorizontal(bool horizontal) { if (m_horizontal != horizontal) {m_horizontal = horizontal; emit horizontalChanged();}}
void setTransient(bool transient) { if (m_transient != transient) {m_transient = transient; emit transientChanged();}}
void setMinimum(int minimum) { if (m_minimum!= minimum) {m_minimum = minimum; emit minimumChanged();}}
void setMaximum(int maximum) { if (m_maximum != maximum) {m_maximum = maximum; emit maximumChanged();}}
void setValue(int value) { if (m_value!= value) {m_value = value; emit valueChanged();}}
void setStep(int step) { if (m_step != step) { m_step = step; emit stepChanged(); }}
void setPaintMargins(int value) { if (m_paintMargins!= value) {m_paintMargins = value; emit paintMarginsChanged(); } }
void setElementType(const QString &str);
void setText(const QString &str) { if (m_text != str) {m_text = str; emit textChanged();}}
void setActiveControl(const QString &str) { if (m_activeControl != str) {m_activeControl = str; emit activeControlChanged();}}
void setHints(const QVariantMap &str);
void setProperties(const QVariantMap &props) { if (m_properties != props) { m_properties = props; emit propertiesChanged(); } }
void resetHints();
int contentWidth() const { return m_contentWidth; }
void setContentWidth(int arg);
int contentHeight() const { return m_contentHeight; }
void setContentHeight(int arg);
virtual void initStyleOption ();
void resolvePalette();
int leftPadding() const;
int topPadding() const;
int rightPadding() const;
int bottomPadding() const;
Q_INVOKABLE qreal textWidth(const QString &);
Q_INVOKABLE qreal textHeight(const QString &);
int textureWidth() const { return m_textureWidth; }
void setTextureWidth(int w);
int textureHeight() const { return m_textureHeight; }
void setTextureHeight(int h);
QQuickItem *control() const;
void setControl(QQuickItem *control);
static QStyle *style();
public Q_SLOTS:
int pixelMetric(const QString&);
QVariant styleHint(const QString&);
void updateSizeHint();
void updateRect();
void updateBaselineOffset();
void updateItem(){polish();}
QString hitTest(int x, int y);
QRectF subControlRect(const QString &subcontrolString);
QString elidedText(const QString &text, int elideMode, int width);
bool hasThemeIcon(const QString &) const;
Q_SIGNALS:
void elementTypeChanged();
void textChanged();
void sunkenChanged();
void raisedChanged();
void activeChanged();
void selectedChanged();
void hasFocusChanged();
void onChanged();
void hoverChanged();
void horizontalChanged();
void transientChanged();
void minimumChanged();
void maximumChanged();
void stepChanged();
void valueChanged();
void activeControlChanged();
void infoChanged();
void styleNameChanged();
void paintMarginsChanged();
void hintChanged();
void propertiesChanged();
void fontChanged();
void controlChanged();
void contentWidthChanged(int arg);
void contentHeightChanged(int arg);
void textureWidthChanged(int w);
void textureHeightChanged(int h);
void leftPaddingChanged();
void topPaddingChanged();
void rightPaddingChanged();
void bottomPaddingChanged();
protected:
bool event(QEvent *) override;
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
void updatePolish() override;
bool eventFilter(QObject *watched, QEvent *event) override;
private:
const char* classNameForItem() const;
QSize sizeFromContents(int width, int height);
qreal baselineOffset();
void styleChanged();
protected:
QStyleOption *m_styleoption;
QPointer<QQuickItem> m_control;
QPointer<QWindow> m_window;
Type m_itemType;
QString m_type;
QString m_text;
QString m_activeControl;
QVariantMap m_hints;
QVariantMap m_properties;
QFont m_font;
bool m_sunken;
bool m_raised;
bool m_active;
bool m_selected;
bool m_focus;
bool m_hover;
bool m_on;
bool m_horizontal;
bool m_transient;
bool m_sharedWidget;
int m_minimum;
int m_maximum;
int m_value;
int m_step;
int m_paintMargins;
int m_contentWidth;
int m_contentHeight;
int m_textureWidth;
int m_textureHeight;
Qt::FocusReason m_lastFocusReason;
QImage m_image;
KyQuickPadding m_border;
static QStyle *s_style;
};
#endif // KYQUICKSTYLEITEM_H

View File

@ -0,0 +1,31 @@
#include "kystylehelper.h"
#include <QQuickWindow>
#include <QGSettings/QGSettings>
#include <QWidget>
KyStyleHelper::KyStyleHelper(QQuickItem *parent)
: QQuickItem(parent)
{
if (QGSettings::isSchemaInstalled("org.ukui.style")) {
QGSettings* styleSettings = new QGSettings("org.ukui.style", QByteArray(), this);
connect(styleSettings, &QGSettings::changed, this, [&](const QString &key){
if (key == "styleName") {
emit paletteChanged();
emit qcolorChanged();
}
if (key == "systemFontSize" || key == "systemFont") {
emit fontChanged();
}
});
}
}
KyStyleHelper::~KyStyleHelper() {}
KyStyleHelper* KyStyleHelper::qmlAttachedProperties(QObject *parent)
{
auto p = qobject_cast<QQuickItem*>(parent);
return new KyStyleHelper(p);
}

View File

@ -0,0 +1,116 @@
#ifndef KYSTYLEHELPER_H
#define KYSTYLEHELPER_H
#include <QApplication>
#include <QQuickItem>
#include <QPalette>
#include <QColor>
class KyStyleHelper : public QQuickItem
{
Q_OBJECT
Q_DISABLE_COPY(KyStyleHelper)
Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
Q_PROPERTY(QFont font READ font NOTIFY fontChanged)
Q_PROPERTY(QColor buttoncolorrole READ buttoncolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor windowcolorrole READ windowcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor darkcolorrole READ darkcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor windowtextcolorrole READ windowtextcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor basecolorrole READ basecolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor textcolorrole READ textcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor buttontextcolorrole READ buttontextcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor highlightcolorrole READ highlightcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor highlightedtextcolorrole READ highlightedtextcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor tooltipbasecolorrole READ tooltipbasecolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor tooltiptextcolorrole READ tooltiptextcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor lightcolorrole READ lightcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor midlightcolorrole READ midlightcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor midcolorrole READ midcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor shadowcolorrole READ shadowcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor alternatebasecolorrole READ alternatebasecolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor linkcolorrole READ linkcolor NOTIFY qcolorChanged)
Q_PROPERTY(QColor linkvisitedcolorrole READ linkvisitedcolor NOTIFY qcolorChanged)
public:
explicit KyStyleHelper(QQuickItem *parent = nullptr);
~KyStyleHelper() override;
static KyStyleHelper* qmlAttachedProperties(QObject* parent);
/* Get palette */
QPalette palette() {
return qApp->palette();
}
/* Get font */
QFont font() {
return qApp->font();
}
/* Get different type of color */
QColor buttoncolor() {
return qApp->palette().button().color();
}
QColor windowcolor() {
return qApp->palette().window().color();
}
QColor darkcolor() {
return qApp->palette().dark().color();
}
QColor windowtextcolor() {
return qApp->palette().windowText().color();
}
QColor basecolor() {
return qApp->palette().base().color();
}
QColor textcolor() {
return qApp->palette().text().color();
}
QColor buttontextcolor() {
return qApp->palette().buttonText().color();
}
QColor highlightcolor() {
return qApp->palette().highlight().color();
}
QColor highlightedtextcolor() {
return qApp->palette().highlightedText().color();
}
QColor tooltipbasecolor() {
return qApp->palette().toolTipBase().color();
}
QColor tooltiptextcolor() {
return qApp->palette().toolTipText().color();
}
QColor lightcolor() {
return qApp->palette().light().color();
}
QColor midlightcolor() {
return qApp->palette().midlight().color();
}
QColor midcolor() {
return qApp->palette().mid().color();
}
QColor shadowcolor() {
return qApp->palette().shadow().color();
}
QColor alternatebasecolor() {
return qApp->palette().alternateBase().color();
}
QColor linkcolor() {
return qApp->palette().link().color();
}
QColor linkvisitedcolor() {
return qApp->palette().linkVisited().color();
}
signals:
void paletteChanged();
void fontChanged();
void qcolorChanged();
};
QML_DECLARE_TYPEINFO(KyStyleHelper, QML_HAS_ATTACHED_PROPERTIES)
#endif // KYSTYLEHELPER_H

View File

@ -0,0 +1,2 @@
module org.kylin.qqc2style.private
plugin qqc2-style-plugin

View File

@ -0,0 +1,47 @@
TEMPLATE = lib
TARGET = qqc2-style-plugin
QT += KConfigCore Kirigami2 quick
CONFIG += plugin c++11 link_pkgconfig
TARGET = $$qtLibraryTarget($$TARGET)
uri = org.kylin.qqc2style.private
PKGCONFIG += gsettings-qt
INCLUDEPATH += /usr/include/KF5/Kirigami2
LIBS += -L/usr/lib -L$$[QT_INSTALL_LIBS] -lKF5Kirigami2
include(../../libqt5-ukui-style/effects/effects.pri)
# Input
SOURCES += \
KyIcon.cpp \
kyquickstyleitem.cpp \
kystylehelper.cpp \
qqc2styleplugin.cpp
HEADERS += \
KyIcon.h \
kyquickpadding_p.h \
kyquickstyleitem.h \
kystylehelper.h \
qqc2styleplugin.h
DISTFILES = qmldir
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
qmldir.files = qmldir
unix {
# installPath = $$[QT_INSTALL_QML]/$$replace(uri, \., /)
installPath = $$[QT_INSTALL_LIBS]/qt5/qml/org/kylin/qqc2style/private/
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}

View File

@ -0,0 +1,13 @@
#include "qqc2styleplugin.h"
#include "kyquickstyleitem.h"
#include "kystylehelper.h"
#include "KyIcon.h"
void Qqc2StylePlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kylin.qqc2style.private"));
// @uri org.kylin.qqc2style.private
qmlRegisterType<KyQuickStyleItem>(uri, 1, 0, "StyleItem");
qmlRegisterType<KyStyleHelper>(uri, 1, 0, "StyleHelper");
qmlRegisterType<KyIcon>(uri, 1, 0, "KyIcon");
}

View File

@ -0,0 +1,15 @@
#ifndef QQC2STYLEPLUGIN_H
#define QQC2STYLEPLUGIN_H
#include <QQmlExtensionPlugin>
class Qqc2StylePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};
#endif // QQC2STYLEPLUGIN_H

View File

@ -159,11 +159,11 @@ const QColor HighLightEffect::getCurrentSymbolicColor()
const QColor HighLightEffect::defaultStyleDark(const QStyleOption *option)
{
auto windowText = qApp->palette().windowText().color();
auto windowText = qApp->palette().color(QPalette::Active, QPalette::WindowText);
qreal h, s, v;
if (option) {
windowText = option->palette.windowText().color();
windowText = option->palette.color(QPalette::Active, QPalette::WindowText);
}
windowText.getHsvF(&h, &s, &v);

View File

@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS += \
kylin-qqc2-style \
qt5-ukui-platformtheme \
ukui-styles \
libqt5-ukui-style \