debug stuff
This commit is contained in:
parent
e75c8370eb
commit
ca07cce5ed
7 changed files with 95 additions and 31 deletions
|
@ -50,19 +50,17 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
return;
|
return;
|
||||||
currentZone = cursorZone;
|
currentZone = cursorZone;
|
||||||
|
|
||||||
QPointF newPos;
|
QPointF zonePos = currentZone->scenePos();
|
||||||
if (cursorZone->getName() == "table") {
|
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
||||||
TableZone *tableZone = (TableZone *) cursorZone;
|
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
||||||
QPointF cp = cursorZone->scenePos();
|
// QPointF cardCenter = cardTopLeft + QPointF(CARD_WIDTH / 2, CARD_HEIGHT / 2);
|
||||||
QPointF localpos = cursorScenePos - hotSpot - cp;
|
QPointF newPos = zonePos + cursorZone->closestGridPoint(cardTopLeft + QPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2));
|
||||||
|
|
||||||
|
// qDebug(QString("cardTopLeft = %1, %2 cardCenter = %3, %4").arg((cardTopLeft).x()).arg((cardTopLeft).y()).arg(cardCenter.x()).arg(cardCenter.y()).toLatin1());
|
||||||
|
|
||||||
newPos = cp + tableZone->mapFromGrid(tableZone->mapToGrid(localpos));
|
|
||||||
} else
|
|
||||||
newPos = cursorScenePos - hotSpot;
|
|
||||||
if (newPos != pos()) {
|
if (newPos != pos()) {
|
||||||
for (int i = 0; i < childDrags.size(); i++)
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||||
// qDebug(QString("setPos: x=%1, y=%2").arg(newPos.x()).arg(newPos.y()).toLatin1());
|
|
||||||
setPos(newPos);
|
setPos(newPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +78,6 @@ void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
QPointF sp = pos();
|
QPointF sp = pos();
|
||||||
qDebug(QString("sp: x=%1, y=%2").arg(sp.x()).arg(sp.y()).toLatin1());
|
qDebug(QString("sp: x=%1, y=%2").arg(sp.x()).arg(sp.y()).toLatin1());
|
||||||
sc->removeItem(this);
|
sc->removeItem(this);
|
||||||
QList<QGraphicsItem *> colliding = sc->items(event->scenePos());
|
|
||||||
|
|
||||||
if (currentZone) {
|
if (currentZone) {
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(item->parentItem());
|
CardZone *startZone = qgraphicsitem_cast<CardZone *>(item->parentItem());
|
||||||
|
|
|
@ -103,3 +103,8 @@ void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
||||||
for (int i = cards.size() - 1; i >= 0; i--)
|
for (int i = cards.size() - 1; i >= 0; i--)
|
||||||
player->client->moveCard(cards.at(i)->getId(), getName(), targetZone, targetX);
|
player->client->moveCard(cards.at(i)->getId(), getName(), targetZone, targetX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF CardZone::closestGridPoint(const QPointF &point)
|
||||||
|
{
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
void setView(ZoneViewZone *_view);
|
void setView(ZoneViewZone *_view);
|
||||||
virtual void reorganizeCards() = 0;
|
virtual void reorganizeCards() = 0;
|
||||||
void moveAllToZone(const QString &targetZone, int targetX);
|
void moveAllToZone(const QString &targetZone, int targetX);
|
||||||
|
virtual QPointF closestGridPoint(const QPointF &point);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -213,6 +213,8 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
QPushButton *playerAreaBgButton = new QPushButton("...");
|
QPushButton *playerAreaBgButton = new QPushButton("...");
|
||||||
connect(playerAreaBgButton, SIGNAL(clicked()), this, SLOT(playerAreaBgButtonClicked()));
|
connect(playerAreaBgButton, SIGNAL(clicked()), this, SLOT(playerAreaBgButtonClicked()));
|
||||||
|
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
QGridLayout *zoneBgGrid = new QGridLayout;
|
QGridLayout *zoneBgGrid = new QGridLayout;
|
||||||
zoneBgGrid->addWidget(handBgLabel, 0, 0);
|
zoneBgGrid->addWidget(handBgLabel, 0, 0);
|
||||||
zoneBgGrid->addWidget(handBgEdit, 0, 1);
|
zoneBgGrid->addWidget(handBgEdit, 0, 1);
|
||||||
|
@ -226,8 +228,21 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
|
|
||||||
zoneBgGroupBox->setLayout(zoneBgGrid);
|
zoneBgGroupBox->setLayout(zoneBgGrid);
|
||||||
|
|
||||||
|
tableGroupBox = new QGroupBox;
|
||||||
|
settings.beginGroup("table");
|
||||||
|
|
||||||
|
economicGridCheckBox = new QCheckBox;
|
||||||
|
economicGridCheckBox->setChecked(settings.value("economic", 1).toInt());
|
||||||
|
connect(economicGridCheckBox, SIGNAL(stateChanged(int)), this, SLOT(economicGridCheckBoxChanged(int)));
|
||||||
|
|
||||||
|
QGridLayout *tableGrid = new QGridLayout;
|
||||||
|
tableGrid->addWidget(economicGridCheckBox, 0, 0, 1, 2);
|
||||||
|
|
||||||
|
tableGroupBox->setLayout(tableGrid);
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(zoneBgGroupBox);
|
mainLayout->addWidget(zoneBgGroupBox);
|
||||||
|
mainLayout->addWidget(tableGroupBox);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
@ -239,6 +254,9 @@ void AppearanceSettingsPage::retranslateUi()
|
||||||
handBgLabel->setText(tr("Path to hand background:"));
|
handBgLabel->setText(tr("Path to hand background:"));
|
||||||
tableBgLabel->setText(tr("Path to table background:"));
|
tableBgLabel->setText(tr("Path to table background:"));
|
||||||
playerAreaBgLabel->setText(tr("Path to player info background:"));
|
playerAreaBgLabel->setText(tr("Path to player info background:"));
|
||||||
|
|
||||||
|
tableGroupBox->setTitle(tr("Table grid layout"));
|
||||||
|
economicGridCheckBox->setText(tr("Economic layout"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppearanceSettingsPage::handBgButtonClicked()
|
void AppearanceSettingsPage::handBgButtonClicked()
|
||||||
|
@ -280,6 +298,15 @@ void AppearanceSettingsPage::playerAreaBgButtonClicked()
|
||||||
emit playerAreaBgChanged(path);
|
emit playerAreaBgChanged(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppearanceSettingsPage::economicGridCheckBoxChanged(int state)
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup("table");
|
||||||
|
settings.setValue("economic", state);
|
||||||
|
|
||||||
|
emit economicGridChanged(state);
|
||||||
|
}
|
||||||
|
|
||||||
MessagesSettingsPage::MessagesSettingsPage()
|
MessagesSettingsPage::MessagesSettingsPage()
|
||||||
{
|
{
|
||||||
aAdd = new QAction(this);
|
aAdd = new QAction(this);
|
||||||
|
|
|
@ -54,14 +54,17 @@ private slots:
|
||||||
void handBgButtonClicked();
|
void handBgButtonClicked();
|
||||||
void tableBgButtonClicked();
|
void tableBgButtonClicked();
|
||||||
void playerAreaBgButtonClicked();
|
void playerAreaBgButtonClicked();
|
||||||
|
void economicGridCheckBoxChanged(int state);
|
||||||
signals:
|
signals:
|
||||||
void handBgChanged(const QString &path);
|
void handBgChanged(const QString &path);
|
||||||
void tableBgChanged(const QString &path);
|
void tableBgChanged(const QString &path);
|
||||||
void playerAreaBgChanged(const QString &path);
|
void playerAreaBgChanged(const QString &path);
|
||||||
|
void economicGridChanged(int state);
|
||||||
private:
|
private:
|
||||||
QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel;
|
QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel;
|
||||||
QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit;
|
QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit;
|
||||||
QGroupBox *zoneBgGroupBox;
|
QCheckBox *economicGridCheckBox;
|
||||||
|
QGroupBox *zoneBgGroupBox, *tableGroupBox;
|
||||||
public:
|
public:
|
||||||
AppearanceSettingsPage();
|
AppearanceSettingsPage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
|
@ -4,13 +4,20 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "table", true, false, true, parent), width(864), height(536)
|
: CardZone(_p, "table", true, false, true, parent)
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString bgPath = settings.value("zonebg/table").toString();
|
QString bgPath = settings.value("zonebg/table").toString();
|
||||||
if (!bgPath.isEmpty())
|
if (!bgPath.isEmpty())
|
||||||
bgPixmap.load(bgPath);
|
bgPixmap.load(bgPath);
|
||||||
|
|
||||||
|
economicGrid = settings.value("table/economic", 1).toInt();
|
||||||
|
if (economicGrid)
|
||||||
|
height = 14.0 / 3 * CARD_HEIGHT + 3 * paddingY;
|
||||||
|
else
|
||||||
|
height = 4 * CARD_HEIGHT + 3 * paddingY;
|
||||||
|
width = 12 * CARD_WIDTH;
|
||||||
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
@ -87,15 +94,22 @@ CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
||||||
|
|
||||||
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
||||||
{
|
{
|
||||||
if (gridPoint.y() == 3)
|
qDebug(QString("mapFromGrid: %1, %2").arg(gridPoint.x()).arg(gridPoint.y()).toLatin1());
|
||||||
|
if (gridPoint.y() == 3) {
|
||||||
|
if (economicGrid)
|
||||||
return QPointF(
|
return QPointF(
|
||||||
20 + (CARD_WIDTH * gridPoint.x() + CARD_WIDTH * (gridPoint.x() / 3)) / gridPointsPerCardX,
|
20 + (CARD_WIDTH * gridPoint.x() + CARD_WIDTH * (gridPoint.x() / 3)) / 2,
|
||||||
(CARD_HEIGHT + paddingY) * gridPoint.y() / gridPointsPerCardY + (gridPoint.x() % 3 * CARD_HEIGHT) / 3
|
(CARD_HEIGHT + paddingY) * gridPoint.y() + (gridPoint.x() % 3 * CARD_HEIGHT) / 3
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
return QPointF(
|
return QPointF(
|
||||||
20 + CARD_WIDTH * gridPoint.x() / gridPointsPerCardX,
|
20 + 3 * CARD_WIDTH * gridPoint.x() / 2,
|
||||||
(CARD_HEIGHT + paddingY) * gridPoint.y() / gridPointsPerCardY
|
(CARD_HEIGHT + paddingY) * gridPoint.y()
|
||||||
|
);
|
||||||
|
} else
|
||||||
|
return QPointF(
|
||||||
|
20 + CARD_WIDTH * gridPoint.x() / 2,
|
||||||
|
(CARD_HEIGHT + paddingY) * gridPoint.y()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,16 +126,28 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
||||||
else if (y > height - CARD_HEIGHT)
|
else if (y > height - CARD_HEIGHT)
|
||||||
y = height - CARD_HEIGHT;
|
y = height - CARD_HEIGHT;
|
||||||
|
|
||||||
if (y >= (CARD_HEIGHT + paddingY) * 3 - 1)
|
qDebug(QString("mapToGrid: %1, %2").arg(x).arg(y).toLatin1());
|
||||||
|
if (y >= (CARD_HEIGHT + paddingY) * 3 - paddingY / 2) {
|
||||||
|
qDebug("UNTER grenze");
|
||||||
|
if (economicGrid)
|
||||||
return QPoint(
|
return QPoint(
|
||||||
(int) round(((double) x * gridPointsPerCardX) / CARD_WIDTH - x / (2 * CARD_WIDTH)),
|
x * 2 / CARD_WIDTH - (x / (2 * CARD_WIDTH)),
|
||||||
3
|
3
|
||||||
);
|
);
|
||||||
else
|
else {
|
||||||
|
qDebug(QString("mapX = %1").arg((int) round((double) x / (1.25 * CARD_WIDTH))).toLatin1());
|
||||||
return QPoint(
|
return QPoint(
|
||||||
(int) round(((double) x * gridPointsPerCardX) / CARD_WIDTH),
|
x / (1.5 * CARD_WIDTH),
|
||||||
(int) round(((double) y * gridPointsPerCardY) / (CARD_HEIGHT + paddingY))
|
3
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug("UEBER grenze");
|
||||||
|
return QPoint(
|
||||||
|
x * 2 / CARD_WIDTH,
|
||||||
|
y / (CARD_HEIGHT + paddingY)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint TableZone::getFreeGridPoint(int row) const
|
QPoint TableZone::getFreeGridPoint(int row) const
|
||||||
|
@ -136,3 +162,8 @@ QPoint TableZone::getFreeGridPoint(int row) const
|
||||||
++x;
|
++x;
|
||||||
return QPoint(x, y);
|
return QPoint(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF TableZone::closestGridPoint(const QPointF &point)
|
||||||
|
{
|
||||||
|
return mapFromGrid(mapToGrid(point));
|
||||||
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@ class TableZone : public CardZone {
|
||||||
private:
|
private:
|
||||||
int width, height;
|
int width, height;
|
||||||
QPixmap bgPixmap;
|
QPixmap bgPixmap;
|
||||||
|
bool economicGrid;
|
||||||
public:
|
public:
|
||||||
static const int gridPointsPerCardX = 2;
|
|
||||||
static const int gridPointsPerCardY = 1;
|
|
||||||
static const int paddingY = 20;
|
static const int paddingY = 20;
|
||||||
|
|
||||||
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
|
@ -23,6 +22,7 @@ public:
|
||||||
QPointF mapFromGrid(const QPoint &gridPoint) const;
|
QPointF mapFromGrid(const QPoint &gridPoint) const;
|
||||||
QPoint mapToGrid(const QPointF &mapPoint) const;
|
QPoint mapToGrid(const QPointF &mapPoint) const;
|
||||||
QPoint getFreeGridPoint(int row) const;
|
QPoint getFreeGridPoint(int row) const;
|
||||||
|
QPointF closestGridPoint(const QPointF &point);
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue