From 76a63b29c295a7f6ae338673a5ba482e8b4a7e26 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Sat, 20 May 2023 11:59:07 +0300 Subject: [PATCH] - support Qt6 (no audio yet) + increase version to 0.1.16 --- app/audio_support.cpp | 7 +++++- app/config.h | 2 +- app/mainwindow.cpp | 48 +++++++++++++++++++++----------------- scripts/build_linux_qt6.sh | 12 ++++++++++ scripts/build_qbreak.py | 2 +- 5 files changed, 47 insertions(+), 24 deletions(-) create mode 100755 scripts/build_linux_qt6.sh diff --git a/app/audio_support.cpp b/app/audio_support.cpp index cf479cc..7b72b68 100644 --- a/app/audio_support.cpp +++ b/app/audio_support.cpp @@ -1,10 +1,12 @@ #include "audio_support.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include extern void play_audio(const app_settings::selected_audio& item) { // Play audio + if (item.name != Audio_Empty && item.name != Audio_Custom) { // Find bundled audio @@ -16,4 +18,7 @@ extern void play_audio(const app_settings::selected_audio& item) if (item.name == Audio_Custom && !item.path.isEmpty()) QSound::play(item.path); } - +#else +extern void play_audio(const app_settings::selected_audio& item) +{} +#endif diff --git a/app/config.h b/app/config.h index d8c2076..197ed28 100644 --- a/app/config.h +++ b/app/config.h @@ -4,7 +4,7 @@ // App version #define QBREAK_VERSION_MAJOR 0 #define QBREAK_VERSION_MINOR 1 -#define QBREAK_VERSION_SUFFIX 15 +#define QBREAK_VERSION_SUFFIX 16 // How often UI is updated - interval in seconds #define INTERVAL_UPDATE_UI (15) diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index c3cadd0..7a848ee 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -12,25 +12,46 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +# include +# include +#endif + #include +static void dispatchToMainThread(std::function callback, std::chrono::milliseconds delay = std::chrono::milliseconds(0)) +{ + // any thread + QTimer* timer = new QTimer(); + timer->moveToThread(qApp->thread()); + timer->setSingleShot(true); + timer->setInterval(delay); + QObject::connect(timer, &QTimer::timeout, [=]() + { + // main thread + callback(); + timer->deleteLater(); + }); + QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection, Q_ARG(int, 0)); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - init(); + + // Defer init call for 100 ms - attempt to resolve the problem with non working setTooltip() + dispatchToMainThread([this](){init();}, std::chrono::milliseconds(100)); } MainWindow::~MainWindow() @@ -128,11 +149,11 @@ static int str_to_seconds(const QString& s) throw std::runtime_error("Bad parameter value."); if (s.back() == 'h') - return s.leftRef(s.size()-1).toInt() * 3600; + return s.left(s.size()-1).toInt() * 3600; if (s.back() == 'm') - return s.leftRef(s.size()-1).toInt() * 60; + return s.left(s.size()-1).toInt() * 60; if (s.back() == 's') - return s.leftRef(s.size()-1).toInt(); + return s.left(s.size()-1).toInt(); if (s.back().isDigit()) return s.toInt(); @@ -293,21 +314,6 @@ QString state2str(AppState state) return QString(); } -static void dispatchToMainThread(std::function callback) -{ - // any thread - QTimer* timer = new QTimer(); - timer->moveToThread(qApp->thread()); - timer->setSingleShot(true); - timer->setInterval(std::chrono::milliseconds(500)); - QObject::connect(timer, &QTimer::timeout, [=]() - { - // main thread - callback(); - timer->deleteLater(); - }); - QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection, Q_ARG(int, 0)); -} void MainWindow::shiftTo(AppState newState) { diff --git a/scripts/build_linux_qt6.sh b/scripts/build_linux_qt6.sh new file mode 100755 index 0000000..40264f1 --- /dev/null +++ b/scripts/build_linux_qt6.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# I use this script on two different hosts so there are logic to find proper Qt installation + +export QT_HOME=/home/$USER/tools/qt/6.4.2/gcc_64 +if [ ! -d "$QT_HOME" ] ; then + export QT_HOME=/home/$USER/tools/qt/6.4.2/gcc_64 +fi + +# Build .appimage +/usr/bin/python3 build_qbreak.py release + diff --git a/scripts/build_qbreak.py b/scripts/build_qbreak.py index b4e90ae..434a297 100755 --- a/scripts/build_qbreak.py +++ b/scripts/build_qbreak.py @@ -84,7 +84,7 @@ if platform.system() == 'Linux': '-qmake=' + os.environ['QT_HOME'] + '/bin/qmake', '-unsupported-allow-new-glibc', #'-no-translations', - '-extra-plugins=iconengines,platformthemes/libqgtk3.so' + '-extra-plugins=iconengines,platformthemes/libqgtk3.so,platforms/libqxcb.so' ] desktop_path = 'appimage_dir/usr/share/applications/qbreak.desktop'