Add the dive computer text.

Added the dive computer text on the bottom left side of the new Profile.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-01-21 10:48:26 -02:00 committed by Dirk Hohndel
parent 63c1a1b3e9
commit caba6500d6
4 changed files with 24 additions and 9 deletions

View file

@ -12,7 +12,7 @@
DiveTextItem::DiveTextItem(QGraphicsItem* parent): QGraphicsItemGroup(parent),
textBackgroundItem(NULL),
textItem(NULL),
internalAlignFlags(0)
internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter)
{
setFlag(ItemIgnoresTransformations);
}
@ -31,13 +31,18 @@ void DiveTextItem::setBrush(const QBrush& b)
void DiveTextItem::setText(const QString& t)
{
text = t;
internalText = t;
updateText();
}
const QString& DiveTextItem::text()
{
return internalText;
}
void DiveTextItem::updateText()
{
if(!internalAlignFlags || text.isEmpty())
if(internalText.isEmpty())
return;
delete textItem;
@ -49,7 +54,7 @@ void DiveTextItem::updateText()
QPainterPath textPath;
qreal xPos = 0, yPos = 0;
QRectF rect = fm.boundingRect(text);
QRectF rect = fm.boundingRect(internalText);
yPos = (internalAlignFlags & Qt::AlignTop) ? -rect.height() :
(internalAlignFlags & Qt::AlignBottom) ? +rect.height() :
/*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4;
@ -58,7 +63,7 @@ void DiveTextItem::updateText()
(internalAlignFlags & Qt::AlignHCenter) ? -rect.width()/2 :
/* (internalAlignFlags & Qt::AlignRight) */ -rect.width();
textPath.addText( xPos, yPos, fnt, text);
textPath.addText( xPos, yPos, fnt, internalText);
QPainterPathStroker stroker;
stroker.setWidth(3);
textBackgroundItem = new QGraphicsPathItem(stroker.createStroke(textPath), this);

View file

@ -18,12 +18,13 @@ public:
void setBrush(const QBrush& brush);
void animatedHide();
void animateMoveTo(qreal x, qreal y);
const QString& text();
private:
void updateText();
int internalAlignFlags;
QGraphicsPathItem *textBackgroundItem;
QGraphicsPathItem *textItem;
QString text;
QString internalText;
color_indice_t colorIndex;
QBrush brush;
};

View file

@ -7,7 +7,7 @@
#include "helpers.h"
#include "profile.h"
#include "diveeventitem.h"
#include "divetextitem.h"
#include <QStateMachine>
#include <QSignalTransition>
#include <QPropertyAnimation>
@ -37,7 +37,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
temperatureItem(NULL),
gasPressureItem(NULL),
cartesianPlane(new DiveCartesianPlane()),
meanDepth(new DiveLineItem())
meanDepth(new DiveLineItem()),
diveComputerText(new DiveTextItem())
{
setScene(new QGraphicsScene());
scene()->setSceneRect(0, 0, 100, 100);
@ -92,10 +93,13 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
cartesianPlane->setLeftAxis(profileYAxis);
scene()->addItem(cartesianPlane);
diveComputerText->setAlignment(Qt::AlignLeft | Qt::AlignTop);
diveComputerText->setBrush(getColor(TIME_TEXT));
// insert in the same way it's declared on the Enum. This is needed so we don't use an map.
QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis <<
timeAxis << depthController << timeController <<
temperatureAxis << cylinderPressureAxis <<
temperatureAxis << cylinderPressureAxis << diveComputerText <<
meanDepth;
Q_FOREACH(QGraphicsItem *item, stateItems) {
scene()->addItem(item);
@ -354,6 +358,9 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
gasPressureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
scene()->addItem(gasPressureItem);
diveComputerText->setText(currentdc->model);
diveComputerText->setPos(1 , sceneRect().height());
emit startProfileState();
}

View file

@ -16,6 +16,7 @@
#include "graphicsview-common.h"
#include "divelineitem.h"
class DiveTextItem;
class TemperatureAxis;
class DiveEventItem;
struct DivePlotDataModel;
@ -81,6 +82,7 @@ private:
DiveGasPressureItem *gasPressureItem;
DiveLineItem *meanDepth;
QList<DiveEventItem*> eventItems;
DiveTextItem *diveComputerText;
};
#endif