forked from qt-creator/qt-creator
DeclarativeObserver: Don't fade in the highlight edge
It feels more responsive when the highlight is immediately visible. Change-Id: Ie3dd0693ecc38f33b001c86970b220b45b37fdfc Reviewed-by: Kai Koehne (cherry picked from Qt 4.8 commit 0b4e028ec294992df01430bdf978982835c7df5c) Reviewed-on: http://codereview.qt.nokia.com/248 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
committed by
Kai Koehne
parent
335f6ad0f7
commit
92298a5c43
@@ -42,10 +42,6 @@
|
|||||||
|
|
||||||
namespace QmlJSDebugger {
|
namespace QmlJSDebugger {
|
||||||
|
|
||||||
const qreal AnimDelta = 0.025f;
|
|
||||||
const int AnimInterval = 30;
|
|
||||||
const int AnimFrames = 10;
|
|
||||||
|
|
||||||
BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem,
|
BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@@ -83,12 +79,8 @@ int BoundingBoxPolygonItem::type() const
|
|||||||
|
|
||||||
BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewInspector *view) :
|
BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewInspector *view) :
|
||||||
LiveLayerItem(view->declarativeView()->scene()),
|
LiveLayerItem(view->declarativeView()->scene()),
|
||||||
m_view(view),
|
m_view(view)
|
||||||
m_animFrame(0)
|
|
||||||
{
|
{
|
||||||
m_animTimer = new QTimer(this);
|
|
||||||
m_animTimer->setInterval(AnimInterval);
|
|
||||||
connect(m_animTimer, SIGNAL(timeout()), SLOT(animTimeout()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingRectHighlighter::~BoundingRectHighlighter()
|
BoundingRectHighlighter::~BoundingRectHighlighter()
|
||||||
@@ -96,37 +88,17 @@ BoundingRectHighlighter::~BoundingRectHighlighter()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoundingRectHighlighter::animTimeout()
|
|
||||||
{
|
|
||||||
++m_animFrame;
|
|
||||||
if (m_animFrame == AnimFrames) {
|
|
||||||
m_animTimer->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal alpha = m_animFrame / float(AnimFrames);
|
|
||||||
|
|
||||||
foreach (BoundingBox *box, m_boxes) {
|
|
||||||
box->highlightPolygonEdge->setOpacity(alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoundingRectHighlighter::clear()
|
void BoundingRectHighlighter::clear()
|
||||||
{
|
{
|
||||||
if (m_boxes.length()) {
|
foreach (BoundingBox *box, m_boxes)
|
||||||
m_animTimer->stop();
|
freeBoundingBox(box);
|
||||||
|
|
||||||
foreach (BoundingBox *box, m_boxes) {
|
|
||||||
freeBoundingBox(box);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox *BoundingRectHighlighter::boxFor(QGraphicsObject *item) const
|
BoundingBox *BoundingRectHighlighter::boxFor(QGraphicsObject *item) const
|
||||||
{
|
{
|
||||||
foreach (BoundingBox *box, m_boxes) {
|
foreach (BoundingBox *box, m_boxes) {
|
||||||
if (box->highlightedObject.data() == item) {
|
if (box->highlightedObject.data() == item)
|
||||||
return box;
|
return box;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -136,15 +108,11 @@ void BoundingRectHighlighter::highlight(QList<QGraphicsObject*> items)
|
|||||||
if (items.isEmpty())
|
if (items.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool animate = false;
|
|
||||||
|
|
||||||
QList<BoundingBox *> newBoxes;
|
QList<BoundingBox *> newBoxes;
|
||||||
foreach (QGraphicsObject *itemToHighlight, items) {
|
foreach (QGraphicsObject *itemToHighlight, items) {
|
||||||
BoundingBox *box = boxFor(itemToHighlight);
|
BoundingBox *box = boxFor(itemToHighlight);
|
||||||
if (!box) {
|
if (!box)
|
||||||
box = createBoundingBox(itemToHighlight);
|
box = createBoundingBox(itemToHighlight);
|
||||||
animate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
newBoxes << box;
|
newBoxes << box;
|
||||||
}
|
}
|
||||||
@@ -155,7 +123,7 @@ void BoundingRectHighlighter::highlight(QList<QGraphicsObject*> items)
|
|||||||
m_boxes << newBoxes;
|
m_boxes << newBoxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
highlightAll(animate);
|
highlightAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight)
|
void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight)
|
||||||
@@ -163,17 +131,14 @@ void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight)
|
|||||||
if (!itemToHighlight)
|
if (!itemToHighlight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool animate = false;
|
|
||||||
|
|
||||||
BoundingBox *box = boxFor(itemToHighlight);
|
BoundingBox *box = boxFor(itemToHighlight);
|
||||||
if (!box) {
|
if (!box) {
|
||||||
box = createBoundingBox(itemToHighlight);
|
box = createBoundingBox(itemToHighlight);
|
||||||
m_boxes << box;
|
m_boxes << box;
|
||||||
animate = true;
|
|
||||||
qSort(m_boxes);
|
qSort(m_boxes);
|
||||||
}
|
}
|
||||||
|
|
||||||
highlightAll(animate);
|
highlightAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight)
|
BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight)
|
||||||
@@ -234,7 +199,7 @@ void BoundingRectHighlighter::itemDestroyed(QObject *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoundingRectHighlighter::highlightAll(bool animate)
|
void BoundingRectHighlighter::highlightAll()
|
||||||
{
|
{
|
||||||
foreach (BoundingBox *box, m_boxes) {
|
foreach (BoundingBox *box, m_boxes) {
|
||||||
if (box && box->highlightedObject.isNull()) {
|
if (box && box->highlightedObject.isNull()) {
|
||||||
@@ -252,21 +217,13 @@ void BoundingRectHighlighter::highlightAll(bool animate)
|
|||||||
|
|
||||||
box->highlightPolygon->setPolygon(QPolygonF(bboxRect));
|
box->highlightPolygon->setPolygon(QPolygonF(bboxRect));
|
||||||
box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect));
|
box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect));
|
||||||
|
|
||||||
if (animate)
|
|
||||||
box->highlightPolygonEdge->setOpacity(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (animate) {
|
|
||||||
m_animFrame = 0;
|
|
||||||
m_animTimer->start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoundingRectHighlighter::refresh()
|
void BoundingRectHighlighter::refresh()
|
||||||
{
|
{
|
||||||
if (!m_boxes.isEmpty())
|
if (!m_boxes.isEmpty())
|
||||||
highlightAll(true);
|
highlightAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -61,12 +61,11 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
void animTimeout();
|
|
||||||
void itemDestroyed(QObject *);
|
void itemDestroyed(QObject *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoundingBox *boxFor(QGraphicsObject *item) const;
|
BoundingBox *boxFor(QGraphicsObject *item) const;
|
||||||
void highlightAll(bool animate);
|
void highlightAll();
|
||||||
BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight);
|
BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight);
|
||||||
void removeBoundingBox(BoundingBox *box);
|
void removeBoundingBox(BoundingBox *box);
|
||||||
void freeBoundingBox(BoundingBox *box);
|
void freeBoundingBox(BoundingBox *box);
|
||||||
@@ -77,10 +76,6 @@ private:
|
|||||||
QDeclarativeViewInspector *m_view;
|
QDeclarativeViewInspector *m_view;
|
||||||
QList<BoundingBox* > m_boxes;
|
QList<BoundingBox* > m_boxes;
|
||||||
QList<BoundingBox* > m_freeBoxes;
|
QList<BoundingBox* > m_freeBoxes;
|
||||||
QTimer *m_animTimer;
|
|
||||||
qreal m_animScale;
|
|
||||||
int m_animFrame;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoundingBox : public QObject
|
class BoundingBox : public QObject
|
||||||
|
Reference in New Issue
Block a user