ZoneViewZone fix

This commit is contained in:
Max-Wilhelm Bruker 2011-07-22 22:04:13 +02:00
parent 60722e6e47
commit 4f4049fccf
6 changed files with 18 additions and 12 deletions

View file

@ -160,6 +160,11 @@ QTransform GameScene::getViewTransform() const
return views().at(0)->transform();
}
QTransform GameScene::getViewportTransform() const
{
return views().at(0)->viewportTransform();
}
void GameScene::processViewSizeChange(const QSize &newSize)
{
viewSize = newSize;

View file

@ -35,6 +35,7 @@ public:
void retranslateUi();
void processViewSizeChange(const QSize &newSize);
QTransform getViewTransform() const;
QTransform getViewportTransform() const;
void startRubberBand(const QPointF &selectionOrigin);
void resizeRubberBand(const QPointF &cursorPoint);

View file

@ -51,7 +51,7 @@ void GameView::startRubberBand(const QPointF &_selectionOrigin)
void GameView::resizeRubberBand(const QPointF &cursorPoint)
{
if (rubberBand)
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), mapFromScene(cursorPoint)).normalized());
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), cursorPoint.toPoint()).normalized());
}
void GameView::stopRubberBand()

View file

@ -1,7 +1,7 @@
#include <QGraphicsSceneMouseEvent>
#include "selectzone.h"
#include "gamescene.h"
#include <QDebug>
SelectZone::SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView)
: CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView)
{
@ -28,8 +28,7 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
continue;
cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect())));
}
static_cast<GameScene *>(scene())->resizeRubberBand(scenePos() + pos);
static_cast<GameScene *>(scene())->resizeRubberBand(deviceTransform(static_cast<GameScene *>(scene())->getViewportTransform()).map(pos));
event->accept();
}
}

View file

@ -36,7 +36,7 @@ QSizeF TitleLabel::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
if (which == Qt::MaximumSize)
return QSizeF(constraint.width(), fm.size(Qt::TextSingleLine, text).height() + 10);
else
return fm.size(Qt::TextSingleLine, text);
return fm.size(Qt::TextSingleLine, text) + QSizeF(10, 10);
}
void TitleLabel::mousePressEvent(QGraphicsSceneMouseEvent *event)
@ -105,10 +105,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
resize(150, 150);
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, this);
connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents()));
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
vbox->addItem(zone);
zone->initializeCards(cardList);
if (sortByNameCheckBox) {
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
@ -117,8 +114,12 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
sortByTypeCheckBox->setChecked(settingsCache->getZoneViewSortByType());
}
setLayout(vbox);
retranslateUi();
setLayout(vbox);
connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents()));
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
zone->initializeCards(cardList);
}
void ZoneViewWidget::retranslateUi()
@ -140,7 +141,7 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
void ZoneViewWidget::resizeToZoneContents()
{
QRectF zoneRect = zone->getOptimumRect();
QSizeF newSize(zoneRect.width() + 10, zoneRect.height() + extraHeight + 10);
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + 10), zoneRect.height() + extraHeight + 10);
setMaximumSize(newSize);
resize(newSize);
if (layout())

View file

@ -96,11 +96,11 @@ void ZoneViewZone::reorganizeCards()
CardItem *c = cardsToDisplay.at(i);
qreal x = (i / rows) * CARD_WIDTH;
qreal y = (i % rows) * CARD_HEIGHT / 3;
c->setPos(x, y);
c->setPos(x + 5, y + 5);
c->setRealZValue(i);
}
optimumRect = QRectF(0, 0, cols * CARD_WIDTH, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT);
optimumRect = QRectF(0, 0, qMax(cols, 3) * CARD_WIDTH + 10, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT + 10);
updateGeometry();
emit optimumRectChanged();
}