Imported existing sources
This commit is contained in:
BIN
images/sketch.png
Normal file
BIN
images/sketch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
83
sketchmainwindow.cpp
Normal file
83
sketchmainwindow.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "sketchmainwindow.h"
|
||||||
|
#include "ui_sketchmainwindow.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
#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("<span style=\"color: red;\">Could not parse page: %0</span>").arg(msg), ui->tabWidget), pageRef->_ref());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene *scene;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scene = file.createScene(page);
|
||||||
|
} catch (QString msg) {
|
||||||
|
ui->tabWidget->addTab(new QLabel(QStringLiteral("<span style=\"color: red;\">Could not render page: %0</span>").arg(msg), ui->tabWidget), page->name());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->tabWidget->addTab(new QGraphicsView(scene, ui->tabWidget), page->name());
|
||||||
|
}
|
||||||
|
}
|
24
sketchmainwindow.h
Normal file
24
sketchmainwindow.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
73
sketchmainwindow.ui
Normal file
73
sketchmainwindow.ui
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SketchMainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="SketchMainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Sketch Viewer</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTabWidget" name="tabWidget"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile">
|
||||||
|
<property name="title">
|
||||||
|
<string>&File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionQuit"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionOpen">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Open</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionQuit">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Quit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>actionQuit</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>SketchMainWindow</receiver>
|
||||||
|
<slot>close()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>399</x>
|
||||||
|
<y>299</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
44
sketchplugin.cpp
Normal file
44
sketchplugin.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "sketchplugin.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
27
sketchplugin.h
Normal file
27
sketchplugin.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
};
|
0
sketchplugin.json
Normal file
0
sketchplugin.json
Normal file
22
sketchplugin.pro
Normal file
22
sketchplugin.pro
Normal file
@@ -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)
|
5
sketchplugin_resources.qrc
Normal file
5
sketchplugin_resources.qrc
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/zeiterfassung/plugins/sketchplugin">
|
||||||
|
<file>images/sketch.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
4
translations/sketchplugin_de.ts
Normal file
4
translations/sketchplugin_de.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="de_DE">
|
||||||
|
</TS>
|
4
translations/sketchplugin_en.ts
Normal file
4
translations/sketchplugin_en.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="en_US">
|
||||||
|
</TS>
|
Reference in New Issue
Block a user