Restructure project

This commit is contained in:
Dark Steveneq
2025-10-11 02:30:58 +02:00
parent a4dfc5b9bc
commit 6bcee551de
26 changed files with 369 additions and 259 deletions

View File

@@ -17,15 +17,24 @@
qt6.qttools
# this is for the shellhook portion
qt6.wrapQtAppsHook
makeWrapper
bashInteractive
# bashInteractive
];
# set the environment variables that unpatched Qt apps expect
shellHook = ''
bashdir=$(mktemp -d)
makeWrapper "$(type -p bash)" "$bashdir/bash" "''${qtWrapperArgs[@]}"
exec "$bashdir/bash"
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
# Add Qt-related environment variables.
# https://discourse.nixos.org/t/qt-development-environment-on-a-flake-system/23707/5
setQtEnvironment=$(mktemp)
random=$(openssl rand -base64 20 | sed "s/[^a-zA-Z0-9]//g")
makeShellWrapper "$(type -p sh)" "$setQtEnvironment" "''${qtWrapperArgs[@]}" --argv0 "$random"
sed "/$random/d" -i "$setQtEnvironment"
source "$setQtEnvironment"
# qmlls does not account for the import path and bases its search off qtbase's path.
# The actual imports come from qtdeclarative. This directs qmlls to the correct imports.
export QMLLS_BUILD_DIRS=$(pwd)/build:$QML2_IMPORT_PATH
'';
};
};

View File

@@ -2,83 +2,42 @@ cmake_minimum_required(VERSION 3.16)
project(qyouradio VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
FUNCTION(PREPEND var )
SET(listVar "")
FOREACH(f ${${var}})
LIST(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
ENDFOREACH(f)
SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION()
find_package(Qt6 REQUIRED COMPONENTS Quick)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
qt_standard_project_setup(REQUIRES 6.8)
add_subdirectory(locale/)
add_subdirectory(src/)
set(PROJECT_SOURCES
${CXX_FILES}
${QML_FILES}
${TS_FILES}
qt_add_executable(appqyouradio
main.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(qyouradio
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET qyouradio APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR}/locale ${TS_FILES})
else()
if(ANDROID)
add_library(qyouradio SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(qyouradio
${PROJECT_SOURCES}
)
endif()
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR}/locale ${TS_FILES})
endif()
target_link_libraries(qyouradio
PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
qt_add_qml_module(appqyouradio
URI qyouradio
VERSION 1.0
QML_FILES
Main.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.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER xyz.nonmesoft.qyouradio)
endif()
set_target_properties(qyouradio PROPERTIES
${BUNDLE_ID_OPTION}
set_target_properties(appqyouradio PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appqyouradio
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
include(GNUInstallDirs)
install(TARGETS qyouradio
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
target_link_libraries(appqyouradio
PRIVATE Qt6::Quick
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_import_qml_plugins(qyouradio)
qt_finalize_executable(qyouradio)
endif()
include(GNUInstallDirs)
install(TARGETS appqyouradio
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_subdirectory(QYRComponents)

25
qyouradio/Main.qml Executable file
View File

@@ -0,0 +1,25 @@
import QtQuick 6.8
import QtQuick.Layouts 6.8
import QYRComponents 1.0
ApplicationWindow {
width: 640
height: 480
title: qsTr("Hello World")
ColumnLayout {
anchors.fill: parent
Button {
text: qsTr("Settings")
}
CheckBox {}
Slider {
from: 0.0
value: 0.5
stepSize: 0.1
to: 1.1
}
}
}

82
qyouradio/QYRComponents/.gitignore vendored Executable file
View File

@@ -0,0 +1,82 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
*.qbs.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# Directories with generated files
.moc/
.obj/
.pch/
.rcc/
.uic/
/build*/

View File

@@ -0,0 +1,10 @@
import QtQuick 6.8
import QtQuick.Controls 6.8 as QC
QC.ApplicationWindow {
visible: true
background: Rectangle {
color: Colors.background
}
}

View File

@@ -0,0 +1,20 @@
import QtQuick 6.8
import QtQuick.Controls 6.8 as QC
QC.Button {
// highlighted: true
background: Rectangle {
color: hovered ? Colors.primaryAlt : Colors.primary
radius: 5
}
// width: player.playing ? 60 : 56
implicitHeight: 36
Component.onCompleted: {
contentItem.color = Colors.text;
font.family = Colors.fontFamily;
font.pointSize = Colors.fontSize.base;
}
}

View File

@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.16)
project(QYRComponents VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
set_source_files_properties(Colors.qml
PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
qt_add_library(QYRComponents STATIC)
qt_add_qml_module(QYRComponents
URI QYRComponents
VERSION 1.0
RESOURCE_PREFIX /qt/qml
QML_FILES Button.qml
QML_FILES Colors.qml
QML_FILES ApplicationWindow.qml
QML_FILES CheckBox.qml
QML_FILES Slider.qml
# SOURCES qyrcomponents.cpp qyrcomponents.h
)
set_target_properties(QYRComponents PROPERTIES
WIN32_EXECUTABLE TRUE
)
target_compile_definitions(QYRComponents
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(QYRComponents
PRIVATE Qt6::Quick)
target_include_directories(QYRComponents PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -0,0 +1,13 @@
import QtQuick 6.8
import QtQuick.Controls 6.8 as QC
QC.CheckBox {
contentItem: Rectangle {
radius: 2
color: parent.checked ? (parent.hovered ? Colors.primaryAlt : Colors.primary) : "#fff"
border.color: parent.checked ? (parent.hovered ? Colors.primaryAlt : Colors.primary) : "#fff"
border.width: 1
implicitWidth: 14
implicitHeight: 14
}
}

View File

@@ -0,0 +1,44 @@
pragma Singleton
import QtQuick 6.8
Item {
QtObject {
id: themes
readonly property var light: {
text: "#1f1f1f"
primary: "#007bff"
primaryAlt: "#0056b3"
background: "#f4f4f4"
}
readonly property var dark: {
text: "#f4f4f4"
primary: "#007bff"
primaryAlt: "#0056b3"
background: "#1f1f1f"
}
}
readonly property string fontFamily: "Arial"
readonly property var fontSize: {
h1: 32
h2: 24
h3: 18
h4: 16
h5: 13
h6: 10
p: 12
base: 12
}
property var currentTheme: themes.dark
//property alias themes: themes
readonly property string text: currentTheme.text
readonly property string primary: currentTheme.primary
readonly property string primaryAlt: currentTheme.primaryAlt
readonly property string background: currentTheme.background
}

View File

@@ -0,0 +1,38 @@
import QtQuick 6.8
import QtQuick.Controls 6.8 as QC
QC.Slider {
snapMode: Slider.SnapAlways
implicitWidth: 130
implicitHeight: 20
OpacityAnimator on opacity{
from: 0.7
to: 1
duration: 200
target: parent
running: this.hovered
}
OpacityAnimator on opacity{
from: 1
to: 0.7
duration: 200
target: parent
running: !this.hovered
}
background: Rectangle {
color: "#555"
radius: 5
}
handle: Rectangle {
x: this.leftPadding + this.visualPosition * (this.availableWidth - width)
y: this.topPadding + this.availableHeight / 2 - height / 2
width: 20
height: 20
radius: 10
color: Colors.primary
}
}

4
qyouradio/QYRComponents/qmldir Executable file
View File

@@ -0,0 +1,4 @@
module QYRComponents
Button 1.0 Button.qml
singleton Colors 1.0 Colors.qml

View File

@@ -0,0 +1,27 @@
#include "qyrcomponents.h"
#include <QPainter>
QYRComponents::QYRComponents(QQuickItem *parent)
: QQuickPaintedItem(parent)
{
// By default, QQuickItem does not draw anything. If you subclass
// QQuickItem to create a visual item, you will need to uncomment the
// following line and re-implement updatePaintNode()
// setFlag(ItemHasContents, true);
}
void QYRComponents::paint(QPainter *painter)
{
QPen pen(QColorConstants::Red, 2);
QBrush brush(QColorConstants::Red);
painter->setPen(pen);
painter->setBrush(brush);
painter->drawRect(0, 0, 100, 100);
}
QYRComponents::~QYRComponents()
{
}

View File

@@ -0,0 +1,17 @@
#ifndef QYRCOMPONENTS_H
#define QYRCOMPONENTS_H
#include <QtQuick/QQuickPaintedItem>
class QYRComponents : public QQuickPaintedItem
{
Q_OBJECT
QML_ELEMENT
Q_DISABLE_COPY(QYRComponents)
public:
explicit QYRComponents(QQuickItem *parent = nullptr);
void paint(QPainter *painter) override;
~QYRComponents() override;
};
#endif // QYRCOMPONENTS_H

View File

@@ -1,7 +0,0 @@
set(TS_FILES
qyouradio_en_US.ts
qyouradio_pl_PL.ts
)
PREPEND(TS_FILES)
set(TS_FILES ${TS_FILES} PARENT_SCOPE)

View File

@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US"></TS>

View File

@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="pl_PL"></TS>

16
qyouradio/main.cpp Executable file
View File

@@ -0,0 +1,16 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("qyouradio", "Main");
return app.exec();
}

View File

@@ -1,8 +0,0 @@
add_subdirectory(qml)
set(QML_FILES ${QML_FILES} PARENT_SCOPE)
set(CXX_FILES
main.cpp
)
PREPEND(CXX_FILES)
set(CXX_FILES ${CXX_FILES} PARENT_SCOPE)

View File

@@ -1,34 +0,0 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QLocale>
#include <QTranslator>
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "qyouradio_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
app.installTranslator(&translator);
break;
}
}
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}

View File

@@ -1,9 +0,0 @@
set(QML_FILES
qml.qrc
# main.qml
components/qml.qrc
# components/Button.qml
)
PREPEND(QML_FILES)
set(QML_FILES ${QML_FILES} PARENT_SCOPE)

View File

@@ -1,18 +0,0 @@
import QtQuick 2.15
import QtQuick.Controls 2.15 as QC
QC.Button {
highlighted: true
background: Rectangle {
color: hovered ? "#0056b3" : "#007bff"
radius: 5
}
implicitHeight: 36
Component.onCompleted: {
contentItem.color = "#f4f4f4";
font.family = "Arial";
font.pointSize = 12;
}
}

View File

@@ -1,13 +0,0 @@
import QtQuick 2.15
import QtQuick.Controls 2.155 as QC
QC.CheckBox {
implicitWidth: 14
implicitHeight: 14
contentItem: Rectangle {
radius: 2
color: parent.checked ? (parent.hovered ? "#0056b3" : "#007bff") : "#ffffff"
border.color: parent.checked ? (parent.hovered ? "#0056b3" : "#007bff") : "#ffffff"
border.width: 1
}
}

View File

@@ -1,62 +0,0 @@
import QtQuick 2.15
import QtQuick.Controls 2.15 as QC
QC.Slider {
from: 0.0
value: 0.5
stepSize: 0.1
to: 1.1
snapMode: Slider.SnapAlways
implicitWidth: 130
implicitHeight: 20
background: Rectangle {
color: "#555"
radius: 5
// OpacityAnimator on opacity {
// from: 0.7
// to: 1
// duration: 200
// target: parent
// running: parent.hovered
// }
// OpacityAnimator on opacity {
// from: 1
// to: 0.7
// duration: 200
// target: parent
// running: !parent.parent.hovered
// }
}
handle: Rectangle {
x: parent.leftPadding + parent.visualPosition * (parent.availableWidth - width)
y: parent.topPadding + parent.availableHeight / 2 - height / 2
width: 20
height: 20
radius: 10
color: "#007bff"
OpacityAnimator on opacity{
from: 0.7
to: 1
duration: 200
target: parent
running: parent.hovered
}
OpacityAnimator on opacity{
from: 1
to: 0.7
duration: 200
target: parent
running: !parent.hovered
}
}
onMoved: function() {
value = Math.max(value, 0.1);
}
}

View File

@@ -1,7 +0,0 @@
<RCC>
<qresource prefix="/components">
<file>Button.qml</file>
<file>CheckBox.qml</file>
<file>Slider.qml</file>
</qresource>
</RCC>

View File

@@ -1,22 +0,0 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import "components/"
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Button {
text: qsTr("Play")
}
CheckBox {
}
Slider {
}
}

View File

@@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>