Skip to content

Commit

Permalink
#38 - moving drawing constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaza-Is committed Feb 22, 2016
1 parent 9cccf39 commit 6e80bbf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/canvasmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ void CanvasManager::movingComponent(Component *component)
if (d->oldSquareNumberOfMovingComponent != 0)
return;

qreal x = component->pos().x() + (component->boundingRect().width()*d->scaleFactor)/2;
qreal y = component->pos().y() + (component->boundingRect().height()*d->scaleFactor)/2;
qreal x = component->pos().x() + (component->boundingRect().width())/2;
qreal y = component->pos().y() + (component->boundingRect().height())/2;



Expand Down Expand Up @@ -307,8 +307,8 @@ void CanvasManager::parkComponent(Component * component, Cell c)
qreal x = (c.col() - 1) * (GRID_STEP *d->scaleFactor ) + (GRID_STEP *d->scaleFactor)/2;
qreal y = (c.row() - 1) * (GRID_STEP *d->scaleFactor) + (GRID_STEP *d->scaleFactor)/2;

component->setPos((x) - (component->boundingRect().width()*d->scaleFactor)/2,
(y) - (component->boundingRect().height()*d->scaleFactor)/2);
component->setPos((x) - (component->boundingRect().width())/2,
(y) - (component->boundingRect().height())/2);
component->updateConnection();
}

Expand Down
53 changes: 53 additions & 0 deletions src/drawingconstants.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
#include "drawingconstants.h"

namespace Logicsim
{
DrawingConstants::DrawingConstants()
{
v_GATE_X_MARGIN = 20;
v_GATE_Y_MARGIN = 5;
v_CANVAS_WIDTH = 2250;
v_CANVAS_HEIGHT = 2250;
v_GRID_STEP = 150;
v_NUMBER_OF_SQUARES_IN_ROW = v_CANVAS_WIDTH / v_GRID_STEP;
v_NUMBER_OF_SQUARES_IN_COLUMN = v_CANVAS_HEIGHT / v_GRID_STEP;


}
DrawingConstants* DrawingConstants::instance = 0;
DrawingConstants* DrawingConstants::Instance()
{
if(instance == 0) instance = new DrawingConstants();
return instance;
}

int DrawingConstants::GATE_X_MARGIN()
{
return v_GATE_X_MARGIN;
}

int DrawingConstants::GATE_Y_MARGIN()
{
return v_GATE_Y_MARGIN;
}

int DrawingConstants::CANVAS_WIDTH()
{
return v_CANVAS_WIDTH;
}

int DrawingConstants::CANVAS_HEIGHT()
{
return v_CANVAS_HEIGHT;
}

int DrawingConstants::GRID_STEP()
{
return v_GRID_STEP;
}

int DrawingConstants::NUMBER_OF_SQUARES_IN_ROW()
{
return v_NUMBER_OF_SQUARES_IN_ROW;
}

int DrawingConstants::NUMBER_OF_SQUARES_IN_COLUMN()
{
return v_NUMBER_OF_SQUARES_IN_COLUMN;
}


} //namespace LogicSim
24 changes: 21 additions & 3 deletions src/drawingconstants.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#ifndef DRAWINGCONSTANTS_H
#define DRAWINGCONSTANTS_H

namespace Logicsim
{

class DrawingConstants
{
public:
DrawingConstants* Instance();
int GATE_X_MARGIN();
int GATE_Y_MARGIN();
int CANVAS_WIDTH();
int CANVAS_HEIGHT();
int GRID_STEP();
int NUMBER_OF_SQUARES_IN_ROW();
int NUMBER_OF_SQUARES_IN_COLUMN();

private:
static DrawingConstants* instance;
DrawingConstants();
int v_GATE_X_MARGIN;
int v_GATE_Y_MARGIN;
int v_CANVAS_WIDTH;
int v_CANVAS_HEIGHT;
int v_GRID_STEP;
int v_NUMBER_OF_SQUARES_IN_ROW;
int v_NUMBER_OF_SQUARES_IN_COLUMN;

signals:

public slots:
};

} //namespace LogicSim
#endif // DRAWINGCONSTANTS_H

0 comments on commit 6e80bbf

Please sign in to comment.