Commit 08f59df1 authored by camilo higuita's avatar camilo higuita

now using mauikit base model and list and fixes on random bugs

parent 75c35315
......@@ -22,13 +22,9 @@ set(pix_SRCS
src/pix.cpp
src/db/db.cpp
src/db/dbactions.cpp
src/models/basemodel.cpp
src/models/baselist.cpp
src/models/gallery/gallery.cpp
src/models/albums/albums.cpp
src/models/folders/folders.cpp
src/models/folders/foldermodel.cpp
src/models/cloud/cloud.cpp
)
set(pix_HDRS
......@@ -37,13 +33,9 @@ set(pix_HDRS
src/db/db.h
src/db/dbactions.h
src/utils/pic.h
src/models/basemodel.h
src/models/baselist.h
src/models/gallery/gallery.h
src/models/albums/albums.h
src/models/folders/folders.h
src/models/folders/foldermodel.h
src/models/cloud/cloud.h
)
set(pix_ASSETS
......
......@@ -151,7 +151,6 @@ int main(int argc, char *argv[])
qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList");
qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
qmlRegisterType<FolderModel>("FolderModel", 1, 0, "FolderModel");
qmlRegisterType<Folders>("FoldersList", 1, 0, "FoldersList");
// qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
......
......@@ -239,14 +239,11 @@ QVariantList DBActions::searchFor(const QStringList &queries, const QString &que
FMH::MODEL_LIST DBActions::getFolders(const QString &query)
{
FMH::MODEL_LIST res;
auto data = this->getDBData(query);
/*Data model keys for to be used on MauiKit Icondelegate component */
for(auto i : data)
res << FMH::getFileInfoModel(i[FMH::MODEL_KEY::URL]);
return res;
const auto data = this->getDBData(query);
return std::accumulate(data.begin(), data.end(), FMH::MODEL_LIST(), [](FMH::MODEL_LIST &res, const FMH::MODEL &item){
res << FMH::getFileInfoModel(item[FMH::MODEL_KEY::URL]);
return res;
});
}
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt, std::function<void(FMH::MODEL &item)> modifier)
......
......@@ -222,30 +222,30 @@ Maui.ApplicationWindow
currentIndex: _actionGroup.currentIndex
onCurrentIndexChanged: _actionGroup.currentIndex = currentIndex
PixViewer
{
id: pixViewer
}
PixViewer
{
id: pixViewer
}
GalleryView
{
id: galleryView
}
// FoldersView
// {
// id: foldersView
// }
FoldersView
{
id: foldersView
}
// AlbumsView
// {
// id: albumsView
// }
AlbumsView
{
id: albumsView
}
// TagsView
// {
// id: tagsView
// }
TagsView
{
id: tagsView
}
// // Loader
......@@ -268,11 +268,13 @@ Maui.ApplicationWindow
SelectionBar
{
id: selectionBox
Layout.fillWidth : true
Layout.leftMargin: Maui.Style.space.big
Layout.rightMargin: Maui.Style.space.big
Layout.bottomMargin: Maui.Style.space.big
Layout.maximumWidth: 500
Layout.minimumWidth: 100
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Layout.margins: Maui.Style.space.big
Layout.topMargin: Maui.Style.space.small
Layout.bottomMargin: Maui.Style.space.big
}
}
......
#ifndef FOLDERMODEL_H
#define FOLDERMODEL_H
#include <QAbstractListModel>
#include <QList>
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/mauilist.h>
#endif
class Folders;
class FolderModel : public QAbstractListModel
class FolderModel : public MauiList
{
Q_OBJECT
Q_PROPERTY(Folders *list READ getList WRITE setList)
......@@ -14,16 +21,7 @@ public:
explicit FolderModel(QObject *parent = nullptr);
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual QHash<int, QByteArray> roleNames() const override;
FMH::MODEL_LIST items() const override final;
Folders* getList() const;
void setList(Folders *value);
......
#include "./src/models/folders/folders.h"
#include "./src/db/dbactions.h"
Folders::Folders(QObject *parent) : QObject(parent)
Folders::Folders(QObject *parent) : MauiList(parent)
{
qDebug()<< "CREATING GALLERY LIST";
this->dba = DBActions::getInstance();
this->sortList();
connect(this, &Folders::sortByChanged, this, &Folders::sortList);
connect(this, &Folders::orderChanged, this, &Folders::sortList);
connect(this, &Folders::queryChanged, this, &Folders::setList);
connect(this, &Folders::sortByChanged, this, &Folders::setList);
}
void Folders::setSortBy(const uint &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
emit this->sortByChanged();
}
uint Folders::getSortBy() const
{
return this->sort;
this->setList();
}
FMH::MODEL_LIST Folders::items() const
......@@ -33,74 +12,10 @@ FMH::MODEL_LIST Folders::items() const
return this->list;
}
void Folders::setQuery(const QString &query)
{
if(this->query == query)
return;
this->query = query;
qDebug()<< "setting ALBUMS query"<< this->query;
emit this->queryChanged();
}
QString Folders::getQuery() const
{
return this->query;
}
void Folders::sortList()
{
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
qSort(this->list.begin(), this->list.end(), [key](const FMH::MODEL& e1, const FMH::MODEL& e2) -> bool
{
auto role = key;
switch(role)
{
case FMH::MODEL_KEY::MODIFIED:
case FMH::MODEL_KEY::DATE:
{
auto currentTime = QDateTime::currentDateTime();
auto date1 = QDateTime::fromString(e1[role], Qt::TextDate);
auto date2 = QDateTime::fromString(e2[role], Qt::TextDate);
if(date1.secsTo(currentTime) < date2.secsTo(currentTime))
return true;
break;
}
case FMH::MODEL_KEY::LABEL:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
if(str1 < str2)
return true;
break;
}
default:
if(e1[role] < e2[role])
return true;
}
return false;
});
}
void Folders::setList()
{
emit this->preListChanged();
this->list = this->dba->getFolders(this->query);
// this->list =
// qDebug()<< "ALBUMS LIST READY"<< list;
this->sortList();
this->list = DBActions::getInstance()->getFolders("select * from sources");
emit this->postListChanged();
}
......
......@@ -6,51 +6,24 @@
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/fmh.h>
#include <MauiKit/mauilist.h>
#endif
class DBActions;
class Folders : public QObject
class Folders : public MauiList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(uint sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
explicit Folders(QObject *parent = nullptr);
FMH::MODEL_LIST items() const;
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const uint &sort);
uint getSortBy() const;
FMH::MODEL_LIST items() const override final;
private:
DBActions *dba;
FMH::MODEL_LIST list;
void sortList();
void setList();
QString query;
uint sort = FMH::MODIFIED;
protected:
signals:
void queryChanged();
void orderChanged();
void sortByChanged();
void preItemAppended();
void postItemAppended();
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
QVariantMap get(const int &index) const;
void refresh();
......
......@@ -65,7 +65,7 @@ public slots:
bool update(const FMH::MODEL &pic);
bool remove(const int &index);
bool deleteAt(const int &index);
bool fav(const int &index, const bool &value);
bool fav(const int &url, const bool &value);
void append(const QVariantMap &pic);
void append(const QString &url);
// void appendAt(const QString &url, const int &pos);
......
......@@ -73,7 +73,7 @@ void Pix::populateDB(const QList<QUrl> &urls)
void Pix::showInFolder(const QStringList &urls)
{
for(const auto &url : urls)
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(url).dir().absolutePath()));
QDesktopServices::openUrl(FMH::fileDir(url));
}
void Pix::addSources(const QStringList &paths)
......
This diff is collapsed.
......@@ -3,7 +3,7 @@ import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.6 as Kirigami
import org.maui.pix 1.0 as Pix
import "../db/Query.js" as Q
import "../widgets/views/Pix.js" as PIX
......@@ -14,12 +14,12 @@ Menu
property bool isFav : false
property int index : -1
onOpened: isFav = dba.isFav(list.get(index).url)
onOpened: isFav = Pix.DB.isFav(model.get(index).url)
MenuItem
{
text: qsTr("Select")
onTriggered: PIX.selectItem(list.get(index))
onTriggered: PIX.selectItem(model.get(index))
}
MenuSeparator{}
......@@ -36,7 +36,7 @@ Menu
onTriggered:
{
dialogLoader.sourceComponent = albumsDialogComponent
dialog.show([list.get(index).url])
dialog.show([model.get(index).url])
}
}
......@@ -46,7 +46,7 @@ Menu
onTriggered:
{
dialogLoader.sourceComponent = tagsDialogComponent
dialog.show([list.get(index).url])
dialog.show([model.get(index).url])
}
}
......@@ -56,11 +56,11 @@ Menu
onTriggered:
{
if(isAndroid)
Maui.Android.shareDialog([list.get(index).url])
Maui.Android.shareDialog([model.get(index).url])
else
{
dialogLoader.sourceComponent = shareDialogComponent
dialog.show([list.get(index).url])
dialog.show([model.get(index).url])
}
}
}
......@@ -70,10 +70,10 @@ Menu
text: qsTr("Save to...")
onTriggered:
{
var pic = list.get(index).url
var pic = model.get(index).url
dialogLoader.sourceComponent= fmDialogComponent
dialog.mode = dialog.modes.SAVE
dialog.suggestedFileName= Maui.FM.getFileInfo(list.get(index).url).label
dialog.suggestedFileName= Maui.FM.getFileInfo(model.get(index).url).label
dialog.show(function(paths)
{
if (typeof paths == 'string')
......@@ -96,7 +96,7 @@ Menu
text: qsTr("Show in folder...")
onTriggered:
{
pix.showInFolder([list.get(index).url])
Pix.Collection.showInFolder([model.get(index).url])
close()
}
}
......@@ -136,7 +136,7 @@ Menu
onRejected: close()
onAccepted:
{
list.deleteAt(index)
model.deleteAt(index)
close()
}
}
......
......@@ -9,7 +9,6 @@ Maui.ItemDelegate
{
id: control
property int picSize : Maui.Style.iconSizes.enormous
property int picRadius : 0
property bool showLabel : true
property bool showIndicator : false
......@@ -17,30 +16,28 @@ Maui.ItemDelegate
property bool fit : false
property bool isHovered : hovered
property bool cachePic: false
property bool dropShadow: false
property alias source : img.source
property alias label : _label.text
property string indicatorColor: ListView.isCurrentItem ? Kirigami.Theme.highlightColor : "transparent"
property color labelColor : (GridView.isCurrentItem || (keepEmblemOverlay && emblemAdded)) && !hovered && showSelectionBackground? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
property color hightlightedColor : GridView.isCurrentItem || hovered || (keepEmblemOverlay && emblemAdded) ? Kirigami.Theme.highlightColor : "transparent"
property color labelColor : (selected || isCurrentItem || (keepEmblemOverlay && selected)) && !hovered && showSelectionBackground? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
property color hightlightedColor : selected || isCurrentItem || hovered || (keepEmblemOverlay && selected) ? Kirigami.Theme.highlightColor : "transparent"
property bool showSelectionBackground : true
property bool emblemAdded : false
property bool selected : false
property bool keepEmblemOverlay : false
// signal rightClicked();
signal emblemClicked();
hoverEnabled: !Kirigami.Settings.isMobile
focus: true
padding: Maui.Style.space.medium
background: Rectangle
{
color: "transparent"
}
// background: Rectangle
// {
// color: "transparent"
// }
// MouseArea
// {
......@@ -56,14 +53,14 @@ Maui.ItemDelegate
Maui.Badge
{
id: emblem
iconName: "list-add"
iconName: selected ? "lisr-remove" : "list-add"
visible: isHovered || showEmblem
z: 999
anchors.top: parent.top
anchors.left: parent.left
onClicked:
{
emblemAdded = !emblemAdded
selected = !selected
emblemClicked(index)
}
}
......@@ -71,7 +68,7 @@ Maui.ItemDelegate
ColumnLayout
{
anchors.fill: parent
anchors.margins: Maui.Style.space.tiny
Item
{
Layout.fillHeight: true
......@@ -82,42 +79,34 @@ Maui.ItemDelegate
{
id: img
anchors.fill: parent
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
sourceSize.height: height
sourceSize.width: width
cache: control.cachePic
antialiasing: true
asynchronous: true
smooth: true
fillMode: fit ? Image.PreserveAspectFit : Image.PreserveAspectCrop
source: (url && url.length>0) ? model.url : "qrc:/img/assets/image-x-generic.svg"
fillMode: control.fit ? Image.PreserveAspectFit : Image.PreserveAspectCrop
source: (model.url && model.url.length>0) ? model.url : "qrc:/img/assets/image-x-generic.svg"
Rectangle
{
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
visible: showIndicator
color: indicatorColor
visible: control.showIndicator
color: control.isCurrentItem ? Kirigami.Theme.highlightColor : "transparent"
height: Maui.Style.iconSizes.small
width: Maui.Style.iconSizes.small
radius: Math.min(width, height)
}
layer.enabled: picRadius > 0
layer.enabled: true
layer.effect: OpacityMask
{
maskSource: Item
maskSource: Rectangle
{
width: img.sourceSize.width
height: img.sourceSize.height
Rectangle
{
anchors.centerIn: parent
width: img.adapt ? img.sourceSize.width : Math.min(img.sourceSize.width, img.sourceSize.height)
height: img.adapt ? img.sourceSize.height : width
radius: picRadius
}
width: img.width
height: img.height
radius: control.picRadius
}
}
......@@ -131,12 +120,24 @@ Maui.ItemDelegate
}
}
Rectangle
// Rectangle
// {
// anchors.fill: parent
// color: hovered ? "#333" : "transparent"
// opacity: hovered ? 0.3 : 0
// radius: picRadius
// }
DropShadow
{
anchors.fill: parent
color: hovered ? "#333" : "transparent"
opacity: hovered ? 0.3 : 0
radius: picRadius
anchors.fill: img
visible: control.dropShadow
horizontalOffset: 0
verticalOffset: 0
radius: 8.0
samples: 17
color: "#80000000"
source: img
}
}
......
import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.6 as Kirigami
import org.kde.mauikit 1.1 as MauiLab
import "../widgets/views/Pix.js" as PIX
import "../widgets/views/Viewer/Viewer.js" as VIEWER
Maui.SelectionBar
MauiLab.SelectionBar
{
id: control
Layout.fillWidth : true
Layout.leftMargin: Maui.Style.space.big
Layout.rightMargin: Maui.Style.space.big
Layout.bottomMargin: Maui.Style.space.big
Layout.topMargin: Maui.Style.space.small
visible: selectionList.count > 0 && currentView !== views.viewer
onIconClicked: _menu.popup()
visible: count > 0 && _actionGroup.currentIndex !== views.viewer
onExitClicked: clear()
// colorScheme.backgroundColor: "#212121"
// Maui.Dialog
// {
// id: removeDialog
// property var paths: []
Menu
// title: qsTr("Delete files?")
// acceptButton.text: qsTr("Accept")
// rejectButton.text: qsTr("Cancel")
// message: qsTr("If you are sure you want to delete the files click on Accept, otherwise click on Cancel")
// onRejected: close()
// onAccepted:
// {
// PIX.removePics(selectedPaths)
// control.clear()
// close()
// }
// }
listDelegate: Maui.ItemDelegate
{
id: _menu
MenuItem
Kirigami.Theme.inherit: true
height: Maui.Style.toolBarHeight
width: parent.width
Maui.ListItemTemplate
{
text: qsTr("Un/Fav them")
onTriggered: VIEWER.fav(selectedPaths)
anchors.fill: parent
label1.text: model.title
label2.text: model.url
imageSource: model.url
}
MenuItem
onClicked: control.removeAtIndex(index)
}
Action
{
text: qsTr("Un/Fav")
icon.name: "love"
onTriggered: VIEWER.fav(selectedPaths)
}
Action
{
text: qsTr("Add to")
icon.name: "document-save"
onTriggered:
{
text: qsTr("Add to...")
onTriggered:
{
dialogLoader.sourceComponent = albumsDialogComponent
dialog.show(control.selectedPaths)
}
dialogLoader.sourceComponent = albumsDialogComponent
dialog.show(control.selectedPaths)
}
}
MenuItem
Action
{
text: qsTr("Tag")
icon.name: "tag"
onTriggered:
{
text: qsTr("Tags...")
onTriggered:
{
dialogLoader.sourceComponent = tagsDialogComponent
dialog.show(selectedPaths)
}
dialogLoader.sourceComponent = tagsDialogComponent
dialog.show(selectedPaths)
}
}
MenuItem
Action
{
text: qsTr("Share")
icon.name: "document-share"
onTriggered:
{
text: qsTr("Share...")
onTriggered:
if(isAndroid)
Maui.Android.shareDialog(selectedPaths)
else
{
if(isAndroid)
Maui.Android.shareDialog(selectedPaths)
else
{
dialogLoader.sourceComponent = shareDialogComponent
dialog.show(selectedPaths)
}
dialogLoader.sourceComponent = shareDialogComponent
dialog.show(selectedPaths)
}
}
}
MenuItem
Action
{
text: qsTr("Export")
icon.name: "document-save"
onTriggered:
{
text: qsTr("Save to...")
onTriggered:
var pics = selectedPaths
dialogLoader.sourceComponent= fmDialogComponent
dialog.show(function(paths)