mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
2e2a87e619
Dirk's implementation of the MeanDepth item was correct, but in order to add the 2 strings to it ( one at the begin, one at the end ) I had to put more stuff inside the ProfileWidget that's already packed with graphics items. So I created a new class MeanDepthItem that contains these 2 strings and will get updated whenever the value changes. I also fixed a math inconsistency where I changed RIGHT to LEFT. (wich fixed a few text-placements, and broke others.) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
86 lines
1.9 KiB
C++
86 lines
1.9 KiB
C++
#include "divetextitem.h"
|
|
#include "animationfunctions.h"
|
|
|
|
#include <QPropertyAnimation>
|
|
#include <QApplication>
|
|
#include <QFont>
|
|
#include <QFontMetrics>
|
|
#include <QBrush>
|
|
#include <QPen>
|
|
#include <QDebug>
|
|
|
|
DiveTextItem::DiveTextItem(QGraphicsItem* parent): QGraphicsItemGroup(parent),
|
|
textBackgroundItem(NULL),
|
|
textItem(NULL),
|
|
internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter)
|
|
{
|
|
setFlag(ItemIgnoresTransformations);
|
|
}
|
|
|
|
void DiveTextItem::setAlignment(int alignFlags)
|
|
{
|
|
internalAlignFlags = alignFlags;
|
|
updateText();
|
|
}
|
|
|
|
void DiveTextItem::setBrush(const QBrush& b)
|
|
{
|
|
brush = b;
|
|
updateText();
|
|
}
|
|
|
|
void DiveTextItem::setText(const QString& t)
|
|
{
|
|
internalText = t;
|
|
updateText();
|
|
}
|
|
|
|
const QString& DiveTextItem::text()
|
|
{
|
|
return internalText;
|
|
}
|
|
|
|
void DiveTextItem::updateText()
|
|
{
|
|
if(internalText.isEmpty())
|
|
return;
|
|
|
|
delete textItem;
|
|
delete textBackgroundItem;
|
|
|
|
QFont fnt(qApp->font());
|
|
QFontMetrics fm(fnt);
|
|
|
|
QPainterPath textPath;
|
|
qreal xPos = 0, yPos = 0;
|
|
|
|
QRectF rect = fm.boundingRect(internalText);
|
|
yPos = (internalAlignFlags & Qt::AlignTop) ? -rect.height() :
|
|
(internalAlignFlags & Qt::AlignBottom) ? +rect.height() :
|
|
/*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4;
|
|
|
|
xPos = (internalAlignFlags & Qt::AlignLeft ) ? -rect.width() :
|
|
(internalAlignFlags & Qt::AlignHCenter) ? -rect.width()/2 :
|
|
/* (internalAlignFlags & Qt::AlignRight) */ 0;
|
|
|
|
textPath.addText( xPos, yPos, fnt, internalText);
|
|
QPainterPathStroker stroker;
|
|
stroker.setWidth(3);
|
|
textBackgroundItem = new QGraphicsPathItem(stroker.createStroke(textPath), this);
|
|
textBackgroundItem->setBrush(QBrush(getColor(TEXT_BACKGROUND)));
|
|
textBackgroundItem->setPen(Qt::NoPen);
|
|
|
|
textItem = new QGraphicsPathItem(textPath, this);
|
|
textItem->setBrush(brush);
|
|
textItem->setPen(Qt::NoPen);
|
|
}
|
|
|
|
void DiveTextItem::animatedHide()
|
|
{
|
|
Animations::hide(this);
|
|
}
|
|
|
|
void DiveTextItem::animateMoveTo(qreal x, qreal y)
|
|
{
|
|
Animations::moveTo(this, x, y);
|
|
}
|