2021-01-01 21:03:26 +00:00
|
|
|
#include "informationbox.h"
|
|
|
|
#include "statscolors.h"
|
|
|
|
#include "zvalues.h"
|
|
|
|
|
|
|
|
#include <QFontMetrics>
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
#include <QGraphicsScene>
|
2021-01-01 21:03:26 +00:00
|
|
|
|
|
|
|
static const QColor informationBorderColor(Qt::black);
|
|
|
|
static const QColor informationColor(0xff, 0xff, 0x00, 192); // Note: fourth argument is opacity
|
|
|
|
static const int informationBorder = 2;
|
2021-01-03 11:49:26 +00:00
|
|
|
static const double informationBorderRadius = 4.0; // Radius of rounded corners
|
2021-01-01 21:03:26 +00:00
|
|
|
static const int distanceFromPointer = 10; // Distance to place box from mouse pointer or scatter item
|
|
|
|
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
InformationBox::InformationBox() : RoundRectItem(informationBorderRadius, nullptr)
|
2021-01-01 21:03:26 +00:00
|
|
|
{
|
|
|
|
setPen(QPen(informationBorderColor, informationBorder));
|
|
|
|
setBrush(informationColor);
|
|
|
|
setZValue(ZValues::informationBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InformationBox::setText(const std::vector<QString> &text, QPointF pos)
|
|
|
|
{
|
|
|
|
width = height = 0.0;
|
|
|
|
textItems.clear();
|
|
|
|
|
|
|
|
for (const QString &s: text) {
|
|
|
|
if (!s.isEmpty())
|
|
|
|
addLine(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
width += 4.0 * informationBorder;
|
|
|
|
height += 4.0 * informationBorder;
|
|
|
|
|
|
|
|
// Setting the position will also set the proper size
|
|
|
|
setPos(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InformationBox::setPos(QPointF pos)
|
|
|
|
{
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
QRectF plotArea = scene()->sceneRect();
|
2021-01-01 21:03:26 +00:00
|
|
|
|
|
|
|
double x = pos.x() + distanceFromPointer;
|
2021-01-06 13:33:06 +00:00
|
|
|
if (x + width >= plotArea.right()) {
|
|
|
|
if (pos.x() - width >= plotArea.x())
|
|
|
|
x = pos.x() - width;
|
|
|
|
else
|
|
|
|
x = pos.x() - width / 2.0;
|
|
|
|
}
|
2021-01-01 21:03:26 +00:00
|
|
|
double y = pos.y() + distanceFromPointer;
|
2021-01-06 13:33:06 +00:00
|
|
|
if (y + height >= plotArea.bottom()) {
|
|
|
|
if (pos.y() - height >= plotArea.y())
|
|
|
|
y = pos.y() - height;
|
|
|
|
else
|
|
|
|
y = pos.y() - height / 2.0;
|
|
|
|
}
|
2021-01-01 21:03:26 +00:00
|
|
|
|
|
|
|
setRect(x, y, width, height);
|
|
|
|
double actY = y + 2.0 * informationBorder;
|
|
|
|
for (auto &item: textItems) {
|
|
|
|
item->setPos(QPointF(x + 2.0 * informationBorder, actY));
|
|
|
|
actY += item->boundingRect().height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InformationBox::addLine(const QString &s)
|
|
|
|
{
|
|
|
|
textItems.emplace_back(new QGraphicsSimpleTextItem(s, this));
|
|
|
|
QGraphicsSimpleTextItem &item = *textItems.back();
|
|
|
|
item.setBrush(QBrush(darkLabelColor));
|
|
|
|
item.setPos(QPointF(0.0, height));
|
|
|
|
item.setFont(font);
|
|
|
|
item.setZValue(ZValues::informationBox);
|
|
|
|
QRectF rect = item.boundingRect();
|
|
|
|
width = std::max(width, rect.width());
|
|
|
|
height += rect.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to stay within three-thirds of the chart height
|
|
|
|
int InformationBox::recommendedMaxLines() const
|
|
|
|
{
|
|
|
|
QFontMetrics fm(font);
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
int maxHeight = static_cast<int>(scene()->sceneRect().height());
|
2021-01-01 21:03:26 +00:00
|
|
|
return maxHeight * 2 / fm.height() / 3;
|
|
|
|
}
|