diff --git a/images/sketch.png b/images/sketch.png new file mode 100644 index 0000000..05310ff Binary files /dev/null and b/images/sketch.png differ diff --git a/sketchmainwindow.cpp b/sketchmainwindow.cpp new file mode 100644 index 0000000..04d057b --- /dev/null +++ b/sketchmainwindow.cpp @@ -0,0 +1,83 @@ +#include "sketchmainwindow.h" +#include "ui_sketchmainwindow.h" + +#include +#include +#include +#include +#include + +#include "sketchfile.h" +#include "container/document.h" +#include "container/page.h" +#include "container/msjsonfilereference.h" + +SketchMainWindow::SketchMainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::SketchMainWindow) +{ + ui->setupUi(this); + + ui->actionOpen->setShortcut(QKeySequence::Open); + ui->actionQuit->setShortcut(QKeySequence::Quit); + + connect(ui->actionOpen, &QAction::triggered, this, &SketchMainWindow::openPressed); +} + +SketchMainWindow::~SketchMainWindow() +{ + delete ui; +} + +void SketchMainWindow::openPressed() +{ + auto filename = QFileDialog::getOpenFileName(this, tr("Select a sketch file"), QString(), QStringLiteral("%0 (*.sketch)").arg(tr("Sketch file"))); + if(filename.isEmpty()) + return; + + load(filename); +} + +void SketchMainWindow::load(const QString &filename) +{ + while(ui->tabWidget->count()) + { + auto widget = ui->tabWidget->widget(0); + ui->tabWidget->removeTab(0); + widget->deleteLater(); + } + + SketchFile file; + try + { + file.open(filename); + } + catch(const QString &msg) + { + QMessageBox::warning(this, tr("Could not load sketch file!"), tr("Could not load sketch file!") % "\n\n" % msg); + return; + } + + for(auto pageRef : file.document()->pages()) + { + Page *page; + try + { + page = file.loadPage(pageRef->_ref()); + } catch (QString msg) { + ui->tabWidget->addTab(new QLabel(QStringLiteral("Could not parse page: %0").arg(msg), ui->tabWidget), pageRef->_ref()); + continue; + } + + QGraphicsScene *scene; + try + { + scene = file.createScene(page); + } catch (QString msg) { + ui->tabWidget->addTab(new QLabel(QStringLiteral("Could not render page: %0").arg(msg), ui->tabWidget), page->name()); + continue; + } + + ui->tabWidget->addTab(new QGraphicsView(scene, ui->tabWidget), page->name()); + } +} diff --git a/sketchmainwindow.h b/sketchmainwindow.h new file mode 100644 index 0000000..d4ec823 --- /dev/null +++ b/sketchmainwindow.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace Ui { +class SketchMainWindow; +} + +class SketchMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit SketchMainWindow(QWidget *parent = 0); + ~SketchMainWindow(); + +private Q_SLOTS: + void openPressed(); + +private: + void load(const QString &filename); + + Ui::SketchMainWindow *ui; +}; diff --git a/sketchmainwindow.ui b/sketchmainwindow.ui new file mode 100644 index 0000000..0fe15fa --- /dev/null +++ b/sketchmainwindow.ui @@ -0,0 +1,73 @@ + + + SketchMainWindow + + + + 0 + 0 + 800 + 600 + + + + Sketch Viewer + + + + + + + + + + + + 0 + 0 + 800 + 20 + + + + + &File + + + + + + + + + + + &Open + + + + + &Quit + + + + + + + actionQuit + triggered() + SketchMainWindow + close() + + + -1 + -1 + + + 399 + 299 + + + + + diff --git a/sketchplugin.cpp b/sketchplugin.cpp new file mode 100644 index 0000000..0d65840 --- /dev/null +++ b/sketchplugin.cpp @@ -0,0 +1,44 @@ +#include "sketchplugin.h" + +#include +#include +#include +#include +#include +#include + +#include "mainwindow.h" +#include "sketchmainwindow.h" + +SketchPlugin::SketchPlugin(QObject *parent) : + ZeiterfassungPlugin(parent) +{ + qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("sketchplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation sketchplugin"; + } + } + else + { + qWarning() << "could not load translation sketchplugin"; + } +} + +void SketchPlugin::attachTo(MainWindow &mainWindow) +{ + mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/sketchplugin/images/sketch.png")), tr("Open Sketch viewer"), + this, &SketchPlugin::openWindow); +} + +void SketchPlugin::openWindow() +{ + auto window = new SketchMainWindow; + window->setAttribute(Qt::WA_DeleteOnClose); + window->show(); +} diff --git a/sketchplugin.h b/sketchplugin.h new file mode 100644 index 0000000..4285c74 --- /dev/null +++ b/sketchplugin.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#include "zeiterfassungplugin.h" + +class MainWindow; + +class Q_DECL_EXPORT SketchPlugin : public ZeiterfassungPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "dbsoftware.zeiterfassung.plugin/1.0" FILE "sketchplugin.json") + Q_INTERFACES(ZeiterfassungPlugin) + +public: + explicit SketchPlugin(QObject *parent = Q_NULLPTR); + + // ZeiterfassungPlugin interface + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private Q_SLOTS: + void openWindow(); + +private: + QTranslator m_translator; +}; diff --git a/sketchplugin.json b/sketchplugin.json new file mode 100644 index 0000000..e69de29 diff --git a/sketchplugin.pro b/sketchplugin.pro new file mode 100644 index 0000000..bc6f14f --- /dev/null +++ b/sketchplugin.pro @@ -0,0 +1,22 @@ +QT += core network gui widgets + +DBLIBS += zeiterfassungcore zeiterfassunggui sketchlib + +TARGET = sketchplugin + +HEADERS += sketchmainwindow.h \ + sketchplugin.h + +SOURCES += sketchmainwindow.cpp \ + sketchplugin.cpp + +FORMS += sketchmainwindow.ui + +RESOURCES += sketchplugin_resources.qrc + +TRANSLATIONS += translations/sketchplugin_en.ts \ + translations/sketchplugin_de.ts + +OTHER_FILES += sketchplugin.json + +include(../plugin.pri) diff --git a/sketchplugin_resources.qrc b/sketchplugin_resources.qrc new file mode 100644 index 0000000..01ae86b --- /dev/null +++ b/sketchplugin_resources.qrc @@ -0,0 +1,5 @@ + + + images/sketch.png + + diff --git a/translations/sketchplugin_de.ts b/translations/sketchplugin_de.ts new file mode 100644 index 0000000..1552582 --- /dev/null +++ b/translations/sketchplugin_de.ts @@ -0,0 +1,4 @@ + + + + diff --git a/translations/sketchplugin_en.ts b/translations/sketchplugin_en.ts new file mode 100644 index 0000000..bc6d6e7 --- /dev/null +++ b/translations/sketchplugin_en.ts @@ -0,0 +1,4 @@ + + + +