Skip to content

Commit

Permalink
Add scroll area for large widget display.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 1, 2015
1 parent a88b8d8 commit 97a7009
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 30 deletions.
34 changes: 18 additions & 16 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,26 @@ Ground::Ground(QWidget *parent) :
retranslate();

//-----Example-----
// QPolygonF debugBorder, debugBarracks;
// //Set a default border.
// //Border.
// debugBorder << QPointF(30, 60) << QPointF(120, 20)
// << QPointF(400, 45) << QPointF(415, 280)
// << QPointF(180, 340) << QPointF(15, 210);
// setBorder(debugBorder);

// //Set a default barracks.
// //Barracks.
// debugBarracks << QPointF(200, 200) << QPointF(200, 275)
// << QPointF(275, 275) << QPointF(275, 200);
// setBarracks(debugBarracks);

// //Set some robots.
// addRobot(new Robot(203, 203));
// addRobot(new Robot(210, 210));
// addRobot(new Robot(210, 220));
// addRobot(new Robot(203, 210));
// addRobot(new Robot(210, 203));
// addRobot(new Robot(203, 250));
// addRobot(new Robot(209, 250));
// addRobot(new Robot(250, 210));
// addRobot(new Robot(203, 207));
// addRobot(new Robot(204, 207));
// //Robots.
// Robot(203, 203));
// Robot(210, 210));
// Robot(210, 220));
// Robot(203, 210));
// Robot(210, 203));
// Robot(203, 250));
// Robot(209, 250));
// Robot(250, 210));
// Robot(203, 207));
// Robot(204, 207));
}

Ground::~Ground()
Expand Down Expand Up @@ -413,6 +410,11 @@ void Ground::clearGroundData()
m_robotList.clear();
m_robotInitialAngle.clear();
m_robotInitialPosition.clear();

//Hack way to repaint all the things. WTF!
hide();
show();

//Resize ground.
setFixedSize(0,0);
}
Expand Down
17 changes: 7 additions & 10 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ MainWindow::MainWindow(QWidget *parent) :
m_robotManagement(new RobotManagement(this)),
m_groundGenerator(new GenerateGround(this))
{
//A hack, using box layout to make the ground the center.
QWidget *container=new QWidget(this);
//Set the central widget.
setCentralWidget(container);
QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::LeftToRight,
container);
container->setLayout(mainLayout);
//Add ground and panel to layout.
mainLayout->addWidget(m_ground, 1, Qt::AlignCenter);
mainLayout->addWidget(m_panel);
//Set the minimum size.
setMinimumSize(500, 309);
//Initial the scroll area.
QScrollArea *groundArea=new QScrollArea(this);
setCentralWidget(groundArea);
groundArea->setAlignment(Qt::AlignCenter);
groundArea->setWidget(m_ground);

//Set the ground generator.
m_ground->setGenerator(m_groundGenerator);
Expand Down
16 changes: 15 additions & 1 deletion robotaddwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ RobotAddWidget::RobotAddWidget(QWidget *parent) :
mainLayout->widget());
buttonLayout->setSpacing(2);
buttonLayout->addWidget(m_okay);
buttonLayout->addWidget(m_cancel);
m_cancel->setShortcut(QKeySequence(Qt::Key_Escape));
buttonLayout->addWidget(m_cancel);
buttonLayout->addStretch();
mainLayout->addLayout(buttonLayout);

Expand All @@ -107,6 +107,18 @@ void RobotAddWidget::updateXAndYRange(const int &minX, const int &minY,
m_yData->setRange(minY, maxY);
}

void RobotAddWidget::enabledWidget()
{
m_okay->setDefault(true);
setEnabled(true);
}

void RobotAddWidget::disabledWidget()
{
m_okay->setDefault(false);
setEnabled(false);
}

void RobotAddWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
Expand All @@ -116,6 +128,8 @@ void RobotAddWidget::showEvent(QShowEvent *event)
m_angleData->setValue(0);
//Update the preview.
onActionParameterChange();
//Set the focus to x data edit.
m_xData->setFocus();
}

void RobotAddWidget::retranslate()
Expand Down
12 changes: 12 additions & 0 deletions robotaddwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ class RobotAddWidget : public QWidget
void updateXAndYRange(const int &minX, const int &minY,
const int &maxX, const int &maxY);

/*!
* \brief Call this function will bind the default button and enabled this
* widget.
*/
void enabledWidget();

/*!
* \brief Call this function will unbind the default button and disable this
* widget.
*/
void disabledWidget();

signals:
/*!
* \brief When this signal is emitted, the robot management dialog will be
Expand Down
21 changes: 19 additions & 2 deletions robotmanagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ GroundBase *RobotManagement::ground()

void RobotManagement::addRobot()
{
//Check the ground first. If it don't have a border, or barracks, we don't
//need to popup this dialog.
if(m_ground->border().isEmpty())
{
return;
}
//Show the add robot widget.
m_robotManagement->disabledWidget();
m_robotAdd->enabledWidget();
m_stackLayout->setCurrentWidget(m_robotAdd);
//Make the preview show the preview robot.
m_groundPreview->setShowPreviewPoint(true);
Expand All @@ -128,9 +136,17 @@ void RobotManagement::addRobot()

void RobotManagement::manageRobot()
{
//Check the ground first. If it don't have a border, or barracks, we don't
//need to popup this dialog.
if(m_ground->border().isEmpty())
{
return;
}
//When you manage the robot, we must reset the ground.
m_ground->reset();
//Show the manage widget.
//Show and enabled the manage widget, disabled the add widget.
m_robotAdd->disabledWidget();
m_robotManagement->enabledWidget();
m_stackLayout->setCurrentWidget(m_robotManagement);
//Hide the preview robot.
m_groundPreview->setShowPreviewPoint(false);
Expand Down Expand Up @@ -177,5 +193,6 @@ void RobotManagement::onActionAddRobot(const QPointF &position,
//Or else, display an error information.
QMessageBox::warning(this,
tr("Add Robot Failed"),
tr("The robot is not in the barracks, you cannot add this robot"));
tr("The robot is not in the barracks, or the position has already got a robot.\n"
"Please change the position of the robot."));
}
14 changes: 13 additions & 1 deletion robotmanagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ RobotManageWidget::RobotManageWidget(QWidget *parent) :
mainLayout->widget());
buttonLayout->setSpacing(2);
buttonLayout->addWidget(m_okay);
buttonLayout->addWidget(m_cancel);
m_cancel->setShortcut(QKeySequence(Qt::Key_Escape));
buttonLayout->addWidget(m_cancel);
buttonLayout->addStretch();
mainLayout->addLayout(buttonLayout);

Expand Down Expand Up @@ -254,6 +254,18 @@ QList<qreal> RobotManageWidget::angleList()
return angleList;
}

void RobotManageWidget::enabledWidget()
{
m_okay->setDefault(true);
setEnabled(true);
}

void RobotManageWidget::disabledWidget()
{
m_okay->setDefault(false);
setEnabled(false);
}

void RobotManageWidget::setGround(GroundBase *ground)
{
//Save the new ground.
Expand Down
12 changes: 12 additions & 0 deletions robotmanagewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ class RobotManageWidget : public QWidget
*/
QList<qreal> angleList();

/*!
* \brief Call this function will bind the default button and enabled this
* widget.
*/
void enabledWidget();

/*!
* \brief Call this function will unbind the default button and disable this
* widget.
*/
void disabledWidget();

signals:
/*!
* \brief When this signal is emitted, the robot management dialog will be
Expand Down

0 comments on commit 97a7009

Please sign in to comment.