summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/utils
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-04-09 08:25:17 +0300
committerMika Salmela <mika.salmela@digia.com>2013-04-09 09:36:55 +0300
commita5aa4f957579636caf6e0e78e5bbc54848a1e13f (patch)
tree198e5d40f20a59bdc72dca056c6dce88e8dc1ead /src/datavis3d/utils
parent19ad20b9f5f8ee6fe11fdcc6391f45afba8300bc (diff)
Moved text printing to Utils -class
Fixed examples Change-Id: Idfb0eb511cb03ac4f038c957f0b93bb5736e6b05 Change-Id: Idfb0eb511cb03ac4f038c957f0b93bb5736e6b05 Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavis3d/utils')
-rw-r--r--src/datavis3d/utils/utils.cpp48
-rw-r--r--src/datavis3d/utils/utils_p.h4
2 files changed, 52 insertions, 0 deletions
diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp
index fe0b9c5a..6a45b1f4 100644
--- a/src/datavis3d/utils/utils.cpp
+++ b/src/datavis3d/utils/utils.cpp
@@ -43,6 +43,8 @@
#include <QVector3D>
#include <QColor>
+#include <QPainter>
+#include <QPoint>
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
@@ -51,4 +53,50 @@ QVector3D Utils::vectorFromColor(const QColor &color)
return QVector3D(color.redF(), color.greenF(), color.blueF());
}
+void Utils::printText(QPainter *painter, const QString &text, const QPoint &position)
+{
+ painter->save();
+ painter->setCompositionMode(QPainter::CompositionMode_Source);
+ // TODO: None of the commented-out stuff works..
+ //painter->setBackgroundMode(Qt::OpaqueMode);
+ //painter->setBackground(QBrush(d_ptr->m_textBackgroundColor));
+ //painter->setBrush(QBrush(d_ptr->m_textBackgroundColor));
+ //painter->setPen(d_ptr->m_textBackgroundColor);
+ painter->setPen(Qt::black); // TODO: Use black, as nothing works
+ QFont bgrFont = QFont(QStringLiteral("Arial"), 17);
+ QFont valueFont = QFont(QStringLiteral("Arial"), 11);
+ valueFont.setBold(true);
+ painter->setFont(bgrFont);
+ QFontMetrics valueFM(valueFont);
+ QFontMetrics bgrFM(bgrFont);
+ int valueStrLen = valueFM.width(text);
+ int bgrStrLen = 0;
+ int bgrHeight = valueFM.height() + 8;
+ QString bgrStr = QString();
+ do {
+ bgrStr.append(QStringLiteral("I"));
+ bgrStrLen = bgrFM.width(bgrStr);
+ } while (bgrStrLen <= (valueStrLen + 8));
+ //int bgrLen = valueStrLen + 10;
+ //painter->drawRoundedRect(data->d_ptr->position().x() - (bgrLen / 2)
+ // , data->d_ptr->position().y() - 30
+ // , bgrLen, 30, 10.0, 10.0);
+ // Hack solution, as drawRect doesn't work
+ painter->drawText(position.x() - (bgrStrLen / 2)
+ , position.y() - bgrHeight
+ , bgrStrLen, bgrHeight
+ , Qt::AlignCenter | Qt::AlignVCenter
+ , bgrStr);
+ //painter->setPen(d_ptr->m_textColor);
+ painter->setPen(Qt::lightGray); // TODO: Use lightGray, as nothing works
+ painter->setFont(valueFont);
+ painter->drawText(position.x() - (valueStrLen / 2)
+ , position.y() - bgrHeight
+ , valueStrLen, bgrHeight
+ , Qt::AlignCenter | Qt::AlignVCenter
+ , text);
+ painter->restore();
+
+}
+
QTCOMMERCIALDATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/utils/utils_p.h b/src/datavis3d/utils/utils_p.h
index 11ddf61f..4e210fde 100644
--- a/src/datavis3d/utils/utils_p.h
+++ b/src/datavis3d/utils/utils_p.h
@@ -46,6 +46,9 @@
class QVector3D;
class QColor;
+class QPainter;
+class QString;
+class QPoint;
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
@@ -53,6 +56,7 @@ class Utils
{
public:
static QVector3D vectorFromColor(const QColor &color);
+ static void printText(QPainter *painter, const QString &text, const QPoint &position);
};
QTCOMMERCIALDATAVIS3D_END_NAMESPACE