Add ObjectsCenter action to center objects in label both h and v. (#184)

This commit is contained in:
Jaye Evins
2025-07-31 18:01:22 -04:00
committed by GitHub
parent 475971b701
commit 9c3e21faf3
8 changed files with 108 additions and 0 deletions
+10
View File
@@ -188,6 +188,16 @@ namespace glabels
};
class Center : public QIcon
{
public:
Center()
{
addPixmap( QPixmap( ":icons/flat/16x16/glabels-center.svg" ) );
}
};
class CenterHoriz : public QIcon
{
public:
+18
View File
@@ -574,6 +574,11 @@ namespace glabels
objectsCenterVertAction->setStatusTip( tr("Vertically center objects in label") );
connect( objectsCenterVertAction, SIGNAL(triggered()), this, SLOT(objectsCenterVert()) );
objectsCenterAction = new QAction( tr("Center Both"), this );
objectsCenterAction->setIcon( Icons::Center() );
objectsCenterAction->setStatusTip( tr("Center objects in label") );
connect( objectsCenterAction, SIGNAL(triggered()), this, SLOT(objectsCenter()) );
/* Help actions */
helpContentsAction = new QAction( tr("&User Manual..."), this );
@@ -698,6 +703,7 @@ namespace glabels
objectsCenterMenu = objectsMenu->addMenu( tr("Center") );
objectsCenterMenu->addAction( objectsCenterHorizAction );
objectsCenterMenu->addAction( objectsCenterVertAction );
objectsCenterMenu->addAction( objectsCenterAction );
helpMenu = menuBar()->addMenu( tr("&Help") );
helpMenu->addAction( helpContentsAction );
@@ -724,6 +730,7 @@ namespace glabels
contextCenterMenu = contextMenu->addMenu( tr("Center") );
contextCenterMenu->addAction( objectsCenterHorizAction );
contextCenterMenu->addAction( objectsCenterVertAction );
contextCenterMenu->addAction( objectsCenterAction );
contextMenu->addSeparator();
contextMenu->addAction( contextCutAction );
contextMenu->addAction( contextCopyAction );
@@ -1005,6 +1012,7 @@ namespace glabels
objectsCenterMenu->setEnabled( isEditorPage && hasSelection );
objectsCenterHorizAction->setEnabled( isEditorPage && hasSelection );
objectsCenterVertAction->setEnabled( isEditorPage && hasSelection );
objectsCenterAction->setEnabled( isEditorPage && hasSelection );
// Help actions
helpContentsAction->setEnabled( true );
@@ -1650,6 +1658,16 @@ namespace glabels
}
///
/// Objects->Center Action
///
void MainWindow::objectsCenter()
{
mUndoRedoModel->checkpoint( tr("Center") );
mModel->centerSelection();
}
///
/// Objects->Center->Vertically Action
///
+2
View File
@@ -142,6 +142,7 @@ namespace glabels
void objectsAlignTop();
void objectsAlignVCenter();
void objectsAlignBottom();
void objectsCenter();
void objectsCenterHoriz();
void objectsCenterVert();
@@ -301,6 +302,7 @@ namespace glabels
QAction* objectsAlignTopAction;
QAction* objectsAlignVCenterAction;
QAction* objectsAlignBottomAction;
QAction* objectsCenterAction;
QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction;
+1
View File
@@ -12,6 +12,7 @@
<file>icons/flat/16x16/glabels-arrow.svg</file>
<file>icons/flat/16x16/glabels-barcode.svg</file>
<file>icons/flat/16x16/glabels-box.svg</file>
<file>icons/flat/16x16/glabels-center.svg</file>
<file>icons/flat/16x16/glabels-center-horiz.svg</file>
<file>icons/flat/16x16/glabels-center-vert.svg</file>
<file>icons/flat/16x16/glabels-edit-clear.svg</file>
@@ -0,0 +1,41 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16" >
<path
style="fill:#333333;fill-opacity:1;stroke:none"
d="M 7.5,6 5,3 10,3 Z" />
<path
style="fill:#333333;fill-opacity:1;stroke:none"
d="M 7.5,9 5,12 10,12 Z" />
<line
style="fill:none;stroke:#333333;stroke-opacity:1;stroke-width:1"
x1="7.5" y1="1" x2="7.5" y2="5" />
<line
style="fill:none;stroke:#333333;stroke-opacity:1;stroke-width:1"
x1="7.5" y1="10" x2="7.5" y2="14" />
<path
style="fill:#333333;fill-opacity:1;stroke:none"
d="M 6,7.5 3,5 3,10 Z" />
<path
style="fill:#333333;fill-opacity:1;stroke:none"
d="M 9,7.5 12,5 12,10 Z" />
<line
style="fill:none;stroke:#333333;stroke-opacity:1;stroke-width:1"
x1="1" y1="7.5" x2="5" y2="7.5" />
<line
style="fill:none;stroke:#333333;stroke-opacity:1;stroke-width:1"
x1="10" y1="7.5" x2="14" y2="7.5" />
<line
style="fill:none;stroke:#333333;stroke-opacity:1;stroke-width:1"
x1="7" y1="7.5" x2="8" y2="7.5" />
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+27
View File
@@ -1163,6 +1163,33 @@ namespace glabels
}
///
/// Align Selected Objects To Center Of Label Both Horizontally and Vertically
///
void Model::centerSelection()
{
Distance xLabelCenter = w() / 2.0;
Distance yLabelCenter = h() / 2.0;
foreach ( ModelObject* object, mObjectList )
{
if ( object->isSelected() )
{
Region r = object->getExtent();
Distance xObjectCenter = (r.x1() + r.x2()) / 2.0;
Distance yObjectCenter = (r.y1() + r.y2()) / 2.0;
Distance dx = xLabelCenter - xObjectCenter;
Distance dy = yLabelCenter - yObjectCenter;
object->setPositionRelative( dx, dy );
}
}
setModified();
emit changed();
}
///
/// Align Selected Objects To Center Of Label Vertically
///
+1
View File
@@ -184,6 +184,7 @@ namespace glabels
void alignSelectionTop();
void alignSelectionBottom();
void alignSelectionVCenter();
void centerSelection();
void centerSelectionHoriz();
void centerSelectionVert();
void moveSelection( const Distance& dx, const Distance& dy );
+8
View File
@@ -1879,6 +1879,14 @@
<source>Redo %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Center Both</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Center objects in label</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>glabels::MergeView</name>