CardInfoWidget fix

This commit is contained in:
Max-Wilhelm Bruker 2012-02-20 12:53:33 +01:00
parent aa158a4be3
commit 8af0f01db8
3 changed files with 25 additions and 18 deletions

View file

@ -10,9 +10,9 @@
#include "main.h" #include "main.h"
#include "settingscache.h" #include "settingscache.h"
CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags) CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags) : QFrame(parent, flags)
, pixmapWidth(160) , pixmapWidth(0)
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH) , aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache. , minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
, mode(_mode) , mode(_mode)
@ -68,18 +68,18 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
grid->setRowStretch(row, 1); grid->setRowStretch(row, 1);
grid->setColumnStretch(1, 1); grid->setColumnStretch(1, 1);
CardInfo *cardBack = db->getCard();
setCard(cardBack);
retranslateUi(); retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised); setFrameStyle(QFrame::Panel | QFrame::Raised);
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
textLabel->setMinimumHeight(100); textLabel->setMinimumHeight(100);
setFixedWidth(sizeHint().width()); setFixedWidth(sizeHint().width());
} else if (mode == ModePopUp) } else if (mode == ModePopUp) {
setFixedWidth(350); setFixedWidth(350);
else pixmapWidth = 250;
} else
setFixedWidth(250); setFixedWidth(250);
setCard(db->getCard(cardName));
setMinimized(settingsCache->getCardInfoMinimized()); setMinimized(settingsCache->getCardInfoMinimized());
} }
@ -106,8 +106,8 @@ void CardInfoWidget::setMinimized(int _minimized)
// Toggle oracle fields according to selected view. // Toggle oracle fields according to selected view.
bool showAll = ((minimized == 1) || (minimized == 2)); bool showAll = ((minimized == 1) || (minimized == 2));
bool showPowTough = showAll && shouldShowPowTough(); bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
bool showLoyalty = showAll && shouldShowLoyalty(); bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
nameLabel1->setVisible(showAll); nameLabel1->setVisible(showAll);
nameLabel2->setVisible(showAll); nameLabel2->setVisible(showAll);
@ -177,6 +177,9 @@ void CardInfoWidget::clear()
void CardInfoWidget::updatePixmap() void CardInfoWidget::updatePixmap()
{ {
if (pixmapWidth == 0)
return;
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio)); QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
if (resizedPixmap) if (resizedPixmap)
cardPicture->setPixmap(*resizedPixmap); cardPicture->setPixmap(*resizedPixmap);
@ -192,14 +195,19 @@ void CardInfoWidget::retranslateUi()
powtoughLabel1->setText(tr("P / T:")); powtoughLabel1->setText(tr("P / T:"));
loyaltyLabel1->setText(tr("Loyalty:")); loyaltyLabel1->setText(tr("Loyalty:"));
} }
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/) void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{ {
if ((mode == ModeGameTab) && (minimized == 1)) if (mode == ModePopUp)
return; return;
if ((minimized == 1) && (mode == ModeGameTab)) {
pixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio))); pixmapWidth = 0;
updatePixmap(); return;
}
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
if (newPixmapWidth != pixmapWidth) {
pixmapWidth = newPixmapWidth;
updatePixmap();
}
} }
QString CardInfoWidget::getCardName() const QString CardInfoWidget::getCardName() const

View file

@ -43,7 +43,7 @@ private:
void setMinimized(int _minimized); void setMinimized(int _minimized);
public: public:
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0); CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
void retranslateUi(); void retranslateUi();
QString getCardName() const; QString getCardName() const;

View file

@ -2,7 +2,7 @@
#include "cardinfowidget.h" #include "cardinfowidget.h"
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QApplication> #include <QApplication>
#include <QDebug>
Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent) Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
: QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0) : QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0)
{ {
@ -10,9 +10,8 @@ Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName) void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName)
{ {
infoPopup = new CardInfoWidget(CardInfoWidget::ModePopUp, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint); infoPopup = new CardInfoWidget(CardInfoWidget::ModePopUp, cardName, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents); infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
infoPopup->setCard(cardName);
QRect screenRect = qApp->desktop()->screenGeometry(this); QRect screenRect = qApp->desktop()->screenGeometry(this);
infoPopup->move( infoPopup->move(
qMax(screenRect.left(), qMin(pos.x() - infoPopup->width() / 2, screenRect.left() + screenRect.width() - infoPopup->width())), qMax(screenRect.left(), qMin(pos.x() - infoPopup->width() / 2, screenRect.left() + screenRect.width() - infoPopup->width())),