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>
28 #include "columnhandleitem.h"
30 ColumnHandleItem::ColumnHandleItem(qreal w, QGraphicsItem *parent)
31 : QGraphicsItem(parent),
36 setAcceptsHoverEvents(true);
38 setCursor(QCursor(Qt::OpenHandCursor));
39 setFlag(ItemIsMovable);
41 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
44 void ColumnHandleItem::setXPos(qreal xpos) {
45 setPos(xpos - width()/2, (qreal)0);
48 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
49 if(rect.height() != boundingRect().height())
50 prepareGeometryChange();
53 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
54 QGraphicsItem::mouseMoveEvent(event);
57 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { qDebug() << "pressed!";
58 setCursor(QCursor(Qt::ClosedHandCursor));
59 QGraphicsItem::mousePressEvent(event);
62 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
63 setCursor(QCursor(Qt::OpenHandCursor));
64 QGraphicsItem::mouseReleaseEvent(event);
67 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
71 QLinearGradient gradient(0, 0, width(), 0);
72 gradient.setColorAt(0.25, Qt::transparent);
73 gradient.setColorAt(0.5, QColor(0, 0, 0, _hover * 200));
74 gradient.setColorAt(0.75, Qt::transparent);
75 painter->fillRect(boundingRect(), gradient);
78 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
81 _timeLine.setDirection(QTimeLine::Forward);
82 if(_timeLine.state() != QTimeLine::Running)
86 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
89 _timeLine.setDirection(QTimeLine::Backward);
90 if(_timeLine.state() != QTimeLine::Running)
94 void ColumnHandleItem::hoverChanged(qreal value) {