From 3a9dddb9c81dc30b74a0db3ebe9ce439165e9041 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 22 May 2020 21:50:13 +0800 Subject: [PATCH] Minor tweaks of the example project. Mainly add a build script. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/QQPlayer-demo/CMakeLists.txt | 8 +++++++- examples/QQPlayer-demo/build.bat | 12 ++++++++++++ examples/QQPlayer-demo/main.cpp | 2 +- examples/QQPlayer-demo/resources/qml/CloseButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/MainMenuButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/MaximizeButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/MinimizeButton.qml | 8 ++++---- examples/QQPlayer-demo/resources/qml/NextButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/OpenFileButton.qml | 8 ++++---- examples/QQPlayer-demo/resources/qml/PlayButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/PreviousButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/ProgressSlider.qml | 2 ++ examples/QQPlayer-demo/resources/qml/StopButton.qml | 8 ++++---- .../QQPlayer-demo/resources/qml/VolumeButton.qml | 8 ++++---- examples/QQPlayer-demo/resources/qml/main.qml | 6 ++++-- 15 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 examples/QQPlayer-demo/build.bat diff --git a/examples/QQPlayer-demo/CMakeLists.txt b/examples/QQPlayer-demo/CMakeLists.txt index a07add5..bd92edb 100644 --- a/examples/QQPlayer-demo/CMakeLists.txt +++ b/examples/QQPlayer-demo/CMakeLists.txt @@ -37,9 +37,15 @@ else() list(APPEND source_files ${qml_files}) endif() -add_executable(QQPlayer ${source_files}) +if(WIN32) + # Without WIN32, a console window will show. + add_executable(QQPlayer WIN32 ${source_files}) +else() + add_executable(QQPlayer ${source_files}) +endif() if(MSVC) + # Silence a compiler warning caused by the Chinese comments in the source file. target_compile_options(QQPlayer PRIVATE -utf-8) endif() target_compile_definitions(QQPlayer PRIVATE $<$,$>:QT_QML_DEBUG>) diff --git a/examples/QQPlayer-demo/build.bat b/examples/QQPlayer-demo/build.bat new file mode 100644 index 0000000..abed907 --- /dev/null +++ b/examples/QQPlayer-demo/build.bat @@ -0,0 +1,12 @@ +@echo off +call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 +call "%SystemDrive%\Qt\5.15.0\msvc2019_64\bin\qtenv2.bat" +cd /d "%~dp0" +if exist build rd /s /q build +md build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin -GNinja .. +cmake --build . +windeployqt --force --no-translations --no-system-d3d-compiler --no-virtualkeyboard --no-compiler-runtime --no-angle --no-opengl-sw --dir "%~dp0build\bin\qml" --libdir "%~dp0build\bin" --plugindir "%~dp0build\bin\plugins" --qmldir "%~dp0resources\qml" "%~dp0build\bin\QQPlayer.exe" +cd /d "%~dp0" +exit /b diff --git a/examples/QQPlayer-demo/main.cpp b/examples/QQPlayer-demo/main.cpp index 81eb459..5cec51f 100644 --- a/examples/QQPlayer-demo/main.cpp +++ b/examples/QQPlayer-demo/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) { QQmlApplicationEngine engine; qmlRegisterType("wangwenx190.Utils", 1, 0, "FramelessHelper"); - const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml")); + const QUrl mainQmlUrl(QString::fromUtf8("qrc:/qml/main.qml")); const QMetaObject::Connection connection = QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &application, [&mainQmlUrl, &connection](QObject *object, const QUrl &url) { diff --git a/examples/QQPlayer-demo/resources/qml/CloseButton.qml b/examples/QQPlayer-demo/resources/qml/CloseButton.qml index 65ebc04..a21a74e 100644 --- a/examples/QQPlayer-demo/resources/qml/CloseButton.qml +++ b/examples/QQPlayer-demo/resources/qml/CloseButton.qml @@ -2,7 +2,7 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 45 implicitHeight: 30 @@ -12,12 +12,12 @@ Button { ToolTip.text: qsTr("Close") contentItem: Image { - anchors.fill: parent + anchors.fill: control source: "qrc:/images/button_close_white.svg" } background: Rectangle { - visible: button.down || button.hovered - color: button.down ? "#8c0a15" : (button.hovered ? "#e81123" : "transparent") + visible: control.down || control.hovered + color: control.down ? "#8c0a15" : (control.hovered ? "#e81123" : "transparent") } } diff --git a/examples/QQPlayer-demo/resources/qml/MainMenuButton.qml b/examples/QQPlayer-demo/resources/qml/MainMenuButton.qml index a76358e..48a062d 100644 --- a/examples/QQPlayer-demo/resources/qml/MainMenuButton.qml +++ b/examples/QQPlayer-demo/resources/qml/MainMenuButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 75 implicitHeight: 15 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/main_menu_blue.png" : "qrc:/images/main_menu_white.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/main_menu_blue.png" : "qrc:/images/main_menu_white.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/MaximizeButton.qml b/examples/QQPlayer-demo/resources/qml/MaximizeButton.qml index 73aad03..41cbe0c 100644 --- a/examples/QQPlayer-demo/resources/qml/MaximizeButton.qml +++ b/examples/QQPlayer-demo/resources/qml/MaximizeButton.qml @@ -2,7 +2,7 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 45 implicitHeight: 30 @@ -14,12 +14,12 @@ Button { ToolTip.text: maximized ? qsTr("Restore") : qsTr("Maximize") contentItem: Image { - anchors.fill: parent + anchors.fill: control source: maximized ? "qrc:/images/button_restore_white.svg" : "qrc:/images/button_maximize_white.svg" } background: Rectangle { - visible: button.down || button.hovered - color: button.down ? "#808080" : (button.hovered ? "#c7c7c7" : "transparent") + visible: control.down || control.hovered + color: control.down ? "#808080" : (control.hovered ? "#c7c7c7" : "transparent") } } diff --git a/examples/QQPlayer-demo/resources/qml/MinimizeButton.qml b/examples/QQPlayer-demo/resources/qml/MinimizeButton.qml index 9a5daf5..7b81000 100644 --- a/examples/QQPlayer-demo/resources/qml/MinimizeButton.qml +++ b/examples/QQPlayer-demo/resources/qml/MinimizeButton.qml @@ -2,7 +2,7 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 45 implicitHeight: 30 @@ -12,12 +12,12 @@ Button { ToolTip.text: qsTr("Minimize") contentItem: Image { - anchors.fill: parent + anchors.fill: control source: "qrc:/images/button_minimize_white.svg" } background: Rectangle { - visible: button.down || button.hovered - color: button.down ? "#808080" : (button.hovered ? "#c7c7c7" : "transparent") + visible: control.down || control.hovered + color: control.down ? "#808080" : (control.hovered ? "#c7c7c7" : "transparent") } } diff --git a/examples/QQPlayer-demo/resources/qml/NextButton.qml b/examples/QQPlayer-demo/resources/qml/NextButton.qml index 4e9c4a9..425a4ec 100644 --- a/examples/QQPlayer-demo/resources/qml/NextButton.qml +++ b/examples/QQPlayer-demo/resources/qml/NextButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 16 implicitHeight: 14 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/next_blue_light.png" : "qrc:/images/next_blue.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/next_blue_light.png" : "qrc:/images/next_blue.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/OpenFileButton.qml b/examples/QQPlayer-demo/resources/qml/OpenFileButton.qml index bc44656..4f6b186 100644 --- a/examples/QQPlayer-demo/resources/qml/OpenFileButton.qml +++ b/examples/QQPlayer-demo/resources/qml/OpenFileButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 187 implicitHeight: 50 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/open_file_blue.png" : "qrc:/images/open_file_white.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/open_file_blue.png" : "qrc:/images/open_file_white.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/PlayButton.qml b/examples/QQPlayer-demo/resources/qml/PlayButton.qml index c05d776..dd159e5 100644 --- a/examples/QQPlayer-demo/resources/qml/PlayButton.qml +++ b/examples/QQPlayer-demo/resources/qml/PlayButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 45 implicitHeight: 45 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/play_blue_light.png" : "qrc:/images/play_blue.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/play_blue_light.png" : "qrc:/images/play_blue.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/PreviousButton.qml b/examples/QQPlayer-demo/resources/qml/PreviousButton.qml index d6d92df..05d3583 100644 --- a/examples/QQPlayer-demo/resources/qml/PreviousButton.qml +++ b/examples/QQPlayer-demo/resources/qml/PreviousButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 16 implicitHeight: 14 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/previous_blue_light.png" : "qrc:/images/previous_blue.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/previous_blue_light.png" : "qrc:/images/previous_blue.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/ProgressSlider.qml b/examples/QQPlayer-demo/resources/qml/ProgressSlider.qml index 606771c..7a7a9c6 100644 --- a/examples/QQPlayer-demo/resources/qml/ProgressSlider.qml +++ b/examples/QQPlayer-demo/resources/qml/ProgressSlider.qml @@ -18,6 +18,7 @@ Slider { property int handleWidth: 14 property int handleBorderWidth: 0 property color handleBorderColor: "transparent" + property bool handleVisibility: true background: Rectangle { x: 0 @@ -48,6 +49,7 @@ Slider { } handle: Rectangle { + visible: control.handleVisibility x: control.visualPosition * (control.availableWidth - width) y: control.availableHeight / 2 - height / 2 implicitWidth: control.handleWidth diff --git a/examples/QQPlayer-demo/resources/qml/StopButton.qml b/examples/QQPlayer-demo/resources/qml/StopButton.qml index 2737310..ac404fa 100644 --- a/examples/QQPlayer-demo/resources/qml/StopButton.qml +++ b/examples/QQPlayer-demo/resources/qml/StopButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 14 implicitHeight: 14 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/stop_blue_light.png" : "qrc:/images/stop_blue.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/stop_blue_light.png" : "qrc:/images/stop_blue.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/VolumeButton.qml b/examples/QQPlayer-demo/resources/qml/VolumeButton.qml index b68bba7..47da2fd 100644 --- a/examples/QQPlayer-demo/resources/qml/VolumeButton.qml +++ b/examples/QQPlayer-demo/resources/qml/VolumeButton.qml @@ -2,15 +2,15 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 Button { - id: button + id: control implicitWidth: 18 implicitHeight: 14 contentItem: Image { - anchors.fill: parent - source: button.down - || button.hovered ? "qrc:/images/volume_blue_light.png" : "qrc:/images/volume_blue.png" + anchors.fill: control + source: control.down + || control.hovered ? "qrc:/images/volume_blue_light.png" : "qrc:/images/volume_blue.png" } background: Item {} diff --git a/examples/QQPlayer-demo/resources/qml/main.qml b/examples/QQPlayer-demo/resources/qml/main.qml index 40c5352..1ec4043 100644 --- a/examples/QQPlayer-demo/resources/qml/main.qml +++ b/examples/QQPlayer-demo/resources/qml/main.qml @@ -9,6 +9,8 @@ Window { height: 540 title: qsTr("QQ Player") + property color themeColor: "#111111" + FramelessHelper { id: framelessHelper } @@ -16,7 +18,7 @@ Window { Rectangle { id: titleBar height: framelessHelper.titleBarHeight - color: "#111111" + color: window.themeColor anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right @@ -94,7 +96,7 @@ Window { anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right - color: "#111111" + color: window.themeColor ProgressSlider { id: progressSlider