Skip to content
Extraits de code Groupes Projets
Vérifiée Valider fc2271fe rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: The user can now close documents

parent 43a7c05f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
...@@ -14,11 +14,24 @@ ...@@ -14,11 +14,24 @@
#include <QMenuBar> #include <QMenuBar>
#include <QImage> #include <QImage>
#include <QToolBar> #include <QToolBar>
#include <QTabWidget>
MainWindow::MainWindow(QWidget *parent) noexcept MainWindow::MainWindow(QWidget *parent) noexcept
: QMainWindow(parent) : QMainWindow(parent)
{ {
/* Some ugly stuff going on here with the toolbars and the menues */
#include "MainWindow.xdef" #include "MainWindow.xdef"
/* Setup the tabs to display the documents */
documents = new QTabWidget(this);
documents->setMovable(true);
documents->setTabsClosable(true);
documents->setElideMode(Qt::ElideRight);
documents->setUsesScrollButtons(true);
connect(documents, &QTabWidget::tabCloseRequested, this, &MainWindow::closeDocument);
setCentralWidget(documents);
/* Main window has finished its construction */
statusBar()->showMessage("QSimulate has started"); statusBar()->showMessage("QSimulate has started");
} }
...@@ -40,7 +53,20 @@ MainWindow::saveFileAs() noexcept ...@@ -40,7 +53,20 @@ MainWindow::saveFileAs() noexcept
} }
void void
MainWindow::openAudioFile() noexcept MainWindow::closeDocument(int index) noexcept
{
const QWidget *widgetToClose = documents->widget(index);
const VivyDocumentView *documentToClose = reinterpret_cast<const VivyDocumentView *>(widgetToClose);
const QString documentName = documentToClose->getDocument()->getName();
qDebug() << "Request to close the document " << documentName << " with tab position " << index;
documents->removeTab(index);
documentStore.closeDocument(documentName);
}
void
MainWindow::openDocument() noexcept
{ {
QString filename = QFileDialog::getOpenFileName(this, "Select a file"); QString filename = QFileDialog::getOpenFileName(this, "Select a file");
if (filename.isEmpty()) { if (filename.isEmpty()) {
...@@ -61,7 +87,7 @@ MainWindow::openAudioFile() noexcept ...@@ -61,7 +87,7 @@ MainWindow::openAudioFile() noexcept
VivyDocumentView *documentView = documentStore.getDocumentView(document->getName()); VivyDocumentView *documentView = documentStore.getDocumentView(document->getName());
if (documentView != nullptr) { if (documentView != nullptr) {
qDebug() << "View constructed successfully"; qDebug() << "View constructed successfully";
setCentralWidget(documentView); documents->addTab(documentView, document->getName());
} else { } else {
qCritical() << "Failed to create the document view for " << document->getName(); qCritical() << "Failed to create the document view for " << document->getName();
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
class QMenu; class QMenu;
class QAction; class QAction;
class QTabWidget;
class VivyApplication; class VivyApplication;
class MainWindow final : public QMainWindow { class MainWindow final : public QMainWindow {
...@@ -18,6 +19,7 @@ class MainWindow final : public QMainWindow { ...@@ -18,6 +19,7 @@ class MainWindow final : public QMainWindow {
VivyDocumentStore documentStore{}; VivyDocumentStore documentStore{};
VivyApplication *application{ nullptr }; VivyApplication *application{ nullptr };
QTabWidget *documents{ nullptr };
public: public:
explicit MainWindow(QWidget *parent = nullptr) noexcept; explicit MainWindow(QWidget *parent = nullptr) noexcept;
...@@ -26,7 +28,9 @@ public: ...@@ -26,7 +28,9 @@ public:
void registerApplication(VivyApplication *) noexcept; void registerApplication(VivyApplication *) noexcept;
private slots: private slots:
void openAudioFile() noexcept; void openDocument() noexcept;
void closeDocument(int index) noexcept;
void openDialogHelp() noexcept; void openDialogHelp() noexcept;
void saveFile() noexcept; void saveFile() noexcept;
void saveFileAs() noexcept; void saveFileAs() noexcept;
......
...@@ -45,17 +45,17 @@ MAIN_WINDOW_MENU(help, "&Help") ...@@ -45,17 +45,17 @@ MAIN_WINDOW_MENU(help, "&Help")
MAIN_WINDOW_TOOLBAR(file, "File") MAIN_WINDOW_TOOLBAR(file, "File")
MAIN_WINDOW_TOOLBAR(other, "Other") MAIN_WINDOW_TOOLBAR(other, "Other")
MAIN_WINDOW_ACTION_ICON(openAudioFile, "&Open audio", "Open an audio file", file, "document-open") MAIN_WINDOW_ACTION_ICON(openDocument, "&Open document", "Open a a document", file, "document-open")
MAIN_WINDOW_ACTION_ICON(saveFile, "&Save file", "Save the current document", file, "document-save") MAIN_WINDOW_ACTION_ICON(saveFile, "&Save file", "Save the current document", file, "document-save")
MAIN_WINDOW_ACTION_ICON(saveFileAs, "&Save file as", "Save the current document as", file, "document-save-as") MAIN_WINDOW_ACTION_ICON(saveFileAs, "&Save file as", "Save the current document as", file, "document-save-as")
MAIN_WINDOW_ACTION_ICON(openDialogHelp, "&About", "Open the help dialog", help, "help-about") MAIN_WINDOW_ACTION_ICON(openDialogHelp, "&About", "Open the help dialog", help, "help-about")
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, openAudioFile) MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, openDocument)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFile) MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFile)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFileAs) MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFileAs)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(other, openDialogHelp) MAIN_WINDOW_TOOLBAR_ADD_ACTION(other, openDialogHelp)
MAIN_WINDOW_ACTION_ADD_SHORTCUT(openAudioFile, QKeySequence::Open) MAIN_WINDOW_ACTION_ADD_SHORTCUT(openDocument, QKeySequence::Open)
MAIN_WINDOW_ACTION_ADD_SHORTCUT(saveFile, QKeySequence::Save) MAIN_WINDOW_ACTION_ADD_SHORTCUT(saveFile, QKeySequence::Save)
// vim: ft=c // vim: ft=c
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter