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>
30 ColumnHandleItem::ColumnHandleItem(qreal w, QGraphicsItem *parent)
31 : QGraphicsItem(parent),
39 setAcceptsHoverEvents(true);
41 setCursor(QCursor(Qt::OpenHandCursor));
43 connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(hoverChanged(qreal)));
46 void ColumnHandleItem::setXPos(qreal xpos) {
50 void ColumnHandleItem::setXLimits(qreal min, qreal max) {
53 //if(x() < min) setPos(min, 0);
54 //else if(x() > max) setPos(max - width(), 0);
57 void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
58 if(rect.height() != boundingRect().height())
59 prepareGeometryChange();
62 void ColumnHandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
63 if(event->buttons() & Qt::LeftButton && _moving) {
64 if(contains(event->lastPos())) {
65 qreal newx = x() + (event->scenePos() - event->lastScenePos()).x();
66 if(newx < _minXPos) newx = _minXPos;
67 else if(newx + width() > _maxXPos) newx = _maxXPos - width();
76 void ColumnHandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
77 if(event->buttons() & Qt::LeftButton) {
78 setCursor(QCursor(Qt::ClosedHandCursor));
86 void ColumnHandleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
89 setCursor(QCursor(Qt::OpenHandCursor));
90 emit positionChanged(x());
97 void ColumnHandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
100 _timeLine.setDirection(QTimeLine::Forward);
101 if(_timeLine.state() != QTimeLine::Running)
105 void ColumnHandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
108 _timeLine.setDirection(QTimeLine::Backward);
109 if(_timeLine.state() != QTimeLine::Running)
113 void ColumnHandleItem::hoverChanged(qreal value) {
118 void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
122 QLinearGradient gradient(boundingRect().topLeft(), boundingRect().topRight());
123 QColor rulerColor = QApplication::palette().windowText().color();
124 rulerColor.setAlphaF(_hover);
125 gradient.setColorAt(0, Qt::transparent);
126 gradient.setColorAt(0.4, rulerColor);
127 gradient.setColorAt(0.6, rulerColor);
128 gradient.setColorAt(1, Qt::transparent);
129 painter->fillRect(boundingRect(), gradient);