--- a/src/mainwindow.cpp Mon Sep 23 14:06:36 2019 +0300 +++ b/src/mainwindow.cpp Thu Oct 03 11:45:44 2019 +0300 @@ -1,20 +1,107 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "version.h" -#include <QQuaternion> +#include <QLabel> +#include <QVBoxLayout> MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}, - ui{std::make_unique<Ui_MainWindow>()} + ui{std::make_unique<Ui_MainWindow>()}, + documents{this} { ui->setupUi(this); + connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel); connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); + updateTitle(); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::newModel() +{ + documents.newModel(); + this->updateTabs(); +} + +#include <QFileDialog> +#include <QMessageBox> +void MainWindow::openModel() +{ + const QString path = QFileDialog::getOpenFileName( + this, "Open model", "", "LDraw models (*.ldr *.dat)"); + if (not path.isEmpty()) + { + QFile file{path}; + const bool open_result = file.open(QIODevice::ReadOnly); + if (open_result) + { + + } + else + { + QMessageBox::critical(this, "Problem opening file", + QString{"Could not open %1: %2"} + .arg(path) + .arg(file.errorString())); + } + } +} + +/** + * @brief Creates a new tab widget for the specified model. + * @param model Model to get a new tab widget for + * @return widget + */ +QWidget* MainWindow::createWidgetForModel(Model* model) +{ + Q_UNUSED(model); + QWidget* widget = new QWidget(ui->tabs); + QLabel* label = new QLabel("asdf", widget); + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(label); + widget->setLayout(layout); + return widget; +} + +/** + * @brief Gets a tab widget for the specified model. If it does not exist, + * it will be created. + * @param model Model to get a tab widget for + * @return widget + */ +QWidget* MainWindow::getWidgetForModel(Model* model) +{ + QWidget* widget = this->modelWidgets.value(model); + if (widget == nullptr) + { + QWidget* const new_widget = createWidgetForModel(model); + this->modelWidgets[model] = new_widget; + return new_widget; + } + else + { + return widget; + } +} + +/** + * @brief Updates the tab widget + */ +void MainWindow::updateTabs() +{ + +} + +/** + * @brief Updates the title of the main window so to contain the app's name + * and version as well as the open document name. + */ +void MainWindow::updateTitle() +{ QString title = ::appName; title += " "; title += fullVersionString(); setWindowTitle(title); } - -MainWindow::~MainWindow() -{ -}