summaryrefslogtreecommitdiffstats
path: root/src/datavis3d
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-04-10 11:00:43 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-04-10 11:01:09 +0300
commitd54dad5da5aca15230889dd801a591b35a0afcb0 (patch)
treea38914e7c4621736a2922176712bd8050e78dd82 /src/datavis3d
parent36c896c95d31ad477e8ef3322e3b26a5c2b6c315 (diff)
Fixed label printing on bars in zoom view
Note: does not work when screen height is larger than width yet Change-Id: I7d109fa251484afadf70784c4ff417a1b62eca3d Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavis3d')
-rw-r--r--src/datavis3d/engine/q3dbars.cpp84
-rw-r--r--src/datavis3d/utils/utils.cpp25
-rw-r--r--src/datavis3d/utils/utils_p.h2
3 files changed, 81 insertions, 30 deletions
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index 242309d3..8c030f7f 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -160,6 +160,10 @@ void Q3DBars::render(QPainter *painter)
Utils::printText(painter, data->d_ptr->valueStr(), data->d_ptr->position());
} else if (d_ptr->m_zoomActivated) {
glDisable(GL_DEPTH_TEST);
+ float scale = 1.0f;
+ //painter->setWindow(d_ptr->m_zoomViewPort); // Using these causes unwanted transformations
+ //painter->setViewport(d_ptr->m_zoomViewPort); // Using these causes unwanted transformations
+ //painter->setViewTransformEnabled(false); // Using these causes unwanted transformations
for (int col = 0; col < d_ptr->m_zoomSelection->d_ptr->row().size(); col++) {
// print value of each column
QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(col);
@@ -169,26 +173,29 @@ void Q3DBars::render(QPainter *painter)
float coordX;
if (ZoomColumn == d_ptr->m_selectionMode) {
coordX = (-(item->d_ptr->translation().z() - zComp) // flip front to left
- * d_ptr->m_zoomViewPort.width() / 2
- + d_ptr->m_zoomViewPort.width()) / 2;
- //coordX = ((item->d_ptr->translation().z() - zComp)
- // * d_ptr->m_zoomViewPort.height()
- // + d_ptr->m_zoomViewPort.width()) / 2;
+ * d_ptr->m_zoomViewPort.height() / 2.0f
+ + d_ptr->m_zoomViewPort.width()) / 2.0f;
} else {
coordX = (item->d_ptr->translation().x()
- * d_ptr->m_zoomViewPort.width() / 2
- + d_ptr->m_zoomViewPort.width()) / 2;
- //coordX = (item->d_ptr->translation().x()
- // * d_ptr->m_zoomViewPort.height()
- // + d_ptr->m_zoomViewPort.width()) / 2;
+ * d_ptr->m_zoomViewPort.height() / 2.0f
+ + d_ptr->m_zoomViewPort.width()) / 2.0f;
}
- float coordY = ((1 - item->d_ptr->translation().y())
- * d_ptr->m_zoomViewPort.height()) / 2;
- QPoint screenCoords(coordX
- , coordY - (d_ptr->m_zoomViewPort.height() / 4)
- * (item->d_ptr->value() / d_ptr->m_heightNormalizer) - 50);
- //qDebug() << "bar" << col << "position on screen" << screenCoords << item->d_ptr->valueStr();
- Utils::printText(painter, item->d_ptr->valueStr(), screenCoords, 45);
+ if (d_ptr->m_zoomViewPort.height() > d_ptr->m_zoomViewPort.width()) {
+ scale = (float)d_ptr->m_zoomViewPort.width()
+ / (float)d_ptr->m_zoomViewPort.height();
+ }
+ //float coordY = ((1.0f - item->d_ptr->translation().y())
+ // * d_ptr->m_zoomViewPort.height()) / 2.0f;
+ // Use a fixed label distance from the bottom of the screen
+ QPoint screenCoords(coordX, 150.0f); // use coord Y for reducing from painter window height to avoid unwanted transformations
+ Utils::printText(painter, item->d_ptr->valueStr(), screenCoords, false, 60.0f, scale);
+ //QPoint screenCoords(coordX, d_ptr->m_zoomViewPort.height() - 100.0f);
+ // Use a label distance from the bottom of the screen based on bar height
+ //QPoint screenCoords(coordX, coordY - (d_ptr->m_zoomViewPort.height() / 4.0f)
+ // * (item->d_ptr->value() / d_ptr->m_heightNormalizer));
+ //qDebug() << "bar" << col << "position on screen" << screenCoords << item->d_ptr->valueStr()
+ // << "viewport:" << d_ptr->m_zoomViewPort.width() << d_ptr->m_zoomViewPort.height();
+ //Utils::printText(painter, item->d_ptr->valueStr(), screenCoords, true, 60.0f);
}
}
}
@@ -217,7 +224,7 @@ void Q3DBars::drawZoomScene()
// Set up projection matrix
QMatrix4x4 projectionMatrix;
- projectionMatrix.perspective(30.0f, (float)d_ptr->m_zoomViewPort.width()
+ projectionMatrix.perspective(45.0f, (float)d_ptr->m_zoomViewPort.width()
/ (float)d_ptr->m_zoomViewPort.height(), 0.1f, 100.0f);
#ifdef ROTATE_ZOOM_SELECTION
@@ -238,10 +245,34 @@ void Q3DBars::drawZoomScene()
#else
// Set view matrix
QMatrix4x4 viewMatrix;
- viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 6.0f + zComp)
+#if 1
+ viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 5.0f + zComp)
+ , QVector3D(0.0f, 0.0f, zComp)
+ , QVector3D(0.0f, 1.0f, 0.0f));
+#else
+ viewMatrix.lookAt(QVector3D(0.0f, 0.0f, d_ptr->m_scaleFactorX + zComp)
, QVector3D(0.0f, 0.0f, zComp)
, QVector3D(0.0f, 1.0f, 0.0f));
- //viewMatrix.scale(1.275f);
+ float zoomwidth;
+ if (ZoomRow == d_ptr->m_selectionMode) {
+ zoomwidth = d_ptr->m_zoomSelection->d_ptr->getItem(0)->d_ptr->translation().x()
+ - d_ptr->m_zoomSelection->d_ptr->getItem(d_ptr->m_zoomSelection->d_ptr->row().size()
+ - 1)->d_ptr->translation().x();
+ zoomwidth *= d_ptr->m_scaleX;
+ } else {
+ zoomwidth = d_ptr->m_zoomSelection->d_ptr->getItem(0)->d_ptr->translation().z()
+ - d_ptr->m_zoomSelection->d_ptr->getItem(d_ptr->m_zoomSelection->d_ptr->row().size()
+ - 1)->d_ptr->translation().z();
+ zoomwidth *= d_ptr->m_scaleZ;
+ }
+ qDebug() << "zoomwidth" << zoomwidth << "inverse / 2" << 0.5f / zoomwidth;
+ viewMatrix.scale(0.5f / zoomwidth);
+#endif
+ if (d_ptr->m_zoomViewPort.height() > d_ptr->m_zoomViewPort.width()) {
+ viewMatrix.scale((float)d_ptr->m_zoomViewPort.width()
+ / (float)d_ptr->m_zoomViewPort.height());
+ // TODO: Center shrunk view
+ }
// Set light position a bit above the camera (depends on do we have row or column zoom)
if (ZoomColumn == d_ptr->m_selectionMode)
@@ -268,7 +299,7 @@ void Q3DBars::drawZoomScene()
else
barPosX = -(item->d_ptr->translation().z() - zComp); // flip z; frontmost bar to the left
modelMatrix.translate(barPosX
- , item->d_ptr->translation().y() - 0.5f
+ , item->d_ptr->translation().y() - 0.5f// TODO: Needs a better system; calculate y position modifier somehow
, zComp);
modelMatrix.scale(QVector3D(d_ptr->m_scaleX, barHeight, d_ptr->m_scaleZ));
@@ -410,7 +441,7 @@ void Q3DBars::drawScene()
glViewport(d_ptr->m_sceneViewPort.x(), d_ptr->m_sceneViewPort.y()
, d_ptr->m_sceneViewPort.width(), d_ptr->m_sceneViewPort.height());
- // Set projection matrix
+ // Set up projection matrix
QMatrix4x4 projectionMatrix;
projectionMatrix.perspective(45.0f, (float)d_ptr->m_sceneViewPort.width()
/ (float)d_ptr->m_sceneViewPort.height(), 0.1f, 100.0f);
@@ -420,6 +451,11 @@ void Q3DBars::drawScene()
, d_ptr->m_zoomLevel
, d_ptr->m_sceneViewPort.width()
, d_ptr->m_sceneViewPort.height());
+ if (d_ptr->m_sceneViewPort.height() > d_ptr->m_sceneViewPort.width()) {
+ viewMatrix.scale((float)d_ptr->m_sceneViewPort.width()
+ / (float)d_ptr->m_sceneViewPort.height());
+ // TODO: Center shrunk view
+ }
// Calculate drawing order
//qDebug() << "viewMatrix z" << viewMatrix.row(0).z(); // jos negatiivinen, käännä bar -piirtojärjestys
@@ -921,9 +957,7 @@ void Q3DBars::resizeEvent(QResizeEvent *event)
else
d_ptr->m_sceneViewPort = QRect(0, 0, width(), height());
d_ptr->m_zoomViewPort = QRect(0, 0, width(), height());
-
- // If orientation changes, we need to scale again
- // TODO: Handle it
+ qDebug() << d_ptr->m_zoomViewPort;
}
void Q3DBars::setBarSpecs(QPointF thickness, QPointF spacing, bool relative)
diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp
index 1d1db3b8..7cad0bea 100644
--- a/src/datavis3d/utils/utils.cpp
+++ b/src/datavis3d/utils/utils.cpp
@@ -58,7 +58,7 @@ QVector3D Utils::vectorFromColor(const QColor &color)
}
void Utils::printText(QPainter *painter, const QString &text, const QPoint &position
- , qreal rotation)
+ , bool absoluteCoords, qreal rotation, qreal scale)
{
painter->save();
painter->setCompositionMode(QPainter::CompositionMode_Source);
@@ -102,9 +102,26 @@ void Utils::printText(QPainter *painter, const QString &text, const QPoint &posi
, Qt::AlignCenter | Qt::AlignVCenter
, text);
#else
- painter->translate(position.x() - ((bgrStrLen / 2) * cos(rotation * m_pi / 180))
- + ((bgrHeight / 2) * sin(rotation * m_pi / 180))
- , position.y() - bgrHeight);
+ //qDebug() << painter->window() << painter->viewport();
+ painter->scale(scale, scale);
+ if (absoluteCoords) {
+ // This assumes absolute screen coordinates
+ painter->translate(position.x() - (((float)bgrStrLen / 2.0f) * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f))
+ , position.y()
+ - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f))));
+ } else {
+ // This calculates y as a distance from screen bottom
+ painter->translate(position.x() - (((float)bgrStrLen / 2) * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f))
+ , painter->window().height() - position.y()
+ - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f))));
+ }
+ //qDebug() << painter->window().height() - position.y()
+ // - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f))
+ // + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f)));
painter->rotate(rotation);
painter->drawText(0, 0
, bgrStrLen, bgrHeight
diff --git a/src/datavis3d/utils/utils_p.h b/src/datavis3d/utils/utils_p.h
index 942d3842..9752066e 100644
--- a/src/datavis3d/utils/utils_p.h
+++ b/src/datavis3d/utils/utils_p.h
@@ -57,7 +57,7 @@ class Utils
public:
static QVector3D vectorFromColor(const QColor &color);
static void printText(QPainter *painter, const QString &text, const QPoint &position
- , qreal rotation = 0);
+ , bool absoluteCoords = true, qreal rotation = 0, qreal scale = 1.0f);
};
QTCOMMERCIALDATAVIS3D_END_NAMESPACE