Changeset View
Changeset View
Standalone View
Standalone View
src/mainwindow.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
65 | void MainWindow::closeEvent(QCloseEvent *event) | 65 | void MainWindow::closeEvent(QCloseEvent *event) | ||
66 | { | 66 | { | ||
67 | if (!askToSave(m_gcodeEditor->modifiedFiles())) { | 67 | if (!askToSave(m_gcodeEditor->modifiedFiles())) { | ||
68 | event->ignore(); | 68 | event->ignore(); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | bool closePrompt = false; | 71 | bool closePrompt = false; | ||
72 | for (int i = 0; i < m_instances->count(); i++) { | 72 | for (int i = 0; i < m_instances->count(); i++) { | ||
73 | AtCoreInstanceWidget *instance = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(i)); | 73 | auto instance = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(i)); | ||
74 | if (instance->isPrinting()) { | 74 | if (instance->isPrinting()) { | ||
75 | closePrompt = true; | 75 | closePrompt = true; | ||
76 | break; | 76 | break; | ||
77 | } | 77 | } | ||
78 | } | 78 | } | ||
79 | if (closePrompt) { | 79 | if (closePrompt) { | ||
80 | if (askToClose()) { | 80 | if (askToClose()) { | ||
81 | event->accept(); | 81 | event->accept(); | ||
Show All 30 Lines | |||||
112 | 112 | | |||
113 | void MainWindow::initWidgets() | 113 | void MainWindow::initWidgets() | ||
114 | { | 114 | { | ||
115 | setupLateralArea(); | 115 | setupLateralArea(); | ||
116 | newAtCoreInstance(); | 116 | newAtCoreInstance(); | ||
117 | // View: | 117 | // View: | ||
118 | // Sidebar, Sidebar Controls, Printer Tabs. | 118 | // Sidebar, Sidebar Controls, Printer Tabs. | ||
119 | // Sidebar Controls and Printer Tabs can be resized, Sidebar can't. | 119 | // Sidebar Controls and Printer Tabs can be resized, Sidebar can't. | ||
120 | auto splitter = new QSplitter(); | 120 | auto splitter = new QSplitter(this); | ||
121 | splitter->addWidget(m_lateral.m_stack); | 121 | splitter->addWidget(m_lateral.m_stack); | ||
122 | splitter->addWidget(m_instances); | 122 | splitter->addWidget(m_instances); | ||
123 | 123 | | |||
124 | auto addTabBtn = new QToolButton(); | 124 | auto addTabBtn = new QToolButton(this); | ||
125 | addTabBtn->setIconSize(QSize(fontMetrics().lineSpacing(), fontMetrics().lineSpacing())); | 125 | addTabBtn->setIconSize(QSize(fontMetrics().lineSpacing(), fontMetrics().lineSpacing())); | ||
126 | addTabBtn->setIcon(QIcon::fromTheme("list-add", QIcon(QString(":/%1/addTab").arg(m_theme)))); | 126 | addTabBtn->setIcon(QIcon::fromTheme("list-add", QIcon(QString(":/%1/addTab").arg(m_theme)))); | ||
127 | addTabBtn->setToolTip(i18n("Create new instance")); | 127 | addTabBtn->setToolTip(i18n("Create new instance")); | ||
128 | addTabBtn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T)); | 128 | addTabBtn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T)); | ||
129 | connect(addTabBtn, &QToolButton::clicked, this, &MainWindow::newAtCoreInstance); | 129 | connect(addTabBtn, &QToolButton::clicked, this, &MainWindow::newAtCoreInstance); | ||
130 | m_instances->setCornerWidget(addTabBtn, Qt::TopLeftCorner); | 130 | m_instances->setCornerWidget(addTabBtn, Qt::TopLeftCorner); | ||
131 | 131 | | |||
132 | auto *centralLayout = new QHBoxLayout(); | 132 | auto *centralLayout = new QHBoxLayout(); | ||
133 | centralLayout->addWidget(m_lateral.m_toolBar); | 133 | centralLayout->addWidget(m_lateral.m_toolBar); | ||
134 | centralLayout->addWidget(splitter); | 134 | centralLayout->addWidget(splitter); | ||
135 | 135 | | |||
136 | auto *centralWidget = new QWidget(); | 136 | auto *centralWidget = new QWidget(this); | ||
137 | centralWidget->setLayout(centralLayout); | 137 | centralWidget->setLayout(centralLayout); | ||
138 | setCentralWidget(centralWidget); | 138 | setCentralWidget(centralWidget); | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | void MainWindow::newAtCoreInstance() | 141 | void MainWindow::newAtCoreInstance() | ||
142 | { | 142 | { | ||
143 | auto newInstanceWidget = new AtCoreInstanceWidget(this); | 143 | auto newInstanceWidget = new AtCoreInstanceWidget(this); | ||
144 | QString name = QString::number(m_instances->addTab(newInstanceWidget, i18n("Connect a printer"))); | 144 | QString name = QString::number(m_instances->addTab(newInstanceWidget, i18n("Connect a printer"))); | ||
145 | newInstanceWidget->setObjectName(name); | 145 | newInstanceWidget->setObjectName(name); | ||
146 | newInstanceWidget->setFileCount(m_openFiles.size()); | 146 | newInstanceWidget->setFileCount(m_openFiles.size()); | ||
147 | connect(this, &MainWindow::profilesChanged, newInstanceWidget, &AtCoreInstanceWidget::updateProfileData); | 147 | connect(this, &MainWindow::profilesChanged, newInstanceWidget, &AtCoreInstanceWidget::updateProfileData); | ||
148 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestProfileDialog, this, [this] { | 148 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestProfileDialog, this, [this] { | ||
149 | std::unique_ptr<ProfilesDialog> pd(new ProfilesDialog); | 149 | std::unique_ptr<ProfilesDialog> pd(new ProfilesDialog(this)); | ||
150 | pd->exec(); | 150 | pd->exec(); | ||
151 | emit(profilesChanged()); | 151 | emit(profilesChanged()); | ||
152 | }); | 152 | }); | ||
153 | 153 | | |||
154 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestFileChooser, this, [newInstanceWidget, this] { | 154 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestFileChooser, this, [newInstanceWidget, this] { | ||
155 | QUrl file; | 155 | QUrl file; | ||
156 | switch (m_openFiles.size()) | 156 | switch (m_openFiles.size()) | ||
157 | { | 157 | { | ||
Show All 20 Lines | 176 | int result = QMessageBox::question( | |||
178 | , i18n("Document Modified") | 178 | , i18n("Document Modified") | ||
179 | , i18n("%1 \n Contains Unsaved Changes That will not be in the print.\n Would you like to Save before printing?", file.toLocalFile()) | 179 | , i18n("%1 \n Contains Unsaved Changes That will not be in the print.\n Would you like to Save before printing?", file.toLocalFile()) | ||
180 | , QMessageBox::Save | 180 | , QMessageBox::Save | ||
181 | , QMessageBox::Cancel | 181 | , QMessageBox::Cancel | ||
182 | , QMessageBox::Ignore | 182 | , QMessageBox::Ignore | ||
183 | ); | 183 | ); | ||
184 | if (result == QMessageBox::Cancel) { | 184 | if (result == QMessageBox::Cancel) { | ||
185 | return; | 185 | return; | ||
186 | } else if (result == QMessageBox::Save) { | 186 | } | ||
187 | if (result == QMessageBox::Save) { | ||||
187 | m_gcodeEditor->saveFile(file); | 188 | m_gcodeEditor->saveFile(file); | ||
188 | } | 189 | } | ||
189 | } | 190 | } | ||
190 | newInstanceWidget->printFile(file); | 191 | newInstanceWidget->printFile(file); | ||
191 | }); | 192 | }); | ||
192 | 193 | | |||
193 | connect(newInstanceWidget, &AtCoreInstanceWidget::bedSizeChanged, this, [this](const QSize & newSize) { | 194 | connect(newInstanceWidget, &AtCoreInstanceWidget::bedSizeChanged, this, [this](const QSize & newSize) { | ||
194 | if (m_currInstance == m_instances->currentIndex()) { | 195 | if (m_currInstance == m_instances->currentIndex()) { | ||
195 | updateBedSize(newSize); | 196 | updateBedSize(newSize); | ||
196 | } | 197 | } | ||
197 | }); | 198 | }); | ||
198 | 199 | | |||
199 | connect(newInstanceWidget, &AtCoreInstanceWidget::connectionChanged, this, &MainWindow::atCoreInstanceNameChange); | 200 | connect(newInstanceWidget, &AtCoreInstanceWidget::connectionChanged, this, &MainWindow::atCoreInstanceNameChange); | ||
200 | 201 | | |||
201 | if (m_instances->count() > 1) { | 202 | if (m_instances->count() > 1) { | ||
202 | m_instances->setTabsClosable(true); | 203 | m_instances->setTabsClosable(true); | ||
203 | m_instances->setMovable(true); | 204 | m_instances->setMovable(true); | ||
204 | m_instances->setCurrentIndex(m_instances->count() - 1); | 205 | m_instances->setCurrentIndex(m_instances->count() - 1); | ||
205 | } | 206 | } | ||
206 | } | 207 | } | ||
207 | // Move to LateralArea. | 208 | // Move to LateralArea. | ||
208 | void MainWindow::setupLateralArea() | 209 | void MainWindow::setupLateralArea() | ||
209 | { | 210 | { | ||
210 | m_lateral.m_toolBar = new QWidget(); | 211 | m_lateral.m_toolBar = new QWidget(this); | ||
211 | m_lateral.m_stack = new QStackedWidget(); | 212 | m_lateral.m_stack = new QStackedWidget(this); | ||
212 | auto buttonLayout = new QVBoxLayout(); | 213 | auto buttonLayout = new QVBoxLayout(); | ||
213 | 214 | | |||
214 | auto setupButton = [this, buttonLayout](const QString & key, const QString & text, const QIcon & icon, QWidget * w) { | 215 | auto setupButton = [this, buttonLayout](const QString & key, const QString & text, const QIcon & icon, QWidget * w) { | ||
215 | auto *btn = new QPushButton(m_lateral.m_toolBar); | 216 | auto *btn = new QPushButton(m_lateral.m_toolBar); | ||
216 | btn->setToolTip(text); | 217 | btn->setToolTip(text); | ||
217 | btn->setAutoExclusive(true); | 218 | btn->setAutoExclusive(true); | ||
218 | btn->setCheckable(true); | 219 | btn->setCheckable(true); | ||
219 | //Check the top most widget, so users see its selected at startup time. | 220 | //Check the top most widget, so users see its selected at startup time. | ||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Line(s) | 414 | { | |||
469 | auto cancelBtn = new QPushButton(QIcon::fromTheme("dialog-cancel", QIcon(QStringLiteral(":/%1/cancel").arg(m_theme))), i18n("Cancel"), dialog); | 470 | auto cancelBtn = new QPushButton(QIcon::fromTheme("dialog-cancel", QIcon(QStringLiteral(":/%1/cancel").arg(m_theme))), i18n("Cancel"), dialog); | ||
470 | cancelBtn->setIconSize(iconSize); | 471 | cancelBtn->setIconSize(iconSize); | ||
471 | cancelBtn->setDefault(true); | 472 | cancelBtn->setDefault(true); | ||
472 | connect(cancelBtn, &QPushButton::clicked, this, [dialog] { | 473 | connect(cancelBtn, &QPushButton::clicked, this, [dialog] { | ||
473 | dialog->reject(); | 474 | dialog->reject(); | ||
474 | }); | 475 | }); | ||
475 | hLayout->addWidget(cancelBtn); | 476 | hLayout->addWidget(cancelBtn); | ||
476 | 477 | | |||
477 | auto ignoreBtn = new QPushButton(QIcon::fromTheme("edit-delete", style()->standardIcon(QStyle::SP_TrashIcon)), i18n("Discard Changes"), dialog); | 478 | auto ignoreBtn = new QPushButton(QIcon::fromTheme("edit-delete", style()->standardIcon(QStyle::SP_TrashIcon)), i18n("Discard Changes"), dialog); | ||
rizzitello: I Did not forget this button see D17116 | |||||
478 | ignoreBtn->setIconSize(iconSize); | 479 | ignoreBtn->setIconSize(iconSize); | ||
479 | connect(ignoreBtn, &QPushButton::clicked, this, [dialog] { | 480 | connect(ignoreBtn, &QPushButton::clicked, this, [dialog] { | ||
480 | dialog->accept(); | 481 | dialog->accept(); | ||
481 | }); | 482 | }); | ||
482 | hLayout->addWidget(ignoreBtn); | 483 | hLayout->addWidget(ignoreBtn); | ||
483 | 484 | | |||
484 | auto layout = new QVBoxLayout; | 485 | auto layout = new QVBoxLayout; | ||
485 | auto label = new QLabel(i18n("Files with Unsaved Changes."), dialog); | 486 | auto label = new QLabel(i18n("Files with Unsaved Changes."), dialog); | ||
Show All 12 Lines |
I Did not forget this button see D17116