summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/downloadfromdivecomputer.ui2
-rw-r--r--qt-ui/mainwindow.cpp14
-rw-r--r--qt-ui/mainwindow.ui21
-rw-r--r--qt-ui/models.cpp2
-rw-r--r--qt-ui/profilegraphics.cpp162
-rw-r--r--qt-ui/profilegraphics.h37
6 files changed, 171 insertions, 67 deletions
diff --git a/qt-ui/downloadfromdivecomputer.ui b/qt-ui/downloadfromdivecomputer.ui
index 4b46a6e43..41f9a4751 100644
--- a/qt-ui/downloadfromdivecomputer.ui
+++ b/qt-ui/downloadfromdivecomputer.ui
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>Form</string>
+ <string>Download From Dive Computer</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index eb7febed7..8b216bd8c 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -47,7 +47,6 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0)
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui->ListWidget, SLOT(reloadHeaderActions()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui->ProfileWidget, SLOT(refresh()));
ui->mainErrorMessage->hide();
- ui->ProfileWidget->setFocusProxy(ui->ListWidget);
ui->ListWidget->reload(DiveTripModel::TREE);
initialUiSetup();
readSettings();
@@ -205,11 +204,20 @@ void MainWindow::on_actionDownloadWeb_triggered()
void MainWindow::on_actionEditDeviceNames_triggered()
{
- qDebug("actionEditDeviceNames");}
+ qDebug("actionEditDeviceNames");
+}
void MainWindow::on_actionAddDive_triggered()
{
- qDebug("actionAddDive");
+ struct dive *dive;
+ dive = alloc_dive();
+ record_dive(dive);
+ process_dives(FALSE, FALSE);
+
+ ui->InfoWidget->reload();
+ ui->globe->reload();
+ ui->ListWidget->reload(DiveTripModel::TREE);
+ ui->ListWidget->setFocus();
}
void MainWindow::on_actionRenumber_triggered()
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index 598068e3d..1a985f812 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -103,7 +103,7 @@
<x>0</x>
<y>0</y>
<width>763</width>
- <height>20</height>
+ <height>34</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -159,12 +159,6 @@
</property>
<addaction name="actionSelectEvents"/>
</widget>
- <widget class="QMenu" name="menuPlanner">
- <property name="title">
- <string>Planner</string>
- </property>
- <addaction name="actionInputPlan"/>
- </widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>Help</string>
@@ -176,7 +170,6 @@
<addaction name="menuLog"/>
<addaction name="menuView"/>
<addaction name="menuFilter"/>
- <addaction name="menuPlanner"/>
<addaction name="menuHelp"/>
</widget>
<action name="actionNew">
@@ -378,6 +371,12 @@
</widget>
<customwidgets>
<customwidget>
+ <class>KMessageWidget</class>
+ <extends>QWidget</extends>
+ <header>kmessagewidget.h</header>
+ <container>1</container>
+ </customwidget>
+ <customwidget>
<class>MainTab</class>
<extends>QWidget</extends>
<header>maintab.h</header>
@@ -399,12 +398,6 @@
<header>globe.h</header>
<container>1</container>
</customwidget>
- <customwidget>
- <class>KMessageWidget</class>
- <extends>QWidget</extends>
- <header>kmessagewidget.h</header>
- <container>1</container>
- </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 8575d6539..1cc9ab869 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -927,7 +927,7 @@ QString DiveItem::displaySac() const
QString str;
if (get_units()->volume == units::LITER)
- str = QString::number(dive->sac / 1000, 'f', 1);
+ str = QString::number(dive->sac / 1000.0, 'f', 1);
else
str = QString::number(ml_to_cuft(dive->sac), 'f', 2);
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index be2f5f039..39edd690a 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -1,4 +1,6 @@
#include "profilegraphics.h"
+#include "mainwindow.h"
+#include "divelistview.h"
#include <QGraphicsScene>
#include <QResizeEvent>
@@ -12,11 +14,13 @@
#include <QPropertyAnimation>
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
+#include <qtextdocument.h>
#include "../color.h"
#include "../display.h"
#include "../dive.h"
#include "../profile.h"
+#include "../device.h"
#include <libdivecomputer/parser.h>
#include <libdivecomputer/version.h>
@@ -145,6 +149,7 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
// Scale the view / do the zoom
QPoint toolTipPos = mapFromScene(toolTip->pos());
+
double scaleFactor = 1.15;
if (event->delta() > 0 && zoomLevel <= 10) {
scale(scaleFactor, scaleFactor);
@@ -171,10 +176,10 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
ensureVisible(event->pos().x() + dx, event->pos().y() + dy, 1, 1);
- toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
-
if (zoomLevel == 0)
QGraphicsView::mouseMoveEvent(event);
+ else
+ toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
}
bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event)
@@ -220,10 +225,14 @@ void ProfileGraphicsView::showEvent(QShowEvent* event)
void ProfileGraphicsView::clear()
{
- scene()->clear();
resetTransform();
zoomLevel = 0;
- toolTip = 0;
+ if(toolTip){
+ scene()->removeItem(toolTip);
+ toolTip->deleteLater();
+ toolTip = 0;
+ }
+ scene()->clear();
}
void ProfileGraphicsView::refresh()
@@ -249,42 +258,32 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
return;
}
+ // best place to put the focus stealer code.
+ setFocusProxy(mainWindow()->dive_list());
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
- QSettings s;
- s.beginGroup("ProfileMap");
- QPointF toolTipPos = s.value("tooltip_position", QPointF(0,0)).toPointF();
- s.endGroup();
-
toolTip = new ToolTipItem();
- toolTip->setPos(toolTipPos);
-
+ installEventFilter(toolTip);
scene()->addItem(toolTip);
// Fix this for printing / screen later.
// plot_set_scale(scale_mode_t);
if (!dc->samples) {
- static struct sample fake[4];
- static struct divecomputer fakedc;
- fakedc = dive->dc;
- fakedc.sample = fake;
- fakedc.samples = 4;
-
- /* The dive has no samples, so create a few fake ones. This assumes an
- ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
- int duration = dive->dc.duration.seconds;
- int maxdepth = dive->dc.maxdepth.mm;
- int asc_desc_time = dive->dc.maxdepth.mm*60/9000;
- if (asc_desc_time * 2 >= duration)
- asc_desc_time = duration / 2;
- fake[1].time.seconds = asc_desc_time;
- fake[1].depth.mm = maxdepth;
- fake[2].time.seconds = duration - asc_desc_time;
- fake[2].depth.mm = maxdepth;
- fake[3].time.seconds = duration * 1.00;
- fakedc.events = dc->events;
- dc = &fakedc;
+ dc = fake_dc(dc);
+ }
+
+ QString nick(get_dc_nickname(dc->model, dc->deviceid));
+ if (nick.isEmpty())
+ nick = QString(dc->model);
+
+ if (nick.isEmpty())
+ nick = tr("unknown divecomputer");
+
+ if ( tr("unknown divecomputer") == nick){
+ mode = PLAN;
+ }else{
+ mode = DIVE;
}
/*
@@ -309,7 +308,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
plot_temperature_profile();
/* Cylinder pressure plot */
- plot_cylinder_pressure(dive, dc);
+ plot_cylinder_pressure(dc);
/* Text on top of all graphs.. */
plot_temperature_text();
@@ -328,13 +327,6 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
scene()->addItem(rect);
/* Put the dive computer name in the lower left corner */
- QString nick(get_dc_nickname(dc->model, dc->deviceid));
- if (nick.isEmpty())
- nick = QString(dc->model);
-
- if (nick.isEmpty())
- nick = tr("unknown divecomputer");
-
gc.leftx = 0; gc.rightx = 1.0;
gc.topy = 0; gc.bottomy = 1.0;
@@ -348,7 +340,6 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
plot_pp_text();
}
-
/* now shift the translation back by half the margin;
* this way we can draw the vertical scales on both sides */
//cairo_translate(gc->cr, -drawing_area->x / 2.0, 0);
@@ -372,6 +363,16 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
if (zoomLevel == 0) {
fitInView(sceneRect());
}
+ toolTip->readPos();
+
+ if(mode == PLAN){
+ timeEditor = new GraphicsTextEditor();
+ timeEditor->setPlainText( dive->duration.seconds ? QString::number(dive->duration.seconds/60) : tr("Set Duration: 10 minutes"));
+ timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y());
+ timeEditor->document();
+ connect(timeEditor, SIGNAL(editingFinished(QString)), this, SLOT(edit_dive_time(QString)));
+ scene()->addItem(timeEditor);
+ }
}
void ProfileGraphicsView::plot_depth_scale()
@@ -726,7 +727,7 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin)
plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit)); //"%.2g%s"
}
-void ProfileGraphicsView::plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc)
+void ProfileGraphicsView::plot_cylinder_pressure(struct divecomputer *dc)
{
int i;
int last = -1, last_index = -1;
@@ -1219,6 +1220,12 @@ void ProfileGraphicsView::plot_temperature_profile()
}
}
+void ProfileGraphicsView::edit_dive_time(const QString& time)
+{
+ // this should set the full time of the dive.
+ refresh();
+}
+
void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
{
QGraphicsPixmapItem *iconItem = 0;
@@ -1374,16 +1381,19 @@ ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), back
{
title = new QGraphicsSimpleTextItem(tr("Information"), this);
separator = new QGraphicsLineItem(this);
-
+ dragging = false;
setFlag(ItemIgnoresTransformations);
- setFlag(ItemIsMovable);
-
status = COLLAPSED;
-
updateTitlePosition();
setZValue(99);
}
+ToolTipItem::~ToolTipItem()
+{
+ clear();
+}
+
+
void ToolTipItem::updateTitlePosition()
{
if (rectangle.width() < title->boundingRect().width() + SPACING*4) {
@@ -1417,6 +1427,46 @@ bool ToolTipItem::isExpanded() {
return status == EXPANDED;
}
+void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
+{
+ persistPos();
+ dragging = false;
+}
+
+void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
+{
+ dragging = true;
+}
+
+void ToolTipItem::persistPos()
+{
+ QPoint currentPos = scene()->views().at(0)->mapFromScene(pos());
+ QSettings s;
+ s.beginGroup("ProfileMap");
+ s.setValue("tooltip_position", currentPos);
+ s.endGroup();
+ s.sync();
+}
+
+void ToolTipItem::readPos()
+{
+ QSettings s;
+ s.beginGroup("ProfileMap");
+ QPointF value = scene()->views().at(0)->mapToScene(
+ s.value("tooltip_position").toPoint()
+ );
+ setPos(value);
+}
+
+bool ToolTipItem::eventFilter(QObject* view, QEvent* event)
+{
+ if (event->type() == QEvent::HoverMove && dragging){
+ QHoverEvent *e = static_cast<QHoverEvent*>(event);
+ QGraphicsView *v = scene()->views().at(0);
+ setPos( v->mapToScene(e->pos()));
+ }
+ return false;
+}
EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent)
{
@@ -1448,5 +1498,27 @@ EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent)
QGraphicsEllipseItem *ball = new QGraphicsEllipseItem(-1, 12, 2,2, this);
ball->setBrush(QBrush(Qt::black));
+}
+GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem* parent): QGraphicsTextItem(parent)
+{
+}
+
+void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
+{
+ // Remove the proxy filter so we can focus here.
+ mainWindow()->graphics()->setFocusProxy(0);
+ setTextInteractionFlags(Qt::TextEditorInteraction | Qt::TextEditable);
+}
+
+void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event)
+{
+ if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return){
+ setTextInteractionFlags(Qt::NoTextInteraction);
+ emit editingFinished( toPlainText() );
+ mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list());
+ return;
+ }
+ emit textChanged( toPlainText() );
+ QGraphicsTextItem::keyReleaseEvent(event);
}
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 9c1c5dbc1..1722e2cc3 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -5,6 +5,9 @@
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QIcon>
+#include <QDoubleSpinBox>
+#include <QPushButton>
+#include <QGraphicsProxyWidget>
struct text_render_options;
struct graphics_context;
@@ -25,6 +28,7 @@ public:
enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
explicit ToolTipItem(QGraphicsItem* parent = 0);
+ virtual ~ToolTipItem();
void collapse();
void expand();
@@ -33,7 +37,11 @@ public:
void removeToolTip(const QString& toolTip);
void refresh(struct graphics_context* gc, QPointF pos);
bool isExpanded();
-
+ void persistPos();
+ void readPos();
+ void mousePressEvent(QGraphicsSceneMouseEvent* event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
+ bool eventFilter(QObject* , QEvent* );
public Q_SLOTS:
void setRect(const QRectF& rect);
@@ -44,8 +52,8 @@ private:
QGraphicsLineItem *separator;
QGraphicsSimpleTextItem *title;
Status status;
-
QRectF rectangle;
+ bool dragging;
};
class EventItem : public QGraphicsPolygonItem
@@ -59,10 +67,26 @@ private:
QIcon icon;
};
+class GraphicsTextEditor : public QGraphicsTextItem{
+ Q_OBJECT
+public:
+ GraphicsTextEditor(QGraphicsItem* parent = 0);
+
+protected:
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
+ virtual void keyReleaseEvent(QKeyEvent* event);
+
+signals:
+ void textChanged(const QString& text);
+ void editingFinished(const QString& text);
+};
+
class ProfileGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
+ enum Mode{DIVE, PLAN};
+
ProfileGraphicsView(QWidget* parent = 0);
void plot(struct dive *d, bool forceRedraw = FALSE);
bool eventFilter(QObject* obj, QEvent* event);
@@ -76,6 +100,7 @@ protected:
public Q_SLOTS:
void refresh();
+ void edit_dive_time(const QString& time);
private:
void plot_depth_profile();
@@ -83,7 +108,7 @@ private:
void plot_events(struct divecomputer *dc);
void plot_one_event(struct event *event);
void plot_temperature_profile();
- void plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc);
+ void plot_cylinder_pressure(struct divecomputer *dc);
void plot_temperature_text();
void plot_single_temp_text(int sec, int mkelvin);
void plot_depth_text();
@@ -112,6 +137,12 @@ private:
QGraphicsItem* timeMarkers;
QGraphicsItem* depthMarkers;
QGraphicsItem* diveComputer;
+
+ // For 'Plan' mode.:
+ GraphicsTextEditor *depthEditor;
+ GraphicsTextEditor *timeEditor;
+
+ enum Mode mode;
};
#endif