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 <QPushButton>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
#include <QScrollBar>
|
||||||
#include "zoneviewwidget.h"
|
#include "zoneviewwidget.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
|
@ -105,8 +106,25 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
|
||||||
extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
|
extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
|
||||||
resize(150, 150);
|
resize(150, 150);
|
||||||
|
|
||||||
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, this);
|
QGraphicsLinearLayout *zoneHBox = new QGraphicsLinearLayout(Qt::Horizontal);
|
||||||
vbox->addItem(zone);
|
|
||||||
|
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) {
|
if (sortByNameCheckBox) {
|
||||||
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
|
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
|
||||||
|
@ -148,13 +166,31 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
|
||||||
void ZoneViewWidget::resizeToZoneContents()
|
void ZoneViewWidget::resizeToZoneContents()
|
||||||
{
|
{
|
||||||
QRectF zoneRect = zone->getOptimumRect();
|
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);
|
setMaximumSize(newSize);
|
||||||
resize(newSize);
|
resize(newSize);
|
||||||
|
|
||||||
|
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
|
||||||
|
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
|
||||||
|
|
||||||
if (layout())
|
if (layout())
|
||||||
layout()->invalidate();
|
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)
|
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
|
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
|
||||||
|
|
|
@ -14,6 +14,7 @@ class QCheckBox;
|
||||||
class GameScene;
|
class GameScene;
|
||||||
class ServerInfo_Card;
|
class ServerInfo_Card;
|
||||||
class QGraphicsSceneMouseEvent;
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QGraphicsSceneWheelEvent;
|
||||||
|
|
||||||
class TitleLabel : public QGraphicsWidget {
|
class TitleLabel : public QGraphicsWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -36,6 +37,7 @@ class ZoneViewWidget : public QGraphicsWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
ZoneViewZone *zone;
|
ZoneViewZone *zone;
|
||||||
|
QGraphicsWidget *zoneContainer;
|
||||||
|
|
||||||
TitleLabel *titleLabel;
|
TitleLabel *titleLabel;
|
||||||
QPushButton *closeButton;
|
QPushButton *closeButton;
|
||||||
|
@ -48,6 +50,8 @@ signals:
|
||||||
void closePressed(ZoneViewWidget *zv);
|
void closePressed(ZoneViewWidget *zv);
|
||||||
private slots:
|
private slots:
|
||||||
void resizeToZoneContents();
|
void resizeToZoneContents();
|
||||||
|
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
|
||||||
|
void handleScrollBarChange(int value);
|
||||||
void zoneDeleted();
|
void zoneDeleted();
|
||||||
void moveWidget(QPointF scenePos);
|
void moveWidget(QPointF scenePos);
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QGraphicsSceneWheelEvent>
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "carddragitem.h"
|
#include "carddragitem.h"
|
||||||
|
@ -82,6 +83,8 @@ void ZoneViewZone::reorganizeCards()
|
||||||
cards[i]->setId(i);
|
cards[i]->setId(i);
|
||||||
|
|
||||||
int cols = floor(sqrt((double) cardCount / 2));
|
int cols = floor(sqrt((double) cardCount / 2));
|
||||||
|
if (cols > 7)
|
||||||
|
cols = 7;
|
||||||
int rows = ceil((double) cardCount / cols);
|
int rows = ceil((double) cardCount / cols);
|
||||||
if (rows < 1)
|
if (rows < 1)
|
||||||
rows = 1;
|
rows = 1;
|
||||||
|
@ -180,3 +183,8 @@ void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
|
||||||
writeableRevealZone = _writeableRevealZone;
|
writeableRevealZone = _writeableRevealZone;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZoneViewZone::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||||
|
{
|
||||||
|
emit wheelEventReceived(event);
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
class ZoneViewWidget;
|
class ZoneViewWidget;
|
||||||
class Response;
|
class Response;
|
||||||
class ServerInfo_Card;
|
class ServerInfo_Card;
|
||||||
|
class QGraphicsSceneWheelEvent;
|
||||||
|
|
||||||
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
|
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -39,9 +40,11 @@ private slots:
|
||||||
signals:
|
signals:
|
||||||
void beingDeleted();
|
void beingDeleted();
|
||||||
void optimumRectChanged();
|
void optimumRectChanged();
|
||||||
|
void wheelEventReceived(QGraphicsSceneWheelEvent *event);
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
||||||
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue