OpenToonz - An open-source full-featured 2D animation creation software
C
Add Vector Align and Distribute Commands
Rodneya4d7d08e5686
diff --git a/LICENSE.txt b/LICENSE.txtindex d3a165a46..d837fe774 100644--- a/LICENSE.txt+++ b/LICENSE.txt@@ -6,6 +6,10 @@ For files in the "stuff/library/mypaint brushes" directory: Please see the licenOpenToonz+Portions adapted from Tahoma2D's vector alignment commands and panel:+Copyright (c) 2016 - 2023, John Dancel (manongjohn)+All rights reserved.+All contributions by DWANGO:Copyright (c) 2016 - 2026, DWANGO Co., Ltd.All rights reserved.@@ -30,4 +34,4 @@ Redistribution and use in source and binary forms, with or without modification,3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\ No newline at end of file+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.diff --git a/doc/vector_alignment.md b/doc/vector_alignment.mdnew file mode 100644index 000000000..48b827772--- /dev/null+++ b/doc/vector_alignment.md@@ -0,0 +1,82 @@+# Vector alignment and distribution++Adapted for OpenToonz from [Tahoma2D PR #1275](https://github.com/tahoma2d/tahoma2d/pull/1275),+**Vector Control Point/Stroke Alignment Commands**, by **John Dancel (manongjohn)**.+The original panel, icons and alignment behavior are the source of this port.+The commit preserves co-author credit; the applicable BSD copyright notice is+retained in `LICENSE.txt`.++Open **Windows > Align and Distribute Panel**. With the Selection Tool, select+vector strokes or groups. With the Control Point Editor Tool, select control+points on one stroke. The panel offers left, right, top, bottom, two center+alignments, and horizontal/vertical distribution. All eight commands can also+be assigned shortcuts or added to a command bar. Set Linear Control Point and+Set Nonlinear Control Point are registered commands as well.++Existing saved Windows room menus gain the panel entry when loaded. There is+no need to reset room layouts or remove customized menus. A panel entry already+present in a submenu keeps its existing placement and label.++## References and scope++- Stroke alignment: Selection Area, First Selected, Last Selected, Smallest+ Object, Largest Object, or Camera Area.+- Control points: Selection Area, First Selected, or Last Selected.+- Distribution: centers are evenly spaced between the two outer objects,+ which stay fixed. Camera Area distribution puts the outer object edges on+ the camera bounds and evenly spaces the centers.+- A group counts as one object. Entered groups are respected; nested groups+ move together without changing internal positions.+- First/Last Selected uses click order. Bulk selections have the existing+ deterministic stroke/control-point index order.+- The displayed vector drawing is edited. Multi-frame and whole-level+ selections are deliberately excluded; raster drawings are unsupported.+- Camera bounds use the current animated camera and column placement. A+ rotated camera is represented by its axis-aligned bounds in drawing space.+- Read-only levels/frames, locked columns, and active editing drags are+ guarded. Commands that would change nothing add no undo entry.++OpenToonz's ordered sets remain the selection API. A separate order list is+used only for alignment references, preserving existing copy/paste,+deformation, grouping and thickness code. Stroke edits notify the vector+image of changed geometry and preserve fill information in undo/redo.+Point edits use the existing editor's handle movement and undo implementation;+selection-preserving undo is enabled only for the new alignment operations.+Panel state never enables or disables another component's global actions.++## Validation++The standalone numerical regression checks cover all eight operations,+reference methods, camera distribution with two objects, coincident centers,+empty/single selections and zero-area control-point bounds. From the repo root:++```sh+g++ -std=c++17 -DLINUX -Itoonz/sources/include \+ toonz/sources/tnztools/tests/vectoralignment_test.cpp \+ -o /tmp/vectoralignment_test+/tmp/vectoralignment_test+```++Local validation also includes C++17/Qt 5.15 syntax compilation of all changed+implementation files, Qt moc/resource generation, XML/resource checks and+clang-format 14 checks. An offscreen Qt menu-loading check covers saved-menu+migration, preserved labels/order, nested panel entries, duplicate handling,+and all seven shipped menus containing a Windows menu. A complete application+build and interactive Windows testing are separate from these checks.++Interactive verification before merging:++1. Align individual strokes and nested groups with each reference method;+ confirm first/last selection follows click order and groups retain shape.+2. Distribute three strokes or points; confirm the two outer centers stay+ fixed. Distribute two objects within Camera Area; confirm finite results.+3. Undo/redo repeatedly, including after changing the current frame/tool;+ verify fills, selection bounds, handles and saved/reloaded geometry.+4. Try raster, locked/read-only and multi-frame selections. Switch tools and+ open/close multiple panels; verify availability and shortcut behavior.+5. Verify Camera Area with animated camera/column transforms and a zero-scale+ column. Existing scene renders change only after an explicit edit command.++AI assistance: Codex (GPT-6) adapted and reviewed the port in response to the+request to extract the pertinent code from PR #1275 for OT-Dev and credit+manongjohn. Interactive application behavior remains to be verified.diff --git a/stuff/profiles/layouts/rooms/Default/menubar_template.xml b/stuff/profiles/layouts/rooms/Default/menubar_template.xmlindex 53be08e71..f028afdff 100644--- a/stuff/profiles/layouts/rooms/Default/menubar_template.xml+++ b/stuff/profiles/layouts/rooms/Default/menubar_template.xml@@ -333,6 +333,7 @@<command>MI_OpenStopMotionPanel</command><command>MI_StartupPopup</command><command>MI_OpenGuidedDrawingControls</command>+ <command>MI_OpenAlignmentPanel</command><command>MI_OpenCustomPanels</command><separator/><command>MI_MaximizePanel</command>diff --git a/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml b/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xmlindex 2d3a52748..a71275ab5 100644--- a/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml+++ b/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml@@ -218,10 +218,11 @@<command>MI_OpenXshView</command><command>MI_OpenHistoryPanel</command><command>MI_OpenCustomPanels</command>+ <command>MI_OpenAlignmentPanel</command><separator/><command>MI_ResetRoomLayout</command></menu><menu title="Help"><command>MI_About</command></menu>-</menubar>\ No newline at end of file+</menubar>diff --git a/toonz/sources/include/tools/strokeselection.h b/toonz/sources/include/tools/strokeselection.hindex 97b969c9a..61cfec0d5 100644--- a/toonz/sources/include/tools/strokeselection.h+++ b/toonz/sources/include/tools/strokeselection.h@@ -14,6 +14,8 @@// STD includes#include <set>+#include <vector>+#include "tools/vectoralignment.h"#undef DVAPI#undef DVVAR@@ -61,7 +63,10 @@ public:TGroupCommand *getGroupCommand() { return m_groupCommand.get(); }- void setImage(const TVectorImageP &image) { m_vi = image; }+ void setImage(const TVectorImageP &image) {+ if (m_vi != image) m_selectionOrder.clear();+ m_vi = image;+ }const TVectorImageP &getImage() const { return m_vi; }const IndexesContainer &getSelection() const { return m_indexes; }@@ -72,7 +77,10 @@ public:bool isSelected(int index) const { return (m_indexes.count(index) > 0); }void select(int index, bool on);void toggle(int index);- void selectNone() override { m_indexes.clear(); }+ void selectNone() override {+ m_indexes.clear();+ m_selectionOrder.clear();+ }void setSceneHandle(TSceneHandle *tsh) { m_sceneHandle = tsh; }@@ -95,12 +103,16 @@ public:void enableCommands() override;void selectAll();+ void alignStrokes(VectorAlignment::Type type);+ void notifyAlignmentChanged();private:+ std::vector<int> selectionOrder() const;void saveSelectedVectors(bool chooseDestination);TVectorImageP m_vi; //!< Selected vector image.IndexesContainer m_indexes; //!< Selected stroke indexes in m_vi.+ std::vector<int> m_selectionOrder;std::unique_ptr<TGroupCommand> m_groupCommand; //!< Groups commands wrapper.TSceneHandle *m_sceneHandle; //!< Global scene handle. \deprecated Usediff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.hindex 1a5e655c7..1bb534c5f 100644--- a/toonz/sources/include/tools/tool.h+++ b/toonz/sources/include/tools/tool.h@@ -12,6 +12,7 @@// TnzCore includes#include "tcommon.h"+#include "tools/vectoralignment.h"#include "tgeometry.h"#include "tfilepath.h"@@ -558,6 +559,11 @@ transformation.void setCanUndo(bool on) { m_canUndo = on; }bool isUndoable() const { return m_canUndo; }+ void setAlignMethod(VectorAlignment::Method method) {+ m_alignMethod = method;+ }+ VectorAlignment::Method getAlignMethod() const { return m_alignMethod; }+void tweenSelectedGuideStrokes();void tweenGuideStrokeToSelected();void flipGuideStrokeDirection(int mode);@@ -591,6 +597,7 @@ protected:bool m_enabled; //!< Whether the tool allows user interaction.bool m_canUndo = true; //!< Whether the tool allows the user to undo while the tool is selected+ VectorAlignment::Method m_alignMethod = VectorAlignment::SELECT_AREA;bool m_active;bool m_picking;diff --git a/toonz/sources/include/tools/toolutils.h b/toonz/sources/include/tools/toolutils.hindex 27adacf9e..89b516a49 100644--- a/toonz/sources/include/tools/toolutils.h+++ b/toonz/sources/include/tools/toolutils.h@@ -405,9 +405,11 @@ class UndoControlPointEditor final : public TToolUndo {int m_row;int m_column;+ bool m_clearSelection;public:- UndoControlPointEditor(TXshSimpleLevel *level, const TFrameId &frameId);+ UndoControlPointEditor(TXshSimpleLevel *level, const TFrameId &frameId,+ bool clearSelection = true);~UndoControlPointEditor();void onAdd() override;diff --git a/toonz/sources/include/tools/vectoralignment.h b/toonz/sources/include/tools/vectoralignment.hnew file mode 100644index 000000000..fa10ebf12--- /dev/null+++ b/toonz/sources/include/tools/vectoralignment.h@@ -0,0 +1,128 @@+#pragma once++#ifndef VECTOR_ALIGNMENT_INCLUDED+#define VECTOR_ALIGNMENT_INCLUDED++// Adapted from manongjohn's Tahoma2D PR #1275.+// Keep the geometry independent of tools, selection containers and panel UI.+#include "tgeometry.h"+#include <algorithm>+#include <numeric>+#include <vector>++namespace VectorAlignment {++enum Type {+ ALIGN_LEFT,+ ALIGN_RIGHT,+ ALIGN_TOP,+ ALIGN_BOTTOM,+ ALIGN_CENTER_H,+ ALIGN_CENTER_V,+ DISTRIBUTE_H,+ DISTRIBUTE_V+};++enum Method {+ SELECT_AREA,+ FIRST_SELECTED,+ LAST_SELECTED,+ SMALLEST_OBJECT,+ LARGEST_OBJECT,+ CAMERA_AREA+};++inline bool isDistribution(Type type) {+ return type == DISTRIBUTE_H || type == DISTRIBUTE_V;+}++// boxes are in selection order; a group occupies one entry.+inline std::vector<TPointD> offsets(const std::vector<TRectD> &boxes, Type type,+ Method method,+ const TRectD &camera = TRectD()) {+ std::vector<TPointD> result(boxes.size());+ if (boxes.empty()) return result;+ if (isDistribution(type)) {+ if (method != SELECT_AREA && method != CAMERA_AREA) return result;+ if (boxes.size() < (method == CAMERA_AREA ? 2u : 3u)) return result;+ bool horizontal = type == DISTRIBUTE_H;+ auto center = [horizontal](const TRectD &box) {+ return horizontal ? (box.x0 + box.x1) * 0.5 : (box.y0 + box.y1) * 0.5;+ };+ std::vector<size_t> sorted(boxes.size());+ std::iota(sorted.begin(), sorted.end(), 0);+ std::stable_sort(sorted.begin(), sorted.end(), [&](size_t a, size_t b) {+ return center(boxes[a]) < center(boxes[b]);+ });+ double first = center(boxes[sorted.front()]);+ double last = center(boxes[sorted.back()]);+ if (method == CAMERA_AREA) {+ const TRectD &a = boxes[sorted.front()], &b = boxes[sorted.back()];+ first = horizontal ? camera.x0 + a.getLx() * 0.5+ : camera.y0 + a.getLy() * 0.5;+ last = horizontal ? camera.x1 - b.getLx() * 0.5+ : camera.y1 - b.getLy() * 0.5;+ if (last < first) return result;+ }+ double spacing = (last - first) / (boxes.size() - 1);+ for (size_t i = 0; i < sorted.size(); ++i) {+ // Selection-area distribution keeps the two outer objects fixed.+ if (method == SELECT_AREA && (i == 0 || i + 1 == sorted.size())) continue;+ double delta = first + spacing * i - center(boxes[sorted[i]]);+ result[sorted[i]] = horizontal ? TPointD(delta, 0) : TPointD(0, delta);+ }+ return result;+ }+ if (boxes.size() < 2 && method != CAMERA_AREA) return result;+ TRectD anchor = boxes.front();+ if (method == CAMERA_AREA)+ anchor = camera;+ else if (method == LAST_SELECTED)+ anchor = boxes.back();+ else if (method == SELECT_AREA) {+ for (const TRectD &box : boxes) {+ anchor.x0 = std::min(anchor.x0, box.x0);+ anchor.y0 = std::min(anchor.y0, box.y0);+ anchor.x1 = std::max(anchor.x1, box.x1);+ anchor.y1 = std::max(anchor.y1, box.y1);+ }+ } else if (method == SMALLEST_OBJECT || method == LARGEST_OBJECT) {+ for (const TRectD &box : boxes) {+ double area = box.getLx() * box.getLy();+ double anchorArea = anchor.getLx() * anchor.getLy();+ if ((method == SMALLEST_OBJECT && area < anchorArea) ||+ (method == LARGEST_OBJECT && area > anchorArea))+ anchor = box;+ }+ }+ for (size_t i = 0; i < boxes.size(); ++i) {+ const TRectD &box = boxes[i];+ switch (type) {+ case ALIGN_LEFT:+ result[i].x = anchor.x0 - box.x0;+ break;+ case ALIGN_RIGHT:+ result[i].x = anchor.x1 - box.x1;+ break;+ case ALIGN_TOP:+ result[i].y = anchor.y1 - box.y1;+ break;+ case ALIGN_BOTTOM:+ result[i].y = anchor.y0 - box.y0;+ break;+ case ALIGN_CENTER_H:+ result[i].y = (anchor.y0 + anchor.y1 - box.y0 - box.y1) * 0.5;+ break;+ case ALIGN_CENTER_V:+ result[i].x = (anchor.x0 + anchor.x1 - box.x0 - box.x1) * 0.5;+ break;+ default:+ break;+ }+ }+ return result;+}++} // namespace VectorAlignment++#endifdiff --git a/toonz/sources/include/toonzqt/selectioncommandids.h b/toonz/sources/include/toonzqt/selectioncommandids.hindex 7871fd955..d44c6ef98 100644--- a/toonz/sources/include/toonzqt/selectioncommandids.h+++ b/toonz/sources/include/toonzqt/selectioncommandids.h@@ -44,4 +44,15 @@#define MI_PasteNumbers "MI_PasteNumbers"#define MI_PasteCellContent "MI_PasteCellContent"+#define MI_AlignLeft "MI_AlignLeft"+#define MI_AlignRight "MI_AlignRight"+#define MI_AlignTop "MI_AlignTop"+#define MI_AlignBottom "MI_AlignBottom"+#define MI_AlignCenterHorizontal "MI_AlignCenterHorizontal"+#define MI_AlignCenterVertical "MI_AlignCenterVertical"+#define MI_DistributeHorizontal "MI_DistributeHorizontal"+#define MI_DistributeVertical "MI_DistributeVertical"+#define MI_SetLinearControlPoint "MI_SetLinearControlPoint"+#define MI_SetNonLinearControlPoint "MI_SetNonLinearControlPoint"+#endifdiff --git a/toonz/sources/tnztools/CMakeLists.txt b/toonz/sources/tnztools/CMakeLists.txtindex b2467d305..14e3b4ef7 100644--- a/toonz/sources/tnztools/CMakeLists.txt+++ b/toonz/sources/tnztools/CMakeLists.txt@@ -42,6 +42,7 @@ set(HEADERS../include/tools/levelselection.h../include/tools/rasterselection.h../include/tools/strokeselection.h+ ../include/tools/vectoralignment.h../include/tools/stylepicker.h../include/tools/tool.h../include/tools/toolcommandids.hdiff --git a/toonz/sources/tnztools/controlpointeditortool.cpp b/toonz/sources/tnztools/controlpointeditortool.cppindex e0b71b55c..62844f7be 100644--- a/toonz/sources/tnztools/controlpointeditortool.cpp+++ b/toonz/sources/tnztools/controlpointeditortool.cpp@@ -20,6 +20,7 @@#include "toonz/stage2.h"#include "toonz/tstageobject.h"+#include "toonzqt/tselectionhandle.h"#include <QKeyEvent>using namespace ToolUtils;@@ -942,13 +943,20 @@ void ControlPointEditorTool::onActivate() {break;}m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);+ m_selection.selectNone();+ m_selection.makeCurrent();m_draw = true;resetSnap();}//----------------------------------------------------------------------------void ControlPointEditorTool::onDeactivate() { m_draw = false; }+void ControlPointEditorTool::onDeactivate() {+ m_draw = false;+ if (TTool::getApplication()->getCurrentSelection()->getSelection() ==+ &m_selection)+ m_selection.makeNotCurrent();+}//---------------------------------------------------------------------------@@ -1038,4 +1046,4 @@ void ControlPointEditorTool::closeFreehand(const TPointD &pos) {m_stroke->setStyle(1);}-ControlPointEditorTool controlPointEditorTool;\ No newline at end of file+ControlPointEditorTool controlPointEditorTool;diff --git a/toonz/sources/tnztools/controlpointselection.cpp b/toonz/sources/tnztools/controlpointselection.cppindex 159dbf000..7d8a2ed6e 100644--- a/toonz/sources/tnztools/controlpointselection.cpp+++ b/toonz/sources/tnztools/controlpointselection.cpp@@ -7,6 +7,10 @@#include "tools/toolhandle.h"#include "tools/toolutils.h"+#include "tools/strokeselection.h"+#include "toonzqt/selectioncommandids.h"+#include "toonzqt/tselectionhandle.h"+#include <QMutexLocker>#include "toonz/tobjecthandle.h"#include "toonz/txshlevelhandle.h"@@ -1077,13 +1081,29 @@ bool ControlPointSelection::isSelected(int index) const {//-----------------------------------------------------------------------------void ControlPointSelection::select(int index) {- m_selectedPoints.insert(index);+ bool wasEmpty = isEmpty();+ if (m_selectedPoints.insert(index).second) m_selectionOrder.push_back(index);+ if (wasEmpty && !isEmpty() && TSelection::getCurrent() == this)+ TSelectionHandle::getCurrent()->notifySelectionChanged();}//-----------------------------------------------------------------------------void ControlPointSelection::unselect(int index) {m_selectedPoints.erase(index);+ m_selectionOrder.erase(+ std::remove(m_selectionOrder.begin(), m_selectionOrder.end(), index),+ m_selectionOrder.end());+ if (isEmpty() && TSelection::getCurrent() == this)+ TSelectionHandle::getCurrent()->notifySelectionChanged();+}++void ControlPointSelection::selectNone() {+ bool wasEmpty = isEmpty();+ m_selectedPoints.clear();+ m_selectionOrder.clear();+ if (!wasEmpty && TSelection::getCurrent() == this)+ TSelectionHandle::getCurrent()->notifySelectionChanged();}//-----------------------------------------------------------------------------@@ -1095,13 +1115,11 @@ void ControlPointSelection::addMenuItems(QMenu *menu) {m_controlPointEditorStroke->getControlPointCount() <= 1))return;- QAction *linear = menu->addAction(tr("Set Linear Control Point"));- QAction *unlinear = menu->addAction(tr("Set Nonlinear Control Point"));+ menu->addAction(+ CommandManager::instance()->getAction(MI_SetLinearControlPoint));+ menu->addAction(+ CommandManager::instance()->getAction(MI_SetNonLinearControlPoint));menu->addSeparator();-- connect(linear, &QAction::triggered, this, &ControlPointSelection::setLinear);- connect(unlinear, &QAction::triggered, this,- &ControlPointSelection::setUnlinear);}//-----------------------------------------------------------------------------@@ -1269,4 +1287,89 @@ void ControlPointSelection::deleteControlPoints() {void ControlPointSelection::enableCommands() {enableCommand(this, "MI_Clear", &ControlPointSelection::deleteControlPoints);+ enableCommand(this, MI_AlignLeft, &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_LEFT);+ enableCommand(this, MI_AlignRight, &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_RIGHT);+ enableCommand(this, MI_AlignTop, &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_TOP);+ enableCommand(this, MI_AlignBottom,+ &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_BOTTOM);+ enableCommand(this, MI_AlignCenterHorizontal,+ &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_CENTER_H);+ enableCommand(this, MI_AlignCenterVertical,+ &ControlPointSelection::alignControlPoints,+ VectorAlignment::ALIGN_CENTER_V);+ enableCommand(this, MI_DistributeHorizontal,+ &ControlPointSelection::alignControlPoints,+ VectorAlignment::DISTRIBUTE_H);+ enableCommand(this, MI_DistributeVertical,+ &ControlPointSelection::alignControlPoints,+ VectorAlignment::DISTRIBUTE_V);+ enableCommand(this, MI_SetLinearControlPoint,+ &ControlPointSelection::setLinear);+ enableCommand(this, MI_SetNonLinearControlPoint,+ &ControlPointSelection::setUnlinear);+}++// Adapted from manongjohn's Tahoma2D PR #1275 using the current OT editor+// and its undo ownership. Handle movement remains in moveControlPoint().+void ControlPointSelection::alignControlPoints(VectorAlignment::Type type) {+ using namespace VectorAlignment;+ TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();+ ControlPointEditorTool *cpTool = dynamic_cast<ControlPointEditorTool *>(tool);+ if (!cpTool || !tool->isEnabled() || cpTool->isBusy() ||+ !m_controlPointEditorStroke || m_selectedPoints.size() < 2)+ return;+ TVectorImageP vi(tool->getImage(false));+ int strokeIndex = m_controlPointEditorStroke->getStrokeIndex();+ if (!vi || strokeIndex < 0 || strokeIndex >= (int)vi->getStrokeCount())+ return;+ Method method = tool->getAlignMethod();+ if (method != SELECT_AREA && method != FIRST_SELECTED &&+ method != LAST_SELECTED)+ method = SELECT_AREA;+ std::vector<int> indexes;+ std::vector<TRectD> boxes;+ for (int index : m_selectionOrder) {+ if (!isSelected(index) || index < 0 ||+ index >= m_controlPointEditorStroke->getControlPointCount())+ continue;+ indexes.push_back(index);+ TThickPoint point = m_controlPointEditorStroke->getControlPoint(index);+ boxes.emplace_back(point.x, point.y, point.x, point.y);+ }+ auto deltas = offsets(boxes, type, method);+ bool changed = std::any_of(deltas.begin(), deltas.end(),+ [](const TPointD &p) { return p != TPointD(); });+ if (!changed) return;+ std::unique_ptr<TUndo> undo;+ if (tool->getApplication()->getCurrentObject()->isSpline()) {+ TXsheet *xsh = tool->getXsheet();+ TStageObject *object =+ xsh ? xsh->getStageObject(tool->getObjectId()) : nullptr;+ if (!object || !object->getSpline()) return;+ undo = std::make_unique<UndoPath>(object->getSpline());+ } else {+ TXshSimpleLevel *level =+ tool->getApplication()->getCurrentLevel()->getSimpleLevel();+ StrokeSelection editable;+ if (!level || !editable.isEditable()) return;+ auto cpUndo = std::make_unique<UndoControlPointEditor>(+ level, tool->getCurrentFid(), false);+ cpUndo->addOldStroke(strokeIndex, vi->getVIStroke(strokeIndex));+ undo = std::move(cpUndo);+ }+ QMutexLocker lock(vi->getMutex());+ vi->findRegions();+ TStroke previous(*vi->getStroke(strokeIndex));+ for (size_t i = 0; i < indexes.size(); ++i)+ if (deltas[i] != TPointD())+ m_controlPointEditorStroke->moveControlPoint(indexes[i], deltas[i]);+ vi->notifyChangedStrokes(strokeIndex, &previous);+ lock.unlock();+ TUndoManager::manager()->add(undo.release());+ tool->notifyImageChanged();}diff --git a/toonz/sources/tnztools/controlpointselection.h b/toonz/sources/tnztools/controlpointselection.hindex 14bad2eef..422dc9217 100644--- a/toonz/sources/tnztools/controlpointselection.h+++ b/toonz/sources/tnztools/controlpointselection.h@@ -166,6 +166,7 @@ class ControlPointSelection final : public QObject, public TSelection {private:std::set<int> m_selectedPoints;+ std::vector<int> m_selectionOrder;int m_strokeIndex = -1;ControlPointEditorStroke* m_controlPointEditorStroke = nullptr;@@ -184,7 +185,7 @@ public:// Selection interface implementationbool isEmpty() const override { return m_selectedPoints.empty(); }- void selectNone() override { m_selectedPoints.clear(); }+ void selectNone() override;// Selection managementbool isSelected(int index) const;@@ -193,6 +194,7 @@ public:// Delete selected control pointsvoid deleteControlPoints();+ void alignControlPoints(VectorAlignment::Type type);// Context menu managementvoid addMenuItems(QMenu* menu);diff --git a/toonz/sources/tnztools/strokeselection.cpp b/toonz/sources/tnztools/strokeselection.cppindex c7170958b..191c961e2 100644--- a/toonz/sources/tnztools/strokeselection.cpp+++ b/toonz/sources/tnztools/strokeselection.cpp@@ -1,6 +1,10 @@#include "tools/strokeselection.h"+#include "vectorselectiontool.h"+#include "toonz/tcolumnhandle.h"+#include "toonz/tcamera.h"+#include <cmath>// TnzTools includes#include "tools/imagegrouping.h"@@ -530,6 +534,7 @@ StrokeSelection::~StrokeSelection() {}StrokeSelection::StrokeSelection(const StrokeSelection &other): m_vi(other.m_vi), m_indexes(other.m_indexes)+ , m_selectionOrder(other.m_selectionOrder), m_groupCommand(new TGroupCommand()), m_sceneHandle(other.m_sceneHandle), m_updateSelectionBBox(other.m_updateSelectionBBox) {@@ -541,6 +546,7 @@ StrokeSelection::StrokeSelection(const StrokeSelection &other)StrokeSelection &StrokeSelection::operator=(const StrokeSelection &other) {m_vi = other.m_vi;m_indexes = other.m_indexes;+ m_selectionOrder = other.m_selectionOrder;m_sceneHandle = other.m_sceneHandle;m_updateSelectionBBox = other.m_updateSelectionBBox;@@ -550,21 +556,19 @@ StrokeSelection &StrokeSelection::operator=(const StrokeSelection &other) {//-----------------------------------------------------------------------------void StrokeSelection::select(int index, bool on) {- if (on)- m_indexes.insert(index);- else+ if (m_selectionOrder.size() != m_indexes.size())+ m_selectionOrder = selectionOrder();+ if (on) {+ if (m_indexes.insert(index).second) m_selectionOrder.push_back(index);+ } else {m_indexes.erase(index);+ m_selectionOrder.erase(+ std::remove(m_selectionOrder.begin(), m_selectionOrder.end(), index),+ m_selectionOrder.end());+ }}-//-------------------------------------------------------------------------------void StrokeSelection::toggle(int index) {- std::set<int>::iterator it = m_indexes.find(index);- if (it == m_indexes.end())- m_indexes.insert(index);- else- m_indexes.erase(it);-}+void StrokeSelection::toggle(int index) { select(index, !isSelected(index)); }//=============================================================================//@@ -1035,6 +1039,22 @@ void StrokeSelection::enableCommands() {enableCommand(this, MI_RemoveEndpoints, &StrokeSelection::removeEndpoints);enableCommand(this, MI_SortWithPaletteOrder, &StrokeSelection::sortWithPaletteOrder);enableCommand(this, MI_SelectAll, &StrokeSelection::selectAll);+ enableCommand(this, MI_AlignLeft, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_LEFT);+ enableCommand(this, MI_AlignRight, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_RIGHT);+ enableCommand(this, MI_AlignTop, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_TOP);+ enableCommand(this, MI_AlignBottom, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_BOTTOM);+ enableCommand(this, MI_AlignCenterHorizontal, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_CENTER_H);+ enableCommand(this, MI_AlignCenterVertical, &StrokeSelection::alignStrokes,+ VectorAlignment::ALIGN_CENTER_V);+ enableCommand(this, MI_DistributeHorizontal, &StrokeSelection::alignStrokes,+ VectorAlignment::DISTRIBUTE_H);+ enableCommand(this, MI_DistributeVertical, &StrokeSelection::alignStrokes,+ VectorAlignment::DISTRIBUTE_V);}//===================================================================@@ -1156,3 +1176,207 @@ bool StrokeSelection::isEditable() {return true;}++// Adapted from manongjohn's Tahoma2D PR #1275. A selected group is one+// alignment object, including every member below the currently entered group.+namespace {+struct AlignmentObject {+ std::vector<int> strokes;+ TRectD box;+};++std::vector<AlignmentObject> alignmentObjects(const TVectorImageP &vi,+ const std::vector<int> &order) {+ std::vector<AlignmentObject> objects;+ std::set<int> included;+ int depth = vi->isInsideGroup();+ for (int index : order) {+ if (index < 0 || index >= (int)vi->getStrokeCount() ||+ included.count(index) || !vi->isEnteredGroupStroke(index))+ continue;+ AlignmentObject object;+ object.strokes.push_back(index);+ object.box = vi->getStroke(index)->getBBox();+ included.insert(index);+ if (vi->getGroupDepth(index) > depth) {+ for (int i = 0; i < (int)vi->getStrokeCount(); ++i) {+ if (included.count(i) || !vi->isEnteredGroupStroke(i) ||+ vi->getCommonGroupDepth(index, i) <= depth)+ continue;+ object.strokes.push_back(i);+ object.box += vi->getStroke(i)->getBBox();+ included.insert(i);+ }+ }+ objects.push_back(object);+ }+ return objects;+}++class AlignStrokesUndo final : public ToolUtils::TToolUndo {+ std::vector<int> m_indexes;+ std::vector<std::unique_ptr<TStroke>> m_before, m_after;+ std::vector<TFilledRegionInf> m_beforeRegions, m_afterRegions;++ void apply(bool forward) const {+ TVectorImageP vi = m_level->getFrame(m_frameId, true);+ if (!vi) return;+ QMutexLocker lock(vi->getMutex());+ const auto &target = forward ? m_after : m_before;+ std::vector<std::unique_ptr<TStroke>> previous;+ std::vector<TStroke *> previousPtrs;+ for (size_t i = 0; i < m_indexes.size(); ++i) {+ int index = m_indexes[i];+ if (index < 0 || index >= (int)vi->getStrokeCount()) return;+ TStroke *stroke = vi->getStroke(index);+ if (stroke->getControlPointCount() != target[i]->getControlPointCount())+ return;+ previous.emplace_back(new TStroke(*stroke));+ previousPtrs.push_back(previous.back().get());+ }+ vi->findRegions();+ for (size_t i = 0; i < m_indexes.size(); ++i) {+ TStroke *stroke = vi->getStroke(m_indexes[i]);+ for (int j = 0; j < stroke->getControlPointCount(); ++j)+ stroke->setControlPoint(j, target[i]->getControlPoint(j));+ }+ vi->notifyChangedStrokes(m_indexes, previousPtrs);+ ImageUtils::assignFillingInformation(+ *vi, forward ? m_afterRegions : m_beforeRegions);+ lock.unlock();+ m_level->touchFrame(m_frameId);+ notifyImageChanged();+ TTool::Application *app = TTool::getApplication();+ TTool *tool = app->getCurrentTool()->getTool();+ if (tool && TVectorImageP(tool->getImage(false)) == vi) {+ StrokeSelection *selection = dynamic_cast<StrokeSelection *>(+ app->getCurrentSelection()->getSelection());+ if (selection)+ selection->notifyAlignmentChanged();+ else+ tool->notifyImageChanged();+ }+ app->getCurrentXsheet()->notifyXsheetChanged();+ }++public:+ AlignStrokesUndo(TXshSimpleLevel *level, const TFrameId &fid,+ const TVectorImageP &vi, const std::vector<int> &indexes)+ : TToolUndo(level, fid), m_indexes(indexes) {+ for (int index : indexes)+ m_before.emplace_back(new TStroke(*vi->getStroke(index)));+ ImageUtils::getFillingInformationOverlappingArea(vi, m_beforeRegions,+ vi->getBBox());+ }+ void captureAfter(const TVectorImageP &vi) {+ for (int index : m_indexes)+ m_after.emplace_back(new TStroke(*vi->getStroke(index)));+ ImageUtils::getFillingInformationOverlappingArea(vi, m_afterRegions,+ vi->getBBox());+ }+ void undo() const override { apply(false); }+ void redo() const override { apply(true); }+ int getSize() const override {+ int size = sizeof(*this);+ for (const auto &stroke : m_before)+ size += 2 * (sizeof(TStroke) ++ stroke->getControlPointCount() * sizeof(TThickPoint));+ return size + (m_beforeRegions.size() + m_afterRegions.size()) *+ sizeof(TFilledRegionInf);+ }+ QString getHistoryString() override {+ return QObject::tr("Align and Distribute Vector Strokes");+ }+};+} // namespace++std::vector<int> StrokeSelection::selectionOrder() const {+ std::vector<int> order;+ std::set<int> remaining = m_indexes;+ for (int index : m_selectionOrder)+ if (remaining.erase(index)) order.push_back(index);+ // Existing callers can populate the set directly (paste, select all, etc.).+ order.insert(order.end(), remaining.begin(), remaining.end());+ return order;+}++void StrokeSelection::notifyAlignmentChanged() {+ TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();+ if (!tool) return;+ m_updateSelectionBBox = true;+ tool->notifyImageChanged();+ m_updateSelectionBBox = false;+}++void StrokeSelection::alignStrokes(VectorAlignment::Type type) {+ using namespace VectorAlignment;+ TTool::Application *app = TTool::getApplication();+ TTool *tool = app->getCurrentTool()->getTool();+ TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel();+ if (!m_vi || isEmpty() || !tool || !tool->isEnabled() || !level ||+ app->getCurrentObject()->isSpline() || tool->isDragging())+ return;+ if (TVectorImageP(tool->getImage(false)) != m_vi) return;+ // These commands operate on the displayed drawing only. Multi-frame/level+ // selection has different semantics and is deliberately left to its tool.+ VectorSelectionTool *selectionTool =+ dynamic_cast<VectorSelectionTool *>(tool);+ if (!selectionTool || selectionTool->isLevelType() ||+ selectionTool->isSelectedFramesType())+ return;+ if (!isEditable()) {+ DVGui::error(QObject::tr("The selection is not editable."));+ return;+ }+ QMutexLocker lock(m_vi->getMutex());+ auto objects = alignmentObjects(m_vi, selectionOrder());+ std::vector<TRectD> boxes;+ for (const auto &object : objects) boxes.push_back(object.box);+ Method method = tool->getAlignMethod();+ TRectD camera;+ if (method == CAMERA_AREA) {+ ToonzScene *scene = app->getCurrentScene()->getScene();+ if (!scene || !scene->getCurrentCamera()) return;+ camera = scene->getCurrentCamera()->getStageRect();+ if (!app->getCurrentFrame()->isEditingLevel()) {+ int col = app->getCurrentColumn()->getColumnIndex();+ TXsheet *xsh = tool->getXsheet();+ if (!xsh || col < 0) return;+ int frame = app->getCurrentFrame()->getFrameIndex();+ TAffine levelAff =+ xsh->getPlacement(TStageObjectId::ColumnId(col), frame);+ if (std::abs(levelAff.det()) < 1e-12) return;+ TAffine cameraAff = xsh->getPlacement(+ TStageObjectId::CameraId(xsh->getCameraColumnIndex()), frame);+ // Align to the camera's axis-aligned bounds in drawing coordinates.+ camera = (levelAff.inv() * cameraAff) * camera;+ }+ }+ auto deltas = offsets(boxes, type, method, camera);+ std::vector<int> indexes;+ for (size_t i = 0; i < objects.size(); ++i)+ if (deltas[i] != TPointD())+ indexes.insert(indexes.end(), objects[i].strokes.begin(),+ objects[i].strokes.end());+ if (indexes.empty()) return;+ m_vi->findRegions();+ auto undo = std::make_unique<AlignStrokesUndo>(level, tool->getCurrentFid(),+ m_vi, indexes);+ std::vector<std::unique_ptr<TStroke>> previous;+ std::vector<TStroke *> previousPtrs;+ for (size_t i = 0; i < objects.size(); ++i) {+ if (deltas[i] == TPointD()) continue;+ for (int index : objects[i].strokes) {+ TStroke *stroke = m_vi->getStroke(index);+ previous.emplace_back(new TStroke(*stroke));+ previousPtrs.push_back(previous.back().get());+ stroke->transform(TTranslation(deltas[i]));+ }+ }+ m_vi->notifyChangedStrokes(indexes, previousPtrs);+ undo->captureAfter(m_vi);+ lock.unlock();+ TUndoManager::manager()->add(undo.release());+ notifyAlignmentChanged();+ app->getCurrentXsheet()->notifyXsheetChanged();+}diff --git a/toonz/sources/tnztools/tests/vectoralignment_test.cpp b/toonz/sources/tnztools/tests/vectoralignment_test.cppnew file mode 100644index 000000000..5e06dc251--- /dev/null+++ b/toonz/sources/tnztools/tests/vectoralignment_test.cpp@@ -0,0 +1,75 @@+// Standalone geometry regression checks; no GUI or application initialization.+// g++ -std=c++17 -DLINUX -I../../include vectoralignment_test.cpp -o+// /tmp/vectoralignment_test+#include "tools/vectoralignment.h"+#include <cmath>+#include <cstdlib>+#include <iostream>++using namespace VectorAlignment;++void expect(double actual, double expected) {+ if (std::abs(actual - expected) < 1e-10) return;+ std::cerr << "Expected " << expected << ", got " << actual << '\n';+ std::exit(1);+}++int main() {+ std::vector<TRectD> boxes = {+ {40, 10, 60, 30}, {0, 0, 10, 10}, {15, 5, 25, 15}};+ auto result = offsets(boxes, ALIGN_LEFT, SELECT_AREA);+ expect(result[0].x, -40);+ expect(result[0].y, 0);+ expect(result[2].x, -15);+ result = offsets(boxes, ALIGN_RIGHT, FIRST_SELECTED);+ expect(result[1].x, 50);+ result = offsets(boxes, ALIGN_TOP, LAST_SELECTED);+ expect(result[0].y, -15);+ result = offsets(boxes, ALIGN_BOTTOM, SELECT_AREA);+ expect(result[0].y, -10);+ result = offsets(boxes, ALIGN_CENTER_H, SELECT_AREA);+ expect(result[0].y, -5);+ expect(result[0].x, 0);+ result = offsets(boxes, ALIGN_CENTER_V, SELECT_AREA);+ expect(result[1].x, 25);+ expect(result[1].y, 0);+ result = offsets(boxes, ALIGN_LEFT, SMALLEST_OBJECT);+ expect(result[0].x, -40);+ result = offsets(boxes, ALIGN_RIGHT, LARGEST_OBJECT);+ expect(result[2].x, 35);+ result = offsets(boxes, DISTRIBUTE_H, SELECT_AREA);+ expect(result[0].x, 0);+ expect(result[1].x, 0);+ expect(result[2].x, 7.5);+ result = offsets(boxes, DISTRIBUTE_V, SELECT_AREA);+ expect(result[2].y, 2.5);+ result = offsets(boxes, DISTRIBUTE_H, FIRST_SELECTED);+ for (const auto &p : result) expect(p.x, 0);+ // Camera distribution places outer edges on the camera bounds and spaces+ // object centers. This remains finite with exactly two objects.+ result = offsets({boxes[0], boxes[1]}, DISTRIBUTE_H, CAMERA_AREA,+ TRectD(0, 0, 100, 100));+ expect(result[0].x, 40);+ expect(result[1].x, 0);+ result = offsets({boxes[0]}, ALIGN_CENTER_V, CAMERA_AREA,+ TRectD(-100, -50, 100, 50));+ expect(result[0].x, -50);+ // Coincident centers, empty selections and undersized selections are safe.+ result = offsets(+ {TRectD(0, 0, 10, 10), TRectD(0, 0, 10, 10), TRectD(0, 0, 10, 10)},+ DISTRIBUTE_H, SELECT_AREA);+ for (const auto &p : result) expect(p.x, 0);+ expect(offsets({}, ALIGN_LEFT, SELECT_AREA).size(), 0);+ result = offsets({boxes[0]}, DISTRIBUTE_H, CAMERA_AREA);+ expect(result[0].x, 0);+ // Control points are zero-area boxes; they must participate in the bounds.+ result = offsets({TRectD(20, 30, 20, 30), TRectD(-10, -5, -10, -5)},+ ALIGN_CENTER_V, SELECT_AREA);+ expect(result[0].x, -15);+ expect(result[1].x, 15);+ result = offsets({TRectD(20, 30, 20, 30), TRectD(-10, -5, -10, -5)},+ ALIGN_CENTER_H, LAST_SELECTED);+ expect(result[0].y, -35);+ expect(result[1].y, 0);+ std::cout << "Vector alignment geometry checks passed\n";+}diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cppindex cadbb4f70..97d7048cf 100644--- a/toonz/sources/tnztools/toolutils.cpp+++ b/toonz/sources/tnztools/toolutils.cpp@@ -1376,8 +1376,10 @@ int ToolUtils::UndoPath::getSize() const { return sizeof(*this) + 500; }//ToolUtils::UndoControlPointEditor::UndoControlPointEditor(- TXshSimpleLevel *level, const TFrameId &frameId)- : TToolUndo(level, frameId), m_isStrokeDelete(false) {+ TXshSimpleLevel *level, const TFrameId &frameId, bool clearSelection)+ : TToolUndo(level, frameId)+ , m_isStrokeDelete(false)+ , m_clearSelection(clearSelection) {TVectorImageP image = level->getFrame(frameId, true);assert(image);if (!image) return;@@ -1424,7 +1426,7 @@ void ToolUtils::UndoControlPointEditor::undo() const {app->getCurrentFrame()->setFid(m_frameId);TSelection *selection = app->getCurrentSelection()->getSelection();- if (selection) selection->selectNone();+ if (m_clearSelection && selection) selection->selectNone();TVectorImageP image = m_level->getFrame(m_frameId, true);assert(image);if (!image) return;@@ -1455,7 +1457,7 @@ void ToolUtils::UndoControlPointEditor::redo() const {} elseapp->getCurrentFrame()->setFid(m_frameId);TSelection *selection = app->getCurrentSelection()->getSelection();- if (selection) selection->selectNone();+ if (m_clearSelection && selection) selection->selectNone();TVectorImageP image = m_level->getFrame(m_frameId, true);assert(image);if (!image) return;diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txtindex f2858a2ab..c0b1e16d7 100644--- a/toonz/sources/toonz/CMakeLists.txt+++ b/toonz/sources/toonz/CMakeLists.txt@@ -113,6 +113,7 @@ set(MOC_HEADERStoolbar.htpanels.htrackerpopup.h+ alignmentpane.hvectorguideddrawingpane.hvectorizerpopup.hvectorizerswatch.h@@ -313,6 +314,7 @@ set(SOURCESkis_tablet_support_win8.cpptimestretchpopup.cpptrackerpopup.cpp+ alignmentpane.cppvectorguideddrawingpane.cppvectorizerpopup.cpprasterizecommand.cppdiff --git a/toonz/sources/toonz/alignmentpane.cpp b/toonz/sources/toonz/alignmentpane.cppnew file mode 100644index 000000000..ca483496e--- /dev/null+++ b/toonz/sources/toonz/alignmentpane.cpp@@ -0,0 +1,237 @@+// Panel and icons adapted from manongjohn, Tahoma2D PR #1275.+#include "alignmentpane.h"+#include "menubarcommandids.h"+#include "tapp.h"++#include "toonz/txshlevelhandle.h"+#include "toonz/txshleveltypes.h"++#include "tools/tool.h"+#include "tools/toolhandle.h"+#include "tools/toolcommandids.h"++#include "toonzqt/menubarcommand.h"+#include "toonzqt/gutil.h"++#include <QComboBox>+#include <QPushButton>+#include <QButtonGroup>+#include <QGridLayout>+#include <QBoxLayout>+#include <QGroupBox>+#include <QLabel>+#include <QSignalBlocker>+#include "toonzqt/selection.h"++AlignmentPane::AlignmentPane(QWidget* parent, Qt::WindowFlags flags)+ : QFrame(parent, flags) {+ setObjectName("AlignmentPanel");++ m_alignMethodCB = new QComboBox();+ m_alignMethodCB->addItem(tr("Selection Area"));+ m_alignMethodCB->setCurrentIndex(0);++ QAction* action;+ m_alignLeftBtn = new QPushButton(createQIcon("select_align_left"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignLeft);+ m_alignLeftBtn->addAction(action);+ m_alignLeftBtn->setToolTip(tr("Align Left"));+ m_alignLeftBtn->setFixedSize(30, 30);+ connect(m_alignLeftBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_alignRightBtn = new QPushButton(createQIcon("select_align_right"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignRight);+ m_alignRightBtn->addAction(action);+ m_alignRightBtn->setToolTip(tr("Align Right"));+ m_alignRightBtn->setFixedSize(30, 30);+ connect(m_alignRightBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_alignTopBtn = new QPushButton(createQIcon("select_align_top"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignTop);+ m_alignTopBtn->addAction(action);+ m_alignTopBtn->setToolTip(tr("Align Top"));+ m_alignTopBtn->setFixedSize(30, 30);+ connect(m_alignTopBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_alignBottomBtn =+ new QPushButton(createQIcon("select_align_bottom"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignBottom);+ m_alignBottomBtn->addAction(action);+ m_alignBottomBtn->setToolTip(tr("Align Bottom"));+ m_alignBottomBtn->setFixedSize(30, 30);+ connect(m_alignBottomBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_alignCenterHBtn =+ new QPushButton(createQIcon("select_align_center_h"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignCenterHorizontal);+ m_alignCenterHBtn->addAction(action);+ m_alignCenterHBtn->setToolTip(tr("Align Center Horizontally"));+ m_alignCenterHBtn->setFixedSize(30, 30);+ connect(m_alignCenterHBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_alignCenterVBtn =+ new QPushButton(createQIcon("select_align_center_v"), 0, this);+ action = CommandManager::instance()->getAction(MI_AlignCenterVertical);+ m_alignCenterVBtn->addAction(action);+ m_alignCenterVBtn->setToolTip(tr("Align Center Vertically"));+ m_alignCenterVBtn->setFixedSize(30, 30);+ connect(m_alignCenterVBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_distributeHBtn =+ new QPushButton(createQIcon("select_distribute_h"), 0, this);+ action = CommandManager::instance()->getAction(MI_DistributeHorizontal);+ m_distributeHBtn->addAction(action);+ m_distributeHBtn->setToolTip(tr("Distribute Horizontally"));+ m_distributeHBtn->setFixedSize(30, 30);+ connect(m_distributeHBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ m_distributeVBtn =+ new QPushButton(createQIcon("select_distribute_v"), 0, this);+ action = CommandManager::instance()->getAction(MI_DistributeVertical);+ m_distributeVBtn->addAction(action);+ m_distributeVBtn->setToolTip(tr("Distribute Vertically"));+ m_distributeVBtn->setFixedSize(30, 30);+ connect(m_distributeVBtn, SIGNAL(clicked()), action, SLOT(trigger()));++ QGridLayout* mainlayout = new QGridLayout();+ mainlayout->setMargin(5);+ mainlayout->setSpacing(2);+ {+ mainlayout->addWidget(new QLabel(tr("Relative to: ")), 0, 0,+ Qt::AlignRight);+ mainlayout->addWidget(m_alignMethodCB, 0, 1);++ QGroupBox* alignBox = new QGroupBox(tr("Align"), this);+ QGridLayout* alignLayout = new QGridLayout();+ alignLayout->setMargin(1);+ alignLayout->setSpacing(1);+ {+ alignLayout->addWidget(m_alignLeftBtn, 0, 0, Qt::AlignCenter);+ alignLayout->addWidget(m_alignCenterVBtn, 0, 1, Qt::AlignCenter);+ alignLayout->addWidget(m_alignRightBtn, 0, 2, Qt::AlignCenter);++ alignLayout->addWidget(m_alignTopBtn, 1, 0, Qt::AlignCenter);+ alignLayout->addWidget(m_alignCenterHBtn, 1, 1, Qt::AlignCenter);+ alignLayout->addWidget(m_alignBottomBtn, 1, 2, Qt::AlignCenter);+ }+ alignBox->setLayout(alignLayout);+ mainlayout->addWidget(alignBox, 1, 0, 1, 2);++ QGroupBox* distributeBox = new QGroupBox(tr("Distribute"), this);+ QGridLayout* distributeLayout = new QGridLayout();+ distributeLayout->setMargin(1);+ distributeLayout->setSpacing(1);+ {+ distributeLayout->addWidget(m_distributeHBtn, 0, 0, Qt::AlignCenter);+ distributeLayout->addWidget(m_distributeVBtn, 0, 1, Qt::AlignCenter);+ }+ distributeBox->setLayout(distributeLayout);+ mainlayout->addWidget(distributeBox, 2, 0, 1, 2);+ }++ setLayout(mainlayout);++ bool ret = true;++ ret = ret && connect(m_alignMethodCB, SIGNAL(currentIndexChanged(int)), this,+ SLOT(onAlignMethodChanged(int)));+ assert(ret);+}++//-----------------------------------------------------------------------------++void AlignmentPane::updateButtons() {+ TTool* tool = TApp::instance()->getCurrentTool()->getTool();+ bool strokes = tool && tool->getName() == T_Selection;+ bool points = tool && tool->getName() == T_ControlPointEditor;+ int method = tool ? tool->getAlignMethod() : VectorAlignment::SELECT_AREA;+ QStringList inputs;+ inputs << tr("Selection Area") << tr("First Selected") << tr("Last Selected");+ if (strokes)+ inputs << tr("Smallest Object") << tr("Largest Object")+ << tr("Camera Area");+ if (method >= inputs.size()) method = VectorAlignment::SELECT_AREA;+ {+ QSignalBlocker blocker(m_alignMethodCB);+ m_alignMethodCB->clear();+ m_alignMethodCB->addItems(inputs);+ m_alignMethodCB->setCurrentIndex(method);+ }+ TSelection* selection =+ TApp::instance()->getCurrentSelection()->getSelection();+ bool enabled = (strokes || points) && tool->isEnabled() && selection &&+ !selection->isEmpty();+ m_alignMethodCB->setEnabled(strokes || points);+ QPushButton* buttons[] = {+ m_alignLeftBtn, m_alignRightBtn, m_alignTopBtn, m_alignBottomBtn,+ m_alignCenterHBtn, m_alignCenterVBtn, m_distributeHBtn, m_distributeVBtn};+ for (int i = 0; i < 8; ++i) {+ QAction* action = buttons[i]->actions().front();+ bool available = enabled && action->isEnabled();+ if (i >= 6)+ available =+ available && (method == VectorAlignment::SELECT_AREA ||+ (strokes && method == VectorAlignment::CAMERA_AREA));+ buttons[i]->setEnabled(available);+ }+}++void AlignmentPane::showEvent(QShowEvent*) {+ TApp* app = TApp::instance();++ bool ret = true;++ ret = ret &&+ connect(app->getCurrentLevel(), SIGNAL(xshLevelSwitched(TXshLevel*)),+ this, SLOT(onLevelSwitched(TXshLevel*)));+ ret = ret && connect(app->getCurrentTool(), SIGNAL(toolSwitched()), this,+ SLOT(onToolSwitched()));+ ret = ret && connect(app->getCurrentTool(), SIGNAL(toolChanged()), this,+ SLOT(onToolSwitched()));+ ret =+ ret && connect(app->getCurrentSelection(),+ SIGNAL(selectionSwitched(TSelection*, TSelection*)), this,+ SLOT(onSelectionSwitched(TSelection*, TSelection*)));++ ret = ret && connect(app->getCurrentSelection(),+ SIGNAL(selectionChanged(TSelection*)), this,+ SLOT(onSelectionChanged()));+ assert(ret);+ updateButtons();+}++//-----------------------------------------------------------------------------++void AlignmentPane::hideEvent(QHideEvent*) {+ TApp* app = TApp::instance();++ disconnect(app->getCurrentLevel(), 0, this, 0);+ disconnect(app->getCurrentTool(), 0, this, 0);+ disconnect(app->getCurrentSelection(), 0, this, 0);+}++//-----------------------------------------------------------------------------++void AlignmentPane::onLevelSwitched(TXshLevel* oldLvl) { updateButtons(); }++//-----------------------------------------------------------------------------++void AlignmentPane::onToolSwitched() { updateButtons(); }++//-----------------------------------------------------------------------------++void AlignmentPane::onAlignMethodChanged(int index) {+ TTool* tool = TApp::instance()->getCurrentTool()->getTool();+ if (!tool) return;+ tool->setAlignMethod(static_cast<VectorAlignment::Method>(index));+ TApp::instance()->getCurrentTool()->notifyToolChanged();+}++//-----------------------------------------------------------------------------++void AlignmentPane::onSelectionSwitched(TSelection* oldSelection,+ TSelection* newSelection) {+ updateButtons();+}++void AlignmentPane::onSelectionChanged() { updateButtons(); }diff --git a/toonz/sources/toonz/alignmentpane.h b/toonz/sources/toonz/alignmentpane.hnew file mode 100644index 000000000..4044f56eb--- /dev/null+++ b/toonz/sources/toonz/alignmentpane.h@@ -0,0 +1,43 @@+#pragma once++#ifndef VECTORALIGNMENTPANE_H+#define VECTORALIGNMENTPANE_H++#include "toonzqt/dvdialog.h"++#include "toonz/txshlevel.h"+#include "toonzqt/tselectionhandle.h"++class QComboBox;+class QPushButton;+class QButtonGroup;++class AlignmentPane final : public QFrame {+ Q_OBJECT++ QComboBox *m_alignMethodCB;++ QPushButton *m_alignLeftBtn, *m_alignRightBtn, *m_alignTopBtn,+ *m_alignBottomBtn, *m_alignCenterHBtn, *m_alignCenterVBtn,+ *m_distributeHBtn, *m_distributeVBtn;++public:+ AlignmentPane(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());+ ~AlignmentPane(){};++private:+ void updateButtons();++protected:+ void showEvent(QShowEvent *) override;+ void hideEvent(QHideEvent *) override;++protected slots:+ void onLevelSwitched(TXshLevel *);+ void onToolSwitched();+ void onSelectionChanged();+ void onAlignMethodChanged(int);+ void onSelectionSwitched(TSelection *, TSelection *);+};++#endif // VECTORALIGNMENTPANE_Hdiff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_bottom.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_bottom.svgnew file mode 100644index 000000000..2e7cda171--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_bottom.svg@@ -0,0 +1,10 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g transform="rotate(90,8,8)">+ <rect x="-16" y="0" width="16" height="16" style="fill-opacity:0" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="1" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="11" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="6" transform="scale(-1,1)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 6,4 V 7 H 1 v 2 h 5 v 3 l 4.03125,-3.96875" />+ </g>+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_center_h.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_center_h.svgnew file mode 100644index 000000000..459b8feed--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_center_h.svg@@ -0,0 +1,9 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect x="0" y="-16" width="16" height="16" style="fill-opacity:0" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-15" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-5" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-10" transform="rotate(90)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 12,15 H 4 l 3.96875,-4.03125" />+ <path style="clip-rule:evenodd;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 12,1 H 4 l 3.96875,4.0000001" />+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_center_v.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_center_v.svgnew file mode 100644index 000000000..d3726b92c--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_center_v.svg@@ -0,0 +1,11 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g transform="rotate(90,8,8)">+ <rect x="0" y="-16" width="16" height="16" style="fill-opacity:0" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-15" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-5" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-10" transform="rotate(90)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 12,15 H 4 l 3.96875,-4.03125" />+ <path style="clip-rule:evenodd;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 12,1 H 4 l 3.96875,4.0000001" />+ </g>+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_left.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_left.svgnew file mode 100644index 000000000..47fb8f3b7--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_left.svg@@ -0,0 +1,8 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect x="0" y="0" width="16" height="16" style="fill-opacity:0;" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="1" y="1" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="1" y="11" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="1" y="6" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="m 10,4 v 3 h 5 v 2 h -5 v 3 L 5.96875,8.03125" />+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_right.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_right.svgnew file mode 100644index 000000000..ab8da9362--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_right.svg@@ -0,0 +1,8 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect x="-16" y="0" width="16" height="16" style="fill-opacity:0" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="1" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="11" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="6" transform="scale(-1,1)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 6,4 V 7 H 1 v 2 h 5 v 3 l 4.03125,-3.96875" />+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_align_top.svg b/toonz/sources/toonz/icons/dark/actions/16/select_align_top.svgnew file mode 100644index 000000000..456560b6c--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_align_top.svg@@ -0,0 +1,10 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g transform="matrix(0,-1,-1,0,16,16)">+ <rect x="-16" y="0" width="16" height="16" style="fill-opacity:0" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="1" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="11" transform="scale(-1,1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-15" y="6" transform="scale(-1,1)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 6,4 V 7 H 1 v 2 h 5 v 3 l 4.03125,-3.96875" />+ </g>+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_distribute_h.svg b/toonz/sources/toonz/icons/dark/actions/16/select_distribute_h.svgnew file mode 100644index 000000000..3c26ab4ac--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_distribute_h.svg@@ -0,0 +1,11 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g transform="rotate(90,8,8)">+ <rect x="-16" y="-16" width="16" height="16" style="fill-opacity:0" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-15" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-5" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-10" transform="scale(-1)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 2,12 H 4 V 9 h 2 v 3 h 2 l -2.96875,3.03125" />+ <path style="clip-rule:evenodd;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 2,4 H 4 V 7 H 6 V 4 H 8 L 5,1" />+ </g>+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/select_distribute_v.svg b/toonz/sources/toonz/icons/dark/actions/16/select_distribute_v.svgnew file mode 100644index 000000000..9b6a9ab4d--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/select_distribute_v.svg@@ -0,0 +1,9 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect x="-16" y="-16" width="16" height="16" style="fill-opacity:0" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-15" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-5" transform="scale(-1)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="-14" y="-10" transform="scale(-1)" />+ <path style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 2,12 H 4 V 9 h 2 v 3 h 2 l -2.96875,3.03125" />+ <path style="clip-rule:evenodd;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 2,4 H 4 V 7 H 6 V 4 H 8 L 5,1" />+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/set_linear_cp.svg b/toonz/sources/toonz/icons/dark/actions/16/set_linear_cp.svgnew file mode 100644index 000000000..f92244db2--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/set_linear_cp.svg@@ -0,0 +1,7 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect x="0" y="-16" width="16" height="16" style="fill-opacity:0" transform="rotate(90)" />+ <rect style="fill:#000000;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-miterlimit:2" width="4" height="4" x="6" y="-10" transform="rotate(90)" />+ <path style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 1,8 H 5" />+ <path style="clip-rule:evenodd;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 15,8 H 11" />+</svg>diff --git a/toonz/sources/toonz/icons/dark/actions/16/set_nonlinear_cp.svg b/toonz/sources/toonz/icons/dark/actions/16/set_nonlinear_cp.svgnew file mode 100644index 000000000..4e83379b1--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/set_nonlinear_cp.svg@@ -0,0 +1,10 @@+<?xml version='1.0' encoding='utf-8'?>+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" version="1.1" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <rect style="clip-rule:evenodd;fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:2" width="4" height="4" x="6" y="-10" transform="rotate(90)" />+ <path style="clip-rule:evenodd;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 4,4 7,7" />+ <path style="clip-rule:evenodd;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-dasharray:none;stroke-opacity:1" d="M 15,5 C 14,5 13,8 11,8" />+ <circle style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:square;stroke-miterlimit:2;stroke-dasharray:none" cx="3" cy="-3" r="1.5" transform="scale(1,-1)" />+ <circle style="clip-rule:evenodd;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:2;stroke-dasharray:none" cx="13" cy="13" r="1.5" />+ <path style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" d="M 1,11 C 2,11 3,8 5,8" />+ <path style="clip-rule:evenodd;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-opacity:1" d="M 12,12 9,9" />+</svg>diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cppindex 23f79a78e..90bfd9b18 100644--- a/toonz/sources/toonz/mainwindow.cpp+++ b/toonz/sources/toonz/mainwindow.cpp@@ -2302,6 +2302,27 @@ void MainWindow::defineActions() {// Menu - Edit+ createMenuEditAction(MI_AlignLeft, QT_TR_NOOP("Align Left"), "",+ "select_align_left");+ createMenuEditAction(MI_AlignRight, QT_TR_NOOP("Align Right"), "",+ "select_align_right");+ createMenuEditAction(MI_AlignTop, QT_TR_NOOP("Align Top"), "",+ "select_align_top");+ createMenuEditAction(MI_AlignBottom, QT_TR_NOOP("Align Bottom"), "",+ "select_align_bottom");+ createMenuEditAction(MI_AlignCenterHorizontal,+ QT_TR_NOOP("Align Center Horizontally"), "",+ "select_align_center_h");+ createMenuEditAction(MI_AlignCenterVertical,+ QT_TR_NOOP("Align Center Vertically"), "",+ "select_align_center_v");+ createMenuEditAction(MI_DistributeHorizontal,+ QT_TR_NOOP("Distribute Horizontally"), "",+ "select_distribute_h");+ createMenuEditAction(MI_DistributeVertical,+ QT_TR_NOOP("Distribute Vertically"), "",+ "select_distribute_v");+createMenuEditAction(MI_SelectAll, QT_TR_NOOP("&Select All"), "Ctrl+A","select_all");createMenuEditAction(MI_InvertSelection, QT_TR_NOOP("&Invert Selection"), "",@@ -2645,6 +2666,12 @@ void MainWindow::defineActions() {createRightClickMenuAction(MI_OpenPltGizmo, QT_TR_NOOP("&Palette Gizmo"), "","palettegizmo");+ createRightClickMenuAction(MI_SetLinearControlPoint,+ QT_TR_NOOP("Set Linear Control Point"), "",+ "set_linear_cp");+ createRightClickMenuAction(MI_SetNonLinearControlPoint,+ QT_TR_NOOP("Set Nonlinear Control Point"), "",+ "set_nonlinear_cp");createRightClickMenuAction(MI_EraseUnusedStyles,QT_TR_NOOP("&Delete Unused Styles"), "","delete_unused_styles");@@ -2808,6 +2835,8 @@ void MainWindow::defineActions() {createMenuHelpAction(MI_About, QT_TR_NOOP("&About OpenToonz..."), "", "info");createMenuWindowsAction(MI_StartupPopup, QT_TR_NOOP("&Startup Popup..."),"Alt+S", "opentoonz");+ createMenuWindowsAction(MI_OpenAlignmentPanel,+ QT_TR_NOOP("Align and Distribute Panel"), "", "");createMenuWindowsAction(MI_OpenGuidedDrawingControls,QT_TR_NOOP("Guided Drawing Controls"), "","guided_drawing");diff --git a/toonz/sources/toonz/menubar.cpp b/toonz/sources/toonz/menubar.cppindex ed8cc4d27..4390d9e34 100644--- a/toonz/sources/toonz/menubar.cpp+++ b/toonz/sources/toonz/menubar.cpp@@ -114,6 +114,28 @@ void ensureHelpActions(QMenu *helpMenu) {enableQuicklinkEditing(helpMenu);}+bool menuContainsAction(QMenu *menu, QAction *target) {+ for (QAction *action : menu->actions()) {+ if (action == target) return true;+ if (action->menu() && menuContainsAction(action->menu(), target))+ return true;+ }+ return false;+}++void ensureAlignmentPanelAction(QMenu *windowsMenu) {+ QAction *alignment =+ CommandManager::instance()->getAction(MI_OpenAlignmentPanel);+ if (!alignment || menuContainsAction(windowsMenu, alignment)) return;++ QAction *customPanels =+ CommandManager::instance()->getAction(MI_OpenCustomPanels);+ if (windowsMenu->actions().contains(customPanels))+ windowsMenu->insertAction(customPanels, alignment);+ else+ windowsMenu->addAction(alignment);+}+} // namespace//=============================================================================@@ -305,6 +327,14 @@ void StackedMenuBar::createMenuBarByName(const QString &roomName) {/* OSX では stacked menu が動いていないのでとりあえず full のみ作成する */addWidget(createFullMenuBar());#endif+ // Legacy room menus also need the panel when no saved menu is available.+ QMenuBar *menuBar = qobject_cast<QMenuBar *>(widget(count() - 1));+ if (menuBar) {+ for (QAction *action : menuBar->actions()) {+ if (action->menu() && action->menu()->title() == tr("Windows"))+ ensureAlignmentPanelAction(action->menu());+ }+ }}//---------------------------------------------------------------------------------@@ -347,6 +377,8 @@ QMenuBar *StackedMenuBar::loadMenuBar(const TFilePath &fp) {// Older Windows profiles keep private menu XML files. Add the new// built-in command without replacing the user's customized menu.if (title == QStringLiteral("Help")) ensureHelpActions(menu);+ if (title == QStringLiteral("Windows"))+ ensureAlignmentPanelAction(menu);menuBar->addMenu(menu);} else {reader.raiseError(tr("Failed to load menu %1").arg(title));@@ -1559,6 +1591,7 @@ QMenuBar *StackedMenuBar::createFullMenuBar() {#endifaddMenuItem(windowsMenu, MI_StartupPopup);addMenuItem(windowsMenu, MI_OpenGuidedDrawingControls);+ addMenuItem(windowsMenu, MI_OpenAlignmentPanel);addMenuItem(windowsMenu, MI_OpenCustomPanels);// windowsMenu->addSeparator();// addMenuItem(windowsMenu, MI_OpenExport);diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.hindex 636e67d92..f4d6a7dd6 100644--- a/toonz/sources/toonz/menubarcommandids.h+++ b/toonz/sources/toonz/menubarcommandids.h@@ -521,4 +521,6 @@#define MI_ClearTags "MI_ClearTags"#define MI_OpenLocator "MI_OpenLocator"+#define MI_OpenAlignmentPanel "MI_OpenAlignmentPanel"+#endifdiff --git a/toonz/sources/toonz/toonz.qrc b/toonz/sources/toonz/toonz.qrcindex 606d6bd19..5115b0e00 100644--- a/toonz/sources/toonz/toonz.qrc+++ b/toonz/sources/toonz/toonz.qrc@@ -1,5 +1,16 @@<RCC><qresource prefix="/">+ <file>icons/dark/actions/16/select_align_left.svg</file>+ <file>icons/dark/actions/16/select_align_right.svg</file>+ <file>icons/dark/actions/16/select_align_top.svg</file>+ <file>icons/dark/actions/16/select_align_bottom.svg</file>+ <file>icons/dark/actions/16/select_align_center_h.svg</file>+ <file>icons/dark/actions/16/select_align_center_v.svg</file>+ <file>icons/dark/actions/16/select_distribute_h.svg</file>+ <file>icons/dark/actions/16/select_distribute_v.svg</file>+ <file>icons/dark/actions/16/set_linear_cp.svg</file>+ <file>icons/dark/actions/16/set_nonlinear_cp.svg</file>+<!-- Note: paths with /colored/ bypass iconEngine's recolor/opacity handling, use for full-color icons --><!-- Tools -->diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cppindex e748318e0..92d2dff94 100644--- a/toonz/sources/toonz/tpanels.cpp+++ b/toonz/sources/toonz/tpanels.cpp@@ -1,6 +1,7 @@#include "tpanels.h"+#include "alignmentpane.h"// Tnz6 includes#include "pane.h"@@ -1799,3 +1800,22 @@ public://=============================================================================OpenFloatingPanel openFxBrowserCommand(MI_InsertFx, "FxBrowser",QObject::tr("FX Browser"));++class AlignmentFactory final : public TPanelFactory {+public:+ AlignmentFactory() : TPanelFactory("AlignmentPanel") {}+ TPanel *createPanel(QWidget *parent) override {+ TPanel *panel = new TPanel(parent);+ panel->setWidget(new AlignmentPane(panel));+ panel->setIsMaximizable(false);+ panel->setObjectName(getPanelType());+ panel->setWindowTitle(QObject::tr("Align and Distribute"));+ panel->setMinimumSize(235, 198);+ return panel;+ }+ void initialize(TPanel *panel) override {}+} alignmentFactory;++OpenFloatingPanel openVectorAlignmentPanelCommand(+ MI_OpenAlignmentPanel, "AlignmentPanel",+ QObject::tr("Align and Distribute"));