From 5db946ef53dbddb49ddc846a18a4d2cae753f7cd Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 22 Apr 2022 11:28:50 -0500 Subject: [PATCH] some changes to songs including attributes --- TODO.org | 6 +-- src/qml/presenter/SongEditor.qml | 43 ++++++--------------- src/songsqlmodel.cpp | 66 +++++++++++++++++++++++++++++--- src/songsqlmodel.h | 16 +++++++- 4 files changed, 88 insertions(+), 43 deletions(-) diff --git a/TODO.org b/TODO.org index 9ddd44a..3240ae0 100644 --- a/TODO.org +++ b/TODO.org @@ -4,12 +4,12 @@ :END: * Inbox -** TODO Make toolbar functional for songeditor [1/4] [25%] +** TODO Make toolbar functional for songeditor [3/4] [75%] [[file:~/dev/church-presenter/src/qml/presenter/SongEditor.qml::Controls.ToolBar {]] - [X] alignment -- [ ] font -- [ ] fontsize +- [X] font +- [X] fontsize - [ ] effects? ** TODO bug in changing slides with the arrows diff --git a/src/qml/presenter/SongEditor.qml b/src/qml/presenter/SongEditor.qml index 6fb6b1c..9f10c60 100644 --- a/src/qml/presenter/SongEditor.qml +++ b/src/qml/presenter/SongEditor.qml @@ -10,16 +10,7 @@ Item { id: root property int songIndex - property string songTitle - property string songLyrics - property string songAuthor - property string songCcli - property string songAudio - property string songVorder - property string songBackground - property string songBackgroundType - property string songHAlignment - property string songVAlignment + property var song GridLayout { id: mainLayout @@ -40,7 +31,7 @@ Item { implicitWidth: 300 editable: true hoverEnabled: true - /* onCurrentTextChanged: showPassiveNotification(currentText) */ + onCurrentTextChanged: showPassiveNotification(currentText) } Controls.SpinBox { editable: true @@ -158,7 +149,7 @@ Item { Layout.rightMargin: 20 placeholderText: "Song Title..." - text: songTitle + text: song.title padding: 10 onEditingFinished: updateTitle(text); } @@ -171,7 +162,7 @@ Item { Layout.rightMargin: 20 placeholderText: "verse order..." - text: songVorder + text: song.vorder padding: 10 onEditingFinished: updateVerseOrder(text); } @@ -191,7 +182,7 @@ Item { width: parent.width placeholderText: "Put lyrics here..." persistentSelection: true - text: songLyrics + text: song.lyrics textFormat: TextEdit.PlainText padding: 10 onEditingFinished: { @@ -210,7 +201,7 @@ Item { Layout.rightMargin: 20 placeholderText: "Author..." - text: songAuthor + text: song.author padding: 10 onEditingFinished: updateAuthor(text) } @@ -277,32 +268,20 @@ Item { } function changeSong(index) { - const song = songsqlmodel.getSong(index); + song = songsqlmodel.getSong(index); songIndex = index; - songTitle = song.title; - songLyrics = song.lyrics; - songAuthor = song.author; - songCcli = song.ccli; - songAudio = song.audio; - songVorder = song.vorder; - songBackground = song.background; - songBackgroundType = song.backgroundType; - songHAlignment = song.horizontalTextAlignment; - songVAlignment = song.verticalTextAlignment; - - alignmentSetTimer.restart(); if (songBackgroundType == "image") { slideEditor.videoBackground = ""; - slideEditor.imageBackground = songBackground; + slideEditor.imageBackground = song.background; } else { slideEditor.imageBackground = ""; - slideEditor.videoBackground = songBackground; + slideEditor.videoBackground = song.background; slideEditor.loadVideo(); } - changeSlideHAlignment(songHAlignment); - changeSlideVAlignment(songVAlignment); + changeSlideHAlignment(song.horizontalTextAlignment); + changeSlideVAlignment(song.verticalTextAlignment); print(song); } diff --git a/src/songsqlmodel.cpp b/src/songsqlmodel.cpp index f56bb3d..8717965 100644 --- a/src/songsqlmodel.cpp +++ b/src/songsqlmodel.cpp @@ -36,6 +36,8 @@ static void createTable() " 'backgroundType' TEXT," " 'horizontalTextAlignment' TEXT," " 'verticalTextAlignment' TEXT," + " 'font' TEXT," + " 'fontSize' INTEGER," " PRIMARY KEY(id))")) { qFatal("Failed to query database: %s", qPrintable(query.lastError().text())); @@ -45,16 +47,16 @@ static void createTable() query.exec( "INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, " - "background, backgroundType, horizontalTextAlignment, verticalTextAlignment) VALUES ('10,000 Reasons', '10,000 reasons " - "for my heart to sing', 'Matt Redman', '13470183', '', '', '', '', 'center', 'center')"); + "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) 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, horizontalTextAlignment, verticalTextAlignment) VALUES ('River', 'Im going down to " - "the river', 'Jordan Feliz', '13470183', '', '', '', '', 'center', 'center')"); + "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) 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, horizontalTextAlignment, verticalTextAlignment) VALUES ('Marvelous Light', 'Into marvelous " - "light Im running', 'Chris Tomlin', '13470183', '', '', '', '', 'center', 'center')"); + "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) VALUES ('Marvelous Light', 'Into marvelous " + "light Im running', 'Chris Tomlin', '13470183', '', '', '', '', 'center', 'center', '', '')"); // qDebug() << query.lastQuery(); query.exec("select * from songs"); @@ -485,3 +487,55 @@ void SongSqlModel::updateVerticalTextAlignment(const int &row, const QString &ve submitAll(); emit verticalTextAlignmentChanged(); } + +QString SongSqlModel::font() const { + return m_font; +} + +void SongSqlModel::setFont(const QString &font) { + if (font == m_font) + return; + + m_font = font; + + select(); + emit fontChanged(); +} + +// This function is for updating the lyrics from outside the delegate +void SongSqlModel::updateFont(const int &row, const QString &font) { + qDebug() << "Row is " << row; + QSqlRecord rowdata = record(row); + qDebug() << rowdata; + rowdata.setValue("font", font); + setRecord(row, rowdata); + qDebug() << rowdata; + submitAll(); + emit fontChanged(); +} + +int SongSqlModel::fontSize() const { + return m_fontSize; +} + +void SongSqlModel::setFontSize(const QString &fontSize) { + if (fontSize == m_fontSize) + return; + + m_fontSize = fontSize; + + select(); + emit fontSizeChanged(); +} + +// This function is for updating the lyrics from outside the delegate +void SongSqlModel::updateFontSize(const int &row, const QString &fontSize) { + qDebug() << "Row is " << row; + QSqlRecord rowdata = record(row); + qDebug() << rowdata; + rowdata.setValue("fontSize", fontSize); + setRecord(row, rowdata); + qDebug() << rowdata; + submitAll(); + emit fontSizeChanged(); +} diff --git a/src/songsqlmodel.h b/src/songsqlmodel.h index 6e637ad..1d2b60f 100644 --- a/src/songsqlmodel.h +++ b/src/songsqlmodel.h @@ -20,6 +20,8 @@ class SongSqlModel : public QSqlTableModel Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged) Q_PROPERTY(QString horizontalTextAlignment READ horizontalTextAlignment WRITE setHorizontalTextAlignment NOTIFY horizontalTextAlignmentChanged) Q_PROPERTY(QString verticalTextAlignment READ verticalTextAlignment WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged) + Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) + Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) QML_ELEMENT public: @@ -36,6 +38,8 @@ public: QString backgroundType() const; QString horizontalTextAlignment() const; QString verticalTextAlignment() const; + QString font() const; + int fontSize() const; void setTitle(const QString &title); void setLyrics(const QString &lyrics); @@ -45,8 +49,10 @@ public: void setVerseOrder(const QString &vorder); void setBackground(const QString &background); void setBackgroundType(const QString &backgroundType); - void setHorizontalTextAlignment(const QString &background); - void setVerticalTextAlignment(const QString &background); + void setHorizontalTextAlignment(const QString &horizontalTextAlignment); + void setVerticalTextAlignment(const QString &verticalTextAlignment); + void setFont(const QString &font); + void setFontSize(const int &fontSize); Q_INVOKABLE void updateTitle(const int &row, const QString &title); Q_INVOKABLE void updateLyrics(const int &row, const QString &lyrics); @@ -58,6 +64,8 @@ public: Q_INVOKABLE void updateBackgroundType(const int &row, const QString &backgroundType); Q_INVOKABLE void updateHorizontalTextAlignment(const int &row, const QString &horizontalTextAlignment); Q_INVOKABLE void updateVerticalTextAlignment(const int &row, const QString &horizontalTextAlignment); + Q_INVOKABLE void updateFont(const int &row, const QString &font); + Q_INVOKABLE void updateFontSize(const int &row, const int &fontSize); Q_INVOKABLE void newSong(); Q_INVOKABLE void deleteSong(const int &row); @@ -78,6 +86,8 @@ signals: void backgroundTypeChanged(); void horizontalTextAlignmentChanged(); void verticalTextAlignmentChanged(); + void fontChanged(); + void fontSizeChanged(); private: int m_id; @@ -91,6 +101,8 @@ private: QString m_backgroundType; QString m_horizontalTextAlignment; QString m_verticalTextAlignment; + QString m_font; + int m_fontSize; }; #endif //SONGSQLMODEL_H