From: hama Date: Mon, 31 Aug 2015 22:22:57 +0000 (+0200) Subject: Perspectives + Views X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c7743248de7aa8a0f909b91ca0892bd91583ee6c;p=reqt Perspectives + Views --- diff --git a/appl/reide/main.cpp b/appl/reide/main.cpp index e11e665..a456b87 100644 --- a/appl/reide/main.cpp +++ b/appl/reide/main.cpp @@ -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 int main(int argc, char *argv[]) { diff --git a/appl/reide/mainwindow.cpp b/appl/reide/mainwindow.cpp index 17e4bda..0e38f05 100644 --- a/appl/reide/mainwindow.cpp +++ b/appl/reide/mainwindow.cpp @@ -9,7 +9,7 @@ * The latest sources: https://github.com/republib */ -#include "reditor.hpp" +#include "reide.hpp" #include "ui_mainwindow.h" #include diff --git a/appl/reide/mainwindow.hpp b/appl/reide/mainwindow.hpp index d80c6f9..64d7b6a 100644 --- a/appl/reide/mainwindow.hpp +++ b/appl/reide/mainwindow.hpp @@ -14,7 +14,7 @@ #include #ifndef REBASE_HPP -#include "reditor.hpp" +#include "reide.hpp" #endif namespace Ui { class MainWindow; diff --git a/appl/reide/project.cpp b/appl/reide/project.cpp index ffda4ee..ab07bd5 100644 --- a/appl/reide/project.cpp +++ b/appl/reide/project.cpp @@ -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"; /** diff --git a/appl/reide/projectselection.cpp b/appl/reide/projectselection.cpp index 1d7fd72..742352f 100644 --- a/appl/reide/projectselection.cpp +++ b/appl/reide/projectselection.cpp @@ -9,7 +9,7 @@ * The latest sources: https://github.com/republib */ -#include "reditor.hpp" +#include "reide.hpp" #include "ui_projectselection.h" #include #include diff --git a/appl/reide/projectselection.hpp b/appl/reide/projectselection.hpp index ea17c30..9a56e71 100644 --- a/appl/reide/projectselection.hpp +++ b/appl/reide/projectselection.hpp @@ -11,7 +11,7 @@ #ifndef PROJECTSELECTION_HPP #define PROJECTSELECTION_HPP -#include "reditor.hpp" +#include "reide.hpp" #include #include namespace Ui { diff --git a/appl/reide/reditor.hpp b/appl/reide/reditor.hpp deleted file mode 100644 index e606072..0000000 --- a/appl/reide/reditor.hpp +++ /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 -#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 index 0000000..182bf48 --- /dev/null +++ b/appl/reide/reide.hpp @@ -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 +#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 + diff --git a/appl/reide/reide.pro b/appl/reide/reide.pro index a47db11..ee33728 100644 --- a/appl/reide/reide.pro +++ b/appl/reide/reide.pro @@ -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 index 0000000..3c15d7e --- /dev/null +++ b/appl/reide/views/EditorView.cpp @@ -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 index 0000000..bd556fe --- /dev/null +++ b/appl/reide/views/EditorView.hpp @@ -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 index 0000000..9a81961 --- /dev/null +++ b/appl/reide/views/FileTreeView.cpp @@ -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 index 0000000..1590142 --- /dev/null +++ b/appl/reide/views/FileTreeView.hpp @@ -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 index 0000000..c733b93 --- /dev/null +++ b/appl/reide/views/Perspective.cpp @@ -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 index 0000000..64d6388 --- /dev/null +++ b/appl/reide/views/Perspective.hpp @@ -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 m_map with the views. + */ + virtual void setDefaultViews() = 0; + void deactivate(); + +protected: + QByteArray m_name; + MainWindow* m_mainWindow; + QList m_views; +}; + +/** + * Manages a collection of Perspectives. + */ +class PerspectiveList { +public: + PerspectiveList(MainWindow* mainWindow); +public: + void addPerspective(Perspective* perspective); + void changePerspective(const QByteArray& perspective); +private: + Perspective* m_current; + QMap 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 index 0000000..60d911f --- /dev/null +++ b/appl/reide/views/ProjectPerspective.cpp @@ -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 index 0000000..fc55bec --- /dev/null +++ b/appl/reide/views/ProjectPerspective.hpp @@ -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 index 0000000..86dc497 --- /dev/null +++ b/appl/reide/views/View.cpp @@ -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 index 0000000..6ba783c --- /dev/null +++ b/appl/reide/views/View.hpp @@ -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 diff --git a/appl/reide/workspace.cpp b/appl/reide/workspace.cpp index 809c011..f6eaa1b 100644 --- a/appl/reide/workspace.cpp +++ b/appl/reide/workspace.cpp @@ -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";