Files
create/src/Gui/ToolBarManager.h
wmayer 21f47cf2ec Gui: fix warnings reported by GH Actions:
* Fix trailing spaces
* Replace tabs
* Mark constructors with one argument explicit
* Fix typos
* Include FCGlobal.h to fix parsing errors
2022-11-11 09:56:43 +01:00

113 lines
3.9 KiB
C++

/***************************************************************************
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_TOOLBARMANAGER_H
#define GUI_TOOLBARMANAGER_H
#include <string>
#include <QStringList>
#include <FCGlobal.h>
class QAction;
class QToolBar;
namespace Gui {
class GuiExport ToolBarItem
{
public:
enum class HideStyle {
VISIBLE,
FORCE_HIDE // Force a toolbar to be hidden. For when all elements are disabled at some point in a workbench.
};
ToolBarItem();
explicit ToolBarItem(ToolBarItem* item, HideStyle forceHide = HideStyle::VISIBLE);
~ToolBarItem();
void setCommand(const std::string&);
const std::string &command() const;
bool hasItems() const;
ToolBarItem* findItem(const std::string&);
ToolBarItem* copy() const;
uint count() const;
void appendItem(ToolBarItem* item);
bool insertItem(ToolBarItem*, ToolBarItem* item);
void removeItem(ToolBarItem* item);
void clear();
ToolBarItem& operator << (ToolBarItem* item);
ToolBarItem& operator << (const std::string& command);
QList<ToolBarItem*> getItems() const;
HideStyle forceHide;
private:
std::string _name;
QList<ToolBarItem*> _items;
};
/**
* The ToolBarManager class is responsible for the creation of toolbars and appending them
* to the main window.
* @see ToolBoxManager
* @see MenuManager
* @author Werner Mayer
*/
class GuiExport ToolBarManager
{
public:
/// The one and only instance.
static ToolBarManager* getInstance();
static void destruct();
/** Sets up the toolbars of a given workbench. */
void setup(ToolBarItem*);
void saveState() const;
void restoreState() const;
void retranslate() const;
void setMovable(bool movable) const;
void setToolbarVisibility(bool show, const QList<QString>& names);
void setToolbarVisibility(bool show, const QString& name);
protected:
void setup(ToolBarItem*, QToolBar*) const;
/** Returns a list of all currently existing toolbars. */
QList<QToolBar*> toolBars() const;
QToolBar* findToolBar(const QList<QToolBar*>&, const QString&) const;
QAction* findAction(const QList<QAction*>&, const QString&) const;
ToolBarManager();
~ToolBarManager();
private:
QStringList toolbarNames;
static ToolBarManager* _instance;
};
} // namespace Gui
#endif // GUI_TOOLBARMANAGER_H