diff --git a/flake.nix b/flake.nix index b11345c..2a7b509 100755 --- a/flake.nix +++ b/flake.nix @@ -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 ''; }; }; diff --git a/qyouradio/CMakeLists.txt b/qyouradio/CMakeLists.txt index f5bc99f..20ae6cf 100755 --- a/qyouradio/CMakeLists.txt +++ b/qyouradio/CMakeLists.txt @@ -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) diff --git a/qyouradio/Main.qml b/qyouradio/Main.qml new file mode 100755 index 0000000..46b4dbc --- /dev/null +++ b/qyouradio/Main.qml @@ -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 + } + } +} diff --git a/qyouradio/QYRComponents/.gitignore b/qyouradio/QYRComponents/.gitignore new file mode 100755 index 0000000..aa3808c --- /dev/null +++ b/qyouradio/QYRComponents/.gitignore @@ -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*/ diff --git a/qyouradio/QYRComponents/ApplicationWindow.qml b/qyouradio/QYRComponents/ApplicationWindow.qml new file mode 100644 index 0000000..eb36604 --- /dev/null +++ b/qyouradio/QYRComponents/ApplicationWindow.qml @@ -0,0 +1,10 @@ +import QtQuick 6.8 +import QtQuick.Controls 6.8 as QC + +QC.ApplicationWindow { + visible: true + + background: Rectangle { + color: Colors.background + } +} diff --git a/qyouradio/QYRComponents/Button.qml b/qyouradio/QYRComponents/Button.qml new file mode 100755 index 0000000..3329a2c --- /dev/null +++ b/qyouradio/QYRComponents/Button.qml @@ -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; + } +} diff --git a/qyouradio/QYRComponents/CMakeLists.txt b/qyouradio/QYRComponents/CMakeLists.txt new file mode 100755 index 0000000..56fd96d --- /dev/null +++ b/qyouradio/QYRComponents/CMakeLists.txt @@ -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 $<$,$>:QT_QML_DEBUG>) +target_link_libraries(QYRComponents + PRIVATE Qt6::Quick) + +target_include_directories(QYRComponents PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + diff --git a/qyouradio/QYRComponents/CheckBox.qml b/qyouradio/QYRComponents/CheckBox.qml new file mode 100644 index 0000000..8d20935 --- /dev/null +++ b/qyouradio/QYRComponents/CheckBox.qml @@ -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 + } +} diff --git a/qyouradio/QYRComponents/Colors.qml b/qyouradio/QYRComponents/Colors.qml new file mode 100644 index 0000000..f9594e5 --- /dev/null +++ b/qyouradio/QYRComponents/Colors.qml @@ -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 + +} diff --git a/qyouradio/QYRComponents/Slider.qml b/qyouradio/QYRComponents/Slider.qml new file mode 100644 index 0000000..f4af270 --- /dev/null +++ b/qyouradio/QYRComponents/Slider.qml @@ -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 + } +} diff --git a/qyouradio/QYRComponents/qmldir b/qyouradio/QYRComponents/qmldir new file mode 100755 index 0000000..3846024 --- /dev/null +++ b/qyouradio/QYRComponents/qmldir @@ -0,0 +1,4 @@ +module QYRComponents + +Button 1.0 Button.qml +singleton Colors 1.0 Colors.qml \ No newline at end of file diff --git a/qyouradio/QYRComponents/qyrcomponents.cpp b/qyouradio/QYRComponents/qyrcomponents.cpp new file mode 100755 index 0000000..1cfc684 --- /dev/null +++ b/qyouradio/QYRComponents/qyrcomponents.cpp @@ -0,0 +1,27 @@ +#include "qyrcomponents.h" + +#include + +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() +{ +} diff --git a/qyouradio/QYRComponents/qyrcomponents.h b/qyouradio/QYRComponents/qyrcomponents.h new file mode 100755 index 0000000..bfebe28 --- /dev/null +++ b/qyouradio/QYRComponents/qyrcomponents.h @@ -0,0 +1,17 @@ +#ifndef QYRCOMPONENTS_H +#define QYRCOMPONENTS_H + +#include + +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 diff --git a/qyouradio/locale/CMakeLists.txt b/qyouradio/locale/CMakeLists.txt deleted file mode 100644 index c0cf048..0000000 --- a/qyouradio/locale/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/qyouradio/locale/qyouradio_en_US.ts b/qyouradio/locale/qyouradio_en_US.ts deleted file mode 100755 index edd0d34..0000000 --- a/qyouradio/locale/qyouradio_en_US.ts +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/qyouradio/locale/qyouradio_pl_PL.ts b/qyouradio/locale/qyouradio_pl_PL.ts deleted file mode 100755 index 9a6efd5..0000000 --- a/qyouradio/locale/qyouradio_pl_PL.ts +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/qyouradio/main.cpp b/qyouradio/main.cpp new file mode 100755 index 0000000..5557f37 --- /dev/null +++ b/qyouradio/main.cpp @@ -0,0 +1,16 @@ +#include +#include + + +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(); +} diff --git a/qyouradio/src/CMakeLists.txt b/qyouradio/src/CMakeLists.txt deleted file mode 100644 index 57b0108..0000000 --- a/qyouradio/src/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/qyouradio/src/main.cpp b/qyouradio/src/main.cpp deleted file mode 100755 index 0bdc446..0000000 --- a/qyouradio/src/main.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -#include -#include - -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(); -} diff --git a/qyouradio/src/qml/CMakeLists.txt b/qyouradio/src/qml/CMakeLists.txt deleted file mode 100644 index bc66982..0000000 --- a/qyouradio/src/qml/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/qyouradio/src/qml/components/Button.qml b/qyouradio/src/qml/components/Button.qml deleted file mode 100644 index 8033669..0000000 --- a/qyouradio/src/qml/components/Button.qml +++ /dev/null @@ -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; - } -} diff --git a/qyouradio/src/qml/components/CheckBox.qml b/qyouradio/src/qml/components/CheckBox.qml deleted file mode 100644 index 9187fcc..0000000 --- a/qyouradio/src/qml/components/CheckBox.qml +++ /dev/null @@ -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 - } -} diff --git a/qyouradio/src/qml/components/Slider.qml b/qyouradio/src/qml/components/Slider.qml deleted file mode 100644 index 36f35b6..0000000 --- a/qyouradio/src/qml/components/Slider.qml +++ /dev/null @@ -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); - } -} diff --git a/qyouradio/src/qml/components/qml.qrc b/qyouradio/src/qml/components/qml.qrc deleted file mode 100755 index 6d9bef5..0000000 --- a/qyouradio/src/qml/components/qml.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - Button.qml - CheckBox.qml - Slider.qml - - diff --git a/qyouradio/src/qml/main.qml b/qyouradio/src/qml/main.qml deleted file mode 100755 index 60b3d5f..0000000 --- a/qyouradio/src/qml/main.qml +++ /dev/null @@ -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 { - - } -} diff --git a/qyouradio/src/qml/qml.qrc b/qyouradio/src/qml/qml.qrc deleted file mode 100755 index 5f6483a..0000000 --- a/qyouradio/src/qml/qml.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - main.qml - -