profile: activate dragging of tooltipitem

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-06-25 17:31:58 +02:00
parent a527415ac9
commit 4c227aba42
6 changed files with 32 additions and 3 deletions

View file

@ -122,7 +122,8 @@ void ProfileView::clear()
profileScene->clear();
//handles.clear();
//gases.clear();
tooltip.reset();
if (tooltip)
tooltip->setVisible(false);
empty = true;
d = nullptr;
dc = 0;
@ -261,6 +262,11 @@ void ProfileView::wheelEvent(QWheelEvent *event)
void ProfileView::mousePressEvent(QMouseEvent *event)
{
// Handle dragging of items
ChartView::mousePressEvent(event);
if (event->isAccepted())
return;
panning = true;
QPointF pos = mapToScene(event->pos());
panStart(pos.x(), pos.y());
@ -268,8 +274,10 @@ void ProfileView::mousePressEvent(QMouseEvent *event)
event->accept();
}
void ProfileView::mouseReleaseEvent(QMouseEvent *)
void ProfileView::mouseReleaseEvent(QMouseEvent *event)
{
ChartView::mouseReleaseEvent(event);
if (panning) {
panning = false;
unsetCursor();
@ -282,6 +290,8 @@ void ProfileView::mouseReleaseEvent(QMouseEvent *)
void ProfileView::mouseMoveEvent(QMouseEvent *event)
{
ChartView::mouseMoveEvent(event);
QPointF pos = mapToScene(event->pos());
if (panning)
pan(pos.x(), pos.y());

View file

@ -7,6 +7,7 @@
#include "core/membuffer.h"
#include "core/profile.h"
#include "core/qthelper.h" // for decoMode
#include "core/settings/qPrefDisplay.h"
#include <cmath>
#include <QApplication>
@ -37,12 +38,16 @@ static QFont makeFont(double dpr)
ToolTipItem::ToolTipItem(ChartView &view, double dpr) :
ChartRectItem(view, ProfileZValue::ToolTipItem,
QPen(tooltipBorderColor, tooltipBorder),
QBrush(tooltipColor), tooltipBorderRadius),
QBrush(tooltipColor), tooltipBorderRadius,
true),
font(makeFont(dpr)),
fm(font),
fontHeight(fm.height())
{
title = stringToPixmap(ProfileTranslations::tr("Information"));
QPointF pos = qPrefDisplay::tooltip_position();
setPos(pos);
}
QPixmap ToolTipItem::stringToPixmap(const QString &str) const
@ -157,3 +162,8 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
}
setTextureDirty();
}
void ToolTipItem::stopDrag(QPointF pos)
{
qPrefDisplay::set_tooltip_position(pos);
}

View file

@ -22,6 +22,8 @@ private:
double width, height;
QPixmap stringToPixmap(const QString &s) const;
void stopDrag(QPointF pos) override;
};

View file

@ -41,6 +41,10 @@ void ChartItem::setPos(QPointF)
{
}
void ChartItem::stopDrag(QPointF pos)
{
}
static int round_up(double f)
{
return static_cast<int>(ceil(f));

View file

@ -31,6 +31,7 @@ public:
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 stopDrag(QPointF pos); // Called when dragging the item finished
protected:
ChartItem(ChartView &v, size_t z, bool dragable = false);
QSizeF sceneSize() const;

View file

@ -282,6 +282,8 @@ void ChartView::mousePressEvent(QMouseEvent *event)
void ChartView::mouseReleaseEvent(QMouseEvent *event)
{
if (draggedItem) {
QPointF pos = event->localPos();
draggedItem->stopDrag(pos);
draggedItem.reset();
ungrabMouse();
event->accept();