From 2ee4d5414eb4a3e0fed03ac5d0b92c80e22b3680 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 25 Nov 2021 20:37:10 +0100 Subject: [PATCH] WIP --- .../streamers/dxf/db_plugin/dbDXFReader.cc | 34 ++++++++++++++++--- src/plugins/tools/view_25d/view_25d.pro | 4 +++ .../tools/xor/lay_plugin/layXORProgress.cc | 5 +++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc index 56b5113c2..9258f3ac3 100644 --- a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc +++ b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc @@ -50,6 +50,30 @@ namespace db { +// --------------------------------------------------------------- + +#if defined(HAVE_QT) + +static int fm_width (const QFontMetrics &fm, const QString &s) +{ +#if QT_VERSION >= 0x60000 + return fm.horizontalAdvance (s); +#else + return fm.width (s); +#endif +} + +static int fm_width (const QFontMetrics &fm, const QChar &s) +{ +#if QT_VERSION >= 0x60000 + return fm.horizontalAdvance (s); +#else + return fm.width (s); +#endif +} + +#endif + // --------------------------------------------------------------- // DXFReader @@ -1279,7 +1303,7 @@ DXFReader::deliver_text (db::Shapes &shapes, const std::string &s, const db::DCp // The m_text_scaling divider is the letter width in percent of the height. // 92 is the default letter pitch in percent of the text height. - int pixel_size_ref = int (floor (0.5 + 100.0 * fm.width (QChar::fromLatin1 ('X')) / (0.92 * m_text_scaling))); + int pixel_size_ref = int (floor (0.5 + 100.0 * fm_width (fm, QChar::fromLatin1 ('X')) / (0.92 * m_text_scaling))); // split text into lines QStringList lines = QString::fromUtf8 (s.c_str ()).split (QString::fromUtf8 ("\n")); @@ -1302,7 +1326,7 @@ DXFReader::deliver_text (db::Shapes &shapes, const std::string &s, const db::DCp lines.clear (); for (QStringList::const_iterator l = ll.begin (); l != ll.end (); ++l) { - if (fm.width (*l) * h / pixel_size_ref > w) { + if (fm_width (fm, *l) * h / pixel_size_ref > w) { // wrapping required QString line; @@ -1321,7 +1345,7 @@ DXFReader::deliver_text (db::Shapes &shapes, const std::string &s, const db::DCp ++i; } - double wc = fm.width (ls) * h / pixel_size_ref; + double wc = fm_width (fm, ls) * h / pixel_size_ref; if (wl + wc > w) { lines.push_back (line); line.clear (); @@ -1351,9 +1375,9 @@ DXFReader::deliver_text (db::Shapes &shapes, const std::string &s, const db::DCp double x0 = 0.0; if (ha == HAlignLeft || ha == NoHAlign) { } else if (ha == HAlignCenter) { - x0 -= fm.width (*l) * 0.5 * h / pixel_size_ref; + x0 -= fm_width (fm, *l) * 0.5 * h / pixel_size_ref; } else { - x0 -= fm.width (*l) * h / pixel_size_ref; + x0 -= fm_width (fm, *l) * h / pixel_size_ref; } QPainterPath pp; diff --git a/src/plugins/tools/view_25d/view_25d.pro b/src/plugins/tools/view_25d/view_25d.pro index 138f0890d..fe4a52dc7 100644 --- a/src/plugins/tools/view_25d/view_25d.pro +++ b/src/plugins/tools/view_25d/view_25d.pro @@ -7,6 +7,10 @@ contains(QT_CONFIG, opengl) { SUBDIRS = lay_plugin unit_tests } + greaterThan(QT_MAJOR_VERSION, 5) { + QT += openglwidgets + } + unit_tests.depends += lay_plugin } diff --git a/src/plugins/tools/xor/lay_plugin/layXORProgress.cc b/src/plugins/tools/xor/lay_plugin/layXORProgress.cc index b0a1a544a..fb13a7ffd 100644 --- a/src/plugins/tools/xor/lay_plugin/layXORProgress.cc +++ b/src/plugins/tools/xor/lay_plugin/layXORProgress.cc @@ -109,8 +109,13 @@ public: QFontMetrics fm (font ()); m_line_height = std::max (fm.height (), m_pixmap_size + 4); m_font_height = fm.height () * 3 / 2; + #if QT_VERSION >= 0x60000 + m_first_column_width = fm.horizontalAdvance (QString::fromUtf8 ("LAYERNAME")); + m_column_width = m_pixmap_size + 4 + m_spacing + fm.horizontalAdvance (QString::fromUtf8 ("1.00G ")); +#else m_first_column_width = fm.width (QString::fromUtf8 ("LAYERNAME")); m_column_width = m_pixmap_size + 4 + m_spacing + fm.width (QString::fromUtf8 ("1.00G ")); +#endif } QSize sizeHint () const