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),
35 _boundingRect(-_width/2, 0, _width, 0),
42 setAcceptsHoverEvents(true);
44 setCursor(QCursor(Qt::OpenHandCursor));
46 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
49 void ColumnHandleItem::setXPos(qreal xpos) {
51 QRectF sceneBRect = _boundingRect.translated(x(), 0);
52 _sceneLeft = sceneBRect.left();
53 _sceneRight = sceneBRect.right();
56 void ColumnHandleItem::setXLimits(qreal min, qreal max) {
59 //if(x() < min) setPos(min, 0);
60 //else if(x() > max) setPos(max - width(), 0);
63 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
64 prepareGeometryChange();
65 _boundingRect = QRectF(-_width/2, rect.y(), _width, rect.height());
68 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
69 if(event->buttons() & Qt::LeftButton && _moving) {
70 if(contains(event->lastPos())) {
71 qreal newx = x() + (event->scenePos() - event->lastScenePos()).x();
72 if(newx < _minXPos) newx = _minXPos;
73 else if(newx + width() > _maxXPos) newx = _maxXPos - width();
82 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
83 if(event->buttons() & Qt::LeftButton) {
84 setCursor(QCursor(Qt::ClosedHandCursor));
92 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
95 setCursor(QCursor(Qt::OpenHandCursor));
96 QRectF sceneBRect = _boundingRect.translated(x(), 0);
97 _sceneLeft = sceneBRect.left();
98 _sceneRight = sceneBRect.right();
99 emit positionChanged(x());
106 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
109 _timeLine.setDirection(QTimeLine::Forward);
110 if(_timeLine.state() != QTimeLine::Running)
114 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
117 _timeLine.setDirection(QTimeLine::Backward);
118 if(_timeLine.state() != QTimeLine::Running)
122 void ColumnHandleItem::hoverChanged(qreal value) {
127 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
131 QLinearGradient gradient(boundingRect().topLeft(), boundingRect().topRight());
132 QColor rulerColor = QApplication::palette().windowText().color();
133 rulerColor.setAlphaF(_hover);
134 gradient.setColorAt(0, Qt::transparent);
135 gradient.setColorAt(0.4, rulerColor);
136 gradient.setColorAt(0.6, rulerColor);
137 gradient.setColorAt(1, Qt::transparent);
138 painter->fillRect(boundingRect(), gradient);