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
99c0a41d
Commit
99c0a41d
authored
Dec 14, 2010
by
Max-Wilhelm Bruker
Browse files
improved rubber band drag
parent
99387861
Changes
15
Show whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
99c0a41d
...
...
@@ -16,6 +16,7 @@ HEADERS += src/counter.h \
src
/
remoteclient
.
h
\
src
/
window_main
.
h
\
src
/
cardzone
.
h
\
src
/
selectzone
.
h
\
src
/
player
.
h
\
src
/
playertarget
.
h
\
src
/
cardlist
.
h
\
...
...
@@ -96,6 +97,7 @@ SOURCES += src/counter.cpp \
src
/
player
.
cpp
\
src
/
playertarget
.
cpp
\
src
/
cardzone
.
cpp
\
src
/
selectzone
.
cpp
\
src
/
cardlist
.
cpp
\
src
/
abstractcarditem
.
cpp
\
src
/
carditem
.
cpp
\
...
...
cockatrice/src/gamescene.cpp
View file @
99c0a41d
...
...
@@ -195,3 +195,18 @@ bool GameScene::event(QEvent *event)
}
return
QGraphicsScene
::
event
(
event
);
}
void
GameScene
::
startRubberBand
(
const
QPointF
&
selectionOrigin
)
{
emit
sigStartRubberBand
(
selectionOrigin
);
}
void
GameScene
::
resizeRubberBand
(
const
QPointF
&
cursorPoint
)
{
emit
sigResizeRubberBand
(
cursorPoint
);
}
void
GameScene
::
stopRubberBand
()
{
emit
sigStopRubberBand
();
}
cockatrice/src/gamescene.h
View file @
99c0a41d
...
...
@@ -23,6 +23,10 @@ public:
void
retranslateUi
();
const
QRectF
&
getPlayersRect
()
const
{
return
playersRect
;
}
void
processViewSizeChange
(
const
QSize
&
newSize
);
void
startRubberBand
(
const
QPointF
&
selectionOrigin
);
void
resizeRubberBand
(
const
QPointF
&
cursorPoint
);
void
stopRubberBand
();
public
slots
:
void
toggleZoneView
(
Player
*
player
,
const
QString
&
zoneName
,
int
numberCards
);
void
addRevealedZoneView
(
Player
*
player
,
CardZone
*
zone
,
const
QList
<
ServerInfo_Card
*>
&
cardList
);
...
...
@@ -35,6 +39,10 @@ private slots:
void
rearrange
();
protected:
bool
event
(
QEvent
*
event
);
signals:
void
sigStartRubberBand
(
const
QPointF
&
selectionOrigin
);
void
sigResizeRubberBand
(
const
QPointF
&
cursorPoint
);
void
sigStopRubberBand
();
};
#endif
cockatrice/src/gameview.cpp
View file @
99c0a41d
...
...
@@ -2,18 +2,22 @@
#include
"gamescene.h"
#include
<QResizeEvent>
#include
<QAction>
#include
<QRubberBand>
GameView
::
GameView
(
QGraphicsScene
*
scene
,
QWidget
*
parent
)
:
QGraphicsView
(
scene
,
parent
)
:
QGraphicsView
(
scene
,
parent
)
,
rubberBand
(
0
)
{
setBackgroundBrush
(
QBrush
(
QColor
(
0
,
0
,
0
)));
setRenderHints
(
QPainter
::
TextAntialiasing
|
QPainter
::
Antialiasing
/* | QPainter::SmoothPixmapTransform*/
);
setDragMode
(
RubberBandDrag
);
setFocusPolicy
(
Qt
::
NoFocus
);
setViewportUpdateMode
(
BoundingRectViewportUpdate
);
connect
(
scene
,
SIGNAL
(
sceneRectChanged
(
const
QRectF
&
)),
this
,
SLOT
(
updateSceneRect
(
const
QRectF
&
)));
connect
(
scene
,
SIGNAL
(
sigStartRubberBand
(
const
QPointF
&
)),
this
,
SLOT
(
startRubberBand
(
const
QPointF
&
)));
connect
(
scene
,
SIGNAL
(
sigResizeRubberBand
(
const
QPointF
&
)),
this
,
SLOT
(
resizeRubberBand
(
const
QPointF
&
)));
connect
(
scene
,
SIGNAL
(
sigStopRubberBand
()),
this
,
SLOT
(
stopRubberBand
()));
aCloseMostRecentZoneView
=
new
QAction
(
this
);
aCloseMostRecentZoneView
->
setShortcut
(
tr
(
"Esc"
));
connect
(
aCloseMostRecentZoneView
,
SIGNAL
(
triggered
()),
scene
,
SLOT
(
closeMostRecentZoneView
()));
...
...
@@ -35,3 +39,25 @@ void GameView::updateSceneRect(const QRectF &rect)
qDebug
(
QString
(
"updateSceneRect = %1,%2"
).
arg
(
rect
.
width
()).
arg
(
rect
.
height
()).
toLatin1
());
fitInView
(
rect
,
Qt
::
KeepAspectRatio
);
}
void
GameView
::
startRubberBand
(
const
QPointF
&
_selectionOrigin
)
{
selectionOrigin
=
_selectionOrigin
;
rubberBand
=
new
QRubberBand
(
QRubberBand
::
Rectangle
,
this
);
rubberBand
->
setGeometry
(
QRect
(
mapFromScene
(
selectionOrigin
),
QSize
(
0
,
0
)));
rubberBand
->
show
();
}
void
GameView
::
resizeRubberBand
(
const
QPointF
&
cursorPoint
)
{
if
(
rubberBand
)
rubberBand
->
setGeometry
(
QRect
(
mapFromScene
(
selectionOrigin
),
mapFromScene
(
cursorPoint
)).
normalized
());
}
void
GameView
::
stopRubberBand
()
{
if
(
rubberBand
)
{
rubberBand
->
deleteLater
();
rubberBand
=
0
;
}
}
cockatrice/src/gameview.h
View file @
99c0a41d
...
...
@@ -3,12 +3,20 @@
#include
<QGraphicsView>
class
QRubberBand
;
class
GameView
:
public
QGraphicsView
{
Q_OBJECT
private:
QAction
*
aCloseMostRecentZoneView
;
QRubberBand
*
rubberBand
;
QPointF
selectionOrigin
;
protected:
void
resizeEvent
(
QResizeEvent
*
event
);
private
slots
:
void
startRubberBand
(
const
QPointF
&
selectionOrigin
);
void
resizeRubberBand
(
const
QPointF
&
cursorPoint
);
void
stopRubberBand
();
public
slots
:
void
updateSceneRect
(
const
QRectF
&
rect
);
public:
...
...
cockatrice/src/handzone.cpp
View file @
99c0a41d
...
...
@@ -5,7 +5,7 @@
#include
"protocol_items.h"
HandZone
::
HandZone
(
Player
*
_p
,
bool
_contentsKnown
,
int
_zoneHeight
,
QGraphicsItem
*
parent
)
:
Card
Zone
(
_p
,
"hand"
,
false
,
false
,
_contentsKnown
,
parent
),
zoneHeight
(
_zoneHeight
)
:
Select
Zone
(
_p
,
"hand"
,
false
,
false
,
_contentsKnown
,
parent
),
zoneHeight
(
_zoneHeight
)
{
connect
(
settingsCache
,
SIGNAL
(
handBgPathChanged
()),
this
,
SLOT
(
updateBgPixmap
()));
updateBgPixmap
();
...
...
cockatrice/src/handzone.h
View file @
99c0a41d
#ifndef HANDZONE_H
#define HANDZONE_H
#include
"
card
zone.h"
#include
"
select
zone.h"
class
HandZone
:
public
Card
Zone
{
class
HandZone
:
public
Select
Zone
{
Q_OBJECT
private:
qreal
width
,
zoneHeight
;
...
...
cockatrice/src/selectzone.cpp
0 → 100644
View file @
99c0a41d
#include
<QGraphicsSceneMouseEvent>
#include
"selectzone.h"
#include
"gamescene.h"
SelectZone
::
SelectZone
(
Player
*
_player
,
const
QString
&
_name
,
bool
_hasCardAttr
,
bool
_isShufflable
,
bool
_contentsKnown
,
QGraphicsItem
*
parent
,
bool
isView
)
:
CardZone
(
_player
,
_name
,
_hasCardAttr
,
_isShufflable
,
_contentsKnown
,
parent
,
isView
)
{
}
void
SelectZone
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
event
->
buttons
().
testFlag
(
Qt
::
LeftButton
))
{
QPointF
pos
=
event
->
pos
();
if
(
pos
.
x
()
<
0
)
pos
.
setX
(
0
);
QRectF
br
=
boundingRect
();
if
(
pos
.
x
()
>
br
.
width
())
pos
.
setX
(
br
.
width
());
if
(
pos
.
y
()
<
0
)
pos
.
setY
(
0
);
if
(
pos
.
y
()
>
br
.
height
())
pos
.
setY
(
br
.
height
());
QRectF
selectionRect
=
QRectF
(
selectionOrigin
,
pos
).
normalized
();
for
(
int
i
=
0
;
i
<
cards
.
size
();
++
i
)
cards
[
i
]
->
setSelected
(
selectionRect
.
intersects
(
cards
[
i
]
->
mapRectToParent
(
cards
[
i
]
->
boundingRect
())));
static_cast
<
GameScene
*>
(
scene
())
->
resizeRubberBand
(
scenePos
()
+
pos
);
event
->
accept
();
}
}
void
SelectZone
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
selectionOrigin
=
event
->
pos
();
static_cast
<
GameScene
*>
(
scene
())
->
startRubberBand
(
event
->
scenePos
());
event
->
accept
();
}
}
void
SelectZone
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
selectionOrigin
=
QPoint
();
static_cast
<
GameScene
*>
(
scene
())
->
stopRubberBand
();
event
->
accept
();
}
cockatrice/src/selectzone.h
0 → 100644
View file @
99c0a41d
#ifndef SELECTZONE_H
#define SELECTZONE_H
#include
"cardzone.h"
class
SelectZone
:
public
CardZone
{
Q_OBJECT
private:
QPointF
selectionOrigin
;
protected:
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
public:
SelectZone
(
Player
*
_player
,
const
QString
&
_name
,
bool
_hasCardAttr
,
bool
_isShufflable
,
bool
_contentsKnown
,
QGraphicsItem
*
parent
=
0
,
bool
isView
=
false
);
};
#endif
cockatrice/src/stackzone.cpp
View file @
99c0a41d
...
...
@@ -7,7 +7,7 @@
#include
"protocol_items.h"
StackZone
::
StackZone
(
Player
*
_p
,
int
_zoneHeight
,
QGraphicsItem
*
parent
)
:
Card
Zone
(
_p
,
"stack"
,
false
,
false
,
true
,
parent
),
zoneHeight
(
_zoneHeight
)
:
Select
Zone
(
_p
,
"stack"
,
false
,
false
,
true
,
parent
),
zoneHeight
(
_zoneHeight
)
{
connect
(
settingsCache
,
SIGNAL
(
stackBgPathChanged
()),
this
,
SLOT
(
updateBgPixmap
()));
updateBgPixmap
();
...
...
cockatrice/src/stackzone.h
View file @
99c0a41d
#ifndef STACKZONE_H
#define STACKZONE_H
#include
"
card
zone.h"
#include
"
select
zone.h"
class
StackZone
:
public
Card
Zone
{
class
StackZone
:
public
Select
Zone
{
Q_OBJECT
private:
qreal
zoneHeight
;
...
...
cockatrice/src/tablezone.cpp
View file @
99c0a41d
...
...
@@ -9,7 +9,7 @@
#include
"arrowitem.h"
TableZone
::
TableZone
(
Player
*
_p
,
QGraphicsItem
*
parent
)
:
Card
Zone
(
_p
,
"table"
,
true
,
false
,
true
,
parent
),
active
(
false
)
:
Select
Zone
(
_p
,
"table"
,
true
,
false
,
true
,
parent
),
active
(
false
)
{
connect
(
settingsCache
,
SIGNAL
(
tableBgPathChanged
()),
this
,
SLOT
(
updateBgPixmap
()));
connect
(
settingsCache
,
SIGNAL
(
economicalGridChanged
()),
this
,
SLOT
(
reorganizeCards
()));
...
...
cockatrice/src/tablezone.h
View file @
99c0a41d
#ifndef TABLEZONE_H
#define TABLEZONE_H
#include
"
card
zone.h"
#include
"
select
zone.h"
class
TableZone
:
public
Card
Zone
{
class
TableZone
:
public
Select
Zone
{
Q_OBJECT
signals:
void
sizeChanged
();
...
...
cockatrice/src/zoneviewzone.cpp
View file @
99c0a41d
...
...
@@ -5,7 +5,7 @@
#include
"protocol_items.h"
ZoneViewZone
::
ZoneViewZone
(
Player
*
_p
,
CardZone
*
_origZone
,
int
_numberCards
,
QGraphicsItem
*
parent
)
:
Card
Zone
(
_p
,
_origZone
->
getName
(),
false
,
false
,
true
,
parent
,
true
),
bRect
(
QRectF
()),
minRows
(
0
),
numberCards
(
_numberCards
),
origZone
(
_origZone
),
sortByName
(
false
),
sortByType
(
false
)
:
Select
Zone
(
_p
,
_origZone
->
getName
(),
false
,
false
,
true
,
parent
,
true
),
bRect
(
QRectF
()),
minRows
(
0
),
numberCards
(
_numberCards
),
origZone
(
_origZone
),
sortByName
(
false
),
sortByType
(
false
)
{
origZone
->
setView
(
this
);
}
...
...
cockatrice/src/zoneviewzone.h
View file @
99c0a41d
#ifndef ZONEVIEWERZONE_H
#define ZONEVIEWERZONE_H
#include
"
card
zone.h"
#include
"
select
zone.h"
#include
<QGraphicsLayoutItem>
class
ZoneViewWidget
;
class
ProtocolResponse
;
class
ServerInfo_Card
;
class
ZoneViewZone
:
public
Card
Zone
,
public
QGraphicsLayoutItem
{
class
ZoneViewZone
:
public
Select
Zone
,
public
QGraphicsLayoutItem
{
Q_OBJECT
private:
QRectF
bRect
,
optimumRect
;
...
...
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