menuactionhelper.h 1.99 KB
Newer Older
1 2 3 4
#ifndef MENUACTIONHELPER_H
#define MENUACTIONHELPER_H

#include "MainWindow.h"
5
#include <QDockWidget>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

class MenuActionHelper : public QObject
{
    Q_OBJECT
public:
    MenuActionHelper(QObject *parent = NULL);
    ~MenuActionHelper() {}

    /** @brief Get title bar mode setting */
    bool dockWidgetTitleBarsEnabled() const { return m_dockWidgetTitleBarsEnabled; }
    void setDockWidgetTitleBarsEnabled(bool enabled);
    bool isAdvancedMode() const { return m_isAdvancedMode; }
    void setAdvancedMode(bool advancedMode);
    QAction *createToolAction(const QString &title, const QString &name = QString());
    QAction *createToolActionForCustomDockWidget(const QString& title, const QString& name, QDockWidget* dockWidget, MainWindow::VIEW_SECTIONS view);
    QDockWidget *createDockWidget(const QString& title, const QString& name);
    bool containsDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const;
    QDockWidget *getDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const;

    /** QMenu to add QActions to */
    void setMenu(QMenu *menu) { m_menu = menu; }

protected:
    virtual bool eventFilter(QObject *object,QEvent *event);

private slots:
    void removeDockWidget();
    /** @brief Shows a Docked Widget based on the action sender */
    void showTool(bool show);

signals:
    void needToShowDockWidget(const QString& name, bool show);
private:
    QMap<QAction*,QString > m_menuToDockNameMap;
    QList<QDockWidget*> m_dockWidgets;
    QMap<MainWindow::VIEW_SECTIONS,QMap<QString,QDockWidget*> > m_centralWidgetToDockWidgetsMap;
    bool m_isAdvancedMode; ///< If enabled dock widgets can be moved and floated.
    bool m_dockWidgetTitleBarsEnabled; ///< If enabled, dock widget titlebars are displayed when NOT in advanced mode.
    QMenu *m_menu; ///< \see setMenu()
    bool m_addedCustomSeperator; ///< Whether we have added a seperator between the actions and the custom actions

    void setDockWidgetTitleBar(QDockWidget* widget);

};

#endif // MENUACTIONHELPER_H