Something went wrong. Try again.
A modern, network-enabled music player platform built on Rockbox technology. rockboxd.tsiry-sandratraina.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * * Copyright (C) 2010 Robert Bieber * * 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 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/
#include <QGraphicsSceneMouseEvent>#include <QPainter>#include <QDebug>
#include <cmath>
#include "rbmovable.h"
const double RBMovable::handleSize = 7;
RBMovable::RBMovable(QGraphicsItem* parent) : QGraphicsItem(parent), dragMode(None){ setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);}
RBMovable::~RBMovable(){}
void RBMovable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ if(isSelected()) { painter->setBrush(Qt::NoBrush); QPen pen; pen.setStyle(Qt::DashLine); pen.setColor(Qt::green); painter->setPen(pen); painter->drawRect(boundingRect());
painter->fillRect(topLeftHandle(), Qt::green); painter->fillRect(topRightHandle(), Qt::green); painter->fillRect(bottomLeftHandle(), Qt::green); painter->fillRect(bottomRightHandle(), Qt::green); } (void)option; (void)widget;}
QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value){ if(change == ItemPositionChange) { QPointF pos = value.toPointF(); QRectF bound = parentItem()->boundingRect();
pos.setX(qMax(0., floor(pos.x()))); pos.setX(qMin(pos.x(), bound.width() - boundingRect().width()));
pos.setY(qMax(0., floor(pos.y()))); pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
return pos; }
return QGraphicsItem::itemChange(change, value);}
void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event){ if(!isSelected()) { QGraphicsItem::mousePressEvent(event); return; }
if(topLeftHandle().contains(event->pos())) { dragStartClick = event->pos() + pos(); dragStartPos = pos(); dragStartSize = boundingRect();
dWidthMin = -1. * pos().x(); dWidthMax = boundingRect().width() - childrenBoundingRect().right();
dHeightMin = -1. * pos().y(); dHeightMax = boundingRect().height() - childrenBoundingRect().bottom();
dragMode = TopLeft; } else if(topRightHandle().contains(event->pos())) { dragStartClick = event->pos() + pos(); dragStartPos = pos(); dragStartSize = boundingRect();
dWidthMin = childrenBoundingRect().width() - boundingRect().width(); dWidthMin = qMax(dWidthMin, -1. * size.width()); dWidthMax = parentItem()->boundingRect().width() - boundingRect().width() - pos().x();
dHeightMin = -1. * pos().y(); dHeightMax = boundingRect().height() - childrenBoundingRect().bottom(); dHeightMax = qMin(dHeightMax, boundingRect().height());
dragMode = TopRight; } else if(bottomLeftHandle().contains(event->pos())) { dragStartClick = event->pos() + pos(); dragStartPos = pos(); dragStartSize = boundingRect();
dWidthMin = -1. * pos().x(); dWidthMax = boundingRect().width() - childrenBoundingRect().right(); dWidthMax = qMin(dWidthMax, size.width());
dHeightMin = -1. * (boundingRect().height() - childrenBoundingRect().bottom()); dHeightMin = qMax(dHeightMin, -1. * boundingRect().height());
dragMode = BottomLeft; } else if(bottomRightHandle().contains(event->pos())) { dragStartClick = event->pos() + pos(); dragStartPos = pos(); dragStartSize = boundingRect();
dWidthMin = -1. * (boundingRect().width() - childrenBoundingRect().right()); dWidthMin = qMax(dWidthMin, -1. * boundingRect().width()); dWidthMax = parentItem()->boundingRect().width() - boundingRect().width() - pos().x();
dHeightMin = -1. * (boundingRect().height() - childrenBoundingRect().bottom()); dHeightMin = qMax(dHeightMin, -1. * boundingRect().height()); dHeightMax = parentItem()->boundingRect().height() - boundingRect().height() - pos().y();
dragMode = BottomRight; } else { QGraphicsItem::mousePressEvent(event); }}
void RBMovable::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
QPointF absPos; QPointF dPos; QPointF dMouse; switch(dragMode) { case None: QGraphicsItem::mouseMoveEvent(event); break;
case TopLeft: /* Dragging from the top left corner */ absPos = event->pos() + pos(); dMouse = QPointF(floor(absPos.x() - dragStartClick.x()), floor(absPos.y() - dragStartClick.y()));
dPos.setX(qMin(dMouse.x(), dWidthMax)); dPos.setX(qMax(dPos.x(), dWidthMin));
dPos.setY(qMin(dMouse.y(), dHeightMax)); dPos.setY(qMax(dPos.y(), dHeightMin));
prepareGeometryChange();
setPos(dragStartPos + dPos);
size.setWidth(dragStartSize.width() - dPos.x()); size.setHeight(dragStartSize.height() - dPos.y());
break;
case TopRight: /* Dragging from the top right corner */ absPos = event->pos() + pos(); dMouse = QPointF(floor(absPos.x() - dragStartClick.x()), floor(absPos.y() - dragStartClick.y()));
dPos.setX(qMin(dMouse.x(), dWidthMax)); dPos.setX(qMax(dPos.x(), dWidthMin));
dPos.setY(qMin(dMouse.y(), dHeightMax)); dPos.setY(qMax(dPos.y(), dHeightMin));
prepareGeometryChange();
setPos(dragStartPos.x(), dragStartPos.y() + dPos.y());
size.setWidth(dragStartSize.width() + dPos.x()); size.setHeight(dragStartSize.height() - dPos.y());
break;
case BottomLeft: /* Dragging from the bottom left corner */ absPos = event->pos() + pos(); dMouse = QPointF(floor(absPos.x() - dragStartClick.x()), floor(absPos.y() - dragStartClick.y()));
dPos.setX(qMin(dMouse.x(), dWidthMax)); dPos.setX(qMax(dPos.x(), dWidthMin));
dPos.setY(qMin(dMouse.y(), dHeightMax)); dPos.setY(qMax(dPos.y(), dHeightMin));
prepareGeometryChange(); setPos(dragStartPos.x() + dPos.x(), dragStartPos.y()); size.setHeight(dragStartSize.height() + dPos.y()); size.setWidth(dragStartSize.width() - dPos.x());
break;
case BottomRight: /* Dragging from the bottom right corner */ absPos = event->pos() + pos(); dMouse = QPointF(floor(absPos.x() - dragStartClick.x()), floor(absPos.y() - dragStartClick.y()));
dPos.setX(qMin(dMouse.x(), dWidthMax)); dPos.setX(qMax(dPos.x(), dWidthMin));
dPos.setY(qMin(dMouse.y(), dHeightMax)); dPos.setY(qMax(dPos.y(), dHeightMin));
prepareGeometryChange();
size.setWidth(dragStartSize.width() + dPos.x()); size.setHeight(dragStartSize.height() + dPos.y());
break; }}
void RBMovable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::mouseReleaseEvent(event);
dragMode = None;
if(isSelected()) { saveGeometry(); }}
QRectF RBMovable::topLeftHandle(){ QRectF bounds = boundingRect(); double width = qMin(bounds.width() / 2. - .5, handleSize); double height = qMin(bounds.height() / 2. - .5, handleSize); double size = qMin(width, height);
return QRectF(0, 0, size, size);}
QRectF RBMovable::topRightHandle(){ QRectF bounds = boundingRect(); double width = qMin(bounds.width() / 2. - .5, handleSize); double height = qMin(bounds.height() / 2. - .5, handleSize); double size = qMin(width, height);
return QRectF(bounds.width() - size, 0, size, size);}
QRectF RBMovable::bottomLeftHandle(){ QRectF bounds = boundingRect(); double width = qMin(bounds.width() / 2. - .5, handleSize); double height = qMin(bounds.height() / 2. - .5, handleSize); double size = qMin(width, height);
return QRectF(0, bounds.height() - size, size, size);}
QRectF RBMovable::bottomRightHandle(){ QRectF bounds = boundingRect(); double width = qMin(bounds.width() / 2. - .5, handleSize); double height = qMin(bounds.height() / 2. - .5, handleSize); double size = qMin(width, height);
return QRectF(bounds.width() - size, bounds.height() - size, size, size);}