-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferSaver.cpp
60 lines (48 loc) · 1.48 KB
/
BufferSaver.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
#include "BufferSaver.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QImage>
#include <QFile>
#include <QDir>
#include <ctime>
static const QString months[] = {"Januray", "February", "March", "April", "May",
"June", "July", "August", "September",
"October", "Novermber", "December"};
BufferSaver::BufferSaver() : setting(NONE)
{
}
BufferSaver::~BufferSaver()
{
}
bool BufferSaver::saveScreenshot(const std::string &path, const std::string &name)
{
QClipboard * clipboard = QGuiApplication::clipboard();
QImage screen = clipboard->image();
QString fullPath = QString::fromStdString(path);
if (setting >= YEAR) {
std::time_t t = std::time(nullptr);
std::tm * curDate = std::localtime(&t);
int year = curDate->tm_year + 1900;
fullPath += QString::number(year) + "/";
if (setting >= MONTH) {
fullPath += months[curDate->tm_mon] + "/";
if (setting >= DAY) {
fullPath += QString::number(curDate->tm_mday) + "/";
}
}
}
QDir dir(fullPath);
dir.mkpath(fullPath);
QFile file(fullPath + QString::fromStdString(name) + ".png");
if (file.open(QIODevice::WriteOnly))
return screen.save(&file, "PNG");
return false;
}
BufferSaver::SubDirSettings BufferSaver::getSetting() const
{
return setting;
}
void BufferSaver::setSetting(const SubDirSettings &value)
{
setting = value;
}