diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 4ba164698..6bc22bad6 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -5,6 +5,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + #ifdef MAC_OS_X_VERSION_MIN_REQUIRED #undef MAC_OS_X_VERSION_MIN_REQUIRED // We need to do this because of Qt: https://bugreports.qt-project.org/browse/QTBUG-22154 @@ -311,6 +315,17 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) QRect Launcher::GraphicsPage::getMaximumResolution() { QRect max; + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + for (QScreen* screen : QGuiApplication::screens()) + { + QRect res = screen->geometry(); + if (res.width() > max.width()) + max.setWidth(res.width()); + if (res.height() > max.height()) + max.setHeight(res.height()); + } +#else int screens = QApplication::desktop()->screenCount(); for (int i = 0; i < screens; ++i) { @@ -320,6 +335,7 @@ QRect Launcher::GraphicsPage::getMaximumResolution() if (res.height() > max.height()) max.setHeight(res.height()); } +#endif return max; } diff --git a/apps/opencs/view/doc/newgame.cpp b/apps/opencs/view/doc/newgame.cpp index b3e2a4f63..8e976c68f 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 78f18b3a1..beb2cf7d8 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/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 529f21165..9c0e33080 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -15,6 +15,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +#include +#endif + #include "../../model/doc/document.hpp" #include "../../model/prefs/state.hpp" #include "../../model/prefs/shortcut.hpp" @@ -1050,7 +1054,7 @@ void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth) if (isGrowLimit) rect = dw->screenGeometry(this); else - rect = dw->screenGeometry(dw->screen(dw->screenNumber(this))); + rect = QGuiApplication::screens().at(dw->screenNumber(this))->geometry(); if (!mScrollbarOnly && mScroll && mSubViews.size() > 1) { diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index 0d32ebd0a..853031ccd 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 e30696458..cd19e54a3 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 dd4405a92..0f920db94 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 1105404b3..996e80da4 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; }