Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
40fbbc59
Commit
40fbbc59
authored
Apr 01, 2012
by
Max-Wilhelm Bruker
Browse files
added size contraints for zone view & scroll bars, fixing issue #34
parent
c835a827
Changes
4
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/zoneviewwidget.cpp
View file @
40fbbc59
...
...
@@ -6,6 +6,7 @@
#include
<QPushButton>
#include
<QPainter>
#include
<QPalette>
#include
<QScrollBar>
#include
"zoneviewwidget.h"
#include
"carditem.h"
#include
"zoneviewzone.h"
...
...
@@ -104,9 +105,26 @@ 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
);
...
...
cockatrice/src/zoneviewwidget.h
View file @
40fbbc59
...
...
@@ -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:
...
...
cockatrice/src/zoneviewzone.cpp
View file @
40fbbc59
#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
);
}
cockatrice/src/zoneviewzone.h
View file @
40fbbc59
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment