#include "sghighlight.h"
#include "sgviewinspector.h"
-#include <QtWidgets/QMenu>
#include <QtGui/QMouseEvent>
#include <QtDeclarative/QQuickView>
#include <QtDeclarative/QQuickItem>
if (QQuickItem *item = inspector()->topVisibleItemAt(event->pos()))
inspector()->setSelectedItems(QList<QQuickItem*>() << item);
} else if (event->button() == Qt::RightButton) {
- QList<QQuickItem*> items = inspector()->itemsAt(event->pos());
- createContextMenu(items, event->globalPos());
+ // todo: Show context menu
}
}
}
}
-void SGSelectionTool::createContextMenu(const QList<QQuickItem *> &items, QPoint pos)
-{
- QMenu contextMenu;
- connect(&contextMenu, SIGNAL(hovered(QAction*)),
- this, SLOT(contextMenuElementHovered(QAction*)));
-
- const QList<QQuickItem*> selectedItems = inspector()->selectedItems();
- int shortcutKey = Qt::Key_1;
-
- foreach (QQuickItem *item, items) {
- const QString title = inspector()->titleForItem(item);
- QAction *elementAction = contextMenu.addAction(title);
- elementAction->setData(QVariant::fromValue(item));
-
- connect(elementAction, SIGNAL(triggered()), this, SLOT(contextMenuElementSelected()));
-
- if (selectedItems.contains(item)) {
- QFont font = elementAction->font();
- font.setBold(true);
- elementAction->setFont(font);
- }
-
- if (shortcutKey <= Qt::Key_9) {
- elementAction->setShortcut(QKeySequence(shortcutKey));
- shortcutKey++;
- }
- }
-
- contextMenu.exec(pos);
-}
-
-void SGSelectionTool::contextMenuElementHovered(QAction *action)
-{
- if (QQuickItem *item = action->data().value<QQuickItem*>())
- m_hoverHighlight->setItem(item);
-}
-
-void SGSelectionTool::contextMenuElementSelected()
-{
- if (QQuickItem *item = static_cast<QAction*>(sender())->data().value<QQuickItem*>())
- inspector()->setSelectedItems(QList<QQuickItem*>() << item);
-}
-
SGViewInspector *SGSelectionTool::inspector() const
{
return static_cast<SGViewInspector*>(AbstractTool::inspector());
#include <QtCore/QList>
#include <QtCore/QPoint>
-QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QQuickItem)
namespace QmlJSDebugger {
void keyPressEvent(QKeyEvent *) {}
void keyReleaseEvent(QKeyEvent *) {}
-private slots:
- void contextMenuElementHovered(QAction *action);
- void contextMenuElementSelected();
-
private:
- void createContextMenu(const QList<QQuickItem*> &items, QPoint pos);
-
SGViewInspector *inspector() const;
SGHoverHighlight *m_hoverHighlight;