QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / plugins / qmltooling / qmldbg_qtquick2 / highlight.cpp
index d014dd4..a8fcace 100644 (file)
 
 #include "highlight.h"
 
+#include <QtCore/QTimer>
 #include <QtGui/QPainter>
-#include <QtQuick/QQuickCanvas>
+#include <QtGui/QStaticText>
+#include <QtQuick/QQuickWindow>
 
 namespace QmlJSDebugger {
 namespace QtQuick2 {
 
+Highlight::Highlight(QQuickItem *parent) : QQuickPaintedItem(parent)
+{
+    initRenderDetails();
+}
+
 Highlight::Highlight(QQuickItem *item, QQuickItem *parent)
     : QQuickPaintedItem(parent)
 {
+    initRenderDetails();
     setItem(item);
 }
 
+void Highlight::initRenderDetails()
+{
+    setRenderTarget(QQuickPaintedItem::FramebufferObject);
+    setPerformanceHint(QQuickPaintedItem::FastFBOResizing, true);
+}
+
 void Highlight::setItem(QQuickItem *item)
 {
     if (m_item)
@@ -67,7 +81,7 @@ void Highlight::setItem(QQuickItem *item)
         connect(item, SIGNAL(transformOriginChanged(TransformOrigin)),
                 SLOT(adjust()));
     }
-    QQuickCanvas *view = item->canvas();
+    QQuickWindow *view = item->window();
     QQuickItem * rootItem = view->rootItem();
     if (rootItem) {
         connect(rootItem, SIGNAL(xChanged()), SLOT(adjust()));
@@ -79,6 +93,7 @@ void Highlight::setItem(QQuickItem *item)
                 SLOT(adjust()));
     }
     m_item = item;
+    setContentsSize(view->size());
     adjust();
 }
 
@@ -95,7 +110,7 @@ void Highlight::adjust()
     setSize(QSizeF(m_item->width(), m_item->height()));
     qreal scaleFactor = 1;
     QPointF originOffset = QPointF(0,0);
-    QQuickCanvas *view = m_item->canvas();
+    QQuickWindow *view = m_item->window();
     if (view->rootItem()) {
         scaleFactor = view->rootItem()->scale();
         originOffset -= view->rootItem()->pos();
@@ -105,7 +120,6 @@ void Highlight::adjust()
     // takes care of it.
     parentItem()->setScale(1/scaleFactor);
     setPos(originOffset);
-    setContentsSize(view->size());
     update();
 }
 
@@ -123,25 +137,68 @@ void HoverHighlight::paint(QPainter *painter)
 }
 
 
+SelectionHighlight::SelectionHighlight(const QString &name, QQuickItem *item, QQuickItem *parent)
+    : Highlight(item, parent),
+      m_name(name),
+      m_nameDisplayActive(false)
+{
+}
+
 void SelectionHighlight::paint(QPainter *painter)
 {
     if (!item())
         return;
-
     painter->save();
+    painter->fillRect(QRectF(0,0,contentsSize().width(), contentsSize().height()),
+                      QColor(0,0,0,127));
     painter->setTransform(transform());
-    if (item()->height() >= 10 && item()->width() >= 10) {
-        QColor colorHighlight = Qt::green;
-        painter->fillRect(QRectF(0, 0, item()->width(), 5), colorHighlight);
-        painter->fillRect(QRectF(0, item()->height()-5, item()->width(), 5), colorHighlight);
-        painter->fillRect(QRectF(0, 5, 5, item()->height() - 10), colorHighlight);
-        painter->fillRect(QRectF(item()->width()-5, 5, 5, item()->height() - 10), colorHighlight);
-    }
-    painter->setPen(QPen(QColor(0, 22, 159)));
-    painter->drawRect(QRect(1, 1, item()->width() - 3, item()->height() - 3));
-    painter->setPen(QColor(158, 199, 255));
-    painter->drawRect(QRect(0, 0, item()->width() - 1, item()->height() - 1));
+    // Setting the composition mode such that the transparency will
+    // be erased as per the selected item.
+    painter->setCompositionMode(QPainter::CompositionMode_Clear);
+    painter->fillRect(0, 0, item()->width(), item()->height(), Qt::black);
     painter->restore();
+
+    // Use the painter with the original transform and not with the
+    // item's transform for display of name.
+    if (!m_nameDisplayActive)
+        return;
+
+    // Paint the text in gray background if display name is active..
+    QRect textRect = painter->boundingRect(QRect(10, contentsSize().height() - 10 ,
+                                 contentsSize().width() - 20, contentsSize().height()),
+                                 Qt::AlignCenter | Qt::ElideRight, m_name);
+
+    qreal xPosition = m_displayPoint.x();
+    if (xPosition + textRect.width() > contentsSize().width())
+        xPosition = contentsSize().width() - textRect.width();
+    if (xPosition < 0) {
+        xPosition = 0;
+        textRect.setWidth(contentsSize().width());
+    }
+    qreal yPosition = m_displayPoint.y() - textRect.height() - 20;
+    if (yPosition < 50 )
+        yPosition = 50;
+
+    painter->fillRect(QRectF(xPosition - 5, yPosition - 5,
+                      textRect.width() + 10, textRect.height() + 10), Qt::gray);
+    painter->drawRect(QRectF(xPosition - 5, yPosition - 5,
+                      textRect.width() + 10, textRect.height() + 10));
+
+    painter->drawStaticText(xPosition, yPosition, QStaticText(m_name));
+}
+
+void SelectionHighlight::showName(const QPointF &displayPoint)
+{
+    m_displayPoint = displayPoint;
+    m_nameDisplayActive = true;
+    QTimer::singleShot(1500, this, SLOT(disableNameDisplay()));
+    update();
+}
+
+void SelectionHighlight::disableNameDisplay()
+{
+    m_nameDisplayActive = false;
+    update();
 }
 
 } // namespace QtQuick2