mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
profile: move DiveHandler to profile-widget folder
These are the small dots that describe dragable points on the profile when in the planner. It makes no sense to have them in desktop's planner-widget code. They belong to the profile. Therefore, move the code there and compile on mobile. Not everything can be compiled on mobile for now, but it is a start. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
cd33d88768
commit
3b2ae46eb8
9 changed files with 147 additions and 124 deletions
|
@ -157,6 +157,7 @@ SOURCES += subsurface-mobile-main.cpp \
|
|||
profile-widget/divepixmapitem.cpp \
|
||||
profile-widget/divetooltipitem.cpp \
|
||||
profile-widget/tankitem.cpp \
|
||||
profile-widget/divehandler.cpp \
|
||||
profile-widget/divelineitem.cpp \
|
||||
profile-widget/diverectitem.cpp \
|
||||
profile-widget/divetextitem.cpp
|
||||
|
@ -292,6 +293,7 @@ HEADERS += \
|
|||
profile-widget/tankitem.h \
|
||||
profile-widget/animationfunctions.h \
|
||||
profile-widget/divecartesianaxis.h \
|
||||
profile-widget/divehandler.h \
|
||||
profile-widget/divelineitem.h \
|
||||
profile-widget/divepixmapitem.h \
|
||||
profile-widget/diverectitem.h \
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include "profile-widget/profilewidget2.h"
|
||||
#include "qt-models/diveplannermodel.h"
|
||||
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QSettings>
|
||||
#include <QShortcut>
|
||||
#ifndef NO_PRINTING
|
||||
#include <QPrintDialog>
|
||||
|
@ -24,89 +22,6 @@
|
|||
#include <QBuffer>
|
||||
#endif
|
||||
|
||||
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
|
||||
{
|
||||
setRect(-5, -5, 10, 10);
|
||||
setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
|
||||
setBrush(Qt::white);
|
||||
setZValue(2);
|
||||
t.start();
|
||||
}
|
||||
|
||||
int DiveHandler::parentIndex()
|
||||
{
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
||||
return view->handles.indexOf(this);
|
||||
}
|
||||
|
||||
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||
{
|
||||
QMenu m;
|
||||
// Don't have a gas selection for the last point
|
||||
emit released();
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
||||
if (index.sibling(index.row() + 1, index.column()).isValid()) {
|
||||
GasSelectionModel *model = GasSelectionModel::instance();
|
||||
model->repopulate();
|
||||
int rowCount = model->rowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
QAction *action = new QAction(&m);
|
||||
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
||||
action->setData(i);
|
||||
connect(action, &QAction::triggered, this, &DiveHandler::changeGas);
|
||||
m.addAction(action);
|
||||
}
|
||||
}
|
||||
// don't allow removing the last point
|
||||
if (plannerModel->rowCount() > 1) {
|
||||
m.addSeparator();
|
||||
m.addAction(gettextFromC::tr("Remove this point"), this, &DiveHandler::selfRemove);
|
||||
m.exec(event->screenPos());
|
||||
}
|
||||
}
|
||||
|
||||
void DiveHandler::selfRemove()
|
||||
{
|
||||
setSelected(true);
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
||||
view->keyDeleteAction();
|
||||
}
|
||||
|
||||
void DiveHandler::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
||||
plannerModel->gasChange(index.sibling(index.row() + 1, index.column()), action->data().toInt());
|
||||
}
|
||||
|
||||
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (t.elapsed() < 40)
|
||||
return;
|
||||
t.start();
|
||||
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
|
||||
if(view->isPointOutOfBoundaries(event->scenePos()))
|
||||
return;
|
||||
|
||||
QGraphicsEllipseItem::mouseMoveEvent(event);
|
||||
emit moved();
|
||||
}
|
||||
|
||||
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
emit released();
|
||||
}
|
||||
|
||||
DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0))
|
||||
{
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
|
|
|
@ -2,41 +2,14 @@
|
|||
#ifndef DIVEPLANNER_H
|
||||
#define DIVEPLANNER_H
|
||||
|
||||
#include <QGraphicsPathItem>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QAbstractButton>
|
||||
#include <QDateTime>
|
||||
#include <QSignalMapper>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
class QListView;
|
||||
class QModelIndex;
|
||||
class DivePlannerPointsModel;
|
||||
|
||||
class DiveHandler : public QObject, public QGraphicsEllipseItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveHandler();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
signals:
|
||||
void moved();
|
||||
void clicked();
|
||||
void released();
|
||||
private:
|
||||
int parentIndex();
|
||||
public
|
||||
slots:
|
||||
void selfRemove();
|
||||
void changeGas();
|
||||
private:
|
||||
QElapsedTimer t;
|
||||
};
|
||||
|
||||
#include "ui_diveplanner.h"
|
||||
|
||||
class DivePlannerWidget : public QWidget {
|
||||
|
|
|
@ -163,6 +163,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
|
|||
../../profile-widget/divepixmapitem.cpp \
|
||||
../../profile-widget/divetooltipitem.cpp \
|
||||
../../profile-widget/tankitem.cpp \
|
||||
../../profile-widget/divehandler.cpp \
|
||||
../../profile-widget/divelineitem.cpp \
|
||||
../../profile-widget/diverectitem.cpp \
|
||||
../../profile-widget/divetextitem.cpp
|
||||
|
@ -322,6 +323,7 @@ HEADERS += \
|
|||
../../profile-widget/tankitem.h \
|
||||
../../profile-widget/animationfunctions.h \
|
||||
../../profile-widget/divecartesianaxis.h \
|
||||
../../profile-widget/divehandler.h \
|
||||
../../profile-widget/divelineitem.h \
|
||||
../../profile-widget/divepixmapitem.h \
|
||||
../../profile-widget/diverectitem.h \
|
||||
|
|
|
@ -6,6 +6,8 @@ set(SUBSURFACE_PROFILE_LIB_SRCS
|
|||
divecartesianaxis.h
|
||||
diveeventitem.cpp
|
||||
diveeventitem.h
|
||||
divehandler.cpp
|
||||
divehandler.h
|
||||
divelineitem.cpp
|
||||
divelineitem.h
|
||||
divepixmapitem.cpp
|
||||
|
|
95
profile-widget/divehandler.cpp
Normal file
95
profile-widget/divehandler.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "divehandler.h"
|
||||
#include "profilewidget2.h"
|
||||
#include "core/gettextfromc.h"
|
||||
#include "qt-models/diveplannermodel.h"
|
||||
#include "qt-models/models.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QSettings>
|
||||
|
||||
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
|
||||
{
|
||||
setRect(-5, -5, 10, 10);
|
||||
setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
|
||||
setBrush(Qt::white);
|
||||
setZValue(2);
|
||||
t.start();
|
||||
}
|
||||
|
||||
int DiveHandler::parentIndex()
|
||||
{
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
||||
return view->handles.indexOf(this);
|
||||
}
|
||||
|
||||
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||
{
|
||||
QMenu m;
|
||||
// Don't have a gas selection for the last point
|
||||
emit released();
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
||||
if (index.sibling(index.row() + 1, index.column()).isValid()) {
|
||||
GasSelectionModel *model = GasSelectionModel::instance();
|
||||
model->repopulate();
|
||||
int rowCount = model->rowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
QAction *action = new QAction(&m);
|
||||
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
||||
action->setData(i);
|
||||
connect(action, &QAction::triggered, this, &DiveHandler::changeGas);
|
||||
m.addAction(action);
|
||||
}
|
||||
}
|
||||
// don't allow removing the last point
|
||||
if (plannerModel->rowCount() > 1) {
|
||||
m.addSeparator();
|
||||
m.addAction(gettextFromC::tr("Remove this point"), this, &DiveHandler::selfRemove);
|
||||
m.exec(event->screenPos());
|
||||
}
|
||||
}
|
||||
|
||||
void DiveHandler::selfRemove()
|
||||
{
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
setSelected(true);
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
||||
view->keyDeleteAction();
|
||||
#endif
|
||||
}
|
||||
|
||||
void DiveHandler::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
||||
plannerModel->gasChange(index.sibling(index.row() + 1, index.column()), action->data().toInt());
|
||||
}
|
||||
|
||||
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (t.elapsed() < 40)
|
||||
return;
|
||||
t.start();
|
||||
|
||||
ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
|
||||
if(view->isPointOutOfBoundaries(event->scenePos()))
|
||||
return;
|
||||
|
||||
QGraphicsEllipseItem::mouseMoveEvent(event);
|
||||
emit moved();
|
||||
}
|
||||
|
||||
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
emit released();
|
||||
}
|
32
profile-widget/divehandler.h
Normal file
32
profile-widget/divehandler.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#ifndef DIVEHANDLER_HPP
|
||||
#define DIVEHANDLER_HPP
|
||||
|
||||
#include <QGraphicsPathItem>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
class DiveHandler : public QObject, public QGraphicsEllipseItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveHandler();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
signals:
|
||||
void moved();
|
||||
void clicked();
|
||||
void released();
|
||||
private:
|
||||
int parentIndex();
|
||||
public
|
||||
slots:
|
||||
void selfRemove();
|
||||
void changeGas();
|
||||
private:
|
||||
QElapsedTimer t;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,6 +12,7 @@
|
|||
#include "profile-widget/diveeventitem.h"
|
||||
#include "profile-widget/divetextitem.h"
|
||||
#include "profile-widget/divetooltipitem.h"
|
||||
#include "profile-widget/divehandler.h"
|
||||
#include "core/planner.h"
|
||||
#include "core/device.h"
|
||||
#include "profile-widget/ruleritem.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "core/divelist.h"
|
||||
#include "core/errorhelper.h"
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
#include "desktop-widgets/diveplanner.h"
|
||||
#include "desktop-widgets/simplewidgets.h"
|
||||
#include "desktop-widgets/divepicturewidget.h"
|
||||
#include "desktop-widgets/mainwindow.h"
|
||||
|
@ -1003,6 +1003,16 @@ void ProfileWidget2::scale(qreal sx, qreal sy)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool ProfileWidget2::isPointOutOfBoundaries(const QPointF &point) const
|
||||
{
|
||||
double xpos = timeAxis->valueAt(point);
|
||||
double ypos = profileYAxis->valueAt(point);
|
||||
return xpos > timeAxis->maximum() ||
|
||||
xpos < timeAxis->minimum() ||
|
||||
ypos > profileYAxis->maximum() ||
|
||||
ypos < profileYAxis->minimum();
|
||||
}
|
||||
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
void ProfileWidget2::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
|
@ -1041,16 +1051,6 @@ void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
bool ProfileWidget2::isPointOutOfBoundaries(const QPointF &point) const
|
||||
{
|
||||
double xpos = timeAxis->valueAt(point);
|
||||
double ypos = profileYAxis->valueAt(point);
|
||||
return xpos > timeAxis->maximum() ||
|
||||
xpos < timeAxis->minimum() ||
|
||||
ypos > profileYAxis->maximum() ||
|
||||
ypos < profileYAxis->minimum();
|
||||
}
|
||||
|
||||
void ProfileWidget2::scrollViewTo(const QPoint &pos)
|
||||
{
|
||||
/* since we cannot use translate() directly on the scene we hack on
|
||||
|
|
|
@ -252,12 +252,14 @@ private:
|
|||
void calculatePictureYPositions();
|
||||
void updateDurationLine(PictureEntry &e);
|
||||
void updateThumbnailPaintOrder();
|
||||
#endif
|
||||
|
||||
QList<DiveHandler *> handles;
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
void repositionDiveHandlers();
|
||||
int fixHandlerIndex(DiveHandler *activeHandler);
|
||||
friend class DiveHandler;
|
||||
#endif
|
||||
friend class DiveHandler;
|
||||
QHash<Qt::Key, QAction *> actionsForKeys;
|
||||
bool shouldCalculateMaxTime;
|
||||
bool shouldCalculateMaxDepth;
|
||||
|
|
Loading…
Reference in a new issue