Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
fc8e1f29
Commit
fc8e1f29
authored
Nov 30, 2020
by
Christoffer Ackelman
Committed by
Esteban Blanc
Dec 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QT: Workaround for QFontMetrics not handling multiline text.
parent
61f2bfb0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
19 deletions
+40
-19
xtt/lib/flow/qt/flow_draw_qt.cqt
xtt/lib/flow/qt/flow_draw_qt.cqt
+18
-8
xtt/lib/glow/qt/glow_draw_qt.cqt
xtt/lib/glow/qt/glow_draw_qt.cqt
+22
-11
No files found.
xtt/lib/flow/qt/flow_draw_qt.cqt
View file @
fc8e1f29
...
...
@@ -1165,15 +1165,21 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
painter->setFont(get_font(painter_type, FONT_SCALE * size));
QRect rect = painter->fontMetrics().boundingRect(str);
int height = rect.height();
int width = 0;
int height = 0;
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect rect = painter->fontMetrics().boundingRect(l[i]);
width = MAX(width, rect.width());
height += rect.height();
}
if (erase_rect > 0) {
painter->eraseRect(x, ROUND(y - 0.8 * height),
rect.width()
+ 1, ROUND(height * (erase_rect / 10.0)));
painter->eraseRect(x, ROUND(y - 0.8 * height),
width
+ 1, ROUND(height * (erase_rect / 10.0)));
}
if (erase_rect < 12) {
painter->drawText(x, ROUND(y - 0.8 * height),
rect.width(), height, Qt::TextDontClip, str, &rect
);
painter->drawText(x, ROUND(y - 0.8 * height),
width, height, Qt::TextDontClip, str
);
}
return 1;
...
...
@@ -1598,10 +1604,14 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len,
painter->setFont(get_font(painter_type, FONT_SCALE * size));
QRect boundingRect = painter->fontMetrics().boundingRect(str);
*width = boundingRect.width();
*height = boundingRect.height();
*width = 0;
*height = 0;
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect boundingRect = painter->fontMetrics().boundingRect(l[i]);
*width = MAX(*width, boundingRect.width());
*height += boundingRect.height();
}
return 1;
}
...
...
xtt/lib/glow/qt/glow_draw_qt.cqt
View file @
fc8e1f29
...
...
@@ -1233,6 +1233,18 @@ int GlowDrawQt::polyline_erase(
wind, glow_eDrawType_LineErase, idx, points, point_cnt);
}
static QRect getTextExtent(unique_ptr<QPainter>& painter, QString& str)
{
QRect r(0, 0, 0, 0);
QStringList l = str.split("\n");
for (int i = 0; i < l.length(); i++) {
QRect rect = painter->fontMetrics().boundingRect(l[i]);
r.setWidth(MAX(r.width(), rect.width()));
r.setHeight(r.height() + rect.height());
}
return r;
}
int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
glow_eDrawType painter_type, glow_eDrawType color, int idx, int highlight,
int line, glow_eFont font_idx, double size, int rot)
...
...
@@ -1266,10 +1278,10 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
painter->setPen(QPen(painter->brush(), size + 1));
}
Q
Rect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len)
);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len)
);
Q
String str = QString::fromLocal8Bit(text, len);
QRect rect = getTextExtent(painter, str
);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, str
);
return 1;
}
...
...
@@ -1338,10 +1350,9 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len,
set_clip(w, painter);
}
QRect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len));
QString str = QString::fromLocal8Bit(text, len);
QRect rect = getTextExtent(painter, str);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, str);
return 1;
}
...
...
@@ -2929,7 +2940,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
painter->setFont(get_font(font_idx, painter_type, size));
QRect rect =
painter->fontMetrics().boundingRect(
str);
QRect rect =
getTextExtent(painter,
str);
int width = rect.width();
int height = rect.height();
height = (int)(height * 0.9);
...
...
@@ -2987,7 +2998,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
painter->setFont(get_font(font_idx, painter_type, size));
QRect rect =
painter->fontMetrics().boundingRect(
str);
QRect rect =
getTextExtent(painter,
str);
width = rect.width();
height = rect.height();
height = (int)(height * 0.9);
...
...
@@ -3047,7 +3058,7 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len,
str = QString::fromUtf8(text);
}
QRect boundingRect =
painter->fontMetrics().boundingRect(
str);
QRect boundingRect =
getTextExtent(painter,
str);
int lwidth = boundingRect.width();
int lheight = boundingRect.height();
lheight = (int)(lheight * 0.9);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment