added size contraints for zone view & scroll bars, fixing issue #34
This commit is contained in:
parent
c835a827b0
commit
40fbbc5982
4 changed files with 55 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <QScrollBar>
|
||||
#include "zoneviewwidget.h"
|
||||
#include "carditem.h"
|
||||
#include "zoneviewzone.h"
|
||||
|
@ -105,8 +106,25 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
|
|||
extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
|
||||
resize(150, 150);
|
||||
|
||||
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, this);
|
||||
vbox->addItem(zone);
|
||||
QGraphicsLinearLayout *zoneHBox = new QGraphicsLinearLayout(Qt::Horizontal);
|
||||
|
||||
zoneContainer = new QGraphicsWidget(this);
|
||||
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
zoneContainer->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
|
||||
zoneHBox->addItem(zoneContainer);
|
||||
|
||||
scrollBar = new QScrollBar(Qt::Vertical);
|
||||
scrollBar->setMinimum(0);
|
||||
scrollBar->setSingleStep(50);
|
||||
connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(handleScrollBarChange(int)));
|
||||
QGraphicsProxyWidget *scrollBarProxy = new QGraphicsProxyWidget;
|
||||
scrollBarProxy->setWidget(scrollBar);
|
||||
zoneHBox->addItem(scrollBarProxy);
|
||||
|
||||
vbox->addItem(zoneHBox);
|
||||
|
||||
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer);
|
||||
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), this, SLOT(handleWheelEvent(QGraphicsSceneWheelEvent *)));
|
||||
|
||||
if (sortByNameCheckBox) {
|
||||
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
|
||||
|
@ -148,13 +166,31 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
|
|||
void ZoneViewWidget::resizeToZoneContents()
|
||||
{
|
||||
QRectF zoneRect = zone->getOptimumRect();
|
||||
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + 10), zoneRect.height() + extraHeight + 10);
|
||||
qreal totalZoneHeight = zoneRect.height();
|
||||
if (zoneRect.height() > 500)
|
||||
zoneRect.setHeight(500);
|
||||
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + scrollBar->width() + 10), zoneRect.height() + extraHeight + 10);
|
||||
setMaximumSize(newSize);
|
||||
resize(newSize);
|
||||
|
||||
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
|
||||
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
|
||||
|
||||
if (layout())
|
||||
layout()->invalidate();
|
||||
}
|
||||
|
||||
void ZoneViewWidget::handleWheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
QWheelEvent wheelEvent(QPoint(), event->delta(), event->buttons(), event->modifiers(), event->orientation());
|
||||
scrollBar->event(&wheelEvent);
|
||||
}
|
||||
|
||||
void ZoneViewWidget::handleScrollBarChange(int value)
|
||||
{
|
||||
zone->setY(-value);
|
||||
}
|
||||
|
||||
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
|
||||
|
|
|
@ -14,6 +14,7 @@ class QCheckBox;
|
|||
class GameScene;
|
||||
class ServerInfo_Card;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QGraphicsSceneWheelEvent;
|
||||
|
||||
class TitleLabel : public QGraphicsWidget {
|
||||
Q_OBJECT
|
||||
|
@ -36,6 +37,7 @@ class ZoneViewWidget : public QGraphicsWidget {
|
|||
Q_OBJECT
|
||||
private:
|
||||
ZoneViewZone *zone;
|
||||
QGraphicsWidget *zoneContainer;
|
||||
|
||||
TitleLabel *titleLabel;
|
||||
QPushButton *closeButton;
|
||||
|
@ -48,6 +50,8 @@ signals:
|
|||
void closePressed(ZoneViewWidget *zv);
|
||||
private slots:
|
||||
void resizeToZoneContents();
|
||||
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
void handleScrollBarChange(int value);
|
||||
void zoneDeleted();
|
||||
void moveWidget(QPointF scenePos);
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <math.h>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include "zoneviewzone.h"
|
||||
#include "player.h"
|
||||
#include "carddragitem.h"
|
||||
|
@ -82,6 +83,8 @@ void ZoneViewZone::reorganizeCards()
|
|||
cards[i]->setId(i);
|
||||
|
||||
int cols = floor(sqrt((double) cardCount / 2));
|
||||
if (cols > 7)
|
||||
cols = 7;
|
||||
int rows = ceil((double) cardCount / cols);
|
||||
if (rows < 1)
|
||||
rows = 1;
|
||||
|
@ -180,3 +183,8 @@ void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
|
|||
writeableRevealZone = _writeableRevealZone;
|
||||
|
||||
}
|
||||
|
||||
void ZoneViewZone::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
emit wheelEventReceived(event);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
class ZoneViewWidget;
|
||||
class Response;
|
||||
class ServerInfo_Card;
|
||||
class QGraphicsSceneWheelEvent;
|
||||
|
||||
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
|
||||
Q_OBJECT
|
||||
|
@ -39,9 +40,11 @@ private slots:
|
|||
signals:
|
||||
void beingDeleted();
|
||||
void optimumRectChanged();
|
||||
void wheelEventReceived(QGraphicsSceneWheelEvent *event);
|
||||
protected:
|
||||
void addCardImpl(CardItem *card, int x, int y);
|
||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue