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 ***************************************************************************/
21 #include "columnhandleitem.h"
23 #include <QApplication>
25 #include <QGraphicsScene>
26 #include <QGraphicsSceneHoverEvent>
32 ColumnHandleItem::ColumnHandleItem(qreal w, QGraphicsItem *parent)
33 : QGraphicsItem(parent),
41 setAcceptsHoverEvents(true);
43 setCursor(QCursor(Qt::OpenHandCursor));
45 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
48 void ColumnHandleItem::setXPos(qreal xpos) {
52 void ColumnHandleItem::setXLimits(qreal min, qreal max) {
55 //if(x() < min) setPos(min, 0);
56 //else if(x() > max) setPos(max - width(), 0);
59 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
61 prepareGeometryChange();
64 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
65 if(event->buttons() & Qt::LeftButton && _moving) {
66 if(contains(event->lastPos())) {
67 qreal newx = x() + (event->scenePos() - event->lastScenePos()).x();
68 if(newx < _minXPos) newx = _minXPos;
69 else if(newx + width() > _maxXPos) newx = _maxXPos - width();
78 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
79 if(event->buttons() & Qt::LeftButton) {
80 setCursor(QCursor(Qt::ClosedHandCursor));
88 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
91 setCursor(QCursor(Qt::OpenHandCursor));
92 emit positionChanged(x());
99 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
102 _timeLine.setDirection(QTimeLine::Forward);
103 if(_timeLine.state() != QTimeLine::Running)
107 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
110 _timeLine.setDirection(QTimeLine::Backward);
111 if(_timeLine.state() != QTimeLine::Running)
115 void ColumnHandleItem::hoverChanged(qreal value) {
120 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
124 QLinearGradient gradient(boundingRect().topLeft(), boundingRect().topRight());
125 QColor rulerColor = QApplication::palette().windowText().color();
126 rulerColor.setAlphaF(_hover);
127 gradient.setColorAt(0, Qt::transparent);
128 gradient.setColorAt(0.4, rulerColor);
129 gradient.setColorAt(0.6, rulerColor);
130 gradient.setColorAt(1, Qt::transparent);
131 painter->fillRect(boundingRect(), gradient);