Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
e0d773e4
Commit
e0d773e4
authored
Jun 20, 2009
by
Max-Wilhelm Bruker
Browse files
forgot some files
parent
c8a2ed94
Changes
4
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/gameselector.cpp
0 → 100644
View file @
e0d773e4
#include
<QtGui>
#include
"gameselector.h"
#include
"dlg_creategame.h"
GameSelector
::
GameSelector
(
Client
*
_client
,
QWidget
*
parent
)
:
QWidget
(
parent
),
client
(
_client
)
{
gameListView
=
new
QTreeView
;
gameListModel
=
new
GamesModel
(
this
);
gameListView
->
setModel
(
gameListModel
);
createButton
=
new
QPushButton
(
tr
(
"&Create"
));
joinButton
=
new
QPushButton
(
tr
(
"&Join"
));
QHBoxLayout
*
buttonLayout
=
new
QHBoxLayout
;
buttonLayout
->
addStretch
();
buttonLayout
->
addWidget
(
createButton
);
buttonLayout
->
addWidget
(
joinButton
);
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addWidget
(
gameListView
);
mainLayout
->
addLayout
(
buttonLayout
);
setLayout
(
mainLayout
);
setMinimumWidth
(
gameListView
->
columnWidth
(
0
)
*
gameListModel
->
columnCount
());
setMinimumHeight
(
400
);
connect
(
createButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actCreate
()));
connect
(
joinButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actJoin
()));
connect
(
client
,
SIGNAL
(
gameListEvent
(
ServerGame
*
)),
gameListModel
,
SLOT
(
updateGameList
(
ServerGame
*
)));
client
->
listGames
();
}
void
GameSelector
::
actCreate
()
{
DlgCreateGame
dlg
(
client
,
this
);
if
(
dlg
.
exec
())
deleteLater
();
}
void
GameSelector
::
actRefresh
()
{
client
->
listGames
();
}
void
GameSelector
::
checkResponse
(
ServerResponse
response
)
{
createButton
->
setEnabled
(
true
);
joinButton
->
setEnabled
(
true
);
if
(
response
==
RespOk
)
deleteLater
();
else
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"XXX"
));
return
;
}
}
void
GameSelector
::
actJoin
()
{
QModelIndex
ind
=
gameListView
->
currentIndex
();
if
(
!
ind
.
isValid
())
return
;
ServerGame
*
game
=
gameListModel
->
getGame
(
ind
.
row
());
QString
password
;
if
(
game
->
getHasPassword
())
{
bool
ok
;
password
=
QInputDialog
::
getText
(
this
,
tr
(
"Join game"
),
tr
(
"Password:"
),
QLineEdit
::
Password
,
QString
(),
&
ok
);
if
(
!
ok
)
return
;
}
PendingCommand
*
joinCommand
=
client
->
joinGame
(
game
->
getGameId
(),
password
);
connect
(
joinCommand
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
)));
createButton
->
setEnabled
(
false
);
joinButton
->
setEnabled
(
false
);
}
cockatrice/src/gameselector.h
0 → 100644
View file @
e0d773e4
#ifndef GAMESELECTOR_H
#define GAMESELECTOR_H
#include
<QWidget>
#include
"gamesmodel.h"
#include
"servergame.h"
#include
"client.h"
class
QPushButton
;
class
QTreeView
;
class
GameSelector
:
public
QWidget
{
Q_OBJECT
public:
GameSelector
(
Client
*
_client
,
QWidget
*
parent
=
0
);
private
slots
:
void
actCreate
();
void
actRefresh
();
void
actJoin
();
void
checkResponse
(
ServerResponse
response
);
private:
Client
*
client
;
QTreeView
*
gameListView
;
GamesModel
*
gameListModel
;
QPushButton
*
createButton
,
*
joinButton
;
};
#endif
cockatrice/src/pilezone.cpp
0 → 100644
View file @
e0d773e4
#include
<QtGui>
#include
"pilezone.h"
#include
"player.h"
#include
"client.h"
#include
"carddragitem.h"
#include
"zoneviewzone.h"
PileZone
::
PileZone
(
Player
*
_p
,
const
QString
&
_name
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
_name
,
false
,
false
,
parent
)
{
cards
=
new
CardList
(
true
);
setCacheMode
(
DeviceCoordinateCache
);
// Do not move this line to the parent constructor!
setCursor
(
Qt
::
OpenHandCursor
);
}
QRectF
PileZone
::
boundingRect
()
const
{
return
QRectF
(
0
,
0
,
CARD_WIDTH
,
CARD_HEIGHT
);
}
void
PileZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
if
(
!
cards
->
isEmpty
())
{
painter
->
save
();
cards
->
at
(
0
)
->
paint
(
painter
,
option
,
widget
);
painter
->
restore
();
}
paintCardNumberEllipse
(
painter
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
}
void
PileZone
::
addCardImpl
(
CardItem
*
card
,
int
x
,
int
/*y*/
)
{
cards
->
insert
(
x
,
card
);
card
->
setPos
(
0
,
0
);
card
->
setVisible
(
false
);
card
->
resetState
();
card
->
setParentItem
(
this
);
}
void
PileZone
::
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
/*dropPoint*/
,
bool
/*faceDown*/
)
{
player
->
client
->
moveCard
(
cardId
,
startZone
->
getName
(),
getName
(),
0
,
0
);
}
void
PileZone
::
reorganizeCards
()
{
qDebug
(
QString
(
"PileZone: reorganize, x=%1, y=%2, w=%3, h=%4"
).
arg
(
boundingRect
().
x
()).
arg
(
boundingRect
().
y
()).
arg
(
boundingRect
().
width
()).
arg
(
boundingRect
().
height
()).
toLatin1
());
update
(
boundingRect
());
}
void
PileZone
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
CardZone
::
mousePressEvent
(
event
);
if
(
event
->
isAccepted
())
return
;
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
setCursor
(
Qt
::
ClosedHandCursor
);
event
->
accept
();
}
else
event
->
ignore
();
}
void
PileZone
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
((
event
->
screenPos
()
-
event
->
buttonDownScreenPos
(
Qt
::
LeftButton
)).
manhattanLength
()
<
QApplication
::
startDragDistance
())
return
;
if
(
cards
->
empty
())
return
;
bool
faceDown
=
event
->
modifiers
().
testFlag
(
Qt
::
ShiftModifier
);
CardItem
*
card
=
cards
->
at
(
0
);
CardDragItem
*
drag
=
card
->
createDragItem
(
card
->
getId
(),
event
->
pos
(),
event
->
scenePos
(),
faceDown
);
drag
->
grabMouse
();
setCursor
(
Qt
::
OpenHandCursor
);
}
void
PileZone
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*/
*
event
*/
)
{
setCursor
(
Qt
::
OpenHandCursor
);
}
cockatrice/src/pilezone.h
0 → 100644
View file @
e0d773e4
#ifndef PILEZONE_H
#define PILEZONE_H
#include
"cardzone.h"
class
PileZone
:
public
CardZone
{
private:
public:
PileZone
(
Player
*
_p
,
const
QString
&
_name
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
reorganizeCards
();
void
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
dropPoint
,
bool
faceDown
);
protected:
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
addCardImpl
(
CardItem
*
card
,
int
x
,
int
y
);
};
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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