QmlDesigner: Adding a toolbar
* Icons are not the final ones. * I fixed a couple of glitches and cleaned up the code. - Action for copy and paste/delete were not properly updated - Delete had no icon - Using std::function for action predicates and operations - The context menu has no icons. This way we avoid having to define 2 icons. Change-Id: Ic23cbc78ba299c19e07e8de775eb813aae55db9b Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
@@ -39,7 +39,7 @@ AbstractActionGroup::AbstractActionGroup(const QString &displayName) :
|
||||
|
||||
ActionInterface::Type AbstractActionGroup::type() const
|
||||
{
|
||||
return ActionInterface::Menu;
|
||||
return ActionInterface::ContextMenu;
|
||||
}
|
||||
|
||||
QAction *AbstractActionGroup::action() const
|
||||
|
@@ -38,7 +38,8 @@ class QMLDESIGNERCORE_EXPORT ActionInterface
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
Menu,
|
||||
ContextMenu,
|
||||
ContextMenuAction,
|
||||
Action
|
||||
};
|
||||
|
||||
|
@@ -35,3 +35,6 @@ HEADERS += qmldesignericonprovider.h
|
||||
FORMS += \
|
||||
$$PWD/addsignalhandlerdialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
$$PWD/componentcore.qrc
|
||||
|
||||
|
@@ -0,0 +1,13 @@
|
||||
<RCC>
|
||||
<qresource prefix="/qmldesigner/icon/designeractions">
|
||||
<file>images/cancel.png</file>
|
||||
<file>images/column.png</file>
|
||||
<file>images/fill.png</file>
|
||||
<file>images/grid.png</file>
|
||||
<file>images/lower.png</file>
|
||||
<file>images/move.png</file>
|
||||
<file>images/raise.png</file>
|
||||
<file>images/row.png</file>
|
||||
<file>images/size.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
@@ -40,6 +40,32 @@ const char anchorsCategory[] = "Anchors";
|
||||
const char positionCategory[] = "Position";
|
||||
const char layoutCategory[] = "Layout";
|
||||
|
||||
const char toFrontCommandId[] = "ToFront";
|
||||
const char toBackCommandId[] = "ToBack";
|
||||
const char raiseCommandId[] = "Raise";
|
||||
const char lowerCommandId[] = "Lower";
|
||||
const char resetZCommandId[] = "ResetZ";
|
||||
const char resetSizeCommandId[] = "ResetSize";
|
||||
const char resetPositionCommandId[] = "ResetPosition";
|
||||
const char visiblityCommandId[] = "ToggleVisiblity";
|
||||
const char anchorsFillCommandId[] = "AnchorsFill";
|
||||
const char anchorsResetCommandId[] = "AnchorsReset";
|
||||
const char removePositionerCommandId[] = "RemovePositioner";
|
||||
const char layoutRowPositionerCommandId[] = "LayoutRowPositioner";
|
||||
const char layoutColumnPositionerCommandId[] = "LayoutColumnPositioner";
|
||||
const char layoutGridPositionerCommandId[] = "LayoutGridPositioner";
|
||||
const char layoutFlowPositionerCommandId[] = "LayoutFlowPositioner";
|
||||
const char removeLayoutCommandId[] = "RemoveLayout";
|
||||
const char layoutRowLayoutCommandId[] = "LayoutRowLayout";
|
||||
const char layoutColumnLayoutCommandId[] = "LayoutColumnLayout";
|
||||
const char layoutGridLayoutCommandId[] = "LayoutGridLayout";
|
||||
const char layoutFillWidthCommandId[] = "LayoutFillWidth";
|
||||
const char layoutFillHeightCommandId[] = "LayoutFillHeight";
|
||||
const char goIntoComponentCommandId[] = "GoIntoComponent";
|
||||
const char goToImplementationCommandId[] = "GoToImplementation";
|
||||
const char addSignalHandlerCommandId[] = "AddSignalHandler";
|
||||
const char moveToComponentCommandId[] = "MoveToComponent";
|
||||
|
||||
const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection");
|
||||
const char stackCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Stack (z)");
|
||||
const char editCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit");
|
||||
@@ -73,7 +99,7 @@ const char resetPositionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMen
|
||||
const char goIntoComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Go into Component");
|
||||
const char goToImplementationDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Go to Implementation");
|
||||
const char addSignalHandlerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add New Signal Handler");
|
||||
const char moveToComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Move to Component");
|
||||
const char moveToComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Move to Component into separate file");
|
||||
|
||||
const char setIdDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Set Id");
|
||||
|
||||
@@ -96,6 +122,19 @@ const char layoutGridLayoutDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContext
|
||||
const char layoutFillWidthDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill Width");
|
||||
const char layoutFillHeightDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill Height");
|
||||
|
||||
const char raiseToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Raise selected item.");
|
||||
const char lowerToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Lower selected item.");
|
||||
|
||||
const char resetSizeToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset size and use implcit size.");
|
||||
const char resetPositionTooltip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset position and use implicit position.");
|
||||
|
||||
const char anchorsFillToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill selected item to parent. ");
|
||||
const char anchorsResetToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset achors for selected item.");
|
||||
|
||||
const char layoutColumnLayoutToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout selected items in ColumnLayout.");
|
||||
const char layoutRowLayoutToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout selected items in RowLayout.");
|
||||
const char layoutGridLayoutToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout selected items in GridLayout.");
|
||||
|
||||
|
||||
const int priorityFirst = 220;
|
||||
const int prioritySelectionCategory = 200;
|
||||
|
@@ -28,10 +28,17 @@
|
||||
#include <nodeproperty.h>
|
||||
#include <nodemetainfo.h>
|
||||
#include "designeractionmanagerview.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
|
||||
#include <documentmanager.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
static inline QString captionForModelNode(const ModelNode &modelNode)
|
||||
@@ -47,20 +54,89 @@ static inline bool contains(const QmlItemNode &node, const QPointF &position)
|
||||
return node.isValid() && node.instanceSceneTransform().mapRect(node.instanceBoundingRect()).contains(position);
|
||||
}
|
||||
|
||||
AbstractView *DesignerActionManager::view()
|
||||
DesignerActionManagerView *DesignerActionManager::view()
|
||||
{
|
||||
return m_designerActionManagerView;
|
||||
}
|
||||
|
||||
class VisiblityModelNodeAction : public ModelNodeAction
|
||||
DesignerActionToolBar *DesignerActionManager::createToolBar(QWidget *parent) const
|
||||
{
|
||||
DesignerActionToolBar *toolBar = new DesignerActionToolBar(parent);
|
||||
|
||||
QList<ActionInterface* > categories = Utils::filtered(designerActions(),
|
||||
[](ActionInterface *action) { return action->type() == ActionInterface::ContextMenu; });
|
||||
|
||||
Utils::sort(categories, [](ActionInterface *l, ActionInterface *r) {
|
||||
return l->priority() > r->priority();
|
||||
});
|
||||
|
||||
for (auto *categoryAction : categories) {
|
||||
QList<ActionInterface* > actions = Utils::filtered(designerActions(), [categoryAction](ActionInterface *action) {
|
||||
return action->category() == categoryAction->menuId();
|
||||
});
|
||||
|
||||
Utils::sort(actions, [](ActionInterface *l, ActionInterface *r) {
|
||||
return l->priority() > r->priority();
|
||||
});
|
||||
|
||||
bool addSeparator = false;
|
||||
bool lastWasSeparator = false;
|
||||
|
||||
for (auto *action : actions) {
|
||||
if (action->type() == ActionInterface::Action
|
||||
&& action->action()
|
||||
&& !action->action()->icon().isNull()) {
|
||||
toolBar->registerAction(action);
|
||||
addSeparator = true;
|
||||
lastWasSeparator = false;
|
||||
} else if (addSeparator && action->action()->isSeparator()) {
|
||||
toolBar->registerAction(action);
|
||||
lastWasSeparator = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (addSeparator && !lastWasSeparator) {
|
||||
toolBar->addSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
return toolBar;
|
||||
}
|
||||
|
||||
void DesignerActionManager::polishActions() const
|
||||
{
|
||||
QList<ActionInterface* > actions = Utils::filtered(designerActions(),
|
||||
[](ActionInterface *action) { return action->type() != ActionInterface::ContextMenu; });
|
||||
|
||||
Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR);
|
||||
|
||||
for (auto *action : actions) {
|
||||
if (!action->menuId().isEmpty()) {
|
||||
const QString id =
|
||||
QString("QmlDesigner.FormEditor.%1.%2").arg(QString::fromLatin1(action->category())).arg(QString::fromLatin1(action->menuId()));
|
||||
|
||||
Core::Command *cmd = Core::ActionManager::registerAction(action->action(), id.toLatin1().constData(), qmlDesignerFormEditorContext);
|
||||
|
||||
cmd->setDefaultKeySequence(action->action()->shortcut());
|
||||
cmd->setDescription(action->action()->toolTip());
|
||||
|
||||
action->action()->setToolTip(cmd->action()->toolTip());
|
||||
action->action()->setShortcut(cmd->action()->shortcut());
|
||||
action->action()->setShortcutContext(Qt::WidgetShortcut); //Hack to avoid conflicting shortcuts. We use the Core::Command for the shortcut.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VisiblityModelNodeAction : public ModelNodeContextMenuAction
|
||||
{
|
||||
public:
|
||||
VisiblityModelNodeAction(const QString &description, const QByteArray &category, int priority,
|
||||
ModelNodeOperations::SelectionAction action,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
ModelNodeAction(description, category, priority, action, enabled, visibility)
|
||||
VisiblityModelNodeAction(const QByteArray &id, const QString &description, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation action,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
ModelNodeContextMenuAction(id, description, category, key, priority, action, enabled, visibility)
|
||||
{}
|
||||
|
||||
virtual void updateContext()
|
||||
{
|
||||
defaultAction()->setSelectionContext(selectionContext());
|
||||
@@ -78,14 +154,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FillLayoutModelNodeAction : public ModelNodeAction
|
||||
class FillLayoutModelNodeAction : public ModelNodeContextMenuAction
|
||||
{
|
||||
public:
|
||||
FillLayoutModelNodeAction(const QString &description, const QByteArray &category, int priority,
|
||||
ModelNodeOperations::SelectionAction action,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
ModelNodeAction(description, category, priority, action, enabled, visibility)
|
||||
FillLayoutModelNodeAction(const QByteArray &id, const QString &description, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation action,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
ModelNodeContextMenuAction(id, description, category, key, priority, action, enabled, visibility)
|
||||
{}
|
||||
virtual void updateContext()
|
||||
{
|
||||
@@ -115,11 +191,11 @@ protected:
|
||||
class FillWidthModelNodeAction : public FillLayoutModelNodeAction
|
||||
{
|
||||
public:
|
||||
FillWidthModelNodeAction(const QString &description, const QByteArray &category, int priority,
|
||||
ModelNodeOperations::SelectionAction action,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
FillLayoutModelNodeAction(description, category, priority, action, enabled, visibility)
|
||||
FillWidthModelNodeAction(const QByteArray &id, const QString &description, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation action,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
FillLayoutModelNodeAction(id, description, category, key, priority, action, enabled, visibility)
|
||||
{
|
||||
m_propertyName = "Layout.fillWidth";
|
||||
}
|
||||
@@ -128,11 +204,11 @@ public:
|
||||
class FillHeightModelNodeAction : public FillLayoutModelNodeAction
|
||||
{
|
||||
public:
|
||||
FillHeightModelNodeAction(const QString &description, const QByteArray &category, int priority,
|
||||
ModelNodeOperations::SelectionAction action,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
FillLayoutModelNodeAction(description, category, priority, action, enabled, visibility)
|
||||
FillHeightModelNodeAction(const QByteArray &id, const QString &description, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation action,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
FillLayoutModelNodeAction(id, description, category, key, priority, action, enabled, visibility)
|
||||
{
|
||||
m_propertyName = "Layout.fillHeight";
|
||||
}
|
||||
@@ -380,140 +456,293 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
using namespace ComponentCoreConstants;
|
||||
using namespace ModelNodeOperations;
|
||||
|
||||
addDesignerAction(new SelectionModelNodeAction(selectionCategoryDisplayName, selectionCategory, prioritySelectionCategory));
|
||||
addDesignerAction(new SelectionModelNodeAction(
|
||||
selectionCategoryDisplayName,
|
||||
selectionCategory,
|
||||
prioritySelectionCategory));
|
||||
|
||||
addDesignerAction(new ActionGroup(stackCategoryDisplayName, stackCategory, priorityStackCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(toFrontDisplayName, stackCategory, 200, &toFront, &singleSelection));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(toBackDisplayName, stackCategory, 180, &toBack, &singleSelection));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(raiseDisplayName, stackCategory, 160, &raise, &selectionNotEmpty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(lowerDisplayName, stackCategory, 140, &lower, &selectionNotEmpty));
|
||||
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(resetZDisplayName, stackCategory, 100, &resetZ, &selectionNotEmptyAndHasZProperty));
|
||||
addDesignerAction(new ActionGroup(
|
||||
stackCategoryDisplayName,
|
||||
stackCategory,
|
||||
priorityStackCategory,
|
||||
&selectionNotEmpty));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
toFrontCommandId,
|
||||
toFrontDisplayName,
|
||||
stackCategory,
|
||||
QKeySequence(),
|
||||
200,
|
||||
&toFront,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
toBackCommandId,
|
||||
toBackDisplayName,
|
||||
stackCategory,
|
||||
QKeySequence(),
|
||||
180,
|
||||
&toBack,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
raiseCommandId, raiseDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/lower.png").icon(),
|
||||
raiseToolTip,
|
||||
stackCategory,
|
||||
QKeySequence("Ctrl+Up"),
|
||||
160,
|
||||
&raise,
|
||||
&selectionNotEmpty));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
lowerCommandId,
|
||||
lowerDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/raise.png").icon(),
|
||||
lowerToolTip,
|
||||
stackCategory,
|
||||
QKeySequence("Ctrl+Down"),
|
||||
140,
|
||||
&lower,
|
||||
&selectionNotEmpty));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
resetZCommandId,
|
||||
resetZDisplayName,
|
||||
stackCategory,
|
||||
QKeySequence(),
|
||||
100,
|
||||
&resetZ,
|
||||
&selectionNotEmptyAndHasZProperty));
|
||||
|
||||
addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(resetPositionDisplayName, editCategory, 200, &resetPosition, &selectionNotEmptyAndHasXorYProperty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(resetSizeDisplayName, editCategory, 180, &resetSize, &selectionNotEmptyAndHasWidthOrHeightProperty));
|
||||
addDesignerAction(new VisiblityModelNodeAction
|
||||
(visibilityDisplayName, editCategory, 160, &setVisible, &singleSelectedItem));
|
||||
|
||||
addDesignerAction(new ActionGroup(anchorsCategoryDisplayName, anchorsCategory,
|
||||
priorityAnchorsCategory, &singleSelectionAndInBaseState));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(anchorsFillDisplayName, anchorsCategory, 200, &anchorsFill, &singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored));
|
||||
addDesignerAction(new SeperatorDesignerAction(editCategory, 220));
|
||||
|
||||
addDesignerAction(new ActionGroup(positionCategoryDisplayName, positionCategory,
|
||||
priorityPositionCategory, &positionOptionVisible));
|
||||
addDesignerAction(new ActionGroup(layoutCategoryDisplayName, layoutCategory,
|
||||
priorityLayoutCategory, &layoutOptionVisible));
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
resetPositionCommandId,
|
||||
resetPositionDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/move.png").icon(),
|
||||
resetPositionTooltip, editCategory, QKeySequence("Ctrl+d"),
|
||||
200,
|
||||
&resetPosition,
|
||||
&selectionNotEmptyAndHasXorYProperty));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(removePositionerDisplayName,
|
||||
positionCategory,
|
||||
210,
|
||||
&removePositioner,
|
||||
&isPositioner,
|
||||
&isPositioner));
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
resetSizeCommandId,
|
||||
resetSizeDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/size.png").icon(),
|
||||
resetSizeToolTip,
|
||||
editCategory,
|
||||
QKeySequence("Ctrl+f"),
|
||||
180,
|
||||
&resetSize,
|
||||
&selectionNotEmptyAndHasWidthOrHeightProperty));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutRowPositionerDisplayName,
|
||||
positionCategory,
|
||||
200,
|
||||
&layoutRowPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
addDesignerAction(new VisiblityModelNodeAction(
|
||||
visiblityCommandId,
|
||||
visibilityDisplayName,
|
||||
editCategory,
|
||||
QKeySequence("Ctrl+g"),
|
||||
160,
|
||||
&setVisible,
|
||||
&singleSelectedItem));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutColumnPositionerDisplayName,
|
||||
positionCategory,
|
||||
180,
|
||||
&layoutColumnPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
addDesignerAction(new ActionGroup(
|
||||
anchorsCategoryDisplayName,
|
||||
anchorsCategory,
|
||||
priorityAnchorsCategory,
|
||||
&singleSelectionAndInBaseState));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutGridPositionerDisplayName,
|
||||
positionCategory,
|
||||
160,
|
||||
&layoutGridPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
anchorsFillCommandId,
|
||||
anchorsFillDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/fill.png").icon(),
|
||||
anchorsFillToolTip,
|
||||
anchorsCategory,
|
||||
QKeySequence(QKeySequence("Ctrl+f")),
|
||||
200,
|
||||
&anchorsFill,
|
||||
&singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutFlowPositionerDisplayName,
|
||||
positionCategory,
|
||||
140,
|
||||
&layoutFlowPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
anchorsResetCommandId,
|
||||
anchorsResetDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/fill.png").icon(),
|
||||
anchorsResetToolTip,
|
||||
anchorsCategory,
|
||||
QKeySequence(QKeySequence("Ctrl+Shift+f")),
|
||||
180,
|
||||
&anchorsReset,
|
||||
&singleSelectionItemIsAnchored));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(layoutCategory, 120));
|
||||
addDesignerAction(new ActionGroup(
|
||||
positionCategoryDisplayName,
|
||||
positionCategory,
|
||||
priorityPositionCategory,
|
||||
&positionOptionVisible));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(removeLayoutDisplayName,
|
||||
layoutCategory,
|
||||
110,
|
||||
&removeLayout,
|
||||
&isLayout,
|
||||
&isLayout));
|
||||
addDesignerAction(new ActionGroup(
|
||||
layoutCategoryDisplayName,
|
||||
layoutCategory,
|
||||
priorityLayoutCategory,
|
||||
&layoutOptionVisible));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutRowLayoutDisplayName,
|
||||
layoutCategory,
|
||||
100,
|
||||
&layoutRowLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
removePositionerCommandId,
|
||||
removePositionerDisplayName,
|
||||
positionCategory,
|
||||
QKeySequence("Ctrl+Shift+p"),
|
||||
210,
|
||||
&removePositioner,
|
||||
&isPositioner,
|
||||
&isPositioner));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutColumnLayoutDisplayName,
|
||||
layoutCategory,
|
||||
80,
|
||||
&layoutColumnLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
layoutRowPositionerCommandId,
|
||||
layoutRowPositionerDisplayName,
|
||||
positionCategory,
|
||||
QKeySequence(),
|
||||
200,
|
||||
&layoutRowPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutGridLayoutDisplayName,
|
||||
layoutCategory,
|
||||
60,
|
||||
&layoutGridLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
layoutColumnPositionerCommandId,
|
||||
layoutColumnPositionerDisplayName,
|
||||
positionCategory,
|
||||
QKeySequence(),
|
||||
180,
|
||||
&layoutColumnPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
|
||||
addDesignerAction(new FillWidthModelNodeAction
|
||||
(layoutFillWidthDisplayName,
|
||||
layoutCategory,
|
||||
40,
|
||||
&setFillWidth,
|
||||
&singleSelectionAndInQtQuickLayout,
|
||||
&singleSelectionAndInQtQuickLayout));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
layoutGridPositionerCommandId,
|
||||
layoutGridPositionerDisplayName,
|
||||
positionCategory,
|
||||
QKeySequence(),
|
||||
160,
|
||||
&layoutGridPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
|
||||
addDesignerAction(new FillHeightModelNodeAction
|
||||
(layoutFillHeightDisplayName,
|
||||
layoutCategory,
|
||||
20,
|
||||
&setFillHeight,
|
||||
&singleSelectionAndInQtQuickLayout,
|
||||
&singleSelectionAndInQtQuickLayout));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
layoutFlowPositionerCommandId,
|
||||
layoutFlowPositionerDisplayName,
|
||||
positionCategory,
|
||||
QKeySequence("Ctrl+m"),
|
||||
140,
|
||||
&layoutFlowPositioner,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(layoutCategory, 120));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
removeLayoutCommandId,
|
||||
removeLayoutDisplayName,
|
||||
layoutCategory,
|
||||
QKeySequence("Ctrl+Shift+u"),
|
||||
110,
|
||||
&removeLayout,
|
||||
&isLayout,
|
||||
&isLayout));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
layoutRowLayoutCommandId,
|
||||
layoutRowLayoutDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/row.png").icon(),
|
||||
layoutRowLayoutToolTip,
|
||||
layoutCategory,
|
||||
QKeySequence("Ctrl+u"),
|
||||
100,
|
||||
&layoutRowLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
layoutColumnLayoutCommandId,
|
||||
layoutColumnLayoutDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/column.png").icon(),
|
||||
layoutColumnLayoutToolTip,
|
||||
layoutCategory,
|
||||
QKeySequence("Ctrl+i"),
|
||||
80,
|
||||
&layoutColumnLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
|
||||
addDesignerAction(new ModelNodeAction(
|
||||
layoutGridLayoutCommandId,
|
||||
layoutGridLayoutDisplayName,
|
||||
Utils::Icon(":/qmldesigner/icon/designeractions/images/grid.png").icon(),
|
||||
layoutGridLayoutToolTip,
|
||||
layoutCategory,
|
||||
QKeySequence("Ctrl+h"),
|
||||
60,
|
||||
&layoutGridLayout,
|
||||
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
|
||||
|
||||
addDesignerAction(new FillWidthModelNodeAction(
|
||||
layoutFillWidthCommandId,
|
||||
layoutFillWidthDisplayName,
|
||||
layoutCategory,
|
||||
QKeySequence(),
|
||||
40,
|
||||
&setFillWidth,
|
||||
&singleSelectionAndInQtQuickLayout,
|
||||
&singleSelectionAndInQtQuickLayout));
|
||||
|
||||
addDesignerAction(new FillHeightModelNodeAction(
|
||||
layoutFillHeightCommandId,
|
||||
layoutFillHeightDisplayName,
|
||||
layoutCategory,
|
||||
QKeySequence(),
|
||||
20,
|
||||
&setFillHeight,
|
||||
&singleSelectionAndInQtQuickLayout,
|
||||
&singleSelectionAndInQtQuickLayout));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(rootCategory, priorityTopLevelSeperator));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(goIntoComponentDisplayName, rootCategory, priorityGoIntoComponent, &goIntoComponent, &selectionIsComponent));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(goToImplementationDisplayName, rootCategory, 42, &goImplementation, &singleSelectedAndUiFile, &singleSelectedAndUiFile));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(addSignalHandlerDisplayName, rootCategory, 42, &addNewSignalHandler, &singleSelectedAndUiFile, &singleSelectedAndUiFile));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(moveToComponentDisplayName, rootCategory, 44, &moveToComponent, &singleSelection, &singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
goIntoComponentCommandId,
|
||||
goIntoComponentDisplayName,
|
||||
rootCategory,
|
||||
QKeySequence(),
|
||||
priorityGoIntoComponent,
|
||||
&goIntoComponentOperation,
|
||||
&selectionIsComponent));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
goToImplementationCommandId,
|
||||
goToImplementationDisplayName,
|
||||
rootCategory,
|
||||
QKeySequence(),
|
||||
42,
|
||||
&goImplementation,
|
||||
&singleSelectedAndUiFile,
|
||||
&singleSelectedAndUiFile));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
addSignalHandlerCommandId,
|
||||
addSignalHandlerDisplayName,
|
||||
rootCategory, QKeySequence(),
|
||||
42, &addNewSignalHandler,
|
||||
&singleSelectedAndUiFile,
|
||||
&singleSelectedAndUiFile));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
moveToComponentCommandId,
|
||||
moveToComponentDisplayName,
|
||||
rootCategory,
|
||||
QKeySequence(),
|
||||
44,
|
||||
&moveToComponent,
|
||||
&singleSelection,
|
||||
&singleSelection));
|
||||
}
|
||||
|
||||
void DesignerActionManager::addDesignerAction(ActionInterface *newAction)
|
||||
@@ -522,6 +751,12 @@ void DesignerActionManager::addDesignerAction(ActionInterface *newAction)
|
||||
m_designerActionManagerView->setDesignerActionList(designerActions());
|
||||
}
|
||||
|
||||
void DesignerActionManager::addCreatorCommand(Core::Command *command, const QByteArray &category, int priority,
|
||||
const QIcon &overrideIcon)
|
||||
{
|
||||
addDesignerAction(new CommandAction(command, category, priority, overrideIcon));
|
||||
}
|
||||
|
||||
QList<ActionInterface* > DesignerActionManager::designerActions() const
|
||||
{
|
||||
QList<ActionInterface* > list;
|
||||
@@ -541,4 +776,35 @@ DesignerActionManager::~DesignerActionManager()
|
||||
{
|
||||
}
|
||||
|
||||
DesignerActionToolBar::DesignerActionToolBar(QWidget *parentWidget) : Utils::StyledBar(parentWidget),
|
||||
m_toolBar(new QToolBar("ActionToolBar", this))
|
||||
{
|
||||
m_toolBar->setContentsMargins(0, 0, 0, 0);
|
||||
m_toolBar->setFloatable(true);
|
||||
m_toolBar->setMovable(true);
|
||||
m_toolBar->setOrientation(Qt::Horizontal);
|
||||
|
||||
QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
|
||||
|
||||
horizontalLayout->setMargin(0);
|
||||
horizontalLayout->setSpacing(0);
|
||||
|
||||
horizontalLayout->setMargin(0);
|
||||
horizontalLayout->setSpacing(0);
|
||||
|
||||
horizontalLayout->addWidget(m_toolBar);
|
||||
}
|
||||
|
||||
void DesignerActionToolBar::registerAction(ActionInterface *action)
|
||||
{
|
||||
m_toolBar->addAction(action->action());
|
||||
}
|
||||
|
||||
void DesignerActionToolBar::addSeparator()
|
||||
{
|
||||
QAction *separatorAction = new QAction(m_toolBar);
|
||||
separatorAction->setSeparator(true);
|
||||
m_toolBar->addAction(separatorAction);
|
||||
}
|
||||
|
||||
} //QmlDesigner
|
||||
|
@@ -27,22 +27,42 @@
|
||||
|
||||
#include <qmldesignercorelib_global.h>
|
||||
#include "actioninterface.h"
|
||||
#include "abstractview.h"
|
||||
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <utils/styledbar.h>
|
||||
|
||||
#include <QToolBar>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class DesignerActionManagerView;
|
||||
|
||||
class DesignerActionToolBar : public Utils::StyledBar
|
||||
{
|
||||
public:
|
||||
DesignerActionToolBar(QWidget *parentWidget);
|
||||
void registerAction(ActionInterface *action);
|
||||
void addSeparator();
|
||||
|
||||
private:
|
||||
QToolBar *m_toolBar;
|
||||
};
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT DesignerActionManager {
|
||||
public:
|
||||
DesignerActionManager(DesignerActionManagerView *designerActionManagerView);
|
||||
~DesignerActionManager();
|
||||
|
||||
void addDesignerAction(ActionInterface *newAction);
|
||||
void addCreatorCommand(Core::Command *command, const QByteArray &category, int priority,
|
||||
const QIcon &overrideIcon = QIcon());
|
||||
QList<ActionInterface* > designerActions() const;
|
||||
|
||||
void createDefaultDesignerActions();
|
||||
AbstractView *view();
|
||||
DesignerActionManagerView *view();
|
||||
|
||||
DesignerActionToolBar *createToolBar(QWidget *parent = 0) const;
|
||||
void polishActions() const;
|
||||
|
||||
private:
|
||||
QList<QSharedPointer<ActionInterface> > m_designerActions;
|
||||
|
@@ -99,9 +99,15 @@ void DesignerActionManagerView::currentStateChanged(const ModelNode &)
|
||||
setupContext();
|
||||
}
|
||||
|
||||
void DesignerActionManagerView::selectedNodesChanged(const QList<ModelNode> &, const QList<ModelNode> &)
|
||||
void DesignerActionManagerView::selectedNodesChanged(const QList<ModelNode> &selectedNodes, const QList<ModelNode> &)
|
||||
{
|
||||
setupContext();
|
||||
|
||||
/* This breaks encapsulation, but the selection state is a very minor information.
|
||||
* Without this signal the ShortcutManager would have to be refactored completely.
|
||||
* This signal is only used to update the state of the cut/copy/delete actions.
|
||||
*/
|
||||
emit selectionChanged(!selectedNodes.isEmpty());
|
||||
}
|
||||
|
||||
void DesignerActionManagerView::nodeOrderChanged(const NodeListProperty &, const ModelNode &, int)
|
||||
@@ -124,6 +130,18 @@ void DesignerActionManagerView::signalHandlerPropertiesChanged(const QVector<Sig
|
||||
setupContext();
|
||||
}
|
||||
|
||||
void DesignerActionManagerView::variantPropertiesChanged(const QList<VariantProperty> &, AbstractView::PropertyChangeFlags propertyChangeFlag)
|
||||
{
|
||||
if (propertyChangeFlag == AbstractView::PropertiesAdded)
|
||||
setupContext();
|
||||
}
|
||||
|
||||
void DesignerActionManagerView::bindingPropertiesChanged(const QList<BindingProperty> &, AbstractView::PropertyChangeFlags propertyChangeFlag)
|
||||
{
|
||||
if (propertyChangeFlag == AbstractView::PropertiesAdded)
|
||||
setupContext();
|
||||
}
|
||||
|
||||
DesignerActionManager &DesignerActionManagerView::designerActionManager()
|
||||
{
|
||||
return m_designerActionManager;
|
||||
|
@@ -60,11 +60,16 @@ public:
|
||||
void nodeOrderChanged(const NodeListProperty &, const ModelNode &, int ) override;
|
||||
void importsChanged(const QList<Import> &, const QList<Import> &) override;
|
||||
void signalHandlerPropertiesChanged(const QVector<SignalHandlerProperty> &/*propertyList*/, PropertyChangeFlags /*propertyChange*/) override;
|
||||
void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChangeFlag) override;
|
||||
void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChangeFlag) override;
|
||||
|
||||
void setDesignerActionList(const QList<ActionInterface* > &designerActionList);
|
||||
DesignerActionManager &designerActionManager();
|
||||
const DesignerActionManager &designerActionManager() const;
|
||||
|
||||
signals:
|
||||
void selectionChanged(bool itemsSelected);
|
||||
|
||||
protected:
|
||||
void setupContext();
|
||||
|
||||
|
After Width: | Height: | Size: 655 B |
After Width: | Height: | Size: 273 B |
BIN
src/plugins/qmldesigner/components/componentcore/images/fill.png
Normal file
After Width: | Height: | Size: 419 B |
BIN
src/plugins/qmldesigner/components/componentcore/images/grid.png
Normal file
After Width: | Height: | Size: 354 B |
After Width: | Height: | Size: 414 B |
BIN
src/plugins/qmldesigner/components/componentcore/images/move.png
Normal file
After Width: | Height: | Size: 309 B |
After Width: | Height: | Size: 345 B |
BIN
src/plugins/qmldesigner/components/componentcore/images/row.png
Normal file
After Width: | Height: | Size: 294 B |
BIN
src/plugins/qmldesigner/components/componentcore/images/size.png
Normal file
After Width: | Height: | Size: 342 B |
@@ -69,7 +69,7 @@ void populateMenu(QSet<ActionInterface* > &actionInterfaces,
|
||||
});
|
||||
|
||||
foreach (ActionInterface* actionInterface, matchingFactoriesList) {
|
||||
if (actionInterface->type() == ActionInterface::Menu) {
|
||||
if (actionInterface->type() == ActionInterface::ContextMenu) {
|
||||
actionInterface->currentContextChanged(selectionContext);
|
||||
QMenu *newMenu = actionInterface->action()->menu();
|
||||
menu->addMenu(newMenu);
|
||||
@@ -77,9 +77,11 @@ void populateMenu(QSet<ActionInterface* > &actionInterfaces,
|
||||
//recurse
|
||||
|
||||
populateMenu(actionInterfaces, actionInterface->menuId(), newMenu, selectionContext);
|
||||
} else if (actionInterface->type() == ActionInterface::Action) {
|
||||
} else if (actionInterface->type() == ActionInterface::ContextMenuAction
|
||||
|| actionInterface->type() == ActionInterface::Action) {
|
||||
QAction* action = actionInterface->action();
|
||||
actionInterface->currentContextChanged(selectionContext);
|
||||
action->setIconVisibleInMenu(false);
|
||||
menu->addAction(action);
|
||||
}
|
||||
}
|
||||
|
@@ -30,12 +30,19 @@
|
||||
#include "abstractactiongroup.h"
|
||||
#include "qmlitemnode.h"
|
||||
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <utils/proxyaction.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
typedef bool (*SelectionContextFunction)(const SelectionContext &);
|
||||
typedef std::function<bool (const SelectionContext &context)> SelectionContextPredicate;
|
||||
typedef std::function<void (const SelectionContext &context)> SelectionContextOperation;
|
||||
|
||||
namespace SelectionContextFunctors {
|
||||
|
||||
@@ -96,7 +103,7 @@ class ActionTemplate : public DefaultAction
|
||||
{
|
||||
|
||||
public:
|
||||
ActionTemplate(const QString &description, ModelNodeOperations::SelectionAction action)
|
||||
ActionTemplate(const QString &description, SelectionContextOperation action)
|
||||
: DefaultAction(description), m_action(action)
|
||||
{ }
|
||||
|
||||
@@ -104,17 +111,18 @@ public /*slots*/:
|
||||
virtual void actionTriggered(bool b)
|
||||
{
|
||||
m_selectionContext.setToggled(b);
|
||||
return m_action(m_selectionContext);
|
||||
m_action(m_selectionContext);
|
||||
}
|
||||
ModelNodeOperations::SelectionAction m_action;
|
||||
|
||||
SelectionContextOperation m_action;
|
||||
};
|
||||
|
||||
class ActionGroup : public AbstractActionGroup
|
||||
{
|
||||
public:
|
||||
ActionGroup(const QString &displayName, const QByteArray &menuId, int priority,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
AbstractActionGroup(displayName),
|
||||
m_menuId(menuId),
|
||||
m_priority(priority),
|
||||
@@ -128,13 +136,13 @@ public:
|
||||
QByteArray category() const { return QByteArray(); }
|
||||
QByteArray menuId() const { return m_menuId; }
|
||||
int priority() const { return m_priority; }
|
||||
Type type() const { return Menu; }
|
||||
Type type() const { return ContextMenu; }
|
||||
|
||||
private:
|
||||
const QByteArray m_menuId;
|
||||
const int m_priority;
|
||||
SelectionContextFunction m_enabled;
|
||||
SelectionContextFunction m_visibility;
|
||||
SelectionContextPredicate m_enabled;
|
||||
SelectionContextPredicate m_visibility;
|
||||
};
|
||||
|
||||
class SeperatorDesignerAction : public AbstractAction
|
||||
@@ -151,41 +159,82 @@ public:
|
||||
QByteArray category() const { return m_category; }
|
||||
QByteArray menuId() const { return QByteArray(); }
|
||||
int priority() const { return m_priority; }
|
||||
Type type() const { return Action; }
|
||||
Type type() const { return ContextMenuAction; }
|
||||
void currentContextChanged(const SelectionContext &) {}
|
||||
|
||||
private:
|
||||
const QByteArray m_category;
|
||||
const int m_priority;
|
||||
SelectionContextFunction m_visibility;
|
||||
SelectionContextPredicate m_visibility;
|
||||
};
|
||||
|
||||
class ModelNodeAction : public AbstractAction
|
||||
class CommandAction : public ActionInterface
|
||||
{
|
||||
public:
|
||||
ModelNodeAction(const QString &description, const QByteArray &category, int priority,
|
||||
ModelNodeOperations::SelectionAction selectionAction,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
CommandAction(Core::Command *command, const QByteArray &category, int priority, const QIcon &overrideIcon) :
|
||||
m_action(overrideIcon.isNull() ? command->action() : Utils::ProxyAction::proxyActionWithIcon(command->action(), overrideIcon)),
|
||||
m_category(category),
|
||||
m_priority(priority)
|
||||
{}
|
||||
|
||||
QAction *action() const override { return m_action; }
|
||||
QByteArray category() const override { return m_category; }
|
||||
QByteArray menuId() const override { return QByteArray(); }
|
||||
int priority() const override { return m_priority; }
|
||||
Type type() const override { return Action; }
|
||||
void currentContextChanged(const SelectionContext &) override {}
|
||||
|
||||
private:
|
||||
QAction *m_action;
|
||||
const QByteArray m_category;
|
||||
const int m_priority;
|
||||
};
|
||||
|
||||
class ModelNodeContextMenuAction : public AbstractAction
|
||||
{
|
||||
public:
|
||||
ModelNodeContextMenuAction(const QByteArray &id, const QString &description, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation selectionAction,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextPredicate visibility = &SelectionContextFunctors::always) :
|
||||
AbstractAction(new ActionTemplate(description, selectionAction)),
|
||||
m_id(id),
|
||||
m_category(category),
|
||||
m_priority(priority),
|
||||
m_enabled(enabled),
|
||||
m_visibility(visibility)
|
||||
{}
|
||||
{
|
||||
action()->setShortcut(key);
|
||||
}
|
||||
|
||||
bool isVisible(const SelectionContext &selectionState) const { return m_visibility(selectionState); }
|
||||
bool isEnabled(const SelectionContext &selectionState) const { return m_enabled(selectionState); }
|
||||
QByteArray category() const { return m_category; }
|
||||
QByteArray menuId() const { return QByteArray(); }
|
||||
int priority() const { return m_priority; }
|
||||
Type type() const { return Action; }
|
||||
bool isVisible(const SelectionContext &selectionState) const override { return m_visibility(selectionState); }
|
||||
bool isEnabled(const SelectionContext &selectionState) const override { return m_enabled(selectionState); }
|
||||
QByteArray category() const override { return m_category; }
|
||||
QByteArray menuId() const override { return m_id; }
|
||||
int priority() const override { return m_priority; }
|
||||
Type type() const override { return ContextMenuAction; }
|
||||
|
||||
private:
|
||||
const QByteArray m_id;
|
||||
const QByteArray m_category;
|
||||
const int m_priority;
|
||||
const SelectionContextFunction m_enabled;
|
||||
const SelectionContextFunction m_visibility;
|
||||
const SelectionContextPredicate m_enabled;
|
||||
const SelectionContextPredicate m_visibility;
|
||||
};
|
||||
|
||||
class ModelNodeAction : public ModelNodeContextMenuAction
|
||||
{
|
||||
public:
|
||||
ModelNodeAction(const QByteArray &id, const QString &description, const QIcon &icon, const QString &tooltip, const QByteArray &category, const QKeySequence &key, int priority,
|
||||
SelectionContextOperation selectionAction,
|
||||
SelectionContextPredicate enabled = &SelectionContextFunctors::always) :
|
||||
ModelNodeContextMenuAction(id, description, category, key, priority, selectionAction, enabled, &SelectionContextFunctors::always)
|
||||
{
|
||||
action()->setIcon(icon);
|
||||
action()->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
Type type() const override { return Action; }
|
||||
};
|
||||
|
||||
|
||||
|
@@ -341,7 +341,7 @@ void resetPosition(const SelectionContext &selectionState)
|
||||
}
|
||||
}
|
||||
|
||||
void goIntoComponent(const SelectionContext &selectionState)
|
||||
void goIntoComponentOperation(const SelectionContext &selectionState)
|
||||
{
|
||||
goIntoComponent(selectionState.currentSingleSelectedNode());
|
||||
}
|
||||
|
@@ -32,8 +32,6 @@ namespace ModelNodeOperations {
|
||||
|
||||
void goIntoComponent(const ModelNode &modelNode);
|
||||
|
||||
typedef void (*SelectionAction)(const SelectionContext &);
|
||||
|
||||
void select(const SelectionContext &selectionState);
|
||||
void deSelect(const SelectionContext &selectionState);
|
||||
void cut(const SelectionContext &selectionState);
|
||||
@@ -51,7 +49,7 @@ void setFillWidth(const SelectionContext &selectionState);
|
||||
void setFillHeight(const SelectionContext &selectionState);
|
||||
void resetSize(const SelectionContext &selectionState);
|
||||
void resetPosition(const SelectionContext &selectionState);
|
||||
void goIntoComponent(const SelectionContext &selectionState);
|
||||
void goIntoComponentOperation(const SelectionContext &selectionState);
|
||||
void setId(const SelectionContext &selectionState);
|
||||
void resetZ(const SelectionContext &selectionState);
|
||||
void anchorsFill(const SelectionContext &selectionState);
|
||||
|
@@ -51,20 +51,9 @@ namespace QmlDesigner {
|
||||
|
||||
FormEditorView::FormEditorView(QObject *parent)
|
||||
: AbstractView(parent),
|
||||
m_formEditorWidget(new FormEditorWidget(this)),
|
||||
m_scene(new FormEditorScene(m_formEditorWidget.data(), this)),
|
||||
m_moveTool(new MoveTool(this)),
|
||||
m_selectionTool(new SelectionTool(this)),
|
||||
m_resizeTool(new ResizeTool(this)),
|
||||
m_dragTool(new DragTool(this)),
|
||||
m_currentTool(m_selectionTool.get()),
|
||||
m_transactionCounter(0)
|
||||
{
|
||||
Internal::FormEditorContext *formEditorContext = new Internal::FormEditorContext(m_formEditorWidget.data());
|
||||
Core::ICore::addContextObject(formEditorContext);
|
||||
|
||||
connect(formEditorWidget()->zoomAction(), SIGNAL(zoomLevelChanged(double)), SLOT(updateGraphicsIndicators()));
|
||||
connect(formEditorWidget()->showBoundingRectAction(), SIGNAL(toggled(bool)), scene(), SLOT(setShowBoundingRects(bool)));
|
||||
}
|
||||
|
||||
FormEditorScene* FormEditorView::scene() const
|
||||
@@ -148,6 +137,25 @@ void FormEditorView::hideNodeFromScene(const QmlItemNode &qmlItemNode)
|
||||
}
|
||||
}
|
||||
|
||||
void FormEditorView::createFormEditorWidget()
|
||||
{
|
||||
m_formEditorWidget = QPointer<FormEditorWidget>(new FormEditorWidget(this));
|
||||
m_scene = QPointer<FormEditorScene>(new FormEditorScene(m_formEditorWidget.data(), this));
|
||||
|
||||
m_moveTool.reset(new MoveTool(this));
|
||||
m_selectionTool.reset(new SelectionTool(this));
|
||||
m_resizeTool.reset(new ResizeTool(this));
|
||||
m_dragTool.reset(new DragTool(this));
|
||||
|
||||
m_currentTool = m_selectionTool.get();
|
||||
|
||||
Internal::FormEditorContext *formEditorContext = new Internal::FormEditorContext(m_formEditorWidget.data());
|
||||
Core::ICore::addContextObject(formEditorContext);
|
||||
|
||||
connect(formEditorWidget()->zoomAction(), SIGNAL(zoomLevelChanged(double)), SLOT(updateGraphicsIndicators()));
|
||||
connect(formEditorWidget()->showBoundingRectAction(), SIGNAL(toggled(bool)), scene(), SLOT(setShowBoundingRects(bool)));
|
||||
}
|
||||
|
||||
void FormEditorView::nodeCreated(const ModelNode &node)
|
||||
{
|
||||
//If the node has source for components/custom parsers we ignore it.
|
||||
@@ -246,6 +254,10 @@ void FormEditorView::nodeReparented(const ModelNode &node, const NodeAbstractPro
|
||||
|
||||
WidgetInfo FormEditorView::widgetInfo()
|
||||
{
|
||||
|
||||
if (!m_formEditorWidget)
|
||||
createFormEditorWidget();
|
||||
|
||||
return createWidgetInfo(m_formEditorWidget.data(), 0, "FormEditor", WidgetInfo::CentralPane, 0, tr("Form Editor"));
|
||||
}
|
||||
|
||||
|
@@ -123,6 +123,7 @@ private: //functions
|
||||
void setupFormEditorItemTree(const QmlItemNode &qmlItemNode);
|
||||
void removeNodeFromScene(const QmlItemNode &qmlItemNode);
|
||||
void hideNodeFromScene(const QmlItemNode &qmlItemNode);
|
||||
void createFormEditorWidget();
|
||||
|
||||
private: //variables
|
||||
QPointer<FormEditorWidget> m_formEditorWidget;
|
||||
|
@@ -23,11 +23,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "designeractionmanager.h"
|
||||
#include "formeditorwidget.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
#include "designersettings.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
#include "qmldesignericons.h"
|
||||
#include "viewmanager.h"
|
||||
#include <theming.h>
|
||||
|
||||
#include <QWheelEvent>
|
||||
@@ -121,8 +123,17 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
|
||||
addAction(m_rootHeightAction.data());
|
||||
upperActions.append(m_rootHeightAction.data());
|
||||
|
||||
static const QList<Utils::Icon> icon = {
|
||||
Utils::Icon({{":/baremetal/images/baremetaldevicesmall.png",
|
||||
Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint),
|
||||
Utils::Icon({{":/baremetal/images/baremetaldevice.png",
|
||||
Utils::Theme::IconsBaseColor}})};
|
||||
|
||||
|
||||
m_toolBox = new ToolBox(this);
|
||||
fillLayout->addWidget(m_toolBox.data());
|
||||
|
||||
|
||||
m_toolBox->setLeftSideActions(upperActions);
|
||||
|
||||
m_backgroundAction = new BackgroundAction(m_toolActionGroup.data());
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QFrame>
|
||||
|
||||
|
@@ -77,7 +77,7 @@ int AddTabDesignerAction::priority() const
|
||||
|
||||
ActionInterface::Type AddTabDesignerAction::type() const
|
||||
{
|
||||
return Action;
|
||||
return ContextMenuAction;
|
||||
}
|
||||
|
||||
bool AddTabDesignerAction::isVisible(const SelectionContext &selectionContext) const
|
||||
|
@@ -54,6 +54,8 @@ class ViewManagerData
|
||||
public:
|
||||
QmlModelState savedState;
|
||||
Internal::DebugView debugView;
|
||||
DesignerActionManagerView designerActionManagerView;
|
||||
NodeInstanceView nodeInstanceView;
|
||||
ComponentView componentView;
|
||||
FormEditorView formEditorView;
|
||||
TextEditorView textEditorView;
|
||||
@@ -61,8 +63,6 @@ public:
|
||||
NavigatorView navigatorView;
|
||||
PropertyEditorView propertyEditorView;
|
||||
StatesEditorView statesEditorView;
|
||||
NodeInstanceView nodeInstanceView;
|
||||
DesignerActionManagerView designerActionManagerView;
|
||||
|
||||
QList<QPointer<AbstractView> > additionalViews;
|
||||
};
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "designmodewidget.h"
|
||||
|
||||
#include <designeractionmanager.h>
|
||||
|
||||
#include <coreplugin/outputpane.h>
|
||||
#include "qmldesignerplugin.h"
|
||||
#include "crumblebar.h"
|
||||
@@ -299,7 +301,14 @@ void DesignModeWidget::setup()
|
||||
QToolBar *toolBar = new QToolBar;
|
||||
toolBar->addAction(viewManager().componentViewAction());
|
||||
toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
m_toolBar->addCenterToolBar(toolBar);
|
||||
DesignerActionToolBar *designerToolBar = QmlDesignerPlugin::instance()->viewManager().designerActionManager().createToolBar(m_toolBar);
|
||||
|
||||
QmlDesignerPlugin::instance()->viewManager().designerActionManager().polishActions();
|
||||
designerToolBar->layout()->addWidget(toolBar);
|
||||
|
||||
m_toolBar->addCenterToolBar(designerToolBar);
|
||||
|
||||
m_toolBar->setMinimumWidth(320);
|
||||
|
||||
m_mainSplitter = new MiniSplitter(this);
|
||||
m_mainSplitter->setObjectName("mainSplitter");
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
|
||||
Type type() const
|
||||
{
|
||||
return Action;
|
||||
return ContextMenuAction;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@@ -118,7 +118,7 @@ public:
|
||||
|
||||
Type type() const
|
||||
{
|
||||
return Action;
|
||||
return ContextMenuAction;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@@ -89,7 +89,7 @@ public:
|
||||
|
||||
Type type() const
|
||||
{
|
||||
return Action;
|
||||
return ContextMenuAction;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
Type type() const
|
||||
{
|
||||
return Action;
|
||||
return ContextMenuAction;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@@ -27,6 +27,10 @@
|
||||
|
||||
#include "designersettings.h"
|
||||
|
||||
#include <viewmanager.h>
|
||||
#include <designeractionmanagerview.h>
|
||||
#include <componentcore_constants.h>
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
@@ -39,6 +43,8 @@
|
||||
#include <qmljseditor/qmljseditordocument.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/proxyaction.h>
|
||||
#include <utils/utilsicons.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <qmljs/qmljsreformatter.h>
|
||||
@@ -47,6 +53,14 @@
|
||||
#include "qmldesignerplugin.h"
|
||||
#include "designmodewidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
|
||||
static void updateClipboard(QAction *action)
|
||||
{
|
||||
const bool dataInClipboard = !QApplication::clipboard()->text().isEmpty();
|
||||
action->setEnabled(dataInClipboard);
|
||||
}
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -139,6 +153,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
|
||||
|
||||
|
||||
Core::Command *command = nullptr;
|
||||
|
||||
//Save As
|
||||
Core::ActionManager::registerAction(&m_saveAsAction, Core::Constants::SAVEAS, qmlDesignerMainContext);
|
||||
connect(&m_saveAsAction, SIGNAL(triggered()), em, SLOT(saveDocumentAs()));
|
||||
@@ -147,6 +163,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
Core::ActionManager::registerAction(&m_closeCurrentEditorAction, Core::Constants::CLOSE, qmlDesignerMainContext);
|
||||
connect(&m_closeCurrentEditorAction, SIGNAL(triggered()), em, SLOT(slotCloseCurrentEditorOrDocument()));
|
||||
|
||||
DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
||||
|
||||
//Close All
|
||||
Core::ActionManager::registerAction(&m_closeAllEditorsAction, Core::Constants::CLOSEALL, qmlDesignerMainContext);
|
||||
connect(&m_closeAllEditorsAction, SIGNAL(triggered()), em, SLOT(closeAllEditors()));
|
||||
@@ -156,10 +174,11 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
connect(&m_closeOtherEditorsAction, SIGNAL(triggered()), em, SLOT(closeOtherDocuments()));
|
||||
|
||||
// Undo / Redo
|
||||
Core::ActionManager::registerAction(&m_undoAction, Core::Constants::UNDO, qmlDesignerMainContext);
|
||||
Core::ActionManager::registerAction(&m_redoAction, Core::Constants::REDO, qmlDesignerMainContext);
|
||||
command = Core::ActionManager::registerAction(&m_undoAction, Core::Constants::UNDO, qmlDesignerMainContext);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 310, Utils::Icons::UNDO_TOOLBAR.icon());
|
||||
command = Core::ActionManager::registerAction(&m_redoAction, Core::Constants::REDO, qmlDesignerMainContext);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 300, Utils::Icons::REDO_TOOLBAR.icon());
|
||||
|
||||
Core::Command *command;
|
||||
|
||||
//GoIntoComponent
|
||||
command = Core::ActionManager::registerAction(&m_goIntoComponentAction,
|
||||
@@ -168,6 +187,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
|
||||
//Edit Menu
|
||||
|
||||
m_deleteAction.setIcon(QIcon::fromTheme(QLatin1String("edit-cut"), Utils::Icons::EDIT_CLEAR_TOOLBAR.icon()));
|
||||
|
||||
Core::ActionManager::registerAction(&m_deleteAction, QmlDesigner::Constants::C_BACKSPACE, qmlDesignerFormEditorContext);
|
||||
command = Core::ActionManager::registerAction(&m_deleteAction, QmlDesigner::Constants::C_BACKSPACE, qmlDesignerNavigatorContext);
|
||||
command->setDefaultKeySequence(QKeySequence(Qt::Key_Backspace));
|
||||
@@ -181,21 +202,25 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes
|
||||
if (!Utils::HostOsInfo::isMacHost())
|
||||
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 280);
|
||||
|
||||
Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerFormEditorContext);
|
||||
command = Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerNavigatorContext);
|
||||
command->setDefaultKeySequence(QKeySequence::Cut);
|
||||
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 260, Utils::Icons::CUT_TOOLBAR.icon());
|
||||
|
||||
Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerFormEditorContext);
|
||||
command = Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerNavigatorContext);
|
||||
command->setDefaultKeySequence(QKeySequence::Copy);
|
||||
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 250, Utils::Icons::COPY_TOOLBAR.icon());
|
||||
|
||||
Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerFormEditorContext);
|
||||
command = Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerNavigatorContext);
|
||||
command->setDefaultKeySequence(QKeySequence::Paste);
|
||||
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
||||
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 240, Utils::Icons::PASTE_TOOLBAR.icon());
|
||||
|
||||
Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerFormEditorContext);
|
||||
command = Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerNavigatorContext);
|
||||
@@ -225,6 +250,17 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
m_escapeAction.setEnabled(false);
|
||||
|
||||
Core::ActionManager::registerAction(&m_hideSidebarsAction, Core::Constants::TOGGLE_SIDEBAR, qmlDesignerMainContext);
|
||||
|
||||
connect(designerActionManager.view(), &DesignerActionManagerView::selectionChanged, this, [this](bool itemsSelected) {
|
||||
m_deleteAction.setEnabled(itemsSelected);
|
||||
m_cutAction.setEnabled(itemsSelected);
|
||||
m_copyAction.setEnabled(itemsSelected);
|
||||
});
|
||||
|
||||
updateClipboard(&m_pasteAction);
|
||||
connect(QApplication::clipboard(), &QClipboard::QClipboard::changed, this, [this]() {
|
||||
updateClipboard(&m_pasteAction);
|
||||
});
|
||||
}
|
||||
|
||||
void ShortCutManager::updateActions(Core::IEditor* currentEditor)
|
||||
|