summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2010-09-19 13:59:56 +0200
committerJens Bache-Wiig <jbache@trolltech.com>2010-09-19 13:59:56 +0200
commitfd0c78bb37e36dbdabe298e42c4931ea40fde1f3 (patch)
tree6dcc3dbc19f9922878abd3f06051a77ed4f15a17
parent4775aea557293693cd6aab52193cf7a66e1ff5e4 (diff)
Add stubs for textBaseLine
-rw-r--r--examples/painting/Drawing.qml6
-rw-r--r--src/context2d.cpp39
-rw-r--r--src/context2d.h4
3 files changed, 42 insertions, 7 deletions
diff --git a/examples/painting/Drawing.qml b/examples/painting/Drawing.qml
index 6c8b82f..f0f39a2 100644
--- a/examples/painting/Drawing.qml
+++ b/examples/painting/Drawing.qml
@@ -38,11 +38,7 @@ Canvas {
function drawPoint() {
ctx.lineWidth = lineWidth
ctx.fillStyle = drawColor
- ctx.shadowOffsetX = 1;
- ctx.shadowOffsetY = 1;
- ctx.shadowBlur = 64;
- ctx.shadowColor = "black";
- ctx.fillRect(mousearea.mouseX, mousearea.mouseY, 20, 20);
+ ctx.fillRect(mousearea.mouseX, mousearea.mouseY, 2, 2);
}
function clear() {
diff --git a/src/context2d.cpp b/src/context2d.cpp
index 6bea78b..7d275fa 100644
--- a/src/context2d.cpp
+++ b/src/context2d.cpp
@@ -474,6 +474,23 @@ void Context2D::setShadowColor(const QString &str)
m_state.flags |= DirtyShadowColor;
}
+QString Context2D::textBaseline()
+{
+ switch(m_state.textBaseline) {
+ default:
+ return "middle";
+ }
+}
+
+void Context2D::setTextBaseline(const QString &)
+{
+ qDebug("Baseline not implemented");
+
+ // ### alphabetic, ideographic, hanging
+
+ m_state.flags |= DirtyTextBaseline;
+}
+
void Context2D::setFont(const QString &fontString)
{
QFont font;
@@ -548,14 +565,32 @@ void Context2D::fillRect(qreal x, qreal y, qreal w, qreal h)
void Context2D::fillText(const QString &text, qreal x, qreal y)
{
+ qDebug("here");
beginPainting();
m_painter.save();
- m_painter.setPen(QPen(m_state.fillStyle,0));
+ m_painter.setPen(QPen(m_state.fillStyle, m_state.lineWidth));
m_painter.setMatrix(m_state.matrix, false);
QFont font;
font.setBold(true);
m_painter.setFont(m_state.font);
- m_painter.drawText(x, y, text);
+ QTextOption opt; // Adjust baseLine etc
+ m_painter.drawText(QRectF(x, y, m_pixmap.width(), m_painter.fontMetrics().height()), text, opt);
+ m_painter.restore();
+ scheduleChange();
+}
+
+void Context2D::strokeText(const QString &text, qreal x, qreal y)
+{
+ beginPainting();
+ m_painter.save();
+ m_painter.setPen(QPen(m_state.fillStyle,0));
+ m_painter.setMatrix(m_state.matrix, false);
+
+ QPainterPath textPath;
+ QFont font = m_state.font;
+ font.setStyleStrategy(QFont::ForceOutline);
+ textPath.addText(x, y, font, text);
+ m_painter.strokePath(textPath, QPen(m_state.fillStyle, m_state.lineWidth));
m_painter.restore();
scheduleChange();
}
diff --git a/src/context2d.h b/src/context2d.h
index dfc3c10..46b0644 100644
--- a/src/context2d.h
+++ b/src/context2d.h
@@ -123,6 +123,7 @@ class Context2D : public QObject
Q_PROPERTY(QString shadowColor READ shadowColor WRITE setShadowColor)
// fonts
Q_PROPERTY(QString font READ font WRITE setFont)
+ Q_PROPERTY(QString textBaseline READ textBaseline WRITE setTextBaseline)
public:
Context2D(QObject *parent = 0);
@@ -162,6 +163,8 @@ public:
void setFont(const QString &font);
QString font();
+ void setTextBaseline(const QString &font);
+ QString textBaseline();
// shadows
qreal shadowOffsetX() const; // (default 0)
@@ -179,6 +182,7 @@ public slots:
void restore(); // pop state stack and restore state
void fillText(const QString &text, qreal x, qreal y);
+ void strokeText(const QString &text, qreal x, qreal y);
void setInPaint(bool val){m_inPaint = val;}
void scale(qreal x, qreal y);