2009-03-03 18:31:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_SCROLLWIDGET_H
|
|
|
|
#define PLASMA_SCROLLWIDGET_H
|
|
|
|
|
2009-12-21 19:36:39 +01:00
|
|
|
#include <QtCore/QAbstractAnimation>
|
2009-03-03 18:31:54 +01:00
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ScrollWidgetPrivate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class ScrollWidget plasma/widgets/ScrollWidget.h <Plasma/Widgets/ScrollWidget>
|
|
|
|
*
|
|
|
|
* @short A container of widgets that can have scrollbars
|
|
|
|
*
|
|
|
|
* A container of widgets that can have horizontal and vertical scrollbars if the content is bigger than the widget itself
|
2009-03-03 19:11:33 +01:00
|
|
|
*
|
|
|
|
* @since 4.3
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT ScrollWidget : public QGraphicsWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QGraphicsWidget *widget READ widget WRITE setWidget)
|
2009-03-26 21:21:48 +01:00
|
|
|
Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy)
|
|
|
|
Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy)
|
2010-10-11 21:59:47 +02:00
|
|
|
Q_PROPERTY(bool overflowBordersVisible READ overflowBordersVisible WRITE setOverflowBordersVisible)
|
2009-10-08 18:04:56 +02:00
|
|
|
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
|
|
|
|
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
|
|
|
|
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
|
2010-04-18 18:31:07 +02:00
|
|
|
Q_PROPERTY(QSizeF snapSize READ snapSize WRITE setSnapSize)
|
2009-03-03 18:31:54 +01:00
|
|
|
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
|
2010-03-18 19:14:39 +01:00
|
|
|
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
|
2010-03-18 20:22:52 +01:00
|
|
|
Q_PROPERTY(bool overShoot READ hasOverShoot WRITE setOverShoot)
|
2009-03-03 18:31:54 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new ScrollWidget
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param parent the parent of this widget
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
|
|
|
explicit ScrollWidget(QGraphicsWidget *parent = 0);
|
2009-12-16 11:57:25 +01:00
|
|
|
explicit ScrollWidget(QGraphicsItem *parent);
|
2009-03-03 18:31:54 +01:00
|
|
|
~ScrollWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the widget this ScrollWidget will contain
|
|
|
|
* ownership is transferred to this scrollwidget,
|
2009-10-21 16:32:24 +02:00
|
|
|
* if an old one was already in, it will be deleted.
|
2010-03-01 22:26:12 +01:00
|
|
|
* If the widget size policy allows for horizontal and/or vertical expansion,
|
|
|
|
* it will be resized when possible, otherwise it will be kept to whichever
|
2009-10-21 16:32:24 +02:00
|
|
|
* width the widget resizes itself.
|
2009-03-03 18:31:54 +01:00
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param widget the new main sub widget
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
|
|
|
void setWidget(QGraphicsWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the main widget
|
|
|
|
*/
|
|
|
|
QGraphicsWidget *widget() const;
|
|
|
|
|
2010-03-18 19:14:39 +01:00
|
|
|
/**
|
|
|
|
* Sets the alignment for the inner widget.
|
|
|
|
* It is only meaningful if the inner widget is smaller
|
|
|
|
* than the viewport.
|
2010-03-18 20:22:52 +01:00
|
|
|
* @since 4.5
|
2010-03-18 19:14:39 +01:00
|
|
|
*/
|
|
|
|
void setAlignment(Qt::Alignment align);
|
|
|
|
|
|
|
|
/**
|
2010-03-18 20:22:52 +01:00
|
|
|
* @return currently set alignment for the inner widget
|
|
|
|
* @since 4.5
|
2010-03-18 19:14:39 +01:00
|
|
|
*/
|
|
|
|
Qt::Alignment alignment() const;
|
|
|
|
|
2010-03-18 20:22:52 +01:00
|
|
|
/**
|
|
|
|
* Tells the scrollwidget whether the widget can scroll a little
|
|
|
|
* beyond its boundaries and then automatically snap back or
|
|
|
|
* whether the widget scrolling always stops at the edges.
|
|
|
|
* @since 4.5
|
|
|
|
*/
|
|
|
|
void setOverShoot(bool enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if overshoot is enabled
|
|
|
|
* @since 4.5
|
|
|
|
*/
|
|
|
|
bool hasOverShoot() const;
|
|
|
|
|
2009-03-03 18:31:54 +01:00
|
|
|
/**
|
|
|
|
* Sets the horizontal scrollbar policy
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param policy desired policy
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
2009-03-26 21:21:48 +01:00
|
|
|
void setHorizontalScrollBarPolicy(const Qt::ScrollBarPolicy policy);
|
2009-03-03 18:31:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the horizontal scrollbar policy
|
|
|
|
*/
|
2009-03-26 21:21:48 +01:00
|
|
|
Qt::ScrollBarPolicy horizontalScrollBarPolicy() const;
|
2009-03-03 18:31:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the vertical scrollbar policy
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param policy desired policy
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
2009-03-26 21:21:48 +01:00
|
|
|
void setVerticalScrollBarPolicy(const Qt::ScrollBarPolicy policy);
|
2009-03-03 18:31:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the vertical scrollbar policy
|
|
|
|
*/
|
2009-03-26 21:21:48 +01:00
|
|
|
Qt::ScrollBarPolicy verticalScrollBarPolicy() const;
|
2009-03-03 18:31:54 +01:00
|
|
|
|
2010-10-11 21:59:47 +02:00
|
|
|
/**
|
|
|
|
* @return true if the widget shows borders when the inner widget
|
|
|
|
* is bigger than the viewport
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
bool overflowBordersVisible() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether borders should be shown when the inner widget
|
|
|
|
* is bigger than the viewport
|
|
|
|
* @param visible true if the border should be visible when
|
|
|
|
* the inner widget overflows
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
void setOverflowBordersVisible(const bool visible);
|
|
|
|
|
2009-09-24 22:40:16 +02:00
|
|
|
/**
|
|
|
|
* Scroll the view until the given rectangle is visible
|
|
|
|
*
|
|
|
|
* @param rect rect we want visible, in coordinates mapped to the inner widget
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-11-14 05:31:20 +01:00
|
|
|
Q_INVOKABLE void ensureRectVisible(const QRectF &rect);
|
2009-09-24 22:40:16 +02:00
|
|
|
|
2009-10-04 22:08:37 +02:00
|
|
|
/**
|
|
|
|
* Scroll the view until the given item is visible
|
|
|
|
*
|
|
|
|
* @param item item we want visible
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-11-14 05:31:20 +01:00
|
|
|
Q_INVOKABLE void ensureItemVisible(QGraphicsItem *item);
|
2009-10-04 22:08:37 +02:00
|
|
|
|
2009-11-06 19:57:35 +01:00
|
|
|
/**
|
|
|
|
* Register an item as a drag handle, it means mouse events will pass trough it
|
|
|
|
* and will be possible to drag the view by dragging the item itself.
|
|
|
|
* The item will still receive mouse clicks if the mouse didn't move
|
|
|
|
* between press and release.
|
|
|
|
*
|
2010-03-18 21:22:03 +01:00
|
|
|
* This function is no more necessary, since it's the authomatic behaviour
|
|
|
|
* for all children items, the implementation has now no effect
|
|
|
|
*
|
2009-11-06 19:57:35 +01:00
|
|
|
* @param item the drag handle item. widget() must be an ancestor if it in
|
|
|
|
* the parent hierarchy. if item doesn't accept mose press events
|
|
|
|
* it's not necessary to call this function.
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2010-03-18 21:22:03 +01:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void registerAsDragHandle(QGraphicsWidget *item);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2009-11-06 19:57:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister the given item as drag handle (if it was registered)
|
2010-03-18 21:22:03 +01:00
|
|
|
*
|
|
|
|
* This function is no more necessary, since it's the authomatic behaviour
|
|
|
|
* for all children items, the implementation has now no effect
|
|
|
|
*
|
2009-11-06 19:57:35 +01:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2010-03-18 21:22:03 +01:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void unregisterAsDragHandle(QGraphicsWidget *item);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2009-11-06 19:57:35 +01:00
|
|
|
|
2009-10-01 18:47:19 +02:00
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* The geometry of the viewport.
|
2009-10-01 18:47:19 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QRectF viewportGeometry() const;
|
|
|
|
|
2009-10-01 18:47:19 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* @return the size of the internal widget
|
2009-10-01 18:47:19 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QSizeF contentsSize() const;
|
2009-10-01 18:47:19 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* Sets the position of the internal widget relative to this widget
|
2009-10-01 18:47:19 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
void setScrollPosition(const QPointF &position);
|
2009-10-01 18:47:19 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* @return the position of the internal widget relative to this widget
|
2009-10-01 18:47:19 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QPointF scrollPosition() const;
|
|
|
|
|
2010-04-18 18:31:07 +02:00
|
|
|
/**
|
|
|
|
* Set the nap size of the kinetic scrolling:
|
|
|
|
* the scrolling will always stop at multiples of that size.
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param the desired snap size
|
2010-04-18 18:31:07 +02:00
|
|
|
* @since 4.5
|
|
|
|
*/
|
|
|
|
void setSnapSize(const QSizeF &size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the snap size of the kinetic scrolling
|
|
|
|
* @since 4.5
|
|
|
|
*/
|
|
|
|
QSizeF snapSize() const;
|
2009-10-01 18:47:19 +02:00
|
|
|
|
2009-03-03 18:31:54 +01:00
|
|
|
/**
|
|
|
|
* Sets the stylesheet used to control the visual display of this ScrollWidget
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param stylesheet a CSS string
|
2009-03-03 18:31:54 +01:00
|
|
|
*/
|
|
|
|
void setStyleSheet(const QString &stylesheet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the stylesheet currently used with this widget
|
|
|
|
*/
|
|
|
|
QString styleSheet() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the native widget wrapped by this ScrollWidget
|
|
|
|
*/
|
|
|
|
QWidget *nativeWidget() const;
|
|
|
|
|
2009-12-21 19:36:39 +01:00
|
|
|
Q_SIGNALS:
|
2010-04-19 17:55:04 +02:00
|
|
|
/**
|
|
|
|
* The widget started or stopped an animated scroll
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-12-21 19:36:39 +01:00
|
|
|
void scrollStateChanged(QAbstractAnimation::State newState,
|
|
|
|
QAbstractAnimation::State oldState);
|
|
|
|
|
2010-04-19 17:55:04 +02:00
|
|
|
/**
|
|
|
|
* The viewport geomety changed, for instance due a widget resize
|
|
|
|
*
|
|
|
|
* @since 4.5
|
|
|
|
*/
|
|
|
|
void viewportGeometryChanged(const QRectF &geomety);
|
|
|
|
|
2009-03-03 18:31:54 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
|
|
|
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
2009-09-17 18:24:19 +02:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
2010-05-09 18:57:05 +02:00
|
|
|
void keyPressEvent(QKeyEvent *event);
|
2009-03-03 18:31:54 +01:00
|
|
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event);
|
2009-10-02 18:07:06 +02:00
|
|
|
void focusInEvent(QFocusEvent *event);
|
2009-10-16 16:10:55 +02:00
|
|
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
|
2010-03-18 19:14:39 +01:00
|
|
|
bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
|
2009-03-03 18:31:54 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
ScrollWidgetPrivate * const d;
|
|
|
|
|
|
|
|
Q_PRIVATE_SLOT(d, void verticalScroll(int value))
|
|
|
|
Q_PRIVATE_SLOT(d, void horizontalScroll(int value))
|
2009-10-04 22:08:37 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void makeRectVisible())
|
2009-12-01 21:49:34 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void makeItemVisible())
|
2009-12-15 22:37:07 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void adjustScrollbars())
|
2010-03-18 19:14:39 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void fixupX())
|
|
|
|
Q_PRIVATE_SLOT(d, void fixupY())
|
|
|
|
Q_PRIVATE_SLOT(d, void setScrollX())
|
|
|
|
Q_PRIVATE_SLOT(d, void setScrollY())
|
2009-12-21 19:36:39 +01:00
|
|
|
|
|
|
|
friend class ScrollWidgetPrivate;
|
2009-03-03 18:31:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|