]> gitweb.hamatoma.de Git - reqt/commitdiff
Perspectives + Views
authorhama <hama@siduction.net>
Mon, 31 Aug 2015 22:22:57 +0000 (00:22 +0200)
committerhama <hama@siduction.net>
Mon, 31 Aug 2015 22:22:57 +0000 (00:22 +0200)
20 files changed:
appl/reide/main.cpp
appl/reide/mainwindow.cpp
appl/reide/mainwindow.hpp
appl/reide/project.cpp
appl/reide/projectselection.cpp
appl/reide/projectselection.hpp
appl/reide/reditor.hpp [deleted file]
appl/reide/reide.hpp [new file with mode: 0644]
appl/reide/reide.pro
appl/reide/views/EditorView.cpp [new file with mode: 0644]
appl/reide/views/EditorView.hpp [new file with mode: 0644]
appl/reide/views/FileTreeView.cpp [new file with mode: 0644]
appl/reide/views/FileTreeView.hpp [new file with mode: 0644]
appl/reide/views/Perspective.cpp [new file with mode: 0644]
appl/reide/views/Perspective.hpp [new file with mode: 0644]
appl/reide/views/ProjectPerspective.cpp [new file with mode: 0644]
appl/reide/views/ProjectPerspective.hpp [new file with mode: 0644]
appl/reide/views/View.cpp [new file with mode: 0644]
appl/reide/views/View.hpp [new file with mode: 0644]
appl/reide/workspace.cpp

index e11e6654181c9aff482d903d8e97469141b87eda..a456b87b00818cfdc741e393e6eb53eb0b66f76b 100644 (file)
@@ -8,7 +8,7 @@
  * You also can use this license: http://www.wtfpl.net
  * The latest sources: https://github.com/republib
  */
-#include "reditor.hpp"
+#include "reide.hpp"
 #include <QApplication>
 
 int main(int argc, char *argv[]) {
index 17e4bda9f2d09522e58942d634ec50d02fe157e4..0e38f059411ba05c2c33740dd8e9fa536f9662e8 100644 (file)
@@ -9,7 +9,7 @@
  * The latest sources: https://github.com/republib
  */
 
-#include "reditor.hpp"
+#include "reide.hpp"
 #include "ui_mainwindow.h"
 #include <QFileDialog>
 
index d80c6f930c4f35b6316ca935fe40fb678bd8dbf3..64d7b6a5d4558a93a17c3293c26765818c8c7394 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <QMainWindow>
 #ifndef REBASE_HPP
-#include "reditor.hpp"
+#include "reide.hpp"
 #endif
 namespace Ui {
 class MainWindow;
index ffda4ee26f23cc71239aa2b050e6c8e64fd83b1f..ab07bd52a1dc7b59568717aca0792b1270acd1b4 100644 (file)
@@ -9,7 +9,7 @@
  * The latest sources: https://github.com/republib
  */
 
-#include "reditor.hpp"
+#include "reide.hpp"
 
 const char* Project::KEY_HISTORY_OPEN_FILES = "openFiles";
 /**
index 1d7fd7248b2eda5584138454f9a95bb8d2b7abf7..742352f0cb79f1c90fb449323203f58bd8a4a664 100644 (file)
@@ -9,7 +9,7 @@
  * The latest sources: https://github.com/republib
  */
 
-#include "reditor.hpp"
+#include "reide.hpp"
 #include "ui_projectselection.h"
 #include <QFileDialog>
 #include <QMessageBox>
index ea17c30db6b4baa6fe7747432dd7b8b41dbec447..9a56e71e6dd444d9d09e69019290841f46e599e5 100644 (file)
@@ -11,7 +11,7 @@
 
 #ifndef PROJECTSELECTION_HPP
 #define PROJECTSELECTION_HPP
-#include "reditor.hpp"
+#include "reide.hpp"
 #include <QDialog>
 #include <QTableWidget>
 namespace Ui {
diff --git a/appl/reide/reditor.hpp b/appl/reide/reditor.hpp
deleted file mode 100644 (file)
index e606072..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * reditor.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef REDITOR_HPP
-#define REDITOR_HPP
-#include <QDockWidget>
-#include "base/rebase.hpp"
-#include "gui/regui.hpp"
-#include "workspace.hpp"
-#include "project.hpp"
-#include "mainwindow.hpp"
-#include "projectselection.hpp"
-#endif // REDITOR_HPP
-
diff --git a/appl/reide/reide.hpp b/appl/reide/reide.hpp
new file mode 100644 (file)
index 0000000..182bf48
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * reditor.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef REIDE_HPP
+#define REIDE_HPP
+#include <QDockWidget>
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+#include "views/View.hpp"
+#include "views/EditorView.hpp"
+#include "views/FileTreeView.hpp"
+#include "views/Perspective.hpp"
+#include "views/ProjectPerspective.hpp"
+#include "workspace.hpp"
+#include "project.hpp"
+#include "mainwindow.hpp"
+#include "projectselection.hpp"
+#endif // REIDE_HPP
+
index a47db111c59c423414d7a0ebfbc2046fdda29485..ee33728d805b673e1f0c0f030da266facb6d39d5 100644 (file)
@@ -27,6 +27,11 @@ SOURCES += \
        projectselection.cpp \
        workspace.cpp \
        project.cpp \
+       views/View.cpp \
+       views/FileTreeView.cpp \
+       views/EditorView.cpp \
+       views/Perspective.cpp \
+       views/ProjectPerspective.cpp \
        main.cpp
 
 
@@ -40,8 +45,8 @@ HEADERS  += mainwindow.hpp \
        projectselection.hpp \
        workspace.hpp \
        project.hpp \
-       reditor.hpp \
-       storage.hpp
+       storage.hpp \
+       reide.hpp
 
 FORMS    += mainwindow.ui \
        projectselection.ui
diff --git a/appl/reide/views/EditorView.cpp b/appl/reide/views/EditorView.cpp
new file mode 100644 (file)
index 0000000..3c15d7e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reide.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param mainWindow   the parent (main window)
+ */
+EditorView::EditorView(MainWindow* mainWindow) :
+           View("EditorView", mainWindow),
+           m_edit(new ReEdit(NULL)) {
+}
+
+/**
+ * Destructor.
+ */
+EditorView::~EditorView() {
+       delete m_edit;
+       m_edit = NULL;
+}
+
diff --git a/appl/reide/views/EditorView.hpp b/appl/reide/views/EditorView.hpp
new file mode 100644 (file)
index 0000000..bd556fe
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef EDITORVIEW_HPP
+#define EDITORVIEW_HPP
+
+class MainWindow;
+
+/**
+ * Abstract base class of the views.
+ *
+ * A view is a widget displayed as a dock in the window displaying a perspective.
+ */
+class EditorView: public View {
+public:
+       EditorView(MainWindow* mainWindow);
+       ~EditorView();
+public:
+       virtual QWidget* widget() {
+               return m_edit;
+       }
+       ;
+protected:
+       ReEdit* m_edit;
+};
+
+#endif // EDITORVIEW_HPP
diff --git a/appl/reide/views/FileTreeView.cpp b/appl/reide/views/FileTreeView.cpp
new file mode 100644 (file)
index 0000000..9a81961
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reide.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param name                 the name of the view
+ * @param mainWindow   the parent (main window)
+ */
+FileTreeView::FileTreeView(MainWindow* mainWindow) :
+           View("FileTreeView", mainWindow) {
+}
diff --git a/appl/reide/views/FileTreeView.hpp b/appl/reide/views/FileTreeView.hpp
new file mode 100644 (file)
index 0000000..1590142
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef FILETREEVIEW_HPP
+#define FILETREEVIEW_HPP
+
+/**
+ * Base class of the views.
+ *
+ * A view is a widget displayed as a dock in the window displaying a perspective.
+ */
+class FileTreeView: public View {
+public:
+       FileTreeView(MainWindow* mainWindow);
+public:
+       /** Returns the view specific widget.
+        * @return the view specific widget
+        */
+       virtual QWidget* widget() {
+               return m_fileTree;
+       }
+protected:
+       ReFileTree* m_fileTree;
+};
+
+#endif // FILETREEVIEW_HPP
diff --git a/appl/reide/views/Perspective.cpp b/appl/reide/views/Perspective.cpp
new file mode 100644 (file)
index 0000000..c733b93
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reide.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param name                 the name of the perspective
+ * @param mainWindow   the parent (main window)
+ */
+Perspective::Perspective(const char* name, MainWindow* mainWindow) :
+           m_name(name),
+           m_mainWindow(mainWindow) {
+}
+
+/**
+ * Destructor.
+ */
+Perspective::~Perspective() {
+       for (int ix = 0; ix < m_views.size(); ix++)
+               delete m_views.at(ix);
+       m_views.clear();
+}
+
+/**
+ * Sets the views as docks in the main window.
+ */
+void Perspective::activate() {
+       // the first view is the central widget, not a dock
+       m_mainWindow->setCentralWidget(m_views.at(0)->m_view->widget());
+       for (int ix = 1; ix < m_views.size(); ix++) {
+               ViewInfo* info = m_views.at(ix);
+               m_mainWindow->addDockWidget(info->m_position, info->m_dockWidget);
+       }
+}
+
+/**
+ * Appends a view to the view list.
+ *
+ * @param view         the view to append
+ * @param position     the positon of the dock
+ */
+void Perspective::append(View* view, Qt::DockWidgetArea position) {
+       ViewInfo* info = new ViewInfo();
+       info->m_position = position;
+       info->m_view = view;
+       info->m_dockWidget = new QDockWidget(m_mainWindow);
+       info->m_dockWidget->setWidget(view->widget());
+       m_views.append(info);
+}
+
+/**
+ * Removes the views (as docks) from the main window.
+ */
+void Perspective::deactivate() {
+       // the first view is the central widget, not a dock
+       for (int ix = 1; ix < m_views.size(); ix++) {
+               ViewInfo* info = m_views.at(ix);
+               m_mainWindow->removeDockWidget(info->m_dockWidget);
+       }
+}
+
+/**
+ * Constructor.
+ */
+PerspectiveList::PerspectiveList(MainWindow* mainWindow) :
+           m_current(NULL),
+           m_map(),
+           m_mainWindow(mainWindow) {
+}
+
+/**
+ * Adds a perspective to the collection.
+ *
+ * @param perspective  the perspective to add
+ */
+void PerspectiveList::addPerspective(Perspective* perspective) {
+       m_map.insert(perspective->name(), perspective);
+}
+
+/**
+ * Deactivates the current perspective and activates another.
+ *
+ * @param perspective  name of the new active perspective
+ */
+void PerspectiveList::changePerspective(const QByteArray& perspective) {
+       if (m_current != NULL)
+               m_current->deactivate();
+       m_current = m_map.value(perspective);
+       if (m_current != NULL)
+               m_current->activate();
+}
diff --git a/appl/reide/views/Perspective.hpp b/appl/reide/views/Perspective.hpp
new file mode 100644 (file)
index 0000000..64d6388
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef PERSPECTIVE_HPP
+#define PERSPECTIVE_HPP
+
+class MainWindow;
+
+class ViewInfo {
+public:
+       View* m_view;
+       Qt::DockWidgetArea m_position;
+       QDockWidget* m_dockWidget;
+};
+
+/**
+ * Abstract base class for perspectives.
+ *
+ * A perspective is a collection of views displayed as docks of a window.
+ */
+class Perspective {
+public:
+       Perspective(const char* name, MainWindow* mainWindow);
+       ~Perspective();
+public:
+       void activate();
+       void append(View* view, Qt::DockWidgetArea location);
+       /** Returns the perspective's name.
+        * @return      the name
+        */
+       const QByteArray& name() const {
+               return m_name;
+       }
+       /**
+        * Prepares the <code>m_map</code> with the views.
+        */
+       virtual void setDefaultViews() = 0;
+       void deactivate();
+
+protected:
+       QByteArray m_name;
+       MainWindow* m_mainWindow;
+       QList<ViewInfo*> m_views;
+};
+
+/**
+ * Manages a collection of <code>Perspective</code>s.
+ */
+class PerspectiveList {
+public:
+       PerspectiveList(MainWindow* mainWindow);
+public:
+       void addPerspective(Perspective* perspective);
+       void changePerspective(const QByteArray& perspective);
+private:
+       Perspective* m_current;
+       QMap<QByteArray, Perspective*> m_map;
+       MainWindow* m_mainWindow;
+};
+
+#endif // PERSPECTIVE_HPP
diff --git a/appl/reide/views/ProjectPerspective.cpp b/appl/reide/views/ProjectPerspective.cpp
new file mode 100644 (file)
index 0000000..60d911f
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reide.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param mainWindow   the parent (main window)
+ */
+ProjectPerspective::ProjectPerspective(MainWindow* mainWindow) :
+           Perspective("ProjectPerspective", mainWindow) {
+}
+
+void ProjectPerspective::setDefaultViews() {
+       append(new EditorView(m_mainWindow), Qt::NoDockWidgetArea);
+       append(new FileTreeView(m_mainWindow), Qt::LeftDockWidgetArea);
+}
diff --git a/appl/reide/views/ProjectPerspective.hpp b/appl/reide/views/ProjectPerspective.hpp
new file mode 100644 (file)
index 0000000..fc55bec
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef PROJECTPERSPECTIVE_HPP
+#define PROJECTPERSPECTIVE_HPP
+
+/**
+ * Manages the aspects of a standard project.
+ */
+class ProjectPerspective: public Perspective {
+public:
+       ProjectPerspective(MainWindow* mainWindow);
+public:
+       virtual void setDefaultViews();
+};
+
+#endif // PROJECTPERSPECTIVE_HPP
diff --git a/appl/reide/views/View.cpp b/appl/reide/views/View.cpp
new file mode 100644 (file)
index 0000000..86dc497
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reide.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param name                 the name of the view
+ * @param mainWindow   the parent (main window)
+ */
+View::View(const char* name, MainWindow* mainWindow) :
+           m_name(name),
+           m_mainWindow(mainWindow) {
+}
diff --git a/appl/reide/views/View.hpp b/appl/reide/views/View.hpp
new file mode 100644 (file)
index 0000000..6ba783c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef VIEW_HPP
+#define VIEW_HPP
+
+class MainWindow;
+
+/**
+ * Base class of the views.
+ *
+ * A view is a widget displayed as a dock in the window displaying a perspective.
+ */
+class View {
+public:
+       View(const char* name, MainWindow* mainWindow);
+public:
+       /** Returns the view's name.
+        * @return the name
+        */
+       const QByteArray& name() const {
+               return m_name;
+       }
+       /**
+        * Returns the view specific widget.
+        * @return the view specific widget
+        */
+       virtual QWidget* widget() = 0;
+
+protected:
+       QByteArray m_name;
+       MainWindow* m_mainWindow;
+};
+
+#endif // VIEW_HPP
index 809c0114ed9445fcec5da4385c0d7893ceac47ff..f6eaa1b9a3b8d3dcf71276e62911afdde8158a60 100644 (file)
@@ -9,7 +9,7 @@
  * The latest sources: https://github.com/republib
  */
 
-#include "reditor.hpp"
+#include "reide.hpp"
 
 const char* Workspace::KEY_HISTORY_FILES = "files";
 const char* Workspace::KEY_HISTORY_PROJECTS = "projecs";