game tab: added splitter for manual size control of text boxes

This commit is contained in:
Max-Wilhelm Bruker 2011-04-06 15:49:03 +02:00
parent 0b22f73095
commit 5f46b5cd41
6 changed files with 36 additions and 61 deletions

View file

@ -11,13 +11,8 @@
#include "settingscache.h" #include "settingscache.h"
CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags) 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) : QFrame(parent, flags), pixmapWidth(160), aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH), minimized(false), mode(_mode), info(0)
{ {
if (mode == ModeGameTab) {
minimizeButton = new QPushButton(QIcon(style()->standardIcon(QStyle::SP_ArrowUp)), QString());
connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimizeClicked()));
}
cardPicture = new QLabel; cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter); cardPicture->setAlignment(Qt::AlignCenter);
@ -38,8 +33,6 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
QGridLayout *grid = new QGridLayout(this); QGridLayout *grid = new QGridLayout(this);
int row = 0; int row = 0;
if (mode == ModeGameTab)
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);
grid->addWidget(nameLabel2, row++, 1); grid->addWidget(nameLabel2, row++, 1);
@ -58,43 +51,15 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
retranslateUi(); retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised); setFrameStyle(QFrame::Panel | QFrame::Raised);
setMinimumHeight(350);
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
textLabel->setFixedHeight(100); textLabel->setFixedHeight(100);
setFixedWidth(sizeHint().width()); setFixedWidth(sizeHint().width());
setMinimized(settingsCache->getCardInfoMinimized()); setMaximumHeight(580);
} else if (mode == ModePopUp) } else if (mode == ModePopUp)
setFixedWidth(350); setFixedWidth(350);
else else
setFixedWidth(250); setFixedWidth(250);
if (mode != ModeDeckEditor)
setFixedHeight(sizeHint().height());
}
void CardInfoWidget::minimizeClicked()
{
setMinimized(!minimized);
settingsCache->setCardInfoMinimized(minimized);
}
void CardInfoWidget::setMinimized(bool _minimized)
{
minimized = _minimized;
cardPicture->setVisible(!minimized);
nameLabel2->setVisible(!minimized);
nameLabel1->setVisible(!minimized);
manacostLabel1->setVisible(!minimized);
manacostLabel2->setVisible(!minimized);
cardtypeLabel1->setVisible(!minimized);
cardtypeLabel2->setVisible(!minimized);
powtoughLabel1->setVisible(!minimized);
powtoughLabel2->setVisible(!minimized);
textLabel->setVisible(!minimized);
if (minimizeButton)
minimizeButton->setIcon(style()->standardIcon(minimized ? QStyle::SP_ArrowDown : QStyle::SP_ArrowUp));
setFixedHeight(sizeHint().height());
} }
void CardInfoWidget::setCard(CardInfo *card) void CardInfoWidget::setCard(CardInfo *card)
@ -147,7 +112,7 @@ void CardInfoWidget::retranslateUi()
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/) void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{ {
if (mode == ModeDeckEditor) { if ((mode == ModeDeckEditor) || (mode == ModeGameTab)) {
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio); pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
updatePixmap(); updatePixmap();
} }

View file

@ -21,7 +21,6 @@ private:
bool minimized; bool minimized;
ResizeMode mode; ResizeMode mode;
QPushButton *minimizeButton;
QLabel *cardPicture; QLabel *cardPicture;
QLabel *nameLabel1, *nameLabel2; QLabel *nameLabel1, *nameLabel2;
QLabel *manacostLabel1, *manacostLabel2; QLabel *manacostLabel1, *manacostLabel2;
@ -30,7 +29,6 @@ private:
QTextEdit *textLabel; QTextEdit *textLabel;
CardInfo *info; CardInfo *info;
void setMinimized(bool _minimized);
public: public:
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0); CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
void retranslateUi(); void retranslateUi();
@ -41,7 +39,6 @@ public slots:
private slots: private slots:
void clear(); void clear();
void updatePixmap(); void updatePixmap();
void minimizeClicked();
signals: signals:
void mouseReleased(); void mouseReleased();
protected: protected:

View file

@ -19,7 +19,7 @@ SettingsCache::SettingsCache()
picDownload = settings->value("personal/picturedownload", true).toBool(); picDownload = settings->value("personal/picturedownload", true).toBool();
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool(); doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
cardInfoMinimized = settings->value("interface/cardinfominimized", false).toBool(); tabGameSplitterSizes = settings->value("interface/tabgame_splittersizes").toByteArray();
displayCardNames = settings->value("cards/displaycardnames", true).toBool(); displayCardNames = settings->value("cards/displaycardnames", true).toBool();
horizontalHand = settings->value("hand/horizontal", true).toBool(); horizontalHand = settings->value("hand/horizontal", true).toBool();
invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool(); invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool();
@ -104,10 +104,10 @@ void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay)
settings->setValue("interface/doubleclicktoplay", doubleClickToPlay); settings->setValue("interface/doubleclicktoplay", doubleClickToPlay);
} }
void SettingsCache::setCardInfoMinimized(bool _cardInfoMinimized) void SettingsCache::setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes)
{ {
cardInfoMinimized = _cardInfoMinimized; tabGameSplitterSizes = _tabGameSplitterSizes;
settings->setValue("interface/cardinfominimized", cardInfoMinimized); settings->setValue("interface/tabgame_splittersizes", tabGameSplitterSizes);
} }
void SettingsCache::setDisplayCardNames(int _displayCardNames) void SettingsCache::setDisplayCardNames(int _displayCardNames)

View file

@ -28,7 +28,7 @@ private:
QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath; QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath;
bool picDownload; bool picDownload;
bool doubleClickToPlay; bool doubleClickToPlay;
bool cardInfoMinimized; QByteArray tabGameSplitterSizes;
bool displayCardNames; bool displayCardNames;
bool horizontalHand; bool horizontalHand;
bool invertVerticalCoordinate; bool invertVerticalCoordinate;
@ -47,7 +47,7 @@ public:
QString getCardBackPicturePath() const { return cardBackPicturePath; } QString getCardBackPicturePath() const { return cardBackPicturePath; }
bool getPicDownload() const { return picDownload; } bool getPicDownload() const { return picDownload; }
bool getDoubleClickToPlay() const { return doubleClickToPlay; } bool getDoubleClickToPlay() const { return doubleClickToPlay; }
bool getCardInfoMinimized() const { return cardInfoMinimized; } QByteArray getTabGameSplitterSizes() const { return tabGameSplitterSizes; }
bool getDisplayCardNames() const { return displayCardNames; } bool getDisplayCardNames() const { return displayCardNames; }
bool getHorizontalHand() const { return horizontalHand; } bool getHorizontalHand() const { return horizontalHand; }
bool getInvertVerticalCoordinate() const { return invertVerticalCoordinate; } bool getInvertVerticalCoordinate() const { return invertVerticalCoordinate; }
@ -66,7 +66,7 @@ public slots:
void setCardBackPicturePath(const QString &_cardBackPicturePath); void setCardBackPicturePath(const QString &_cardBackPicturePath);
void setPicDownload(int _picDownload); void setPicDownload(int _picDownload);
void setDoubleClickToPlay(int _doubleClickToPlay); void setDoubleClickToPlay(int _doubleClickToPlay);
void setCardInfoMinimized(bool _cardInfoMinimized); void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes);
void setDisplayCardNames(int _displayCardNames); void setDisplayCardNames(int _displayCardNames);
void setHorizontalHand(int _horizontalHand); void setHorizontalHand(int _horizontalHand);
void setInvertVerticalCoordinate(int _invertVerticalCoordinate); void setInvertVerticalCoordinate(int _invertVerticalCoordinate);

View file

@ -1,5 +1,6 @@
#include <QLabel> #include <QLabel>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QSplitter>
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QMessageBox> #include <QMessageBox>
@ -191,17 +192,23 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
deckViewContainerLayout = new QVBoxLayout; deckViewContainerLayout = new QVBoxLayout;
QVBoxLayout *verticalLayout = new QVBoxLayout; QVBoxLayout *messageLogLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo); messageLogLayout->addWidget(timeElapsedLabel);
verticalLayout->addWidget(playerListWidget, 1); messageLogLayout->addWidget(messageLog);
verticalLayout->addWidget(timeElapsedLabel); messageLogLayout->addLayout(hLayout);
verticalLayout->addWidget(messageLog, 5);
verticalLayout->addLayout(hLayout); QWidget *messageLogLayoutWidget = new QWidget;
messageLogLayoutWidget->setLayout(messageLogLayout);
splitter = new QSplitter(Qt::Vertical);
splitter->addWidget(cardInfo);
splitter->addWidget(playerListWidget);
splitter->addWidget(messageLogLayoutWidget);
mainLayout = new QHBoxLayout; mainLayout = new QHBoxLayout;
mainLayout->addWidget(gameView, 10); mainLayout->addWidget(gameView, 10);
mainLayout->addLayout(deckViewContainerLayout, 10); mainLayout->addLayout(deckViewContainerLayout, 10);
mainLayout->addLayout(verticalLayout); mainLayout->addWidget(splitter);
if (spectator && !spectatorsCanTalk) { if (spectator && !spectatorsCanTalk) {
sayLabel->hide(); sayLabel->hide();
@ -253,12 +260,16 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
retranslateUi(); retranslateUi();
setLayout(mainLayout); setLayout(mainLayout);
splitter->restoreState(settingsCache->getTabGameSplitterSizes());
messageLog->logGameJoined(gameId); messageLog->logGameJoined(gameId);
} }
TabGame::~TabGame() TabGame::~TabGame()
{ {
settingsCache->setTabGameSplitterSizes(splitter->saveState());
QMapIterator<int, Player *> i(players); QMapIterator<int, Player *> i(players);
while (i.hasNext()) while (i.hasNext())
delete i.next().value(); delete i.next().value();
@ -767,12 +778,12 @@ void TabGame::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, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
connect(infoPopup, SIGNAL(mouseReleased()), this, SLOT(deleteCardInfoPopup())); connect(infoPopup, SIGNAL(mouseReleased()), this, SLOT(deleteCardInfoPopup()));
infoPopup->setCard(cardName); infoPopup->setCard(cardName);
QRect screenRect = qApp->desktop()->screenGeometry(this); 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(); infoPopup->show();
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->grabMouse(); infoPopup->grabMouse();
} }

View file

@ -12,6 +12,7 @@ class DeckView;
class GameScene; class GameScene;
class CardInfoWidget; class CardInfoWidget;
class MessageLogWidget; class MessageLogWidget;
class QSplitter;
class QLabel; class QLabel;
class QLineEdit; class QLineEdit;
class QPushButton; class QPushButton;
@ -98,6 +99,7 @@ private:
int currentPhase; int currentPhase;
int activePlayer; int activePlayer;
QSplitter *splitter;
CardInfoWidget *infoPopup; CardInfoWidget *infoPopup;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
PlayerListWidget *playerListWidget; PlayerListWidget *playerListWidget;