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
46fdae43
Commit
46fdae43
authored
Jul 20, 2011
by
Max-Wilhelm Bruker
Browse files
visual improvements: card hover effect, independent scaling of ZoneViewWidget
parent
6b7c5eef
Changes
8
Show whitespace changes
Inline
Side-by-side
cockatrice/src/abstractcarditem.cpp
View file @
46fdae43
...
...
@@ -82,9 +82,8 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
painter
->
setFont
(
f
);
}
void
AbstractCardItem
::
paintPicture
(
QPainter
*
painter
,
int
angle
)
void
AbstractCardItem
::
paintPicture
(
QPainter
*
painter
,
const
QSizeF
&
translatedSize
,
int
angle
)
{
QSizeF
translatedSize
=
getTranslatedSize
(
painter
);
QRectF
totalBoundingRect
=
painter
->
combinedTransform
().
mapRect
(
boundingRect
());
qreal
scaleFactor
=
translatedSize
.
width
()
/
boundingRect
().
width
();
...
...
@@ -143,15 +142,20 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
{
painter
->
save
();
paintPicture
(
painter
,
tapAngle
);
QSizeF
translatedSize
=
getTranslatedSize
(
painter
);
paintPicture
(
painter
,
translatedSize
,
tapAngle
);
painter
->
save
();
painter
->
setRenderHint
(
QPainter
::
Antialiasing
,
false
);
transformPainter
(
painter
,
translatedSize
,
tapAngle
);
if
(
isSelected
())
{
painter
->
setPen
(
Qt
::
red
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
translatedSize
.
width
()
-
1
,
translatedSize
.
height
()
-
1
));
}
else
if
(
isHovered
)
{
painter
->
setPen
(
Qt
::
yellow
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
translatedSize
.
width
()
-
1
,
translatedSize
.
height
()
-
1
));
}
painter
->
restore
();
painter
->
restore
();
}
...
...
cockatrice/src/abstractcarditem.h
View file @
46fdae43
...
...
@@ -37,7 +37,8 @@ public:
AbstractCardItem
(
const
QString
&
_name
=
QString
(),
Player
*
_owner
=
0
,
QGraphicsItem
*
parent
=
0
);
~
AbstractCardItem
();
QRectF
boundingRect
()
const
;
void
paintPicture
(
QPainter
*
painter
,
int
angle
);
QSizeF
getTranslatedSize
(
QPainter
*
painter
)
const
;
void
paintPicture
(
QPainter
*
painter
,
const
QSizeF
&
translatedSize
,
int
angle
);
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
CardInfo
*
getInfo
()
const
{
return
info
;
}
QString
getName
()
const
{
return
name
;
}
...
...
@@ -52,7 +53,6 @@ public:
void
processHoverEvent
();
void
deleteCardInfoPopup
()
{
emit
deleteCardInfoPopup
(
name
);
}
protected:
QSizeF
getTranslatedSize
(
QPainter
*
painter
)
const
;
void
transformPainter
(
QPainter
*
painter
,
const
QSizeF
&
translatedSize
,
int
angle
);
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
...
...
cockatrice/src/carddragitem.cpp
View file @
46fdae43
...
...
@@ -2,7 +2,7 @@
#include
"cardzone.h"
#include
"tablezone.h"
#include
"zoneviewzone.h"
#include
<QGraphicsS
cene
>
#include
"games
cene
.h"
#include
<QGraphicsSceneMouseEvent>
#include
<QCursor>
#include
<QPainter>
...
...
@@ -22,7 +22,7 @@ void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
void
CardDragItem
::
updatePosition
(
const
QPointF
&
cursorScenePos
)
{
QList
<
QGraphicsItem
*>
colliding
=
scene
()
->
items
(
cursorScenePos
);
QList
<
QGraphicsItem
*>
colliding
=
scene
()
->
items
(
cursorScenePos
,
Qt
::
IntersectsItemBoundingRect
,
Qt
::
DescendingOrder
,
static_cast
<
GameScene
*>
(
scene
())
->
getViewTransform
()
);
CardZone
*
cardZone
=
0
;
ZoneViewZone
*
zoneViewZone
=
0
;
...
...
cockatrice/src/gamescene.cpp
View file @
46fdae43
...
...
@@ -9,6 +9,7 @@
#include
<QGraphicsSceneMouseEvent>
#include
<QSet>
#include
<QBasicTimer>
#include
<QGraphicsView>
GameScene
::
GameScene
(
PhasesToolbar
*
_phasesToolbar
,
QObject
*
parent
)
:
QGraphicsScene
(
parent
),
phasesToolbar
(
_phasesToolbar
)
...
...
@@ -25,8 +26,8 @@ GameScene::~GameScene()
void
GameScene
::
retranslateUi
()
{
for
(
int
i
=
0
;
i
<
v
iews
.
size
();
++
i
)
v
iews
[
i
]
->
retranslateUi
();
for
(
int
i
=
0
;
i
<
zoneV
iews
.
size
();
++
i
)
zoneV
iews
[
i
]
->
retranslateUi
();
}
void
GameScene
::
addPlayer
(
Player
*
player
)
...
...
@@ -111,47 +112,52 @@ void GameScene::rearrange()
void
GameScene
::
toggleZoneView
(
Player
*
player
,
const
QString
&
zoneName
,
int
numberCards
)
{
for
(
int
i
=
0
;
i
<
v
iews
.
size
();
i
++
)
{
ZoneViewZone
*
temp
=
v
iews
[
i
]
->
getZone
();
for
(
int
i
=
0
;
i
<
zoneV
iews
.
size
();
i
++
)
{
ZoneViewZone
*
temp
=
zoneV
iews
[
i
]
->
getZone
();
if
((
temp
->
getName
()
==
zoneName
)
&&
(
temp
->
getPlayer
()
==
player
))
{
// view is already open
v
iews
[
i
]
->
close
();
zoneV
iews
[
i
]
->
close
();
if
(
temp
->
getNumberCards
()
==
numberCards
)
return
;
}
}
ZoneViewWidget
*
item
=
new
ZoneViewWidget
(
player
,
player
->
getZones
().
value
(
zoneName
),
numberCards
,
false
);
v
iews
.
append
(
item
);
zoneV
iews
.
append
(
item
);
connect
(
item
,
SIGNAL
(
closePressed
(
ZoneViewWidget
*
)),
this
,
SLOT
(
removeZoneView
(
ZoneViewWidget
*
)));
addItem
(
item
);
item
->
setPos
(
10
0
,
10
0
);
item
->
setPos
(
5
0
,
5
0
);
}
void
GameScene
::
addRevealedZoneView
(
Player
*
player
,
CardZone
*
zone
,
const
QList
<
ServerInfo_Card
*>
&
cardList
)
{
ZoneViewWidget
*
item
=
new
ZoneViewWidget
(
player
,
zone
,
-
2
,
true
,
cardList
);
v
iews
.
append
(
item
);
zoneV
iews
.
append
(
item
);
connect
(
item
,
SIGNAL
(
closePressed
(
ZoneViewWidget
*
)),
this
,
SLOT
(
removeZoneView
(
ZoneViewWidget
*
)));
addItem
(
item
);
item
->
setPos
(
10
0
,
10
0
);
item
->
setPos
(
5
0
,
5
0
);
}
void
GameScene
::
removeZoneView
(
ZoneViewWidget
*
item
)
{
v
iews
.
removeAt
(
v
iews
.
indexOf
(
item
));
zoneV
iews
.
removeAt
(
zoneV
iews
.
indexOf
(
item
));
removeItem
(
item
);
}
void
GameScene
::
clearViews
()
{
for
(
int
i
=
0
;
i
<
v
iews
.
size
();
++
i
)
v
iews
[
i
]
->
close
();
for
(
int
i
=
0
;
i
<
zoneV
iews
.
size
();
++
i
)
zoneV
iews
[
i
]
->
close
();
}
void
GameScene
::
closeMostRecentZoneView
()
{
if
(
!
views
.
isEmpty
())
views
.
last
()
->
close
();
if
(
!
zoneViews
.
isEmpty
())
zoneViews
.
last
()
->
close
();
}
QTransform
GameScene
::
getViewTransform
()
const
{
return
views
().
at
(
0
)
->
transform
();
}
void
GameScene
::
processViewSizeChange
(
const
QSize
&
newSize
)
...
...
@@ -191,7 +197,7 @@ void GameScene::processViewSizeChange(const QSize &newSize)
void
GameScene
::
updateHover
(
const
QPointF
&
scenePos
)
{
QList
<
QGraphicsItem
*>
itemList
=
items
(
scenePos
);
QList
<
QGraphicsItem
*>
itemList
=
items
(
scenePos
,
Qt
::
IntersectsItemBoundingRect
,
Qt
::
DescendingOrder
,
getViewTransform
()
);
// Search for the topmost zone and ignore all cards not belonging to that zone.
CardZone
*
zone
=
0
;
...
...
cockatrice/src/gamescene.h
View file @
46fdae43
...
...
@@ -23,7 +23,7 @@ private:
PhasesToolbar
*
phasesToolbar
;
QList
<
Player
*>
players
;
QList
<
QList
<
Player
*>
>
playersByColumn
;
QList
<
ZoneViewWidget
*>
v
iews
;
QList
<
ZoneViewWidget
*>
zoneV
iews
;
QSize
viewSize
;
QPointer
<
CardItem
>
hoveredCard
;
QBasicTimer
*
animationTimer
;
...
...
@@ -34,6 +34,7 @@ public:
~
GameScene
();
void
retranslateUi
();
void
processViewSizeChange
(
const
QSize
&
newSize
);
QTransform
getViewTransform
()
const
;
void
startRubberBand
(
const
QPointF
&
selectionOrigin
);
void
resizeRubberBand
(
const
QPointF
&
cursorPoint
);
...
...
cockatrice/src/pilezone.cpp
View file @
46fdae43
...
...
@@ -25,7 +25,7 @@ QRectF PileZone::boundingRect() const
void
PileZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
)
{
if
(
!
cards
.
isEmpty
())
cards
.
at
(
0
)
->
paintPicture
(
painter
,
90
);
cards
.
at
(
0
)
->
paintPicture
(
painter
,
cards
.
at
(
0
)
->
getTranslatedSize
(
painter
),
90
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
...
...
cockatrice/src/zoneviewwidget.cpp
View file @
46fdae43
#include
<QGraphicsLinearLayout>
#include
<QGraphicsProxyWidget>
#include
<QGraphicsSceneMouseEvent>
#include
<QCheckBox>
#include
<QLabel>
#include
<QPushButton>
#include
<QPainter>
#include
<QPalette>
#include
"zoneviewwidget.h"
#include
"carditem.h"
#include
"zoneviewzone.h"
...
...
@@ -8,19 +13,70 @@
#include
"gamescene.h"
#include
"protocol_items.h"
#include
"settingscache.h"
#include
"gamescene.h"
TitleLabel
::
TitleLabel
()
:
QGraphicsWidget
(),
text
(
" "
)
{
setAcceptHoverEvents
(
true
);
}
void
TitleLabel
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
)
{
QBrush
windowBrush
=
palette
().
window
();
windowBrush
.
setColor
(
windowBrush
.
color
().
darker
(
150
));
painter
->
fillRect
(
boundingRect
(),
windowBrush
);
painter
->
drawText
(
boundingRect
(),
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
,
text
);
}
QSizeF
TitleLabel
::
sizeHint
(
Qt
::
SizeHint
which
,
const
QSizeF
&
constraint
)
const
{
QFont
f
;
QFontMetrics
fm
(
f
);
if
(
which
==
Qt
::
MaximumSize
)
return
QSizeF
(
constraint
.
width
(),
fm
.
size
(
Qt
::
TextSingleLine
,
text
).
height
()
+
10
);
else
return
fm
.
size
(
Qt
::
TextSingleLine
,
text
);
}
void
TitleLabel
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
buttonDownPos
=
static_cast
<
GameScene
*>
(
scene
())
->
getViewTransform
().
inverted
().
map
(
event
->
pos
());
event
->
accept
();
}
else
event
->
ignore
();
}
void
TitleLabel
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
emit
mouseMoved
(
event
->
scenePos
()
-
buttonDownPos
);
}
ZoneViewWidget
::
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
,
bool
_revealZone
,
const
QList
<
ServerInfo_Card
*>
&
cardList
)
:
QGraphicsWidget
(
0
,
Qt
::
Tool
|
Qt
::
CustomizeWindowHint
|
Qt
::
WindowSystemMenuHint
|
Qt
::
WindowTitleHint
/* | Qt::WindowCloseButton
Hint
*/
),
player
(
_player
)
:
QGraphicsWidget
(
0
,
Qt
::
Tool
|
Qt
::
FramelessWindow
Hint
),
player
(
_player
)
{
setAcceptHoverEvents
(
true
);
setAttribute
(
Qt
::
WA_DeleteOnClose
);
setZValue
(
2000000006
);
setFlag
(
ItemIgnoresTransformations
);
setAutoFillBackground
(
true
);
QFont
font
;
font
.
setPixelSize
(
10
);
setFont
(
font
);
QGraphicsLinearLayout
*
hbox
=
new
QGraphicsLinearLayout
(
Qt
::
Horizontal
);
titleLabel
=
new
TitleLabel
;
connect
(
titleLabel
,
SIGNAL
(
mouseMoved
(
QPointF
)),
this
,
SLOT
(
moveWidget
(
QPointF
)));
closeButton
=
new
QPushButton
(
"X"
);
connect
(
closeButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
close
()));
closeButton
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
);
QGraphicsProxyWidget
*
closeButtonProxy
=
new
QGraphicsProxyWidget
;
closeButtonProxy
->
setWidget
(
closeButton
);
hbox
->
addItem
(
titleLabel
);
hbox
->
addItem
(
closeButtonProxy
);
QGraphicsLinearLayout
*
vbox
=
new
QGraphicsLinearLayout
(
Qt
::
Vertical
);
vbox
->
addItem
(
hbox
);
if
(
numberCards
<
0
)
{
sortByNameCheckBox
=
new
QCheckBox
;
QGraphicsProxyWidget
*
sortByNameProxy
=
new
QGraphicsProxyWidget
;
...
...
@@ -67,7 +123,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
void
ZoneViewWidget
::
retranslateUi
()
{
setWindowTitle
(
zone
->
getTranslatedName
(
false
,
CaseNominative
));
titleLabel
->
setText
(
zone
->
getTranslatedName
(
false
,
CaseNominative
));
if
(
sortByNameCheckBox
)
sortByNameCheckBox
->
setText
(
tr
(
"sort by name"
));
if
(
sortByTypeCheckBox
)
...
...
@@ -76,6 +132,11 @@ void ZoneViewWidget::retranslateUi()
shuffleCheckBox
->
setText
(
tr
(
"shuffle when closing"
));
}
void
ZoneViewWidget
::
moveWidget
(
QPointF
scenePos
)
{
setPos
(
scenePos
);
}
void
ZoneViewWidget
::
resizeToZoneContents
()
{
QRectF
zoneRect
=
zone
->
getOptimumRect
();
...
...
cockatrice/src/zoneviewwidget.h
View file @
46fdae43
#ifndef ZONEVIEWWIDGET_H
#define ZONEVIEWWIDGET_H
#include
<QDialog>
#include
<QGraphicsScene>
#include
<QGraphicsWidget>
class
QLabel
;
class
QPushButton
;
class
CardZone
;
class
ZoneViewZone
;
class
Player
;
...
...
@@ -13,12 +13,32 @@ class QScrollBar;
class
QCheckBox
;
class
GameScene
;
class
ServerInfo_Card
;
class
QGraphicsSceneMouseEvent
;
class
TitleLabel
:
public
QGraphicsWidget
{
Q_OBJECT
private:
QString
text
;
QPointF
buttonDownPos
;
public:
TitleLabel
();
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
);
void
setText
(
const
QString
&
_text
)
{
text
=
_text
;
update
();
}
signals:
void
mouseMoved
(
QPointF
scenePos
);
protected:
QSizeF
sizeHint
(
Qt
::
SizeHint
which
,
const
QSizeF
&
constraint
)
const
;
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
};
class
ZoneViewWidget
:
public
QGraphicsWidget
{
Q_OBJECT
private:
ZoneViewZone
*
zone
;
TitleLabel
*
titleLabel
;
QPushButton
*
closeButton
;
QScrollBar
*
scrollBar
;
QCheckBox
*
sortByNameCheckBox
,
*
sortByTypeCheckBox
,
*
shuffleCheckBox
;
...
...
@@ -29,6 +49,7 @@ signals:
private
slots
:
void
resizeToZoneContents
();
void
zoneDeleted
();
void
moveWidget
(
QPointF
scenePos
);
public:
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
=
0
,
bool
_revealZone
=
false
,
const
QList
<
ServerInfo_Card
*>
&
cardList
=
QList
<
ServerInfo_Card
*>
());
ZoneViewZone
*
getZone
()
const
{
return
zone
;
}
...
...
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