mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-12 14:26:16 +00:00
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 <tcanabrava@kde.org>
This commit is contained in:
parent
ca517f1bf8
commit
c98894fd52
2 changed files with 41 additions and 14 deletions
|
@ -21,9 +21,16 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
setBackgroundBrush(profile_color[BACKGROUND].at(0));
|
setBackgroundBrush(profile_color[BACKGROUND].at(0));
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setScene(new QGraphicsScene());
|
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));
|
verticalLine->setPen(QPen(Qt::DotLine));
|
||||||
scene()->addItem(verticalLine);
|
scene()->addItem(verticalLine);
|
||||||
|
|
||||||
|
@ -88,6 +95,13 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
setRenderHint(QPainter::Antialiasing);
|
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()
|
void DivePlannerGraphics::cancelClicked()
|
||||||
{
|
{
|
||||||
qDebug() << "clicked";
|
qDebug() << "clicked";
|
||||||
|
@ -133,10 +147,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
createDecoStops();
|
createDecoStops();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerGraphics::clearGeneratedDeco()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DivePlannerGraphics::createDecoStops()
|
void DivePlannerGraphics::createDecoStops()
|
||||||
{
|
{
|
||||||
qDeleteAll(lines);
|
qDeleteAll(lines);
|
||||||
|
|
|
@ -65,10 +65,11 @@ protected:
|
||||||
virtual void mousePressEvent(QMouseEvent* event);
|
virtual void mousePressEvent(QMouseEvent* event);
|
||||||
virtual void mouseReleaseEvent(QMouseEvent* event);
|
virtual void mouseReleaseEvent(QMouseEvent* event);
|
||||||
|
|
||||||
void clearGeneratedDeco();
|
|
||||||
void createDecoStops();
|
void createDecoStops();
|
||||||
bool isPointOutOfBoundaries(const QPointF& point);
|
bool isPointOutOfBoundaries(const QPointF& point);
|
||||||
void deleteTemporaryDivePlan(struct divedatapoint* dp);
|
void deleteTemporaryDivePlan(struct divedatapoint* dp);
|
||||||
|
|
||||||
|
qreal fromPercent(qreal percent, Qt::Orientation orientation);
|
||||||
private slots:
|
private slots:
|
||||||
void increaseTime();
|
void increaseTime();
|
||||||
void increaseDepth();
|
void increaseDepth();
|
||||||
|
@ -77,25 +78,41 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveActiveHandler(const QPointF& pos);
|
void moveActiveHandler(const QPointF& pos);
|
||||||
|
|
||||||
|
/* This are the lines of the plotted dive. */
|
||||||
QList<QGraphicsLineItem*> lines;
|
QList<QGraphicsLineItem*> lines;
|
||||||
|
|
||||||
|
/* This is the user-entered handles. */
|
||||||
QList<DiveHandler *> handles;
|
QList<DiveHandler *> handles;
|
||||||
|
|
||||||
|
/* those are the lines that follows the mouse. */
|
||||||
QGraphicsLineItem *verticalLine;
|
QGraphicsLineItem *verticalLine;
|
||||||
QGraphicsLineItem *horizontalLine;
|
QGraphicsLineItem *horizontalLine;
|
||||||
|
|
||||||
|
/* This is the handler that's being dragged. */
|
||||||
DiveHandler *activeDraggedHandler;
|
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;
|
QGraphicsPolygonItem *diveBg;
|
||||||
|
|
||||||
|
/* This is the bottom ruler - the x axis, and it's associated text */
|
||||||
Ruler *timeLine;
|
Ruler *timeLine;
|
||||||
QGraphicsSimpleTextItem *timeString;
|
QGraphicsSimpleTextItem *timeString;
|
||||||
|
|
||||||
|
/* this is the left ruler, the y axis, and it's associated text. */
|
||||||
Ruler *depthLine;
|
Ruler *depthLine;
|
||||||
QGraphicsSimpleTextItem *depthString;
|
QGraphicsSimpleTextItem *depthString;
|
||||||
|
|
||||||
Button *plusTime;
|
/* Buttons */
|
||||||
Button *plusDepth;
|
Button *plusTime; // adds 10 minutes to the time ruler.
|
||||||
Button *lessTime;
|
Button *plusDepth; // adds 10 meters to the depth ruler.
|
||||||
Button *lessDepth;
|
Button *lessTime; // remove 10 minutes to the time ruler.
|
||||||
Button *okBtn;
|
Button *lessDepth; // remove 10 meters to the depth ruler.
|
||||||
Button *cancelBtn;
|
Button *okBtn; // accepts, and creates a new dive based on the plan.
|
||||||
QPointF lastValidPos;
|
Button *cancelBtn; // rejects, and clears the dive plan.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue