@@ -123,6 +123,11 @@ DefaultParamsDialog::DefaultParamsDialog(QWidget* parent)
123123 Alignment (Alignment::BOTTOM, Alignment::RIGHT)
124124 );
125125
126+ alignmentButtonGroup = std::make_unique<QButtonGroup>(this );
127+ for (const auto & buttonAndAlignment : alignmentByButton) {
128+ alignmentButtonGroup->addButton (buttonAndAlignment.first );
129+ }
130+
126131 darkerThresholdLink->setText (
127132 Utils::richTextForLink (darkerThresholdLink->text ())
128133 );
@@ -239,21 +244,40 @@ void DefaultParamsDialog::updatePageLayoutDisplay(const DefaultParams::PageLayou
239244 setLinkButtonLinked (leftRightLink, leftRightLinkEnabled);
240245
241246 const Alignment& alignment = params.getAlignment ();
242- if (alignment.vertical () == Alignment::VAUTO ) {
247+ if (alignment.isAuto () ) {
243248 alignmentMode->setCurrentIndex (0 );
244- alignButtonsWidget->setEnabled (false );
245- } else if (alignment.vertical () == Alignment::VORIGINAL) {
249+ autoAlignSettingsGroup->setVisible (true );
250+ autoVerticalAligningCB->setChecked (alignment.isAutoVertical ());
251+ autoHorizontalAligningCB->setChecked (alignment.isAutoHorizontal ());
252+ } else if (alignment.isOriginal ()) {
246253 alignmentMode->setCurrentIndex (2 );
247- alignButtonsWidget->setEnabled (false );
254+ autoAlignSettingsGroup->setVisible (true );
255+ autoVerticalAligningCB->setChecked (alignment.isAutoVertical ());
256+ autoHorizontalAligningCB->setChecked (alignment.isAutoHorizontal ());
248257 } else {
249258 alignmentMode->setCurrentIndex (1 );
250- alignButtonsWidget-> setEnabled (!alignment. isNull () );
259+ autoAlignSettingsGroup-> setVisible ( false );
251260 }
261+ updateAlignmentButtonsEnabled ();
262+ updateAutoModeButtons ();
263+
252264 alignWithOthersCB->setChecked (!alignment.isNull ());
253265
254- for (const auto & value : alignmentByButton) {
255- if (value.second == alignment) {
256- value.first ->setChecked (true );
266+ for (const auto & kv : alignmentByButton) {
267+ if (alignment.isAuto () || alignment.isOriginal ()) {
268+ if (!alignment.isAutoHorizontal ()
269+ && (kv.second .vertical () == Alignment::VCENTER)
270+ && (kv.second .horizontal () == alignment.horizontal ())) {
271+ kv.first ->setChecked (true );
272+ break ;
273+ } else if (!alignment.isAutoVertical ()
274+ && (kv.second .horizontal () == Alignment::HCENTER)
275+ && (kv.second .vertical () == alignment.vertical ())) {
276+ kv.first ->setChecked (true );
277+ break ;
278+ }
279+ } else if (kv.second == alignment) {
280+ kv.first ->setChecked (true );
257281 break ;
258282 }
259283 }
@@ -393,6 +417,8 @@ void DefaultParamsDialog::setupUiConnections() {
393417 connect (profileDeleteButton, SIGNAL (pressed ()), this , SLOT (profileDeletePressed ()));
394418 connect (colorSegmentationCB, SIGNAL (clicked (bool )), this , SLOT (colorSegmentationToggled (bool )));
395419 connect (posterizeCB, SIGNAL (clicked (bool )), this , SLOT (posterizeToggled (bool )));
420+ connect (autoHorizontalAligningCB, SIGNAL (toggled (bool )), this , SLOT (autoHorizontalAligningToggled (bool )));
421+ connect (autoVerticalAligningCB, SIGNAL (toggled (bool )), this , SLOT (autoVerticalAligningToggled (bool )));
396422}
397423
398424void DefaultParamsDialog::removeUiConnections () {
@@ -432,6 +458,8 @@ void DefaultParamsDialog::removeUiConnections() {
432458 disconnect (profileDeleteButton, SIGNAL (pressed ()), this , SLOT (profileDeletePressed ()));
433459 disconnect (colorSegmentationCB, SIGNAL (clicked (bool )), this , SLOT (colorSegmentationToggled (bool )));
434460 disconnect (posterizeCB, SIGNAL (clicked (bool )), this , SLOT (posterizeToggled (bool )));
461+ disconnect (autoHorizontalAligningCB, SIGNAL (toggled (bool )), this , SLOT (autoHorizontalAligningToggled (bool )));
462+ disconnect (autoVerticalAligningCB, SIGNAL (toggled (bool )), this , SLOT (autoVerticalAligningToggled (bool )));
435463}
436464
437465void DefaultParamsDialog::rotateLeft () {
@@ -522,13 +550,13 @@ void DefaultParamsDialog::autoMarginsToggled(const bool checked) {
522550}
523551
524552void DefaultParamsDialog::alignmentModeChanged (const int idx) {
525- const bool enabled = alignWithOthersCB->isChecked () && (idx == 1 );
526- alignButtonsWidget->setEnabled (enabled);
553+ autoAlignSettingsGroup->setVisible ((idx == 0 ) || (idx == 2 ));
554+ updateAlignmentButtonsEnabled ();
555+ updateAutoModeButtons ();
527556}
528557
529- void DefaultParamsDialog::alignWithOthersToggled (const bool checked) {
530- const bool enabled = checked && (alignmentMode->currentIndex () == 1 );
531- alignButtonsWidget->setEnabled (enabled);
558+ void DefaultParamsDialog::alignWithOthersToggled (const bool ) {
559+ updateAlignmentButtonsEnabled ();
532560}
533561
534562void DefaultParamsDialog::colorModeChanged (const int idx) {
@@ -664,23 +692,30 @@ std::unique_ptr<DefaultParams> DefaultParamsDialog::buildParams() const {
664692 Alignment alignment;
665693 switch (alignmentMode->currentIndex ()) {
666694 case 0 :
667- alignment.setVertical (Alignment::VAUTO);
668- alignment.setHorizontal (Alignment::HCENTER);
695+ if (autoVerticalAligningCB->isChecked ()) {
696+ alignment.setVertical (Alignment::VAUTO);
697+ } else {
698+ alignment.setVertical (alignmentByButton.at (getCheckedAlignmentButton ()).vertical ());
699+ }
700+ if (autoHorizontalAligningCB->isChecked ()) {
701+ alignment.setHorizontal (Alignment::HAUTO);
702+ } else {
703+ alignment.setHorizontal (alignmentByButton.at (getCheckedAlignmentButton ()).horizontal ());
704+ }
669705 break ;
670706 case 1 :
671- for (auto item : alignmentByButton) {
672- if (item.first ->isChecked ()) {
673- alignment = item.second ;
674- break ;
675- }
676- }
707+ alignment = alignmentByButton.at (getCheckedAlignmentButton ());
677708 break ;
678709 case 2 :
679- alignment.setVertical (Alignment::VORIGINAL);
680- if (autoMargins->isChecked ()) {
710+ if (autoVerticalAligningCB->isChecked ()) {
711+ alignment.setVertical (Alignment::VORIGINAL);
712+ } else {
713+ alignment.setVertical (alignmentByButton.at (getCheckedAlignmentButton ()).vertical ());
714+ }
715+ if (autoHorizontalAligningCB->isChecked ()) {
681716 alignment.setHorizontal (Alignment::HORIGINAL);
682717 } else {
683- alignment.setHorizontal (Alignment::HCENTER );
718+ alignment.setHorizontal (alignmentByButton. at ( getCheckedAlignmentButton ()). horizontal () );
684719 }
685720 break ;
686721 default :
@@ -793,7 +828,7 @@ std::unique_ptr<DefaultParams> DefaultParamsDialog::buildParams() const {
793828
794829void DefaultParamsDialog::updateUnits (const Units units) {
795830 currentUnits = units;
796- unitsLabel->setText (unitsToString (units));
831+ unitsLabel->setText (unitsToLocalizedString (units));
797832
798833 {
799834 int decimals;
@@ -1089,3 +1124,84 @@ void DefaultParamsDialog::colorSegmentationToggled(bool checked) {
10891124void DefaultParamsDialog::posterizeToggled (bool checked) {
10901125 posterizeOptionsWidget->setEnabled (checked);
10911126}
1127+
1128+ void DefaultParamsDialog::updateAlignmentButtonsEnabled () {
1129+ bool enableHorizontalButtons;
1130+ bool enableVerticalButtons;
1131+ if ((alignmentMode->currentIndex () == 0 ) || (alignmentMode->currentIndex () == 2 )) {
1132+ enableHorizontalButtons = !autoHorizontalAligningCB->isChecked () ? alignWithOthersCB->isChecked ()
1133+ : false ;
1134+ enableVerticalButtons = !autoVerticalAligningCB->isChecked () ? alignWithOthersCB->isChecked ()
1135+ : false ;
1136+ } else {
1137+ enableHorizontalButtons = enableVerticalButtons = alignWithOthersCB->isChecked ();
1138+ }
1139+
1140+ alignTopLeftBtn->setEnabled (enableHorizontalButtons && enableVerticalButtons);
1141+ alignTopBtn->setEnabled (enableVerticalButtons);
1142+ alignTopRightBtn->setEnabled (enableHorizontalButtons && enableVerticalButtons);
1143+ alignLeftBtn->setEnabled (enableHorizontalButtons);
1144+ alignCenterBtn->setEnabled (enableHorizontalButtons || enableVerticalButtons);
1145+ alignRightBtn->setEnabled (enableHorizontalButtons);
1146+ alignBottomLeftBtn->setEnabled (enableHorizontalButtons && enableVerticalButtons);
1147+ alignBottomBtn->setEnabled (enableVerticalButtons);
1148+ alignBottomRightBtn->setEnabled (enableHorizontalButtons && enableVerticalButtons);
1149+ }
1150+
1151+ void DefaultParamsDialog::updateAutoModeButtons () {
1152+ if ((alignmentMode->currentIndex () == 0 ) || (alignmentMode->currentIndex () == 2 )) {
1153+ if (autoVerticalAligningCB->isChecked () && !autoHorizontalAligningCB->isChecked ()) {
1154+ autoVerticalAligningCB->setEnabled (false );
1155+ } else if (autoHorizontalAligningCB->isChecked () && !autoVerticalAligningCB->isChecked ()) {
1156+ autoHorizontalAligningCB->setEnabled (false );
1157+ } else {
1158+ autoVerticalAligningCB->setEnabled (true );
1159+ autoHorizontalAligningCB->setEnabled (true );
1160+ }
1161+ }
1162+
1163+ if (autoVerticalAligningCB->isChecked () && !autoHorizontalAligningCB->isChecked ()) {
1164+ switch (alignmentByButton.at (getCheckedAlignmentButton ()).horizontal ()) {
1165+ case Alignment::LEFT:
1166+ alignLeftBtn->setChecked (true );
1167+ break ;
1168+ case Alignment::RIGHT:
1169+ alignRightBtn->setChecked (true );
1170+ break ;
1171+ default :
1172+ alignCenterBtn->setChecked (true );
1173+ break ;
1174+ }
1175+ } else if (autoHorizontalAligningCB->isChecked () && !autoVerticalAligningCB->isChecked ()) {
1176+ switch (alignmentByButton.at (getCheckedAlignmentButton ()).vertical ()) {
1177+ case Alignment::TOP:
1178+ alignTopBtn->setChecked (true );
1179+ break ;
1180+ case Alignment::BOTTOM:
1181+ alignBottomBtn->setChecked (true );
1182+ break ;
1183+ default :
1184+ alignCenterBtn->setChecked (true );
1185+ break ;
1186+ }
1187+ }
1188+ }
1189+
1190+ QToolButton* DefaultParamsDialog::getCheckedAlignmentButton () const {
1191+ auto * checkedButton = dynamic_cast <QToolButton*>(alignmentButtonGroup->checkedButton ());
1192+ if (!checkedButton) {
1193+ checkedButton = alignCenterBtn;
1194+ }
1195+
1196+ return checkedButton;
1197+ }
1198+
1199+ void DefaultParamsDialog::autoHorizontalAligningToggled (bool ) {
1200+ updateAlignmentButtonsEnabled ();
1201+ updateAutoModeButtons ();
1202+ }
1203+
1204+ void DefaultParamsDialog::autoVerticalAligningToggled (bool ) {
1205+ updateAlignmentButtonsEnabled ();
1206+ updateAutoModeButtons ();
1207+ }
0 commit comments