QmlDesigner: Move positioning using Positioners

Move positioning using Positioners to another context menu categeory.
The fact that we have Layouts and Positioners in Qt Quick and both do
something quite similar is something we cannot change.
I also do not like to remove Positioners from the designer, because
they have use cases. But having both in the same context menu was a mistake
I think.
So I moved the Positioner operations into their own menu/category.

The plan is to add a toolbar (eventually), but only support layouts in
the toolbar to minimize confusion.

Change-Id: I5a6abebca209eb43cac7404e12aa998c466cd62d
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-07-16 15:58:35 +02:00
committed by Thomas Hartmann
parent 91dbd9c2d8
commit cad4ee7116
2 changed files with 60 additions and 37 deletions

View File

@@ -43,12 +43,14 @@ const char selectionCategory[] = "Selection";
const char stackCategory[] = "Stack (z)";
const char editCategory[] = "Edit";
const char anchorsCategory[] = "Anchors";
const char positionCategory[] = "Position";
const char layoutCategory[] = "Layout";
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");
const char anchorsCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Anchors");
const char positionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position");
const char layoutCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout");
const char selectParentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Select Parent: %1");
@@ -84,10 +86,10 @@ const char resetZDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Re
const char anchorsFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill");
const char anchorsResetDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset");
const char layoutColumnPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout in Column (Positioner)");
const char layoutRowPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout in Row (Positioner)");
const char layoutGridPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout in Grid (Positioner)");
const char layoutFlowPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Layout in Flow (Positioner)");
const char layoutColumnPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position in Column");
const char layoutRowPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position in Row");
const char layoutGridPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position in Grid");
const char layoutFlowPositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position in Flow");
const char removePositionerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Remove Positioner");
const char removeLayoutDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Remove Layout");
@@ -104,6 +106,7 @@ const int prioritySelectionCategory = 200;
const int priorityStackCategory = 180;
const int priorityEditCategory = 160;
const int priorityAnchorsCategory = 140;
const int priorityPositionCategory = 130;
const int priorityLayoutCategory = 120;
const int priorityTopLevelSeperator = 100;
const int priorityCustomActions = 80;

View File

@@ -34,6 +34,9 @@
#include <nodemetainfo.h>
#include "designeractionmanagerview.h"
#include <documentmanager.h>
#include <qmldesignerplugin.h>
namespace QmlDesigner {
static inline QString captionForModelNode(const ModelNode &modelNode)
@@ -249,24 +252,15 @@ bool isNotInLayout(const SelectionContext &context)
bool selectionCanBeLayouted(const SelectionContext &context)
{
return selectionHasSameParentAndInBaseState(context)
return multiSelection(context)
&& selectionHasSameParentAndInBaseState(context)
&& inBaseState(context)
&& isNotInLayout(context);
}
bool hasQtQuickLayoutImport(const SelectionContext &context)
bool selectionCanBeLayoutedAndQtQuickLayoutPossible(const SelectionContext &context)
{
if (context.view() && context.view()->model()) {
Import import = Import::createLibraryImport(QStringLiteral("QtQuick.Layouts"), QStringLiteral("1.0"));
return context.view()->model()->hasImport(import, true, true);
}
return false;
}
bool selectionCanBeLayoutedAndasQtQuickLayoutImport(const SelectionContext &context)
{
return selectionCanBeLayouted(context) && hasQtQuickLayoutImport(context);
return selectionCanBeLayouted(context) && context.view()->majorQtQuickVersion() > 1;
}
bool selectionNotEmptyAndHasZProperty(const SelectionContext &context)
@@ -360,9 +354,31 @@ bool isPositioner(const SelectionContext &context)
bool layoutOptionVisible(const SelectionContext &context)
{
return multiSelectionAndInBaseState(context)
|| singleSelectionAndInQtQuickLayout(context);
|| singleSelectionAndInQtQuickLayout(context)
|| isLayout(context);
}
bool positionOptionVisible(const SelectionContext &context)
{
return multiSelectionAndInBaseState(context)
|| isPositioner(context);
}
bool singleSelectedAndUiFile(const SelectionContext &context)
{
if (!singleSelection(context))
return false;
DesignDocument *designDocument = QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
if (!designDocument)
return false;
return designDocument->fileName().toFileInfo().completeSuffix()
== QLatin1String("ui.qml");
}
void DesignerActionManager::createDefaultDesignerActions()
{
using namespace SelectionContextFunctors;
@@ -399,8 +415,11 @@ void DesignerActionManager::createDefaultDesignerActions()
addDesignerAction(new ModelNodeAction
(anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored));
addDesignerAction(new ActionGroup(layoutCategoryDisplayName, layoutCategory,
addDesignerAction(new ActionGroup(positionCategoryDisplayName, positionCategory,
priorityPositionCategory, &positionOptionVisible));
addDesignerAction(new ActionGroup(layoutCategoryDisplayName, layoutCategory,
priorityLayoutCategory, &layoutOptionVisible));
addDesignerAction(new ModelNodeAction
(removePositionerDisplayName,
positionCategory,
@@ -408,37 +427,38 @@ void DesignerActionManager::createDefaultDesignerActions()
&removePositioner,
&isPositioner,
&isPositioner));
addDesignerAction(new ModelNodeAction
(layoutRowPositionerDisplayName,
layoutCategory,
positionCategory,
200,
&layoutRowPositioner,
&selectionCanBeLayouted,
selectionCanBeLayouted));
&selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutColumnPositionerDisplayName,
layoutCategory,
positionCategory,
180,
&layoutColumnPositioner,
&selectionCanBeLayouted,
selectionCanBeLayouted));
&selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutGridPositionerDisplayName,
layoutCategory,
positionCategory,
160,
&layoutGridPositioner,
&selectionCanBeLayouted,
selectionCanBeLayouted));
&selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutFlowPositionerDisplayName,
layoutCategory,
positionCategory,
140,
&layoutFlowPositioner,
&selectionCanBeLayouted,
selectionCanBeLayouted));
&selectionCanBeLayouted));
addDesignerAction(new SeperatorDesignerAction(layoutCategory, 120));
@@ -455,40 +475,40 @@ void DesignerActionManager::createDefaultDesignerActions()
layoutCategory,
100,
&layoutRowLayout,
&selectionCanBeLayoutedAndasQtQuickLayoutImport,
&selectionCanBeLayoutedAndasQtQuickLayoutImport));
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
addDesignerAction(new ModelNodeAction
(layoutColumnLayoutDisplayName,
layoutCategory,
80,
&layoutColumnLayout,
&selectionCanBeLayoutedAndasQtQuickLayoutImport,
&selectionCanBeLayoutedAndasQtQuickLayoutImport));
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
addDesignerAction(new ModelNodeAction
(layoutGridLayoutDisplayName,
layoutCategory,
60,
&layoutGridLayout,
&selectionCanBeLayoutedAndasQtQuickLayoutImport,
&selectionCanBeLayoutedAndasQtQuickLayoutImport));
&selectionCanBeLayoutedAndQtQuickLayoutPossible,
&selectionCanBeLayoutedAndQtQuickLayoutPossible));
addDesignerAction(new FillWidthModelNodeAction
(layoutFillWidthDisplayName,
layoutCategory,
40,
&setFillWidth,
singleSelectionAndInQtQuickLayout,
singleSelectionAndInQtQuickLayout));
&singleSelectionAndInQtQuickLayout,
&singleSelectionAndInQtQuickLayout));
addDesignerAction(new FillHeightModelNodeAction
(layoutFillHeightDisplayName,
layoutCategory,
20,
&setFillHeight,
singleSelectionAndInQtQuickLayout,
singleSelectionAndInQtQuickLayout));
&singleSelectionAndInQtQuickLayout,
&singleSelectionAndInQtQuickLayout));
addDesignerAction(new SeperatorDesignerAction(rootCategory, priorityTopLevelSeperator));
addDesignerAction(new ModelNodeAction