-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
308 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import QtQuick | ||
|
||
Rectangle { | ||
id: root | ||
|
||
width: 200 | ||
height: 100 | ||
|
||
property color borderColor: "#505008" | ||
property color powerColor: "#41cd52" | ||
property color alarmColor: "#fa7671" | ||
property int alarmValue: 20 | ||
property int value: 0 | ||
|
||
Rectangle { | ||
id: batteryRect | ||
|
||
x: 10 | ||
y: 10 | ||
width: root.width - x * 3 | ||
height: root.height - y * 2 | ||
border.color: root.borderColor | ||
border.width: 2 | ||
radius: 5 | ||
|
||
Rectangle { | ||
x: batteryRect.border.width * 2 | ||
y: batteryRect.border.width * 2 | ||
width: (batteryRect.width - x * 2) * (value / 100) | ||
height: batteryRect.height - y * 2 | ||
color: value > root.alarmValue ? root.powerColor : root.alarmColor | ||
radius: batteryRect.radius | ||
} | ||
|
||
Text { | ||
text: value.toString() + "%" | ||
font.pointSize: { | ||
var width = batteryRect.width / 5 | ||
return width > 0 ? width : 14 | ||
} | ||
color: value > root.alarmValue ? "black" : root.alarmColor | ||
anchors.centerIn: batteryRect | ||
} | ||
} | ||
|
||
Rectangle { | ||
width: 10 | ||
height: 20 | ||
color: root.borderColor | ||
x: batteryRect.x + batteryRect.width | ||
y: (root.height - height) / 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
QT += quick | ||
|
||
SOURCES += \ | ||
main.cc | ||
|
||
resources.files = Main.qml | ||
resources.prefix = /qml | ||
RESOURCES += resources | ||
|
||
# Additional import path used to resolve QML modules in Qt Creator's code model | ||
QML_IMPORT_PATH = | ||
|
||
# Additional import path used to resolve QML modules just for Qt Quick Designer | ||
QML_DESIGNER_IMPORT_PATH = | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
resources.files += \ | ||
Battery.qml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
qt_add_executable(BatteryQuick main.cc) | ||
|
||
qt_add_qml_module( | ||
BatteryQuick | ||
URI | ||
qml | ||
VERSION | ||
1.0 | ||
QML_FILES | ||
Main.qml | ||
Battery.qml) | ||
|
||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. If | ||
# you are developing for iOS or macOS you should consider setting an explicit, | ||
# fixed bundle identifier manually though. | ||
set_target_properties( | ||
BatteryQuick | ||
PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.BatteryQuick | ||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} | ||
MACOSX_BUNDLE_SHORT_VERSION_STRING | ||
${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} | ||
MACOSX_BUNDLE TRUE | ||
WIN32_EXECUTABLE TRUE) | ||
|
||
target_link_libraries(BatteryQuick PRIVATE Qt6::Quick) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import QtQuick | ||
import QtQuick.Layouts | ||
import QtQuick.Controls | ||
import QtQuick.Controls.Fusion | ||
|
||
Window { | ||
id: root | ||
|
||
width: 300 | ||
height: 160 | ||
visible: true | ||
title: qsTr("Battery") | ||
|
||
RowLayout { | ||
spacing: 10 | ||
anchors.fill: parent | ||
|
||
Battery { | ||
id: battery | ||
|
||
Layout.fillWidth: true | ||
Layout.fillHeight: true | ||
Layout.margins: 10 | ||
value: 20 | ||
} | ||
|
||
Slider { | ||
id: control | ||
|
||
Layout.fillWidth: true | ||
Layout.fillHeight: true | ||
Layout.margins: 10 | ||
orientation: Qt.Vertical | ||
focus: false | ||
from: 0 | ||
to: 100 | ||
value: battery.value | ||
|
||
onValueChanged: { | ||
// console.log("value: " + value) | ||
battery.value = value | ||
} | ||
|
||
background: Rectangle { | ||
x: control.leftPadding + control.availableWidth / 2 - width / 2 | ||
y: control.topPadding | ||
width: 4 | ||
height: control.availableHeight | ||
radius: 2 | ||
color: "#21be2b" | ||
|
||
Rectangle { | ||
width: parent.width | ||
height: control.visualPosition * parent.height | ||
color: "#bdbebf" | ||
radius: 2 | ||
} | ||
} | ||
|
||
handle: Rectangle { | ||
x: control.leftPadding + control.availableWidth / 2 - width / 2 | ||
y: control.topPadding + control.visualPosition * (control.availableHeight - height) | ||
implicitWidth: 26 | ||
implicitHeight: 26 | ||
radius: 13 | ||
color: control.pressed ? "#f0f0f0" : "#f6f6f6" | ||
border.color: "#bdbebf" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <QGuiApplication> | ||
#include <QQmlApplicationEngine> | ||
|
||
auto main(int argc, char *argv[]) -> int | ||
{ | ||
QGuiApplication app(argc, argv); | ||
|
||
QQmlApplicationEngine engine; | ||
const QUrl url(u"qrc:/qml/Main.qml"_qs); | ||
QObject::connect( | ||
&engine, | ||
&QQmlApplicationEngine::objectCreated, | ||
&app, | ||
[url](QObject *obj, const QUrl &objUrl) { | ||
if ((obj == nullptr) && url == objUrl) { | ||
QCoreApplication::exit(-1); | ||
} | ||
}, | ||
Qt::QueuedConnection); | ||
engine.load(url); | ||
|
||
return app.exec(); | ||
} |
Oops, something went wrong.