Browse Source

Add auto saving.

tags/v5.0.0
ArsenArsen 5 years ago
parent
commit
24ee056485
  1. 2
      .gitignore
  2. 6
      KShare.pro
  3. 18
      formatter.cpp
  4. 12
      formatter.hpp
  5. 7
      main.cpp
  6. 18
      mainwindow.cpp
  7. 3
      mainwindow.hpp
  8. 39
      mainwindow.ui
  9. 10
      uploaders/uploadersingleton.cpp

2
.gitignore vendored

@ -45,4 +45,6 @@ KShare
*.Debug
vgcore.*
*.Release

6
KShare.pro

@ -34,7 +34,8 @@ SOURCES += main.cpp\
uploaders/default/imguruploader.cpp \
io/ioutils.cpp \
settings.cpp \
uploaders/default/clipboarduploader.cpp
uploaders/default/clipboarduploader.cpp \
formatter.cpp
HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \
@ -47,7 +48,8 @@ HEADERS += mainwindow.hpp \
uploaders/default/imguruploader.hpp \
io/ioutils.hpp \
settings.hpp \
uploaders/default/clipboarduploader.hpp
uploaders/default/clipboarduploader.hpp \
formatter.hpp
FORMS += mainwindow.ui

18
formatter.cpp

@ -0,0 +1,18 @@
#include "formatter.hpp"
#include <QDateTime>
#include <QStringList>
QString formatter::format(QString toFormat)
{
QRegExp dateRegex("%\\((.+)\\)date");
dateRegex.indexIn(toFormat);
QStringList capturedTexts(dateRegex.capturedTexts());
QString formatted(toFormat);
QDateTime date = QDateTime::currentDateTime();
for (int i = 0; i < capturedTexts.length(); i += 2)
{
formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
}
return formatted;
}

12
formatter.hpp

@ -0,0 +1,12 @@
#ifndef FORMATTER_HPP
#define FORMATTER_HPP
#include <QRegExp>
#include <QString>
namespace formatter
{
QString format(QString toFormat);
}
#endif // FORMATTER_HPP

7
main.cpp

@ -1,13 +1,12 @@
#include "mainwindow.hpp"
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <cropeditor/cropeditor.hpp>
#include <screenshotutil.hpp>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("KShare");
a.setOrganizationName("ArsenArsen");
a.setApplicationName("1.0");
MainWindow w;
w.show();
return a.exec();

18
mainwindow.cpp

@ -10,6 +10,7 @@
#include <QSystemTrayIcon>
#include <QTimer>
#include <QUrl>
#include <settings.hpp>
#include <uploaders/uploadersingleton.hpp>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
@ -41,10 +42,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
{
QListWidgetItem *item = new QListWidgetItem(u->name());
item->setToolTip(u->description());
// ui->uploaderList->setCurrentIndex(ui->uploaderList->model()->index(++i, 0))
ui->uploaderList->addItem(item);
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
}
// Set filename scheme
if ((settings::settings().contains("fileFormat")))
setScheme(settings::settings().value("fileFormat").toString());
else
setScheme("Screenshot %(yyyy-MM-dd HH:mm:ss)date");
}
MainWindow::~MainWindow()
@ -52,6 +58,11 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::setScheme(QString scheme)
{
ui->nameScheme->setText(scheme);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
@ -91,3 +102,8 @@ void MainWindow::on_uploaderList_clicked(const QModelIndex &)
UploaderSingleton::inst().set(index.at(0)->text());
}
}
void MainWindow::on_nameScheme_textEdited(const QString &arg1)
{
settings::settings().setValue("fileFormat", arg1);
}

3
mainwindow.hpp

@ -20,11 +20,14 @@ class MainWindow : public QMainWindow
void on_actionFullscreen_triggered();
void on_actionArea_triggered();
void on_uploaderList_clicked(const QModelIndex &);
void on_nameScheme_textEdited(const QString &arg1);
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void setScheme(QString scheme);
private:
Ui::MainWindow *ui;
QSystemTrayIcon *tray;

39
mainwindow.ui

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>262</width>
<height>239</height>
<width>256</width>
<height>286</height>
</rect>
</property>
<property name="windowTitle">
@ -29,7 +29,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>241</width>
<width>181</width>
<height>19</height>
</rect>
</property>
@ -42,18 +42,47 @@
<rect>
<x>0</x>
<y>20</y>
<width>256</width>
<width>251</width>
<height>192</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="nameScheme">
<property name="geometry">
<rect>
<x>0</x>
<y>230</y>
<width>251</width>
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>http://doc.qt.io/qt-5/qdatetime.html#toString</string>
</property>
<property name="text">
<string>Screenshot %(yyyy-MM-dd HH:mm:ss)date</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>0</x>
<y>210</y>
<width>141</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>File name scheme:</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>262</width>
<width>256</width>
<height>24</height>
</rect>
</property>

10
uploaders/uploadersingleton.cpp

@ -3,6 +3,7 @@
#include "default/imguruploader.hpp"
#include <QDir>
#include <QStandardPaths>
#include <formatter.hpp>
#include <settings.hpp>
UploaderSingleton::UploaderSingleton()
@ -40,6 +41,15 @@ void UploaderSingleton::registerUploader(Uploader *uploader)
void UploaderSingleton::upload(QPixmap *pixmap)
{
if (settings::settings().contains("fileFormat"))
{
QString format = settings::settings().value("fileFormat").toString();
if (!format.isEmpty())
{
pixmap->save(QDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).absoluteFilePath(formatter::format(format) + ".png"),
"PNG");
}
}
uploaders.value(uploader)->doUpload(pixmap);
}

Loading…
Cancel
Save