QmlDesigner: Update the Stack (z) context menu

* Rename arrange menu and items
* Remove the "Reset z property" item
* Add reverse item and functionality
* Fix some related typos and formatting

Task-number: QDS-2938
Change-Id: I0e706aefdaed99b28faae4b307146847a54a24ed
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2020-10-28 09:32:44 +01:00
committed by Henning Gründl
parent b30b2f481c
commit c019860809
6 changed files with 99 additions and 41 deletions

View File

@@ -34,7 +34,7 @@ namespace ComponentCoreConstants {
const char rootCategory[] = ""; const char rootCategory[] = "";
const char selectionCategory[] = "Selection"; const char selectionCategory[] = "Selection";
const char stackCategory[] = "Stack (z)"; const char arrangeCategory[] = "Arrange";
const char qmlPreviewCategory[] = "QmlPreview"; const char qmlPreviewCategory[] = "QmlPreview";
const char editCategory[] = "Edit"; const char editCategory[] = "Edit";
const char anchorsCategory[] = "Anchors"; const char anchorsCategory[] = "Anchors";
@@ -52,6 +52,7 @@ const char toBackCommandId[] = "ToBack";
const char raiseCommandId[] = "Raise"; const char raiseCommandId[] = "Raise";
const char lowerCommandId[] = "Lower"; const char lowerCommandId[] = "Lower";
const char resetZCommandId[] = "ResetZ"; const char resetZCommandId[] = "ResetZ";
const char reverseCommandId[] = "Reverse";
const char resetSizeCommandId[] = "ResetSize"; const char resetSizeCommandId[] = "ResetSize";
const char resetPositionCommandId[] = "ResetPosition"; const char resetPositionCommandId[] = "ResetPosition";
const char visiblityCommandId[] = "ToggleVisiblity"; const char visiblityCommandId[] = "ToggleVisiblity";
@@ -90,7 +91,7 @@ const char fitSelectionToScreenCommandId[] = "FitSelectionToScreen";
const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection"); const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection");
const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect"); const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect");
const char selectEffectDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Select Effect"); const char selectEffectDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Select Effect");
const char stackCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Stack (z)"); const char arrangeCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Arrange");
const char editCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit"); const char editCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit");
const char anchorsCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Anchors"); const char anchorsCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Anchors");
const char positionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position"); const char positionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Position");
@@ -105,11 +106,11 @@ const char copySelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMen
const char pasteSelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Paste"); const char pasteSelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Paste");
const char deleteSelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Delete Selection"); const char deleteSelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Delete Selection");
const char toFrontDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "To Front"); const char toFrontDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Bring to Front");
const char toBackDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "To Back"); const char toBackDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Send to Back");
const char raiseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Raise"); const char raiseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Bring Forward");
const char lowerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Lower"); const char lowerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Send Backward");
const char undoDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Undo"); const char undoDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Undo");
const char redoDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Redo"); const char redoDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Redo");
@@ -129,6 +130,8 @@ const char setIdDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Set
const char resetZDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset z Property"); const char resetZDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset z Property");
const char reverseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reverse");
const char anchorsFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill"); const char anchorsFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill");
const char anchorsResetDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset"); const char anchorsResetDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset");

View File

@@ -594,6 +594,11 @@ bool selectionHasSameParentAndInBaseState(const SelectionContext &context)
return selectionHasSameParent(context) && inBaseState(context); return selectionHasSameParent(context) && inBaseState(context);
} }
bool multiSelectionAndHasSameParent(const SelectionContext &context)
{
return multiSelection(context) && selectionHasSameParent(context);
}
bool isNotInLayout(const SelectionContext &context) bool isNotInLayout(const SelectionContext &context)
{ {
if (selectionNotEmpty(context)) { if (selectionNotEmpty(context)) {
@@ -914,8 +919,8 @@ void DesignerActionManager::createDefaultDesignerActions()
prioritySelectionCategory)); prioritySelectionCategory));
addDesignerAction(new ActionGroup( addDesignerAction(new ActionGroup(
stackCategoryDisplayName, arrangeCategoryDisplayName,
stackCategory, arrangeCategory,
priorityStackCategory, priorityStackCategory,
&selectionNotEmpty)); &selectionNotEmpty));
@@ -923,28 +928,19 @@ void DesignerActionManager::createDefaultDesignerActions()
toFrontCommandId, toFrontCommandId,
toFrontDisplayName, toFrontDisplayName,
{}, {},
stackCategory, arrangeCategory,
QKeySequence(), QKeySequence(),
200, 200,
&toFront, &toFront,
&singleSelection)); &singleSelection));
addDesignerAction(new ModelNodeContextMenuAction( addDesignerAction(new ModelNodeContextMenuAction(
toBackCommandId, raiseCommandId,
toBackDisplayName, raiseDisplayName,
{}, Utils::Icon({{":/qmldesigner/icon/designeractions/images/raise.png", Utils::Theme::IconsBaseColor}}).icon(),
stackCategory, arrangeCategory,
QKeySequence(), QKeySequence(),
180, 180,
&toBack,
&singleSelection));
addDesignerAction(new ModelNodeContextMenuAction(
raiseCommandId, raiseDisplayName,
Utils::Icon({{":/qmldesigner/icon/designeractions/images/raise.png", Utils::Theme::IconsBaseColor}}).icon(),
stackCategory,
QKeySequence(),
160,
&raise, &raise,
&raiseAvailable)); &raiseAvailable));
@@ -952,23 +948,31 @@ void DesignerActionManager::createDefaultDesignerActions()
lowerCommandId, lowerCommandId,
lowerDisplayName, lowerDisplayName,
Utils::Icon({{":/qmldesigner/icon/designeractions/images/lower.png", Utils::Theme::IconsBaseColor}}).icon(), Utils::Icon({{":/qmldesigner/icon/designeractions/images/lower.png", Utils::Theme::IconsBaseColor}}).icon(),
stackCategory, arrangeCategory,
QKeySequence(), QKeySequence(),
140, 160,
&lower, &lower,
&lowerAvailable)); &lowerAvailable));
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120)); addDesignerAction(new ModelNodeContextMenuAction(
toBackCommandId,
toBackDisplayName,
{},
arrangeCategory,
QKeySequence(),
140,
&toBack,
&singleSelection));
addDesignerAction(new ModelNodeContextMenuAction( addDesignerAction(new ModelNodeContextMenuAction(
resetZCommandId, reverseCommandId,
resetZDisplayName, reverseDisplayName,
{}, {},
stackCategory, arrangeCategory,
QKeySequence(), QKeySequence(),
100, 100,
&resetZ, &reverse,
&selectionNotEmptyAndHasZProperty)); &multiSelectionAndHasSameParent));
addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty)); addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
@@ -979,7 +983,9 @@ void DesignerActionManager::createDefaultDesignerActions()
resetPositionDisplayName, resetPositionDisplayName,
Utils::Icon({{":/utils/images/pan.png", Utils::Theme::IconsBaseColor}, Utils::Icon({{":/utils/images/pan.png", Utils::Theme::IconsBaseColor},
{":/utils/images/iconoverlay_reset.png", Utils::Theme::IconsStopToolBarColor}}).icon(), {":/utils/images/iconoverlay_reset.png", Utils::Theme::IconsStopToolBarColor}}).icon(),
resetPositionTooltip, editCategory, QKeySequence("Ctrl+d"), resetPositionTooltip,
editCategory,
QKeySequence("Ctrl+d"),
200, 200,
&resetPosition, &resetPosition,
&selectionNotEmptyAndHasXorYProperty)); &selectionNotEmptyAndHasXorYProperty));

View File

@@ -206,9 +206,9 @@ void toBack(const SelectionContext &selectionState)
} }
} }
enum OderAction {RaiseItem, LowerItem}; enum OrderAction {RaiseItem, LowerItem};
void changeOrder(const SelectionContext &selectionState, OderAction orderAction) void changeOrder(const SelectionContext &selectionState, OrderAction orderAction)
{ {
if (!selectionState.view()) if (!selectionState.view())
return; return;
@@ -221,13 +221,12 @@ void changeOrder(const SelectionContext &selectionState, OderAction orderAction)
if (!modelNode.parentProperty().isNodeListProperty()) if (!modelNode.parentProperty().isNodeListProperty())
return; return;
selectionState.view()->executeInTransaction("DesignerActionManager|raise",[orderAction, selectionState, modelNode](){ selectionState.view()->executeInTransaction("DesignerActionManager|changeOrder", [orderAction, selectionState, modelNode]() {
ModelNode modelNode = selectionState.currentSingleSelectedNode(); ModelNode modelNode = selectionState.currentSingleSelectedNode();
NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty(); NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty();
const int index = parentProperty.indexOf(modelNode); const int index = parentProperty.indexOf(modelNode);
if (orderAction == RaiseItem) { if (orderAction == RaiseItem) {
if (index < parentProperty.count() - 1) if (index < parentProperty.count() - 1)
parentProperty.slide(index, index + 1); parentProperty.slide(index, index + 1);
} else if (orderAction == LowerItem) { } else if (orderAction == LowerItem) {
@@ -244,7 +243,6 @@ void raise(const SelectionContext &selectionState)
void lower(const SelectionContext &selectionState) void lower(const SelectionContext &selectionState)
{ {
changeOrder(selectionState, LowerItem); changeOrder(selectionState, LowerItem);
} }
@@ -344,8 +342,8 @@ void resetZ(const SelectionContext &selectionState)
if (!selectionState.view()) if (!selectionState.view())
return; return;
selectionState.view()->executeInTransaction("DesignerActionManager|resetZ",[selectionState](){ selectionState.view()->executeInTransaction("DesignerActionManager|resetZ", [selectionState](){
foreach (ModelNode node, selectionState.selectedModelNodes()) { for (ModelNode node : selectionState.selectedModelNodes()) {
QmlItemNode itemNode(node); QmlItemNode itemNode(node);
if (itemNode.isValid()) if (itemNode.isValid())
itemNode.removeProperty("z"); itemNode.removeProperty("z");
@@ -353,6 +351,16 @@ void resetZ(const SelectionContext &selectionState)
}); });
} }
void reverse(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
selectionState.view()->executeInTransaction("DesignerActionManager|reverse", [selectionState](){
NodeListProperty::reverseModelNodes(selectionState.selectedModelNodes());
});
}
static inline void backupPropertyAndRemove(const ModelNode &node, const PropertyName &propertyName) static inline void backupPropertyAndRemove(const ModelNode &node, const PropertyName &propertyName)
{ {
if (node.hasVariantProperty(propertyName)) { if (node.hasVariantProperty(propertyName)) {
@@ -366,7 +374,6 @@ static inline void backupPropertyAndRemove(const ModelNode &node, const Property
} }
} }
static inline void restoreProperty(const ModelNode &node, const PropertyName &propertyName) static inline void restoreProperty(const ModelNode &node, const PropertyName &propertyName)
{ {
if (node.hasAuxiliaryData(auxDataString + propertyName)) if (node.hasAuxiliaryData(auxDataString + propertyName))

View File

@@ -52,6 +52,7 @@ void resetPosition(const SelectionContext &selectionState);
void goIntoComponentOperation(const SelectionContext &selectionState); void goIntoComponentOperation(const SelectionContext &selectionState);
void setId(const SelectionContext &selectionState); void setId(const SelectionContext &selectionState);
void resetZ(const SelectionContext &selectionState); void resetZ(const SelectionContext &selectionState);
void reverse(const SelectionContext &selectionState);
void anchorsFill(const SelectionContext &selectionState); void anchorsFill(const SelectionContext &selectionState);
void anchorsReset(const SelectionContext &selectionState); void anchorsReset(const SelectionContext &selectionState);
void layoutRowPositioner(const SelectionContext &selectionState); void layoutRowPositioner(const SelectionContext &selectionState);

View File

@@ -51,9 +51,12 @@ public:
const QList<ModelNode> toModelNodeList() const; const QList<ModelNode> toModelNodeList() const;
const QList<QmlObjectNode> toQmlObjectNodeList() const; const QList<QmlObjectNode> toQmlObjectNodeList() const;
void slide(int, int) const; void slide(int, int) const;
void swap(int, int) const;
void reparentHere(const ModelNode &modelNode); void reparentHere(const ModelNode &modelNode);
ModelNode at(int index) const; ModelNode at(int index) const;
static void reverseModelNodes(const QList<ModelNode> &nodes);
protected: protected:
NodeListProperty(const PropertyName &propertyName, const Internal::InternalNodePointer &internalNode, Model* model, AbstractView *view); NodeListProperty(const PropertyName &propertyName, const Internal::InternalNodePointer &internalNode, Model* model, AbstractView *view);
NodeListProperty(const Internal::InternalNodeListPropertyPointer &internalNodeListProperty, Model* model, AbstractView *view); NodeListProperty(const Internal::InternalNodeListPropertyPointer &internalNodeListProperty, Model* model, AbstractView *view);

View File

@@ -32,7 +32,7 @@
#include "model_p.h" #include "model_p.h"
#include <qmlobjectnode.h> #include <qmlobjectnode.h>
#include <cmath>
namespace QmlDesigner { namespace QmlDesigner {
@@ -95,12 +95,30 @@ void NodeListProperty::slide(int from, int to) const
Internal::WriteLocker locker(model()); Internal::WriteLocker locker(model());
if (!isValid()) if (!isValid())
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list property>"); throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list property>");
if (to > count() - 1) if (to < 0 || to > count() - 1 || from < 0 || from > count() - 1)
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list sliding>"); throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list sliding>");
privateModel()->changeNodeOrder(internalNode(), name(), from, to); privateModel()->changeNodeOrder(internalNode(), name(), from, to);
} }
void NodeListProperty::swap(int from, int to) const
{
if (from == to)
return;
// Prerequisite a < b
int a = from;
int b = to;
if (a > b) {
a = to;
b = from;
}
slide(b, a);
slide(a + 1, b);
}
void NodeListProperty::reparentHere(const ModelNode &modelNode) void NodeListProperty::reparentHere(const ModelNode &modelNode)
{ {
NodeAbstractProperty::reparentHere(modelNode, true); NodeAbstractProperty::reparentHere(modelNode, true);
@@ -119,4 +137,24 @@ ModelNode NodeListProperty::at(int index) const
return ModelNode(); return ModelNode();
} }
void NodeListProperty::reverseModelNodes(const QList<ModelNode> &nodes)
{
ModelNode firstNode = nodes.first();
if (!firstNode.isValid())
return;
NodeListProperty parentProperty = firstNode.parentProperty().toNodeListProperty();
std::vector<int> selectedNodeIndices;
for (ModelNode modelNode : nodes)
selectedNodeIndices.push_back(parentProperty.indexOf(modelNode));
std::sort(selectedNodeIndices.begin(), selectedNodeIndices.end());
int mid = std::ceil(selectedNodeIndices.size() / 2);
for (int i = 0; i != mid; ++i)
parentProperty.swap(selectedNodeIndices[i], selectedNodeIndices[selectedNodeIndices.size() - 1 - i]);
}
} // namespace QmlDesigner } // namespace QmlDesigner