WARNING: this breaks completely the add / plan dive because it will not show the correct dialog anymore.
it's the beginning of the work, I'm sending this just you can take a look and give me some pointers if the code is wrong or not. Dirk, don't apply those untill I have something more conctrete to show. Why I'm sending those if I don't wanna to be merged? don't know, I'm also sleepy. it's almost midnight. actually I think that 0006 and 0008 doesn't break current functionality and may be merged. I'll continue this tomorrow. Tomaz
From 8119893a124ac12a404958017c3065eb2e321cda Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 12 May 2014 20:51:39 -0300 Subject: [PATCH 6/9] Removed silly macro to pretend that we were doing things the right way. That macro was useless, I sould have been drunk when I wrote it, and I don't drink. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/diveplanner.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index b45b4e0..aabd331 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1624,17 +1624,10 @@ ExpanderGraphics::ExpanderGraphics(QGraphicsItem *parent) : QGraphicsRectItem(pa leftWing(new QGraphicsPixmapItem(this)), rightWing(new QGraphicsPixmapItem(this)) { - QPixmap p; -#define CREATE(item, pixmap) \ - p = QPixmap(QString(pixmap)); \ - item->setPixmap(p); - - CREATE(icon, ":icon_time"); - CREATE(bg, ":round_base"); - CREATE(leftWing, ":left_wing"); - CREATE(rightWing, ":right_wing"); -#undef CREATE - + icon->setPixmap(QPixmap(":icon_time")); + bg->setPixmap(QPixmap(":round_base")); + leftWing->setPixmap(QPixmap(":left_wing")); + rightWing->setPixmap(QPixmap(":right_wing")); decreaseBtn->setPixmap(QPixmap(":arrow_down")); increaseBtn->setPixmap(QPixmap(":arrow_up")); -- 1.9.2
From d94f4a0f8820cc761785be6eee56154a37097ab9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 12 May 2014 21:20:50 -0300 Subject: [PATCH 7/9] Started to port the Planner to the new profile code. This is a start of the code to port the planner to the new profile. Nothing works yet and the planner is severely damaged by this. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 3 +-- qt-ui/profile/profilewidget2.cpp | 12 ++++++++++++ qt-ui/profile/profilewidget2.h | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 709693c..ccd6b5b 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -420,7 +420,6 @@ void MainWindow::on_actionAddDive_triggered() struct dive *dive = alloc_dive(); dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file - dive->latitude.udeg = 0; dive->longitude.udeg = 0; record_dive(dive); @@ -430,8 +429,8 @@ void MainWindow::on_actionAddDive_triggered() ui.InfoWidget->setCurrentIndex(0); ui.InfoWidget->updateDiveInfo(selected_dive); ui.InfoWidget->addDiveStarted(); - ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. ui.infoPane->setCurrentIndex(MAINTAB); + ui.newProfile->setAddState(); DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->createSimpleDive(); ui.ListWidget->reload(DiveTripModel::CURRENT); diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index d2d01a3..0a14ec7 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -682,6 +682,18 @@ void ProfileWidget2::setProfileState() rulerItem->sourceNode()->setVisible(rulerVisible); } + +void ProfileWidget2::setAddState() +{ + // This takes care of positioning everything related to the profile graph. + setProfileState(); + // Then we add down here what is missing to the *add* part. + if (currentState == ADD) + return; + + currentState = ADD; +} + extern struct ev_select *ev_namelist; extern int evn_allocated; extern int evn_used; diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index d00cb26..c79e97c 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -74,6 +74,7 @@ slots: // Necessary to call from QAction's signals. void settingsChanged(); void setEmptyState(); void setProfileState(); + void setAddState(); void changeGas(); void addBookmark(); void hideEvents(); -- 1.9.2
From a8312a49bbf965c6c7d3b1ed78516791c276b16b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 12 May 2014 21:26:12 -0300 Subject: [PATCH 8/9] Only set the state to profile if it's empty, not if iits Add or Plan. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/profilewidget2.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 0a14ec7..3c9a54e 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -368,7 +368,8 @@ void ProfileWidget2::plotDives(QList<dive *> dives) if (d->id == dataModel->id() && dc_number == dataModel->dcShown()) return; - setProfileState(); + if(currentState == EMPTY) + setProfileState(); // next get the dive computer structure - if there are no samples // let's create a fake profile that's somewhat reasonable for the -- 1.9.2
From 7fb59bb9a0ab2ee5a050f733fa675ce154e2e443 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 12 May 2014 22:37:24 -0300 Subject: [PATCH 9/9] Changed the event-handlers to point-methods. This way we can override the event handlers by passing a pointer to a new method and things should work. The Profile2 class is fairly monolithyc ( I don't like that ) and doesn't works in a plugin-like way, and I would need probably to change a lot of stuff for that, so I'll just keep like what it is today. I needed a way to change the behavior of the mouse press / move when on different types of views, this way seemed the best cost / benefit: we can add more different states of the profile ( view dive, view multiple dives, plan, add dive, edit ) creating the events that should override the original ones, and set them. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/profilewidget2.cpp | 65 ++++++++++++++++++++++++++++++---------- qt-ui/profile/profilewidget2.h | 12 ++++++++ 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 3c9a54e..f795610 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -336,6 +336,18 @@ void ProfileWidget2::plotDives(QList<dive *> dives) if (!d) return; + // No need to do this again if we are already showing the same dive + // computer of the same dive, so we check the unique id of the dive + // and the selected dive computer number against the ones we are + // showing (can't compare the dive pointers as those might change). + // I'm unclear what the semantics are supposed to be if we actually + // use more than one 'dives' as argument - so ignoring that right now :-) + if (d->id == dataModel->id() && dc_number == dataModel->dcShown()) + return; + + if(currentState == EMPTY) + setProfileState(); + int animSpeedBackup = -1; if (firstCall && MainWindow::instance()->filesFromCommandLine()) { animSpeedBackup = prefs.animation; @@ -359,17 +371,6 @@ void ProfileWidget2::plotDives(QList<dive *> dives) rulerItem->sourceNode()->setVisible(rulerVisible); rulerItem->destNode()->setVisible(rulerVisible); - // No need to do this again if we are already showing the same dive - // computer of the same dive, so we check the unique id of the dive - // and the selected dive computer number against the ones we are - // showing (can't compare the dive pointers as those might change). - // I'm unclear what the semantics are supposed to be if we actually - // use more than one 'dives' as argument - so ignoring that right now :-) - if (d->id == dataModel->id() && dc_number == dataModel->dcShown()) - return; - - if(currentState == EMPTY) - setProfileState(); // next get the dive computer structure - if there are no samples // let's create a fake profile that's somewhat reasonable for the @@ -506,8 +507,31 @@ void ProfileWidget2::settingsChanged() if (needReplot) replot(); } +void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event) +{ + if (currContextMenuEvent) + (this->*currContextMenuEvent)(event); +} + +void ProfileWidget2::mouseMoveEvent(QMouseEvent* event) +{ + if(currMouseMoveEvent) + (this->*currMouseMoveEvent)(event); +} -void ProfileWidget2::resizeEvent(QResizeEvent *event) +void ProfileWidget2::resizeEvent(QResizeEvent* event) +{ + if(currResizeEvent) + (this->*currResizeEvent)(event); +} + +void ProfileWidget2::wheelEvent(QWheelEvent* event) +{ + if(currWheelEvent) + (this->*currWheelEvent)(event); +} + +void ProfileWidget2::profile_resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); fitInView(sceneRect(), Qt::IgnoreAspectRatio); @@ -527,7 +551,7 @@ void ProfileWidget2::fixBackgroundPos() background->setY(mapToScene(y, 20).y()); } -void ProfileWidget2::wheelEvent(QWheelEvent *event) +void ProfileWidget2::profile_wheelEvent(QWheelEvent *event) { if (currentState == EMPTY) return; @@ -558,7 +582,7 @@ void ProfileWidget2::scrollViewTo(const QPoint &pos) hs->setValue(xRat * hs->maximum()); } -void ProfileWidget2::mouseMoveEvent(QMouseEvent *event) +void ProfileWidget2::profile_mouseMoveEvent(QMouseEvent *event) { toolTipItem->refresh(mapToScene(event->pos())); QPoint toolTipPos = mapFromScene(toolTipItem->pos()); @@ -586,6 +610,11 @@ void ProfileWidget2::setEmptyState() if (currentState == EMPTY) return; + currContextMenuEvent = &ProfileWidget2::profile_contextMenuEvent; + currMouseMoveEvent = &ProfileWidget2::profile_mouseMoveEvent; + currResizeEvent = &ProfileWidget2::profile_resizeEvent; + currWheelEvent = &ProfileWidget2::profile_wheelEvent; + dataModel->clear(); currentState = EMPTY; MainWindow::instance()->setToolButtonsEnabled(false); @@ -624,6 +653,11 @@ void ProfileWidget2::setProfileState() if (currentState == PROFILE) return; + currContextMenuEvent = &ProfileWidget2::profile_contextMenuEvent; + currMouseMoveEvent = &ProfileWidget2::profile_mouseMoveEvent; + currResizeEvent = &ProfileWidget2::profile_resizeEvent; + currWheelEvent = &ProfileWidget2::profile_wheelEvent; + currentState = PROFILE; MainWindow::instance()->setToolButtonsEnabled(true); toolTipItem->readPos(); @@ -692,6 +726,7 @@ void ProfileWidget2::setAddState() if (currentState == ADD) return; + setBackgroundBrush(QColor(Qt::darkCyan)); currentState = ADD; } @@ -699,7 +734,7 @@ extern struct ev_select *ev_namelist; extern int evn_allocated; extern int evn_used; -void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) +void ProfileWidget2::profile_contextMenuEvent(QContextMenuEvent *event) { if (selected_dive == -1) return; diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index c79e97c..577e84d 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -88,6 +88,11 @@ protected: virtual void mouseMoveEvent(QMouseEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event); + void profile_resizeEvent(QResizeEvent *event); + void profile_wheelEvent(QWheelEvent *event); + void profile_mouseMoveEvent(QMouseEvent *event); + void profile_contextMenuEvent(QContextMenuEvent *event); + private: /*methods*/ void fixBackgroundPos(); void scrollViewTo(const QPoint &pos); @@ -105,6 +110,13 @@ private: QString backgroundFile; ToolTipItem *toolTipItem; bool isPlotZoomed; + + // Pointer to methods. uglyer than pointer to functions, but works beautifully. + void (ProfileWidget2::*currResizeEvent)(QResizeEvent *event); + void (ProfileWidget2::*currWheelEvent)(QWheelEvent *event); + void (ProfileWidget2::*currMouseMoveEvent)(QMouseEvent *event); + void (ProfileWidget2::*currContextMenuEvent)(QContextMenuEvent *event); + // All those here should probably be merged into one structure, // So it's esyer to replicate for more dives later. // In the meantime, keep it here. -- 1.9.2
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
