Commit b821e385 authored by Camilo Higuita's avatar Camilo Higuita

working galleryView

parent 828dd10e
...@@ -20,7 +20,6 @@ DEFINES += QT_DEPRECATED_WARNINGS ...@@ -20,7 +20,6 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp \ SOURCES += main.cpp \
src/utils/utils.cpp \
src/db/collectionDB.cpp \ src/db/collectionDB.cpp \
src/utils/pix.cpp src/utils/pix.cpp
...@@ -47,6 +46,5 @@ DISTFILES += \ ...@@ -47,6 +46,5 @@ DISTFILES += \
HEADERS += \ HEADERS += \
src/utils/pix.h \ src/utils/pix.h \
src/utils/utils.h \
src/db/collectionDB.h \ src/db/collectionDB.h \
src/db/fileloader.h src/db/fileloader.h
[Global]
IconName=preferences-system-bluetooth
Comment=Tiny Music Player
Name=Babe
[Event/Notify]
Name=Babe...
Comment=Connection to device failed
Icon=babe-qt
Action=Popup
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QFontDatabase> #include <QFontDatabase>
#include <QQmlContext> #include <QQmlContext>
#include <QQuickStyle>
#include "src/utils/pix.h" #include "src/utils/pix.h"
#include "src/utils/utils.h"
//#ifdef Q_OS_ANDROID //#ifdef Q_OS_ANDROID
//#include "./3rdparty/kirigami/src/kirigamiplugin.h" //#include "./3rdparty/kirigami/src/kirigamiplugin.h"
...@@ -26,10 +25,7 @@ int main(int argc, char *argv[]) ...@@ -26,10 +25,7 @@ int main(int argc, char *argv[])
auto context = engine.rootContext(); auto context = engine.rootContext();
Pix pix; Pix pix;
context->setContextProperty("PIX", &pix); context->setContextProperty("pix", &pix);
Utils util;
context->setContextProperty("UTI", &util);
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
......
var Query = {
allPics : "select * from images order by addDate desc"
}
...@@ -268,6 +268,33 @@ DB_LIST CollectionDB::getDBData(const QString &queryTxt) ...@@ -268,6 +268,33 @@ DB_LIST CollectionDB::getDBData(const QString &queryTxt)
} }
QVariantList CollectionDB::getDBDataQML(const QString &queryTxt)
{
QVariantList mapList;
auto query = this->getQuery(queryTxt);
if(query.exec())
{
while(query.next())
{
QVariantMap data;
for(auto key : KEYMAP.keys())
if(query.record().indexOf(KEYMAP[key])>-1)
data[KEYMAP[key]] = query.value(KEYMAP[key]).toString();
mapList<< data;
}
}else qDebug()<< query.lastError()<< query.lastQuery();
return mapList;
}
QSqlQuery CollectionDB::getQuery(const QString &queryTxt) QSqlQuery CollectionDB::getQuery(const QString &queryTxt)
{ {
QSqlQuery query(queryTxt, this->m_db); QSqlQuery query(queryTxt, this->m_db);
......
...@@ -38,6 +38,8 @@ public: ...@@ -38,6 +38,8 @@ public:
/*useful tools*/ /*useful tools*/
PIX::DB_LIST getDBData(const QString &queryTxt); PIX::DB_LIST getDBData(const QString &queryTxt);
QVariantList getDBDataQML(const QString &queryTxt);
bool execQuery(const QString &queryTxt); bool execQuery(const QString &queryTxt);
QSqlQuery getQuery(const QString &queryTxt); QSqlQuery getQuery(const QString &queryTxt);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <QThread> #include <QThread>
#include <QObject> #include <QObject>
#include <QDirIterator> #include <QDirIterator>
#include <QFileInfo>
#include "collectionDB.h" #include "collectionDB.h"
class FileLoader : public QObject class FileLoader : public QObject
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
qRegisterMetaType<PIX::TABLE>("PIX::TABLE"); qRegisterMetaType<PIX::TABLE>("PIX::TABLE");
qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>"); qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>");
this->con = new CollectionDB("fileLoader", this); this->con = new CollectionDB(this);
this->moveToThread(&t); this->moveToThread(&t);
t.start(); t.start();
} }
...@@ -88,8 +88,8 @@ public slots: ...@@ -88,8 +88,8 @@ public slots:
{PIX::KEY::FAV, "0"}, {PIX::KEY::FAV, "0"},
{PIX::KEY::RATE, "0"}, {PIX::KEY::RATE, "0"},
{PIX::KEY::COLOR, ""}, {PIX::KEY::COLOR, ""},
{PIX::KEY::SOURCES_URL,sourceUrl}, {PIX::KEY::SOURCES_URL, sourceUrl},
{PIX::KEY::PIC_DATE, info.birthTime().toString()} {PIX::KEY::PIC_DATE, info.created().toString()}
}; };
this->con->addPic(trackMap); this->con->addPic(trackMap);
......
...@@ -23,16 +23,18 @@ ApplicationWindow ...@@ -23,16 +23,18 @@ ApplicationWindow
currentIndex: currentView currentIndex: currentView
onGalleryViewClicked: currentView = 0 onViewerViewClicked: currentView = 0
onAlbumsViewClicked: currentView = 1 onGalleryViewClicked: currentView = 1
onTagsViewClicked: currentView = 2 onFoldersViewClicked: currentView = 2
onSettingsViewClicked: currentView = 3 onAlbumsViewClicked: currentView = 3
onTagsViewClicked: currentView = 4
onSettingsViewClicked: {}
} }
Rectangle Rectangle
{ {
anchors.fill: parent anchors.fill: parent
color: UTI.altColor() color: pix.altColor()
z: -999 z: -999
} }
...@@ -53,6 +55,11 @@ ApplicationWindow ...@@ -53,6 +55,11 @@ ApplicationWindow
currentView = currentIndex currentView = currentIndex
} }
PixsViewer
{
}
GalleryView GalleryView
{ {
......
...@@ -15,5 +15,10 @@ ...@@ -15,5 +15,10 @@
<file>widgets/SettingsView.qml</file> <file>widgets/SettingsView.qml</file>
<file>db/script.sql</file> <file>db/script.sql</file>
<file>widgets/FoldersView.qml</file> <file>widgets/FoldersView.qml</file>
<file>view_models/PixPic.qml</file>
<file>view_models/PixHolder.qml</file>
<file>../assets/face.png</file>
<file>../assets/Babe.notifyrc</file>
<file>db/Query.js</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -2,24 +2,28 @@ ...@@ -2,24 +2,28 @@
#include "../db/fileloader.h" #include "../db/fileloader.h"
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QTimer> #include <QTimer>
#include <QApplication>
#include <QDesktopWidget>
#include <QDirIterator>
#include <QtQml>
#include <QPalette>
#include <QWidget>
#include <QColor>
using namespace PIX; using namespace PIX;
Pix::Pix(QObject *parent) : QObject(parent) Pix::Pix(QObject *parent) : QObject(parent)
{ {
qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath; qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath;
qDebug() << "Getting settings info from: " << PIX::SettingPath; qDebug() << "Getting settings info from: " << PIX::SettingPath;
qDebug() << "Getting artwork files from: " << PIX::CachePath; qDebug() << "Getting artwork files from: " << PIX::CachePath;
// if(!PIX::fileExists(notifyDir+"/Babe.notifyrc")) // if(!PIX::fileExists(notifyDir+"/Pix.notifyrc"))
// { // {
// qDebug()<<"The Knotify file does not exists, going to create it"; // qDebug()<<"The Knotify file does not exists, going to create it";
// QFile knotify(":Data/data/Babe.notifyrc"); // QFile knotify(":Data/data/Pix.notifyrc");
// if(knotify.copy(notifyDir+"/Babe.notifyrc")) // if(knotify.copy(notifyDir+"/Pix.notifyrc"))
// qDebug()<<"the knotify file got copied"; // qDebug()<<"the knotify file got copied";
// } // }
...@@ -32,7 +36,7 @@ Pix::Pix(QObject *parent) : QObject(parent) ...@@ -32,7 +36,7 @@ Pix::Pix(QObject *parent) : QObject(parent)
cachePath_dir.mkpath("."); cachePath_dir.mkpath(".");
this->con = new CollectionDB("Pix", this); this->con = new CollectionDB(this);
this->fileLoader = new FileLoader; this->fileLoader = new FileLoader;
this->watcher = new QFileSystemWatcher(this); this->watcher = new QFileSystemWatcher(this);
connect(this->watcher, &QFileSystemWatcher::directoryChanged, this, &Pix::handleDirectoryChanged); connect(this->watcher, &QFileSystemWatcher::directoryChanged, this, &Pix::handleDirectoryChanged);
...@@ -72,16 +76,7 @@ QVariantList Pix::getList(const QStringList &urls) ...@@ -72,16 +76,7 @@ QVariantList Pix::getList(const QStringList &urls)
QVariantList Pix::get(const QString &queryTxt) QVariantList Pix::get(const QString &queryTxt)
{ {
QVariantList res; return this->con->getDBDataQML(queryTxt);
for(auto data : this->con->getDBData(queryTxt))
{
QVariantMap map;
for(auto key : data.keys())
map[PIX::KEYMAP[key]] = data[key];
res << map;
}
return res;
} }
bool Pix::run(const QString &query) bool Pix::run(const QString &query)
...@@ -151,3 +146,140 @@ void Pix::handleDirectoryChanged(const QString &dir) ...@@ -151,3 +146,140 @@ void Pix::handleDirectoryChanged(const QString &dir)
wait->start(); wait->start();
} }
QString Pix::backgroundColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Background).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Pix::foregroundColor()
{
#if defined(Q_OS_ANDROID)
return "#FFF";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Text).name();
#elif defined(Q_OS_WIN32)
return "#FFF";
#endif
}
QString Pix::hightlightColor()
{
#if defined(Q_OS_ANDROID)
return "";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Highlight).name();
#elif defined(Q_OS_WIN32)
return "";
#endif
}
QString Pix::midColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Midlight).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Pix::altColor()
{
#if defined(Q_OS_ANDROID)
return "#232629";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Base).name();
#elif defined(Q_OS_WIN32)
return "#232629";
#endif
}
QString Pix::pixColor()
{
return "#03A9F4";
}
bool Pix::isMobile()
{
return PIX::isMobile();
}
int Pix::screenGeometry(QString &side)
{
side = side.toLower();
auto geo = QApplication::desktop()->screenGeometry();
if(side == "width")
return geo.width();
else if(side == "height")
return geo.height();
else return 0;
}
int Pix::cursorPos(QString &axis)
{
axis = axis.toLower();
auto pos = QCursor::pos();
if(axis == "x")
return pos.x();
else if(axis == "y")
return pos.y();
else return 0;
}
QString Pix::homeDir()
{
return PIX::PicturesPath;
}
QVariantList Pix::getDirs(const QString &pathUrl)
{
auto path = pathUrl;
if(path.startsWith("file://"))
path.replace("file://", "");
qDebug()<<"DIRECTRORY"<<path;
QVariantList paths;
if (QFileInfo(path).isDir())
{
QDirIterator it(path, QDir::Dirs, QDirIterator::NoIteratorFlags);
while (it.hasNext())
{
auto url = it.next();
auto name = QDir(url).dirName();
qDebug()<<name<<url;
QVariantMap map = { {"url", url }, {"name", name} };
paths << map;
}
}
return paths;
}
QVariantMap Pix::getParentDir(const QString &path)
{
auto dir = QDir(path);
dir.cdUp();
auto dirPath = dir.absolutePath();
if(dir.isReadable() && !dir.isRoot() && dir.exists())
return {{"url", dirPath}, {"name", dir.dirName()}};
else
return {{"url", path}, {"name", QFileInfo(path).dir().dirName()}};
}
...@@ -228,6 +228,26 @@ namespace PIX ...@@ -228,6 +228,26 @@ namespace PIX
return variant; return variant;
} }
inline bool isMobile()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return true;
#elif defined(Q_OS_HAIKU)
return false;
#endif
}
} }
...@@ -247,6 +267,24 @@ public: ...@@ -247,6 +267,24 @@ public:
Q_INVOKABLE QVariantList get(const QString &queryTxt); Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE bool run(const QString &query); Q_INVOKABLE bool run(const QString &query);
Q_INVOKABLE static QString backgroundColor();
Q_INVOKABLE static QString foregroundColor();
Q_INVOKABLE static QString hightlightColor();
Q_INVOKABLE static QString midColor();
Q_INVOKABLE static QString altColor();
Q_INVOKABLE static QString pixColor();
Q_INVOKABLE static bool isMobile();
Q_INVOKABLE static int screenGeometry(QString &side);
Q_INVOKABLE static int cursorPos(QString &axis);
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
private: private:
CollectionDB *con; CollectionDB *con;
FileLoader *fileLoader; FileLoader *fileLoader;
...@@ -256,7 +294,7 @@ private: ...@@ -256,7 +294,7 @@ private:
void populateDB(const QString &path); void populateDB(const QString &path);
void collectionWatcher(); void collectionWatcher();
void addToWatcher(QStringList paths); void addToWatcher(QStringList paths);
void handleDirectoryChanged(const QString &dir); void handleDirectoryChanged(const QString &dir);
signals: signals:
void refreshTables(QVariantMap tables); void refreshTables(QVariantMap tables);
......
#include "utils.h"
#include "pix.h"
#include <QPalette>
#include <QWidget>
#include <QColor>
using namespace PIX;
Utils::Utils(QObject *parent) : QObject(parent)
{ }
QString Utils::backgroundColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Background).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Utils::foregroundColor()
{
#if defined(Q_OS_ANDROID)
return "#FFF";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Text).name();
#elif defined(Q_OS_WIN32)
return "#FFF";
#endif
}
QString Utils::hightlightColor()
{
#if defined(Q_OS_ANDROID)
return "";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Highlight).name();
#elif defined(Q_OS_WIN32)
return "";
#endif
}
QString Utils::midColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Midlight).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Utils::altColor()
{
#if defined(Q_OS_ANDROID)
return "#232629";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Base).name();
#elif defined(Q_OS_WIN32)
return "#232629";
#endif
}
#ifndef UTILS_H
#define UTILS_H
#include <QObject>
class Utils : public QObject
{
Q_OBJECT
public:
explicit Utils(QObject *parent = nullptr);
Q_INVOKABLE static QString backgroundColor();
Q_INVOKABLE static QString foregroundColor();
Q_INVOKABLE static QString hightlightColor();
Q_INVOKABLE static QString midColor();
Q_INVOKABLE static QString altColor();
};
#endif // UTILS_H
import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3 import QtQuick 2.9
Item Pane
{ {
id: gridPage
/*props*/
property int picSize : 150
property int picSpacing: 20
property int picRadius : 4
property alias gridModel: gridModel
property alias grid: grid
/*signals*/
signal picClicked(string url)
width: 500
height: 400
background: Rectangle
{
anchors.fill: parent
color: pix.altColor()
z: -999
}
function clearGrid()
{
gridModel.clear()
}
PixHolder
{
visible: grid.count === 0
message: "No pics..."
}
GridView
{
id: grid
// width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
width: parent.width
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
cellWidth: picSize + picSpacing
cellHeight: picSize + picSpacing
highlightFollowsCurrentItem: false
focus: true
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.AutoFlickDirection
snapMode: GridView.SnapToRow
// flow: GridView.FlowTopToBottom
// maximumFlickVelocity: albumSize*8
ListModel {id: gridModel}
model: gridModel
highlight: Rectangle
{
id: highlight
width: picSize
height: picSize
color: pix.hightlightColor()
radius: 2
}
onWidthChanged:
{
var amount = parseInt(grid.width/(picSize + picSpacing),10)
var leftSpace = parseInt(grid.width-(amount*(picSize + picSpacing)), 10)
var size = parseInt((picSize + picSpacing)+(parseInt(leftSpace/amount, 10)), 10)
size = size > picSize + picSpacing ? size : picSize + picSpacing
grid.cellWidth = size
// grid.cellHeight = size
}
delegate: PixPic
{
id: delegate
picSize : gridPage.picSize
Connections
{
target: delegate
onPicClicked:
{
var url = grid.model.get(index).url
gridPage.picClicked(url)
grid.currentIndex = index
}
}
}
ScrollBar.vertical: ScrollBar{ visible: !pix.isMobile()}
}
} }
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
Item
{
property string emoji
property string message
clip: true
anchors.fill: parent