Thu, 03 Oct 2019 11:45:44 +0300
stuff
0 | 1 | #include "mainwindow.h" |
2 | #include "ui_mainwindow.h" | |
1 | 3 | #include "version.h" |
5 | 4 | #include <QLabel> |
5 | #include <QVBoxLayout> | |
0 | 6 | |
7 | MainWindow::MainWindow(QWidget *parent) : | |
3 | 8 | QMainWindow{parent}, |
5 | 9 | ui{std::make_unique<Ui_MainWindow>()}, |
10 | documents{this} | |
0 | 11 | { |
3 | 12 | ui->setupUi(this); |
5 | 13 | connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel); |
3 | 14 | connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); |
5 | 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 | { | |
1 | 103 | QString title = ::appName; |
104 | title += " "; | |
105 | title += fullVersionString(); | |
106 | setWindowTitle(title); | |
0 | 107 | } |