Commit 6d9672fb authored by camilo higuita's avatar camilo higuita

initial work on albums view #4

parent d6d035a5
......@@ -5,7 +5,7 @@
<file>assets/face-sleeping.png</file>
<file>assets/face-hug.png</file>
<file>assets/pix.png</file>
<file>assets/tag.png</file>
<file>assets/tag.svg</file>
<file>assets/album_bg_normal.png</file>
</qresource>
</RCC>
......@@ -4,5 +4,7 @@ var Query = {
picLikeUrl_ : "select * from images where url like \"%1%\" ",
picTags_ : "select * from images_tags where url = \"%1\"",
allTags : "select * from tags"
allTags : "select * from tags",
allAlbums : "select * from albums"
}
......@@ -121,6 +121,11 @@ bool DBActions::isFav(const QString &url)
return data.first()[PIX::KEY::FAV] == "1" ? true : false;
}
bool DBActions::addTag(const QString &tag)
{
}
bool DBActions::picTag(const QString &tag, const QString &url)
{
QVariantMap tagMap
......@@ -144,6 +149,17 @@ bool DBActions::removePicTag(const QString &tag, const QString &url)
return this->remove(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], tagMap);
}
bool DBActions::addAlbum(const QString &album)
{
QVariantMap albumMap
{
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
};
this->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap);
}
QVariantList DBActions::getFolders()
{
QVariantList res;
......
......@@ -21,9 +21,12 @@ class DBActions : public DB
Q_INVOKABLE bool favPic(const QString &url, const bool &fav);
Q_INVOKABLE bool isFav(const QString &url);
Q_INVOKABLE bool addTag(const QString &tag);
Q_INVOKABLE bool picTag(const QString &tag, const QString &url);
Q_INVOKABLE bool removePicTag(const QString &tag, const QString &url);
Q_INVOKABLE bool addAlbum(const QString &album);
/* utils */
Q_INVOKABLE QVariantList getFolders();
......
......@@ -37,5 +37,10 @@
<file>widgets/dialogs/Tags/TagsDialog.qml</file>
<file>widgets/dialogs/Tags/TagsList.qml</file>
<file>view_models/PixDelegate.qml</file>
<file>widgets/views/Albums/AlbumsGrid.qml</file>
<file>widgets/views/Albums/AlbumDelegate.qml</file>
<file>widgets/dialogs/Albums/AlbumsDialog.qml</file>
<file>widgets/dialogs/Albums/AlbumsList.qml</file>
<file>widgets/dialogs/Albums/NewAlbumDialog.qml</file>
</qresource>
</RCC>
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../custom/TagBar"
import "../../../db/Query.js" as Q
import "../../views/Pix.js" as PIX
PixPopup
{
padding: contentMargins*2
property string picUrl : ""
onOpened: populate()
signal picTagged(string tag)
ColumnLayout
{
anchors.fill: parent
AlbumsList
{
id: albumsList
Layout.fillHeight: true
Layout.fillWidth: true
width: parent.width
height: parent.height
onTagClicked:
{
tagListComposer.model.insert(0, {tag: albumsList.model.get(index).album})
}
}
TextField
{
id: tagText
Layout.fillWidth: true
placeholderText: "Tags..."
onAccepted:
{
var tags = tagText.text.split(",")
for(var i in tags)
{
var tag = tags[i].trim()
if(!pix.checkExistance("tags", "tag", tag))
{
albumsList.model.insert(0, {tag: tag})
tagListComposer.model.insert(0, {tag: tag})
}
}
clear()
}
}
TagList
{
id: tagListComposer
Layout.fillWidth: true
height: 64
width: parent.width
onTagRemoved:
{
pix.removePicTag(model.get(index).tag, pixViewer.currentPic.url)
tagListComposer.model.remove(index)
}
}
Button
{
text: qsTr("Add")
Layout.alignment: Qt.AlignRight
onClicked: addTags(picUrl)
}
}
function addTags(url)
{
var tags = []
for(var i = 0; i < tagListComposer.model.count; i++)
tags.push(tagListComposer.model.get(i))
if(tags.length > 0)
for(i in tags)
{
if(PIX.addTag(tags[i].tag, picUrl))
picTagged(tags[i].tag)
}
close()
}
function populate()
{
tagsList.model.clear()
var tags = pix.get(Q.Query.allTags)
if(tags.length > 0)
for(var i in tags)
tagsList.model.append(tags[i])
tagListComposer.populate(picUrl)
}
}
import QtQuick 2.0
import QtQuick.Controls 2.2
import "../../../view_models"
ListView
{
id: tagListRoot
signal tagClicked(int index)
highlight: Rectangle
{
width: tagListRoot.width
height: tagListRoot.currentItem.height
color: highlightColor
}
focus: true
interactive: true
highlightFollowsCurrentItem: true
model: ListModel{}
delegate: PixDelegate
{
id: delegate
label: tag
Connections
{
target: delegate
onClicked:
{
tagListRoot.currentIndex = index
tagClicked(index)
}
}
}
}
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../custom/TagBar"
import "../../../db/Query.js" as Q
import "../../views/Pix.js" as PIX
PixPopup
{
padding: contentMargins*2
parent: parent
maxWidth: 200
height: 120
signal albumCreated(string album)
ColumnLayout
{
anchors.fill: parent
TextField
{
id: albumText
Layout.fillWidth: true
placeholderText: qsTr("New album...")
onAccepted: addAlbum()
}
Button
{
text: qsTr("Create")
Layout.alignment: Qt.AlignRight
onClicked: addAlbum()
}
}
function addAlbum()
{
if (pix.addAlbum(albumText.text))
albumCreated(albumText.text)
albumText.clear()
close()
}
}
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import org.kde.kirigami 2.2 as Kirigami
ItemDelegate
{
property int albumSize : 32
height: albumSize*2
width: albumSize*3
background: Rectangle
{
color: "transparent"
}
ColumnLayout
{
anchors.fill: parent
Image
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
source: "qrc:/img/assets/album_bg_normal.png"
height: albumSize
sourceSize.height: albumSize
sourceSize.width: albumSize
cache: true
antialiasing: true
fillMode: Image.PreserveAspectFit
}
Label
{
text: album
width: parent.width
Layout.fillWidth: true
horizontalAlignment: Qt.AlignHCenter
elide: Qt.ElideRight
font.pointSize: fontSizes.default
}
}
}
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
GridView
{
id: albumsGridRoot
property int gridSize : 64
signal albumClicked(int index)
clip: true
width: parent.width
height: parent.height
cellHeight: gridSize*2
cellWidth: gridSize*2
focus: true
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.AutoFlickDirection
snapMode: GridView.SnapToRow
model: ListModel
{
id: gridModel
ListElement{album: "Favs"}
ListElement{album: "Recent"}
ListElement{album: "albums"}
ListElement{album: "albums"}
ListElement{album: "albums"}
}
highlightFollowsCurrentItem: true
delegate: AlbumDelegate
{
id: delegate
albumSize : 48
Connections
{
target: delegate
onClicked: albumClicked(index)
}
}
ScrollBar.vertical: ScrollBar{ visible: true}
}
import QtQuick 2.9
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../../db/Query.js" as Q
import "../../dialogs/Albums"
Item
PixPage
{
headerbarExit: stackView.currentItem === picsView
headerbarExitIcon: "go-previous"
headerbarTitle: albumGrid.count+qsTr(" Albums")
onExit: stackView.pop(albumGrid)
headerBarRight: [
PixButton
{
iconName: "overflow-menu"
}
]
headerBarLeft: [
PixButton
{
iconName: "list-add"
onClicked: newAlbumDialog.open()
}
]
NewAlbumDialog
{
id: newAlbumDialog
onAlbumCreated: albumGrid.model.append({"album": album})
}
content: StackView
{
id: stackView
height: parent.height
width: parent.width
initialItem: AlbumsGrid
{
id: albumGrid
onAlbumClicked:
{
headerbarTitle = model.get(index).album
picsView.clear()
// picsView.populate(model.get(index).url)
// if(stackView.currentItem === folderGrid)
// stackView.push(picsView)
}
}
PixGrid
{
id: picsView
headerbarVisible: false
}
}
function populate()
{
var albums = pix.get(Q.Query.allAlbums())
if(albums.length > 0)
for(var i in albums)
albumGrid.model.append(albums[i])
}
function clear()
{
albumGrid.model.clear()
}
function addAlbum()
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment