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