2015-07-17 16:09:42 +00:00
|
|
|
#include "qmlprofile.h"
|
2015-11-05 15:59:09 +00:00
|
|
|
#include "profile-widget/profilewidget2.h"
|
|
|
|
#include "subsurface-core/dive.h"
|
2015-07-25 16:10:51 +00:00
|
|
|
#include <QTransform>
|
2015-07-17 16:09:42 +00:00
|
|
|
|
|
|
|
QMLProfile::QMLProfile(QQuickItem *parent) :
|
2015-12-29 17:50:47 +00:00
|
|
|
QQuickPaintedItem(parent),
|
|
|
|
m_margin(0)
|
2015-07-17 16:09:42 +00:00
|
|
|
{
|
2015-12-29 17:51:34 +00:00
|
|
|
setAntialiasing(true);
|
2015-11-12 00:43:13 +00:00
|
|
|
m_profileWidget = new ProfileWidget2(0);
|
|
|
|
m_profileWidget->setProfileState();
|
2015-12-29 15:15:52 +00:00
|
|
|
m_profileWidget->setPrintMode(true);
|
|
|
|
m_profileWidget->setFontPrintScale(0.8);
|
2015-11-12 00:43:13 +00:00
|
|
|
//m_profileWidget->setGeometry(this->geometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
QMLProfile::~QMLProfile()
|
|
|
|
{
|
|
|
|
m_profileWidget->deleteLater();
|
2015-07-17 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMLProfile::paint(QPainter *painter)
|
|
|
|
{
|
2015-11-12 00:43:13 +00:00
|
|
|
m_profileWidget->render(painter);
|
2015-07-17 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 17:50:47 +00:00
|
|
|
void QMLProfile::setMargin(int margin)
|
|
|
|
{
|
|
|
|
m_margin = margin;
|
|
|
|
}
|
|
|
|
|
2015-07-17 16:09:42 +00:00
|
|
|
QString QMLProfile::diveId() const
|
|
|
|
{
|
|
|
|
return m_diveId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMLProfile::setDiveId(const QString &diveId)
|
|
|
|
{
|
2015-12-26 00:53:57 +00:00
|
|
|
static bool firstRun = true;
|
|
|
|
static QTransform profileTransform;
|
2015-07-17 16:09:42 +00:00
|
|
|
m_diveId = diveId;
|
2015-12-01 23:22:38 +00:00
|
|
|
struct dive *d = get_dive_by_uniq_id(m_diveId.toInt());
|
|
|
|
if (m_diveId.toInt() < 1)
|
|
|
|
return;
|
|
|
|
if (!d)
|
|
|
|
return;
|
2016-01-13 02:05:06 +00:00
|
|
|
//qDebug() << "setDiveId called with pos/size" << x() << y() << width() << height();
|
2015-12-02 19:26:32 +00:00
|
|
|
// set the profile widget's geometry and scale the viewport so
|
|
|
|
// the scene fills it, then plot the dive on that widget
|
2016-01-13 02:05:06 +00:00
|
|
|
// the profile widget doesn't handle subsequent geometry changes well,
|
|
|
|
// so only do it once, then scale the image to the item's dimension.
|
2015-12-26 00:53:57 +00:00
|
|
|
if (firstRun) {
|
|
|
|
firstRun = false;
|
2015-12-30 13:22:30 +00:00
|
|
|
m_profileWidget->setGeometry(QRect(x(), y(), width(), height()));
|
2015-12-26 00:53:57 +00:00
|
|
|
}
|
2016-01-13 02:05:06 +00:00
|
|
|
// scale the profile widget's image to devicePixelRatio and a magic number
|
|
|
|
qreal dpr = (80 * (m_devicePixelRatio > 2 ? m_devicePixelRatio : 1.0));
|
|
|
|
qreal sx = width() / dpr;
|
|
|
|
qreal sy = height() / dpr;
|
|
|
|
// don't forget to reset, otherwise we're
|
|
|
|
// scaling scaled items, growing it bigger and bigger with every pass
|
|
|
|
profileTransform.reset();
|
|
|
|
profileTransform.scale(sx, sy);
|
|
|
|
//qDebug() << "scale:" << sx << sy;
|
|
|
|
|
2015-12-02 19:26:32 +00:00
|
|
|
m_profileWidget->setTransform(profileTransform);
|
2015-12-26 00:53:57 +00:00
|
|
|
qDebug() << "effective transformation:" <<
|
|
|
|
m_profileWidget->transform().m11() <<
|
|
|
|
m_profileWidget->transform().m12() <<
|
|
|
|
m_profileWidget->transform().m13() <<
|
|
|
|
m_profileWidget->transform().m21() <<
|
|
|
|
m_profileWidget->transform().m22() <<
|
|
|
|
m_profileWidget->transform().m23() <<
|
|
|
|
m_profileWidget->transform().m31() <<
|
|
|
|
m_profileWidget->transform().m32() <<
|
|
|
|
m_profileWidget->transform().m33();
|
2015-12-01 23:22:38 +00:00
|
|
|
m_profileWidget->plotDive(d);
|
2016-01-13 02:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal QMLProfile::devicePixelRatio() const
|
|
|
|
{
|
|
|
|
return m_devicePixelRatio;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMLProfile::setDevicePixelRatio(qreal dpr)
|
|
|
|
{
|
|
|
|
if (dpr != m_devicePixelRatio) {
|
|
|
|
m_devicePixelRatio = dpr;
|
|
|
|
emit devicePixelRatioChanged();
|
|
|
|
}
|
2015-07-17 16:09:42 +00:00
|
|
|
}
|