card info widget fix
This commit is contained in:
parent
10a92c3e85
commit
2543a5b241
5 changed files with 34 additions and 20 deletions
|
@ -184,7 +184,7 @@ 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(false, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
|
infoWidget = new CardInfoWidget(CardInfoWidget::ModePopUp, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
|
||||||
infoWidget->setCard(this);
|
infoWidget->setCard(this);
|
||||||
infoWidget->move(event->screenPos().x() - infoWidget->width() / 2, event->screenPos().y() - infoWidget->height() / 2);
|
infoWidget->move(event->screenPos().x() - infoWidget->width() / 2, event->screenPos().y() - infoWidget->height() / 2);
|
||||||
infoWidget->show();
|
infoWidget->show();
|
||||||
|
|
|
@ -9,12 +9,10 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
|
||||||
CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::WindowFlags flags)
|
CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags)
|
||||||
: QFrame(parent, flags), pixmapHeight(pixmapWidth), minimized(false), minimizeButton(0), info(0)
|
: QFrame(parent, flags), pixmapWidth(160), aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH), minimized(false), mode(_mode), minimizeButton(0), info(0)
|
||||||
{
|
{
|
||||||
pixmapHeight = pixmapWidth * CARD_HEIGHT / CARD_WIDTH;
|
if (mode == ModeGameTab) {
|
||||||
|
|
||||||
if (showMinimizeButton) {
|
|
||||||
minimizeButton = new QPushButton(QIcon(style()->standardIcon(QStyle::SP_ArrowUp)), QString());
|
minimizeButton = new QPushButton(QIcon(style()->standardIcon(QStyle::SP_ArrowUp)), QString());
|
||||||
connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimizeClicked()));
|
connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimizeClicked()));
|
||||||
}
|
}
|
||||||
|
@ -51,7 +49,7 @@ CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::Win
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout(this);
|
QGridLayout *grid = new QGridLayout(this);
|
||||||
int row = 0;
|
int row = 0;
|
||||||
if (showMinimizeButton)
|
if (mode == ModeGameTab)
|
||||||
grid->addWidget(minimizeButton, row++, 1, 1, 1, Qt::AlignRight);
|
grid->addWidget(minimizeButton, row++, 1, 1, 1, Qt::AlignRight);
|
||||||
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
||||||
grid->addWidget(nameLabel1, row, 0);
|
grid->addWidget(nameLabel1, row, 0);
|
||||||
|
@ -71,12 +69,15 @@ CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::Win
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||||
if (showMinimizeButton) {
|
if (mode == ModeGameTab) {
|
||||||
textLabel->setFixedHeight(100);
|
textLabel->setFixedHeight(100);
|
||||||
setFixedWidth(sizeHint().width());
|
setFixedWidth(sizeHint().width());
|
||||||
setMinimized(settingsCache->getCardInfoMinimized());
|
setMinimized(settingsCache->getCardInfoMinimized());
|
||||||
} else
|
} else if (mode == ModePopUp)
|
||||||
setFixedWidth(350);
|
setFixedWidth(350);
|
||||||
|
else
|
||||||
|
setFixedWidth(250);
|
||||||
|
if (mode != ModeDeckEditor)
|
||||||
setFixedHeight(sizeHint().height());
|
setFixedHeight(sizeHint().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,11 +135,11 @@ void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
|
|
||||||
void CardInfoWidget::updatePixmap()
|
void CardInfoWidget::updatePixmap()
|
||||||
{
|
{
|
||||||
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapHeight));
|
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
||||||
if (resizedPixmap)
|
if (resizedPixmap)
|
||||||
cardPicture->setPixmap(*resizedPixmap);
|
cardPicture->setPixmap(*resizedPixmap);
|
||||||
else
|
else
|
||||||
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapHeight))));
|
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::retranslateUi()
|
void CardInfoWidget::retranslateUi()
|
||||||
|
@ -148,3 +149,11 @@ void CardInfoWidget::retranslateUi()
|
||||||
cardtypeLabel1->setText(tr("Card type:"));
|
cardtypeLabel1->setText(tr("Card type:"));
|
||||||
powtoughLabel1->setText(tr("P / T:"));
|
powtoughLabel1->setText(tr("P / T:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
||||||
|
{
|
||||||
|
if (mode == ModeDeckEditor) {
|
||||||
|
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
|
||||||
|
updatePixmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,13 +8,17 @@ class QTextEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class AbstractCardItem;
|
class AbstractCardItem;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
class QResizeEvent;
|
||||||
|
|
||||||
class CardInfoWidget : public QFrame {
|
class CardInfoWidget : public QFrame {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
||||||
private:
|
private:
|
||||||
static const int pixmapWidth = 160;
|
int pixmapWidth;
|
||||||
int pixmapHeight;
|
qreal aspectRatio;
|
||||||
bool minimized;
|
bool minimized;
|
||||||
|
ResizeMode mode;
|
||||||
|
|
||||||
QPushButton *minimizeButton;
|
QPushButton *minimizeButton;
|
||||||
QLabel *cardPicture;
|
QLabel *cardPicture;
|
||||||
|
@ -27,7 +31,7 @@ private:
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
void setMinimized(bool _minimized);
|
void setMinimized(bool _minimized);
|
||||||
public:
|
public:
|
||||||
CardInfoWidget(bool showMinimizeButton = true, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
public slots:
|
public slots:
|
||||||
void setCard(CardInfo *card);
|
void setCard(CardInfo *card);
|
||||||
|
@ -36,6 +40,8 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
void minimizeClicked();
|
void minimizeClicked();
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -164,7 +164,7 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
|
||||||
gameView = new GameView(scene);
|
gameView = new GameView(scene);
|
||||||
gameView->hide();
|
gameView->hide();
|
||||||
|
|
||||||
cardInfo = new CardInfoWidget;
|
cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab);
|
||||||
playerListWidget = new PlayerListWidget;
|
playerListWidget = new PlayerListWidget;
|
||||||
playerListWidget->setFocusPolicy(Qt::NoFocus);
|
playerListWidget->setFocusPolicy(Qt::NoFocus);
|
||||||
messageLog = new MessageLogWidget;
|
messageLog = new MessageLogWidget;
|
||||||
|
|
|
@ -81,8 +81,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||||
leftFrame->addLayout(searchLayout);
|
leftFrame->addLayout(searchLayout);
|
||||||
leftFrame->addWidget(databaseView);
|
leftFrame->addWidget(databaseView);
|
||||||
|
|
||||||
cardInfo = new CardInfoWidget;
|
cardInfo = new CardInfoWidget(CardInfoWidget::ModeDeckEditor);
|
||||||
cardInfo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
cardInfo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||||
|
|
||||||
QToolBar *verticalToolBar = new QToolBar;
|
QToolBar *verticalToolBar = new QToolBar;
|
||||||
verticalToolBar->setOrientation(Qt::Vertical);
|
verticalToolBar->setOrientation(Qt::Vertical);
|
||||||
|
@ -94,9 +94,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||||
verticalToolBarLayout->addStretch();
|
verticalToolBarLayout->addStretch();
|
||||||
|
|
||||||
QVBoxLayout *middleFrame = new QVBoxLayout;
|
QVBoxLayout *middleFrame = new QVBoxLayout;
|
||||||
middleFrame->addWidget(cardInfo);
|
middleFrame->addWidget(cardInfo, 10);
|
||||||
middleFrame->addLayout(verticalToolBarLayout);
|
middleFrame->addLayout(verticalToolBarLayout);
|
||||||
middleFrame->addStretch();
|
|
||||||
|
|
||||||
deckModel = new DeckListModel(this);
|
deckModel = new DeckListModel(this);
|
||||||
deckView = new QTreeView();
|
deckView = new QTreeView();
|
||||||
|
|
Loading…
Reference in a new issue