2010-09-17 22:49:24 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file mixercurvepoint.h
|
|
|
|
* @author Edouard Lafargue Copyright (C) 2010.
|
|
|
|
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Configuration Plugin
|
|
|
|
* @{
|
|
|
|
* @brief A point on the mixer curve
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
#include "mixercurveline.h"
|
|
|
|
#include "mixercurvepoint.h"
|
|
|
|
#include "mixercurvewidget.h"
|
|
|
|
|
|
|
|
Node::Node(MixerCurveWidget *graphWidget)
|
|
|
|
: graph(graphWidget)
|
|
|
|
{
|
|
|
|
setFlag(ItemIsMovable);
|
|
|
|
setFlag(ItemSendsGeometryChanges);
|
|
|
|
setCacheMode(DeviceCoordinateCache);
|
|
|
|
setZValue(-1);
|
2010-09-19 07:47:18 +02:00
|
|
|
vertical = false;
|
2010-09-17 22:49:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::addEdge(Edge *edge)
|
|
|
|
{
|
|
|
|
edgeList << edge;
|
|
|
|
edge->adjust();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Edge *> Node::edges() const
|
|
|
|
{
|
|
|
|
return edgeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF Node::boundingRect() const
|
|
|
|
{
|
|
|
|
qreal adjust = 2;
|
|
|
|
return QRectF(-10 - adjust, -10 - adjust,
|
|
|
|
23 + adjust, 23 + adjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath Node::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
path.addEllipse(-10, -10, 20, 20);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
|
|
|
{
|
2010-09-24 22:39:37 +02:00
|
|
|
/*
|
2010-09-17 22:49:24 +02:00
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
painter->setBrush(Qt::darkGray);
|
|
|
|
painter->drawEllipse(-7, -7, 20, 20);
|
2010-09-24 22:39:37 +02:00
|
|
|
*/
|
2010-09-17 22:49:24 +02:00
|
|
|
|
|
|
|
QRadialGradient gradient(-3, -3, 10);
|
|
|
|
if (option->state & QStyle::State_Sunken) {
|
|
|
|
gradient.setCenter(3, 3);
|
|
|
|
gradient.setFocalPoint(3, 3);
|
2010-09-24 22:39:37 +02:00
|
|
|
gradient.setColorAt(1, QColor("#1c870b").light(120));
|
|
|
|
gradient.setColorAt(0, QColor("#116703").light(120));
|
2010-09-17 22:49:24 +02:00
|
|
|
} else {
|
2010-09-24 22:39:37 +02:00
|
|
|
gradient.setColorAt(0, "#1c870b");
|
|
|
|
gradient.setColorAt(1, "#116703");
|
2010-09-17 22:49:24 +02:00
|
|
|
}
|
|
|
|
painter->setBrush(gradient);
|
|
|
|
painter->setPen(QPen(Qt::black, 0));
|
|
|
|
painter->drawEllipse(-10, -10, 20, 20);
|
|
|
|
}
|
|
|
|
|
2010-09-19 07:47:18 +02:00
|
|
|
void Node::verticalMove(bool flag){
|
|
|
|
vertical = flag;
|
|
|
|
}
|
|
|
|
|
2010-09-17 22:49:24 +02:00
|
|
|
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2010-09-19 07:47:18 +02:00
|
|
|
|
2010-09-17 22:49:24 +02:00
|
|
|
switch (change) {
|
2010-09-19 07:47:18 +02:00
|
|
|
case ItemPositionChange: {
|
|
|
|
if (!vertical)
|
|
|
|
break;
|
2010-09-24 22:39:37 +02:00
|
|
|
// Force node to move vertically
|
2010-09-19 07:47:18 +02:00
|
|
|
QPointF newPos = value.toPointF();
|
|
|
|
newPos.setX(pos().x());
|
2010-09-24 22:39:37 +02:00
|
|
|
// Stay inside graph
|
|
|
|
if (newPos.y() < 0)
|
|
|
|
newPos.setY(0);
|
|
|
|
if (newPos.y() > graph->height())
|
|
|
|
newPos.setY(graph->height());
|
2010-09-19 07:47:18 +02:00
|
|
|
return newPos;
|
|
|
|
}
|
2010-09-17 22:49:24 +02:00
|
|
|
case ItemPositionHasChanged:
|
|
|
|
foreach (Edge *edge, edgeList)
|
|
|
|
edge->adjust();
|
|
|
|
graph->itemMoved();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
QGraphicsItem::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|