Skip to content

Commit

Permalink
qmlui: add support for 2D view background picture
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Nov 5, 2023
1 parent 5084c9f commit 6acd398
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 111 deletions.
10 changes: 10 additions & 0 deletions qmlui/contextmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ QString ContextManager::currentContext() const
return m_view->rootObject()->property("currentContext").toString();
}

MainView2D *ContextManager::get2DView()
{
return m_2DView;
}

MainView3D *ContextManager::get3DView()
{
return m_3DView;
}

QVector3D ContextManager::environmentSize() const
{
return m_monProps->gridSize();
Expand Down
3 changes: 3 additions & 0 deletions qmlui/contextmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class ContextManager : public QObject
/** Return the currently active context */
QString currentContext() const;

MainView2D *get2DView();
MainView3D *get3DView();

/** Get/Set the environment width/height/depth size */
QVector3D environmentSize() const;
void setEnvironmentSize(QVector3D environmentSize);
Expand Down
18 changes: 18 additions & 0 deletions qmlui/mainview2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,24 @@ void MainView2D::setPointOfView(int pointOfView)
slotRefreshView();
}

QString MainView2D::backgroundImage()
{
return m_monProps->commonBackgroundImage();
}

void MainView2D::setBackgroundImage(QString image)
{
QString strippedPath = image.replace("file://", "");
QString currentImage = m_monProps->commonBackgroundImage();

if (strippedPath == currentImage)
return;

Tardis::instance()->enqueueAction(Tardis::EnvironmentBackgroundImage, 0, QVariant(currentImage), QVariant(strippedPath));
m_monProps->setCommonBackgroundImage(strippedPath);
emit backgroundImageChanged();
}




Expand Down
6 changes: 6 additions & 0 deletions qmlui/mainview2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MainView2D : public PreviewContext
Q_PROPERTY(qreal gridScale READ gridScale WRITE setGridScale NOTIFY gridScaleChanged)
Q_PROPERTY(qreal cellPixels READ cellPixels WRITE setCellPixels NOTIFY cellPixelsChanged)
Q_PROPERTY(int pointOfView READ pointOfView WRITE setPointOfView NOTIFY pointOfViewChanged)
Q_PROPERTY(QString backgroundImage READ backgroundImage WRITE setBackgroundImage NOTIFY backgroundImageChanged)

public:
explicit MainView2D(QQuickView *view, Doc *doc, QObject *parent = 0);
Expand Down Expand Up @@ -114,6 +115,10 @@ class MainView2D : public PreviewContext
int pointOfView() const;
void setPointOfView(int pointOfView);

/** Get/Set the main background image */
QString backgroundImage();
void setBackgroundImage(QString image);

protected:
/** First time 2D view variables initializations */
bool initialize2DProperties();
Expand All @@ -128,6 +133,7 @@ class MainView2D : public PreviewContext
void gridScaleChanged(qreal gridScale);
void cellPixelsChanged(qreal cellPixels);
void pointOfViewChanged(int pointOfView);
void backgroundImageChanged();

public slots:
/** @reimp */
Expand Down
15 changes: 14 additions & 1 deletion qmlui/qml/fixturesfunctions/2DView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Rectangle
* The stacking order of this view is very important and delicate
* From bottom to top:
* Flickable (z = 1): main scrollable area
* Image (z = 0): Main background image
* Canvas (z = 0): The actual grid graphics view
* DropArea (z = 0): allow to drop items from fixture browser
* Rectangle (z = 1): multiple drag layer as big as the Canvas layer
Expand Down Expand Up @@ -142,6 +143,17 @@ Rectangle
twoDContents.requestPaint()
}

Image
{
x: twoDContents.xOffset
y: twoDContents.yOffset
width: twoDView.contentWidth - (x * 2)
height: twoDView.contentHeight - (y * 2)
source: View2D.backgroundImage ? "file://" + View2D.backgroundImage : ""
sourceSize: Qt.size(width, height)
fillMode: Image.PreserveAspectFit
}

Canvas
{
id: twoDContents
Expand Down Expand Up @@ -175,14 +187,15 @@ Rectangle
var context = getContext("2d")
context.globalAlpha = 1.0
context.strokeStyle = "#5F5F5F"
context.fillStyle = "black"
context.fillStyle = "transparent"
context.lineWidth = 1

context.beginPath()
context.clearRect(0, 0, width, height)
context.fillRect(0, 0, width, height)
context.rect(xOffset, yOffset, width - (xOffset * 2), height - (yOffset * 2))

// draw the view grid
for (var vl = 1; vl < twoDView.gridSize.width; vl++)
{
var xPos = (cellSize * vl) + xOffset
Expand Down
Loading

0 comments on commit 6acd398

Please sign in to comment.