mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <tcanabrava@kde.org>
This commit is contained in:
parent
c98894fd52
commit
6115dc1f12
2 changed files with 39 additions and 10 deletions
|
@ -29,12 +29,18 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
fromPercent(0, Qt::Horizontal),
|
fromPercent(0, Qt::Horizontal),
|
||||||
fromPercent(0, Qt::Vertical),
|
fromPercent(0, Qt::Vertical),
|
||||||
fromPercent(0, Qt::Horizontal),
|
fromPercent(0, Qt::Horizontal),
|
||||||
fromPercent(100, Qt::Vertical));
|
fromPercent(100, Qt::Vertical)
|
||||||
|
);
|
||||||
|
|
||||||
verticalLine->setPen(QPen(Qt::DotLine));
|
verticalLine->setPen(QPen(Qt::DotLine));
|
||||||
scene()->addItem(verticalLine);
|
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));
|
horizontalLine->setPen(QPen(Qt::DotLine));
|
||||||
scene()->addItem(horizontalLine);
|
scene()->addItem(horizontalLine);
|
||||||
|
|
||||||
|
@ -42,8 +48,14 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
timeLine->setMinimum(0);
|
timeLine->setMinimum(0);
|
||||||
timeLine->setMaximum(TIME_INITIAL_MAX);
|
timeLine->setMaximum(TIME_INITIAL_MAX);
|
||||||
timeLine->setTickInterval(10);
|
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->setOrientation(Qt::Horizontal);
|
||||||
|
timeLine->setTickSize(fromPercent(1, Qt::Vertical));
|
||||||
timeLine->updateTicks();
|
timeLine->updateTicks();
|
||||||
scene()->addItem(timeLine);
|
scene()->addItem(timeLine);
|
||||||
|
|
||||||
|
@ -51,8 +63,16 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
depthLine->setMinimum(0);
|
depthLine->setMinimum(0);
|
||||||
depthLine->setMaximum(40);
|
depthLine->setMaximum(40);
|
||||||
depthLine->setTickInterval(10);
|
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->setOrientation(Qt::Vertical);
|
||||||
|
depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
|
||||||
depthLine->updateTicks();
|
depthLine->updateTicks();
|
||||||
scene()->addItem(depthLine);
|
scene()->addItem(depthLine);
|
||||||
|
|
||||||
|
@ -262,12 +282,13 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
|
||||||
if (isPointOutOfBoundaries(mappedPos))
|
if (isPointOutOfBoundaries(mappedPos))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 200);
|
verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical));
|
||||||
horizontalLine->setLine(0, mappedPos.y(), 200, mappedPos.y());
|
horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y());
|
||||||
|
|
||||||
depthString->setText(QString::number(rint(depthLine->valueAt(mappedPos))) + "m" );
|
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->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)
|
if (activeDraggedHandler)
|
||||||
moveActiveHandler(mappedPos);
|
moveActiveHandler(mappedPos);
|
||||||
|
@ -388,17 +409,23 @@ void Ruler::updateTicks()
|
||||||
double steps = (max - min) / interval;
|
double steps = (max - min) / interval;
|
||||||
double stepSize = (m.x2() - m.x1()) / steps;
|
double stepSize = (m.x2() - m.x1()) / steps;
|
||||||
for (qreal 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() + 1, this));
|
ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
double steps = (max - min) / interval;
|
double steps = (max - min) / interval;
|
||||||
double stepSize = (m.y2() - m.y1()) / steps;
|
double stepSize = (m.y2() - m.y1()) / steps;
|
||||||
for (qreal pos = m.y1(); pos < m.y2(); pos += stepSize) {
|
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)
|
void Ruler::setTickInterval(double i)
|
||||||
{
|
{
|
||||||
interval = i;
|
interval = i;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
void setMaximum(double maximum);
|
void setMaximum(double maximum);
|
||||||
void setTickInterval(double interval);
|
void setTickInterval(double interval);
|
||||||
void setOrientation(Qt::Orientation orientation);
|
void setOrientation(Qt::Orientation orientation);
|
||||||
|
void setTickSize(qreal size);
|
||||||
void updateTicks();
|
void updateTicks();
|
||||||
double minimum() const;
|
double minimum() const;
|
||||||
double maximum() const;
|
double maximum() const;
|
||||||
|
@ -51,6 +52,7 @@ private:
|
||||||
double interval;
|
double interval;
|
||||||
double posBegin;
|
double posBegin;
|
||||||
double posEnd;
|
double posEnd;
|
||||||
|
double tickSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DivePlannerGraphics : public QGraphicsView {
|
class DivePlannerGraphics : public QGraphicsView {
|
||||||
|
|
Loading…
Add table
Reference in a new issue