nice way to get main window
This commit is contained in:
parent
d8d38cd107
commit
9f8bdd3c3e
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user