making songeditor align text

This commit is contained in:
Chris Cochrun 2022-04-12 17:21:50 -05:00
parent 86a5bbf93c
commit e22ac445c5
6 changed files with 145 additions and 38 deletions

View file

@ -160,7 +160,7 @@ Item {
} else if (textIndex <= root.text.length) {
previewSlide.text = root.text[textIndex];
print(root.text[textIndex]);
--textIndex
--textIndex;
}
} else if (itemType === "video") {
clearText();

View file

@ -22,8 +22,8 @@ Item {
property string chosenFont: "Quicksand"
property var text: "This is demo text"
property color backgroundColor
property var horizontalAlignment
property var verticalAlignment
property var horizontalAlignment: Text.AlignHCenter
property var verticalAlignment: Text.AlignVCenter
//these properties are for giving video info to parents
property int mpvPosition: mpv.position
@ -119,8 +119,8 @@ Item {
/* minimumPointSize: 5 */
fontSizeMode: Text.Fit
font.family: chosenFont
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
horizontalAlignment: horizontalAlignment
verticalAlignment: verticalAlignment
style: Text.Raised
anchors.fill: parent
clip: true

View file

@ -13,7 +13,8 @@ Item {
property string imageBackground
property string videoBackground
property string textAlignment
property var hTextAlignment
property var vTextAlignment
Presenter.Slide {
id: representation
@ -22,14 +23,17 @@ Item {
editMode: true
imageSource: imageBackground
videoSource: videoBackground
horizontalAlignment: hTextAlignment
verticalAlignment: vTextAlignment
preview: true
}
Component.onCompleted: updateHAlignment(textAlignment)
Component.onCompleted: {
}
function loadVideo() {
representation.loadVideo();
representation.pause();
representation.pauseVideo();
}
function updateHAlignment(alignment) {
@ -48,4 +52,18 @@ Item {
break;
}
}
function updateVAlignment(alignment) {
switch (alignment) {
case "top" :
representation.verticalAlignment = Text.AlignBottom;
break;
case "center" :
representation.verticalAlignment = Text.AlignVCenter;
break;
case "bottom" :
representation.verticalAlignment = Text.AlignBottom;
break;
}
}
}

View file

@ -19,6 +19,7 @@ Item {
property string songBackground
property string songBackgroundType
property string songHAlignment
property string songVAlignment
GridLayout {
id: mainLayout
@ -48,16 +49,18 @@ Item {
hoverEnabled: true
}
Controls.ComboBox {
id: hAlignmentBox
model: ["Left", "Center", "Right", "Justify"]
implicitWidth: 100
hoverEnabled: true
onCurrentTextChanged: updateTextAlignment(currentText.toLowerCase());
onCurrentTextChanged: updateHorizontalTextAlignment(currentText.toLowerCase());
}
Controls.ComboBox {
id: vAlignmentBox
model: ["Top", "Center", "Bottom"]
implicitWidth: 100
hoverEnabled: true
onCurrentTextChanged: print(currentText.toLowerCase());
onCurrentTextChanged: updateVerticalTextAlignment(currentText.toLowerCase());
}
Controls.ToolButton {
text: "B"
@ -226,7 +229,6 @@ Item {
Layout.bottomMargin: 30
Layout.rightMargin: 20
Layout.leftMargin: 20
textAlignment: songHAlignment
}
}
}
@ -285,7 +287,9 @@ Item {
songVorder = song.vorder;
songBackground = song.background;
songBackgroundType = song.backgroundType;
songHAlignment = song.textAlignment;
songHAlignment = song.horizontalTextAlignment;
songVAlignment = song.verticalTextAlignment;
if (songBackgroundType == "image") {
slideEditor.videoBackground = "";
slideEditor.imageBackground = songBackground;
@ -294,6 +298,10 @@ Item {
slideEditor.videoBackground = songBackground;
slideEditor.loadVideo();
}
changeSlideHAlignment(songHAlignment);
changeSlideVAlignment(songVAlignment);
print(song);
}
@ -328,7 +336,54 @@ Item {
print("changed background");
}
function updateTextAlignment(textAlignment) {
songsqlmodel.updateTextAlignment(songIndex, textAlignment)
function updateHorizontalTextAlignment(textAlignment) {
changeSlideHAlignment(textAlignment);
songsqlmodel.updateHorizontalTextAlignment(songIndex, textAlignment);
}
function updateVerticalTextAlignment(textAlignment) {
changeSlideVAlignment(textAlignment);
songsqlmodel.updateVerticalTextAlignment(songIndex, textAlignment)
}
function changeSlideHAlignment(alignment) {
print("AHHHHHHHHHHH")
switch (alignment) {
case "left" :
hAlignmentBox.currentIndex = 0;
slideEditor.hTextAlignment = Text.AlignLeft;
break;
case "center" :
hAlignmentBox.currentIndex = 1;
slideEditor.hTextAlignment = Text.AlignHCenter;
break;
case "right" :
hAlignmentBox.currentIndex = 2;
slideEditor.hTextAlignment = Text.AlignRight;
break;
case "justify" :
hAlignmentBox.currentIndex = 3;
slideEditor.hTextAlignment = Text.AlignJustify;
break;
}
}
function changeSlideVAlignment(alignment) {
print("AHHHHHHHHHHH")
switch (alignment) {
case "top" :
vAlignmentBox.currentIndex = 0;
slideEditor.vTextAlignment = Text.AlignBottom;
break;
case "center" :
vAlignmentBox.currentIndex = 1;
slideEditor.vTextAlignment = Text.AlignVCenter;
break;
case "bottom" :
vAlignmentBox.currentIndex = 2;
slideEditor.vTextAlignment = Text.AlignBottom;
break;
}
}
}

View file

@ -34,7 +34,8 @@ static void createTable()
" 'vorder' TEXT,"
" 'background' TEXT,"
" 'backgroundType' TEXT,"
" 'textAlignment' TEXT,"
" 'horizontalTextAlignment' TEXT,"
" 'verticalTextAlignment' TEXT,"
" PRIMARY KEY(id))")) {
qFatal("Failed to query database: %s",
qPrintable(query.lastError().text()));
@ -44,16 +45,16 @@ static void createTable()
query.exec(
"INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, "
"background, backgroundType, textAlignment) VALUES ('10,000 Reasons', '10,000 reasons "
"for my heart to sing', 'Matt Redman', '13470183', '', '', '', '', 'center')");
"background, backgroundType, horizontalTextAlignment, verticalTextAlignment) VALUES ('10,000 Reasons', '10,000 reasons "
"for my heart to sing', 'Matt Redman', '13470183', '', '', '', '', 'center', 'center')");
// qDebug() << query.lastQuery();
query.exec("INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, "
"background, backgroundType, textAlignment) VALUES ('River', 'Im going down to "
"the river', 'Jordan Feliz', '13470183', '', '', '', '', 'center')");
"background, backgroundType, horizontalTextAlignment, verticalTextAlignment) VALUES ('River', 'Im going down to "
"the river', 'Jordan Feliz', '13470183', '', '', '', '', 'center', 'center')");
query.exec(
"INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, "
"background, backgroundType, textAlignment) VALUES ('Marvelous Light', 'Into marvelous "
"light Im running', 'Chris Tomlin', '13470183', '', '', '', '', 'center')");
"background, backgroundType, horizontalTextAlignment, verticalTextAlignment) VALUES ('Marvelous Light', 'Into marvelous "
"light Im running', 'Chris Tomlin', '13470183', '', '', '', '', 'center', 'center')");
// qDebug() << query.lastQuery();
query.exec("select * from songs");
@ -94,7 +95,8 @@ QHash<int, QByteArray> SongSqlModel::roleNames() const
names[Qt::UserRole + 6] = "vorder";
names[Qt::UserRole + 7] = "background";
names[Qt::UserRole + 8] = "backgroundType";
names[Qt::UserRole + 9] = "textAlignment";
names[Qt::UserRole + 9] = "horizontalTextAlignment";
names[Qt::UserRole + 10] = "verticalTextAlignment";
return names;
}
@ -140,7 +142,7 @@ QVariantMap SongSqlModel::getSong(const int &row) {
// song.append(recordData.value("vorder"));
// song.append(recordData.value("background"));
// song.append(recordData.value("backgroundType"));
// song.append(recordData.value("textAlignment"));
// song.append(recordData.value("horizontalTextAlignment"));
// return song;
@ -432,28 +434,54 @@ void SongSqlModel::updateBackgroundType(const int &row, const QString &backgroun
emit backgroundTypeChanged();
}
QString SongSqlModel::textAlignment() const {
return m_textAlignment;
QString SongSqlModel::horizontalTextAlignment() const {
return m_horizontalTextAlignment;
}
void SongSqlModel::setTextAlignment(const QString &textAlignment) {
if (textAlignment == m_textAlignment)
void SongSqlModel::setHorizontalTextAlignment(const QString &horizontalTextAlignment) {
if (horizontalTextAlignment == m_horizontalTextAlignment)
return;
m_textAlignment = textAlignment;
m_horizontalTextAlignment = horizontalTextAlignment;
select();
emit textAlignmentChanged();
emit horizontalTextAlignmentChanged();
}
// This function is for updating the lyrics from outside the delegate
void SongSqlModel::updateTextAlignment(const int &row, const QString &textAlignment) {
void SongSqlModel::updateHorizontalTextAlignment(const int &row, const QString &horizontalTextAlignment) {
qDebug() << "Row is " << row;
QSqlRecord rowdata = record(row);
qDebug() << rowdata;
rowdata.setValue("textAlignment", textAlignment);
rowdata.setValue("horizontalTextAlignment", horizontalTextAlignment);
setRecord(row, rowdata);
qDebug() << rowdata;
submitAll();
emit textAlignmentChanged();
emit horizontalTextAlignmentChanged();
}
QString SongSqlModel::verticalTextAlignment() const {
return m_verticalTextAlignment;
}
void SongSqlModel::setVerticalTextAlignment(const QString &verticalTextAlignment) {
if (verticalTextAlignment == m_verticalTextAlignment)
return;
m_verticalTextAlignment = verticalTextAlignment;
select();
emit verticalTextAlignmentChanged();
}
// This function is for updating the lyrics from outside the delegate
void SongSqlModel::updateVerticalTextAlignment(const int &row, const QString &verticalTextAlignment) {
qDebug() << "Row is " << row;
QSqlRecord rowdata = record(row);
qDebug() << rowdata;
rowdata.setValue("verticalTextAlignment", verticalTextAlignment);
setRecord(row, rowdata);
qDebug() << rowdata;
submitAll();
emit verticalTextAlignmentChanged();
}

View file

@ -18,7 +18,8 @@ class SongSqlModel : public QSqlTableModel
Q_PROPERTY(QString vorder READ vorder WRITE setVerseOrder NOTIFY vorderChanged)
Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged)
Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged)
Q_PROPERTY(QString textAlignment READ textAlignment WRITE setTextAlignment NOTIFY textAlignmentChanged)
Q_PROPERTY(QString horizontalTextAlignment READ horizontalTextAlignment WRITE setHorizontalTextAlignment NOTIFY horizontalTextAlignmentChanged)
Q_PROPERTY(QString verticalTextAlignment READ verticalTextAlignment WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged)
QML_ELEMENT
public:
@ -33,7 +34,8 @@ public:
QString vorder() const;
QString background() const;
QString backgroundType() const;
QString textAlignment() const;
QString horizontalTextAlignment() const;
QString verticalTextAlignment() const;
void setTitle(const QString &title);
void setLyrics(const QString &lyrics);
@ -43,7 +45,8 @@ public:
void setVerseOrder(const QString &vorder);
void setBackground(const QString &background);
void setBackgroundType(const QString &backgroundType);
void setTextAlignment(const QString &background);
void setHorizontalTextAlignment(const QString &background);
void setVerticalTextAlignment(const QString &background);
Q_INVOKABLE void updateTitle(const int &row, const QString &title);
Q_INVOKABLE void updateLyrics(const int &row, const QString &lyrics);
@ -53,7 +56,8 @@ public:
Q_INVOKABLE void updateVerseOrder(const int &row, const QString &vorder);
Q_INVOKABLE void updateBackground(const int &row, const QString &background);
Q_INVOKABLE void updateBackgroundType(const int &row, const QString &backgroundType);
Q_INVOKABLE void updateTextAlignment(const int &row, const QString &textAlignment);
Q_INVOKABLE void updateHorizontalTextAlignment(const int &row, const QString &horizontalTextAlignment);
Q_INVOKABLE void updateVerticalTextAlignment(const int &row, const QString &horizontalTextAlignment);
Q_INVOKABLE void newSong();
Q_INVOKABLE void deleteSong(const int &row);
@ -72,7 +76,8 @@ signals:
void vorderChanged();
void backgroundChanged();
void backgroundTypeChanged();
void textAlignmentChanged();
void horizontalTextAlignmentChanged();
void verticalTextAlignmentChanged();
private:
int m_id;
@ -84,7 +89,8 @@ private:
QString m_vorder;
QString m_background;
QString m_backgroundType;
QString m_textAlignment;
QString m_horizontalTextAlignment;
QString m_verticalTextAlignment;
};
#endif //SONGSQLMODEL_H