Mouse interactions in Library

This commit is contained in:
Chris Cochrun 2022-02-25 13:53:25 -06:00
parent b2ea6ab22a
commit 7f432212cd
4 changed files with 105 additions and 75 deletions

View file

@ -140,23 +140,45 @@ Item {
Component {
id: songDelegate
Item{
implicitWidth: ListView.view.width
height: selectedLibrary == "songs" ? 50 : 0
Kirigami.BasicListItem {
id: songListItem
property bool rightMenu: false
implicitWidth: ListView.view.width
height: selectedLibrary == "songs" ? 40 : 0
height: selectedLibrary == "songs" ? 50 : 0
clip: true
label: title
subtitle: author
hoverEnabled: true
ListView.onAdd: {
showPassiveNotification(title, 3000)
songLibraryList.currentIndex = index
song = index
songTitle = title
songLyrics = lyrics
songAuthor = author
songVorder = vorder
supportsMouseEvents: false
backgroundColor: {
if (parent.ListView.isCurrentItem) {
Kirigami.Theme.highlightColor;
} else if (dragHandler.containsMouse){
Kirigami.Theme.hoverColor;
} else {
Kirigami.Theme.backgroundColor;
}
}
textColor: {
if (parent.ListView.isCurrentItem || dragHandler.containsMouse)
activeTextColor;
else
Kirigami.Theme.textColor;
}
/* onAdd: { */
/* showPassiveNotification(title, 3000) */
/* songLibraryList.currentIndex = index */
/* song = index */
/* songTitle = title */
/* songLyrics = lyrics */
/* songAuthor = author */
/* songVorder = vorder */
/* } */
Behavior on height {
NumberAnimation {
@ -164,39 +186,6 @@ Item {
duration: 300
}
}
MouseArea {
id: dragHandler
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
/* width: parent.width */
/* height: parent.height */
/* Layout.alignment: Qt.AlignTop */
/* x: parent.x */
/* y: parent.y */
drag {
target: songListItem
onActiveChanged: {
if (dragHandler.drag.active) {
draggedLibraryItem = songLibraryList.currentItem
showPassiveNotification(index)
}
}
}
onClicked: {
if(mouse.button == Qt.RightButton)
showPassiveNotification("Delete me!");
else{
showPassiveNotification(title, 3000)
songLibraryList.currentIndex = index
song = index
songTitle = title
songLyrics = lyrics
songAuthor = author
songVorder = vorder
}
}
}
Drag.active: dragHandler.drag.active
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
@ -210,6 +199,53 @@ Item {
y: y
}
}
}
MouseArea {
id: dragHandler
anchors.fill: parent
hoverEnabled: true
drag {
target: songListItem
onActiveChanged: {
if (dragHandler.drag.active) {
draggedLibraryItem = songLibraryList.currentItem
showPassiveNotification(index)
}
}
filterChildren: true
threshold: 10
}
MouseArea {
id: clickHandler
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if(mouse.button == Qt.RightButton)
rightClickSongMenu.popup()
else{
showPassiveNotification(title, 3000)
songLibraryList.currentIndex = index
song = index
songTitle = title
songLyrics = lyrics
songAuthor = author
songVorder = vorder
}
}
}
}
Controls.Menu {
id: rightClickSongMenu
x: clickHandler.mouseX
y: clickHandler.mouseY + 10
Kirigami.Action {
text: "delete"
onTriggered: songsqlmodel.deleteSong(index)
}
}
}
}
@ -464,9 +500,4 @@ Item {
}
}
}
function updateSongLyrics(lyrics) {
showPassiveNotification("library function" + lyrics)
showPassiveNotification("WE DID IT!")
}
}

View file

@ -67,6 +67,7 @@ Item {
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.Tooltip
color: Kirigami.Theme.backgroundColor
radius: 10
border.color: Kirigami.Theme.activeBackgroundColor
border.width: 2
}

View file

@ -22,7 +22,7 @@ static void createTable()
QSqlQuery query;
if (!query.exec("CREATE TABLE IF NOT EXISTS 'songs' ("
" 'id' INT NOT NULL,"
" 'id' INTEGER NOT NULL,"
" 'title' TEXT NOT NULL,"
" 'lyrics' TEXT,"
" 'author' TEXT,"
@ -36,10 +36,10 @@ static void createTable()
qDebug() << query.lastQuery();
qDebug() << "inserting into songs";
query.exec("INSERT INTO songs VALUES (1, '10,000 Reasons', '10,000 reasons for my heart to sing', 'Matt Redman', '13470183', '', '')");
query.exec("INSERT INTO songs (title, lyrics, author, ccli, audio, vorder) VALUES ('10,000 Reasons', '10,000 reasons for my heart to sing', 'Matt Redman', '13470183', '', '')");
qDebug() << query.lastQuery();
query.exec("INSERT INTO songs VALUES (2, 'River', 'Im going down to the river', 'Jordan Feliz', '13470183', '', '')");
query.exec("INSERT INTO songs VALUES (3, 'Marvelous Light', 'Into marvelous "
query.exec("INSERT INTO songs (title, lyrics, author, ccli, audio, vorder) VALUES ('River', 'Im going down to the river', 'Jordan Feliz', '13470183', '', '')");
query.exec("INSERT INTO songs (title, lyrics, author, ccli, audio, vorder) VALUES ('Marvelous Light', 'Into marvelous "
"light Im running', 'Chris Tomlin', '13470183', '', '')");
query.exec("select * from songs");
@ -52,7 +52,7 @@ SongSqlModel::SongSqlModel(QObject *parent)
qDebug() << "creating table";
createTable();
setTable(songsTableName);
setEditStrategy(QSqlTableModel::OnFieldChange);
setEditStrategy(QSqlTableModel::OnManualSubmit);
// make sure to call select else the model won't fill
select();
}
@ -86,19 +86,26 @@ void SongSqlModel::newSong() {
int rows = rowCount();
qDebug() << rows;
QSqlRecord recorddata = record(rows);
recorddata.setValue("id", rows + 1);
QSqlRecord recorddata = record();
recorddata.setValue("title", "new song");
qDebug() << recorddata;
if (insertRecord(rows, recorddata)) {
submitAll();
select();
}else {
qDebug() << lastError();
}
}
void SongSqlModel::deleteSong(const int &row) {
QSqlRecord recordData = record(row);
if (recordData.isEmpty())
return;
removeRow(row);
submitAll();
}
int SongSqlModel::id() const {
return m_id;
}
@ -121,11 +128,11 @@ void SongSqlModel::setTitle(const QString &title) {
void SongSqlModel::updateTitle(const int &row, const QString &title) {
qDebug() << "Row is " << row;
QSqlRecord rowdata = record(row);
qDebug() << rowdata;
rowdata.setValue("title", title);
setRecord(row, rowdata);
qDebug() << rowdata;
submitAll();
select();
emit titleChanged();
}
@ -150,8 +157,6 @@ void SongSqlModel::updateAuthor(const int &row, const QString &author) {
rowdata.setValue("author", author);
setRecord(row, rowdata);
submitAll();
select();
emit authorChanged();
}
@ -176,8 +181,6 @@ void SongSqlModel::updateLyrics(const int &row, const QString &lyrics) {
rowdata.setValue("lyrics", lyrics);
setRecord(row, rowdata);
submitAll();
select();
emit lyricsChanged();
}
@ -202,8 +205,6 @@ void SongSqlModel::updateCcli(const int &row, const QString &ccli) {
rowdata.setValue("ccli", ccli);
setRecord(row, rowdata);
submitAll();
select();
emit ccliChanged();
}
@ -228,8 +229,6 @@ void SongSqlModel::updateAudio(const int &row, const QString &audio) {
rowdata.setValue("audio", audio);
setRecord(row, rowdata);
submitAll();
select();
emit audioChanged();
}
@ -252,7 +251,5 @@ void SongSqlModel::updateVerseOrder(const int &row, const QString &vorder) {
rowdata.setValue("vorder", vorder);
setRecord(row, rowdata);
submitAll();
select();
emit vorderChanged();
}

View file

@ -45,6 +45,7 @@ public:
Q_INVOKABLE void updateVerseOrder(const int &row, const QString &vorder);
Q_INVOKABLE void newSong();
Q_INVOKABLE void deleteSong(const int &row);
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;