From 4f4049fccf3422cf6d895bd25f6cd8aa25b298c4 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Fri, 22 Jul 2011 22:04:13 +0200 Subject: [PATCH] ZoneViewZone fix --- cockatrice/src/gamescene.cpp | 5 +++++ cockatrice/src/gamescene.h | 1 + cockatrice/src/gameview.cpp | 2 +- cockatrice/src/selectzone.cpp | 5 ++--- cockatrice/src/zoneviewwidget.cpp | 13 +++++++------ cockatrice/src/zoneviewzone.cpp | 4 ++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index fefa37cc..5cb1d29b 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -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; diff --git a/cockatrice/src/gamescene.h b/cockatrice/src/gamescene.h index 8389a3b6..2f3b5ca9 100644 --- a/cockatrice/src/gamescene.h +++ b/cockatrice/src/gamescene.h @@ -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); diff --git a/cockatrice/src/gameview.cpp b/cockatrice/src/gameview.cpp index 8a7f89fb..e1d32a0d 100644 --- a/cockatrice/src/gameview.cpp +++ b/cockatrice/src/gameview.cpp @@ -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() diff --git a/cockatrice/src/selectzone.cpp b/cockatrice/src/selectzone.cpp index 8b86cd88..729dfcc4 100644 --- a/cockatrice/src/selectzone.cpp +++ b/cockatrice/src/selectzone.cpp @@ -1,7 +1,7 @@ #include #include "selectzone.h" #include "gamescene.h" - +#include 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(scene())->resizeRubberBand(scenePos() + pos); + static_cast(scene())->resizeRubberBand(deviceTransform(static_cast(scene())->getViewportTransform()).map(pos)); event->accept(); } } diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 812b1439..bdbc8ff7 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -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()) diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 0064d370..172267a5 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -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(); }