Mouse interactions in Library
This commit is contained in:
parent
b2ea6ab22a
commit
7f432212cd
4 changed files with 105 additions and 75 deletions
|
@ -140,39 +140,72 @@ Item {
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: songDelegate
|
id: songDelegate
|
||||||
Kirigami.BasicListItem {
|
Item{
|
||||||
id: songListItem
|
|
||||||
implicitWidth: ListView.view.width
|
implicitWidth: ListView.view.width
|
||||||
height: selectedLibrary == "songs" ? 40 : 0
|
height: selectedLibrary == "songs" ? 50 : 0
|
||||||
clip: true
|
Kirigami.BasicListItem {
|
||||||
label: title
|
id: songListItem
|
||||||
subtitle: author
|
|
||||||
hoverEnabled: true
|
property bool rightMenu: false
|
||||||
ListView.onAdd: {
|
|
||||||
showPassiveNotification(title, 3000)
|
implicitWidth: ListView.view.width
|
||||||
songLibraryList.currentIndex = index
|
height: selectedLibrary == "songs" ? 50 : 0
|
||||||
song = index
|
clip: true
|
||||||
songTitle = title
|
label: title
|
||||||
songLyrics = lyrics
|
subtitle: author
|
||||||
songAuthor = author
|
supportsMouseEvents: false
|
||||||
songVorder = vorder
|
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 {
|
||||||
|
easing.type: Easing.OutCubic
|
||||||
|
duration: 300
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Drag.active: dragHandler.drag.active
|
||||||
|
Drag.hotSpot.x: width / 2
|
||||||
|
Drag.hotSpot.y: height / 2
|
||||||
|
|
||||||
|
states: State {
|
||||||
|
name: "dragged"
|
||||||
|
when: songListItem.Drag.active
|
||||||
|
PropertyChanges {
|
||||||
|
target: songListItem
|
||||||
|
x: x
|
||||||
|
y: y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on height {
|
|
||||||
NumberAnimation {
|
|
||||||
easing.type: Easing.OutCubic
|
|
||||||
duration: 300
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: dragHandler
|
id: dragHandler
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
hoverEnabled: true
|
||||||
/* width: parent.width */
|
|
||||||
/* height: parent.height */
|
|
||||||
/* Layout.alignment: Qt.AlignTop */
|
|
||||||
/* x: parent.x */
|
|
||||||
/* y: parent.y */
|
|
||||||
drag {
|
drag {
|
||||||
target: songListItem
|
target: songListItem
|
||||||
onActiveChanged: {
|
onActiveChanged: {
|
||||||
|
@ -181,33 +214,36 @@ Item {
|
||||||
showPassiveNotification(index)
|
showPassiveNotification(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
filterChildren: true
|
||||||
|
threshold: 10
|
||||||
}
|
}
|
||||||
onClicked: {
|
MouseArea {
|
||||||
if(mouse.button == Qt.RightButton)
|
id: clickHandler
|
||||||
showPassiveNotification("Delete me!");
|
anchors.fill: parent
|
||||||
else{
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
showPassiveNotification(title, 3000)
|
onClicked: {
|
||||||
songLibraryList.currentIndex = index
|
if(mouse.button == Qt.RightButton)
|
||||||
song = index
|
rightClickSongMenu.popup()
|
||||||
songTitle = title
|
else{
|
||||||
songLyrics = lyrics
|
showPassiveNotification(title, 3000)
|
||||||
songAuthor = author
|
songLibraryList.currentIndex = index
|
||||||
songVorder = vorder
|
song = index
|
||||||
|
songTitle = title
|
||||||
|
songLyrics = lyrics
|
||||||
|
songAuthor = author
|
||||||
|
songVorder = vorder
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Drag.active: dragHandler.drag.active
|
Controls.Menu {
|
||||||
Drag.hotSpot.x: width / 2
|
id: rightClickSongMenu
|
||||||
Drag.hotSpot.y: height / 2
|
x: clickHandler.mouseX
|
||||||
|
y: clickHandler.mouseY + 10
|
||||||
states: State {
|
Kirigami.Action {
|
||||||
name: "dragged"
|
text: "delete"
|
||||||
when: songListItem.Drag.active
|
onTriggered: songsqlmodel.deleteSong(index)
|
||||||
PropertyChanges {
|
|
||||||
target: songListItem
|
|
||||||
x: x
|
|
||||||
y: y
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,9 +500,4 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSongLyrics(lyrics) {
|
|
||||||
showPassiveNotification("library function" + lyrics)
|
|
||||||
showPassiveNotification("WE DID IT!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ Item {
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
Kirigami.Theme.colorSet: Kirigami.Theme.Tooltip
|
Kirigami.Theme.colorSet: Kirigami.Theme.Tooltip
|
||||||
color: Kirigami.Theme.backgroundColor
|
color: Kirigami.Theme.backgroundColor
|
||||||
|
radius: 10
|
||||||
border.color: Kirigami.Theme.activeBackgroundColor
|
border.color: Kirigami.Theme.activeBackgroundColor
|
||||||
border.width: 2
|
border.width: 2
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ static void createTable()
|
||||||
|
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
if (!query.exec("CREATE TABLE IF NOT EXISTS 'songs' ("
|
if (!query.exec("CREATE TABLE IF NOT EXISTS 'songs' ("
|
||||||
" 'id' INT NOT NULL,"
|
" 'id' INTEGER NOT NULL,"
|
||||||
" 'title' TEXT NOT NULL,"
|
" 'title' TEXT NOT NULL,"
|
||||||
" 'lyrics' TEXT,"
|
" 'lyrics' TEXT,"
|
||||||
" 'author' TEXT,"
|
" 'author' TEXT,"
|
||||||
|
@ -36,10 +36,10 @@ static void createTable()
|
||||||
qDebug() << query.lastQuery();
|
qDebug() << query.lastQuery();
|
||||||
qDebug() << "inserting into songs";
|
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();
|
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 (title, lyrics, author, ccli, audio, vorder) VALUES ('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 ('Marvelous Light', 'Into marvelous "
|
||||||
"light Im running', 'Chris Tomlin', '13470183', '', '')");
|
"light Im running', 'Chris Tomlin', '13470183', '', '')");
|
||||||
|
|
||||||
query.exec("select * from songs");
|
query.exec("select * from songs");
|
||||||
|
@ -52,7 +52,7 @@ SongSqlModel::SongSqlModel(QObject *parent)
|
||||||
qDebug() << "creating table";
|
qDebug() << "creating table";
|
||||||
createTable();
|
createTable();
|
||||||
setTable(songsTableName);
|
setTable(songsTableName);
|
||||||
setEditStrategy(QSqlTableModel::OnFieldChange);
|
setEditStrategy(QSqlTableModel::OnManualSubmit);
|
||||||
// make sure to call select else the model won't fill
|
// make sure to call select else the model won't fill
|
||||||
select();
|
select();
|
||||||
}
|
}
|
||||||
|
@ -86,19 +86,26 @@ void SongSqlModel::newSong() {
|
||||||
int rows = rowCount();
|
int rows = rowCount();
|
||||||
|
|
||||||
qDebug() << rows;
|
qDebug() << rows;
|
||||||
QSqlRecord recorddata = record(rows);
|
QSqlRecord recorddata = record();
|
||||||
recorddata.setValue("id", rows + 1);
|
|
||||||
recorddata.setValue("title", "new song");
|
recorddata.setValue("title", "new song");
|
||||||
qDebug() << recorddata;
|
qDebug() << recorddata;
|
||||||
|
|
||||||
if (insertRecord(rows, recorddata)) {
|
if (insertRecord(rows, recorddata)) {
|
||||||
submitAll();
|
submitAll();
|
||||||
select();
|
|
||||||
}else {
|
}else {
|
||||||
qDebug() << lastError();
|
qDebug() << lastError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SongSqlModel::deleteSong(const int &row) {
|
||||||
|
QSqlRecord recordData = record(row);
|
||||||
|
if (recordData.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
removeRow(row);
|
||||||
|
submitAll();
|
||||||
|
}
|
||||||
|
|
||||||
int SongSqlModel::id() const {
|
int SongSqlModel::id() const {
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
@ -121,11 +128,11 @@ void SongSqlModel::setTitle(const QString &title) {
|
||||||
void SongSqlModel::updateTitle(const int &row, const QString &title) {
|
void SongSqlModel::updateTitle(const int &row, const QString &title) {
|
||||||
qDebug() << "Row is " << row;
|
qDebug() << "Row is " << row;
|
||||||
QSqlRecord rowdata = record(row);
|
QSqlRecord rowdata = record(row);
|
||||||
|
qDebug() << rowdata;
|
||||||
rowdata.setValue("title", title);
|
rowdata.setValue("title", title);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
|
qDebug() << rowdata;
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit titleChanged();
|
emit titleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,8 +157,6 @@ void SongSqlModel::updateAuthor(const int &row, const QString &author) {
|
||||||
rowdata.setValue("author", author);
|
rowdata.setValue("author", author);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit authorChanged();
|
emit authorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +181,6 @@ void SongSqlModel::updateLyrics(const int &row, const QString &lyrics) {
|
||||||
rowdata.setValue("lyrics", lyrics);
|
rowdata.setValue("lyrics", lyrics);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit lyricsChanged();
|
emit lyricsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,8 +205,6 @@ void SongSqlModel::updateCcli(const int &row, const QString &ccli) {
|
||||||
rowdata.setValue("ccli", ccli);
|
rowdata.setValue("ccli", ccli);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit ccliChanged();
|
emit ccliChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +229,6 @@ void SongSqlModel::updateAudio(const int &row, const QString &audio) {
|
||||||
rowdata.setValue("audio", audio);
|
rowdata.setValue("audio", audio);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit audioChanged();
|
emit audioChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +251,5 @@ void SongSqlModel::updateVerseOrder(const int &row, const QString &vorder) {
|
||||||
rowdata.setValue("vorder", vorder);
|
rowdata.setValue("vorder", vorder);
|
||||||
setRecord(row, rowdata);
|
setRecord(row, rowdata);
|
||||||
submitAll();
|
submitAll();
|
||||||
|
|
||||||
select();
|
|
||||||
emit vorderChanged();
|
emit vorderChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
Q_INVOKABLE void updateVerseOrder(const int &row, const QString &vorder);
|
Q_INVOKABLE void updateVerseOrder(const int &row, const QString &vorder);
|
||||||
|
|
||||||
Q_INVOKABLE void newSong();
|
Q_INVOKABLE void newSong();
|
||||||
|
Q_INVOKABLE void deleteSong(const int &row);
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue