diff options
| author | Alexey Andreyev <aa13q@ya.ru> | 2023-03-25 01:10:18 +0300 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2023-03-24 23:42:29 +0100 |
| commit | b833a5d261727616b18cfc81f13b624b1316044f (patch) | |
| tree | ffee83549a0d34b90937850c206cfc8bec72e3a4 | |
| parent | c15e14e9d1fc9042c53d782dcdfeed1bea5a10d8 (diff) | |
Introduce Qt 6 support
With QT_VERSION_CHECK and core5compat module
| -rw-r--r-- | src/browsertab.cpp | 5 | ||||
| -rw-r--r-- | src/kristall.pro | 2 | ||||
| -rw-r--r-- | src/renderers/renderhelpers.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/kristalltextbrowser.cpp | 17 | ||||
| -rw-r--r-- | src/widgets/mediaplayer.cpp | 38 | ||||
| -rw-r--r-- | src/widgets/mediaplayer.hpp | 5 |
6 files changed, 69 insertions, 3 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 1b90720..eb879d1 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -28,6 +28,7 @@ #include <cassert> #include <QTabWidget> +#include <QtGlobal> #include <QMenu> #include <QMessageBox> #include <QInputDialog> @@ -1124,7 +1125,11 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new QInputDialog input { this }; input.setInputMode(QInputDialog::TextInput); input.setLabelText(tr("This style has no embedded name. Please enter a name for the preset:")); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) input.setTextValue(this->current_location.fileName().split(".", QString::SkipEmptyParts).first()); +#else + input.setTextValue(this->current_location.fileName().split(".", Qt::SkipEmptyParts).first()); +#endif if(input.exec() != QDialog::Accepted) return; diff --git a/src/kristall.pro b/src/kristall.pro index 646d302..550a055 100644 --- a/src/kristall.pro +++ b/src/kristall.pro @@ -1,7 +1,7 @@ QT += core gui svg greaterThan(QT_MAJOR_VERSION, 4): QT += widgets network multimedia multimediawidgets - +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings diff --git a/src/renderers/renderhelpers.cpp b/src/renderers/renderhelpers.cpp index 30c51d5..9851c99 100644 --- a/src/renderers/renderhelpers.cpp +++ b/src/renderers/renderhelpers.cpp @@ -16,6 +16,7 @@ #include <QTextCursor> #include <QTextFrame> #include <QTextFrameFormat> +#include <QtGlobal> #include <string> #include <iostream> @@ -358,7 +359,11 @@ void renderhelpers::renderEscapeCodes(const QByteArray &input, { it++; const auto escSequence = *it; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (escSequence == "[") +#else + if (escSequence == QChar::fromLatin1('[')) +#endif { it++; parseCSI(input, it, format, defaultFormat, cursor); diff --git a/src/widgets/kristalltextbrowser.cpp b/src/widgets/kristalltextbrowser.cpp index 5f34c10..a4fc4e8 100644 --- a/src/widgets/kristalltextbrowser.cpp +++ b/src/widgets/kristalltextbrowser.cpp @@ -2,9 +2,14 @@ #include "kristall.hpp" +#include <QtGlobal> #include <QMouseEvent> #include <QScroller> +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include <QTouchDevice> +#else +#include <QInputDevice> +#endif #include <QRegularExpression> #include <QLineEdit> #include <QApplication> @@ -17,6 +22,7 @@ KristallTextBrowser::KristallTextBrowser(QWidget *parent) : connect(this, &QTextBrowser::anchorClicked, this, &KristallTextBrowser::on_anchorClicked); // Enable touch scrolling on touchscreen devices +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) for (int i = 0; i < QTouchDevice::devices().length(); ++i) { if (QTouchDevice::devices()[i]->type() == QTouchDevice::TouchScreen) @@ -26,6 +32,17 @@ KristallTextBrowser::KristallTextBrowser(QWidget *parent) : break; } } +#else + for (auto &device: QInputDevice::devices()) + { + if (device->type() == QInputDevice::DeviceType::TouchScreen) + { + this->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); + QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture); + break; + } + } +#endif } void KristallTextBrowser::mouseReleaseEvent(QMouseEvent *event) diff --git a/src/widgets/mediaplayer.cpp b/src/widgets/mediaplayer.cpp index d2592c7..41aa105 100644 --- a/src/widgets/mediaplayer.cpp +++ b/src/widgets/mediaplayer.cpp @@ -3,10 +3,15 @@ #include "kristall.hpp" -#include <QMediaContent> +#include <QtGlobal> #include <QToolButton> #include <QTime> #include <QIcon> +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#include <QMediaContent> +#else +#include <QUrl> +#endif MediaPlayer::MediaPlayer(QWidget *parent) : QWidget(parent), @@ -27,10 +32,18 @@ MediaPlayer::MediaPlayer(QWidget *parent) : connect(&this->player, &QMediaPlayer::durationChanged, this->ui->media_progress, &QSlider::setMaximum); connect(&this->player, &QMediaPlayer::positionChanged, this->ui->media_progress, &QSlider::setValue); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) connect(&this->player, &QMediaPlayer::audioAvailableChanged, this->ui->mute_button, &QToolButton::setEnabled); +#else + connect(&this->player, &QMediaPlayer::hasAudioChanged, this->ui->mute_button, &QToolButton::setEnabled); +#endif // connect(&this->player, &QMediaPlayer::videoAvailableChanged, this->ui->video_out, &QVideoWidget::setVisible); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) connect(&this->player, &QMediaPlayer::stateChanged, this, &MediaPlayer::on_media_playbackChanged); +#else + connect(&this->player, &QMediaPlayer::playbackStateChanged, this, &MediaPlayer::on_media_playbackChanged); +#endif connect(&this->player, &QMediaPlayer::mediaStatusChanged, [](QMediaPlayer::MediaStatus status) { qDebug() << "media status changed" << status; }); @@ -55,9 +68,12 @@ void MediaPlayer::setMedia(QByteArray const & data, QUrl const & ref_url, QStrin this->media_stream.setData(data); // = QBuffer { &this->backing_buffer }; this->media_stream.open(QIODevice::ReadOnly); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QMediaContent content { ref_url }; - this->player.setMedia(content, &this->media_stream); +#else + this->player.setSource(ref_url); +#endif } void MediaPlayer::stopPlaying() @@ -67,16 +83,24 @@ void MediaPlayer::stopPlaying() void MediaPlayer::on_playpause_button_clicked() { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if(this->player.state() != QMediaPlayer::PlayingState) { this->player.play(); } else { this->player.pause(); } +#else + // aa13q +#endif } void MediaPlayer::on_mute_button_clicked(bool checked) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) this->player.setMuted(checked); +#else + // aa13q +#endif } void MediaPlayer::on_media_positionChanged(qint64 pos) @@ -86,6 +110,7 @@ void MediaPlayer::on_media_positionChanged(qint64 pos) this->ui->media_position->setText(time.toString()); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void MediaPlayer::on_media_playbackChanged(QMediaPlayer::State status) { this->ui->playpause_button->setIcon((status == QMediaPlayer::PlayingState) @@ -93,3 +118,12 @@ void MediaPlayer::on_media_playbackChanged(QMediaPlayer::State status) : QIcon::fromTheme("media-playback-start") ); } +#else +void MediaPlayer::on_media_playbackChanged(QMediaPlayer::PlaybackState status) +{ + this->ui->playpause_button->setIcon((status == QMediaPlayer::PlayingState) + ? QIcon::fromTheme("media-playback-pause") + : QIcon::fromTheme("media-playback-start") + ); +} +#endif diff --git a/src/widgets/mediaplayer.hpp b/src/widgets/mediaplayer.hpp index c39a800..d7e6699 100644 --- a/src/widgets/mediaplayer.hpp +++ b/src/widgets/mediaplayer.hpp @@ -1,6 +1,7 @@ #ifndef MEDIAPLAYER_HPP #define MEDIAPLAYER_HPP +#include <QtGlobal> #include <QWidget> #include <QBuffer> #include <QVideoWidget> @@ -30,7 +31,11 @@ private slots: private: // slots void on_media_positionChanged(qint64 pos); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void on_media_playbackChanged(QMediaPlayer::State); +#else + void on_media_playbackChanged(QMediaPlayer::PlaybackState); +#endif private: Ui::MediaPlayer *ui; |
