Start to make things sane again...

Change the 'namespace ItemPos' declared on the commit before this one to a
struct that will have all the 'on canvas' and 'off canvas' positions and
representations of all items, so we know where to change.

Also remove the remaining stuff from planer that was going to exist on
this profile.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-02-07 15:32:39 -02:00 committed by Dirk Hohndel
parent 9756be59aa
commit 86bc3bd58f
2 changed files with 42 additions and 37 deletions

View file

@ -22,23 +22,31 @@
#endif #endif
#include "mainwindow.h" #include "mainwindow.h"
namespace ItemPos{ /* This is the global 'Item position' variable.
int backgroundOnCanvas; * it should tell you where to position things up
int backgroundOffCanvas; * on the canvas.
int profileYAxisOnCanvas; *
int profileYAxisOffCanvas; * please, please, please, use this instead of
// unused so far: * hard coding the item on the scene with a random
int gasYAxisOnCanvas; * value.
int depthControllerOnCanvas; */
int timeControllerOnCanvas; static struct _ItemPos{
int gasYAxisOffCanvas; struct _Pos{
int timeAxisOnCanvas; QPointF on;
int timeAxisOffCanvas; QPointF off;
int timeAxisEditMode; };
int depthControllerOffCanvas; struct _Axis{
int timeControllerOffCanvas; _Pos pos;
QLineF profileYAxisExpanded; QLineF shrinked;
} QLineF expanded;
};
_Pos background;
_Axis depth;
_Axis partialgas;
_Axis time;
_Axis cylinder;
_Axis temperature;
} itemPos;
ProfileWidget2::ProfileWidget2(QWidget *parent) : ProfileWidget2::ProfileWidget2(QWidget *parent) :
QGraphicsView(parent), QGraphicsView(parent),
@ -51,8 +59,6 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
gasYAxis(new PartialGasPressureAxis()), gasYAxis(new PartialGasPressureAxis()),
temperatureAxis(new TemperatureAxis()), temperatureAxis(new TemperatureAxis()),
timeAxis(new TimeAxis()), timeAxis(new TimeAxis()),
depthController(new DiveRectItem()),
timeController(new DiveRectItem()),
diveProfileItem(new DiveProfileItem()), diveProfileItem(new DiveProfileItem()),
cylinderPressureAxis(new DiveCartesianAxis()), cylinderPressureAxis(new DiveCartesianAxis()),
temperatureItem(new DiveTemperatureItem()), temperatureItem(new DiveTemperatureItem()),
@ -87,8 +93,6 @@ void ProfileWidget2::addItemsToScene()
scene()->addItem(gasYAxis); scene()->addItem(gasYAxis);
scene()->addItem(temperatureAxis); scene()->addItem(temperatureAxis);
scene()->addItem(timeAxis); scene()->addItem(timeAxis);
scene()->addItem(depthController);
scene()->addItem(timeController);
scene()->addItem(diveProfileItem); scene()->addItem(diveProfileItem);
scene()->addItem(cylinderPressureAxis); scene()->addItem(cylinderPressureAxis);
scene()->addItem(temperatureItem); scene()->addItem(temperatureItem);
@ -131,9 +135,6 @@ void ProfileWidget2::setupItemOnScene()
cylinderPressureAxis->setTickSize(2); cylinderPressureAxis->setTickSize(2);
cylinderPressureAxis->setTickInterval(30000); cylinderPressureAxis->setTickInterval(30000);
depthController->setRect(0, 0, 10, 5);
timeController->setRect(0, 0, 10, 5);
timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
meanDepth->setLine(0,0,96,0); meanDepth->setLine(0,0,96,0);
meanDepth->setX(3); meanDepth->setX(3);
meanDepth->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine)); meanDepth->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
@ -173,7 +174,11 @@ void ProfileWidget2::setupItemOnScene()
void ProfileWidget2::setupItemSizes() void ProfileWidget2::setupItemSizes()
{ {
// Scene is *always* 100 / 100.
itemPos.background.on.setX(0);
itemPos.background.on.setY(0);
itemPos.background.off.setX(0);
itemPos.background.off.setY(110);
} }
void ProfileWidget2::setupItem(AbstractProfilePolygonItem* item, DiveCartesianAxis* hAxis, DiveCartesianAxis* vAxis, DivePlotDataModel* model, int vData, int hData, int zValue) void ProfileWidget2::setupItem(AbstractProfilePolygonItem* item, DiveCartesianAxis* hAxis, DiveCartesianAxis* vAxis, DivePlotDataModel* model, int vData, int hData, int zValue)
@ -290,7 +295,9 @@ void ProfileWidget2::settingsChanged()
void ProfileWidget2::resizeEvent(QResizeEvent* event) void ProfileWidget2::resizeEvent(QResizeEvent* event)
{ {
QGraphicsView::resizeEvent(event); QGraphicsView::resizeEvent(event); DiveRectItem *depthController;
DiveRectItem *timeController;
fitInView(sceneRect(), Qt::IgnoreAspectRatio); fitInView(sceneRect(), Qt::IgnoreAspectRatio);
} }
@ -301,9 +308,8 @@ void ProfileWidget2::fixBackgroundPos()
return; return;
QPixmap p = toBeScaled.scaledToHeight(viewport()->height()); QPixmap p = toBeScaled.scaledToHeight(viewport()->height());
int x = viewport()->width() / 2 - p.width() / 2; int x = viewport()->width() / 2 - p.width() / 2;
DivePixmapItem *bg = background; background->setPixmap(p);
bg->setPixmap(p); background->setX(mapToScene(x, 0).x());
bg->setX(mapToScene(x, 0).x());
} }
void ProfileWidget2::wheelEvent(QWheelEvent* event) void ProfileWidget2::wheelEvent(QWheelEvent* event)

View file

@ -44,12 +44,6 @@ struct AbstractProfilePolygonItem;
class ProfileWidget2 : public QGraphicsView { class ProfileWidget2 : public QGraphicsView {
Q_OBJECT Q_OBJECT
void fixBackgroundPos();
void scrollViewTo(const QPoint& pos);
void setupSceneAndFlags();
void setupItemSizes();
void addItemsToScene();
void setupItemOnScene();
public: public:
enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID }; enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS}; enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
@ -69,6 +63,13 @@ protected:
signals: signals:
void startProfileState(); void startProfileState();
void startEmptyState(); void startEmptyState();
private: /*methods*/
void fixBackgroundPos();
void scrollViewTo(const QPoint& pos);
void setupSceneAndFlags();
void setupItemSizes();
void addItemsToScene();
void setupItemOnScene();
private: private:
DivePlotDataModel *dataModel; DivePlotDataModel *dataModel;
State currentState; State currentState;
@ -83,8 +84,6 @@ private:
PartialGasPressureAxis *gasYAxis; PartialGasPressureAxis *gasYAxis;
TemperatureAxis *temperatureAxis; TemperatureAxis *temperatureAxis;
TimeAxis *timeAxis; TimeAxis *timeAxis;
DiveRectItem *depthController;
DiveRectItem *timeController;
DiveProfileItem *diveProfileItem; DiveProfileItem *diveProfileItem;
DiveCartesianPlane *cartesianPlane; DiveCartesianPlane *cartesianPlane;
DiveTemperatureItem *temperatureItem; DiveTemperatureItem *temperatureItem;