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 <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-07-02 13:31:25 -03:00
parent 23b29bd3cd
commit effb7e2fac
3 changed files with 25 additions and 2 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);