mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Added a new class to handle the DivePlanner dialog
Added a new class named DivePlanner that is a QDialog, and renamed the old DivePlanner class to DivePlannerGraphics. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
8fcd465a65
commit
fdd8a4811b
3 changed files with 122 additions and 21 deletions
|
@ -1,14 +1,9 @@
|
|||
#include "diveplanner.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include "ui_diveplanner.h"
|
||||
|
||||
DivePlanner* DivePlanner::instance()
|
||||
{
|
||||
static DivePlanner *self = new DivePlanner();
|
||||
return self;
|
||||
}
|
||||
|
||||
DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
|
||||
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
setScene( new QGraphicsScene());
|
||||
|
@ -49,7 +44,7 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedH
|
|||
scene()->addItem(depthString);
|
||||
}
|
||||
|
||||
void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
QPointF mappedPos = mapToScene(event->pos());
|
||||
if(isPointOutOfBoundaries(mappedPos))
|
||||
|
@ -86,7 +81,7 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
|||
item->depth = (depthLine->valueAt(mappedPos));
|
||||
}
|
||||
|
||||
void DivePlanner::clear_generated_deco()
|
||||
void DivePlannerGraphics::clear_generated_deco()
|
||||
{
|
||||
for(int i = handles.count(); i <= lines.count(); i++){
|
||||
scene()->removeItem(lines.last());
|
||||
|
@ -95,7 +90,7 @@ void DivePlanner::clear_generated_deco()
|
|||
}
|
||||
}
|
||||
|
||||
void DivePlanner::create_deco_stop()
|
||||
void DivePlannerGraphics::create_deco_stop()
|
||||
{
|
||||
// This needs to be done in the following steps:
|
||||
// Get the user-input and calculate the dive info
|
||||
|
@ -126,19 +121,19 @@ void DivePlanner::create_deco_stop()
|
|||
lines << item;
|
||||
}
|
||||
|
||||
void DivePlanner::resizeEvent(QResizeEvent* event)
|
||||
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void DivePlanner::showEvent(QShowEvent* event)
|
||||
void DivePlannerGraphics::showEvent(QShowEvent* event)
|
||||
{
|
||||
QGraphicsView::showEvent(event);
|
||||
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void DivePlanner::mouseMoveEvent(QMouseEvent* event)
|
||||
void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QPointF mappedPos = mapToScene(event->pos());
|
||||
if (isPointOutOfBoundaries(mappedPos))
|
||||
|
@ -165,7 +160,7 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void DivePlanner::moveActiveHandler(QPointF pos)
|
||||
void DivePlannerGraphics::moveActiveHandler(QPointF pos)
|
||||
{
|
||||
int idx = handles.indexOf(activeDraggedHandler);
|
||||
bool moveLines = false;;
|
||||
|
@ -209,7 +204,7 @@ void DivePlanner::moveActiveHandler(QPointF pos)
|
|||
}
|
||||
}
|
||||
|
||||
bool DivePlanner::isPointOutOfBoundaries(QPointF point)
|
||||
bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point)
|
||||
{
|
||||
if (point.x() > sceneRect().width()
|
||||
|| point.x() < 0
|
||||
|
@ -221,7 +216,7 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point)
|
|||
return false;
|
||||
}
|
||||
|
||||
void DivePlanner::mousePressEvent(QMouseEvent* event)
|
||||
void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QPointF mappedPos = mapToScene(event->pos());
|
||||
Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos)){
|
||||
|
@ -232,7 +227,7 @@ void DivePlanner::mousePressEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void DivePlanner::mouseReleaseEvent(QMouseEvent* event)
|
||||
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (activeDraggedHandler){
|
||||
QPointF mappedPos = mapToScene(event->pos());
|
||||
|
@ -303,5 +298,21 @@ qreal Ruler::posAtValue(qreal value)
|
|||
{
|
||||
QLineF m = line();
|
||||
// I need to finish this later. hungry as hell.
|
||||
|
||||
}
|
||||
|
||||
|
||||
DivePlanner::DivePlanner() : ui(new Ui::DivePlanner())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
struct dive* DivePlanner::getDive()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DivePlanner* DivePlanner::instance()
|
||||
{
|
||||
static DivePlanner *self = new DivePlanner();
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsPathItem>
|
||||
#include <QDialog>
|
||||
|
||||
class DiveHandler : public QGraphicsEllipseItem{
|
||||
public:
|
||||
|
@ -34,10 +35,10 @@ private:
|
|||
double posEnd;
|
||||
};
|
||||
|
||||
class DivePlanner : public QGraphicsView {
|
||||
class DivePlannerGraphics : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DivePlanner *instance();
|
||||
DivePlannerGraphics(QWidget* parent = 0);
|
||||
protected:
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* event);
|
||||
virtual void showEvent(QShowEvent* event);
|
||||
|
@ -51,7 +52,7 @@ protected:
|
|||
bool isPointOutOfBoundaries(QPointF point);
|
||||
|
||||
private:
|
||||
DivePlanner(QWidget* parent = 0);
|
||||
|
||||
void moveActiveHandler(QPointF pos);
|
||||
QList<QGraphicsLineItem*> lines;
|
||||
QList<DiveHandler *> handles;
|
||||
|
@ -66,4 +67,19 @@ private:
|
|||
QGraphicsSimpleTextItem *depthString;
|
||||
|
||||
};
|
||||
|
||||
namespace Ui{
|
||||
class DivePlanner;
|
||||
}
|
||||
|
||||
class DivePlanner : public QDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DivePlanner *instance();
|
||||
struct dive* getDive();
|
||||
|
||||
private:
|
||||
DivePlanner();
|
||||
Ui::DivePlanner *ui;
|
||||
};
|
||||
#endif
|
||||
|
|
74
qt-ui/diveplanner.ui
Normal file
74
qt-ui/diveplanner.ui
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DivePlanner</class>
|
||||
<widget class="QDialog" name="DivePlanner">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>575</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="DivePlannerGraphics" name="graphicsView"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>DivePlannerGraphics</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>diveplanner.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DivePlanner</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>DivePlanner</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in a new issue