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
a7616835
Commit
a7616835
authored
Sep 10, 2015
by
Fabio Bas
Browse files
Clamp zone view widget's titlebar inside the viewable area
parent
3bc61eb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/zoneviewwidget.cpp
View file @
a7616835
...
...
@@ -20,44 +20,6 @@
#include
"pb/command_stop_dump_zone.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
)
:
QGraphicsWidget
(
0
,
Qt
::
Window
),
canBeShuffled
(
_origZone
->
getIsShufflable
()),
player
(
_player
)
{
...
...
@@ -174,8 +136,20 @@ void ZoneViewWidget::retranslateUi()
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
)
{
scenePos
.
setX
(
0
);
...
...
@@ -185,16 +159,17 @@ void ZoneViewWidget::moveWidget(QPointF scenePos)
scenePos
.
setX
(
maxw
);
}
if
(
scenePos
.
y
()
<
0
)
if
(
scenePos
.
y
()
<
titleBarHeight
)
{
scenePos
.
setY
(
0
);
scenePos
.
setY
(
titleBarHeight
);
}
else
{
qreal
maxh
=
scene
()
->
sceneRect
().
height
()
-
100
;
qreal
maxh
=
scene
()
->
sceneRect
().
height
()
-
titleBarHeight
;
if
(
scenePos
.
y
()
>
maxh
)
scenePos
.
setY
(
maxh
);
}
setPos
(
scenePos
);
if
(
scenePos
!=
pos
())
setPos
(
scenePos
);
}
void
ZoneViewWidget
::
resizeToZoneContents
()
...
...
cockatrice/src/zoneviewwidget.h
View file @
a7616835
...
...
@@ -18,30 +18,12 @@ class QGraphicsSceneMouseEvent;
class
QGraphicsSceneWheelEvent
;
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
{
Q_OBJECT
private:
ZoneViewZone
*
zone
;
QGraphicsWidget
*
zoneContainer
;
TitleLabel
*
titleLabel
;
QPushButton
*
closeButton
;
QScrollBar
*
scrollBar
;
QCheckBox
sortByNameCheckBox
;
...
...
@@ -62,7 +44,7 @@ private slots:
void
handleWheelEvent
(
QGraphicsSceneWheelEvent
*
event
);
void
handleScrollBarChange
(
int
value
);
void
zoneDeleted
();
void
move
Widget
(
QPointF
scenePos
);
void
move
Event
(
QGraphicsSceneMoveEvent
*
/* event */
);
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
*>
());
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