CardInfoWidget improvement by Absinthe and Hellkeepa
This commit is contained in:
parent
a03bf8884f
commit
9cfe4bea59
4 changed files with 82 additions and 6 deletions
|
@ -11,8 +11,24 @@
|
|||
#include "settingscache.h"
|
||||
|
||||
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), info(0)
|
||||
: QFrame(parent, flags)
|
||||
, pixmapWidth(160)
|
||||
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
|
||||
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
|
||||
, mode(_mode)
|
||||
, info(0)
|
||||
{
|
||||
if (mode == ModeGameTab) {
|
||||
// Create indexed list of status views for card.
|
||||
const QStringList cardInfoStatus = QStringList() << tr("Hide card info") << tr("Show card only") << tr("Show text only") << tr("Show full info");
|
||||
|
||||
// Create droplist for cardinfo view selection, and set right current index.
|
||||
dropList = new QComboBox();
|
||||
dropList->addItems(cardInfoStatus);
|
||||
dropList->setCurrentIndex(minimized);
|
||||
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
|
||||
}
|
||||
|
||||
cardPicture = new QLabel;
|
||||
cardPicture->setAlignment(Qt::AlignCenter);
|
||||
|
||||
|
@ -33,6 +49,8 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
|
|||
|
||||
QGridLayout *grid = new QGridLayout(this);
|
||||
int row = 0;
|
||||
if (mode == ModeGameTab)
|
||||
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
|
||||
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
||||
grid->addWidget(nameLabel1, row, 0);
|
||||
grid->addWidget(nameLabel2, row++, 1);
|
||||
|
@ -51,15 +69,51 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
|
|||
|
||||
retranslateUi();
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
setMinimumHeight(350);
|
||||
if (mode == ModeGameTab) {
|
||||
textLabel->setFixedHeight(100);
|
||||
setFixedWidth(sizeHint().width());
|
||||
setMaximumHeight(580);
|
||||
setMinimized(settingsCache->getCardInfoMinimized());
|
||||
} else if (mode == ModePopUp)
|
||||
setFixedWidth(350);
|
||||
else
|
||||
setFixedWidth(250);
|
||||
if (mode != ModeDeckEditor)
|
||||
setFixedHeight(sizeHint().height());
|
||||
}
|
||||
|
||||
void CardInfoWidget::minimizeClicked(int newMinimized)
|
||||
{
|
||||
// Set new status, and store it in the settings cache.
|
||||
setMinimized(newMinimized);
|
||||
settingsCache->setCardInfoMinimized(newMinimized);
|
||||
}
|
||||
|
||||
void CardInfoWidget::setMinimized(int _minimized)
|
||||
{
|
||||
minimized = _minimized;
|
||||
|
||||
// Set the picture to be shown only at "card only" (1) and "full info" (3)
|
||||
if (minimized == 1 || minimized == 3) {
|
||||
cardPicture->setVisible(true);
|
||||
} else {
|
||||
cardPicture->setVisible(false);
|
||||
}
|
||||
|
||||
// Set the rest of the fields to be shown only at "full info" (3) and "oracle only" (2)
|
||||
bool showAll = (minimized == 2 || minimized == 3) ? true : false;
|
||||
|
||||
// Toggle oracle fields as according to selected view.
|
||||
nameLabel2->setVisible(showAll);
|
||||
nameLabel1->setVisible(showAll);
|
||||
manacostLabel1->setVisible(showAll);
|
||||
manacostLabel2->setVisible(showAll);
|
||||
cardtypeLabel1->setVisible(showAll);
|
||||
cardtypeLabel2->setVisible(showAll);
|
||||
powtoughLabel1->setVisible(showAll);
|
||||
powtoughLabel2->setVisible(showAll);
|
||||
textLabel->setVisible(showAll);
|
||||
|
||||
setFixedHeight(sizeHint().height());
|
||||
}
|
||||
|
||||
void CardInfoWidget::setCard(CardInfo *card)
|
||||
|
@ -112,7 +166,7 @@ void CardInfoWidget::retranslateUi()
|
|||
|
||||
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
||||
{
|
||||
if ((mode == ModeDeckEditor) || (mode == ModeGameTab)) {
|
||||
if (mode == ModeDeckEditor) {
|
||||
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
|
||||
updatePixmap();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define CARDINFOWIDGET_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QStringList>
|
||||
#include <QComboBox>
|
||||
|
||||
class QLabel;
|
||||
class QTextEdit;
|
||||
|
@ -13,34 +15,44 @@ class QMouseEvent;
|
|||
|
||||
class CardInfoWidget : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
||||
|
||||
private:
|
||||
int pixmapWidth;
|
||||
qreal aspectRatio;
|
||||
bool minimized;
|
||||
int minimized; // 0 - minimized, 1 - card, 2 - oracle only, 3 - full
|
||||
ResizeMode mode;
|
||||
|
||||
QComboBox *dropList;
|
||||
QLabel *cardPicture;
|
||||
QLabel *nameLabel1, *nameLabel2;
|
||||
QLabel *manacostLabel1, *manacostLabel2;
|
||||
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
||||
QLabel *powtoughLabel1, *powtoughLabel2;
|
||||
QTextEdit *textLabel;
|
||||
|
||||
|
||||
CardInfo *info;
|
||||
void setMinimized(int _minimized);
|
||||
|
||||
public:
|
||||
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void retranslateUi();
|
||||
|
||||
public slots:
|
||||
void setCard(CardInfo *card);
|
||||
void setCard(const QString &cardName);
|
||||
void setCard(AbstractCardItem *card);
|
||||
|
||||
private slots:
|
||||
void clear();
|
||||
void updatePixmap();
|
||||
void minimizeClicked(int newMinimized);
|
||||
|
||||
signals:
|
||||
void mouseReleased();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
|
|
@ -19,6 +19,7 @@ SettingsCache::SettingsCache()
|
|||
|
||||
picDownload = settings->value("personal/picturedownload", true).toBool();
|
||||
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
|
||||
cardInfoMinimized = settings->value("interface/cardinfominimized", 0).toInt();
|
||||
tabGameSplitterSizes = settings->value("interface/tabgame_splittersizes").toByteArray();
|
||||
displayCardNames = settings->value("cards/displaycardnames", true).toBool();
|
||||
horizontalHand = settings->value("hand/horizontal", true).toBool();
|
||||
|
@ -107,6 +108,12 @@ void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay)
|
|||
settings->setValue("interface/doubleclicktoplay", doubleClickToPlay);
|
||||
}
|
||||
|
||||
void SettingsCache::setCardInfoMinimized(int _cardInfoMinimized)
|
||||
{
|
||||
cardInfoMinimized = _cardInfoMinimized;
|
||||
settings->setValue("interface/cardinfominimized", cardInfoMinimized);
|
||||
}
|
||||
|
||||
void SettingsCache::setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes)
|
||||
{
|
||||
tabGameSplitterSizes = _tabGameSplitterSizes;
|
||||
|
|
|
@ -29,6 +29,7 @@ private:
|
|||
QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath;
|
||||
bool picDownload;
|
||||
bool doubleClickToPlay;
|
||||
int cardInfoMinimized;
|
||||
QByteArray tabGameSplitterSizes;
|
||||
bool displayCardNames;
|
||||
bool horizontalHand;
|
||||
|
@ -50,6 +51,7 @@ public:
|
|||
QString getCardBackPicturePath() const { return cardBackPicturePath; }
|
||||
bool getPicDownload() const { return picDownload; }
|
||||
bool getDoubleClickToPlay() const { return doubleClickToPlay; }
|
||||
int getCardInfoMinimized() const { return cardInfoMinimized; }
|
||||
QByteArray getTabGameSplitterSizes() const { return tabGameSplitterSizes; }
|
||||
bool getDisplayCardNames() const { return displayCardNames; }
|
||||
bool getHorizontalHand() const { return horizontalHand; }
|
||||
|
@ -71,6 +73,7 @@ public slots:
|
|||
void setCardBackPicturePath(const QString &_cardBackPicturePath);
|
||||
void setPicDownload(int _picDownload);
|
||||
void setDoubleClickToPlay(int _doubleClickToPlay);
|
||||
void setCardInfoMinimized(int _cardInfoMinimized);
|
||||
void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes);
|
||||
void setDisplayCardNames(int _displayCardNames);
|
||||
void setHorizontalHand(int _horizontalHand);
|
||||
|
|
Loading…
Reference in a new issue