Skip to content

Commit eb47f39

Browse files
committed
Implement text alignment setting on Lyrics view
Closes #37
1 parent add112c commit eb47f39

File tree

7 files changed

+130
-55
lines changed

7 files changed

+130
-55
lines changed

lyrics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Lyrics::Lyrics(QWidget *parent) : FramelessWindow(parent),
146146
m_normalColor = Settings::instance()->getFutureColor();
147147
m_otherColor = Settings::instance()->getPastColor();
148148
m_highlightColor = Settings::instance()->highlightColor();
149+
m_alignment = Settings::instance()->getTextAlignment();
149150
vlayout->addWidget(m_textViewer);
150151
this->setCentralWidget(centralWidget);
151152
#ifndef QT_NO_SHORTCUT
@@ -283,6 +284,7 @@ void Lyrics::displayText()
283284
{
284285
m_textViewer->clear();
285286
m_textViewer->setTextColor(m_normalColor);
287+
m_textViewer->setAlignment(m_alignment);
286288
m_textPos.clear();
287289
if (m_song != nullptr) {
288290
QList<QPair<int,QByteArray>> textList = m_song->getRawText(m_track, static_cast<Sequence::TextType>(m_type));
@@ -390,6 +392,7 @@ void Lyrics::applySettings()
390392
m_normalColor = Settings::instance()->getFutureColor();
391393
m_otherColor = Settings::instance()->getPastColor();
392394
m_highlightColor = Settings::instance()->highlightColor();
395+
m_alignment = Settings::instance()->getTextAlignment();
393396

394397
QPalette p;
395398
p.setColor(QPalette::Highlight, m_highlightColor);

lyrics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public slots:
8080
QColor m_normalColor;
8181
QColor m_otherColor;
8282
QColor m_highlightColor;
83+
Qt::Alignment m_alignment{Qt::AlignLeft};
8384
QAction *m_actionCopy;
8485
QAction *m_actionSave;
8586
QAction *m_actionPrint;

prefsdialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void PrefsDialog::restoreDefaults()
108108
setHighlightColor(highlightColor);
109109
ui->chkAutoPlay->setChecked(true);
110110
ui->chkAutoAdvance->setChecked(true);
111+
setTextAlignment(0); //Left
111112

112113
ui->chkVelocityColor->setChecked(true);
113114
ui->cboHighlight->setCurrentIndex(0);
@@ -236,6 +237,7 @@ void PrefsDialog::showEvent ( QShowEvent *event )
236237
ui->cboNoteNames->setCurrentIndex(static_cast<int>(Settings::instance()->namesVisibility()));
237238
setSingleColor( Settings::instance()->getSingleColor() );
238239
ui->chkOctaveSubscript->setChecked( Settings::instance()->octaveSubscript() );
240+
ui->cboTextAlignment->setCurrentIndex(Settings::instance()->textAlignment());
239241

240242
ui->tabWidget->setCurrentIndex(0);
241243
}
@@ -273,6 +275,7 @@ void PrefsDialog::apply()
273275
}
274276
Settings::instance()->setNamesVisibility(static_cast<LabelVisibility>(ui->cboNoteNames->currentIndex()));
275277
Settings::instance()->setOctaveSubscript(ui->chkOctaveSubscript->isChecked());
278+
Settings::instance()->setTextAlignment(ui->cboTextAlignment->currentIndex());
276279
}
277280

278281
void PrefsDialog::setFutureColor(QColor c)
@@ -311,6 +314,11 @@ void PrefsDialog::setHighlightColor(QColor c)
311314
ui->editHighlightColor->setText(c.name(QColor::HexRgb));
312315
}
313316

317+
void PrefsDialog::setTextAlignment(int a)
318+
{
319+
ui->cboTextAlignment->setCurrentIndex(a);
320+
}
321+
314322
void PrefsDialog::retranslateUi()
315323
{
316324
ui->retranslateUi(this);

prefsdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PrefsDialog : public QDialog
3737
void setPastColor(QColor c);
3838
void setSingleColor(QColor c);
3939
void setHighlightColor(QColor c);
40+
void setTextAlignment(int a);
4041
void retranslateUi();
4142

4243
public slots:

prefsdialog.ui

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<item>
2222
<widget class="QTabWidget" name="tabWidget">
2323
<property name="currentIndex">
24-
<number>1</number>
24+
<number>0</number>
2525
</property>
2626
<widget class="QWidget" name="tabGen">
2727
<attribute name="title">
@@ -187,17 +187,10 @@
187187
<attribute name="title">
188188
<string>Lyrics</string>
189189
</attribute>
190-
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,1,0">
190+
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
191191
<property name="sizeConstraint">
192192
<enum>QLayout::SizeConstraint::SetNoConstraint</enum>
193193
</property>
194-
<item row="0" column="3">
195-
<widget class="QToolButton" name="btnTextFont">
196-
<property name="text">
197-
<string>...</string>
198-
</property>
199-
</widget>
200-
</item>
201194
<item row="2" column="0">
202195
<widget class="QLabel" name="lblPastColor">
203196
<property name="text">
@@ -208,7 +201,21 @@
208201
</property>
209202
</widget>
210203
</item>
211-
<item row="4" column="0">
204+
<item row="1" column="3">
205+
<widget class="QToolButton" name="btnFutureColor">
206+
<property name="text">
207+
<string>...</string>
208+
</property>
209+
</widget>
210+
</item>
211+
<item row="1" column="2">
212+
<widget class="QLabel" name="editFutureColor">
213+
<property name="autoFillBackground">
214+
<bool>true</bool>
215+
</property>
216+
</widget>
217+
</item>
218+
<item row="5" column="0">
212219
<spacer name="verticalSpacer_2">
213220
<property name="orientation">
214221
<enum>Qt::Orientation::Vertical</enum>
@@ -231,27 +238,30 @@
231238
</property>
232239
</widget>
233240
</item>
234-
<item row="0" column="1" colspan="2">
235-
<widget class="QLineEdit" name="editTextFont">
236-
<property name="readOnly">
237-
<bool>true</bool>
241+
<item row="0" column="3">
242+
<widget class="QToolButton" name="btnTextFont">
243+
<property name="text">
244+
<string>...</string>
238245
</property>
239246
</widget>
240247
</item>
241-
<item row="1" column="2">
242-
<widget class="QLabel" name="editFutureColor">
248+
<item row="1" column="1">
249+
<widget class="QLabel" name="lblFuture"/>
250+
</item>
251+
<item row="2" column="2">
252+
<widget class="QLabel" name="editPastColor">
243253
<property name="autoFillBackground">
244254
<bool>true</bool>
245255
</property>
246256
</widget>
247257
</item>
248-
<item row="1" column="1">
249-
<widget class="QLabel" name="lblFuture"/>
250-
</item>
251-
<item row="2" column="3">
252-
<widget class="QToolButton" name="btnPastColor">
258+
<item row="3" column="2">
259+
<widget class="QLabel" name="editHighlightColor">
260+
<property name="autoFillBackground">
261+
<bool>true</bool>
262+
</property>
253263
<property name="text">
254-
<string>...</string>
264+
<string/>
255265
</property>
256266
</widget>
257267
</item>
@@ -265,44 +275,37 @@
265275
</property>
266276
</widget>
267277
</item>
268-
<item row="0" column="0">
269-
<widget class="QLabel" name="lblTextFont">
270-
<property name="text">
271-
<string>Text Font</string>
272-
</property>
273-
<property name="buddy">
274-
<cstring>editTextFont</cstring>
278+
<item row="3" column="1">
279+
<widget class="QLabel" name="lblHigh"/>
280+
</item>
281+
<item row="0" column="1" colspan="2">
282+
<widget class="QLineEdit" name="editTextFont">
283+
<property name="readOnly">
284+
<bool>true</bool>
275285
</property>
276286
</widget>
277287
</item>
278-
<item row="1" column="3">
279-
<widget class="QToolButton" name="btnFutureColor">
288+
<item row="2" column="3">
289+
<widget class="QToolButton" name="btnPastColor">
280290
<property name="text">
281291
<string>...</string>
282292
</property>
283293
</widget>
284294
</item>
285-
<item row="2" column="2">
286-
<widget class="QLabel" name="editPastColor">
287-
<property name="autoFillBackground">
288-
<bool>true</bool>
289-
</property>
290-
</widget>
291-
</item>
292295
<item row="3" column="0">
293296
<widget class="QLabel" name="lblHighlightColor">
294297
<property name="text">
295298
<string>Highlight Color</string>
296299
</property>
297300
</widget>
298301
</item>
299-
<item row="3" column="2">
300-
<widget class="QLabel" name="editHighlightColor">
301-
<property name="autoFillBackground">
302-
<bool>true</bool>
303-
</property>
302+
<item row="0" column="0">
303+
<widget class="QLabel" name="lblTextFont">
304304
<property name="text">
305-
<string/>
305+
<string>Text Font</string>
306+
</property>
307+
<property name="buddy">
308+
<cstring>editTextFont</cstring>
306309
</property>
307310
</widget>
308311
</item>
@@ -313,8 +316,36 @@
313316
</property>
314317
</widget>
315318
</item>
316-
<item row="3" column="1">
317-
<widget class="QLabel" name="lblHigh"/>
319+
<item row="4" column="0">
320+
<widget class="QLabel" name="lblAlignment">
321+
<property name="text">
322+
<string>Text Alignment</string>
323+
</property>
324+
</widget>
325+
</item>
326+
<item row="4" column="1" colspan="3">
327+
<widget class="QComboBox" name="cboTextAlignment">
328+
<item>
329+
<property name="text">
330+
<string extracomment="Aligns with the left edge.">Left</string>
331+
</property>
332+
</item>
333+
<item>
334+
<property name="text">
335+
<string extracomment="Aligns with the right edge.">Right</string>
336+
</property>
337+
</item>
338+
<item>
339+
<property name="text">
340+
<string extracomment="Centers horizontally in the available space.">Center</string>
341+
</property>
342+
</item>
343+
<item>
344+
<property name="text">
345+
<string extracomment="Justifies the text in the available space.">Justified</string>
346+
</property>
347+
</item>
348+
</widget>
318349
</item>
319350
</layout>
320351
</widget>

settings.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void Settings::ResetDefaults()
132132
m_velocityColor = true;
133133
m_showStatusBar = true;
134134
m_showToolBar = true;
135+
m_textAlignment = 0; // Left
135136
#if defined(Q_OS_WINDOWS)
136137
m_winSnap = true;
137138
#endif
@@ -273,6 +274,7 @@ void Settings::internalRead(QSettings &settings)
273274
.toString());
274275
m_lyricsWindowGeometry = settings.value("Geometry", QByteArray()).toByteArray();
275276
m_lyricsWindowState = settings.value("State", QByteArray()).toByteArray();
277+
m_textAlignment = settings.value("Alignment", 0).toInt();
276278
settings.endGroup();
277279

278280
settings.beginGroup("PlayerPianoSettings");
@@ -344,6 +346,7 @@ void Settings::internalSave(QSettings &settings)
344346
settings.setValue("HighlightColor", m_highlightColor.name(QColor::HexRgb));
345347
settings.setValue("Geometry", m_lyricsWindowGeometry);
346348
settings.setValue("State", m_lyricsWindowState);
349+
settings.setValue("Alignment", m_textAlignment);
347350
settings.endGroup();
348351

349352
settings.beginGroup("PlayerPianoSettings");
@@ -380,6 +383,29 @@ void Settings::forceSettings(QSettings &settings)
380383
#endif
381384
}
382385

386+
int Settings::textAlignment() const
387+
{
388+
return m_textAlignment;
389+
}
390+
391+
void Settings::setTextAlignment(int newTextAlignment)
392+
{
393+
m_textAlignment = newTextAlignment;
394+
}
395+
396+
Qt::Alignment Settings::getTextAlignment()
397+
{
398+
const QList<Qt::Alignment> values{Qt::AlignLeft,
399+
Qt::AlignRight,
400+
Qt::AlignHCenter,
401+
Qt::AlignJustify};
402+
if (m_textAlignment >= 0 && m_textAlignment < values.size()) {
403+
return values[m_textAlignment];
404+
} else {
405+
return Qt::AlignLeft;
406+
}
407+
}
408+
383409
QColor Settings::highlightColor() const
384410
{
385411
return m_highlightColor;
@@ -467,9 +493,9 @@ void Settings::loadTranslations()
467493
if (m_trq->load(loc, "qt", "_", Settings::systemLocales())) {
468494
ok = QCoreApplication::installTranslator(m_trq);
469495
}
470-
if(!ok) {
471-
qWarning() << "Failure loading Qt system translations for" << lang
472-
<< "from" << Settings::systemLocales();
496+
if (!ok) {
497+
qWarning() << "Failure loading Qt system translations for" << lang << "from"
498+
<< Settings::systemLocales();
473499
delete m_trq;
474500
}
475501
ok = false;
@@ -478,8 +504,8 @@ void Settings::loadTranslations()
478504
ok = QCoreApplication::installTranslator(m_trp);
479505
}
480506
if (!ok) {
481-
qWarning() << "Failure loading application translations for" << lang
482-
<< "from" << Settings::localeDirectory();
507+
qWarning() << "Failure loading application translations for" << lang << "from"
508+
<< Settings::localeDirectory();
483509
delete m_trp;
484510
}
485511
ok = false;
@@ -488,8 +514,8 @@ void Settings::loadTranslations()
488514
ok = QCoreApplication::installTranslator(m_trl);
489515
}
490516
if (!ok) {
491-
qWarning() << "Failure loading widgets library translations for" << lang
492-
<< "from" << Settings::drumstickLocales();
517+
qWarning() << "Failure loading widgets library translations for" << lang << "from"
518+
<< Settings::drumstickLocales();
493519
delete m_trl;
494520
}
495521
}
@@ -826,7 +852,7 @@ PianoPalette Settings::getPalette(int pal)
826852
QList<QString> Settings::availablePaletteNames(bool forHighlight)
827853
{
828854
QList<QString> tmp;
829-
for (PianoPalette& p : m_paletteList) {
855+
for (PianoPalette &p : m_paletteList) {
830856
if (forHighlight && !p.isHighLight()) {
831857
continue;
832858
}
@@ -842,7 +868,7 @@ int Settings::availablePalettes() const
842868

843869
void Settings::retranslatePalettes()
844870
{
845-
for (PianoPalette& pal : m_paletteList) {
871+
for (PianoPalette &pal : m_paletteList) {
846872
pal.retranslateStrings();
847873
}
848874
}

settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class Settings : public QObject
181181
QColor highlightColor() const;
182182
void setHighlightColor(const QColor &newHighlightColor);
183183

184+
int textAlignment() const;
185+
void setTextAlignment(int newTextAlignment);
186+
Qt::Alignment getTextAlignment();
187+
184188
signals:
185189
void ValuesChanged();
186190

@@ -230,6 +234,7 @@ public slots:
230234
int m_soloVolumeReduction;
231235
bool m_autoSongSettings;
232236
bool m_octaveSubscript;
237+
int m_textAlignment;
233238
LabelVisibility m_namesVisibility;
234239
QFont m_notesFont;
235240
QFont m_lyricsFont;

0 commit comments

Comments
 (0)