[LyX/master] Re-instate support for Qt 5.9.4
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Mon Nov 4 16:40:34 UTC 2024
commit 159e8f2dde4bef7ca3e49ce65b570bf69df7bb2c
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Wed Oct 30 23:49:18 2024 +0100
Re-instate support for Qt 5.9.4
It was a bit overkill to require support for Qt 5.12 at 6ba2b5c5 and
c39d5b76. Revert partly these commits.
---
INSTALL | 2 +-
README | 2 +-
configure.ac | 2 +-
src/frontends/qt/CategorizedCombo.cpp | 4 ++++
src/frontends/qt/GuiApplication.cpp | 7 +++++++
src/frontends/qt/GuiDocument.cpp | 16 ++++++++++++++++
src/frontends/qt/GuiFontMetrics.cpp | 11 +++++++++++
src/frontends/qt/GuiKeySymbol.cpp | 14 ++++++++++++--
src/frontends/qt/GuiView.cpp | 12 ++++++++++++
src/frontends/qt/GuiWorkArea.cpp | 6 ++++--
src/frontends/qt/LayoutBox.cpp | 4 ++++
src/frontends/qt/qt_helpers.cpp | 4 ++++
src/support/ConsoleApplicationPrivate.h | 6 ++++++
13 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/INSTALL b/INSTALL
index b5afc79a6f..13477e9462 100644
--- a/INSTALL
+++ b/INSTALL
@@ -59,7 +59,7 @@ LyX makes great use of the C++ Standard Library. This means that gcc
users will have to install the relevant libstdc++ library to be able
to compile this version of LyX.
-LyX requires Qt 5.12 and higher. It is also possible to compile
+LyX requires Qt 5.9.4 or higher. It is also possible to compile
against Qt 6. The only special point to make is that you must ensure
that both LyX and the Qt libraries are compiled with the same C++
compiler.
diff --git a/README b/README
index 93b56c79f0..fcc37dde49 100644
--- a/README
+++ b/README
@@ -90,7 +90,7 @@ What do I need to compile LyX from the source distribution?
but clang and MSVC are known to work too. As of LyX 2.5.0, you
need at least gcc 8.0.
- * The Qt library, at least version 5.12. It is also possible to
+ * The Qt library, at least version 5.9.4. It is also possible to
compile with Qt 6.x.
Read the file "INSTALL" for more information on compiling.
diff --git a/configure.ac b/configure.ac
index cfe65299df..58b698ec4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,7 +147,7 @@ AC_CHECK_HEADERS(magic.h,
### setup the qt frontend.
dnl The code below is not in a macro, because this would cause big
dnl problems with the AC_REQUIRE contained in QT_DO_IT_ALL.
-QT_DO_IT_ALL([5.12.0])
+QT_DO_IT_ALL([5.9.4])
AC_SUBST([FRONTENDS_SUBDIRS], [qt])
FRONTEND_INFO="${FRONTEND_INFO}\
Qt Frontend:\n\
diff --git a/src/frontends/qt/CategorizedCombo.cpp b/src/frontends/qt/CategorizedCombo.cpp
index ac4b45068f..0482e1c874 100644
--- a/src/frontends/qt/CategorizedCombo.cpp
+++ b/src/frontends/qt/CategorizedCombo.cpp
@@ -287,7 +287,11 @@ void CategorizedCombo::Private::setFilter(QString const & s)
lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
filter_ = s;
+#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
+ filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+#else
filterModel_->setFilterRegularExpression(charFilterRegExp(filter_));
+#endif
countCategories();
// restore old selection
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 9ea148135a..65ed25013e 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -106,7 +106,9 @@
#include <QObject>
#include <QPainter>
#include <QPixmap>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QRandomGenerator>
+#endif
#include <QScreen>
#include <QSessionManager>
#include <QSettings>
@@ -1136,7 +1138,12 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
#endif
setDesktopFileName(lyx_package);
+
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QRandomGenerator(QDateTime::currentDateTime().toSecsSinceEpoch());
+#else
+ qsrand(QDateTime::currentDateTime().toTime_t());
+#endif
// Install LyX translator for missing Qt translations
installTranslator(&d->gui_trans_);
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 4e41d8e8c2..067f162b3e 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -494,7 +494,13 @@ PreambleModule::PreambleModule(QWidget * parent)
checkFindButton();
int const tabStop = 4;
QFontMetrics metrics(preambleTE->currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+ // horizontalAdvance() is available starting in 5.11.0
+ // setTabStopDistance() is available starting in 5.10.0
preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
+#else
+ preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
+#endif
}
@@ -640,7 +646,13 @@ LocalLayout::LocalLayout(QWidget * parent)
connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
int const tabStop = 4;
QFontMetrics metrics(locallayoutTE->currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+ // horizontalAdvance() is available starting in 5.11.0
+ // setTabStopDistance() is available starting in 5.10.0
locallayoutTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
+#else
+ locallayoutTE->setTabStopWidth(tabStop * metrics.width(' '));
+#endif
}
@@ -2512,7 +2524,11 @@ void GuiDocument::updateQuoteStyles(bool const set)
for (int i = 0; i < langModule->quoteStyleCO->count(); ++i) {
langModule->quoteStyleCO->setItemData(i, QVariant(comboFont), Qt::FontRole);
QString str = langModule->quoteStyleCO->itemText(i);
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
qswidth = max(qswidth, fm.horizontalAdvance(str));
+#else
+ qswidth = max(qswidth, fm.width(str));
+#endif
}
// add scrollbar width and margin to width
qswidth += langModule->quoteStyleCO->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp
index 28f9a5ab54..cefce08e9b 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -283,7 +283,11 @@ int GuiFontMetrics::width(docstring const & s) const
if (math_char) {
QString const qs = toqstr(s);
int br_width = rbearing(s[0]);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int s_width = metrics_.horizontalAdvance(qs);
+#else
+ int s_width = metrics_.width(qs);
+#endif
// keep value 0 for math chars with width 0
if (s_width != 0)
w = max(br_width, s_width);
@@ -663,10 +667,17 @@ int GuiFontMetrics::width(char_type c) const
if (value != outOfLimitMetric)
return value;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if (is_utf16(c))
value = metrics_.horizontalAdvance(ucs4_to_qchar(c));
else
value = metrics_.horizontalAdvance(toqstr(docstring(1, c)));
+#else
+ if (is_utf16(c))
+ value = metrics_.width(ucs4_to_qchar(c));
+ else
+ value = metrics_.width(toqstr(docstring(1, c)));
+#endif
width_cache_.insert(c, value);
diff --git a/src/frontends/qt/GuiKeySymbol.cpp b/src/frontends/qt/GuiKeySymbol.cpp
index a054f4bc4d..b785791c85 100644
--- a/src/frontends/qt/GuiKeySymbol.cpp
+++ b/src/frontends/qt/GuiKeySymbol.cpp
@@ -845,15 +845,25 @@ bool KeySymbol::operator==(KeySymbol const & ks) const
KeyModifier q_key_state(Qt::KeyboardModifiers state)
{
KeyModifier k = NoModifier;
+#if defined(Q_OS_MAC) && (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
+ /// Additional check for Control and Meta modifier swap state.
+ /// Starting with Qt 5 the modifiers aren't reported correctly.
+ /// Until this is fixed a correction is required.
+ /// AFAIK it is fixed at least with Qt 5.12.0
+ const bool dontSwapCtrlAndMeta =
+ frontend::theGuiApp()->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
+#else
+ const bool dontSwapCtrlAndMeta = false;
+#endif
- if (state & Qt::ControlModifier)
+ if (state & (dontSwapCtrlAndMeta ? Qt::MetaModifier : Qt::ControlModifier))
k |= ControlModifier;
if (state & Qt::ShiftModifier)
k |= ShiftModifier;
if (state & Qt::AltModifier)
k |= AltModifier;
#if defined(USE_MACOSX_PACKAGING) || defined(USE_META_KEYBINDING)
- if (state & Qt::MetaModifier)
+ if (state & (dontSwapCtrlAndMeta ? Qt::ControlModifier : Qt::MetaModifier))
k |= MetaModifier;
#else
if (state & Qt::MetaModifier)
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index e1c21edf86..4163affb52 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -665,7 +665,11 @@ GuiView::GuiView(int id)
connect(stat_counts_, SIGNAL(clicked()), this, SLOT(statsPressed()));
zoom_slider_ = new QSlider(Qt::Horizontal, statusBar());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
zoom_slider_->setFixedWidth(fm.horizontalAdvance('x') * 15);
+#else
+ zoom_slider_->setFixedWidth(fm.width('x') * 15);
+#endif
// Make the defaultZoom center
zoom_slider_->setRange(10, (lyxrc.defaultZoom * 2) - 10);
// Initialize proper zoom value
@@ -678,7 +682,11 @@ GuiView::GuiView(int id)
zoom_slider_->setToolTip(qt_("Workarea zoom level. Drag, use Ctrl-+/- or Shift-Mousewheel to adjust."));
// Buttons to change zoom stepwise
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
QSize s(fm.horizontalAdvance('+'), fm.height());
+#else
+ QSize s(fm.width('+'), fm.height());
+#endif
zoom_in_ = new GuiClickableLabel(statusBar());
zoom_in_->setText("+");
zoom_in_->setFixedSize(s);
@@ -718,7 +726,11 @@ GuiView::GuiView(int id)
// zoom_value_->setPalette(palette);
zoom_value_->setForegroundRole(statusBar()->foregroundRole());
zoom_value_->setFixedHeight(fm.height());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
zoom_value_->setMinimumWidth(fm.horizontalAdvance("444\%"));
+#else
+ zoom_value_->setMinimumWidth(fm.width("444\%"));
+#endif
zoom_value_->setAlignment(Qt::AlignCenter);
zoom_value_->setText(toqstr(bformat(_("[[ZOOM]]%1$d%"), zoom)));
statusBar()->addPermanentWidget(zoom_value_);
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 33616b4c09..c6885b0f67 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -774,7 +774,8 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
#endif
q_button_state(e->button()), q_key_state(e->modifiers()));
-#if QT_VERSION < QT_VERSION_CHECK(5,15,1)
+#if (QT_VERSION > QT_VERSION_CHECK(5,10,1) && \
+ QT_VERSION < QT_VERSION_CHECK(5,15,1))
d->synthetic_mouse_event_.cmd = cmd; // QtBug QAbstractScrollArea::mouseMoveEvent
#endif
d->dispatch(cmd);
@@ -784,7 +785,8 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
{
-#if QT_VERSION < QT_VERSION_CHECK(5,15,1)
+#if (QT_VERSION > QT_VERSION_CHECK(5,10,1) && \
+ QT_VERSION < QT_VERSION_CHECK(5,15,1))
// cancel the event if the coordinates didn't change, this is due to QtBug
// QAbstractScrollArea::mouseMoveEvent, the event is triggered falsely when quickly
// double tapping a touchpad. To test: try to select a word by quickly double tapping
diff --git a/src/frontends/qt/LayoutBox.cpp b/src/frontends/qt/LayoutBox.cpp
index 444109260c..1cc6476a30 100644
--- a/src/frontends/qt/LayoutBox.cpp
+++ b/src/frontends/qt/LayoutBox.cpp
@@ -320,7 +320,11 @@ void LayoutBox::Private::setFilter(QString const & s)
lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
filter_ = s;
+#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
+ filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+#else
filterModel_->setFilterRegularExpression(charFilterRegExp(filter_));
+#endif
countCategories();
// restore old selection
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index bdd0e40b26..e03da21fea 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -769,7 +769,11 @@ QString formatToolTip(QString text, int width)
text = Qt::convertFromPlainText(text, Qt::WhiteSpaceNormal);
// Compute desired width in pixels
QFont const font = QToolTip::font();
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int const px_width = width * QFontMetrics(font).horizontalAdvance("M");
+#else
+ int const px_width = width * QFontMetrics(font).width("M");
+#endif
// Determine the ideal width of the tooltip
QTextDocument td("");
td.setHtml(text);
diff --git a/src/support/ConsoleApplicationPrivate.h b/src/support/ConsoleApplicationPrivate.h
index affca2439c..347f9ad62f 100644
--- a/src/support/ConsoleApplicationPrivate.h
+++ b/src/support/ConsoleApplicationPrivate.h
@@ -16,7 +16,9 @@
#include <QCoreApplication>
#include <QDateTime>
#include <QTimer>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QRandomGenerator>
+#endif
#include <string>
@@ -39,7 +41,11 @@ public:
setOrganizationDomain("lyx.org");
setApplicationName(toqstr(app));
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QRandomGenerator(QDateTime::currentDateTime().toSecsSinceEpoch());
+#else
+ qsrand(QDateTime::currentDateTime().toTime_t());
+#endif
}
int execute()
{
More information about the lyx-cvs
mailing list