Skip to content

Commit 64a1d3a

Browse files
committed
Checkbox and CheckboxLabel and PrefsButton Added
1 parent 8a8c437 commit 64a1d3a

9 files changed

+253
-6
lines changed

Settings/GeneralSettingsPage.qml

+22
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,27 @@ ScreenPage{
1515
PrefsComboBoxLabel{
1616
model: SideListModel{}//["Adesh","Kabir","Raj","Adesh","Kabir","Raj","Adesh","Kabir","Raj"]
1717
}
18+
PrefsCheckbox{
19+
20+
}
21+
PrefsCheckboxLable{
22+
description: qsTr("Example APP demonstrating Qt Quick Controls 2 %1").arg("<a href='https://www.example.com'>Click me!</a>")
23+
}
24+
PrefsButton
25+
{
26+
width: innerText.width + 40
27+
height: 38
28+
buttonText: "Send Diagnostics";
29+
innerText.color: "#4169E1"
30+
color: "transparent"
31+
hoverColor: "#A7C7E7"
32+
pressColor: "#A7C7E7"
33+
borderColor: "#4169E1"
34+
fontSize: 12
35+
borderWidth: 1
36+
borderRadius: 8
37+
onClicked: {
38+
}
39+
}
1840
}
1941
}

Settings/SideListDelegate.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ItemDelegate {
4949
font.weight: Font.Medium
5050
verticalAlignment: Image.AlignVCenter
5151
Layout.alignment: Qt.AlignVCenter
52-
color: root.highlighted || root.hovered ? "white" : Qt.darkGray
52+
color: root.highlighted || root.hovered ? "white" : "dark"
5353
}
5454
}
5555
}

common/LabelSubheading.qml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ekke (Ekkehard Gentz) @ekkescorner
21
import QtQuick 2.9
32
import QtQuick.Layouts 1.3
43
import QtQuick.Controls 2.2

common/PrefsButton.qml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//Import the declarative plugins
2+
import QtQuick 2.0
3+
import QtQuick.Layouts 1.3
4+
import QtQuick.Controls 2.5
5+
//Implementation of the Button control.
6+
Item {
7+
id: button
8+
width:innerText.width + 40
9+
height: 30
10+
property alias buttonText: innerText.text;
11+
property alias innerText: innerText
12+
property alias buttonText2: innerText2.text;
13+
property alias innerText2: innerText2
14+
property color color: "transparent"
15+
property color hoverColor: "#aaaaaa"
16+
property color pressColor: "slategray"
17+
property color borderColor: "white"
18+
property string sourceIcon: ""
19+
property int fontSize: 16
20+
property int borderWidth: 1
21+
property int borderRadius: 2
22+
property int iconWidth: 20
23+
property int iconHeight: 20
24+
scale: state === "Pressed" ? 0.95 : 1.0
25+
onEnabledChanged: state = ""
26+
property bool iconButton: false
27+
signal clicked
28+
29+
//define a scale animation
30+
Behavior on scale {
31+
NumberAnimation {
32+
duration: 100
33+
easing.type: Easing.InOutQuad
34+
}
35+
}
36+
37+
//Rectangle to draw the button
38+
Rectangle {
39+
id: rectangleButton
40+
anchors.fill: parent
41+
radius: borderRadius
42+
color: button.enabled ? button.color : "grey"
43+
border.width: borderWidth
44+
border.color:borderColor
45+
visible: !iconButton
46+
opacity: 0.8
47+
Image{
48+
visible: sourceIcon
49+
source: sourceIcon
50+
sourceSize: Qt.size(iconWidth,iconHeight)
51+
anchors.centerIn: parent
52+
clip: true
53+
smooth: true
54+
opacity: 0.54
55+
}
56+
57+
Label {
58+
id: innerText
59+
font.pointSize: fontSize
60+
anchors.centerIn: parent
61+
visible: text
62+
}
63+
}
64+
Rectangle {
65+
id: rectangleButton2
66+
anchors.fill: parent
67+
radius: borderRadius
68+
color: button.enabled ? button.color : "grey"
69+
border.width: borderWidth
70+
border.color:borderColor
71+
visible: iconButton
72+
ColumnLayout{
73+
Layout.fillWidth: true
74+
Layout.fillHeight: true
75+
anchors.centerIn: parent
76+
Image{
77+
source:sourceIcon
78+
sourceSize: Qt.size(iconWidth,iconHeight)
79+
clip: true
80+
smooth: true
81+
opacity: 0.54
82+
Layout.alignment: Qt.AlignHCenter
83+
}
84+
85+
Text {
86+
id: innerText2
87+
font.pointSize: fontSize
88+
visible: text
89+
Layout.alignment: Qt.AlignHCenter
90+
}
91+
}
92+
}
93+
94+
//change the color of the button in differen button states
95+
states: [
96+
State {
97+
name: "Hovering"
98+
PropertyChanges {
99+
target:iconButton ? rectangleButton2 : rectangleButton
100+
color: hoverColor
101+
}
102+
},
103+
State {
104+
name: "Pressed"
105+
PropertyChanges {
106+
target: iconButton ? rectangleButton2 : rectangleButton
107+
color: pressColor
108+
}
109+
}
110+
]
111+
112+
//define transmission for the states
113+
transitions: [
114+
Transition {
115+
from: ""; to: "Hovering"
116+
ColorAnimation { duration: 200 }
117+
},
118+
Transition {
119+
from: "*"; to: "Pressed"
120+
ColorAnimation { duration: 10 }
121+
}
122+
]
123+
124+
//Mouse area to react on click events
125+
MouseArea {
126+
hoverEnabled: true
127+
anchors.fill: button
128+
onEntered: { button.state='Hovering'}
129+
onExited: { button.state=''}
130+
onClicked: { button.clicked();}
131+
onPressed: { button.state="Pressed" }
132+
onReleased: {
133+
if (containsMouse)
134+
button.state="Hovering";
135+
else
136+
button.state="";
137+
}
138+
}
139+
}

common/PrefsCheckbox.qml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import QtQuick 2.12
2+
import QtQuick.Controls 2.12
3+
4+
CheckBox {
5+
id: control
6+
text: qsTr("Format Secure Notes Using Markdown")
7+
checked: true
8+
font.pointSize: 12
9+
spacing: 15
10+
indicator: Rectangle {
11+
implicitWidth: 22
12+
implicitHeight: 22
13+
x: control.leftPadding
14+
y: parent.height / 2 - height / 2
15+
radius: 5
16+
color: control.checked ? "blue" : checkBoxHover.hovered ? "#dde4de" : "transparent"
17+
border.width: 1
18+
border.color: control.checked ? "blue" : "grey"
19+
HoverHandler{
20+
id:checkBoxHover
21+
}
22+
23+
Label{
24+
text: "+"
25+
color: "white"
26+
visible:control.checked
27+
font.pointSize: 10
28+
font.bold: true
29+
anchors.centerIn: parent
30+
bottomInset: 2
31+
}
32+
}
33+
}

common/PrefsCheckboxLable.qml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Layouts 1.3
4+
ColumnLayout{
5+
Layout.fillWidth: true
6+
property string description: qsTr("Example APP demonstrating Qt Quick Controls 2")
7+
spacing: 5
8+
CheckBox {
9+
id: control
10+
text: qsTr("Format Secure Notes Using Markdown")
11+
checked: true
12+
font.pointSize: 12
13+
spacing: 15
14+
indicator: Rectangle {
15+
implicitWidth: 22
16+
implicitHeight: 22
17+
x: control.leftPadding
18+
y: parent.height / 2 - height / 2
19+
radius: 5
20+
color: control.checked ? "blue" : checkBoxHover.hovered ? "#dde4de" : "transparent"
21+
border.width: 1
22+
border.color: control.checked ? "blue" : "grey"
23+
HoverHandler{
24+
id:checkBoxHover
25+
}
26+
27+
Label{
28+
text: "+"
29+
color: "white"
30+
visible:control.checked
31+
font.pointSize: 10
32+
font.bold: true
33+
anchors.centerIn: parent
34+
bottomInset: 2
35+
}
36+
}
37+
}
38+
39+
LabelSubheading {
40+
width: root.width
41+
leftPadding: control.spacing + 22 + spacing
42+
rightPadding: 10
43+
wrapMode: Text.WordWrap
44+
font.pointSize: control.font.pointSize - 1
45+
text:description
46+
// Open the link in a browser when clicked
47+
onLinkActivated: {
48+
Qt.openUrlExternally(link)
49+
}
50+
}
51+
}

common/PrefsComboBox.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ComboBox {
5555
font.weight: Font.Medium
5656
verticalAlignment: Image.AlignVCenter
5757
Layout.alignment: Qt.AlignVCenter
58-
color: itemDelegate.hovered ? "white" : Qt.darkGray
58+
color: itemDelegate.hovered ? "white" : "dark"
5959
Layout.leftMargin: iconImageRect.visible ? 0 : 10
6060
}
6161

@@ -133,7 +133,7 @@ ComboBox {
133133
font.weight: Font.Medium
134134
verticalAlignment: Image.AlignVCenter
135135
Layout.alignment: Qt.AlignVCenter
136-
color: Qt.darkGray
136+
color: "black"
137137
elide: Text.ElideRight
138138
Layout.leftMargin:iconRect.visible ? 0 : 10
139139
}

common/PrefsComboBoxLabel.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ComboBox {
3737
font.weight: Font.Medium
3838
verticalAlignment: Image.AlignVCenter
3939
Layout.alignment: Qt.AlignVCenter
40-
color: itemDelegate.hovered ? "white" : Qt.darkGray
40+
color: itemDelegate.hovered ? "white" : "dark"
4141
Layout.leftMargin: 10
4242
}
4343

@@ -98,7 +98,7 @@ ComboBox {
9898
font.weight: Font.Medium
9999
verticalAlignment: Image.AlignVCenter
100100
Layout.alignment: Qt.AlignVCenter
101-
color: Qt.darkGray
101+
color: "black"
102102
elide: Text.ElideRight
103103
Layout.leftMargin: 10
104104
}

qml.qrc

+3
Original file line numberDiff line numberDiff line change
@@ -596,5 +596,8 @@
596596
<file>Settings/GeneralSettingsPage.qml</file>
597597
<file>common/PrefsComboBox.qml</file>
598598
<file>common/PrefsComboBoxLabel.qml</file>
599+
<file>common/PrefsCheckbox.qml</file>
600+
<file>common/PrefsCheckboxLable.qml</file>
601+
<file>common/PrefsButton.qml</file>
599602
</qresource>
600603
</RCC>

0 commit comments

Comments
 (0)