Skip to content

Commit

Permalink
CommandPalette: support align actions
Browse files Browse the repository at this point in the history
Ref: #214
  • Loading branch information
rodlie committed Jul 28, 2024
1 parent bf7cdb5 commit 1ad03e9
Showing 1 changed file with 350 additions and 1 deletion.
351 changes: 350 additions & 1 deletion src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ void MainWindow::addRasterEffect(const qsptr<RasterEffect> &rasterEffect)
void MainWindow::setupExtraMenus()
{
const auto menu = new QMenu(this);
// TODO: make a function to add extra actions

// add rotate
{
const auto act = menu->addAction(QIcon::fromTheme("loop"/* TODO: find new (blender) icon! */),
Expand Down Expand Up @@ -1464,6 +1464,355 @@ void MainWindow::setupExtraMenus()
});
cmdAddAction(act);
}
// align
{
const int alignTotal = 28;

const QString alignTextDefault = tr("Align %1 %2 Relative to %3");
const QString alignGeometry = tr("Geometry");
const QString alignPivot = tr("Pivot");
const QString alignScene = tr("Scene");
const QString alignLast = tr("Last Selected");

const QString alignCenter = tr("Center");
const QString alignCenterIcon = "pivot-align-center";

const QString alignLeft = tr("Left");
const QString alignLeftIcon = "pivot-align-left";

const QString alignRight = tr("Right");
const QString alignRightIcon = "pivot-align-right";

const QString alignTop = tr("Top");
const QString alignTopIcon = "pivot-align-top";

const QString alignBottom = tr("Bottom");
const QString alignBottomIcon = "pivot-align-bottom";

const QString alignHCenter = tr("Horizontal Center");
const QString alignHCenterIcon = "pivot-align-hcenter";

const QString alignVCenter = tr("Vertical Center");
const QString alignVCenterIcon = "pivot-align-vcenter";

for (int i = 0; i < alignTotal; i++) {
QString alignString;
QString pivotString;
QString relString;
QString iconString = "alignCenter";
AlignPivot pivot = AlignPivot::geometry;
AlignRelativeTo rel = AlignRelativeTo::scene;
Qt::Alignment align = Qt::AlignLeft;
bool alignBoth = false;

switch(i) {
case 0: // Align Center - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignCenter;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignCenterIcon;
alignBoth = true;
align = Qt::AlignHCenter;
break;
case 1: // Align Center - Pivot Relative to Scene
alignString = alignCenter;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignCenterIcon;
alignBoth = true;
align = Qt::AlignHCenter;
break;
case 2: // Align Center - Geometry Relative to Last Selected
alignString = alignCenter;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignCenterIcon;
alignBoth = true;
align = Qt::AlignHCenter;
break;
case 3: // Align Center - Pivot Relative to Last Selected
alignString = alignCenter;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignCenterIcon;
alignBoth = true;
align = Qt::AlignHCenter;
break;
case 4: // Align Left - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignLeft;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignLeftIcon;
alignBoth = false;
align = Qt::AlignLeft;
break;
case 5: // Align Left - Pivot Relative to Scene
alignString = alignLeft;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignLeftIcon;
alignBoth = false;
align = Qt::AlignLeft;
break;
case 6: // Align Left - Geometry Relative to Last Selected
alignString = alignLeft;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignLeftIcon;
alignBoth = false;
align = Qt::AlignLeft;
break;
case 7: // Align Left - Pivot Relative to Last Selected
alignString = alignLeft;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignLeftIcon;
alignBoth = false;
align = Qt::AlignLeft;
break;
case 8: // Align Right - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignRight;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignRightIcon;
alignBoth = false;
align = Qt::AlignRight;
break;
case 9: // Align Right - Pivot Relative to Scene
alignString = alignRight;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignRightIcon;
alignBoth = false;
align = Qt::AlignRight;
break;
case 10: // Align Right - Geometry Relative to Last Selected
alignString = alignRight;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignRightIcon;
alignBoth = false;
align = Qt::AlignRight;
break;
case 11: // Align Right - Pivot Relative to Last Selected
alignString = alignRight;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignRightIcon;
alignBoth = false;
align = Qt::AlignRight;
break;
case 12: // Align Top - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignTop;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignTopIcon;
alignBoth = false;
align = Qt::AlignTop;
break;
case 13: // Align Top - Pivot Relative to Scene
alignString = alignTop;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignTopIcon;
alignBoth = false;
align = Qt::AlignTop;
break;
case 14: // Align Top - Geometry Relative to Last Selected
alignString = alignTop;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignTopIcon;
alignBoth = false;
align = Qt::AlignTop;
break;
case 15: // Align Top - Pivot Relative to Last Selected
alignString = alignTop;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignTopIcon;
alignBoth = false;
align = Qt::AlignTop;
break;
case 16: // Align Bottom - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignBottom;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignBottomIcon;
alignBoth = false;
align = Qt::AlignBottom;
break;
case 17: // Align Bottom - Pivot Relative to Scene
alignString = alignBottom;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignBottomIcon;
alignBoth = false;
align = Qt::AlignBottom;
break;
case 18: // Align Bottom - Geometry Relative to Last Selected
alignString = alignBottom;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignBottomIcon;
alignBoth = false;
align = Qt::AlignBottom;
break;
case 19: // Align Bottom - Pivot Relative to Last Selected
alignString = alignBottom;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignBottomIcon;
alignBoth = false;
align = Qt::AlignBottom;
break;
case 20: // Align HCenter - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignHCenter;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignHCenterIcon;
alignBoth = false;
align = Qt::AlignHCenter;
break;
case 21: // Align HCenter - Pivot Relative to Scene
alignString = alignHCenter;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignHCenterIcon;
alignBoth = false;
align = Qt::AlignHCenter;
break;
case 22: // Align HCenter - Geometry Relative to Last Selected
alignString = alignHCenter;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignHCenterIcon;
alignBoth = false;
align = Qt::AlignHCenter;
break;
case 23: // Align HCenter - Pivot Relative to Last Selected
alignString = alignHCenter;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignHCenterIcon;
alignBoth = false;
align = Qt::AlignHCenter;
break;
case 24: // Align VCenter - Geometry Relative to Scene -----------------------------------------------------------------------------------
alignString = alignVCenter;
pivotString = alignGeometry;
relString = alignScene;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::scene;
iconString = alignVCenterIcon;
alignBoth = false;
align = Qt::AlignVCenter;
break;
case 25: // Align VCenter - Pivot Relative to Scene
alignString = alignVCenter;
pivotString = alignPivot;
relString = alignScene;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::scene;
iconString = alignVCenterIcon;
alignBoth = false;
align = Qt::AlignVCenter;
break;
case 26: // Align VCenter - Geometry Relative to Last Selected
alignString = alignVCenter;
pivotString = alignGeometry;
relString = alignLast;
pivot = AlignPivot::geometry;
rel = AlignRelativeTo::lastSelected;
iconString = alignVCenterIcon;
alignBoth = false;
align = Qt::AlignVCenter;
break;
case 27: // Align VCenter - Pivot Relative to Last Selected
alignString = alignVCenter;
pivotString = alignPivot;
relString = alignLast;
pivot = AlignPivot::pivot;
rel = AlignRelativeTo::lastSelected;
iconString = alignVCenterIcon;
alignBoth = false;
align = Qt::AlignVCenter;
break;
default:
return;
}

const auto act = menu->addAction(QIcon::fromTheme(iconString),
QString(alignTextDefault).arg(alignString,
pivotString,
relString));
connect(act, &QAction::triggered, this, [this,
align,
pivot,
rel,
alignBoth]() {
const auto scene = *mDocument.fActiveScene;
if (!scene) { return; }
scene->alignSelectedBoxes(align, pivot, rel);
if (alignBoth && (align == Qt::AlignVCenter || align == Qt::AlignHCenter)) {
scene->alignSelectedBoxes(align == Qt::AlignVCenter ? Qt::AlignHCenter : Qt::AlignVCenter,
pivot,
rel);
}
mDocument.actionFinished();
});
cmdAddAction(act);
}
}
//
}

void MainWindow::setResolutionText(QString text)
Expand Down

0 comments on commit 1ad03e9

Please sign in to comment.