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
4c9555bb
Commit
4c9555bb
authored
Sep 12, 2015
by
Zach
Browse files
Merge pull request #1496 from ctrlaltca/clamp_zoneview
Clamp zone view widget's titlebar inside the viewable area
parents
29446d80
a7616835
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/zoneviewwidget.cpp
View file @
4c9555bb
...
@@ -20,44 +20,6 @@
...
@@ -20,44 +20,6 @@
#include
"pb/command_stop_dump_zone.pb.h"
#include
"pb/command_stop_dump_zone.pb.h"
#include
"pb/command_shuffle.pb.h"
#include
"pb/command_shuffle.pb.h"
TitleLabel
::
TitleLabel
()
:
QGraphicsWidget
(),
text
(
" "
)
{
setAcceptHoverEvents
(
true
);
}
void
TitleLabel
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
)
{
QBrush
windowBrush
=
palette
().
window
();
windowBrush
.
setColor
(
windowBrush
.
color
().
darker
(
150
));
painter
->
fillRect
(
boundingRect
(),
windowBrush
);
painter
->
drawText
(
boundingRect
(),
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
,
text
);
}
QSizeF
TitleLabel
::
sizeHint
(
Qt
::
SizeHint
which
,
const
QSizeF
&
constraint
)
const
{
QFont
f
;
QFontMetrics
fm
(
f
);
if
(
which
==
Qt
::
MaximumSize
)
return
QSizeF
(
constraint
.
width
(),
fm
.
size
(
Qt
::
TextSingleLine
,
text
).
height
()
+
10
);
else
return
fm
.
size
(
Qt
::
TextSingleLine
,
text
)
+
QSizeF
(
10
,
10
);
}
void
TitleLabel
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
buttonDownPos
=
static_cast
<
GameScene
*>
(
scene
())
->
getViewTransform
().
inverted
().
map
(
event
->
pos
());
event
->
accept
();
}
else
event
->
ignore
();
}
void
TitleLabel
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
emit
mouseMoved
(
event
->
scenePos
()
-
buttonDownPos
);
}
ZoneViewWidget
::
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
,
bool
_revealZone
,
bool
_writeableRevealZone
,
const
QList
<
const
ServerInfo_Card
*>
&
cardList
)
ZoneViewWidget
::
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
,
bool
_revealZone
,
bool
_writeableRevealZone
,
const
QList
<
const
ServerInfo_Card
*>
&
cardList
)
:
QGraphicsWidget
(
0
,
Qt
::
Window
),
canBeShuffled
(
_origZone
->
getIsShufflable
()),
player
(
_player
)
:
QGraphicsWidget
(
0
,
Qt
::
Window
),
canBeShuffled
(
_origZone
->
getIsShufflable
()),
player
(
_player
)
{
{
...
@@ -174,8 +136,20 @@ void ZoneViewWidget::retranslateUi()
...
@@ -174,8 +136,20 @@ void ZoneViewWidget::retranslateUi()
pileViewCheckBox
.
setText
(
tr
(
"pile view"
));
pileViewCheckBox
.
setText
(
tr
(
"pile view"
));
}
}
void
ZoneViewWidget
::
move
Widget
(
QPointF
scenePos
)
void
ZoneViewWidget
::
move
Event
(
QGraphicsSceneMoveEvent
*
/* event */
)
{
{
if
(
!
scene
())
return
;
static
int
titleBarHeight
=
0
;
if
(
titleBarHeight
==
0
)
{
QStyleOptionTitleBar
so
;
titleBarHeight
=
style
()
->
pixelMetric
(
QStyle
::
PM_TitleBarHeight
,
&
so
,
(
QWidget
*
)
this
);
}
QPointF
scenePos
=
pos
();
if
(
scenePos
.
x
()
<
0
)
if
(
scenePos
.
x
()
<
0
)
{
{
scenePos
.
setX
(
0
);
scenePos
.
setX
(
0
);
...
@@ -185,16 +159,17 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
...
@@ -185,16 +159,17 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
scenePos
.
setX
(
maxw
);
scenePos
.
setX
(
maxw
);
}
}
if
(
scenePos
.
y
()
<
0
)
if
(
scenePos
.
y
()
<
titleBarHeight
)
{
{
scenePos
.
setY
(
0
);
scenePos
.
setY
(
titleBarHeight
);
}
else
{
}
else
{
qreal
maxh
=
scene
()
->
sceneRect
().
height
()
-
100
;
qreal
maxh
=
scene
()
->
sceneRect
().
height
()
-
titleBarHeight
;
if
(
scenePos
.
y
()
>
maxh
)
if
(
scenePos
.
y
()
>
maxh
)
scenePos
.
setY
(
maxh
);
scenePos
.
setY
(
maxh
);
}
}
setPos
(
scenePos
);
if
(
scenePos
!=
pos
())
setPos
(
scenePos
);
}
}
void
ZoneViewWidget
::
resizeToZoneContents
()
void
ZoneViewWidget
::
resizeToZoneContents
()
...
...
cockatrice/src/zoneviewwidget.h
View file @
4c9555bb
...
@@ -18,30 +18,12 @@ class QGraphicsSceneMouseEvent;
...
@@ -18,30 +18,12 @@ class QGraphicsSceneMouseEvent;
class
QGraphicsSceneWheelEvent
;
class
QGraphicsSceneWheelEvent
;
class
QStyleOption
;
class
QStyleOption
;
class
TitleLabel
:
public
QGraphicsWidget
{
Q_OBJECT
private:
QString
text
;
QPointF
buttonDownPos
;
public:
TitleLabel
();
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
);
void
setText
(
const
QString
&
_text
)
{
text
=
_text
;
update
();
}
signals:
void
mouseMoved
(
QPointF
scenePos
);
protected:
QSizeF
sizeHint
(
Qt
::
SizeHint
which
,
const
QSizeF
&
constraint
)
const
;
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
};
class
ZoneViewWidget
:
public
QGraphicsWidget
{
class
ZoneViewWidget
:
public
QGraphicsWidget
{
Q_OBJECT
Q_OBJECT
private:
private:
ZoneViewZone
*
zone
;
ZoneViewZone
*
zone
;
QGraphicsWidget
*
zoneContainer
;
QGraphicsWidget
*
zoneContainer
;
TitleLabel
*
titleLabel
;
QPushButton
*
closeButton
;
QPushButton
*
closeButton
;
QScrollBar
*
scrollBar
;
QScrollBar
*
scrollBar
;
QCheckBox
sortByNameCheckBox
;
QCheckBox
sortByNameCheckBox
;
...
@@ -62,7 +44,7 @@ private slots:
...
@@ -62,7 +44,7 @@ private slots:
void
handleWheelEvent
(
QGraphicsSceneWheelEvent
*
event
);
void
handleWheelEvent
(
QGraphicsSceneWheelEvent
*
event
);
void
handleScrollBarChange
(
int
value
);
void
handleScrollBarChange
(
int
value
);
void
zoneDeleted
();
void
zoneDeleted
();
void
move
Widget
(
QPointF
scenePos
);
void
move
Event
(
QGraphicsSceneMoveEvent
*
/* event */
);
public:
public:
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
=
0
,
bool
_revealZone
=
false
,
bool
_writeableRevealZone
=
false
,
const
QList
<
const
ServerInfo_Card
*>
&
cardList
=
QList
<
const
ServerInfo_Card
*>
());
ZoneViewWidget
(
Player
*
_player
,
CardZone
*
_origZone
,
int
numberCards
=
0
,
bool
_revealZone
=
false
,
bool
_writeableRevealZone
=
false
,
const
QList
<
const
ServerInfo_Card
*>
&
cardList
=
QList
<
const
ServerInfo_Card
*>
());
ZoneViewZone
*
getZone
()
const
{
return
zone
;
}
ZoneViewZone
*
getZone
()
const
{
return
zone
;
}
...
...
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