forked from len0rd/rockbox
Theme Editor: Implemented resizing in RBMovable subclasses. Implementation is still somewhat crash-prone, but mostly works at this point
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27729 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4b49ef2ade
commit
10b9e3b024
10 changed files with 249 additions and 38 deletions
|
@ -28,23 +28,17 @@
|
||||||
RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
|
RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
|
||||||
int maxHeight, int artWidth, int artHeight,
|
int maxHeight, int artWidth, int artHeight,
|
||||||
ParseTreeNode* node, char hAlign, char vAlign)
|
ParseTreeNode* node, char hAlign, char vAlign)
|
||||||
: RBMovable(parent), size(0, 0, maxWidth,
|
: RBMovable(parent),artWidth(artWidth),
|
||||||
maxHeight),
|
artHeight(artHeight), hAlign(hAlign), vAlign(vAlign),
|
||||||
artWidth(artWidth), artHeight(artHeight),
|
|
||||||
hAlign(hAlign), vAlign(vAlign),
|
|
||||||
texture(":/render/albumart.png"), node(node)
|
texture(":/render/albumart.png"), node(node)
|
||||||
{
|
{
|
||||||
|
size = QRectF(0, 0, maxWidth, maxHeight);
|
||||||
setFlag(ItemSendsGeometryChanges, false);
|
setFlag(ItemSendsGeometryChanges, false);
|
||||||
|
|
||||||
setPos(x, y);
|
setPos(x, y);
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBAlbumArt::boundingRect() const
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RBAlbumArt::paint(QPainter *painter,
|
void RBAlbumArt::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,6 @@ public:
|
||||||
int artWidth, int artHeight, ParseTreeNode* node,
|
int artWidth, int artHeight, ParseTreeNode* node,
|
||||||
char hAlign = 'c', char vAlign = 'c');
|
char hAlign = 'c', char vAlign = 'c');
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
|
@ -48,7 +47,6 @@ protected:
|
||||||
void saveGeometry();
|
void saveGeometry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF size;
|
|
||||||
int artWidth;
|
int artWidth;
|
||||||
int artHeight;
|
int artHeight;
|
||||||
char hAlign;
|
char hAlign;
|
||||||
|
|
|
@ -79,11 +79,6 @@ RBImage::~RBImage()
|
||||||
delete image;
|
delete image;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBImage::boundingRect() const
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,6 @@ public:
|
||||||
RBImage(const RBImage& other, QGraphicsItem* parent);
|
RBImage(const RBImage& other, QGraphicsItem* parent);
|
||||||
virtual ~RBImage();
|
virtual ~RBImage();
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
|
@ -62,8 +61,6 @@ private:
|
||||||
int tiles;
|
int tiles;
|
||||||
int currentTile;
|
int currentTile;
|
||||||
|
|
||||||
QRectF size;
|
|
||||||
|
|
||||||
ParseTreeNode* node;
|
ParseTreeNode* node;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,13 +19,16 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "rbmovable.h"
|
#include "rbmovable.h"
|
||||||
|
|
||||||
|
const double RBMovable::handleSize = 7;
|
||||||
|
|
||||||
RBMovable::RBMovable(QGraphicsItem* parent)
|
RBMovable::RBMovable(QGraphicsItem* parent)
|
||||||
: QGraphicsItem(parent), geomChanged(false)
|
: QGraphicsItem(parent), dragMode(None)
|
||||||
{
|
{
|
||||||
setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);
|
setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +48,11 @@ void RBMovable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
pen.setColor(Qt::green);
|
pen.setColor(Qt::green);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(boundingRect());
|
painter->drawRect(boundingRect());
|
||||||
|
|
||||||
|
painter->fillRect(topLeftHandle(), Qt::green);
|
||||||
|
painter->fillRect(topRightHandle(), Qt::green);
|
||||||
|
painter->fillRect(bottomLeftHandle(), Qt::green);
|
||||||
|
painter->fillRect(bottomRightHandle(), Qt::green);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +69,6 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
pos.setY(qMax(0., pos.y()));
|
pos.setY(qMax(0., pos.y()));
|
||||||
pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
|
pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
|
||||||
|
|
||||||
geomChanged = true;
|
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@ -71,15 +78,223 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
|
|
||||||
void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if(!isSelected())
|
||||||
|
{
|
||||||
QGraphicsItem::mousePressEvent(event);
|
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 = absPos - dragStartClick;
|
||||||
|
|
||||||
|
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 = absPos - dragStartClick;
|
||||||
|
|
||||||
|
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 = absPos - dragStartClick;
|
||||||
|
|
||||||
|
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 = absPos - dragStartClick;
|
||||||
|
|
||||||
|
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)
|
void RBMovable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsItem::mouseReleaseEvent(event);
|
QGraphicsItem::mouseReleaseEvent(event);
|
||||||
|
|
||||||
|
dragMode = None;
|
||||||
|
|
||||||
if(isSelected())
|
if(isSelected())
|
||||||
{
|
{
|
||||||
saveGeometry();
|
saveGeometry();
|
||||||
geomChanged = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -42,15 +42,41 @@ public:
|
||||||
virtual void paint(QPainter *painter,
|
virtual void paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget);
|
const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
virtual QRectF boundingRect() const{ return size; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QVariant itemChange(GraphicsItemChange change,
|
virtual QVariant itemChange(GraphicsItemChange change,
|
||||||
const QVariant &value);
|
const QVariant &value);
|
||||||
/* Responsible for updating the parse tree */
|
/* Responsible for updating the parse tree */
|
||||||
virtual void saveGeometry() = 0;
|
virtual void saveGeometry() = 0;
|
||||||
|
|
||||||
bool geomChanged;
|
QRectF size;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const double handleSize;
|
||||||
|
|
||||||
|
QRectF topLeftHandle();
|
||||||
|
QRectF topRightHandle();
|
||||||
|
QRectF bottomLeftHandle();
|
||||||
|
QRectF bottomRightHandle();
|
||||||
|
|
||||||
|
enum{
|
||||||
|
None,
|
||||||
|
TopLeft,
|
||||||
|
TopRight,
|
||||||
|
BottomLeft,
|
||||||
|
BottomRight
|
||||||
|
} dragMode;
|
||||||
|
QPointF dragStartPos;
|
||||||
|
QRectF dragStartSize;
|
||||||
|
QPointF dragStartClick;
|
||||||
|
double dHeightMin;
|
||||||
|
double dHeightMax;
|
||||||
|
double dWidthMin;
|
||||||
|
double dWidthMax;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -103,11 +103,6 @@ RBProgressBar::~RBProgressBar()
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBProgressBar::boundingRect() const
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RBProgressBar::paint(QPainter *painter,
|
void RBProgressBar::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
|
|
|
@ -40,7 +40,6 @@ public:
|
||||||
ParseTreeNode* node, bool pv = 0);
|
ParseTreeNode* node, bool pv = 0);
|
||||||
virtual ~RBProgressBar();
|
virtual ~RBProgressBar();
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
|
@ -50,7 +49,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
QPixmap* bitmap;
|
QPixmap* bitmap;
|
||||||
QColor color;
|
QColor color;
|
||||||
QRectF size;
|
|
||||||
QRectF renderSize;
|
QRectF renderSize;
|
||||||
|
|
||||||
ParseTreeNode* node;
|
ParseTreeNode* node;
|
||||||
|
|
|
@ -161,11 +161,6 @@ QPainterPath RBViewport::shape() const
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBViewport::boundingRect() const
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RBViewport::paint(QPainter *painter,
|
void RBViewport::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,6 @@ public:
|
||||||
virtual ~RBViewport();
|
virtual ~RBViewport();
|
||||||
|
|
||||||
QPainterPath shape() const;
|
QPainterPath shape() const;
|
||||||
QRectF boundingRect() const;
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
|
@ -91,7 +90,6 @@ private:
|
||||||
void alignCenter();
|
void alignCenter();
|
||||||
void alignRight();
|
void alignRight();
|
||||||
|
|
||||||
QRectF size;
|
|
||||||
RBFont* font;
|
RBFont* font;
|
||||||
QColor foreground;
|
QColor foreground;
|
||||||
QColor background;
|
QColor background;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue