Added card hover + card info widget popup to MessageLogWidget
This commit is contained in:
parent
e1ad152f65
commit
cf95e5f328
6 changed files with 112 additions and 14 deletions
|
@ -183,21 +183,14 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
else if (event->button() == Qt::MidButton) {
|
else if (event->button() == Qt::MidButton)
|
||||||
infoWidget = new CardInfoWidget(CardInfoWidget::ModePopUp, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
|
emit showCardInfoPopup(event->screenPos(), name);
|
||||||
infoWidget->setCard(this);
|
|
||||||
infoWidget->move(event->screenPos().x() - infoWidget->width() / 2, event->screenPos().y() - infoWidget->height() / 2);
|
|
||||||
infoWidget->show();
|
|
||||||
}
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (infoWidget) {
|
emit deleteCardInfoPopup();
|
||||||
infoWidget->deleteLater();
|
|
||||||
infoWidget = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::processHoverEvent()
|
void AbstractCardItem::processHoverEvent()
|
||||||
|
|
|
@ -27,6 +27,8 @@ private slots:
|
||||||
void pixmapUpdated();
|
void pixmapUpdated();
|
||||||
signals:
|
signals:
|
||||||
void hovered(AbstractCardItem *card);
|
void hovered(AbstractCardItem *card);
|
||||||
|
void showCardInfoPopup(QPoint pos, QString cardName);
|
||||||
|
void deleteCardInfoPopup();
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCard };
|
enum { Type = typeCard };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "messagelogwidget.h"
|
#include "messagelogwidget.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include <QApplication>
|
#include "cardinfowidget.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QTextBlock>
|
||||||
|
|
||||||
QString MessageLogWidget::sanitizeHtml(QString dirty) const
|
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)
|
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)
|
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);
|
f.setPixelSize(11);
|
||||||
setFont(f);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
#ifndef MESSAGELOGWIDGET_H
|
#ifndef MESSAGELOGWIDGET_H
|
||||||
#define MESSAGELOGWIDGET_H
|
#define MESSAGELOGWIDGET_H
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
#include "protocol_datastructures.h"
|
#include "protocol_datastructures.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
class QMouseEvent;
|
||||||
|
class QEvent;
|
||||||
|
class CardInfoWidget;
|
||||||
|
|
||||||
class MessageLogWidget : public QTextEdit {
|
class MessageLogWidget : public QTextEdit {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
CardInfoWidget *infoWidget;
|
||||||
QString sanitizeHtml(QString dirty) const;
|
QString sanitizeHtml(QString dirty) const;
|
||||||
QString trZoneName(CardZone *zone, Player *player, bool hisOwn, GrammaticalCase gc) 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:
|
public slots:
|
||||||
void logConnecting(QString hostname);
|
void logConnecting(QString hostname);
|
||||||
void logConnected();
|
void logConnected();
|
||||||
|
@ -58,6 +67,12 @@ public slots:
|
||||||
public:
|
public:
|
||||||
void connectToPlayer(Player *player);
|
void connectToPlayer(Player *player);
|
||||||
MessageLogWidget(QWidget *parent = 0);
|
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
|
#endif
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
#include "cardinfowidget.h"
|
#include "cardinfowidget.h"
|
||||||
#include "playerlistwidget.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)
|
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);
|
scene = new GameScene(this);
|
||||||
gameView = new GameView(scene);
|
gameView = new GameView(scene);
|
||||||
|
@ -168,6 +170,9 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
|
||||||
playerListWidget = new PlayerListWidget;
|
playerListWidget = new PlayerListWidget;
|
||||||
playerListWidget->setFocusPolicy(Qt::NoFocus);
|
playerListWidget->setFocusPolicy(Qt::NoFocus);
|
||||||
messageLog = new MessageLogWidget;
|
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;
|
sayLabel = new QLabel;
|
||||||
sayEdit = new QLineEdit;
|
sayEdit = new QLineEdit;
|
||||||
sayLabel->setBuddy(sayEdit);
|
sayLabel->setBuddy(sayEdit);
|
||||||
|
@ -649,6 +654,8 @@ void TabGame::eventPing(Event_Ping *event, GameEventContext * /*context*/)
|
||||||
void TabGame::newCardAdded(AbstractCardItem *card)
|
void TabGame::newCardAdded(AbstractCardItem *card)
|
||||||
{
|
{
|
||||||
connect(card, SIGNAL(hovered(AbstractCardItem *)), cardInfo, SLOT(setCard(AbstractCardItem *)));
|
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
|
CardItem *TabGame::getCard(int playerId, const QString &zoneName, int cardId) const
|
||||||
|
@ -680,3 +687,23 @@ Player *TabGame::getActiveLocalPlayer() const
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ private:
|
||||||
int currentPhase;
|
int currentPhase;
|
||||||
int activePlayer;
|
int activePlayer;
|
||||||
|
|
||||||
|
CardInfoWidget *infoPopup;
|
||||||
CardInfoWidget *cardInfo;
|
CardInfoWidget *cardInfo;
|
||||||
PlayerListWidget *playerListWidget;
|
PlayerListWidget *playerListWidget;
|
||||||
MessageLogWidget *messageLog;
|
MessageLogWidget *messageLog;
|
||||||
|
@ -134,6 +135,8 @@ signals:
|
||||||
void gameClosing(TabGame *tab);
|
void gameClosing(TabGame *tab);
|
||||||
private slots:
|
private slots:
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
|
void showCardInfoPopup(const QPoint &pos, const QString &cardName);
|
||||||
|
void deleteCardInfoPopup();
|
||||||
|
|
||||||
void actConcede();
|
void actConcede();
|
||||||
void actLeaveGame();
|
void actLeaveGame();
|
||||||
|
|
Loading…
Reference in a new issue