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
cf95e5f3
Commit
cf95e5f3
authored
Oct 15, 2010
by
Max-Wilhelm Bruker
Browse files
Added card hover + card info widget popup to MessageLogWidget
parent
e1ad152f
Changes
6
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/abstractcarditem.cpp
View file @
cf95e5f3
...
...
@@ -183,21 +183,14 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
if
(
event
->
button
()
==
Qt
::
LeftButton
)
setCursor
(
Qt
::
ClosedHandCursor
);
else
if
(
event
->
button
()
==
Qt
::
MidButton
)
{
infoWidget
=
new
CardInfoWidget
(
CardInfoWidget
::
ModePopUp
,
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
();
}
else
if
(
event
->
button
()
==
Qt
::
MidButton
)
emit
showCardInfoPopup
(
event
->
screenPos
(),
name
);
event
->
accept
();
}
void
AbstractCardItem
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
infoWidget
)
{
infoWidget
->
deleteLater
();
infoWidget
=
0
;
}
emit
deleteCardInfoPopup
();
}
void
AbstractCardItem
::
processHoverEvent
()
...
...
cockatrice/src/abstractcarditem.h
View file @
cf95e5f3
...
...
@@ -27,6 +27,8 @@ private slots:
void
pixmapUpdated
();
signals:
void
hovered
(
AbstractCardItem
*
card
);
void
showCardInfoPopup
(
QPoint
pos
,
QString
cardName
);
void
deleteCardInfoPopup
();
public:
enum
{
Type
=
typeCard
};
int
type
()
const
{
return
Type
;
}
...
...
cockatrice/src/messagelogwidget.cpp
View file @
cf95e5f3
#include
"messagelogwidget.h"
#include
"player.h"
#include
"cardzone.h"
#include
<QApplication>
#include
"cardinfowidget.h"
#include
<QDebug>
#include
<QMouseEvent>
#include
<QTextBlock>
QString
MessageLogWidget
::
sanitizeHtml
(
QString
dirty
)
const
{
...
...
@@ -227,7 +230,7 @@ void MessageLogWidget::logUnattachCard(Player *player, QString cardName)
void
MessageLogWidget
::
logCreateToken
(
Player
*
player
,
QString
cardName
,
QString
pt
)
{
append
(
tr
(
"%1 creates token: %2%3."
).
arg
(
sanitizeHtml
(
player
->
getName
())).
arg
(
QString
(
"<font color=
\"
blue
\"
>
%1
</font>"
).
arg
(
sanitizeHtml
(
cardName
))).
arg
(
pt
.
isEmpty
()
?
QString
()
:
QString
(
" (%1)"
).
arg
(
sanitizeHtml
(
pt
))));
append
(
tr
(
"%1 creates token: %2%3."
).
arg
(
sanitizeHtml
(
player
->
getName
())).
arg
(
QString
(
"<font color=
\"
blue
\"
>
<a name=
\"
foo
\"
>%1</a>
</font>"
).
arg
(
sanitizeHtml
(
cardName
))).
arg
(
pt
.
isEmpty
()
?
QString
()
:
QString
(
" (%1)"
).
arg
(
sanitizeHtml
(
pt
))));
}
void
MessageLogWidget
::
logCreateArrow
(
Player
*
player
,
Player
*
startPlayer
,
QString
startCard
,
Player
*
targetPlayer
,
QString
targetCard
,
bool
playerTarget
)
...
...
@@ -375,3 +378,58 @@ MessageLogWidget::MessageLogWidget(QWidget *parent)
f
.
setPixelSize
(
11
);
setFont
(
f
);
}
void
MessageLogWidget
::
enterEvent
(
QEvent
*
event
)
{
setMouseTracking
(
true
);
}
void
MessageLogWidget
::
leaveEvent
(
QEvent
*
event
)
{
setMouseTracking
(
false
);
}
QString
MessageLogWidget
::
getCardNameUnderMouse
(
const
QPoint
&
pos
)
const
{
QTextCursor
cursor
(
cursorForPosition
(
pos
));
QTextBlock
block
(
cursor
.
block
());
QTextBlock
::
iterator
it
;
for
(
it
=
block
.
begin
();
!
(
it
.
atEnd
());
++
it
)
{
QTextFragment
frag
=
it
.
fragment
();
if
(
!
frag
.
contains
(
cursor
.
position
()))
continue
;
if
(
frag
.
charFormat
().
foreground
().
color
()
==
Qt
::
blue
)
return
frag
.
text
();
break
;
}
return
QString
();
}
void
MessageLogWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
QString
cardName
=
getCardNameUnderMouse
(
event
->
pos
());
if
(
!
cardName
.
isEmpty
())
emit
cardNameHovered
(
cardName
);
QTextEdit
::
mouseMoveEvent
(
event
);
}
void
MessageLogWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
MidButton
)
{
QString
cardName
=
getCardNameUnderMouse
(
event
->
pos
());
if
(
!
cardName
.
isEmpty
())
emit
showCardInfoPopup
(
event
->
globalPos
(),
cardName
);
}
QTextEdit
::
mousePressEvent
(
event
);
}
void
MessageLogWidget
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
emit
deleteCardInfoPopup
();
QTextEdit
::
mouseReleaseEvent
(
event
);
}
cockatrice/src/messagelogwidget.h
View file @
cf95e5f3
#ifndef MESSAGELOGWIDGET_H
#define MESSAGELOGWIDGET_H
#include
<Q
Plain
TextEdit>
#include
<QTextEdit>
#include
<QAbstractSocket>
#include
"translation.h"
#include
"protocol_datastructures.h"
class
Player
;
class
CardZone
;
class
QMouseEvent
;
class
QEvent
;
class
CardInfoWidget
;
class
MessageLogWidget
:
public
QTextEdit
{
Q_OBJECT
private:
CardInfoWidget
*
infoWidget
;
QString
sanitizeHtml
(
QString
dirty
)
const
;
QString
trZoneName
(
CardZone
*
zone
,
Player
*
player
,
bool
hisOwn
,
GrammaticalCase
gc
)
const
;
QString
getCardNameUnderMouse
(
const
QPoint
&
pos
)
const
;
signals:
void
cardNameHovered
(
QString
cardName
);
void
showCardInfoPopup
(
QPoint
pos
,
QString
cardName
);
void
deleteCardInfoPopup
();
public
slots
:
void
logConnecting
(
QString
hostname
);
void
logConnected
();
...
...
@@ -58,6 +67,12 @@ public slots:
public:
void
connectToPlayer
(
Player
*
player
);
MessageLogWidget
(
QWidget
*
parent
=
0
);
protected:
void
enterEvent
(
QEvent
*
event
);
void
leaveEvent
(
QEvent
*
event
);
void
mouseMoveEvent
(
QMouseEvent
*
event
);
void
mousePressEvent
(
QMouseEvent
*
event
);
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
};
#endif
cockatrice/src/tab_game.cpp
View file @
cf95e5f3
...
...
@@ -4,6 +4,8 @@
#include
<QAction>
#include
<QMessageBox>
#include
<QFileDialog>
#include
<QApplication>
#include
<QDesktopWidget>
#include
"tab_game.h"
#include
"cardinfowidget.h"
#include
"playerlistwidget.h"
...
...
@@ -158,7 +160,7 @@ void DeckViewContainer::setDeck(DeckList *deck)
}
TabGame
::
TabGame
(
QList
<
AbstractClient
*>
&
_clients
,
int
_gameId
,
const
QString
&
_gameDescription
,
int
_localPlayerId
,
bool
_spectator
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
bool
_resuming
)
:
Tab
(),
clients
(
_clients
),
gameId
(
_gameId
),
gameDescription
(
_gameDescription
),
localPlayerId
(
_localPlayerId
),
spectator
(
_spectator
),
spectatorsCanTalk
(
_spectatorsCanTalk
),
spectatorsSeeEverything
(
_spectatorsSeeEverything
),
started
(
false
),
resuming
(
_resuming
),
currentPhase
(
-
1
)
:
Tab
(),
clients
(
_clients
),
gameId
(
_gameId
),
gameDescription
(
_gameDescription
),
localPlayerId
(
_localPlayerId
),
spectator
(
_spectator
),
spectatorsCanTalk
(
_spectatorsCanTalk
),
spectatorsSeeEverything
(
_spectatorsSeeEverything
),
started
(
false
),
resuming
(
_resuming
),
currentPhase
(
-
1
)
,
infoPopup
(
0
)
{
scene
=
new
GameScene
(
this
);
gameView
=
new
GameView
(
scene
);
...
...
@@ -168,6 +170,9 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
playerListWidget
=
new
PlayerListWidget
;
playerListWidget
->
setFocusPolicy
(
Qt
::
NoFocus
);
messageLog
=
new
MessageLogWidget
;
connect
(
messageLog
,
SIGNAL
(
cardNameHovered
(
QString
)),
cardInfo
,
SLOT
(
setCard
(
QString
)));
connect
(
messageLog
,
SIGNAL
(
showCardInfoPopup
(
QPoint
,
QString
)),
this
,
SLOT
(
showCardInfoPopup
(
QPoint
,
QString
)));
connect
(
messageLog
,
SIGNAL
(
deleteCardInfoPopup
()),
this
,
SLOT
(
deleteCardInfoPopup
()));
sayLabel
=
new
QLabel
;
sayEdit
=
new
QLineEdit
;
sayLabel
->
setBuddy
(
sayEdit
);
...
...
@@ -649,6 +654,8 @@ void TabGame::eventPing(Event_Ping *event, GameEventContext * /*context*/)
void
TabGame
::
newCardAdded
(
AbstractCardItem
*
card
)
{
connect
(
card
,
SIGNAL
(
hovered
(
AbstractCardItem
*
)),
cardInfo
,
SLOT
(
setCard
(
AbstractCardItem
*
)));
connect
(
card
,
SIGNAL
(
showCardInfoPopup
(
QPoint
,
QString
)),
this
,
SLOT
(
showCardInfoPopup
(
QPoint
,
QString
)));
connect
(
card
,
SIGNAL
(
deleteCardInfoPopup
()),
this
,
SLOT
(
deleteCardInfoPopup
()));
}
CardItem
*
TabGame
::
getCard
(
int
playerId
,
const
QString
&
zoneName
,
int
cardId
)
const
...
...
@@ -680,3 +687,23 @@ Player *TabGame::getActiveLocalPlayer() const
return
0
;
}
void
TabGame
::
showCardInfoPopup
(
const
QPoint
&
pos
,
const
QString
&
cardName
)
{
infoPopup
=
new
CardInfoWidget
(
CardInfoWidget
::
ModePopUp
,
0
,
Qt
::
Widget
|
Qt
::
FramelessWindowHint
|
Qt
::
X11BypassWindowManagerHint
|
Qt
::
WindowStaysOnTopHint
);
infoPopup
->
setCard
(
cardName
);
QRect
screenRect
=
qApp
->
desktop
()
->
screenGeometry
(
this
);
infoPopup
->
move
(
qMax
(
screenRect
.
left
(),
qMin
(
pos
.
x
()
-
infoPopup
->
width
()
/
2
,
screenRect
.
left
()
+
screenRect
.
width
()
-
infoPopup
->
width
())),
qMax
(
screenRect
.
top
(),
qMin
(
pos
.
y
()
-
infoPopup
->
height
()
/
2
,
screenRect
.
top
()
+
screenRect
.
height
()
-
infoPopup
->
height
()))
);
infoPopup
->
show
();
}
void
TabGame
::
deleteCardInfoPopup
()
{
if
(
infoPopup
)
{
infoPopup
->
deleteLater
();
infoPopup
=
0
;
}
}
cockatrice/src/tab_game.h
View file @
cf95e5f3
...
...
@@ -96,6 +96,7 @@ private:
int
currentPhase
;
int
activePlayer
;
CardInfoWidget
*
infoPopup
;
CardInfoWidget
*
cardInfo
;
PlayerListWidget
*
playerListWidget
;
MessageLogWidget
*
messageLog
;
...
...
@@ -134,6 +135,8 @@ signals:
void
gameClosing
(
TabGame
*
tab
);
private
slots
:
void
newCardAdded
(
AbstractCardItem
*
card
);
void
showCardInfoPopup
(
const
QPoint
&
pos
,
const
QString
&
cardName
);
void
deleteCardInfoPopup
();
void
actConcede
();
void
actLeaveGame
();
...
...
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