mirror of https://github.com/qt/qtdatavis3d.git
Label "skewing" fixed
Task-number: QTRD-2322 Change-Id: Ie4bb95dc4f62bad1fef605461452168ea260fa26 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Mika Salmela <mika.salmela@digia.com>
This commit is contained in:
parent
9f8f25a8b5
commit
5261fd6733
|
@ -173,7 +173,7 @@ int AxisRenderCache::maxLabelWidth(const QStringList &labels) const
|
|||
{
|
||||
int labelWidth = 0;
|
||||
QFont labelFont = m_font;
|
||||
labelFont.setPointSize(50);
|
||||
labelFont.setPointSize(textureFontSize);
|
||||
QFontMetrics labelFM(labelFont);
|
||||
for (int i = 0; i < labels.size(); i++) {
|
||||
int newWidth = labelFM.width(labels.at(i));
|
||||
|
|
|
@ -216,7 +216,7 @@ void Bars3DRenderer::updateScene(Q3DScene *scene)
|
|||
scene->setUnderSideCameraEnabled(m_hasNegativeValues);
|
||||
if (m_hasHeightAdjustmentChanged) {
|
||||
// Set initial camera position. Also update if height adjustment has changed.
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp),
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance + zComp),
|
||||
QVector3D(0.0f, -m_yAdjustment, zComp),
|
||||
QVector3D(0.0f, 1.0f, 0.0f));
|
||||
m_hasHeightAdjustmentChanged = false;
|
||||
|
@ -363,10 +363,8 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel,
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glCullFace(GL_BACK);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Draw labels for axes
|
||||
BarRenderItem *dummyItem(0);
|
||||
|
@ -439,8 +437,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel,
|
|||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone)
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Release label shader
|
||||
|
@ -1233,10 +1230,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
|
|||
m_labelShader->bind();
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Calculate the positions for row and column labels and store them
|
||||
for (int row = 0; row != m_cachedRowCount; row++) {
|
||||
|
@ -1472,8 +1467,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
|
|||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone)
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// Release label shader
|
||||
m_labelShader->release();
|
||||
|
|
|
@ -309,10 +309,11 @@ void Drawer::drawLabel(const AbstractRenderItem &item, const LabelItem &labelIte
|
|||
modelMatrix.rotate(rotation.x(), 1.0f, 0.0f, 0.0f);
|
||||
|
||||
if (useDepth && !rotateAlong) {
|
||||
qreal yComp = qreal(qRadiansToDegrees(qTan(positionComp.y() / cameraDistance)));
|
||||
// Apply negative camera rotations to keep labels facing camera
|
||||
QPointF camRotations = camera->rotations();
|
||||
modelMatrix.rotate(-camRotations.x(), 0.0f, 1.0f, 0.0f);
|
||||
modelMatrix.rotate(-camRotations.y(), 1.0f, 0.0f, 0.0f);
|
||||
modelMatrix.rotate(-camRotations.y() - yComp, 1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
// Scale label based on text size
|
||||
|
|
|
@ -170,7 +170,7 @@ void Scatter3DRenderer::updateScene(Q3DScene *scene)
|
|||
|
||||
if (m_hasHeightAdjustmentChanged) {
|
||||
// Set initial m_cachedScene->activeCamera() position. Also update if height adjustment has changed.
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp),
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance + zComp),
|
||||
QVector3D(0.0f, 0.0f, zComp),
|
||||
QVector3D(0.0f, 1.0f, 0.0f));
|
||||
m_hasHeightAdjustmentChanged = false;
|
||||
|
@ -1071,10 +1071,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
|
|||
m_labelShader->bind();
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Z Labels
|
||||
if (m_axisCacheZ.segmentCount() > 0) {
|
||||
|
@ -1333,7 +1331,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
|
|||
QVector3D(0.0f, 0.0f, zComp),
|
||||
QVector3D(0.0f, 0.0f, 0.0f), 0,
|
||||
m_cachedSelectionMode, m_labelShader,
|
||||
m_labelObj, m_cachedScene->activeCamera(), true, false, Drawer::LabelMid);
|
||||
m_labelObj, m_cachedScene->activeCamera(), true, false,
|
||||
Drawer::LabelMid);
|
||||
|
||||
// Reset label update flag; they should have been updated when we get here
|
||||
m_updateLabels = false;
|
||||
|
@ -1341,8 +1340,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
|
|||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone)
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// Release label shader
|
||||
m_labelShader->release();
|
||||
|
|
|
@ -281,7 +281,7 @@ void Surface3DRenderer::updateScene(Q3DScene *scene)
|
|||
// Set initial camera position
|
||||
// X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later
|
||||
if (m_hasHeightAdjustmentChanged) {
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp),
|
||||
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance + zComp),
|
||||
QVector3D(0.0f, 0.0f, zComp),
|
||||
QVector3D(0.0f, 1.0f, 0.0f));
|
||||
// For now this is used just to make things once. Proper use will come
|
||||
|
@ -1006,10 +1006,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
|
|||
// Draw axis labels
|
||||
m_labelShader->bind();
|
||||
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Z Labels
|
||||
QVector3D positionZComp(0.0f, 0.0f, zComp);
|
||||
|
@ -1179,8 +1177,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
|
|||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (m_cachedLabelTransparency > QDataVis::TransparencyNone)
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// Release label shader
|
||||
m_labelShader->release();
|
||||
|
|
|
@ -40,6 +40,10 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
|
|||
// Constants used in several files
|
||||
// Compensation for z position; move all objects to positive z, as shader can't handle negative values correctly
|
||||
const GLfloat zComp = 10.0f;
|
||||
// Distance from camera to origin
|
||||
const GLfloat cameraDistance = 6.0f;
|
||||
// Size of font to be used in label texture rendering. Doesn't affect the actual font size.
|
||||
const int textureFontSize = 50;
|
||||
// Default light position. To have shadows working correctly, light should be as far as camera, or a bit further
|
||||
// y position is added to the minimum height (or can be thought to be that much above or below the camera)
|
||||
const QVector3D defaultLightPos = QVector3D(0.0f, 0.5f, zComp);
|
||||
|
|
|
@ -52,7 +52,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
|
|||
GLuint paddingHeight = 15;
|
||||
// Calculate text dimensions
|
||||
QFont valueFont = font;
|
||||
valueFont.setPointSize(50);
|
||||
valueFont.setPointSize(textureFontSize);
|
||||
QFontMetrics valueFM(valueFont);
|
||||
int valueStrWidth = valueFM.width(text);
|
||||
if (maxLabelWidth && QDataVis::TransparencyNoBackground != transparency)
|
||||
|
@ -88,9 +88,9 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
|
|||
// Paint text
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
painter.setFont(valueFont);
|
||||
switch (transparency) {
|
||||
case QDataVis::TransparencyNoBackground: {
|
||||
painter.setFont(valueFont);
|
||||
painter.setPen(txtColor);
|
||||
#if defined(Q_OS_ANDROID)
|
||||
painter.drawText((labelSize.width() - valueStrWidth) / 2.0f,
|
||||
|
@ -108,12 +108,14 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
|
|||
}
|
||||
case QDataVis::TransparencyFromTheme: {
|
||||
painter.setBrush(QBrush(bgrColor));
|
||||
if (borders)
|
||||
if (borders) {
|
||||
painter.setPen(QPen(QBrush(txtColor), 5, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
|
||||
else
|
||||
painter.drawRoundedRect(5, 5, labelSize.width() - 10, labelSize.height() - 10,
|
||||
10.0, 10.0);
|
||||
} else {
|
||||
painter.setPen(bgrColor);
|
||||
painter.drawRoundedRect(0, 0, labelSize.width(), labelSize.height(), 10.0, 10.0f);
|
||||
painter.setFont(valueFont);
|
||||
painter.drawRoundedRect(0, 0, labelSize.width(), labelSize.height(), 10.0, 10.0);
|
||||
}
|
||||
painter.setPen(txtColor);
|
||||
painter.drawText((labelSize.width() - valueStrWidth) / 2.0f,
|
||||
(labelSize.height() - valueStrHeight) / 2.0f,
|
||||
|
@ -123,13 +125,16 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
|
|||
break;
|
||||
}
|
||||
case QDataVis::TransparencyNone: {
|
||||
painter.setBrush(QBrush(bgrColor));
|
||||
if (borders)
|
||||
painter.setPen(QPen(QBrush(txtColor), 7.5));
|
||||
else
|
||||
painter.setPen(bgrColor);
|
||||
painter.drawRect(0, 0, labelSize.width(), labelSize.height());
|
||||
painter.setFont(valueFont);
|
||||
QColor labelColor = QColor(bgrColor);
|
||||
labelColor.setAlphaF(1.0);
|
||||
painter.setBrush(QBrush(labelColor));
|
||||
if (borders) {
|
||||
painter.setPen(QPen(QBrush(txtColor), 7.5, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
|
||||
painter.drawRect(7.5, 7.5, labelSize.width() - 15, labelSize.height() - 15);
|
||||
} else {
|
||||
painter.setPen(labelColor);
|
||||
painter.drawRect(0, 0, labelSize.width(), labelSize.height());
|
||||
}
|
||||
painter.setPen(txtColor);
|
||||
painter.drawText((labelSize.width() - valueStrWidth) / 2.0f,
|
||||
(labelSize.height() - valueStrHeight) / 2.0f,
|
||||
|
|
|
@ -468,7 +468,7 @@ void ChartModifier::changeTransparency()
|
|||
m_chart->setLabelTransparency((QDataVis::LabelTransparency)transparency);
|
||||
|
||||
if (++transparency > QDataVis::TransparencyNoBackground)
|
||||
transparency = QDataVis::TransparencyFromTheme;
|
||||
transparency = QDataVis::TransparencyNone;
|
||||
}
|
||||
|
||||
void ChartModifier::changeSelectionMode()
|
||||
|
|
Loading…
Reference in New Issue