Files
IfcOpenShell/src/qtviewer/MainWindow.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
3.7 KiB
C++
Raw Normal View History

#include <QCoreApplication>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QFileDialog>
#include <QFileInfo>
#include <QFile>
#include <QMessageBox>
2023-08-29 09:48:27 +05:30
#include <QSplitter>
#include <sstream>
#include "MainWindow.h"
#include "MessageLogger.h"
#include "IfcViewerWidget.h"
MainWindow::MainWindow(qreal dpiScale, QWidget *parent)
: QMainWindow(parent), m_dpiScale(dpiScale)
2012-06-22 12:28:34 +00:00
{
this->setWindowTitle("IfcOpenShell Viewer");
this->resize(800, 600); //temporary reasonable initial size
2012-06-22 12:28:34 +00:00
m_glWidget = new IfcViewerWidget(m_dpiScale, this);
2023-08-29 09:48:27 +05:30
QSizePolicy glSizePolicy = m_glWidget->sizePolicy();
glSizePolicy.setVerticalStretch(3);
m_glWidget->setSizePolicy(glSizePolicy);
m_outputText = new QPlainTextEdit(this);
m_outputText->setReadOnly(true);
QSplitter* splitter = new QSplitter(Qt::Vertical, this);
splitter->addWidget(m_glWidget);
splitter->addWidget(m_outputText);
setCentralWidget(splitter);
2012-06-22 12:28:34 +00:00
createActions();
createMenus();
createConnections();
}
2012-06-22 12:28:34 +00:00
void MainWindow::createActions()
{
openAction = new QAction(tr("&Open"), this);
2012-06-22 12:28:34 +00:00
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
quitAction = new QAction(tr("E&xit"), this);
quitAction->setShortcut(QKeySequence::Quit);
2012-06-22 12:28:34 +00:00
m_backgroundAction = new QAction(tr("&Background"));
2012-06-22 12:28:34 +00:00
m_backgroundAction->setEnabled(false);
m_backgroundAction->setCheckable(true);
m_backgroundAction->setChecked(false);
m_outlineAction = new QAction(tr("&Outline"));
2012-06-22 12:28:34 +00:00
m_outlineAction->setEnabled(false);
m_outlineAction->setCheckable(true);
m_outlineAction->setChecked(false);
}
2012-06-22 12:28:34 +00:00
void MainWindow::createMenus()
{
QMenuBar *menuBar = new QMenuBar();
setMenuBar(menuBar);
2012-06-22 12:28:34 +00:00
fileMenu = new QMenu(tr("&File"), menuBar);
menuBar->addMenu(fileMenu);
2012-06-22 12:28:34 +00:00
fileMenu->addAction(openAction);
fileMenu->addAction(quitAction);
viewMenu = new QMenu(tr("&View"), menuBar);
menuBar->addMenu(viewMenu);
viewMenu->addAction(m_backgroundAction);
viewMenu->addAction(m_outlineAction);
2012-06-22 12:28:34 +00:00
}
void MainWindow::createConnections()
2012-06-22 12:28:34 +00:00
{
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
//connect(m_backgroundAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewBackground(bool)));
//connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool)));
2023-08-29 09:48:27 +05:30
//connect(&m_parser, &ParseIfcFile::parsingInfo, this, &MainWindow::appendToOutputText);
connect(&MessageLogger::getInstance(), SIGNAL(logMessage(QString)), this, SLOT(appendToOutputText(QString)));
connect(this, SIGNAL(loadFileInViewerWidget(const std::string&)), m_glWidget, SLOT(loadFile(const std::string&)));
2023-08-29 09:48:27 +05:30
}
void MainWindow::appendToOutputText(const QString& message)
{
m_outputText->appendPlainText(message);
2012-06-22 12:28:34 +00:00
}
void MainWindow::openFile()
2012-06-22 12:28:34 +00:00
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Open IFC File"),
".", tr("IFC Files (*.ifc)"));
2012-06-22 12:28:34 +00:00
QFileInfo fileInfo(filePath);
QString fileName = fileInfo.fileName();
2012-06-22 12:28:34 +00:00
if (fileName.isEmpty())
return;
2012-06-22 12:28:34 +00:00
// Check if the file is a Qt resource file
if (fileName.startsWith(":/"))
return;
QFile file(filePath);
if (!file.exists()) {
QMessageBox::critical(this, tr("Open IFC"),
QString("Could not open '%1'.").arg(filePath));
m_outlineAction->setEnabled(false);
m_backgroundAction->setEnabled(false);
return;
}
2023-08-29 09:48:27 +05:30
QString message = tr("Opening file: %1\n").arg(filePath);
appendToOutputText(message);
setWindowTitle(tr("%1 - IFCViewer").arg(fileName));
2012-06-22 12:28:34 +00:00
m_outlineAction->setEnabled(true);
m_backgroundAction->setEnabled(true);
emit loadFileInViewerWidget(filePath.toStdString());
}