mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08: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 <QFile>
|
||||
#include <QFileDialog>
|
||||
#include "connectiondiagram.h"
|
||||
#include "ui_connectiondiagram.h"
|
||||
|
||||
@ -62,8 +63,8 @@ void ConnectionDiagram::setupGraphicsScene()
|
||||
m_renderer->load(QString(":/setupwizard/resources/connection-diagrams.svg")) &&
|
||||
m_renderer->isValid())
|
||||
{
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
ui->connectionDiagram->setScene(scene);
|
||||
m_scene = new QGraphicsScene(this);
|
||||
ui->connectionDiagram->setScene(m_scene);
|
||||
//ui->connectionDiagram->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
|
||||
m_background = new QGraphicsSvgItem();
|
||||
@ -72,7 +73,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
||||
m_background->setOpacity(0);
|
||||
//m_background->setFlags(QGraphicsItem::ItemClipsToShape);
|
||||
m_background->setZValue(-1);
|
||||
scene->addItem(m_background);
|
||||
m_scene->addItem(m_background);
|
||||
|
||||
QList<QString> elementsToShow;
|
||||
|
||||
@ -139,7 +140,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
||||
break;
|
||||
}
|
||||
|
||||
setupGraphicsSceneItems(scene, elementsToShow);
|
||||
setupGraphicsSceneItems(elementsToShow);
|
||||
|
||||
ui->connectionDiagram->setSceneRect(m_background->boundingRect());
|
||||
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;
|
||||
QRectF backgBounds = m_renderer->boundsOnElement("background");
|
||||
@ -168,7 +169,7 @@ void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QList<QSt
|
||||
//QRectF orig = m_renderer->boundsOnElement(elementId);
|
||||
//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();
|
||||
}
|
||||
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;
|
||||
QGraphicsSvgItem* m_background;
|
||||
QGraphicsScene *m_scene;
|
||||
|
||||
void setupGraphicsScene();
|
||||
void setupGraphicsSceneItems(QGraphicsScene *scene, QList<QString> elementsToShow);
|
||||
void setupGraphicsSceneItems(QList<QString> elementsToShow);
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void showEvent(QShowEvent *event);
|
||||
|
||||
private slots:
|
||||
|
||||
void on_saveButton_clicked();
|
||||
};
|
||||
|
||||
#endif // CONNECTIONDIAGRAM_H
|
||||
|
@ -43,48 +43,68 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<sender>closeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ConnectionDiagram</receiver>
|
||||
<slot>accept()</slot>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
<x>752</x>
|
||||
<y>418</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</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>
|
||||
<x>399</x>
|
||||
<y>219</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
Loading…
Reference in New Issue
Block a user