mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 19:14:51 +00:00
Replace QFontMetrics::width() by horizontalAdvance() in Qt>=5.11
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.
(cherry picked from commit 21422dd652
)
This commit is contained in:
parent
20c8959790
commit
f4314b6461
@ -11,6 +11,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "GuiFontExample.h"
|
#include "GuiFontExample.h"
|
||||||
|
#include "GuiFontMetrics.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
@ -28,20 +29,20 @@ void GuiFontExample::set(QFont const & font, QString const & text)
|
|||||||
|
|
||||||
QSize GuiFontExample::sizeHint() const
|
QSize GuiFontExample::sizeHint() const
|
||||||
{
|
{
|
||||||
QFontMetrics m(font_);
|
lyx::frontend::GuiFontMetrics m(font_);
|
||||||
return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
|
return QSize(m.width(text_) + 10, m.maxHeight() + 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiFontExample::paintEvent(QPaintEvent *)
|
void GuiFontExample::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter p;
|
QPainter p;
|
||||||
QFontMetrics m(font_);
|
lyx::frontend::GuiFontMetrics m(font_);
|
||||||
|
|
||||||
p.begin(this);
|
p.begin(this);
|
||||||
p.setFont(font_);
|
p.setFont(font_);
|
||||||
p.drawRect(0, 0, width() - 1, height() - 1);
|
p.drawRect(0, 0, width() - 1, height() - 1);
|
||||||
p.drawText(5, 3 + m.ascent(), text_);
|
p.drawText(5, 3 + m.maxAscent(), text_);
|
||||||
p.end();
|
p.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,10 +563,17 @@ int GuiFontMetrics::width(char_type c) const
|
|||||||
if (value != outOfLimitMetric)
|
if (value != outOfLimitMetric)
|
||||||
return value;
|
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))
|
if (is_utf16(c))
|
||||||
value = metrics_.width(ucs4_to_qchar(c));
|
value = metrics_.width(ucs4_to_qchar(c));
|
||||||
else
|
else
|
||||||
value = metrics_.width(toqstr(docstring(1, c)));
|
value = metrics_.width(toqstr(docstring(1, c)));
|
||||||
|
#endif
|
||||||
|
|
||||||
width_cache_.insert(c, value);
|
width_cache_.insert(c, value);
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "PanelStack.h"
|
#include "PanelStack.h"
|
||||||
|
|
||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
|
#include "GuiFontMetrics.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
@ -21,7 +22,6 @@
|
|||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QFontMetrics>
|
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QHideEvent>
|
#include <QHideEvent>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
@ -118,7 +118,7 @@ void PanelStack::addCategory(QString const & name, QString const & parent)
|
|||||||
|
|
||||||
panel_map_[name] = item;
|
panel_map_[name] = item;
|
||||||
|
|
||||||
QFontMetrics fm(list_->font());
|
GuiFontMetrics fm(list_->font());
|
||||||
|
|
||||||
// calculate the real size the current item needs in the listview
|
// calculate the real size the current item needs in the listview
|
||||||
int itemsize = fm.width(qt_(name)) + 10 + list_->indentation() * depth;
|
int itemsize = fm.width(qt_(name)) + 10 + list_->indentation() * depth;
|
||||||
|
@ -100,3 +100,4 @@ What's new
|
|||||||
|
|
||||||
* BUILD/INSTALLATION
|
* BUILD/INSTALLATION
|
||||||
|
|
||||||
|
- Remove use of deprecated Qt methods.
|
||||||
|
Loading…
Reference in New Issue
Block a user