From 7c06d6d84ffe3bf5bd1867e8bfd0f93ef2acb49d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 1 Sep 2009 17:22:47 +0200 Subject: [PATCH] zone background textures --- cockatrice/src/dlg_settings.cpp | 81 +++++++++++++++++++++++++++++++++ cockatrice/src/dlg_settings.h | 12 +++++ cockatrice/src/handzone.cpp | 10 +++- cockatrice/src/handzone.h | 1 + cockatrice/src/playerarea.cpp | 10 +++- cockatrice/src/playerarea.h | 1 + cockatrice/src/tablezone.cpp | 11 ++++- cockatrice/src/tablezone.h | 1 + 8 files changed, 124 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 219452e0..024166ff 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -191,12 +191,93 @@ void GeneralSettingsPage::retranslateUi() AppearanceSettingsPage::AppearanceSettingsPage() { + zoneBgGroupBox = new QGroupBox; + QSettings settings; + settings.beginGroup("zonebg"); + + handBgLabel = new QLabel; + handBgEdit = new QLineEdit(settings.value("hand").toString()); + handBgEdit->setReadOnly(true); + QPushButton *handBgButton = new QPushButton("..."); + connect(handBgButton, SIGNAL(clicked()), this, SLOT(handBgButtonClicked())); + + tableBgLabel = new QLabel; + tableBgEdit = new QLineEdit(settings.value("table").toString()); + tableBgEdit->setReadOnly(true); + QPushButton *tableBgButton = new QPushButton("..."); + connect(tableBgButton, SIGNAL(clicked()), this, SLOT(tableBgButtonClicked())); + + playerAreaBgLabel = new QLabel; + playerAreaBgEdit = new QLineEdit(settings.value("carddatabase").toString()); + playerAreaBgEdit->setReadOnly(true); + QPushButton *playerAreaBgButton = new QPushButton("..."); + connect(playerAreaBgButton, SIGNAL(clicked()), this, SLOT(playerAreaBgButtonClicked())); + + QGridLayout *zoneBgGrid = new QGridLayout; + zoneBgGrid->addWidget(handBgLabel, 0, 0); + zoneBgGrid->addWidget(handBgEdit, 0, 1); + zoneBgGrid->addWidget(handBgButton, 0, 2); + zoneBgGrid->addWidget(tableBgLabel, 1, 0); + zoneBgGrid->addWidget(tableBgEdit, 1, 1); + zoneBgGrid->addWidget(tableBgButton, 1, 2); + zoneBgGrid->addWidget(playerAreaBgLabel, 2, 0); + zoneBgGrid->addWidget(playerAreaBgEdit, 2, 1); + zoneBgGrid->addWidget(playerAreaBgButton, 2, 2); + + zoneBgGroupBox->setLayout(zoneBgGrid); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(zoneBgGroupBox); + + setLayout(mainLayout); } void AppearanceSettingsPage::retranslateUi() { + zoneBgGroupBox->setTitle(tr("Zone background pictures")); + handBgLabel->setText(tr("Path to hand background:")); + tableBgLabel->setText(tr("Path to table background:")); + playerAreaBgLabel->setText(tr("Path to player info background:")); +} +void AppearanceSettingsPage::handBgButtonClicked() +{ + QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); + if (path.isEmpty()) + return; + QSettings settings; + settings.beginGroup("zonebg"); + settings.setValue("hand", path); + handBgEdit->setText(path); + + emit handBgChanged(path); +} + +void AppearanceSettingsPage::tableBgButtonClicked() +{ + QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); + if (path.isEmpty()) + return; + QSettings settings; + settings.beginGroup("zonebg"); + settings.setValue("table", path); + tableBgEdit->setText(path); + + emit tableBgChanged(path); +} + +void AppearanceSettingsPage::playerAreaBgButtonClicked() +{ + QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); + if (path.isEmpty()) + return; + QSettings settings; + settings.beginGroup("zonebg"); + settings.setValue("playerarea", path); + playerAreaBgEdit->setText(path); + + emit playerAreaBgChanged(path); } MessagesSettingsPage::MessagesSettingsPage() diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 684aee09..9e69980e 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -50,6 +50,18 @@ private: class AppearanceSettingsPage : public AbstractSettingsPage { Q_OBJECT +private slots: + void handBgButtonClicked(); + void tableBgButtonClicked(); + void playerAreaBgButtonClicked(); +signals: + void handBgChanged(const QString &path); + void tableBgChanged(const QString &path); + void playerAreaBgChanged(const QString &path); +private: + QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel; + QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit; + QGroupBox *zoneBgGroupBox; public: AppearanceSettingsPage(); void retranslateUi(); diff --git a/cockatrice/src/handzone.cpp b/cockatrice/src/handzone.cpp index 012550a8..18885c39 100644 --- a/cockatrice/src/handzone.cpp +++ b/cockatrice/src/handzone.cpp @@ -6,6 +6,11 @@ HandZone::HandZone(Player *_p, QGraphicsItem *parent) : CardZone(_p, "hand", false, false, _p->getLocal(), parent) { + QSettings settings; + QString bgPath = settings.value("zonebg/hand").toString(); + if (!bgPath.isEmpty()) + bgPixmap.load(bgPath); + setCacheMode(DeviceCoordinateCache); setAcceptsHoverEvents(true); // Awkwardly, this is needed to repaint the cached item after it has been corrupted by buggy rubberband drag. } @@ -17,7 +22,10 @@ QRectF HandZone::boundingRect() const void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - painter->fillRect(boundingRect(), Qt::darkGreen); + if (bgPixmap.isNull()) + painter->fillRect(boundingRect(), Qt::darkGreen); + else + painter->fillRect(boundingRect(), QBrush(bgPixmap)); } void HandZone::reorganizeCards() diff --git a/cockatrice/src/handzone.h b/cockatrice/src/handzone.h index dabad0bd..38057ea4 100644 --- a/cockatrice/src/handzone.h +++ b/cockatrice/src/handzone.h @@ -5,6 +5,7 @@ class HandZone : public CardZone { private: + QPixmap bgPixmap; public: HandZone(Player *_p, QGraphicsItem *parent = 0); QRectF boundingRect() const; diff --git a/cockatrice/src/playerarea.cpp b/cockatrice/src/playerarea.cpp index 66297148..df2b43eb 100644 --- a/cockatrice/src/playerarea.cpp +++ b/cockatrice/src/playerarea.cpp @@ -5,10 +5,15 @@ #include "pilezone.h" #include "counter.h" #include +#include PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent) : QGraphicsItem(parent), player(_player) { + QSettings settings; + QString bgPath = settings.value("zonebg/playerarea").toString(); + if (!bgPath.isEmpty()) + bgPixmap.load(bgPath); setCacheMode(DeviceCoordinateCache); QPointF base = QPointF(55, 50); @@ -51,7 +56,10 @@ QRectF PlayerArea::boundingRect() const void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - painter->fillRect(boundingRect(), QColor(200, 200, 200)); + if (bgPixmap.isNull()) + painter->fillRect(boundingRect(), QColor(200, 200, 200)); + else + painter->fillRect(boundingRect(), QBrush(bgPixmap)); QString nameStr = player->getName(); QFont font("Times"); diff --git a/cockatrice/src/playerarea.h b/cockatrice/src/playerarea.h index cf2e4d81..efd98b3b 100644 --- a/cockatrice/src/playerarea.h +++ b/cockatrice/src/playerarea.h @@ -9,6 +9,7 @@ class Counter; class PlayerArea : public QGraphicsItem { private: + QPixmap bgPixmap; QRectF bRect; Player *player; QList counterList; diff --git a/cockatrice/src/tablezone.cpp b/cockatrice/src/tablezone.cpp index 28b83808..c3894ea3 100644 --- a/cockatrice/src/tablezone.cpp +++ b/cockatrice/src/tablezone.cpp @@ -48,6 +48,12 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent) << QPoint(19, 0) << QPoint(1, 0) << QPoint(22, 0)); + QSettings settings; + QString bgPath = settings.value("zonebg/table").toString(); + if (!bgPath.isEmpty()) + bgPixmap.load(bgPath); + + setCacheMode(DeviceCoordinateCache); } QRectF TableZone::boundingRect() const @@ -57,7 +63,10 @@ QRectF TableZone::boundingRect() const void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - painter->fillRect(boundingRect(), QColor(0, 0, 100)); + if (bgPixmap.isNull()) + painter->fillRect(boundingRect(), QColor(0, 0, 100)); + else + painter->fillRect(boundingRect(), QBrush(bgPixmap)); } void TableZone::addCardImpl(CardItem *card, int _x, int _y) diff --git a/cockatrice/src/tablezone.h b/cockatrice/src/tablezone.h index 36b4b824..ec06a645 100644 --- a/cockatrice/src/tablezone.h +++ b/cockatrice/src/tablezone.h @@ -7,6 +7,7 @@ class TableZone : public CardZone { private: int width, height; QList > gridPoints; + QPixmap bgPixmap; public: static const int gridPointsPerCardX = 2; static const int gridPointsPerCardY = 3;