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
a215b350
Commit
a215b350
authored
Oct 13, 2010
by
Max-Wilhelm Bruker
Browse files
Added MTGO-like card info widget, made original info widget hideable
parent
d6c00d65
Changes
7
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/abstractcarditem.cpp
View file @
a215b350
...
...
@@ -5,6 +5,7 @@
#include
<QGraphicsSceneMouseEvent>
#include
<math.h>
#include
"carddatabase.h"
#include
"cardinfowidget.h"
#include
"abstractcarditem.h"
#include
"settingscache.h"
#include
"main.h"
...
...
@@ -12,7 +13,7 @@
#include
<QTimer>
AbstractCardItem
::
AbstractCardItem
(
const
QString
&
_name
,
Player
*
_owner
,
QGraphicsItem
*
parent
)
:
ArrowTarget
(
_owner
,
parent
),
info
(
db
->
getCard
(
_name
)),
name
(
_name
),
tapped
(
false
),
tapAngle
(
0
)
:
ArrowTarget
(
_owner
,
parent
),
info
(
db
->
getCard
(
_name
)),
infoWidget
(
0
),
name
(
_name
),
tapped
(
false
),
tapAngle
(
0
)
{
setCursor
(
Qt
::
OpenHandCursor
);
setFlag
(
ItemIsSelectable
);
...
...
@@ -180,9 +181,23 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
if
(
event
->
button
()
==
Qt
::
LeftButton
)
setCursor
(
Qt
::
ClosedHandCursor
);
else
if
(
event
->
button
()
==
Qt
::
MidButton
)
{
infoWidget
=
new
CardInfoWidget
(
false
,
0
,
Qt
::
Widget
|
Qt
::
FramelessWindowHint
|
Qt
::
X11BypassWindowManagerHint
|
Qt
::
WindowStaysOnTopHint
);
infoWidget
->
setCard
(
this
);
infoWidget
->
move
(
event
->
screenPos
().
x
()
-
infoWidget
->
width
()
/
2
,
event
->
screenPos
().
y
()
-
infoWidget
->
height
()
/
2
);
infoWidget
->
show
();
}
event
->
accept
();
}
void
AbstractCardItem
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
infoWidget
)
{
infoWidget
->
deleteLater
();
infoWidget
=
0
;
}
}
void
AbstractCardItem
::
processHoverEvent
()
{
emit
hovered
(
this
);
...
...
cockatrice/src/abstractcarditem.h
View file @
a215b350
...
...
@@ -4,6 +4,7 @@
#include
"arrowtarget.h"
class
CardInfo
;
class
CardInfoWidget
;
class
Player
;
class
QTimer
;
...
...
@@ -14,6 +15,7 @@ class AbstractCardItem : public QObject, public ArrowTarget {
Q_OBJECT
protected:
CardInfo
*
info
;
CardInfoWidget
*
infoWidget
;
QString
name
;
bool
tapped
;
int
tapAngle
;
...
...
@@ -42,6 +44,7 @@ public:
void
processHoverEvent
();
protected:
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
QVariant
itemChange
(
QGraphicsItem
::
GraphicsItemChange
change
,
const
QVariant
&
value
);
};
...
...
cockatrice/src/cardinfowidget.cpp
View file @
a215b350
#include
<QGridLayout>
#include
<QLabel>
#include
<QTextEdit>
#include
<QPushButton>
#include
<QStyle>
#include
"cardinfowidget.h"
#include
"carditem.h"
#include
"carddatabase.h"
#include
"main.h"
CardInfoWidget
::
CardInfoWidget
(
QWidget
*
parent
)
:
QFrame
(
parent
),
pixmapHeight
(
pixmapWidth
),
info
(
0
)
CardInfoWidget
::
CardInfoWidget
(
bool
showMinimizeButton
,
QWidget
*
parent
,
Qt
::
WindowFlags
flags
)
:
QFrame
(
parent
,
flags
),
pixmapHeight
(
pixmapWidth
),
minimized
(
false
),
minimizeButton
(
0
),
info
(
0
)
{
pixmapHeight
=
pixmapWidth
*
CARD_HEIGHT
/
CARD_WIDTH
;
if
(
showMinimizeButton
)
{
minimizeButton
=
new
QPushButton
(
QIcon
(
style
()
->
standardIcon
(
QStyle
::
SP_ArrowUp
)),
QString
());
connect
(
minimizeButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
minimizeClicked
()));
}
cardPicture
=
new
QLabel
;
cardPicture
->
setAlignment
(
Qt
::
AlignCenter
);
...
...
@@ -40,31 +49,51 @@ CardInfoWidget::CardInfoWidget(QWidget *parent)
textLabel
->
setFont
(
f
);
QGridLayout
*
grid
=
new
QGridLayout
(
this
);
grid
->
addWidget
(
cardPicture
,
0
,
0
,
1
,
2
);
grid
->
addWidget
(
nameLabel1
,
1
,
0
);
grid
->
addWidget
(
nameLabel2
,
1
,
1
);
grid
->
addWidget
(
manacostLabel1
,
2
,
0
);
grid
->
addWidget
(
manacostLabel2
,
2
,
1
);
grid
->
addWidget
(
cardtypeLabel1
,
3
,
0
);
grid
->
addWidget
(
cardtypeLabel2
,
3
,
1
);
grid
->
addWidget
(
powtoughLabel1
,
4
,
0
);
grid
->
addWidget
(
powtoughLabel2
,
4
,
1
);
grid
->
addWidget
(
textLabel
,
5
,
0
,
-
1
,
2
);
grid
->
setRowStretch
(
5
,
1
);
int
row
=
0
;
if
(
showMinimizeButton
)
grid
->
addWidget
(
minimizeButton
,
row
++
,
1
,
1
,
1
,
Qt
::
AlignRight
);
grid
->
addWidget
(
cardPicture
,
row
++
,
0
,
1
,
2
);
grid
->
addWidget
(
nameLabel1
,
row
,
0
);
grid
->
addWidget
(
nameLabel2
,
row
++
,
1
);
grid
->
addWidget
(
manacostLabel1
,
row
,
0
);
grid
->
addWidget
(
manacostLabel2
,
row
++
,
1
);
grid
->
addWidget
(
cardtypeLabel1
,
row
,
0
);
grid
->
addWidget
(
cardtypeLabel2
,
row
++
,
1
);
grid
->
addWidget
(
powtoughLabel1
,
row
,
0
);
grid
->
addWidget
(
powtoughLabel2
,
row
++
,
1
);
grid
->
addWidget
(
textLabel
,
row
,
0
,
-
1
,
2
);
grid
->
setRowStretch
(
row
,
1
);
grid
->
setColumnStretch
(
1
,
1
);
CardInfo
*
cardBack
=
db
->
getCard
();
QPixmap
*
bigPixmap
=
cardBack
->
loadPixmap
();
if
(
bigPixmap
->
isNull
())
pixmapHeight
=
pixmapWidth
*
CARD_HEIGHT
/
CARD_WIDTH
;
else
pixmapHeight
=
pixmapWidth
*
bigPixmap
->
height
()
/
bigPixmap
->
width
();
setCard
(
cardBack
);
retranslateUi
();
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
textLabel
->
setFixedHeight
(
100
);
setFixedSize
(
sizeHint
());
if
(
showMinimizeButton
)
{
textLabel
->
setFixedHeight
(
100
);
setFixedWidth
(
sizeHint
().
width
());
}
else
setFixedWidth
(
350
);
setFixedHeight
(
sizeHint
().
height
());
}
void
CardInfoWidget
::
minimizeClicked
()
{
cardPicture
->
setVisible
(
minimized
);
nameLabel2
->
setVisible
(
minimized
);
nameLabel1
->
setVisible
(
minimized
);
manacostLabel1
->
setVisible
(
minimized
);
manacostLabel2
->
setVisible
(
minimized
);
cardtypeLabel1
->
setVisible
(
minimized
);
cardtypeLabel2
->
setVisible
(
minimized
);
powtoughLabel1
->
setVisible
(
minimized
);
powtoughLabel2
->
setVisible
(
minimized
);
textLabel
->
setVisible
(
minimized
);
minimizeButton
->
setIcon
(
style
()
->
standardIcon
(
minimized
?
QStyle
::
SP_ArrowUp
:
QStyle
::
SP_ArrowDown
));
minimized
=
!
minimized
;
setFixedHeight
(
sizeHint
().
height
());
}
void
CardInfoWidget
::
setCard
(
CardInfo
*
card
)
...
...
cockatrice/src/cardinfowidget.h
View file @
a215b350
...
...
@@ -5,6 +5,7 @@
class
QLabel
;
class
QTextEdit
;
class
QPushButton
;
class
AbstractCardItem
;
class
CardInfo
;
...
...
@@ -13,7 +14,9 @@ class CardInfoWidget : public QFrame {
private:
static
const
int
pixmapWidth
=
160
;
int
pixmapHeight
;
bool
minimized
;
QPushButton
*
minimizeButton
;
QLabel
*
cardPicture
;
QLabel
*
nameLabel1
,
*
nameLabel2
;
QLabel
*
manacostLabel1
,
*
manacostLabel2
;
...
...
@@ -23,7 +26,7 @@ private:
CardInfo
*
info
;
public:
CardInfoWidget
(
QWidget
*
parent
=
0
);
CardInfoWidget
(
bool
showMinimizeButton
=
true
,
QWidget
*
parent
=
0
,
Qt
::
WindowFlags
f
=
0
);
void
retranslateUi
();
public
slots
:
void
setCard
(
CardInfo
*
card
);
...
...
@@ -31,6 +34,7 @@ public slots:
void
setCard
(
AbstractCardItem
*
card
);
private
slots
:
void
updatePixmap
();
void
minimizeClicked
();
};
#endif
cockatrice/src/carditem.cpp
View file @
a215b350
...
...
@@ -325,7 +325,7 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
scene
()
->
addItem
(
childArrow
);
arrow
->
addChildArrow
(
childArrow
);
}
}
else
{
}
else
if
(
event
->
buttons
().
testFlag
(
Qt
::
LeftButton
))
{
if
((
event
->
screenPos
()
-
event
->
buttonDownScreenPos
(
Qt
::
LeftButton
)).
manhattanLength
()
<
2
*
QApplication
::
startDragDistance
())
return
;
if
(
!
owner
->
getLocal
())
...
...
@@ -384,6 +384,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
playCard
(
event
);
setCursor
(
Qt
::
OpenHandCursor
);
AbstractCardItem
::
mouseReleaseEvent
(
event
);
}
void
CardItem
::
mouseDoubleClickEvent
(
QGraphicsSceneMouseEvent
*
event
)
...
...
cockatrice/src/playerlistwidget.cpp
View file @
a215b350
...
...
@@ -13,6 +13,7 @@ PlayerListWidget::PlayerListWidget(QWidget *parent)
playerIcon
=
QIcon
(
":/resources/icon_player.svg"
);
spectatorIcon
=
QIcon
(
":/resources/icon_spectator.svg"
);
setMinimumHeight
(
100
);
setIconSize
(
QSize
(
20
,
15
));
setColumnCount
(
6
);
setRootIsDecorated
(
false
);
...
...
cockatrice/src/tab_game.cpp
View file @
a215b350
...
...
@@ -185,7 +185,7 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
QVBoxLayout
*
verticalLayout
=
new
QVBoxLayout
;
verticalLayout
->
addWidget
(
cardInfo
);
verticalLayout
->
addWidget
(
playerListWidget
,
1
);
verticalLayout
->
addWidget
(
messageLog
,
3
);
verticalLayout
->
addWidget
(
messageLog
,
5
);
verticalLayout
->
addLayout
(
hLayout
);
mainLayout
=
new
QHBoxLayout
;
...
...
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