diff options
Diffstat (limited to 'src/datavis3d/utils/utils.cpp')
-rw-r--r-- | src/datavis3d/utils/utils.cpp | 93 |
1 files changed, 43 insertions, 50 deletions
diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp index 89068c01..c6a17eae 100644 --- a/src/datavis3d/utils/utils.cpp +++ b/src/datavis3d/utils/utils.cpp @@ -60,16 +60,11 @@ QVector3D Utils::vectorFromColor(const QColor &color) return QVector3D(color.redF(), color.greenF(), color.blueF()); } -void Utils::printText(QPainter *painter, const QString &text, const QSize &position - , bool absoluteCoords, qreal rotation, qreal scale) +void Utils::printText(QPainter *painter, const QString &text, const QSize &position, + bool absoluteCoords, qreal rotation, qreal scale) { 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); @@ -85,40 +80,38 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit 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); #if 0 // Hack solution, as drawRect doesn't work - painter->drawText(position.width() - (bgrStrLen / 2) - , position.height() - bgrHeight - , bgrStrLen, bgrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , bgrStr); + painter->drawText(position.width() - (bgrStrLen / 2), + position.height() - 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.width() - (valueStrLen / 2) - , position.height() - bgrHeight - , valueStrLen, bgrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , text); + painter->drawText(position.width() - (valueStrLen / 2), + position.height() - bgrHeight, + valueStrLen, bgrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); #else //qDebug() << painter->window() << painter->viewport(); painter->scale(scale, scale); if (absoluteCoords) { // This assumes absolute screen coordinates - painter->translate(position.width() - (((float)bgrStrLen / 2.0f) * cos(rotation * m_pi / 180.0f)) - + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)) - , position.height() + painter->translate(position.width() - (((float)bgrStrLen / 2.0f) + * cos(rotation * m_pi / 180.0f)) + + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)), + position.height() - ((((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.width() - (((float)bgrStrLen / 2) * cos(rotation * m_pi / 180.0f)) - + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)) - , painter->window().height() - position.height() + painter->translate(position.width() - (((float)bgrStrLen / 2.0f) + * cos(rotation * m_pi / 180.0f)) + + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)), + painter->window().height() - position.height() - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f)) + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f)))); } @@ -126,24 +119,24 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit // - ((((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 - , Qt::AlignCenter | Qt::AlignVCenter - , bgrStr); + painter->drawText(0, 0, + bgrStrLen, bgrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + bgrStr); painter->setPen(Qt::lightGray); // TODO: Use lightGray, as nothing works painter->setFont(valueFont); - painter->drawText(6, 0 - , valueStrLen, bgrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , text); + painter->drawText(6, 0, + valueStrLen, bgrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); painter->resetTransform(); #endif painter->restore(); } -QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor - , const QColor &txtColor - , Q3DBars::LabelTransparency transparency) +QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor, + const QColor &txtColor, + Q3DBars::LabelTransparency transparency) { // Calculate text dimensions QFont valueFont = font; @@ -171,10 +164,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo { painter.setFont(valueFont); painter.setPen(txtColor); - painter.drawText(0, 0 - , valueStrWidth, valueStrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , text); + painter.drawText(0, 0, + valueStrWidth, valueStrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); break; } case Q3DBars::TransparencyFromTheme: @@ -184,10 +177,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo painter.drawRoundedRect(0, 0, labelSize.width(), labelSize.height(), 10.0, 10.0f); painter.setFont(valueFont); painter.setPen(txtColor); - painter.drawText(15, 15 - , valueStrWidth, valueStrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , text); + painter.drawText(15, 15, + valueStrWidth, valueStrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); break; } case Q3DBars::TransparencyNone: @@ -197,10 +190,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo painter.drawRect(0, 0, labelSize.width(), labelSize.height()); painter.setFont(valueFont); painter.setPen(txtColor); - painter.drawText(15, 15 - , valueStrWidth, valueStrHeight - , Qt::AlignCenter | Qt::AlignVCenter - , text); + painter.drawText(15, 15, + valueStrWidth, valueStrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); break; } } |