Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qt-tutorial-porting
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Tvete
qt-tutorial-porting
Commits
a8a17fc9
Commit
a8a17fc9
authored
May 22, 2018
by
Paul Tvete
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use layouts instead of hardcoded sizes
parent
2f4c634c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
24 deletions
+31
-24
t14/cannon.h
t14/cannon.h
+1
-0
t14/gamebrd.cpp
t14/gamebrd.cpp
+30
-21
t14/gamebrd.h
t14/gamebrd.h
+0
-2
t14/main.cpp
t14/main.cpp
+0
-1
No files found.
t14/cannon.h
View file @
a8a17fc9
...
...
@@ -20,6 +20,7 @@ public:
int
force
()
const
{
return
f
;
}
bool
gameOver
()
const
{
return
gameEnded
;
}
bool
isShooting
()
const
{
return
shooting
;
}
QSize
sizeHint
()
const
{
return
QSize
(
400
,
300
);
}
public
slots
:
void
setAngle
(
int
degrees
);
void
setForce
(
int
newton
);
...
...
t14/gamebrd.cpp
View file @
a8a17fc9
...
...
@@ -13,14 +13,15 @@
#include <qpushbutton.h>
#include <qlcdnumber.h>
#include <QBoxLayout>
#include <QGridLayout>
#include "lcdrange.h"
#include "cannon.h"
GameBoard
::
GameBoard
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
setMinimumSize
(
500
,
355
);
quit
=
new
QPushButton
(
"Quit"
,
this
);
quit
->
setFont
(
QFont
(
"Times"
,
18
,
QFont
::
Bold
)
);
...
...
@@ -35,7 +36,7 @@ GameBoard::GameBoard(QWidget *parent)
frame
=
new
QFrame
(
this
);
frame
->
setFrameStyle
(
QFrame
::
WinPanel
|
QFrame
::
Sunken
);
cannonField
=
new
CannonField
(
this
);
cannonField
=
new
CannonField
(
frame
);
cannonField
->
setPalette
(
QPalette
(
QColor
(
250
,
250
,
200
))
);
cannonField
->
setAutoFillBackground
(
true
);
...
...
@@ -72,28 +73,36 @@ GameBoard::GameBoard(QWidget *parent)
QShortcut
*
quitShortcut
=
new
QShortcut
(
Qt
::
Key_Q
,
this
);
connect
(
quitShortcut
,
SIGNAL
(
activated
()),
qApp
,
SLOT
(
quit
()));
quit
->
setGeometry
(
10
,
10
,
75
,
30
);
angle
->
setGeometry
(
10
,
quit
->
y
()
+
quit
->
height
()
+
10
,
75
,
130
);
force
->
setGeometry
(
10
,
angle
->
y
()
+
angle
->
height
()
+
10
,
75
,
130
);
frame
->
move
(
angle
->
x
()
+
angle
->
width
()
+
10
,
angle
->
y
()
);
cannonField
->
move
(
frame
->
x
()
+
2
,
frame
->
y
()
+
2
);
shoot
->
setGeometry
(
10
,
315
,
75
,
30
);
restart
->
setGeometry
(
380
,
10
,
110
,
30
);
hits
->
setGeometry
(
130
,
10
,
40
,
30
);
hitsL
->
setGeometry
(
hits
->
x
()
+
hits
->
width
()
+
5
,
10
,
60
,
30
);
shotsLeft
->
setGeometry
(
240
,
10
,
40
,
30
);
shotsLeftL
->
setGeometry
(
shotsLeft
->
x
()
+
shotsLeft
->
width
()
+
5
,
10
,
60
,
30
);
QGridLayout
*
topLayout
=
new
QGridLayout
(
this
);
topLayout
->
addWidget
(
quit
,
0
,
0
);
QVBoxLayout
*
sideColumn
=
new
QVBoxLayout
;
topLayout
->
addLayout
(
sideColumn
,
1
,
0
);
sideColumn
->
addWidget
(
angle
);
sideColumn
->
addWidget
(
force
);
sideColumn
->
addWidget
(
shoot
);
QHBoxLayout
*
topRow
=
new
QHBoxLayout
;
topLayout
->
addLayout
(
topRow
,
0
,
1
);
topRow
->
addStretch
();
topRow
->
addWidget
(
hits
);
topRow
->
addWidget
(
hitsL
);
topRow
->
addStretch
();
topRow
->
addWidget
(
shotsLeft
);
topRow
->
addWidget
(
shotsLeftL
);
topRow
->
addStretch
();
topRow
->
addWidget
(
restart
);
topLayout
->
addWidget
(
frame
,
1
,
1
);
QVBoxLayout
*
frameLayout
=
new
QVBoxLayout
(
frame
);
frameLayout
->
addWidget
(
cannonField
);
int
margin
=
frame
->
frameWidth
();
frameLayout
->
setContentsMargins
(
margin
,
margin
,
margin
,
margin
);
newGame
();
}
void
GameBoard
::
resizeEvent
(
QResizeEvent
*
)
{
frame
->
resize
(
width
()
-
frame
->
x
()
-
10
,
height
()
-
frame
->
y
()
-
10
);
cannonField
->
resize
(
frame
->
width
()
-
4
,
frame
->
height
()
-
4
);
}
void
GameBoard
::
fire
()
{
if
(
cannonField
->
gameOver
()
||
cannonField
->
isShooting
()
)
...
...
t14/gamebrd.h
View file @
a8a17fc9
...
...
@@ -24,8 +24,6 @@ class GameBoard : public QWidget
Q_OBJECT
public:
GameBoard
(
QWidget
*
parent
=
0
);
protected:
void
resizeEvent
(
QResizeEvent
*
);
protected
slots
:
void
fire
();
void
hit
();
...
...
t14/main.cpp
View file @
a8a17fc9
...
...
@@ -14,7 +14,6 @@ int main( int argc, char **argv )
QApplication
a
(
argc
,
argv
);
GameBoard
gb
;
gb
.
setGeometry
(
100
,
100
,
500
,
355
);
gb
.
show
();
return
a
.
exec
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment