src/mainwindow.cpp

changeset 5
593a658cba8e
parent 3
55a55a9ec2c2
child 6
73e448b2943d
equal deleted inserted replaced
4:68988ebc2a68 5:593a658cba8e
1 #include "mainwindow.h" 1 #include "mainwindow.h"
2 #include "ui_mainwindow.h" 2 #include "ui_mainwindow.h"
3 #include "version.h" 3 #include "version.h"
4 #include <QQuaternion> 4 #include <QLabel>
5 #include <QVBoxLayout>
5 6
6 MainWindow::MainWindow(QWidget *parent) : 7 MainWindow::MainWindow(QWidget *parent) :
7 QMainWindow{parent}, 8 QMainWindow{parent},
8 ui{std::make_unique<Ui_MainWindow>()} 9 ui{std::make_unique<Ui_MainWindow>()},
10 documents{this}
9 { 11 {
10 ui->setupUi(this); 12 ui->setupUi(this);
13 connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel);
11 connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); 14 connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close);
15 updateTitle();
16 }
17
18 MainWindow::~MainWindow()
19 {
20 }
21
22 void MainWindow::newModel()
23 {
24 documents.newModel();
25 this->updateTabs();
26 }
27
28 #include <QFileDialog>
29 #include <QMessageBox>
30 void MainWindow::openModel()
31 {
32 const QString path = QFileDialog::getOpenFileName(
33 this, "Open model", "", "LDraw models (*.ldr *.dat)");
34 if (not path.isEmpty())
35 {
36 QFile file{path};
37 const bool open_result = file.open(QIODevice::ReadOnly);
38 if (open_result)
39 {
40
41 }
42 else
43 {
44 QMessageBox::critical(this, "Problem opening file",
45 QString{"Could not open %1: %2"}
46 .arg(path)
47 .arg(file.errorString()));
48 }
49 }
50 }
51
52 /**
53 * @brief Creates a new tab widget for the specified model.
54 * @param model Model to get a new tab widget for
55 * @return widget
56 */
57 QWidget* MainWindow::createWidgetForModel(Model* model)
58 {
59 Q_UNUSED(model);
60 QWidget* widget = new QWidget(ui->tabs);
61 QLabel* label = new QLabel("asdf", widget);
62 QVBoxLayout* layout = new QVBoxLayout;
63 layout->addWidget(label);
64 widget->setLayout(layout);
65 return widget;
66 }
67
68 /**
69 * @brief Gets a tab widget for the specified model. If it does not exist,
70 * it will be created.
71 * @param model Model to get a tab widget for
72 * @return widget
73 */
74 QWidget* MainWindow::getWidgetForModel(Model* model)
75 {
76 QWidget* widget = this->modelWidgets.value(model);
77 if (widget == nullptr)
78 {
79 QWidget* const new_widget = createWidgetForModel(model);
80 this->modelWidgets[model] = new_widget;
81 return new_widget;
82 }
83 else
84 {
85 return widget;
86 }
87 }
88
89 /**
90 * @brief Updates the tab widget
91 */
92 void MainWindow::updateTabs()
93 {
94
95 }
96
97 /**
98 * @brief Updates the title of the main window so to contain the app's name
99 * and version as well as the open document name.
100 */
101 void MainWindow::updateTitle()
102 {
12 QString title = ::appName; 103 QString title = ::appName;
13 title += " "; 104 title += " ";
14 title += fullVersionString(); 105 title += fullVersionString();
15 setWindowTitle(title); 106 setWindowTitle(title);
16 } 107 }
17
18 MainWindow::~MainWindow()
19 {
20 }

mercurial