mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: convert the "ruler item" to qt-quick
Code is mostly based on the "tooltip item". The dragging code was slightly reworked to be more logical. A "disk item" was added for the handles. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b167e130a4
commit
ea0085fef6
14 changed files with 313 additions and 228 deletions
|
|
@ -37,7 +37,7 @@ QRectF ChartItem::getRect() const
|
|||
return rect;
|
||||
}
|
||||
|
||||
void ChartItem::setPos(QPointF)
|
||||
void ChartItem::drag(QPointF)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +119,11 @@ void ChartPixmapItem::resize(QSizeF size)
|
|||
setTextureDirty();
|
||||
}
|
||||
|
||||
void ChartPixmapItem::drag(QPointF pos)
|
||||
{
|
||||
setPos(pos);
|
||||
}
|
||||
|
||||
void ChartPixmapItem::setPos(QPointF pos)
|
||||
{
|
||||
rect.moveTopLeft(pos);
|
||||
|
|
@ -158,6 +163,8 @@ ChartRectItem::~ChartRectItem()
|
|||
void ChartRectItem::resize(QSizeF size)
|
||||
{
|
||||
ChartPixmapItem::resize(size);
|
||||
if (!painter)
|
||||
return;
|
||||
img->fill(Qt::transparent);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(brush);
|
||||
|
|
@ -175,7 +182,8 @@ void AnimatedChartRectItem::setPixmap(const QPixmap &p, int animSpeed)
|
|||
{
|
||||
if (animSpeed <= 0) {
|
||||
resize(p.size());
|
||||
painter->drawPixmap(0, 0, p, 0, 0, p.width(), p.height());
|
||||
if (painter)
|
||||
painter->drawPixmap(0, 0, p, 0, 0, p.width(), p.height());
|
||||
setTextureDirty();
|
||||
return;
|
||||
}
|
||||
|
|
@ -194,10 +202,47 @@ void AnimatedChartRectItem::anim(double fraction)
|
|||
QSize s(mid(originalSize.width(), pixmap.width(), fraction),
|
||||
mid(originalSize.height(), pixmap.height(), fraction));
|
||||
resize(s);
|
||||
painter->drawPixmap(0, 0, pixmap, 0, 0, s.width(), s.height());
|
||||
if (painter)
|
||||
painter->drawPixmap(0, 0, pixmap, 0, 0, s.width(), s.height());
|
||||
setTextureDirty();
|
||||
}
|
||||
|
||||
ChartDiskItem::ChartDiskItem(ChartView &v, size_t z, const QPen &pen, const QBrush &brush, bool dragable) :
|
||||
ChartPixmapItem(v, z, dragable),
|
||||
pen(pen), brush(brush)
|
||||
{
|
||||
}
|
||||
|
||||
ChartDiskItem::~ChartDiskItem()
|
||||
{
|
||||
}
|
||||
|
||||
void ChartDiskItem::resize(double radius)
|
||||
{
|
||||
ChartPixmapItem::resize(QSizeF(2.0 * radius, 2.0 * radius));
|
||||
if (!painter)
|
||||
return;
|
||||
img->fill(Qt::transparent);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(brush);
|
||||
QSize imgSize = img->size();
|
||||
int width = pen.width();
|
||||
QRect rect(width / 2, width / 2, imgSize.width() - width, imgSize.height() - width);
|
||||
painter->drawEllipse(rect);
|
||||
}
|
||||
|
||||
// Moves the _center_ of the disk to given position.
|
||||
void ChartDiskItem::setPos(QPointF pos)
|
||||
{
|
||||
rect.moveCenter(pos);
|
||||
setPositionDirty();
|
||||
}
|
||||
|
||||
QPointF ChartDiskItem::getPos() const
|
||||
{
|
||||
return rect.center();
|
||||
}
|
||||
|
||||
ChartTextItem::ChartTextItem(ChartView &v, size_t z, const QFont &f, const std::vector<QString> &text, bool center) :
|
||||
ChartPixmapItem(v, z), f(f), center(center)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public:
|
|||
const bool dragable; // Item can be dragged with the mouse. Must be set in constructor.
|
||||
virtual ~ChartItem(); // Attention: must only be called by render thread.
|
||||
QRectF getRect() const;
|
||||
virtual void setPos(QPointF pos); // Called when dragging the item
|
||||
virtual void drag(QPointF pos); // Called when dragging the item
|
||||
virtual void stopDrag(QPointF pos); // Called when dragging the item finished
|
||||
protected:
|
||||
ChartItem(ChartView &v, size_t z, bool dragable = false);
|
||||
|
|
@ -81,7 +81,8 @@ public:
|
|||
ChartPixmapItem(ChartView &v, size_t z, bool dragable = false);
|
||||
~ChartPixmapItem();
|
||||
|
||||
void setPos(QPointF pos) override;
|
||||
virtual void setPos(QPointF pos);
|
||||
void drag(QPointF pos) override; // calls setPos() by default
|
||||
void setScale(double scale);
|
||||
void render() override;
|
||||
protected:
|
||||
|
|
@ -131,6 +132,19 @@ private:
|
|||
QSize originalSize;
|
||||
};
|
||||
|
||||
// A solid disk, potentially with border.
|
||||
class ChartDiskItem : public ChartPixmapItem {
|
||||
public:
|
||||
ChartDiskItem(ChartView &v, size_t z, const QPen &pen, const QBrush &brush, bool dragable = false);
|
||||
~ChartDiskItem();
|
||||
void resize(double radius);
|
||||
void setPos(QPointF pos) override;
|
||||
QPointF getPos() const;
|
||||
private:
|
||||
QPen pen;
|
||||
QBrush brush;
|
||||
};
|
||||
|
||||
// Attention: text is only drawn after calling setColor()!
|
||||
class ChartTextItem : public ChartPixmapItem {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ void ChartView::mouseMoveEvent(QMouseEvent *event)
|
|||
QSizeF sceneSize = size();
|
||||
if (sceneSize.width() <= 1.0 || sceneSize.height() <= 1.0)
|
||||
return;
|
||||
draggedItem->setPos(event->pos() - dragStartMouse + dragStartItem);
|
||||
draggedItem->drag(event->pos() - dragStartMouse + dragStartItem);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue