1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
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),
35 _boundingRect(-_width/2, 0, _width, 0),
41 _rulerColor(QApplication::palette().windowText().color())
43 _timeLine.setUpdateInterval(20);
45 setAcceptsHoverEvents(true);
47 setCursor(QCursor(Qt::OpenHandCursor));
49 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
52 void ColumnHandleItem::setXPos(qreal xpos) {
54 QRectF sceneBRect = _boundingRect.translated(x(), 0);
55 _sceneLeft = sceneBRect.left();
56 _sceneRight = sceneBRect.right();
59 void ColumnHandleItem::setXLimits(qreal min, qreal max) {
62 //if(x() < min) setPos(min, 0);
63 //else if(x() > max) setPos(max - width(), 0);
66 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
67 prepareGeometryChange();
68 _boundingRect = QRectF(-_width/2, rect.y(), _width, rect.height());
71 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
72 if(event->buttons() & Qt::LeftButton && _moving) {
73 if(contains(event->lastPos())) {
74 qreal newx = x() + (event->scenePos() - event->lastScenePos()).x();
75 if(newx < _minXPos) newx = _minXPos;
76 else if(newx + width() > _maxXPos) newx = _maxXPos - width();
85 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
86 if(event->buttons() & Qt::LeftButton) {
87 setCursor(QCursor(Qt::ClosedHandCursor));
95 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
98 setCursor(QCursor(Qt::OpenHandCursor));
99 QRectF sceneBRect = _boundingRect.translated(x(), 0);
100 _sceneLeft = sceneBRect.left();
101 _sceneRight = sceneBRect.right();
102 emit positionChanged(x());
109 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
112 _timeLine.setDirection(QTimeLine::Forward);
113 if(_timeLine.state() != QTimeLine::Running)
117 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
120 _timeLine.setDirection(QTimeLine::Backward);
121 if(_timeLine.state() != QTimeLine::Running)
125 void ColumnHandleItem::hoverChanged(qreal value) {
130 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
134 QLinearGradient gradient(boundingRect().topLeft(), boundingRect().topRight());
135 QColor _rulerColor = QApplication::palette().windowText().color();
136 _rulerColor.setAlphaF(_hover);
137 gradient.setColorAt(0, Qt::transparent);
138 gradient.setColorAt(0.4, _rulerColor);
139 gradient.setColorAt(0.6, _rulerColor);
140 gradient.setColorAt(1, Qt::transparent);
141 painter->fillRect(boundingRect(), gradient);