Removing plugin system is holding back development to much.
This commit is contained in:
parent
048843a1d4
commit
edb789ca4a
22 changed files with 198 additions and 562 deletions
|
|
@ -1,6 +0,0 @@
|
|||
#include "LMainMenu.h"
|
||||
|
||||
LMainMenu::LMainMenu()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
#ifndef LMAINMENU_H
|
||||
#define LMAINMENU_H
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
class QAction;
|
||||
|
||||
class LMenuGroupItem {
|
||||
public:
|
||||
LMenuGroupItem(QAction *action, int position)
|
||||
: m_menuAction(action)
|
||||
, m_position(position)
|
||||
{}
|
||||
|
||||
int position() const { return m_position; }
|
||||
|
||||
private:
|
||||
QAction *m_menuAction;
|
||||
int m_position;
|
||||
};
|
||||
|
||||
// Menu's are divided into logical groups,
|
||||
// these groups form only a single level they are NOT submenu's
|
||||
class LMenuGroup {
|
||||
public:
|
||||
|
||||
explicit LMenuGroup(QString group_id);
|
||||
QString groupId() const;
|
||||
|
||||
private:
|
||||
QString m_groupId;
|
||||
};
|
||||
|
||||
class LMenu {
|
||||
public:
|
||||
QString menuId() const;
|
||||
|
||||
void addGroup(const LMenuGroup &group)
|
||||
{
|
||||
m_groups.push_back(group);
|
||||
}
|
||||
private:
|
||||
using Groups = std::vector<LMenuGroup>;
|
||||
|
||||
QString m_caption;
|
||||
Groups m_groups;
|
||||
};
|
||||
|
||||
|
||||
class LMainMenu: public LMenu {
|
||||
public:
|
||||
LMainMenu();
|
||||
};
|
||||
|
||||
#endif // LMAINMENU_H
|
||||
|
|
@ -1,217 +0,0 @@
|
|||
#include "LMainWindow.h"
|
||||
#include "PluginContentWidget.h"
|
||||
#include "PluginContentWidgetContextBase.h"
|
||||
#include "PluginModule.h"
|
||||
#include "PluginRegister.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QToolBar>
|
||||
|
||||
namespace LMainWindow_details {
|
||||
|
||||
class LMainWindowContentContext: public PluginContentWidgetContextBase {
|
||||
public:
|
||||
explicit LMainWindowContentContext(LMainWindow *window)
|
||||
: m_window(window)
|
||||
{}
|
||||
|
||||
void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) override
|
||||
{
|
||||
m_window->setTabCaptionForWidget(content, caption, hint);
|
||||
}
|
||||
|
||||
void setIcon(PluginContentWidget *content, const QString &iconname) override
|
||||
{
|
||||
m_window->setTabIcon(content, iconname);
|
||||
}
|
||||
|
||||
void showStatusMessage(const QString &msg) override
|
||||
{
|
||||
m_window->statusBar()->showMessage(msg);
|
||||
}
|
||||
|
||||
void addContentWidget(PluginContentWidget *widget) override
|
||||
{
|
||||
PluginContentWidgetContextBase::addContentWidget(widget);
|
||||
m_window->addPage(widget, "");
|
||||
}
|
||||
|
||||
QWidget* container() override
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
private:
|
||||
LMainWindow *m_window;
|
||||
};
|
||||
|
||||
}
|
||||
using namespace LMainWindow_details;
|
||||
|
||||
|
||||
|
||||
LMainWindow::LMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
m_context = new LMainWindowContentContext(this);
|
||||
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
m_tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
|
||||
m_tabWidget->setDocumentMode(true);
|
||||
|
||||
setCentralWidget(m_tabWidget);
|
||||
|
||||
// menu
|
||||
auto menuBar = new QMenuBar(this);
|
||||
setMenuBar(menuBar);
|
||||
|
||||
// tooolbar
|
||||
m_mainToolBar = new QToolBar(this);
|
||||
addToolBar(Qt::TopToolBarArea, m_mainToolBar);
|
||||
|
||||
// statusbar
|
||||
auto statusBar = new QStatusBar(this);
|
||||
setStatusBar(statusBar);
|
||||
|
||||
m_fileMenu = new QMenu(tr("File"), this);
|
||||
|
||||
createActions();
|
||||
m_mainToolBar->addAction(m_closeAction);
|
||||
|
||||
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, &LMainWindow::tabWidget_tabCloseRequested);
|
||||
connect(m_tabWidget, &QTabWidget::currentChanged, this, &LMainWindow::tabWidget_currentChanged);
|
||||
}
|
||||
|
||||
LMainWindow::~LMainWindow()
|
||||
{
|
||||
delete m_context;
|
||||
}
|
||||
|
||||
void LMainWindow::initModuleMenus()
|
||||
{
|
||||
menuBar()->addMenu(m_fileMenu);
|
||||
addModuleMenuActions();
|
||||
}
|
||||
|
||||
void LMainWindow::addModuleMenuActions()
|
||||
{
|
||||
auto reg = PluginRegister::getInstance();
|
||||
auto mods = reg->modules();
|
||||
for (auto && mod : mods) {
|
||||
auto items = mod.second->staticActions();
|
||||
for (auto && item : items) {
|
||||
addMenuAction(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LMainWindow::createActions()
|
||||
{
|
||||
{
|
||||
auto action = m_closeAction = new QAction(this);
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
action->setIcon(icon);
|
||||
connect(m_closeAction, &QAction::triggered, this, &LMainWindow::actionClose_triggered);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LMainWindow::addMenuAction(const StaticAction &ma)
|
||||
{
|
||||
qDebug() << "add action " << ma.text();
|
||||
//auto ac =
|
||||
m_fileMenu->addAction(ma.icon(), ma.text(),
|
||||
[ma, this] ()
|
||||
{
|
||||
ma.perform(m_context);
|
||||
},
|
||||
ma.shortcut());
|
||||
|
||||
|
||||
// auto ac = new QAction(this);
|
||||
// ac->
|
||||
}
|
||||
|
||||
void LMainWindow::actionClose_triggered()
|
||||
{
|
||||
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
void LMainWindow::addPage(PluginContentWidget* page, QString caption)
|
||||
{
|
||||
m_tabWidget->addTab(page, caption);
|
||||
m_tabWidget->setCurrentWidget(page);
|
||||
}
|
||||
|
||||
void LMainWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
m_tabWidget->setTabText(index, caption);
|
||||
m_tabWidget->setTabToolTip(index, hint);
|
||||
}
|
||||
|
||||
void LMainWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
auto n = ":/icons/16x16/" + iconname;
|
||||
m_tabWidget->setTabIcon(index, QIcon(n));
|
||||
}
|
||||
|
||||
IPluginContentWidgetContext* LMainWindow::context()
|
||||
{
|
||||
return m_context;
|
||||
}
|
||||
|
||||
void LMainWindow::tabWidget_tabCloseRequested(int index)
|
||||
{
|
||||
QWidget *widget = m_tabWidget->widget(index);
|
||||
PluginContentWidget *plg_page = dynamic_cast<PluginContentWidget*>(widget);
|
||||
if (plg_page) {
|
||||
if (plg_page->canClose()) {
|
||||
m_tabWidget->removeTab(index);
|
||||
m_context->removeContentWidget(plg_page);
|
||||
delete plg_page;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// old behaviour shouldn't be needed any more when all pages have been migrated
|
||||
// to PlgPage
|
||||
m_tabWidget->removeTab(index);
|
||||
delete widget;
|
||||
}
|
||||
}
|
||||
|
||||
void LMainWindow::tabWidget_currentChanged(int index)
|
||||
{
|
||||
// remove buttons of old page
|
||||
if (m_previousPage) {
|
||||
removeModuleWidgetActionsForPage(m_previousPage);
|
||||
}
|
||||
|
||||
// add buttons of new page
|
||||
PluginContentWidget * page = nullptr;
|
||||
if (index >= 0) {
|
||||
QWidget *widget = m_tabWidget->widget(index);
|
||||
page = dynamic_cast<PluginContentWidget*>(widget);
|
||||
if (page) {
|
||||
addModuleWidgetActionsForPage(page);
|
||||
}
|
||||
}
|
||||
m_previousPage = page;
|
||||
}
|
||||
|
||||
void LMainWindow::addModuleWidgetActionsForPage(PluginContentWidget *page)
|
||||
{
|
||||
m_context->addWidgetActionsToToolbar(page, m_mainToolBar);
|
||||
m_context->addContextActionsToMenu(page, menuBar());
|
||||
}
|
||||
|
||||
void LMainWindow::removeModuleWidgetActionsForPage(PluginContentWidget *page)
|
||||
{
|
||||
m_context->removeContextActionsFromMenu(page, menuBar());
|
||||
m_context->removeWidgetActionsFromToolbar(page, m_mainToolBar);
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef LMAINWINDOW_H
|
||||
#define LMAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class IPluginContentWidgetContext;
|
||||
class StaticAction;
|
||||
class PluginContentWidget;
|
||||
|
||||
namespace LMainWindow_details {
|
||||
class LMainWindowContentContext;
|
||||
}
|
||||
|
||||
class LMainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
LMainWindow(QWidget *parent = nullptr);
|
||||
~LMainWindow();
|
||||
|
||||
void initModuleMenus();
|
||||
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
|
||||
void setTabIcon(QWidget *widget, const QString &iconname);
|
||||
|
||||
/// Called when a newly created page is added to the QTabWidget
|
||||
void addPage(PluginContentWidget* page, QString caption);
|
||||
|
||||
IPluginContentWidgetContext* context();
|
||||
protected:
|
||||
QTabWidget *m_tabWidget = nullptr;
|
||||
QToolBar *m_mainToolBar = nullptr;
|
||||
|
||||
// Standard menu's
|
||||
QMenu *m_fileMenu = nullptr;
|
||||
|
||||
// Standard actions
|
||||
QAction *m_closeAction = nullptr;
|
||||
|
||||
|
||||
void addModuleMenuActions();
|
||||
|
||||
void addModuleWidgetActionsForPage(PluginContentWidget *page);
|
||||
void removeModuleWidgetActionsForPage(PluginContentWidget *page);
|
||||
private:
|
||||
LMainWindow_details::LMainWindowContentContext *m_context;
|
||||
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
||||
|
||||
void createActions();
|
||||
void addMenuAction(const StaticAction &ma);
|
||||
|
||||
private slots:
|
||||
void actionClose_triggered();
|
||||
void tabWidget_tabCloseRequested(int index);
|
||||
void tabWidget_currentChanged(int index);
|
||||
};
|
||||
|
||||
|
||||
#endif // LMAINWINDOW_H
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include "LMenu.h"
|
||||
|
||||
LMenu::LMenu()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef LMENU_H
|
||||
#define LMENU_H
|
||||
|
||||
/** Represents a menu wraps QMenu to give it more dynamic functionality
|
||||
*
|
||||
*/
|
||||
class LMenu
|
||||
{
|
||||
public:
|
||||
LMenu();
|
||||
};
|
||||
|
||||
#endif // LMENU_H
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include "LMenuBar.h"
|
||||
|
||||
LMenuBar::LMenuBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef LMENUBAR_H
|
||||
#define LMENUBAR_H
|
||||
|
||||
/** Represents the main menubar. Linked to a QMenuBar
|
||||
*/
|
||||
class LMenuBar {
|
||||
public:
|
||||
LMenuBar();
|
||||
};
|
||||
|
||||
#endif // LMENUBAR_H
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include "LMenuItem.h"
|
||||
|
||||
LMenuItem::LMenuItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef LMENUITEM_H
|
||||
#define LMENUITEM_H
|
||||
|
||||
|
||||
class LMenuItem {
|
||||
public:
|
||||
LMenuItem();
|
||||
};
|
||||
|
||||
#endif // LMENUITEM_H
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include "LMenuSection.h"
|
||||
|
||||
LMenuSection::LMenuSection()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef LMENUSECTION_H
|
||||
#define LMENUSECTION_H
|
||||
|
||||
/** Logical grouping within a menu
|
||||
*/
|
||||
class LMenuSection {
|
||||
public:
|
||||
LMenuSection();
|
||||
};
|
||||
|
||||
#endif // LMENUSECTION_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue