Skip to content

Commit

Permalink
1.0 Release Candidate III
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 4, 2015
1 parent 1046d6a commit f300a3c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
36 changes: 32 additions & 4 deletions gridwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QPainter>
#include <QStaticText>

#include "groundglobal.h"

Expand All @@ -36,15 +37,42 @@ void GridWidget::paintEvent(QPaintEvent *event)
QPainter painter(this);
painter.setPen(GroundGlobal::instance()->referenceLineColor());
painter.setBrush(QColor(0,0,0,0));
for(int i=30; i<=height(); i+=30)
QFont textFont=font();
textFont.setPixelSize(4);
painter.setFont(textFont);
int stopWidth=width()+height()+m_gridStep;
for(int i=0; i<stopWidth; i+=m_gridStep)
{
painter.drawLine(0, i, width(), i);
//Draw right top to left bottom lines.
painter.drawLine(i, 0, i-height(), height());
//Draw left top to right bottom lines.
painter.drawLine(i, 0, i+height(), height());
int horizon=i-m_gridSize+8;
for(int j=-m_gridSize-2; j<height()+m_gridStep; j+=m_gridSize)
{
painter.drawStaticText(horizon,
j,
QStaticText("("+QString::number(horizon)+", "+QString::number(j)+")"));
horizon-=m_gridSize;
}
}
for(int i=30; i<=width(); i+=30)
stopWidth=-height();
for(int i=0; i>=stopWidth; i-=m_gridStep)
{
painter.drawLine(i, 0, i, height());
painter.drawLine(i, 0, i+height(), height());
}
}

int GridWidget::m_gridStep=100;
int GridWidget::m_gridSize=50;

void GridWidget::setGridStep(int gridStep)
{
//Update the parameter.
m_gridStep = gridStep;
m_gridSize = m_gridStep>>1;
}

QWidget *GridWidget::widget() const
{
return m_widget;
Expand Down
9 changes: 9 additions & 0 deletions gridwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class GridWidget : public QWidget
*/
QWidget *widget() const;

static int gridSize();
static void setGridSize(int gridSize);

static int gridStep();
static void setGridStep(int gridStep);

signals:

public slots:
Expand All @@ -64,6 +70,9 @@ public slots:

private:
QWidget *m_widget;

static int m_gridSize;
static int m_gridStep;
};

#endif // GRIDWIDGET_H
2 changes: 1 addition & 1 deletion groundglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GroundGlobal::GroundGlobal(QObject *parent) :
m_barracksColor(QColor(79,219,251)),
m_referenceLineColor(QColor(27, 68, 76)),
m_baseColor(QColor(1,7,20)),
m_groundColor(QColor(0x00, 0x40, 0x51))
m_groundColor(QColor(0x00, 0x40, 0x51, 200))
{
}

Expand Down

0 comments on commit f300a3c

Please sign in to comment.