Introduce Qt 6 support
With QT_VERSION_CHECK and core5compat module
This commit is contained in:
parent
c15e14e9d1
commit
b833a5d261
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue