mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-39 Added saving as image to the connection diagram dialog.
This commit is contained in:
parent
b889035a24
commit
37abf82fc2
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QFileDialog>
|
||||||
#include "connectiondiagram.h"
|
#include "connectiondiagram.h"
|
||||||
#include "ui_connectiondiagram.h"
|
#include "ui_connectiondiagram.h"
|
||||||
|
|
||||||
@ -62,8 +63,8 @@ void ConnectionDiagram::setupGraphicsScene()
|
|||||||
m_renderer->load(QString(":/setupwizard/resources/connection-diagrams.svg")) &&
|
m_renderer->load(QString(":/setupwizard/resources/connection-diagrams.svg")) &&
|
||||||
m_renderer->isValid())
|
m_renderer->isValid())
|
||||||
{
|
{
|
||||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
m_scene = new QGraphicsScene(this);
|
||||||
ui->connectionDiagram->setScene(scene);
|
ui->connectionDiagram->setScene(m_scene);
|
||||||
//ui->connectionDiagram->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
//ui->connectionDiagram->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||||
|
|
||||||
m_background = new QGraphicsSvgItem();
|
m_background = new QGraphicsSvgItem();
|
||||||
@ -72,7 +73,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
|||||||
m_background->setOpacity(0);
|
m_background->setOpacity(0);
|
||||||
//m_background->setFlags(QGraphicsItem::ItemClipsToShape);
|
//m_background->setFlags(QGraphicsItem::ItemClipsToShape);
|
||||||
m_background->setZValue(-1);
|
m_background->setZValue(-1);
|
||||||
scene->addItem(m_background);
|
m_scene->addItem(m_background);
|
||||||
|
|
||||||
QList<QString> elementsToShow;
|
QList<QString> elementsToShow;
|
||||||
|
|
||||||
@ -139,7 +140,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupGraphicsSceneItems(scene, elementsToShow);
|
setupGraphicsSceneItems(elementsToShow);
|
||||||
|
|
||||||
ui->connectionDiagram->setSceneRect(m_background->boundingRect());
|
ui->connectionDiagram->setSceneRect(m_background->boundingRect());
|
||||||
ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio);
|
ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio);
|
||||||
@ -148,7 +149,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QList<QString> elementsToShow)
|
void ConnectionDiagram::setupGraphicsSceneItems(QList<QString> elementsToShow)
|
||||||
{
|
{
|
||||||
qreal z = 0;
|
qreal z = 0;
|
||||||
QRectF backgBounds = m_renderer->boundsOnElement("background");
|
QRectF backgBounds = m_renderer->boundsOnElement("background");
|
||||||
@ -168,7 +169,7 @@ void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QList<QSt
|
|||||||
//QRectF orig = m_renderer->boundsOnElement(elementId);
|
//QRectF orig = m_renderer->boundsOnElement(elementId);
|
||||||
//element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y());
|
//element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y());
|
||||||
|
|
||||||
scene->addItem(element);
|
m_scene->addItem(element);
|
||||||
qDebug() << "Adding " << elementId << " to scene at " << element->pos();
|
qDebug() << "Adding " << elementId << " to scene at " << element->pos();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -177,4 +178,14 @@ void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QList<QSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionDiagram::on_saveButton_clicked()
|
||||||
|
{
|
||||||
|
QImage image(2200, 1100, QImage::Format_ARGB32);
|
||||||
|
image.fill(0);
|
||||||
|
QPainter painter(&image);
|
||||||
|
m_scene->render(&painter);
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Images (*.png *.xpm *.jpg)"));
|
||||||
|
if(!fileName.isEmpty()) {
|
||||||
|
image.save(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -54,13 +54,17 @@ private:
|
|||||||
|
|
||||||
QSvgRenderer *m_renderer;
|
QSvgRenderer *m_renderer;
|
||||||
QGraphicsSvgItem* m_background;
|
QGraphicsSvgItem* m_background;
|
||||||
|
QGraphicsScene *m_scene;
|
||||||
|
|
||||||
void setupGraphicsScene();
|
void setupGraphicsScene();
|
||||||
void setupGraphicsSceneItems(QGraphicsScene *scene, QList<QString> elementsToShow);
|
void setupGraphicsSceneItems(QList<QString> elementsToShow);
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void on_saveButton_clicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONNECTIONDIAGRAM_H
|
#endif // CONNECTIONDIAGRAM_H
|
||||||
|
@ -43,48 +43,68 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="orientation">
|
<item>
|
||||||
<enum>Qt::Horizontal</enum>
|
<spacer name="horizontalSpacer">
|
||||||
</property>
|
<property name="orientation">
|
||||||
<property name="standardButtons">
|
<enum>Qt::Horizontal</enum>
|
||||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
</property>
|
||||||
</property>
|
<property name="sizeHint" stdset="0">
|
||||||
</widget>
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="saveButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="closeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
<property name="default">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>closeButton</sender>
|
||||||
<signal>accepted()</signal>
|
<signal>clicked()</signal>
|
||||||
<receiver>ConnectionDiagram</receiver>
|
<receiver>ConnectionDiagram</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>close()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>248</x>
|
<x>752</x>
|
||||||
<y>254</y>
|
<y>418</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>157</x>
|
<x>399</x>
|
||||||
<y>274</y>
|
<y>219</y>
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>rejected()</signal>
|
|
||||||
<receiver>ConnectionDiagram</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>316</x>
|
|
||||||
<y>260</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>286</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
Loading…
Reference in New Issue
Block a user