1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include <QGraphicsScene>
23 #include <QGraphicsSceneHoverEvent>
26 #include "columnhandleitem.h"
28 ColumnHandleItem::ColumnHandleItem(qreal w, QGraphicsItem *parent)
29 : QGraphicsItem(parent),
37 setAcceptsHoverEvents(true);
39 setCursor(QCursor(Qt::OpenHandCursor));
41 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
44 void ColumnHandleItem::setXPos(qreal xpos) {
45 setPos(xpos - width()/2, 0);
48 void ColumnHandleItem::setXLimits(qreal min, qreal max) {
51 //if(x() < min) setPos(min, 0);
52 //else if(x() > max) setPos(max - width(), 0);
55 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
56 if(rect.height() != boundingRect().height())
57 prepareGeometryChange();
60 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
61 if(event->buttons() & Qt::LeftButton && _moving) {
62 if(contains(event->lastPos())) {
63 qreal newx = x() + (event->scenePos() - event->lastScenePos()).x();
64 if(newx < _minXPos) newx = _minXPos;
65 else if(newx + width() > _maxXPos) newx = _maxXPos - width();
74 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
75 if(event->buttons() & Qt::LeftButton) {
76 setCursor(QCursor(Qt::ClosedHandCursor));
84 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
87 setCursor(QCursor(Qt::OpenHandCursor));
88 emit positionChanged(x() + width()/2);
95 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
98 _timeLine.setDirection(QTimeLine::Forward);
99 if(_timeLine.state() != QTimeLine::Running)
103 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
106 _timeLine.setDirection(QTimeLine::Backward);
107 if(_timeLine.state() != QTimeLine::Running)
111 void ColumnHandleItem::hoverChanged(qreal value) {
116 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
120 QLinearGradient gradient(0, 0, width(), 0);
121 gradient.setColorAt(0.25, Qt::transparent);
122 gradient.setColorAt(0.5, QColor(0, 0, 0, _hover * 200));
123 gradient.setColorAt(0.75, Qt::transparent);
124 painter->fillRect(boundingRect(), gradient);