@@ -489,6 +489,7 @@ add_files(
|
||||
utility/messaging/type/graph/MessageGraphNodeHide.h
|
||||
utility/messaging/type/graph/MessageGraphNodeMove.h
|
||||
utility/messaging/type/graph/MessageScrollGraph.h
|
||||
utility/messaging/type/graph/MessageSaveAsImage.h
|
||||
|
||||
utility/messaging/type/history/MessageHistoryToPosition.h
|
||||
utility/messaging/type/history/MessageHistoryRedo.h
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGE_SAVE_AS_IMAGE_H
|
||||
#define MESSAGE_SAVE_AS_IMAGE_H
|
||||
|
||||
#include "Message.h"
|
||||
|
||||
|
||||
class MessageSaveAsImage: public Message<MessageSaveAsImage>
|
||||
{
|
||||
public:
|
||||
MessageSaveAsImage(QString path) : path(path) {}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageSaveAsImage";
|
||||
}
|
||||
|
||||
QString path;
|
||||
};
|
||||
|
||||
#endif /* MESSAGE_SAVE_AS_IMAGE_H */
|
||||
@@ -166,6 +166,8 @@ QtGraphicsView::QtGraphicsView(GraphFocusHandler* focusHandler, QWidget* parent)
|
||||
m_legendButton->setObjectName(QStringLiteral("legend_button"));
|
||||
m_legendButton->setToolTip(QStringLiteral("show legend"));
|
||||
connect(m_legendButton, &QPushButton::clicked, this, &QtGraphicsView::legendClicked);
|
||||
|
||||
m_tabId = TabId::currentTab();
|
||||
}
|
||||
|
||||
float QtGraphicsView::getZoomFactor() const
|
||||
@@ -183,6 +185,8 @@ void QtGraphicsView::setSceneRect(const QRectF& rect)
|
||||
{
|
||||
QGraphicsView::setSceneRect(rect);
|
||||
scene()->setSceneRect(rect);
|
||||
m_imageCached = toQImage();
|
||||
m_tabId = TabId::currentTab();
|
||||
}
|
||||
|
||||
QtGraphNode* QtGraphicsView::getNodeAtCursorPosition() const
|
||||
@@ -724,7 +728,6 @@ void QtGraphicsView::exportGraph()
|
||||
QStringLiteral("PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp);;SVG (*.svg)"))
|
||||
.toStdWString());
|
||||
|
||||
|
||||
if (filePath.extension() == L".svg")
|
||||
{
|
||||
QSvgGenerator svgGen;
|
||||
@@ -852,3 +855,11 @@ void QtGraphicsView::updateTransform()
|
||||
float zoomFactor = m_appZoomFactor * m_zoomFactor;
|
||||
setTransform(QTransform(zoomFactor, 0, 0, zoomFactor, 0, 0));
|
||||
}
|
||||
|
||||
void QtGraphicsView::handleMessage(MessageSaveAsImage* message)
|
||||
{
|
||||
if ( (message->getSchedulerId() == getSchedulerId()) && !m_imageCached.isNull() )
|
||||
{
|
||||
m_imageCached.save(message->path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "types.h"
|
||||
#include "MessageListener.h"
|
||||
#include "MessageSaveAsImage.h"
|
||||
|
||||
|
||||
class GraphFocusHandler;
|
||||
class QPushButton;
|
||||
@@ -14,7 +17,7 @@ class QtGraphEdge;
|
||||
class QtGraphNode;
|
||||
class QtSelfRefreshIconButton;
|
||||
|
||||
class QtGraphicsView: public QGraphicsView
|
||||
class QtGraphicsView: public QGraphicsView, public MessageListener<MessageSaveAsImage>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -33,6 +36,11 @@ public:
|
||||
|
||||
void updateZoom(float delta);
|
||||
|
||||
Id getSchedulerId() const override
|
||||
{
|
||||
return m_tabId;
|
||||
}
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
@@ -90,6 +98,8 @@ private:
|
||||
void setZoomFactor(float zoomFactor);
|
||||
void updateTransform();
|
||||
|
||||
void handleMessage(MessageSaveAsImage* message) override;
|
||||
|
||||
GraphFocusHandler* m_focusHandler;
|
||||
|
||||
QPoint m_last;
|
||||
@@ -141,6 +151,9 @@ private:
|
||||
|
||||
float m_zoomInButtonSpeed;
|
||||
float m_zoomOutButtonSpeed;
|
||||
|
||||
QImage m_imageCached;
|
||||
Id m_tabId;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPHICS_VIEW_H
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "MessageTabSelect.h"
|
||||
#include "MessageWindowClosed.h"
|
||||
#include "MessageZoom.h"
|
||||
#include "MessageSaveAsImage.h"
|
||||
#include "QtAbout.h"
|
||||
#include "QtContextMenu.h"
|
||||
#include "QtFileDialog.h"
|
||||
@@ -710,6 +711,19 @@ void QtMainWindow::forceRefresh()
|
||||
MessageRefresh().refreshAll().dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::saveAsImage()
|
||||
{
|
||||
QString filePath = QtFileDialog::showSaveFileDialog(this, tr("Save as Image"), FilePath(),
|
||||
"PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp)");
|
||||
if (filePath.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
MessageSaveAsImage m(filePath);
|
||||
m.setSchedulerId(TabId::currentTab());
|
||||
m.dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::undo()
|
||||
{
|
||||
MessageHistoryUndo().dispatch();
|
||||
@@ -924,6 +938,8 @@ void QtMainWindow::setupEditMenu()
|
||||
this,
|
||||
&QtMainWindow::openSettings,
|
||||
QKeySequence(Qt::CTRL + Qt::Key_Comma));
|
||||
|
||||
menu->addAction(tr("&Save as Image"), this, &QtMainWindow::saveAsImage, QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_S));
|
||||
}
|
||||
|
||||
void QtMainWindow::setupViewMenu()
|
||||
|
||||
@@ -150,6 +150,7 @@ public slots:
|
||||
void updateRecentProjectsMenu();
|
||||
|
||||
void toggleView(View* view, bool fromMenu);
|
||||
void saveAsImage();
|
||||
|
||||
private slots:
|
||||
void toggleShowDockWidgetTitleBars();
|
||||
|
||||
Reference in New Issue
Block a user