-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimagefiles.cpp
112 lines (96 loc) · 3.66 KB
/
imagefiles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <QDirIterator>
#include <QSettings>
#include <QDebug>
#include <QDateTime>
#include <QStandardPaths>
#include "imagefiles.h"
imageFiles::imageFiles(QObject *parent) : QObject(parent)
{
imagePointer = 0;
qsrand(QDateTime::currentMSecsSinceEpoch());
// qsrand(5);
}
imageFiles::~imageFiles()
{
}
QString imageFiles::nextImage()
{
if( imagePointer == 0) {
int randNum = qrand();
// qDebug() << "Random number:" << randNum;
imagesShown.insert(0, randNum % imageCount);
} else {
imagePointer--;
if(imagePointer < 0)
imagePointer = 0;
}
QString imageURL = "image://myImageProvider/"+photoUrlList.at(
imagesShown.at(imagePointer));
// qDebug() << imageURL << imagesShown;
return imageURL;
}
QString imageFiles::previousImage()
{
imagePointer+=2; // NOT SURE WHY THIS NEEDS TO BE "PLUS 2" BUT IT WORKS
if(imagePointer >= imagesShown.size())
imagePointer = imagesShown.size()-1;
QString imageURL = "image://myImageProvider/"+photoUrlList.at(
imagesShown.at(imagePointer));
// qDebug() << imageURL;
return imageURL;
}
void imageFiles::ReadURLs()
{
photoUrlList.clear();
#ifdef Q_OS_LINUX
//// Lenovo
// photoUrlList.append("/home/ggalt/Pictures/2014-summer/DSC_3264.jpg");
// photoUrlList.append("/home/ggalt/Pictures/2014-summer/DSC_3325.jpg");
// photoUrlList.append("/home/ggalt/Pictures/2014-summer/P1000417.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2014-summer/P1000504.JPG");
readImageURLsFromDisk(QDir("/home/ggalt/Pictures/"));
//// Main
// photoUrlList.append("/home/ggalt/Pictures/2006-Summer/IMG_0430.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2006-Summer/IMG_0431.JPG");
// photoUrlList.append("'/home/ggalt/Pictures/2015/Hawaii and California/DSC_0611.JPG'");
// photoUrlList.append("/home/ggalt/Pictures/OldPhotos/DSC_0688.JPG");
// readImageURLsFromDisk(QDir("/home/ggalt/Pictures/"));
// photoUrlList.append("/home/ggalt/Pictures/2013_07_Hawaii/G0010093ww.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2013_07_Hawaii/G0010093.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2013_07_Hawaii/GOPR0116.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2013_07_Hawaii/GOPR0137.JPG");
// photoUrlList.append("/home/ggalt/Pictures/2013_07_Hawaii/GOPR0170.JPG");
#else
// Windows laptop
// photoUrlList.append("C:/Users/ggalt66/Pictures/Desktop Images/DSC_0682");
// photoUrlList.append("C:/Users/ggalt66/Pictures/Desktop Images/DSC_0759");
// photoUrlList.append("C:/Users/ggalt66/Pictures/Desktop Images/DSC_1656");
// photoUrlList.append("C:/Users/ggalt66/Pictures/Desktop Images/DSC_0738");
readImageURLsFromDisk(QDir("C:/Users/ggalt66/Pictures/"));
// Windows Desktop
// readImageURLsFromDisk(QDir("C:/Users/George Galt/Pictures"));
#endif
imageCount = photoUrlList.size();
}
void imageFiles::setupImageProvider(QQmlEngine *eng)
{
imageProvider = new MyImageProvider(QQmlImageProviderBase::Image);
eng->addImageProvider("myImageProvider", imageProvider);
}
void imageFiles::readImageURLsFromDisk(QDir d)
{
// qDebug() << "Image URL:" << d;
photoUrlList.clear();
QDirIterator it(d, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
if( it.fileInfo().isFile() ) {
QString entry = it.fileInfo().absoluteFilePath();
if( entry.contains(".JPG") || entry.contains(".jpg")) {
photoUrlList.append(entry);
}
}
}
imageCount = photoUrlList.count();
// qDebug() << imageCount << photoUrlList.at(0);
}