Skip to content

Commit

Permalink
start of QML port - only real feature so far: thumbnails (almost comp…
Browse files Browse the repository at this point in the history
…lete)
  • Loading branch information
luspi committed Feb 1, 2015
0 parents commit dff125a
Show file tree
Hide file tree
Showing 26 changed files with 2,071 additions and 0 deletions.
45 changes: 45 additions & 0 deletions CMake/FindMagick.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#-*-cmake-*-
#
# Test for GraphicsMagick libraries, unlike CMake's FindGraphicsMagick.cmake which
# tests for GraphicsMagick's binary utilities
#
# Once loaded this will define
# MAGICK++_FOUND - system has GraphicsMagick
# MAGICK++_INCLUDE_DIR - include directory for GraphicsMagick
# MAGICK++_LIBRARY_DIR - library directory for GraphicsMagick
# MAGICK++_LIBRARIES - libraries you need to link to
#

SET(MAGICK++_FOUND "NO" )

FIND_PATH(MAGICK++_INCLUDE_DIR Magick++.h
"$ENV{MAGICK_LOCATION}/Magick++"
"$ENV{MAGICK_LOCATION}/include/Magick++"
"$ENV{MAGICK_LOCATION}/include/"
"$ENV{MAGICK_LOCATION}"
/usr/include/Magick++
/usr/include/GraphicsMagick
/usr/include/
/opt/local/include/GraphicsMagick/Magick++
/opt/local/include/GraphicsMagick
)

FIND_LIBRARY(Magick++ GraphicsMagick++ PATHS
"$ENV{MAGICK_LOCATION}/.libs"
"$ENV{MAGICK_LOCATION}/lib"
/opt/local/lib
DOC "GraphicsMagick Magick++ library"
)

SET(MAGICK++_LIBRARIES ${Magick++} )

IF(MAGICK++_INCLUDE_DIR)
IF(MAGICK++_LIBRARIES)
SET(MAGICK++_FOUND "YES")
MESSAGE(STATUS "GraphicsMagick found at: ${MAGICK++_INCLUDE_DIR}")
GET_FILENAME_COMPONENT(MAGICK++_LIBRARY_DIR ${Magick++} PATH)
ENDIF(MAGICK++_LIBRARIES)
ENDIF(MAGICK++_INCLUDE_DIR)

#####

84 changes: 84 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
##################################################
# CMakeLists for PhotoQt-QML: http://photoqt.org #
##################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(photoqt)

#### SOURCES ####
SET(photoqt_SOURCES cplusplus/main.cpp cplusplus/mainwindow.cpp cplusplus/variables.h)
SET(photoqt_SOURCES ${photoqt_SOURCES} cplusplus/handlefiles/loaddir.cpp)
SET(photoqt_SOURCES ${photoqt_SOURCES} cplusplus/imageprovider/imageproviderfull.cpp cplusplus/imageprovider/imageproviderthumbnail.cpp)
SET(photoqt_SOURCES ${photoqt_SOURCES} cplusplus/settings/settings.cpp)
SET(photoqt_SOURCES ${photoqt_SOURCES} qml/mainwindow.qml qml/slidein/ThumbnailBar.qml qml/mainview/Background.qml qml/mainview/Display.qml qml/mainview/QuickInfo.qml qml/slidein/MetaData.qml qml/Shortcuts.qml)

#### HEADER ####
SET(photoqt_HEADERS cplusplus/mainwindow.h cplusplus/variables.h)
SET(photoqt_HEADERS ${photoqt_HEADERS} cplusplus/handlefiles/loaddir.h)
SET(photoqt_HEADERS ${photoqt_HEADERS} cplusplus/imageprovider/imageproviderthumbnail.h cplusplus/imageprovider/imageproviderfull.h)
SET(photoqt_HEADERS ${photoqt_HEADERS} cplusplus/settings/settings.h)


#############################################
#### OPTIONS THAT CAN BE SET BY THE USER ####
#############################################

OPTION(EXIV2 "Use exiv2 library" ON)
OPTION(GM "Use graphicsmagick library" ON)
OPTION(QTONLY "ONLY USE QT-ONLY FEATURES" OFF)


################################
#### FIND REQUIRED PACKAGES ####
################################

FIND_PACKAGE(Qt5 COMPONENTS Quick Widgets Core Svg REQUIRED)
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
FIND_PACKAGE(Magick)

SET(CMAKE_BUILD_TYPE "Debug")


####################################
#### TRANSLATIONS AND RESOURCES ####
####################################

# Set resources
SET(photoqt_RESOURCES qrc.qrc img.qrc)
QT5_ADD_RESOURCES(RESOURCES ${photoqt_RESOURCES})


######################
#### FINISHING UP ####
######################

SET(CMAKE_BUILD_TYPE Debug)

# moc files
QT5_WRAP_CPP(photoqt_HEADERS_MOC ${photoqt_HEADERS})

# include, add defiunitions and include dirs
INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDES})
ADD_DEFINITIONS(${Qt5Widgets_DEFINITIONS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

# And add the executeable
add_executable(photoqt ${photoqt_SOURCES} ${photoqt_HEADERS_MOC} ${RESOURCES})
qt5_use_modules(photoqt Quick Widgets Sql Svg Core)


IF(GM)
IF(NOT ${MAGICK++_FOUND})
MESSAGE(FATAL_ERROR "** Unable to locate GraphicsMagick... is it installed?")
ELSEIF(${MAGICK++_FOUND})
INCLUDE_DIRECTORIES(${MAGICK++_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(photoqt "GraphicsMagick++")
ADD_DEFINITIONS(-DGM)
MESSAGE("** Graphicsmagick enabled")
ENDIF(NOT ${MAGICK++_FOUND})
ELSEIF(NOT GM)
MESSAGE("** Graphicsmagick DISABLED")
ENDIF(GM)



4 changes: 4 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
219 changes: 219 additions & 0 deletions cplusplus/handlefiles/loaddir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
#include "loaddir.h"

LoadDir::LoadDir() : QObject() {
settings = new QSettings(QDir::homePath() + "/.photoqt/settings",QSettings::IniFormat);
}


QFileInfoList LoadDir::loadDir(QByteArray filepath) {

currentfile = filepath;
counttot = 0;

QDir dir(QFileInfo(filepath).absolutePath());

// These are the images known by PhotoQt
QStringList flt = QStringList() << "*.jpg" << "*.png" << "*.jpeg";
dir.setNameFilters(flt);


// Store a QFileInfoList and a QStringList with the filenames
allImgsInfo = dir.entryInfoList(QDir::Files,QDir::IgnoreCase);

// When opening an unknown file (i.e., one that doesn't match any set format), then we need to manually add it to the list of loaded images
if(!allImgsInfo.contains(QFileInfo(currentfile))) allImgsInfo.append(QFileInfo(currentfile));

// Sort images...
bool asc = settings->value("Behaviour/SortImagesAscending").toBool();
QString sortby = settings->value("Behaviour/SortImagesBy").toString();
if(sortby == "name") {
qDebug() << "sortby: name";
std::sort(allImgsInfo.begin(),allImgsInfo.end(),(asc ? sort_name : sort_name_desc));
}
if(sortby == "naturalname") {
qDebug() << "sortby: natural name";
std::sort(allImgsInfo.begin(),allImgsInfo.end(),(asc ? sort_naturalname : sort_naturalname_desc));
}
if(sortby == "date") {
qDebug() << "sortby: date";
std::sort(allImgsInfo.begin(),allImgsInfo.end(),(asc ? sort_date : sort_date_desc));
}
if(sortby == "size") {
qDebug() << "sortby: size";
std::sort(allImgsInfo.begin(),allImgsInfo.end(),(asc ? sort_size : sort_size_desc));
}

// Storing number of images
counttot = allImgsInfo.length();

return allImgsInfo;

}


// FOR SORTING, WE HAVE ALL FUNCTIONS FOR DESCENDING AND ASCENDING CASE, AS THIS IS FASTER THAN REVERSING THE ORDER
// AFTERWARDS (PARTICULARLY FOR DIRECTORIES WITH A LARGE NUMBER OF FILES

bool LoadDir::sort_name(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s1fileinfo.fileName().compare(s2fileinfo.fileName(), Qt::CaseInsensitive) <= 0);
}
bool LoadDir::sort_name_desc(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s2fileinfo.fileName().compare(s1fileinfo.fileName(), Qt::CaseInsensitive) <= 0);
}
bool LoadDir::sort_date(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s1fileinfo.created().secsTo(s2fileinfo.created()) >= 0);
}
bool LoadDir::sort_date_desc(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s1fileinfo.created().secsTo(s2fileinfo.created()) < 0);
}
bool LoadDir::sort_size(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s1fileinfo.size() >= s2fileinfo.size());
}
bool LoadDir::sort_size_desc(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {
return(s1fileinfo.size() < s2fileinfo.size());
}

// Algorithm used for sorting a directory using natural sort
// Credits to: http://www.qtcentre.org/archive/index.php/t-21411.html
bool LoadDir::sort_naturalname(const QFileInfo& s1fileinfo,const QFileInfo& s2fileinfo) {

const QString s1 = s1fileinfo.fileName();
const QString s2 = s2fileinfo.fileName();

// ignore common prefix..
int i = 0;

while ((i < s1.length()) && (i < s2.length()) && (s1.at(i).toLower() == s2.at(i).toLower()))
++i;
++i;

// something left to compare?
if ((i < s1.length()) && (i < s2.length())) {

// get number prefix from position i - doesnt matter from which string
int k = i-1;

//If not number return native comparator
if(!s1.at(k).isNumber() || !s2.at(k).isNumber()) {

//Two next lines
//E.g. 1_... < 12_...
if(s1.at(k).isNumber())
return false;
if(s2.at(k).isNumber())
return true;
return QString::compare(s1, s2, Qt::CaseSensitive) < 0;
}

QString n = "";
k--;

while ((k >= 0) && (s1.at(k).isNumber())) {
n = s1.at(k)+n;
--k;
}

// get relevant/signficant number string for s1
k = i-1;
QString n1 = "";
while ((k < s1.length()) && (s1.at(k).isNumber())) {
n1 += s1.at(k);
++k;
}

// get relevant/signficant number string for s2
//Decrease by
k = i-1;
QString n2 = "";
while ((k < s2.length()) && (s2.at(k).isNumber())) {
n2 += s2.at(k);
++k;
}

// got two numbers to compare?
if (!n1.isEmpty() && !n2.isEmpty())
return (n+n1).toInt() < (n+n2).toInt();
else {
// not a number has to win over a number.. number could have ended earlier... same prefix..
if (!n1.isEmpty())
return false;
if (!n2.isEmpty())
return true;
return s1.at(i) < s2.at(i);
}
} else {
// shortest string wins
return s1.length() < s2.length();
}
}
bool LoadDir::sort_naturalname_desc(const QFileInfo& s1fileinfo,const QFileInfo& s2fileinfo) {

const QString s2 = s1fileinfo.fileName();
const QString s1 = s2fileinfo.fileName();

// ignore common prefix..
int i = 0;

while ((i < s1.length()) && (i < s2.length()) && (s1.at(i).toLower() == s2.at(i).toLower()))
++i;
++i;

// something left to compare?
if ((i < s1.length()) && (i < s2.length())) {

// get number prefix from position i - doesnt matter from which string
int k = i-1;

//If not number return native comparator
if(!s1.at(k).isNumber() || !s2.at(k).isNumber()) {

//Two next lines
//E.g. 1_... < 12_...
if(s1.at(k).isNumber())
return false;
if(s2.at(k).isNumber())
return true;
return QString::compare(s1, s2, Qt::CaseSensitive) < 0;
}

QString n = "";
k--;

while ((k >= 0) && (s1.at(k).isNumber())) {
n = s1.at(k)+n;
--k;
}

// get relevant/signficant number string for s1
k = i-1;
QString n1 = "";
while ((k < s1.length()) && (s1.at(k).isNumber())) {
n1 += s1.at(k);
++k;
}

// get relevant/signficant number string for s2
//Decrease by
k = i-1;
QString n2 = "";
while ((k < s2.length()) && (s2.at(k).isNumber())) {
n2 += s2.at(k);
++k;
}

// got two numbers to compare?
if (!n1.isEmpty() && !n2.isEmpty())
return (n+n1).toInt() < (n+n2).toInt();
else {
// not a number has to win over a number.. number could have ended earlier... same prefix..
if (!n1.isEmpty())
return false;
if (!n2.isEmpty())
return true;
return s1.at(i) < s2.at(i);
}
} else {
// shortest string wins
return s1.length() < s2.length();
}
}
Loading

0 comments on commit dff125a

Please sign in to comment.