forked from qt-creator/qt-creator
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:
committed by
Henning Gründl
parent
b30b2f481c
commit
c019860809
@@ -34,7 +34,7 @@ namespace ComponentCoreConstants {
|
||||
const char rootCategory[] = "";
|
||||
|
||||
const char selectionCategory[] = "Selection";
|
||||
const char stackCategory[] = "Stack (z)";
|
||||
const char arrangeCategory[] = "Arrange";
|
||||
const char qmlPreviewCategory[] = "QmlPreview";
|
||||
const char editCategory[] = "Edit";
|
||||
const char anchorsCategory[] = "Anchors";
|
||||
@@ -52,6 +52,7 @@ const char toBackCommandId[] = "ToBack";
|
||||
const char raiseCommandId[] = "Raise";
|
||||
const char lowerCommandId[] = "Lower";
|
||||
const char resetZCommandId[] = "ResetZ";
|
||||
const char reverseCommandId[] = "Reverse";
|
||||
const char resetSizeCommandId[] = "ResetSize";
|
||||
const char resetPositionCommandId[] = "ResetPosition";
|
||||
const char visiblityCommandId[] = "ToggleVisiblity";
|
||||
@@ -90,7 +91,7 @@ const char fitSelectionToScreenCommandId[] = "FitSelectionToScreen";
|
||||
const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection");
|
||||
const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect");
|
||||
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 anchorsCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Anchors");
|
||||
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 deleteSelectionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Delete Selection");
|
||||
|
||||
const char toFrontDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "To Front");
|
||||
const char toBackDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "To Back");
|
||||
const char toFrontDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Bring to Front");
|
||||
const char toBackDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Send to Back");
|
||||
|
||||
const char raiseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Raise");
|
||||
const char lowerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Lower");
|
||||
const char raiseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Bring Forward");
|
||||
const char lowerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Send Backward");
|
||||
|
||||
const char undoDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Undo");
|
||||
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 reverseDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reverse");
|
||||
|
||||
const char anchorsFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fill");
|
||||
const char anchorsResetDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Reset");
|
||||
|
||||
|
@@ -594,6 +594,11 @@ bool selectionHasSameParentAndInBaseState(const SelectionContext &context)
|
||||
return selectionHasSameParent(context) && inBaseState(context);
|
||||
}
|
||||
|
||||
bool multiSelectionAndHasSameParent(const SelectionContext &context)
|
||||
{
|
||||
return multiSelection(context) && selectionHasSameParent(context);
|
||||
}
|
||||
|
||||
bool isNotInLayout(const SelectionContext &context)
|
||||
{
|
||||
if (selectionNotEmpty(context)) {
|
||||
@@ -914,8 +919,8 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
prioritySelectionCategory));
|
||||
|
||||
addDesignerAction(new ActionGroup(
|
||||
stackCategoryDisplayName,
|
||||
stackCategory,
|
||||
arrangeCategoryDisplayName,
|
||||
arrangeCategory,
|
||||
priorityStackCategory,
|
||||
&selectionNotEmpty));
|
||||
|
||||
@@ -923,28 +928,19 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
toFrontCommandId,
|
||||
toFrontDisplayName,
|
||||
{},
|
||||
stackCategory,
|
||||
arrangeCategory,
|
||||
QKeySequence(),
|
||||
200,
|
||||
&toFront,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
toBackCommandId,
|
||||
toBackDisplayName,
|
||||
{},
|
||||
stackCategory,
|
||||
raiseCommandId,
|
||||
raiseDisplayName,
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/raise.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
arrangeCategory,
|
||||
QKeySequence(),
|
||||
180,
|
||||
&toBack,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
raiseCommandId, raiseDisplayName,
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/raise.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
stackCategory,
|
||||
QKeySequence(),
|
||||
160,
|
||||
&raise,
|
||||
&raiseAvailable));
|
||||
|
||||
@@ -952,23 +948,31 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
lowerCommandId,
|
||||
lowerDisplayName,
|
||||
Utils::Icon({{":/qmldesigner/icon/designeractions/images/lower.png", Utils::Theme::IconsBaseColor}}).icon(),
|
||||
stackCategory,
|
||||
arrangeCategory,
|
||||
QKeySequence(),
|
||||
140,
|
||||
160,
|
||||
&lower,
|
||||
&lowerAvailable));
|
||||
|
||||
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120));
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
toBackCommandId,
|
||||
toBackDisplayName,
|
||||
{},
|
||||
arrangeCategory,
|
||||
QKeySequence(),
|
||||
140,
|
||||
&toBack,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
resetZCommandId,
|
||||
resetZDisplayName,
|
||||
reverseCommandId,
|
||||
reverseDisplayName,
|
||||
{},
|
||||
stackCategory,
|
||||
arrangeCategory,
|
||||
QKeySequence(),
|
||||
100,
|
||||
&resetZ,
|
||||
&selectionNotEmptyAndHasZProperty));
|
||||
&reverse,
|
||||
&multiSelectionAndHasSameParent));
|
||||
|
||||
addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
|
||||
|
||||
@@ -979,7 +983,9 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
resetPositionDisplayName,
|
||||
Utils::Icon({{":/utils/images/pan.png", Utils::Theme::IconsBaseColor},
|
||||
{":/utils/images/iconoverlay_reset.png", Utils::Theme::IconsStopToolBarColor}}).icon(),
|
||||
resetPositionTooltip, editCategory, QKeySequence("Ctrl+d"),
|
||||
resetPositionTooltip,
|
||||
editCategory,
|
||||
QKeySequence("Ctrl+d"),
|
||||
200,
|
||||
&resetPosition,
|
||||
&selectionNotEmptyAndHasXorYProperty));
|
||||
|
@@ -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())
|
||||
return;
|
||||
@@ -221,13 +221,12 @@ void changeOrder(const SelectionContext &selectionState, OderAction orderAction)
|
||||
if (!modelNode.parentProperty().isNodeListProperty())
|
||||
return;
|
||||
|
||||
selectionState.view()->executeInTransaction("DesignerActionManager|raise",[orderAction, selectionState, modelNode](){
|
||||
selectionState.view()->executeInTransaction("DesignerActionManager|changeOrder", [orderAction, selectionState, modelNode]() {
|
||||
ModelNode modelNode = selectionState.currentSingleSelectedNode();
|
||||
NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty();
|
||||
const int index = parentProperty.indexOf(modelNode);
|
||||
|
||||
if (orderAction == RaiseItem) {
|
||||
|
||||
if (index < parentProperty.count() - 1)
|
||||
parentProperty.slide(index, index + 1);
|
||||
} else if (orderAction == LowerItem) {
|
||||
@@ -244,7 +243,6 @@ void raise(const SelectionContext &selectionState)
|
||||
|
||||
void lower(const SelectionContext &selectionState)
|
||||
{
|
||||
|
||||
changeOrder(selectionState, LowerItem);
|
||||
}
|
||||
|
||||
@@ -345,7 +343,7 @@ void resetZ(const SelectionContext &selectionState)
|
||||
return;
|
||||
|
||||
selectionState.view()->executeInTransaction("DesignerActionManager|resetZ", [selectionState](){
|
||||
foreach (ModelNode node, selectionState.selectedModelNodes()) {
|
||||
for (ModelNode node : selectionState.selectedModelNodes()) {
|
||||
QmlItemNode itemNode(node);
|
||||
if (itemNode.isValid())
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (node.hasAuxiliaryData(auxDataString + propertyName))
|
||||
|
@@ -52,6 +52,7 @@ void resetPosition(const SelectionContext &selectionState);
|
||||
void goIntoComponentOperation(const SelectionContext &selectionState);
|
||||
void setId(const SelectionContext &selectionState);
|
||||
void resetZ(const SelectionContext &selectionState);
|
||||
void reverse(const SelectionContext &selectionState);
|
||||
void anchorsFill(const SelectionContext &selectionState);
|
||||
void anchorsReset(const SelectionContext &selectionState);
|
||||
void layoutRowPositioner(const SelectionContext &selectionState);
|
||||
|
@@ -51,9 +51,12 @@ public:
|
||||
const QList<ModelNode> toModelNodeList() const;
|
||||
const QList<QmlObjectNode> toQmlObjectNodeList() const;
|
||||
void slide(int, int) const;
|
||||
void swap(int, int) const;
|
||||
void reparentHere(const ModelNode &modelNode);
|
||||
ModelNode at(int index) const;
|
||||
|
||||
static void reverseModelNodes(const QList<ModelNode> &nodes);
|
||||
|
||||
protected:
|
||||
NodeListProperty(const PropertyName &propertyName, const Internal::InternalNodePointer &internalNode, Model* model, AbstractView *view);
|
||||
NodeListProperty(const Internal::InternalNodeListPropertyPointer &internalNodeListProperty, Model* model, AbstractView *view);
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include "model_p.h"
|
||||
#include <qmlobjectnode.h>
|
||||
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -95,12 +95,30 @@ void NodeListProperty::slide(int from, int to) const
|
||||
Internal::WriteLocker locker(model());
|
||||
if (!isValid())
|
||||
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>");
|
||||
|
||||
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)
|
||||
{
|
||||
NodeAbstractProperty::reparentHere(modelNode, true);
|
||||
@@ -119,4 +137,24 @@ ModelNode NodeListProperty::at(int index) const
|
||||
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
|
||||
|
Reference in New Issue
Block a user