]> git.lyx.org Git - features.git/commitdiff
Replace QFontMetrics::width() by horizontalAdvance() in Qt>=5.11
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 24 Oct 2020 17:29:34 +0000 (19:29 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 24 Oct 2020 17:52:18 +0000 (19:52 +0200)
The method horizontalAdvance() replaces width() starting with Qt 5.11.
To handle this, all direct calls to QFontMetrics::width() are replaced
by calls to GuiFontMetrics::width(), and the code for
GuiFontMetrics::width(QChar) uses horizontalAdvance on newer Qt
versions.

src/frontends/qt/GuiFontExample.cpp
src/frontends/qt/GuiFontMetrics.cpp
src/frontends/qt/GuiView.cpp
src/frontends/qt/PanelStack.cpp

index cb27b5fb5a84295b50199b4b74823d88bf92de2c..8a4ca13df8f83334ef93397526a8b4158ead5d3e 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "GuiFontExample.h"
+#include "GuiFontMetrics.h"
 
 #include <QPainter>
 #include <QPaintEvent>
@@ -28,20 +29,20 @@ void GuiFontExample::set(QFont const & font, QString const & text)
 
 QSize GuiFontExample::sizeHint() const
 {
-       QFontMetrics m(font_);
-       return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
+       lyx::frontend::GuiFontMetrics m(font_);
+       return QSize(m.width(text_) + 10, m.maxHeight() + 6);
 }
 
 
 void GuiFontExample::paintEvent(QPaintEvent *)
 {
        QPainter p;
-       QFontMetrics m(font_);
+       lyx::frontend::GuiFontMetrics m(font_);
 
        p.begin(this);
        p.setFont(font_);
        p.drawRect(0, 0, width() - 1, height() - 1);
-       p.drawText(5, 3 + m.ascent(), text_);
+       p.drawText(5, 3 + m.maxAscent(), text_);
        p.end();
 }
 
index 83c9f650f827a944650e0bf158c3bf2bd7f894c3..dffa827830724c14b8321c6be11c12447c527c90 100644 (file)
@@ -627,10 +627,17 @@ int GuiFontMetrics::width(char_type c) const
        if (value != outOfLimitMetric)
                return value;
 
+#if QT_VERSION >= 0x050b00
+       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);
 
index 4dca7bf5311198796e2e69568cdcfa8027add089..907f151c0369604c68128e3a8b4ac809ba0a99e7 100644 (file)
@@ -21,6 +21,7 @@
 #include "GuiApplication.h"
 #include "GuiClickableLabel.h"
 #include "GuiCompleter.h"
+#include "GuiFontMetrics.h"
 #include "GuiKeySymbol.h"
 #include "GuiToc.h"
 #include "GuiToolbar.h"
@@ -199,12 +200,12 @@ public:
                // Check how long the logo gets with the current font
                // and adapt if the font is running wider than what
                // we assume
-               QFontMetrics fm(font);
+               GuiFontMetrics fm(font);
                // Split the title into lines to measure the longest line
                // in the current l7n.
                QStringList titlesegs = htext.split('\n');
                int wline = 0;
-               int hline = fm.height();
+               int hline = fm.maxHeight();
                QStringList::const_iterator sit;
                for (sit = titlesegs.constBegin(); sit != titlesegs.constEnd(); ++sit) {
                        if (fm.width(*sit) > wline)
index 2614284a8d2f287b8a00cb1c912ecc6ab786a2c5..22eab2a6cecc3b60bc4b89bbfdf5c0a929eedfb9 100644 (file)
@@ -13,6 +13,7 @@
 #include "PanelStack.h"
 
 #include "GuiApplication.h"
+#include "GuiFontMetrics.h"
 #include "qt_helpers.h"
 
 #include "FancyLineEdit.h"
@@ -23,7 +24,6 @@
 #include <QAbstractButton>
 #include <QApplication>
 #include <QComboBox>
-#include <QFontMetrics>
 #include <QGroupBox>
 #include <QHideEvent>
 #include <QHash>
@@ -120,7 +120,7 @@ void PanelStack::addCategory(QString const & name, QString const & parent)
 
        panel_map_[name] = item;
 
-       QFontMetrics fm(list_->font());
+       GuiFontMetrics fm(list_->font());
 
        // calculate the real size the current item needs in the listview
        int itemsize = fm.width(qt_(name)) + 10 + list_->indentation() * depth;