From 30fad70d72ded1bc5573bed5a4df17647558fb13 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Mon, 17 Sep 2018 19:44:16 +0200 Subject: [PATCH] Imported existing sources --- images/sketch.png | Bin 0 -> 3139 bytes sketchmainwindow.cpp | 83 ++++++++++++++++++++++++++++++++ sketchmainwindow.h | 24 +++++++++ sketchmainwindow.ui | 73 ++++++++++++++++++++++++++++ sketchplugin.cpp | 44 +++++++++++++++++ sketchplugin.h | 27 +++++++++++ sketchplugin.json | 0 sketchplugin.pro | 22 +++++++++ sketchplugin_resources.qrc | 5 ++ translations/sketchplugin_de.ts | 4 ++ translations/sketchplugin_en.ts | 4 ++ 11 files changed, 286 insertions(+) create mode 100644 images/sketch.png create mode 100644 sketchmainwindow.cpp create mode 100644 sketchmainwindow.h create mode 100644 sketchmainwindow.ui create mode 100644 sketchplugin.cpp create mode 100644 sketchplugin.h create mode 100644 sketchplugin.json create mode 100644 sketchplugin.pro create mode 100644 sketchplugin_resources.qrc create mode 100644 translations/sketchplugin_de.ts create mode 100644 translations/sketchplugin_en.ts diff --git a/images/sketch.png b/images/sketch.png new file mode 100644 index 0000000000000000000000000000000000000000..05310ffe63965d93c364c66d3b4a626b0986d124 GIT binary patch literal 3139 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4mJh`hElEaktaqI1@+zCsr zh90kferNga=X;kw@7<6PvuVvE?#KzNa>5P=F?~{E<;<7#+MLtl=`eYU-jOMe+&bYt z8uZ*20_MBVFiEG~oq2ceyO-~t@BIGbp`GpN zGv{~?`+aBWwhTV+6Yl$c@AH4}cRv4f{=Zqyjka76`Zeq4uiws}C$t`G{9(c$`Qd8+ ze~p@nWqi}F#v2?mnIwDskLQVH2mPJRnCqlYr%lLV`{P})K47OElhI$(7$E`kHr3`1 zX_oNDC11BU?WohyY+gNKirL9*riPs-_ZzINm*);vNo3o~!znkJP0Z*BlUr9pM+J|g z6XSax$vvEJ_p&hlc~hS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q}s?Kf6_5}y-PeQtr=1l7*@lddxF&A;#ce`)!?Marv_^q!u!*ZF(>k62{d za#zN*1#Vvh+CoKx#lF0L+fx_3A#!PzMzW`6RLhy_U+exUJk_?}v??~jv{ZV>%Y(YV zp1oGk*}J33($DT~V4>{G_9G6e=K>A3`>alQ(Rw{--`C5l`3{CME4<l)|upHM3FTPc?p%Cgv2=4R2-h!wt7IxmO&Z=M1% z&nB+^X0YRNZMx0rSyDeXO3Mk9{gIN}?_j0P^7KfsBA4K{ZD;rk*BoLxm!DE`D7xHT z{@Nnrbzgh>-qb~WIrRGDwN+evF$bQDG72ua8g_d1>3mMq5 zr&zz0OnLCP|Kiq{i?*3c=Y|?qZ;w;F`V?e2-b_fKx(-2I)#{WAi24s|ZK^$;>`4Q*+7V6pLj zu)#u+SxXkZSi1k^=LYqtCYJbhA?aUDsPYGuRFVF8mg>CvCFml48dI!7P2r zL@x)XuOeKx>!)6f{=Y`qw(NMzpNX;k9v>&YKH(ISb(xtlUx@XJ=(&0W4}KOOnVFJH zyX$8@jO{P;NqhOi*X{q>`3noa9c7t5@vOzA#fFP#pJ?*vSf9Ky+s|^-OcrmWN#;3= z^Zyvjibhy-Ib>FB{&MHv^Z==5oyBIFE5cc#D<;oQuj4#*CsDzdb7^2z-hb^~ZRaNc z-_F4BCGVc1b9voF%eP9_lO~Q~~=Y*_qY-OlcRZ+BmRJ1_Mv1A|1}Z{|mOmFid1gKC~VJGs$ccJuj^9rJfjeOPX@ zVcv9~*Hw#6^Y#Cp)Q`A-VE?6BzdvR#?{K?)J;LW^|0)0VyZ(O~3>y2te-1h9nlf|3 z%mCi}Wq*evI89QU{S Yy_TsBaxp343=9kmp00i_>zopr0M)1Ivj6}9 literal 0 HcmV?d00001 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 @@ + + + +