-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <QDebug> | ||
#include <QPainter> | ||
|
||
#include "julia_display.hpp" | ||
namespace qmlwrap | ||
{ | ||
|
||
JuliaDisplay::JuliaDisplay(QQuickItem *parent) : QQuickPaintedItem(parent) | ||
{ | ||
} | ||
|
||
void JuliaDisplay::paint(QPainter *painter) | ||
{ | ||
painter->drawPixmap(0,0,m_pixmap); | ||
} | ||
|
||
void JuliaDisplay::load_png(cxx_wrap::ArrayRef<unsigned char> data) | ||
{ | ||
if(m_pixmap.isNull()) | ||
{ | ||
clear(); | ||
} | ||
if(!m_pixmap.loadFromData(data.data(), data.size(), "PNG")) | ||
{ | ||
qWarning() << "Failed to load PNG data"; | ||
clear(); | ||
} | ||
update(); | ||
} | ||
|
||
void JuliaDisplay::clear() | ||
{ | ||
m_pixmap = QPixmap(width(), height()); | ||
m_pixmap.fill(Qt::transparent); | ||
} | ||
|
||
void JuliaDisplay::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | ||
{ | ||
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); | ||
if(newGeometry != oldGeometry) | ||
{ | ||
clear(); | ||
} | ||
} | ||
|
||
} // namespace qmlwrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef QML_JULIA_DISPLAY_H | ||
#define QML_JULIA_DISPLAY_H | ||
|
||
#include <cxx_wrap.hpp> | ||
|
||
#include <QObject> | ||
#include <QPixmap> | ||
#include <QQuickPaintedItem> | ||
|
||
namespace qmlwrap | ||
{ | ||
|
||
/// Groups signals (defined using QML) that can be emitted from Julia | ||
class JuliaDisplay : public QQuickPaintedItem | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
JuliaDisplay(QQuickItem *parent = 0); | ||
|
||
void paint(QPainter *painter); | ||
|
||
void load_png(cxx_wrap::ArrayRef<unsigned char> data); | ||
|
||
void clear(); | ||
|
||
protected: | ||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | ||
|
||
private: | ||
QPixmap m_pixmap; | ||
}; | ||
|
||
} // namespace qmlwrap | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Base.Test | ||
using QML | ||
using TestImages | ||
|
||
function test_display(d::JuliaDisplay) | ||
img = testimage("lena_color_256") | ||
display(d, img) | ||
end | ||
|
||
@qmlfunction test_display | ||
|
||
qml_file = joinpath(Pkg.dir("QML"), "test", "qml", "image.qml") | ||
|
||
app = QML.application() | ||
qml_engine4 = QQmlApplicationEngine() | ||
|
||
# Load QML after setting context properties, to avoid errors | ||
load(qml_engine4, qml_file) | ||
|
||
# Run the application | ||
QML.exec() | ||
|
||
# Needed to prevent crash-on-exit | ||
finalize(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import QtQuick 2.0 | ||
import QtQuick.Controls 1.0 | ||
import QtQuick.Layouts 1.0 | ||
import org.julialang 1.0 | ||
|
||
ApplicationWindow { | ||
title: "My Application" | ||
width: 300 | ||
height: 300 | ||
visible: true | ||
|
||
ColumnLayout { | ||
spacing: 6 | ||
anchors.centerIn: parent | ||
|
||
Button { | ||
Layout.alignment: Qt.AlignCenter | ||
text: "Push Me" | ||
onClicked: Julia.test_display(jdisp) | ||
} | ||
|
||
JuliaDisplay { | ||
id: jdisp | ||
width: 256 | ||
height: 256 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters