card info widget fix

This commit is contained in:
Max-Wilhelm Bruker 2010-10-14 16:49:18 +02:00
parent 10a92c3e85
commit 2543a5b241
5 changed files with 34 additions and 20 deletions

View file

@ -184,7 +184,7 @@ 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 = 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();

View file

@ -9,12 +9,10 @@
#include "main.h"
#include "settingscache.h"
CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags), pixmapHeight(pixmapWidth), minimized(false), minimizeButton(0), info(0)
CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags)
: 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 (showMinimizeButton) {
if (mode == ModeGameTab) {
minimizeButton = new QPushButton(QIcon(style()->standardIcon(QStyle::SP_ArrowUp)), QString());
connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimizeClicked()));
}
@ -51,7 +49,7 @@ CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::Win
QGridLayout *grid = new QGridLayout(this);
int row = 0;
if (showMinimizeButton)
if (mode == ModeGameTab)
grid->addWidget(minimizeButton, row++, 1, 1, 1, Qt::AlignRight);
grid->addWidget(cardPicture, row++, 0, 1, 2);
grid->addWidget(nameLabel1, row, 0);
@ -71,13 +69,16 @@ CardInfoWidget::CardInfoWidget(bool showMinimizeButton, QWidget *parent, Qt::Win
retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised);
if (showMinimizeButton) {
if (mode == ModeGameTab) {
textLabel->setFixedHeight(100);
setFixedWidth(sizeHint().width());
setMinimized(settingsCache->getCardInfoMinimized());
} else
} else if (mode == ModePopUp)
setFixedWidth(350);
setFixedHeight(sizeHint().height());
else
setFixedWidth(250);
if (mode != ModeDeckEditor)
setFixedHeight(sizeHint().height());
}
void CardInfoWidget::minimizeClicked()
@ -134,11 +135,11 @@ void CardInfoWidget::setCard(AbstractCardItem *card)
void CardInfoWidget::updatePixmap()
{
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapHeight));
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
if (resizedPixmap)
cardPicture->setPixmap(*resizedPixmap);
else
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapHeight))));
cardPicture->setPixmap(*(db->getCard()->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio))));
}
void CardInfoWidget::retranslateUi()
@ -148,3 +149,11 @@ void CardInfoWidget::retranslateUi()
cardtypeLabel1->setText(tr("Card type:"));
powtoughLabel1->setText(tr("P / T:"));
}
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{
if (mode == ModeDeckEditor) {
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
updatePixmap();
}
}

View file

@ -8,13 +8,17 @@ class QTextEdit;
class QPushButton;
class AbstractCardItem;
class CardInfo;
class QResizeEvent;
class CardInfoWidget : public QFrame {
Q_OBJECT
public:
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
private:
static const int pixmapWidth = 160;
int pixmapHeight;
int pixmapWidth;
qreal aspectRatio;
bool minimized;
ResizeMode mode;
QPushButton *minimizeButton;
QLabel *cardPicture;
@ -27,7 +31,7 @@ private:
CardInfo *info;
void setMinimized(bool _minimized);
public:
CardInfoWidget(bool showMinimizeButton = true, QWidget *parent = 0, Qt::WindowFlags f = 0);
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
void retranslateUi();
public slots:
void setCard(CardInfo *card);
@ -36,6 +40,8 @@ public slots:
private slots:
void updatePixmap();
void minimizeClicked();
protected:
void resizeEvent(QResizeEvent *event);
};
#endif

View file

@ -164,7 +164,7 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
gameView = new GameView(scene);
gameView->hide();
cardInfo = new CardInfoWidget;
cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab);
playerListWidget = new PlayerListWidget;
playerListWidget->setFocusPolicy(Qt::NoFocus);
messageLog = new MessageLogWidget;

View file

@ -81,8 +81,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
leftFrame->addLayout(searchLayout);
leftFrame->addWidget(databaseView);
cardInfo = new CardInfoWidget;
cardInfo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
cardInfo = new CardInfoWidget(CardInfoWidget::ModeDeckEditor);
cardInfo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
QToolBar *verticalToolBar = new QToolBar;
verticalToolBar->setOrientation(Qt::Vertical);
@ -94,9 +94,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
verticalToolBarLayout->addStretch();
QVBoxLayout *middleFrame = new QVBoxLayout;
middleFrame->addWidget(cardInfo);
middleFrame->addWidget(cardInfo, 10);
middleFrame->addLayout(verticalToolBarLayout);
middleFrame->addStretch();
deckModel = new DeckListModel(this);
deckView = new QTreeView();