Commit 47f3a019 authored by Christoffer Ackelman's avatar Christoffer Ackelman

Fixed QT drawing text and rectangles.

parent 3a092405
...@@ -59,7 +59,8 @@ ...@@ -59,7 +59,8 @@
#include "cow_qt_helpers.h" #include "cow_qt_helpers.h"
#define DRAW_PRESS_PIX 9 #define DRAW_PRESS_PIX 9
#define TEXT_SCALE 1024
#define roundi(x) ((int) round(x))
typedef struct { typedef struct {
QWidget *w; QWidget *w;
...@@ -910,6 +911,7 @@ int FlowDrawQt::rect_helper(FlowCtx *ctx, int painter_type, int size, int x, ...@@ -910,6 +911,7 @@ int FlowDrawQt::rect_helper(FlowCtx *ctx, int painter_type, int size, int x,
if (fill) { if (fill) {
painter->fillRect(x, y, width, height, painter->brush()); painter->fillRect(x, y, width, height, painter->brush());
} else { } else {
painter->setBrush(Qt::NoBrush);
painter->drawRect(x, y, width, height); painter->drawRect(x, y, width, height);
} }
...@@ -978,6 +980,7 @@ int FlowDrawQt::triangle_helper(FlowCtx *ctx, int painter_type, int size, int x, ...@@ -978,6 +980,7 @@ int FlowDrawQt::triangle_helper(FlowCtx *ctx, int painter_type, int size, int x,
path.addPolygon(poly); path.addPolygon(poly);
painter->fillPath(path, painter->brush()); painter->fillPath(path, painter->brush());
} else { } else {
painter->setBrush(Qt::NoBrush);
painter->drawPolygon(poly); painter->drawPolygon(poly);
} }
...@@ -1105,6 +1108,7 @@ int FlowDrawQt::arc_helper(FlowCtx *ctx, int painter_type, int size, int x, ...@@ -1105,6 +1108,7 @@ int FlowDrawQt::arc_helper(FlowCtx *ctx, int painter_type, int size, int x,
if (nav && ctx->no_nav) { return 1; } if (nav && ctx->no_nav) { return 1; }
QPainter *painter = get_painter(painter_type, size, nav); QPainter *painter = get_painter(painter_type, size, nav);
painter->setBrush(Qt::NoBrush);
painter->drawArc(x, y, width, height, angle1 * 64, angle2 * 64); painter->drawArc(x, y, width, height, angle1 * 64, angle2 * 64);
delete painter; delete painter;
...@@ -1257,14 +1261,13 @@ int FlowDrawQt::text_pango_helper(FlowCtx *ctx, int x, int y, char *text, ...@@ -1257,14 +1261,13 @@ int FlowDrawQt::text_pango_helper(FlowCtx *ctx, int x, int y, char *text,
int height = rect.height(); int height = rect.height();
if (erase_rect > 0) { if (erase_rect > 0) {
painter->eraseRect(x, y - (int) (0.8 / TEXT_SCALE * height), painter->eraseRect(x, roundi(y - 0.8 * height),
rect.width() / TEXT_SCALE, rect.width(),
height / TEXT_SCALE * (erase_rect / 10.0)); roundi(height * (erase_rect / 10.0)));
} }
if (erase_rect < 12) { if (erase_rect < 12) {
painter painter->drawText(x, roundi(y - 0.8 * height), rect.width(), height, Qt::TextDontClip, str);
->drawText(TEXT_SCALE * x, (int) (TEXT_SCALE * y - 0.8 * height), str);
} }
delete painter; delete painter;
...@@ -1686,8 +1689,8 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx *ctx, const char *text, int len, ...@@ -1686,8 +1689,8 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx *ctx, const char *text, int len,
QRect boundingRect = painter->fontMetrics().boundingRect(str); QRect boundingRect = painter->fontMetrics().boundingRect(str);
*width = boundingRect.width() / TEXT_SCALE; *width = boundingRect.width();
*height = boundingRect.height() / TEXT_SCALE; *height = boundingRect.height();
delete painter; delete painter;
......
...@@ -221,6 +221,7 @@ void QtScrollWidgetFlow::moveEvent(QMoveEvent *event) ...@@ -221,6 +221,7 @@ void QtScrollWidgetFlow::moveEvent(QMoveEvent *event)
void QtScrollWidgetFlow::resizeEvent(QResizeEvent *event) void QtScrollWidgetFlow::resizeEvent(QResizeEvent *event)
{ {
this->image = QImage(event->size(), QImage::Format_RGB32);
realize(); realize();
handleEvent(event, true); handleEvent(event, true);
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
......
...@@ -74,7 +74,8 @@ using namespace std; ...@@ -74,7 +74,8 @@ using namespace std;
#include "cow_qt_helpers.h" #include "cow_qt_helpers.h"
#define DRAW_PRESS_PIX 9 #define DRAW_PRESS_PIX 9
#define TEXT_SCALE 1024
#define roundi(x) ((int) round(x))
static char font_names[glow_eFont__][glow_eDrawFont__][DRAW_FONT_SIZE][80] = static char font_names[glow_eFont__][glow_eDrawFont__][DRAW_FONT_SIZE][80] =
{{{"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--10-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--12-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--24-*-*-*-P-*-ISO8859-1"}, {"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--10-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--12-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1"}}, {{{"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--10-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--12-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Bold-R-Normal--24-*-*-*-P-*-ISO8859-1"}, {"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--10-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--12-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1", "-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1"}},
...@@ -941,6 +942,7 @@ int GlowDrawQt::rect_helper(GlowWind *wind, int painter_type, int size, int x, ...@@ -941,6 +942,7 @@ int GlowDrawQt::rect_helper(GlowWind *wind, int painter_type, int size, int x,
if (fill) { if (fill) {
painter->fillRect(x, y, width, height, painter->brush()); painter->fillRect(x, y, width, height, painter->brush());
} else { } else {
painter->setBrush(Qt::NoBrush);
painter->drawRect(x, y, width, height); painter->drawRect(x, y, width, height);
} }
...@@ -1037,6 +1039,7 @@ int GlowDrawQt::arc_helper(GlowWind *wind, int painter_type, int size, int x, ...@@ -1037,6 +1039,7 @@ int GlowDrawQt::arc_helper(GlowWind *wind, int painter_type, int size, int x,
if (fill) { if (fill) {
painter->drawPie(x, y, width, height, angle1 * 64, angle2 * 64); painter->drawPie(x, y, width, height, angle1 * 64, angle2 * 64);
} else { } else {
painter->setBrush(Qt::NoBrush);
painter->drawArc(x, y, width, height, angle1 * 64, angle2 * 64); painter->drawArc(x, y, width, height, angle1 * 64, angle2 * 64);
} }
...@@ -1227,11 +1230,10 @@ int GlowDrawQt::polyline_helper(GlowWind *wind, int painter_type, int size, ...@@ -1227,11 +1230,10 @@ int GlowDrawQt::polyline_helper(GlowWind *wind, int painter_type, int size,
int cnt; int cnt;
QPoint *qpoints = points_to_qt_points_curve(wind, points, point_cnt, &cnt); QPoint *qpoints = points_to_qt_points_curve(wind, points, point_cnt, &cnt);
if (fill) { if (!fill) {
painter->drawPolygon(qpoints, point_cnt); painter->setBrush(Qt::NoBrush);
} else {
painter->drawLines(qpoints, cnt);
} }
painter->drawPolygon(qpoints, point_cnt);
delete qpoints; delete qpoints;
delete painter; delete painter;
...@@ -1305,7 +1307,8 @@ int GlowDrawQt::text(GlowWind *wind, int x, int y, char *text, int len, ...@@ -1305,7 +1307,8 @@ int GlowDrawQt::text(GlowWind *wind, int x, int y, char *text, int len,
} }
painter->setFont(QFont(font_names[font_idx][font_type][idx])); painter->setFont(QFont(font_names[font_idx][font_type][idx]));
painter->drawText(x, y, QString::fromLocal8Bit(text, len)); QRect rect = painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, QString::fromLocal8Bit(text, len));
delete painter; delete painter;
...@@ -1378,7 +1381,8 @@ int GlowDrawQt::text_erase(GlowWind *wind, int x, int y, char *text, int len, ...@@ -1378,7 +1381,8 @@ int GlowDrawQt::text_erase(GlowWind *wind, int x, int y, char *text, int len,
} }
painter->setFont(QFont(font_names[font_idx][font_type][idx])); painter->setFont(QFont(font_names[font_idx][font_type][idx]));
painter->drawText(x, y, QString::fromLocal8Bit(text, len)); QRect rect = painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, QString::fromLocal8Bit(text, len));
delete painter; delete painter;
...@@ -3133,19 +3137,19 @@ int GlowDrawQt::text_qt(GlowWind *wind, int x, int y, char *text, int len, ...@@ -3133,19 +3137,19 @@ int GlowDrawQt::text_qt(GlowWind *wind, int x, int y, char *text, int len,
int px, py; int px, py;
if (rot == 180) { if (rot == 180) {
px = -TEXT_SCALE * x - width; px = -x - width;
py = (int) (-TEXT_SCALE * y - FONT_DESCENT * height); py = (int) (-y - FONT_DESCENT * height);
} else if (rot == 90) { } else if (rot == 90) {
px = -TEXT_SCALE * y - width + height / 2; px = -y - width + height / 2;
py = TEXT_SCALE * x; py = x;
} else if (rot == 270) { } else if (rot == 270) {
px = TEXT_SCALE * y - width; px = y - width;
py = -TEXT_SCALE * x - height; py = -x - height;
} else { } else {
px = TEXT_SCALE * x; px = x;
py = (int) (TEXT_SCALE * y - (1.0 - FONT_DESCENT) * height); py = (int) (y - (1.0 - FONT_DESCENT) * height);
} }
painter->drawText(px, py, str); painter->drawText(px, py, rect.width(), rect.height(), Qt::TextDontClip, str);
delete painter; delete painter;
...@@ -3195,20 +3199,20 @@ int GlowDrawQt::text_erase_qt(GlowWind *wind, int x, int y, char *text, int len, ...@@ -3195,20 +3199,20 @@ int GlowDrawQt::text_erase_qt(GlowWind *wind, int x, int y, char *text, int len,
} }
if (rot == 90) { if (rot == 90) {
px = x;// - height/TEXT_SCALE/2; px = x;// - height/2;
py = y - width / TEXT_SCALE; py = y - width;
ph = width / TEXT_SCALE; ph = width;
pw = height / TEXT_SCALE; pw = height;
} else if (rot == 270) { } else if (rot == 270) {
px = x;// - height/TEXT_SCALE/2; px = x;// - height/2;
py = y - height / TEXT_SCALE / 2; py = y - height / 2;
ph = width / TEXT_SCALE; ph = width;
pw = height / TEXT_SCALE; pw = height;
} else { } else {
px = x; px = x;
py = (int) (y - (1.0 - FONT_DESCENT) * height / TEXT_SCALE); py = (int) (y - (1.0 - FONT_DESCENT) * height);
pw = width / TEXT_SCALE; pw = width;
ph = height / TEXT_SCALE; ph = height;
} }
QPainter *painter = get_painter(w->buffer, this, painter_type, idx); QPainter *painter = get_painter(w->buffer, this, painter_type, idx);
...@@ -3258,13 +3262,13 @@ int GlowDrawQt::get_text_extent_qt(const char *text, int len, ...@@ -3258,13 +3262,13 @@ int GlowDrawQt::get_text_extent_qt(const char *text, int len,
lheight = (int) (lheight * 0.9); lheight = (int) (lheight * 0.9);
if (rot == 90 || rot == 270) { if (rot == 90 || rot == 270) {
*height = lwidth / TEXT_SCALE; *height = lwidth;
*width = lheight / TEXT_SCALE; *width = lheight;
} else { } else {
*width = lwidth / TEXT_SCALE; *width = lwidth;
*height = lheight / TEXT_SCALE; *height = lheight;
} }
*descent = (int) (FONT_DESCENT * lheight / TEXT_SCALE); *descent = (int) (FONT_DESCENT * lheight);
delete painter; delete painter;
......
...@@ -221,6 +221,7 @@ void QtScrollWidgetGlow::moveEvent(QMoveEvent *event) ...@@ -221,6 +221,7 @@ void QtScrollWidgetGlow::moveEvent(QMoveEvent *event)
void QtScrollWidgetGlow::resizeEvent( void QtScrollWidgetGlow::resizeEvent(
QResizeEvent *event) QResizeEvent *event)
{ {
this->image = QImage(event->size(), QImage::Format_RGB32);
realize(); realize();
handleEvent(event, true); handleEvent(event, true);
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment