UI: Cleanup Qt for Qt6

This changes cleans up some deprecated functions that were removed in
Qt6. Some are placed behind version ifdefs and others are replaced for
their non-deprecated Qt5 version.
master
Kurt Kartaltepe 2021-03-04 21:30:03 -08:00 committed by Jim
parent 40f99da8a2
commit 513bcb8e35
11 changed files with 48 additions and 11 deletions

View File

@ -419,7 +419,11 @@ static inline void updateStyle(QWidget *widget)
widget->update();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void OBSHotkeyWidget::enterEvent(QEnterEvent *event)
#else
void OBSHotkeyWidget::enterEvent(QEvent *event)
#endif
{
if (!label)
return;
@ -448,7 +452,11 @@ void OBSHotkeyLabel::highlightPair(bool highlight)
updateStyle(this);
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void OBSHotkeyLabel::enterEvent(QEnterEvent *event)
#else
void OBSHotkeyLabel::enterEvent(QEvent *event)
#endif
{
if (!pairPartner)
return;

View File

@ -36,7 +36,11 @@ public:
QPointer<OBSHotkeyLabel> pairPartner;
QPointer<OBSHotkeyWidget> widget;
void highlightPair(bool highlight);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;
void setToolTip(const QString &toolTip);
};
@ -131,7 +135,11 @@ public:
void Save();
void Save(std::vector<obs_key_combination_t> &combinations);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;
private:

View File

@ -101,7 +101,11 @@ void OBSLogViewer::InitLog()
if (file.open(QIODevice::ReadOnly)) {
QTextStream in(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
in.setEncoding(QStringConverter::Utf8);
#else
in.setCodec("UTF-8");
#endif
while (!in.atEnd()) {
QString line = in.readLine();

View File

@ -31,7 +31,6 @@
#if !defined(_WIN32) && !defined(__APPLE__)
#include <obs-nix-platform.h>
#include <QX11Info>
#endif
#ifdef ENABLE_WAYLAND

View File

@ -28,7 +28,12 @@
#include <memory>
#include <vector>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#define QT_UTF8(str) QString::fromUtf8(str, -1)
#else
#define QT_UTF8(str) QString::fromUtf8(str)
#endif
#define QT_TO_UTF8(str) str.toUtf8().constData()
class QDataStream;

View File

@ -147,7 +147,7 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
void SourceTreeItem::paintEvent(QPaintEvent *event)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
@ -305,7 +305,11 @@ void SourceTreeItem::mouseDoubleClickEvent(QMouseEvent *event)
}
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void SourceTreeItem::enterEvent(QEnterEvent *event)
#else
void SourceTreeItem::enterEvent(QEvent *event)
#endif
{
QWidget::enterEvent(event);

View File

@ -32,7 +32,11 @@ class SourceTreeItem : public QWidget {
friend class SourceTreeModel;
void mouseDoubleClickEvent(QMouseEvent *event) override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;
virtual bool eventFilter(QObject *object, QEvent *event) override;

View File

@ -24,7 +24,6 @@
#include <QShowEvent>
#include <QDesktopServices>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QScreen>
#include <QColorDialog>
#include <QSizePolicy>
@ -73,7 +72,6 @@
#include <fstream>
#include <sstream>
#include <QScreen>
#include <QWindow>
#include <json11.hpp>
@ -207,8 +205,10 @@ extern void RegisterRestreamAuth();
OBSBasic::OBSBasic(QWidget *parent)
: OBSMainWindow(parent), ui(new Ui::OBSBasic)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<SignalContainer<OBSScene>>(
"SignalContainer<OBSScene>");
#endif
setAttribute(Qt::WA_NativeWindow);
@ -263,10 +263,12 @@ OBSBasic::OBSBasic(QWidget *parent)
qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
qRegisterMetaType<SavedProjectorInfo *>("SavedProjectorInfo *");
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<std::vector<std::shared_ptr<OBSSignal>>>(
"std::vector<std::shared_ptr<OBSSignal>>");
qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
qRegisterMetaTypeStreamOperators<OBSSceneItem>("OBSSceneItem");
#endif
ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
@ -384,7 +386,8 @@ OBSBasic::OBSBasic(QWidget *parent)
QRect windowGeometry = normalGeometry();
if (!WindowPositionValid(windowGeometry)) {
QRect rect = App()->desktop()->geometry();
QRect rect =
QGuiApplication::primaryScreen()->geometry();
setGeometry(QStyle::alignedRect(Qt::LeftToRight,
Qt::AlignCenter, size(),
rect));
@ -7286,7 +7289,8 @@ void OBSBasic::OpenSavedProjector(SavedProjectorInfo *info)
projector->restoreGeometry(byteArray);
if (!WindowPositionValid(projector->normalGeometry())) {
QRect rect = App()->desktop()->geometry();
QRect rect = QGuiApplication::primaryScreen()
->geometry();
projector->setGeometry(QStyle::alignedRect(
Qt::LeftToRight, Qt::AlignCenter,
size(), rect));

View File

@ -904,8 +904,8 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
channelIndex = ui->channelSetup->currentIndex();
sampleRateIndex = ui->sampleRate->currentIndex();
QRegExp rx("\\d{1,5}x\\d{1,5}");
QValidator *validator = new QRegExpValidator(rx, this);
QRegularExpression rx("\\d{1,5}x\\d{1,5}");
QValidator *validator = new QRegularExpressionValidator(rx, this);
ui->baseResolution->lineEdit()->setValidator(validator);
ui->outputResolution->lineEdit()->setValidator(validator);
}

View File

@ -6,12 +6,12 @@
#include "obs-app.hpp"
#include "qt-wrappers.hpp"
#include <QDesktopWidget>
#include <QPushButton>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QScreen>
#include <string>
@ -204,7 +204,8 @@ OBSBasicStats::OBSBasicStats(QWidget *parent, bool closeable)
QRect windowGeometry = normalGeometry();
if (!WindowPositionValid(windowGeometry)) {
QRect rect = App()->desktop()->geometry();
QRect rect =
QGuiApplication::primaryScreen()->geometry();
setGeometry(QStyle::alignedRect(Qt::LeftToRight,
Qt::AlignCenter, size(),
rect));

View File

@ -68,7 +68,7 @@ QWidget *MissingFilesPathItemDelegate::createEditor(
};
QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
QLineEdit *text = new QLineEdit();