Merge pull request #1496 from ctrlaltca/clamp_zoneview
Clamp zone view widget's titlebar inside the viewable area
This commit is contained in:
commit
4c9555bb59
2 changed files with 20 additions and 63 deletions
|
@ -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()
|
||||||
pileViewCheckBox.setText(tr("pile view"));
|
pileViewCheckBox.setText(tr("pile view"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewWidget::moveWidget(QPointF scenePos)
|
void ZoneViewWidget::moveEvent(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)
|
||||||
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()
|
||||||
|
|
|
@ -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:
|
||||||
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
|
void handleWheelEvent(QGraphicsSceneWheelEvent *event);
|
||||||
void handleScrollBarChange(int value);
|
void handleScrollBarChange(int value);
|
||||||
void zoneDeleted();
|
void zoneDeleted();
|
||||||
void moveWidget(QPointF scenePos);
|
void moveEvent(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; }
|
||||||
|
|
Loading…
Reference in a new issue