From e44021b369fd868c5a5461155a43de89b07d2e78 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Thu, 28 Nov 2019 08:34:18 +0400 Subject: [PATCH] Fix most of deprecated API usage in the editor --- apps/opencs/view/doc/newgame.cpp | 8 ++++++++ apps/opencs/view/doc/startup.cpp | 9 +++++++++ apps/opencs/view/prefs/dialogue.cpp | 18 +++++++++++++++++- apps/opencs/view/widget/coloreditor.cpp | 8 ++++++++ apps/opencs/view/world/enumdelegate.cpp | 5 +++++ apps/opencs/view/world/scriptedit.cpp | 9 +++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/doc/newgame.cpp b/apps/opencs/view/doc/newgame.cpp index b3e2a4f637..8e976c68f9 100644 --- a/apps/opencs/view/doc/newgame.cpp +++ b/apps/opencs/view/doc/newgame.cpp @@ -6,6 +6,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + #include "filewidget.hpp" #include "adjusterwidget.hpp" @@ -46,7 +50,11 @@ CSVDoc::NewGameDialogue::NewGameDialogue() connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)), mAdjusterWidget, SLOT (setName (const QString&, bool))); +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + QRect scr = QGuiApplication::primaryScreen()->geometry(); +#else QRect scr = QApplication::desktop()->screenGeometry(); +#endif QRect rect = geometry(); move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y()); } diff --git a/apps/opencs/view/doc/startup.cpp b/apps/opencs/view/doc/startup.cpp index 78f18b3a14..beb2cf7d81 100644 --- a/apps/opencs/view/doc/startup.cpp +++ b/apps/opencs/view/doc/startup.cpp @@ -10,6 +10,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + QPushButton *CSVDoc::StartupDialogue::addButton (const QString& label, const QIcon& icon) { int column = mColumn--; @@ -119,7 +123,12 @@ CSVDoc::StartupDialogue::StartupDialogue() : mWidth (0), mColumn (2) setLayout (layout); +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + QRect scr = QGuiApplication::primaryScreen()->geometry(); +#else QRect scr = QApplication::desktop()->screenGeometry(); +#endif + QRect rect = geometry(); move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y()); } diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index 0d32ebd0ad..853031ccd3 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -8,6 +8,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + #include #include "../../model/prefs/state.hpp" @@ -34,7 +38,12 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) ++iter) { QString label = QString::fromUtf8 (iter->second.getKey().c_str()); + +#if QT_VERSION >= QT_VERSION_CHECK(5,11,0) + maxWidth = std::max (maxWidth, metrics.horizontalAdvance (label)); +#else maxWidth = std::max (maxWidth, metrics.width (label)); +#endif list->addItem (label); } @@ -107,8 +116,15 @@ void CSVPrefs::Dialogue::show() } else { +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + QRect scr = QGuiApplication::primaryScreen()->geometry(); +#else + QRect scr = QApplication::desktop()->screenGeometry(); +#endif + // otherwise place at the centre of the screen - QPoint screenCenter = QApplication::desktop()->screenGeometry().center(); + QPoint screenCenter = scr.center(); + move (screenCenter - QPoint(frameGeometry().width()/2, frameGeometry().height()/2)); } diff --git a/apps/opencs/view/widget/coloreditor.cpp b/apps/opencs/view/widget/coloreditor.cpp index e30696458f..cd19e54a31 100644 --- a/apps/opencs/view/widget/coloreditor.cpp +++ b/apps/opencs/view/widget/coloreditor.cpp @@ -6,6 +6,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + #include "colorpickerpopup.hpp" CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, const bool popupOnStart) @@ -95,7 +99,11 @@ QPoint CSVWidget::ColorEditor::calculatePopupPosition() { QRect editorGeometry = geometry(); QRect popupGeometry = mColorPicker->geometry(); +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + QRect screenGeometry = QGuiApplication::primaryScreen()->geometry(); +#else QRect screenGeometry = QApplication::desktop()->screenGeometry(); +#endif // Center the popup horizontally relative to the editor int localPopupX = (editorGeometry.width() - popupGeometry.width()) / 2; diff --git a/apps/opencs/view/world/enumdelegate.cpp b/apps/opencs/view/world/enumdelegate.cpp index dd4405a923..0f920db944 100644 --- a/apps/opencs/view/world/enumdelegate.cpp +++ b/apps/opencs/view/world/enumdelegate.cpp @@ -134,7 +134,12 @@ QSize CSVWorld::EnumDelegate::sizeHint(const QStyleOptionViewItem &option, const itemOption.state = option.state; const QString &valueText = mValues.at(valueIndex).second; + +#if QT_VERSION >= QT_VERSION_CHECK(5,11,0) + QSize valueSize = QSize(itemOption.fontMetrics.horizontalAdvance(valueText), itemOption.fontMetrics.height()); +#else QSize valueSize = QSize(itemOption.fontMetrics.width(valueText), itemOption.fontMetrics.height()); +#endif itemOption.currentText = valueText; return QApplication::style()->sizeFromContents(QStyle::CT_ComboBox, &itemOption, valueSize); diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 1105404b37..996e80da42 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -205,7 +205,12 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) const void CSVWorld::ScriptEdit::setTabWidth() { // Set tab width to specified number of characters using current font. +#if QT_VERSION >= QT_VERSION_CHECK(5,11,0) + setTabStopDistance(mTabCharCount * fontMetrics().horizontalAdvance(' ')); +#else setTabStopWidth(mTabCharCount * fontMetrics().width(' ')); +#endif + } void CSVWorld::ScriptEdit::wrapLines(bool wrap) @@ -285,7 +290,11 @@ int CSVWorld::ScriptEdit::lineNumberAreaWidth() ++digits; } +#if QT_VERSION >= QT_VERSION_CHECK(5,11,0) + int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits; +#else int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; +#endif return space; }