summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/mainwindow.cpp13
-rw-r--r--qt-ui/mainwindow.h2
-rw-r--r--qt-ui/mainwindow.ui6
-rw-r--r--qt-ui/profilegraphics.cpp74
-rw-r--r--qt-ui/profilegraphics.h9
5 files changed, 76 insertions, 28 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 160a657da..863e35088 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -45,6 +45,11 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
ui->ListWidget->setCurrentIndex(firstDiveOrTrip);
}
+void MainWindow::redrawProfile()
+{
+ ui->ProfileWidget->plot(get_dive(selected_dive));
+}
+
void MainWindow::on_actionNew_triggered()
{
qDebug("actionNew");
@@ -96,7 +101,7 @@ void MainWindow::dive_selection_changed(const QItemSelection& newSelection, cons
continue;
select_dive(get_divenr(d));
}
- ui->ProfileWidget->plot(get_dive(selected_dive));
+ redrawProfile();
ui->InfoWidget->updateDiveInfo(selected_dive);
}
@@ -239,12 +244,14 @@ void MainWindow::on_actionViewAll_triggered()
void MainWindow::on_actionPreviousDC_triggered()
{
- qDebug("actionPreviousDC");
+ dc_number--;
+ redrawProfile();
}
void MainWindow::on_actionNextDC_triggered()
{
- qDebug("actionNextDC");
+ dc_number++;
+ redrawProfile();
}
void MainWindow::on_actionSelectEvents_triggered()
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 3b35d44e5..b76199a8b 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -82,7 +82,7 @@ private:
bool askSaveChanges();
void readSettings();
void writeSettings();
-
+ void redrawProfile();
};
#endif
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index 377605326..b2969ac61 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -315,11 +315,17 @@
<property name="text">
<string>Prev DC</string>
</property>
+ <property name="shortcut">
+ <string>Left</string>
+ </property>
</action>
<action name="actionNextDC">
<property name="text">
<string>Next DC</string>
</property>
+ <property name="shortcut">
+ <string>Right</string>
+ </property>
</action>
<action name="actionSelectEvents">
<property name="text">
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index c1e51ac25..6e699fe51 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -119,7 +119,6 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
gc.printer = false;
setScene(new QGraphicsScene());
setBackgroundBrush(QColor("#F3F3E6"));
- scene()->setSceneRect(0,0,1000,1000);
scene()->installEventFilter(this);
setRenderHint(QPainter::Antialiasing);
@@ -166,7 +165,12 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
toolTip->refresh(&gc, mapToScene(event->pos()));
QPoint toolTipPos = mapFromScene(toolTip->pos());
- ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100);
+
+ double dx = sceneRect().x();
+ double dy = sceneRect().y();
+
+ ensureVisible(event->pos().x() + dx, event->pos().y() + dy, 1, 1);
+
toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
if (zoomLevel < 0)
@@ -196,16 +200,26 @@ static void plot_set_scale(scale_mode_t scale)
}
}
+void ProfileGraphicsView::showEvent(QShowEvent* event)
+{
+ if (dive)
+ plot(dive);
+}
+
void ProfileGraphicsView::plot(struct dive *d)
{
- scene()->clear();
+ scene()->clear();
if (dive != d){
resetTransform();
zoomLevel = 0;
dive = d;
}
+ if(!isVisible()){
+ return;
+ }
+
if(!dive)
return;
@@ -293,15 +307,16 @@ void ProfileGraphicsView::plot(struct dive *d)
scene()->addItem(rect);
/* Put the dive computer name in the lower left corner */
- const char *nickname;
- nickname = get_dc_nickname(dc->model, dc->deviceid);
- if (!nickname || *nickname == '\0')
- nickname = dc->model;
- if (nickname) {
+ QString nick(get_dc_nickname(dc->model, dc->deviceid));
+ if (nick.isEmpty())
+ nick = QString(dc->model);
+
+ if (!nick.isEmpty()) {
text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE};
- plot_text(&computer, gc.leftx, gc.bottomy, nickname);
+ diveComputer = plot_text(&computer, QPointF(gc.leftx, gc.bottomy), nick);
}
-
+ // The Time ruler should be right after the DiveComputer:
+ timeMarkers->setPos(0, diveComputer->y());
if (PP_GRAPHS_ENABLED) {
plot_pp_gas_profile();
@@ -327,7 +342,11 @@ void ProfileGraphicsView::plot(struct dive *d)
}
#endif
- scene()->setSceneRect(scene()->itemsBoundingRect());
+ QRectF r = scene()->itemsBoundingRect();
+ scene()->setSceneRect(r.x() - 15, r.y() -15, r.width() + 30, r.height() + 30);
+ if(zoomLevel == 0){
+ fitInView(sceneRect());
+ }
}
void ProfileGraphicsView::plot_depth_scale()
@@ -351,10 +370,13 @@ void ProfileGraphicsView::plot_depth_scale()
* partial pressure graphs) where this would look out
* of place - so we only make sure that we print the next
* marker below the actual maxdepth of the dive */
+ depthMarkers = new QGraphicsRectItem();
for (i = marker; i <= gc.pi.maxdepth + marker; i += marker) {
double d = get_depth_units(i, NULL, NULL);
- plot_text(&tro, -0.002, i, QString::number(d));
+ plot_text(&tro, QPointF(-0.002, i), QString::number(d), depthMarkers);
}
+ scene()->addItem(depthMarkers);
+ depthMarkers->setPos(depthMarkers->pos().x() - 10, 0);
}
void ProfileGraphicsView::plot_pp_text()
@@ -375,7 +397,7 @@ void ProfileGraphicsView::plot_pp_text()
pen.setColor(c);
item->setPen(pen);
scene()->addItem(item);
- plot_text(&tro, hpos + 30, m, QString::number(m));
+ plot_text(&tro, QPointF(hpos + 30, m), QString::number(m));
}
}
@@ -514,7 +536,7 @@ void ProfileGraphicsView::plot_deco_text()
float y = gc.topy = 1.0;
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, -0.2};
gc.bottomy = 0.0;
- plot_text(&tro, x, y, QString("GF %1/%2").arg(prefs.gflow * 100).arg(prefs.gfhigh * 100));
+ plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow * 100).arg(prefs.gfhigh * 100));
}
}
@@ -563,7 +585,7 @@ void ProfileGraphicsView::plot_pressure_value(int mbar, int sec, double xalign,
pressure = get_pressure_units(mbar, &unit);
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign};
- plot_text(&tro, sec, mbar, QString("%1 %2").arg(pressure).arg(unit));
+ plot_text(&tro, QPointF(sec, mbar), QString("%1 %2").arg(pressure).arg(unit));
}
void ProfileGraphicsView::plot_depth_text()
@@ -617,7 +639,7 @@ void ProfileGraphicsView::plot_depth_sample(struct plot_data *entry,text_render_
d = get_depth_units(entry->depth, &decimals, NULL);
- plot_text(tro, sec, entry->depth, QString("%1").arg(d)); // , decimals, d);
+ plot_text(tro, QPointF(sec, entry->depth), QString("%1").arg(d)); // , decimals, d);
}
@@ -666,7 +688,7 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin)
const char *unit;
static text_render_options_t tro = {TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP};
deg = get_temp_units(mkelvin, &unit);
- plot_text(&tro, sec, mkelvin, QString("%1%2").arg(deg).arg(unit)); //"%.2g%s"
+ plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg).arg(unit)); //"%.2g%s"
}
void ProfileGraphicsView::plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc)
@@ -889,17 +911,20 @@ void ProfileGraphicsView::plot_depth_profile()
scene()->addItem(item);
}
+ timeMarkers = new QGraphicsRectItem();
/* now the text on the time markers */
struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP};
if (maxtime < 600) {
/* Be a bit more verbose with shorter dives */
for (i = incr; i < maxtime; i += incr)
- plot_text(&tro, i, 1, QString("%1:%2").arg(i/60).arg(i%60));
+ plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60), timeMarkers);
} else {
/* Only render the time on every second marker for normal dives */
for (i = incr; i < maxtime; i += 2 * incr)
- plot_text(&tro, i, 1, QString::number(i/60));
+ plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers);
}
+ timeMarkers->setPos(0,0);
+ scene()->addItem(timeMarkers);
/* Depth markers: every 30 ft or 10 m*/
gc.leftx = 0; gc.rightx = 1.0;
@@ -1077,20 +1102,23 @@ void ProfileGraphicsView::plot_depth_profile()
}
}
-void ProfileGraphicsView::plot_text(text_render_options_t *tro, double x, double y, const QString& text)
+QGraphicsSimpleTextItem *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent)
{
QFontMetrics fm(font());
double dx = tro->hpos * (fm.width(text));
double dy = tro->vpos * (fm.height());
- QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text);
- QPointF point(SCALEGC(x, y)); // This is neded because of the SCALE macro.
+ QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text, parent);
+ QPointF point(SCALEGC(pos.x(), pos.y())); // This is neded because of the SCALE macro.
item->setPos(point.x() + dx, point.y() +dy);
item->setBrush(QBrush(profile_color[tro->color].first()));
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
- scene()->addItem(item);
+
+ if(!parent)
+ scene()->addItem(item);
+ return item;
}
void ProfileGraphicsView::resizeEvent(QResizeEvent *event)
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index a2033ca75..7cf88cbc3 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -69,10 +69,11 @@ protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
+ void showEvent(QShowEvent* event);
private:
void plot_depth_profile();
- void plot_text(text_render_options_t *tro, double x, double y, const QString &text);
+ QGraphicsSimpleTextItem* plot_text(text_render_options_t *tro, const QPointF& pos, const QString &text, QGraphicsItem *parent = 0);
void plot_events(struct divecomputer *dc);
void plot_one_event(struct event *event);
void plot_temperature_profile();
@@ -97,6 +98,12 @@ private:
graphics_context gc;
struct dive *dive;
int zoomLevel;
+
+ // Top Level Items.
+ QGraphicsItem* profileGrid;
+ QGraphicsItem* timeMarkers;
+ QGraphicsItem* depthMarkers;
+ QGraphicsItem* diveComputer;
};
#endif