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.
This commit is contained in:
Jean-Marc Lasgouttes 2024-10-30 23:49:18 +01:00
parent 0bd1951184
commit 159e8f2dde
13 changed files with 83 additions and 7 deletions

View File

@ -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.

2
README
View File

@ -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.

View File

@ -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\

View File

@ -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

View File

@ -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_);

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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_);

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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()
{