diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-10 20:48:52 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-10 20:48:52 +0200 |
commit | 9f8bdd3c3ece772b0a19bfa5693bcd2646d20bb6 (patch) | |
tree | 52418942483bfd14c0aeca538cb96a40decefff7 | |
parent | d8d38cd1078a40e2660c4dd4ff91966ac3f031bb (diff) | |
download | nextpnr-9f8bdd3c3ece772b0a19bfa5693bcd2646d20bb6.tar.gz nextpnr-9f8bdd3c3ece772b0a19bfa5693bcd2646d20bb6.tar.bz2 nextpnr-9f8bdd3c3ece772b0a19bfa5693bcd2646d20bb6.zip |
nice way to get main window
-rw-r--r-- | gui/fpgaviewwidget.cc | 16 | ||||
-rw-r--r-- | gui/fpgaviewwidget.h | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index db4179e4..58df0586 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -1,13 +1,24 @@ #include "fpgaviewwidget.h" +#include <QApplication> #include <QCoreApplication> #include <QMouseEvent> +#include <QWidget> #include <math.h> #include "mainwindow.h" FPGAViewWidget::FPGAViewWidget(QWidget *parent) : QOpenGLWidget(parent), m_xMove(0), m_yMove(0), m_zDistance(1.0) { - design = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget()->parentWidget())->getDesign(); + design = qobject_cast<MainWindow *>(getMainWindow())->getDesign(); +} + +QMainWindow *FPGAViewWidget::getMainWindow() +{ + QWidgetList widgets = qApp->topLevelWidgets(); + for (QWidgetList::iterator i = widgets.begin(); i != widgets.end(); ++i) + if ((*i)->objectName() == "MainWindow") + return (QMainWindow *)(*i); + return NULL; } FPGAViewWidget::~FPGAViewWidget() {} @@ -64,11 +75,10 @@ void FPGAViewWidget::drawElement(const GraphicElement &el) glVertex3f((offset + scale * el.x2), (offset + scale * el.y2), 0.0f); glVertex3f((offset + scale * el.x1), (offset + scale * el.y2), 0.0f); - + glVertex3f((offset + scale * el.x1), (offset + scale * el.y2), 0.0f); glVertex3f((offset + scale * el.x1), (offset + scale * el.y1), 0.0f); glEnd(); - } if (el.type == GraphicElement::G_LINE) { diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 1eb98065..c54a745e 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -1,6 +1,7 @@ #ifndef MAPGLWIDGET_H #define MAPGLWIDGET_H +#include <QMainWindow> #include <QOpenGLFunctions> #include <QOpenGLWidget> #include <QPainter> @@ -33,6 +34,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; void drawElement(const GraphicElement &el); + QMainWindow *getMainWindow(); private: int m_windowWidth; |