From ca517f1bf8f3c690e2d3651d7f74e1b68ed3bb98 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 10:13:06 -0300 Subject: Shared background for profile and planner. Share the background for profile and planner. Those are not the same class, but they should behave somwheat the same. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 053e4efff..115aa5f7a 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,4 +1,6 @@ #include "diveplanner.h" +#include "graphicsview-common.h" + #include "../dive.h" #include #include @@ -15,6 +17,8 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0), lastValidPos(0.0, 0.0) { + fill_profile_color(); + setBackgroundBrush(profile_color[BACKGROUND].at(0)); setMouseTracking(true); setScene(new QGraphicsScene()); scene()->setSceneRect(0,0,200,200); -- cgit v1.2.3-70-g09d2 From c98894fd5200008a8ef77b748bd5bdb4684cebdd Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 10:53:08 -0300 Subject: Added a method and a simple stub to position things using percentage. Added a method and a simple stub to position things on the canvas using percentage - this way I have a proper control on where I want to put things on screen and it will make simpler for future changes, even if the amount of code written is a bit bigger. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 22 ++++++++++++++++------ qt-ui/diveplanner.h | 33 +++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 14 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 115aa5f7a..0ee87fea5 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -21,9 +21,16 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) setBackgroundBrush(profile_color[BACKGROUND].at(0)); setMouseTracking(true); setScene(new QGraphicsScene()); - scene()->setSceneRect(0,0,200,200); + scene()->setSceneRect(0,0,1920,1080); + + QRectF r = scene()->sceneRect(); + + verticalLine = new QGraphicsLineItem( + fromPercent(0, Qt::Horizontal), + fromPercent(0, Qt::Vertical), + fromPercent(0, Qt::Horizontal), + fromPercent(100, Qt::Vertical)); - verticalLine = new QGraphicsLineItem(0,0,0, 200); verticalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(verticalLine); @@ -88,6 +95,13 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) setRenderHint(QPainter::Antialiasing); } +qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation) +{ + qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height(); + qreal result = (total * percent) / 100; + return result; +} + void DivePlannerGraphics::cancelClicked() { qDebug() << "clicked"; @@ -133,10 +147,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) createDecoStops(); } -void DivePlannerGraphics::clearGeneratedDeco() -{ -} - void DivePlannerGraphics::createDecoStops() { qDeleteAll(lines); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index fff6a6e57..5f0ec7e08 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -65,10 +65,11 @@ protected: virtual void mousePressEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event); - void clearGeneratedDeco(); void createDecoStops(); bool isPointOutOfBoundaries(const QPointF& point); void deleteTemporaryDivePlan(struct divedatapoint* dp); + + qreal fromPercent(qreal percent, Qt::Orientation orientation); private slots: void increaseTime(); void increaseDepth(); @@ -77,25 +78,41 @@ private slots: private: void moveActiveHandler(const QPointF& pos); + + /* This are the lines of the plotted dive. */ QList lines; + + /* This is the user-entered handles. */ QList handles; + + /* those are the lines that follows the mouse. */ QGraphicsLineItem *verticalLine; QGraphicsLineItem *horizontalLine; + + /* This is the handler that's being dragged. */ DiveHandler *activeDraggedHandler; + + // helper to save the positions where the drag-handler is valid. + QPointF lastValidPos; + + /* this is the background of the dive, the blue-gradient. */ QGraphicsPolygonItem *diveBg; + + /* This is the bottom ruler - the x axis, and it's associated text */ Ruler *timeLine; QGraphicsSimpleTextItem *timeString; + /* this is the left ruler, the y axis, and it's associated text. */ Ruler *depthLine; QGraphicsSimpleTextItem *depthString; - Button *plusTime; - Button *plusDepth; - Button *lessTime; - Button *lessDepth; - Button *okBtn; - Button *cancelBtn; - QPointF lastValidPos; + /* Buttons */ + Button *plusTime; // adds 10 minutes to the time ruler. + Button *plusDepth; // adds 10 meters to the depth ruler. + Button *lessTime; // remove 10 minutes to the time ruler. + Button *lessDepth; // remove 10 meters to the depth ruler. + Button *okBtn; // accepts, and creates a new dive based on the plan. + Button *cancelBtn; // rejects, and clears the dive plan. }; #endif -- cgit v1.2.3-70-g09d2 From 6115dc1f1299d300d477e32745bbb29bdfe3429d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 11:12:15 -0300 Subject: Change the rules so they work with percentages. Changed the ruler so that they work with percentages, also added a new method to the rules to set the size of the ticks. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 47 +++++++++++++++++++++++++++++++++++++---------- qt-ui/diveplanner.h | 2 ++ 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 0ee87fea5..7d00d1d63 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -29,12 +29,18 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), - fromPercent(100, Qt::Vertical)); + fromPercent(100, Qt::Vertical) + ); verticalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(verticalLine); - horizontalLine = new QGraphicsLineItem(0,0,200,0); + horizontalLine = new QGraphicsLineItem( + fromPercent(0, Qt::Horizontal), + fromPercent(0, Qt::Vertical), + fromPercent(100, Qt::Horizontal), + fromPercent(0, Qt::Vertical) + ); horizontalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(horizontalLine); @@ -42,8 +48,14 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) timeLine->setMinimum(0); timeLine->setMaximum(TIME_INITIAL_MAX); timeLine->setTickInterval(10); - timeLine->setLine(10, 190, 190, 190); + timeLine->setLine( + fromPercent(10, Qt::Horizontal), + fromPercent(90, Qt::Vertical), + fromPercent(90, Qt::Horizontal), + fromPercent(90, Qt::Vertical) + ); timeLine->setOrientation(Qt::Horizontal); + timeLine->setTickSize(fromPercent(1, Qt::Vertical)); timeLine->updateTicks(); scene()->addItem(timeLine); @@ -51,8 +63,16 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) depthLine->setMinimum(0); depthLine->setMaximum(40); depthLine->setTickInterval(10); - depthLine->setLine(10, 1, 10, 190); + + depthLine->setLine( + fromPercent(10, Qt::Horizontal), + fromPercent(10, Qt::Vertical), + fromPercent(10, Qt::Horizontal), + fromPercent(90, Qt::Vertical) + ); + depthLine->setOrientation(Qt::Vertical); + depthLine->setTickSize(fromPercent(1, Qt::Horizontal)); depthLine->updateTicks(); scene()->addItem(depthLine); @@ -262,12 +282,13 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) if (isPointOutOfBoundaries(mappedPos)) return; - verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 200); - horizontalLine->setLine(0, mappedPos.y(), 200, mappedPos.y()); + verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical)); + horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y()); + depthString->setText(QString::number(rint(depthLine->valueAt(mappedPos))) + "m" ); - depthString->setPos(0, mappedPos.y()); + depthString->setPos(fromPercent(5, Qt::Horizontal), mappedPos.y()); timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min"); - timeString->setPos(mappedPos.x()+1, 180); + timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical)); if (activeDraggedHandler) moveActiveHandler(mappedPos); @@ -388,17 +409,23 @@ void Ruler::updateTicks() double steps = (max - min) / interval; double stepSize = (m.x2() - m.x1()) / steps; for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) { - ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + 1, this)); + ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); } } else { double steps = (max - min) / interval; double stepSize = (m.y2() - m.y1()) / steps; for (qreal pos = m.y1(); pos < m.y2(); pos += stepSize) { - ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - 1, pos, this)); + ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this)); } } } +void Ruler::setTickSize(qreal size) +{ + tickSize = size; +} + + void Ruler::setTickInterval(double i) { interval = i; diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 5f0ec7e08..da3e6a4f1 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -37,6 +37,7 @@ public: void setMaximum(double maximum); void setTickInterval(double interval); void setOrientation(Qt::Orientation orientation); + void setTickSize(qreal size); void updateTicks(); double minimum() const; double maximum() const; @@ -51,6 +52,7 @@ private: double interval; double posBegin; double posEnd; + double tickSize; }; class DivePlannerGraphics : public QGraphicsView { -- cgit v1.2.3-70-g09d2 From b07429ff8b9b026044d5851d44151b57f76d7475 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 11:14:11 -0300 Subject: Added the last 'tick' to the rulers The last tick to the rulers were missing, this was making them to look odd, this make the rulers better looking, but it caused the other-non-ported-yet-to-percent stuff to behave in a not so good way, most visible one is the handlers, gonna update them next. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 7d00d1d63..640192d55 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -408,15 +408,19 @@ void Ruler::updateTicks() if (orientation == Qt::Horizontal) { double steps = (max - min) / interval; double stepSize = (m.x2() - m.x1()) / steps; - for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) { + qreal pos; + for (pos = m.x1(); pos < m.x2(); pos += stepSize) { ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); } + ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); } else { double steps = (max - min) / interval; double stepSize = (m.y2() - m.y1()) / steps; - for (qreal pos = m.y1(); pos < m.y2(); pos += stepSize) { + qreal pos; + for (pos = m.y1(); pos < m.y2(); pos += stepSize) { ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this)); } + ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this)); } } -- cgit v1.2.3-70-g09d2 From 94c2e5dc18e5dcf8bd4d69cc82f2798a85b85bc0 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 11:21:28 -0300 Subject: Correct collors for the DivePlanner background. Use the correct colors for the Background on the Dive Plan, same as on the Profile. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 640192d55..eb8f51afa 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -242,16 +242,16 @@ void DivePlannerGraphics::createDecoStops() diveBg->setPolygon(poly); QRectF b = poly.boundingRect(); - QLinearGradient linearGrad( + QLinearGradient pat( b.x(), b.y(), b.x(), b.height() + b.y() ); - linearGrad.setColorAt(0, Qt::green); - linearGrad.setColorAt(1, Qt::white); - diveBg->setBrush(linearGrad); + pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first()); + pat.setColorAt(0, profile_color[DEPTH_TOP].first()); + diveBg->setBrush(pat); deleteTemporaryDivePlan(diveplan.dp); } @@ -409,7 +409,7 @@ void Ruler::updateTicks() double steps = (max - min) / interval; double stepSize = (m.x2() - m.x1()) / steps; qreal pos; - for (pos = m.x1(); pos < m.x2(); pos += stepSize) { + for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) { ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); } ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); -- cgit v1.2.3-70-g09d2 From 43664d7cd5468aa579fc48179f1b5c407a01b83f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 11:47:26 -0300 Subject: Fixed positioning of the dive Handlers. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index eb8f51afa..2bdec9b74 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -218,7 +218,7 @@ void DivePlannerGraphics::createDecoStops() // Re-position the user generated dive handlers Q_FOREACH(DiveHandler *h, handles){ - h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000); + h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm / 1000)); } // (re-) create the profile with different colors for segments that were -- cgit v1.2.3-70-g09d2 From 23b29bd3cd0982eb921dc5cbf8f9e13074fe9e32 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 12:01:47 -0300 Subject: Use the same profile colors on the planer for the Time and Depth Use the same profile colors on the planner for the Time and Depth rulers. this needed a new method on the rulers - setColor, that will call the setPen method and make everything behave properly. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 27 +++++++++++++++++++++------ qt-ui/diveplanner.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2bdec9b74..d0ba86f94 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -56,6 +56,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) ); timeLine->setOrientation(Qt::Horizontal); timeLine->setTickSize(fromPercent(1, Qt::Vertical)); + timeLine->setColor(profile_color[TIME_GRID].at(0)); timeLine->updateTicks(); scene()->addItem(timeLine); @@ -63,16 +64,15 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) depthLine->setMinimum(0); depthLine->setMaximum(40); depthLine->setTickInterval(10); - depthLine->setLine( fromPercent(10, Qt::Horizontal), fromPercent(10, Qt::Vertical), fromPercent(10, Qt::Horizontal), fromPercent(90, Qt::Vertical) ); - depthLine->setOrientation(Qt::Vertical); depthLine->setTickSize(fromPercent(1, Qt::Horizontal)); + depthLine->setColor(profile_color[DEPTH_GRID].at(0)); depthLine->updateTicks(); scene()->addItem(depthLine); @@ -405,22 +405,32 @@ void Ruler::updateTicks() qDeleteAll(ticks); ticks.clear(); QLineF m = line(); + QGraphicsLineItem *item = NULL; + if (orientation == Qt::Horizontal) { double steps = (max - min) / interval; double stepSize = (m.x2() - m.x1()) / steps; qreal pos; for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) { - ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); + item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this); + item->setPen(pen()); + ticks.push_back(item); } - ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this)); + item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this); + item->setPen(pen()); + ticks.push_back(item); } else { double steps = (max - min) / interval; double stepSize = (m.y2() - m.y1()) / steps; qreal pos; for (pos = m.y1(); pos < m.y2(); pos += stepSize) { - ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this)); + item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this); + item->setPen(pen()); + ticks.push_back(item); } - ticks.push_back(new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this)); + item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this); + item->setPen(pen()); + ticks.push_back(item); } } @@ -469,6 +479,11 @@ double Ruler::minimum() const return min; } +void Ruler::setColor(const QColor& color) +{ + setPen(QPen(color)); +} + Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem() { icon = new QGraphicsPixmapItem(this); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index da3e6a4f1..41b4e5c89 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -43,6 +43,7 @@ public: double maximum() const; qreal valueAt(const QPointF& p); qreal posAtValue(qreal value); + void setColor(const QColor& color); private: Qt::Orientation orientation; -- cgit v1.2.3-70-g09d2 From effb7e2fac59cf2b44aa010b1ee17de24d7c6214 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 13:31:25 -0300 Subject: Change the color of the DepthString based on it's deepness Change the color of the DepthString based on it's deepness on the profile planner. The new color of the profileString ( the string that follows the mouse stating how deep you are) is now interpolated from SAMPLE_SHALLOW and SAMPLE_DEEP - but since those two colors were the same and I had to change it so that could work, I want somebody to check if my choose of colors were ok. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 22 ++++++++++++++++++++++ qt-ui/diveplanner.h | 1 + qt-ui/graphicsview-common.cpp | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d0ba86f94..8f8a3b534 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -78,10 +78,12 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) timeString = new QGraphicsSimpleTextItem(); timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations); + timeString->setBrush(profile_color[TIME_TEXT].at(0)); scene()->addItem(timeString); depthString = new QGraphicsSimpleTextItem(); depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); + depthString->setBrush(profile_color[SAMPLE_DEEP].at(0)); scene()->addItem(depthString); diveBg = new QGraphicsPolygonItem(); @@ -290,6 +292,16 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min"); timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical)); + // calculate the correct color for the depthString. + // QGradient doesn't returns it's interpolation, meh. + double percent = depthLine->percentAt(mappedPos); + QColor& startColor = profile_color[SAMPLE_SHALLOW].first(); + QColor& endColor = profile_color[SAMPLE_DEEP].first(); + short redDelta = (endColor.red() - startColor.red()) * percent + startColor.red(); + short greenDelta = (endColor.green() - startColor.green()) * percent + startColor.green(); + short blueDelta = (endColor.blue() - startColor.blue()) * percent + startColor.blue(); + depthString->setBrush( QColor(redDelta, greenDelta, blueDelta)); + if (activeDraggedHandler) moveActiveHandler(mappedPos); if (!handles.count()) @@ -469,6 +481,16 @@ qreal Ruler::posAtValue(qreal value) return retValue; } +qreal Ruler::percentAt(const QPointF& p) +{ + qreal value = valueAt(p); + QLineF m = line(); + double size = max - min; + double percent = value / size; + return percent; +} + + double Ruler::maximum() const { return max; diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 41b4e5c89..a7459de1b 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -42,6 +42,7 @@ public: double minimum() const; double maximum() const; qreal valueAt(const QPointF& p); + qreal percentAt(const QPointF& p); qreal posAtValue(qreal value); void setColor(const QColor& color); diff --git a/qt-ui/graphicsview-common.cpp b/qt-ui/graphicsview-common.cpp index 7545557d9..464626f4b 100644 --- a/qt-ui/graphicsview-common.cpp +++ b/qt-ui/graphicsview-common.cpp @@ -33,8 +33,8 @@ void fill_profile_color() profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS); profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS); profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); - profile_color[SAMPLE_DEEP] = COLOR(PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1); - profile_color[SAMPLE_SHALLOW] = COLOR(PERSIANRED1, BLACK1_LOW_TRANS, PERSIANRED1); + profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1_LOW_TRANS, PERSIANRED1); + profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1); profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS); profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS); profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); -- cgit v1.2.3-70-g09d2 From a7506848b31a3bde21096cf34caacce8a7509f44 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 13:39:54 -0300 Subject: Removed user-entered lines on the plan, keeping only deco. Removed the user-entered lines on the plan, keeping only deco, This way the graph looks way prettier and we don't loose any functionality. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 8f8a3b534..146484a49 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -87,7 +87,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) scene()->addItem(depthString); diveBg = new QGraphicsPolygonItem(); - diveBg->setBrush(QBrush(Qt::green)); + diveBg->setPen(QPen(QBrush(),0)); scene()->addItem(diveBg); plusDepth = new Button(); @@ -233,12 +233,14 @@ void DivePlannerGraphics::createDecoStops() for (dp = diveplan.dp; dp != NULL; dp = dp->next) { double xpos = timeLine->posAtValue(dp->time / 60.0); double ypos = depthLine->posAtValue(dp->depth / 1000.0); - QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos); - item->setPen(QPen(QBrush(dp->entered ? Qt::black : Qt::red),0)); + if(!dp->entered){ + QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos); + item->setPen(QPen(QBrush(Qt::red),0)); + scene()->addItem(item); + lines << item; + } lastx = xpos; lasty = ypos; - scene()->addItem(item); - lines << item; poly.append(QPointF(lastx, lasty)); } -- cgit v1.2.3-70-g09d2 From 6e6a1c08c3c62eac6a809559fc55485b564de3e0 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 14:14:09 -0300 Subject: Make the 'increase depth' button to work. Make the increase depth button to work, it also adds a 'safety' stop at 150m, I know that this is deep, and maybe we need to adjust this to a better safety stop. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 146484a49..7c355a64a 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -14,6 +14,9 @@ #define TIME_INITIAL_MAX 30 +#define MAX_DEEPNESS 150 +#define MIN_DEEPNESS 40 + DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0), lastValidPos(0.0, 0.0) { @@ -92,13 +95,15 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) plusDepth = new Button(); plusDepth->setPixmap(QPixmap(":plus")); - plusDepth->setPos(0, 1); + plusDepth->setPos(fromPercent(5, Qt::Horizontal), fromPercent(5, Qt::Vertical)); + plusDepth->setToolTip("Increase maximum depth by 10m"); scene()->addItem(plusDepth); connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth())); plusTime = new Button(); plusTime->setPixmap(QPixmap(":plus")); - plusTime->setPos(180, 190); + plusTime->setPos(fromPercent(90, Qt::Horizontal), fromPercent(95, Qt::Vertical)); + plusTime->setToolTip("Increase minimum dive time by 10m"); scene()->addItem(plusTime); connect(plusTime, SIGNAL(clicked()), this, SLOT(increaseTime())); @@ -137,7 +142,11 @@ void DivePlannerGraphics::okClicked() void DivePlannerGraphics::increaseDepth() { - qDebug() << "Increase Depth Clicked"; + if (depthLine->maximum() + 10 > MAX_DEEPNESS) + return; + depthLine->setMaximum( depthLine->maximum() + 10); + depthLine->updateTicks(); + createDecoStops(); } void DivePlannerGraphics::increaseTime() @@ -515,12 +524,12 @@ Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem() icon->setPos(0,0); text->setPos(0,0); setFlag(ItemIgnoresTransformations); - setPen(QPen(QBrush(Qt::white), 0)); + setPen(QPen(QBrush(), 0)); } void Button::setPixmap(const QPixmap& pixmap) { - icon->setPixmap(pixmap.scaled(20,20)); + icon->setPixmap(pixmap.scaled(20,20, Qt::KeepAspectRatio, Qt::SmoothTransformation)); if(pixmap.isNull()){ icon->hide(); }else{ -- cgit v1.2.3-70-g09d2 From 7c8bdf70d5300a0325c7c6cc8872373fc8274063 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 2 Jul 2013 14:36:52 -0300 Subject: Make the increase time button to work. Makes the increase time button to work, it will increase the minimum time, not the correct time of the dive. the total time is calculated by the deco, and does not come from this, unless the deco is smaller than the minimum time. This patch also fixes the problem where a button would only click once - I was holding the first clicked button as the 'mouse grabber', bad tomaz. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 10 ++++++++-- qt-ui/diveplanner.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'qt-ui/diveplanner.cpp') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 7c355a64a..4a8ade9df 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "ui_diveplanner.h" #include "mainwindow.h" @@ -119,6 +120,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) scene()->addItem(cancelBtn); connect(cancelBtn, SIGNAL(clicked()), this, SLOT(cancelClicked())); + minMinutes = TIME_INITIAL_MAX; setRenderHint(QPainter::Antialiasing); } @@ -151,7 +153,10 @@ void DivePlannerGraphics::increaseDepth() void DivePlannerGraphics::increaseTime() { - qDebug() << "Increase Time Clicked"; + minMinutes += 10; + timeLine->setMaximum( minMinutes ); + timeLine->updateTicks(); + createDecoStops(); } void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) @@ -222,7 +227,7 @@ void DivePlannerGraphics::createDecoStops() if (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum()) { - double newMax = fmax(dp->time / 60.0 + 5, TIME_INITIAL_MAX); + double newMax = fmax(dp->time / 60.0 + 5, minMinutes); timeLine->setMaximum(newMax); timeLine->updateTicks(); } @@ -553,5 +558,6 @@ void Button::setText(const QString& t) void Button::mousePressEvent(QGraphicsSceneMouseEvent* event) { + event->ignore(); emit clicked(); } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index a7459de1b..e9dfd91e9 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -72,8 +72,8 @@ protected: void createDecoStops(); bool isPointOutOfBoundaries(const QPointF& point); void deleteTemporaryDivePlan(struct divedatapoint* dp); - qreal fromPercent(qreal percent, Qt::Orientation orientation); + private slots: void increaseTime(); void increaseDepth(); @@ -117,6 +117,8 @@ private: Button *lessDepth; // remove 10 meters to the depth ruler. Button *okBtn; // accepts, and creates a new dive based on the plan. Button *cancelBtn; // rejects, and clears the dive plan. + + int minMinutes; // this holds the minimum duration of the dive. }; #endif -- cgit v1.2.3-70-g09d2