aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mscrollchain/scrollablewidget.cpp
blob: 7dd8b3b07560e072759fc762dfd9f08baa475660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "scrollablewidget.h"

ScrollableWidget::ScrollableWidget(QGraphicsItem *parent)
    : QGraphicsWidget(parent),
      mContentItem(0)
{
    // Not really needed but illustrates the use of this widget.
    setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
}
ScrollableWidget::~ScrollableWidget() {}

void ScrollableWidget::setContentItem(QGraphicsItem *item)
{
    delete mContentItem;
    mContentItem = item;
    item->setParentItem(this);
    item->setPos(QPointF());
}

const QGraphicsItem *ScrollableWidget::contentItem() const
{
    return mContentItem;
}

void ScrollableWidget::scrollContents(const QPoint &offset)
{
    if (mContentItem) {
        mContentItem->setPos(mContentItem->pos() + offset);
    }
}

void ScrollableWidget::clearScroll()
{
    if (mContentItem) {
        mContentItem->setPos(QPointF());
    }
}