Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "alignSelect.h"
24 :
25 : #include <QButtonGroup>
26 :
27 : #include "ui/view/widgetutils.h"
28 :
29 : using namespace mu::notation;
30 : using namespace muse::ui;
31 :
32 0 : AlignSelect::AlignSelect(QWidget* parent)
33 0 : : QWidget(parent), muse::Contextable(muse::iocCtxForQWidget(this))
34 : {
35 0 : setupUi(this);
36 :
37 0 : horizontalAlignButtons = new QButtonGroup(this);
38 0 : horizontalAlignButtons->addButton(alignLeft);
39 0 : horizontalAlignButtons->addButton(alignHCenter);
40 0 : horizontalAlignButtons->addButton(alignRight);
41 0 : horizontalAlignButtons->addButton(alignJustify);
42 :
43 0 : verticalAlignButtons = new QButtonGroup(this);
44 0 : verticalAlignButtons->addButton(alignTop);
45 0 : verticalAlignButtons->addButton(alignVCenter);
46 0 : verticalAlignButtons->addButton(alignBaseline);
47 0 : verticalAlignButtons->addButton(alignBottom);
48 :
49 0 : positionButtons = new QButtonGroup(this);
50 0 : positionButtons->addButton(positionLeft);
51 0 : positionButtons->addButton(positionHCenter);
52 0 : positionButtons->addButton(positionRight);
53 :
54 0 : WidgetUtils::setWidgetIcon(alignLeft, IconCode::Code::TEXT_ALIGN_LEFT);
55 0 : WidgetUtils::setWidgetIcon(alignRight, IconCode::Code::TEXT_ALIGN_RIGHT);
56 0 : WidgetUtils::setWidgetIcon(alignHCenter, IconCode::Code::TEXT_ALIGN_CENTER);
57 0 : WidgetUtils::setWidgetIcon(alignJustify, IconCode::Code::TEXT_ALIGN_JUSTIFY);
58 0 : WidgetUtils::setWidgetIcon(alignVCenter, IconCode::Code::TEXT_ALIGN_MIDDLE);
59 0 : WidgetUtils::setWidgetIcon(alignTop, IconCode::Code::TEXT_ALIGN_TOP);
60 0 : WidgetUtils::setWidgetIcon(alignBaseline, IconCode::Code::TEXT_ALIGN_BASELINE);
61 0 : WidgetUtils::setWidgetIcon(alignBottom, IconCode::Code::TEXT_ALIGN_BOTTOM);
62 0 : WidgetUtils::setWidgetIcon(positionLeft, IconCode::Code::ALIGN_LEFT);
63 0 : WidgetUtils::setWidgetIcon(positionRight, IconCode::Code::ALIGN_RIGHT);
64 0 : WidgetUtils::setWidgetIcon(positionHCenter, IconCode::Code::ALIGN_HORIZONTAL_CENTER);
65 :
66 0 : connect(horizontalAlignButtons, &QButtonGroup::buttonToggled, this, &AlignSelect::_alignChanged);
67 0 : connect(verticalAlignButtons, &QButtonGroup::buttonToggled, this, &AlignSelect::_alignChanged);
68 0 : connect(positionButtons, &QButtonGroup::buttonToggled, this, &AlignSelect::_positionChanged);
69 0 : }
70 :
71 0 : void AlignSelect::_alignChanged()
72 : {
73 0 : emit alignChanged(align());
74 0 : }
75 :
76 0 : void AlignSelect::_positionChanged()
77 : {
78 0 : emit positionChanged(position());
79 0 : }
80 :
81 0 : mu::engraving::Align AlignSelect::align() const
82 : {
83 0 : mu::engraving::Align a = { mu::engraving::AlignH::LEFT, mu::engraving::AlignV::TOP };
84 0 : if (alignHCenter->isChecked()) {
85 0 : a = mu::engraving::AlignH::HCENTER;
86 0 : } else if (alignRight->isChecked()) {
87 0 : a = mu::engraving::AlignH::RIGHT;
88 0 : } else if (alignJustify->isChecked()) {
89 0 : a = mu::engraving::AlignH::JUSTIFY;
90 : }
91 0 : if (alignVCenter->isChecked()) {
92 0 : a = mu::engraving::AlignV::VCENTER;
93 0 : } else if (alignBottom->isChecked()) {
94 0 : a = mu::engraving::AlignV::BOTTOM;
95 0 : } else if (alignBaseline->isChecked()) {
96 0 : a = mu::engraving::AlignV::BASELINE;
97 : }
98 0 : return a;
99 : }
100 :
101 0 : mu::engraving::AlignH AlignSelect::position() const
102 : {
103 0 : mu::engraving::AlignH position = mu::engraving::AlignH::LEFT;
104 0 : if (positionHCenter->isChecked()) {
105 0 : position = mu::engraving::AlignH::HCENTER;
106 0 : } else if (positionRight->isChecked()) {
107 0 : position = mu::engraving::AlignH::RIGHT;
108 : }
109 0 : return position;
110 : }
111 :
112 0 : void AlignSelect::setAlign(mu::engraving::Align a)
113 : {
114 0 : blockAlign(true);
115 0 : if (a == mu::engraving::AlignH::HCENTER) {
116 0 : alignHCenter->setChecked(true);
117 0 : } else if (a == mu::engraving::AlignH::RIGHT) {
118 0 : alignRight->setChecked(true);
119 0 : } else if (a == mu::engraving::AlignH::JUSTIFY) {
120 0 : alignJustify->setChecked(true);
121 : } else {
122 0 : alignLeft->setChecked(true);
123 : }
124 0 : if (a == mu::engraving::AlignV::VCENTER) {
125 0 : alignVCenter->setChecked(true);
126 0 : } else if (a == mu::engraving::AlignV::BOTTOM) {
127 0 : alignBottom->setChecked(true);
128 0 : } else if (a == mu::engraving::AlignV::BASELINE) {
129 0 : alignBaseline->setChecked(true);
130 : } else {
131 0 : alignTop->setChecked(true);
132 : }
133 0 : blockAlign(false);
134 0 : }
135 :
136 0 : void AlignSelect::setPosition(mu::engraving::AlignH a)
137 : {
138 0 : blockPosition(true);
139 0 : if (a == mu::engraving::AlignH::HCENTER) {
140 0 : positionHCenter->setChecked(true);
141 0 : } else if (a == mu::engraving::AlignH::RIGHT) {
142 0 : positionRight->setChecked(true);
143 : } else {
144 0 : positionLeft->setChecked(true);
145 : }
146 0 : blockPosition(false);
147 0 : }
148 :
149 0 : void AlignSelect::blockAlign(bool val)
150 : {
151 0 : horizontalAlignButtons->blockSignals(val);
152 0 : verticalAlignButtons->blockSignals(val);
153 0 : }
154 :
155 0 : void AlignSelect::blockPosition(bool val)
156 : {
157 0 : positionButtons->blockSignals(val);
158 0 : }
|