diff --git a/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.cpp b/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.cpp new file mode 100644 index 00000000000..669fff04b2b --- /dev/null +++ b/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "abstractactiongroup.h" + +#include + +namespace QmlDesigner { + +AbstractActionGroup::AbstractActionGroup(const QString &displayName) : + m_displayName(displayName), + m_menu(new QMenu) +{ + m_menu->setTitle(displayName); + m_action = m_menu->menuAction(); +} + +AbstractDesignerAction::Type AbstractActionGroup::type() const +{ + return AbstractDesignerAction::Menu; +} + +QAction *AbstractActionGroup::action() const +{ + return m_action; +} + +QMenu *AbstractActionGroup::menu() const +{ + return m_menu.data(); +} + +void AbstractActionGroup::currentContextChanged(const SelectionContext &selectionContext) +{ + m_selectionContext = selectionContext; + updateContext(); +} + +void AbstractActionGroup::updateContext() +{ + if (m_selectionContext.isValid()) { + m_action->setEnabled(isEnabled(m_selectionContext)); + m_action->setVisible(isVisible(m_selectionContext)); + } +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.h b/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.h new file mode 100644 index 00000000000..3e4b9862452 --- /dev/null +++ b/src/plugins/qmldesigner/components/componentcore/abstractactiongroup.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MENUDESIGNERACTION_H +#define MENUDESIGNERACTION_H + +#include "abstractdesigneraction.h" + +#include +#include +#include + +namespace QmlDesigner { + +class QMLDESIGNERCORE_EXPORT AbstractActionGroup : public AbstractDesignerAction +{ +public: + AbstractActionGroup(const QString &displayName); + + virtual bool isVisible(const SelectionContext &m_selectionState) const = 0; + virtual bool isEnabled(const SelectionContext &m_selectionState) const = 0; + AbstractDesignerAction::Type type() const QTC_OVERRIDE; + QAction *action() const QTC_OVERRIDE; + QMenu *menu() const; + + virtual void currentContextChanged(const SelectionContext &selectionContext) QTC_OVERRIDE; + virtual void updateContext(); + +protected: + const QString m_displayName; + SelectionContext m_selectionContext; + QScopedPointer m_menu; + QAction *m_action; +}; + +} // namespace QmlDesigner + +#endif // MENUDESIGNERACTION_H diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore.pri b/src/plugins/qmldesigner/components/componentcore/componentcore.pri index 023f4b7fb11..9e826feec68 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore.pri +++ b/src/plugins/qmldesigner/components/componentcore/componentcore.pri @@ -1,6 +1,7 @@ VPATH += $$PWD SOURCES += modelnodecontextmenu.cpp +SOURCES += abstractactiongroup.cpp SOURCES += designeractionmanagerview.cpp SOURCES += defaultdesigneraction.cpp SOURCES += modelnodecontextmenu_helper.cpp @@ -10,6 +11,7 @@ SOURCES += modelnodeoperations.cpp SOURCES += crumblebar.cpp HEADERS += modelnodecontextmenu.h +HEADERS += abstractactiongroup.h HEADERS += designeractionmanagerview.h HEADERS += defaultdesigneraction.h HEADERS += modelnodecontextmenu_helper.h diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index c9cd12c0a25..f4a8eb57fc6 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -139,11 +139,11 @@ public: } }; -class SelectionModelNodeAction : public MenuDesignerAction +class SelectionModelNodeAction : public ActionGroup { public: SelectionModelNodeAction(const QString &displayName, const QByteArray &menuId, int priority) : - MenuDesignerAction(displayName, menuId, priority, + ActionGroup(displayName, menuId, priority, &SelectionContextFunctors::always, &SelectionContextFunctors::selectionEnabled) {} @@ -321,7 +321,7 @@ void DesignerActionManager::createDefaultDesignerActions() addDesignerAction(new SelectionModelNodeAction(selectionCategoryDisplayName, selectionCategory, prioritySelectionCategory)); - addDesignerAction(new MenuDesignerAction(stackCategoryDisplayName, stackCategory, priorityStackCategory, &selectionNotEmpty)); + addDesignerAction(new ActionGroup(stackCategoryDisplayName, stackCategory, priorityStackCategory, &selectionNotEmpty)); addDesignerAction(new ModelNodeAction (toFrontDisplayName, stackCategory, 200, &toFront, &singleSelection)); addDesignerAction(new ModelNodeAction @@ -334,7 +334,7 @@ void DesignerActionManager::createDefaultDesignerActions() addDesignerAction(new ModelNodeAction (resetZDisplayName, stackCategory, 100, &resetZ, &selectionNotEmptyAndHasZProperty)); - addDesignerAction(new MenuDesignerAction(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty)); + addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty)); addDesignerAction(new ModelNodeAction (resetPositionDisplayName, editCategory, 200, &resetPosition, &selectionNotEmptyAndHasXorYProperty)); addDesignerAction(new ModelNodeAction @@ -342,14 +342,14 @@ void DesignerActionManager::createDefaultDesignerActions() addDesignerAction(new VisiblityModelNodeAction (visibilityDisplayName, editCategory, 160, &setVisible, &singleSelectedItem)); - addDesignerAction(new MenuDesignerAction(anchorsCategoryDisplayName, anchorsCategory, + addDesignerAction(new ActionGroup(anchorsCategoryDisplayName, anchorsCategory, priorityAnchorsCategory, &singleSelectionAndInBaseState)); addDesignerAction(new ModelNodeAction (anchorsFillDisplayName, anchorsCategory, 200, &anchorsFill, &singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot)); addDesignerAction(new ModelNodeAction (anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored)); - addDesignerAction(new MenuDesignerAction(layoutCategoryDisplayName, layoutCategory, + addDesignerAction(new ActionGroup(layoutCategoryDisplayName, layoutCategory, priorityLayoutCategory, &layoutOptionVisible)); addDesignerAction(new ModelNodeAction (layoutRowPositionerDisplayName, diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h index f9821ded616..d2517e9482d 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h @@ -32,6 +32,7 @@ #include "modelnodeoperations.h" #include "defaultdesigneraction.h" +#include "abstractactiongroup.h" #include "qmlitemnode.h" #include @@ -39,7 +40,7 @@ namespace QmlDesigner { -typedef bool (*SelectionContextFunction)(const SelectionContext &); +typedef bool (*SelectionContextFunction)(const SelectionContext &); namespace SelectionContextFunctors { @@ -113,21 +114,18 @@ public /*slots*/: ModelNodeOperations::SelectionAction m_action; }; -class MenuDesignerAction : public AbstractDesignerAction +class ActionGroup : public AbstractActionGroup { public: - MenuDesignerAction(const QString &displayName, const QByteArray &menuId, int priority, + ActionGroup(const QString &displayName, const QByteArray &menuId, int priority, SelectionContextFunction enabled = &SelectionContextFunctors::always, SelectionContextFunction visibility = &SelectionContextFunctors::always) : - m_displayName(displayName), + AbstractActionGroup(displayName), m_menuId(menuId), m_priority(priority), - m_menu(new QMenu), m_enabled(enabled), m_visibility(visibility) { - m_menu->setTitle(displayName); - m_action = m_menu->menuAction(); } bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); } @@ -138,27 +136,9 @@ public: AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; } QAction *action() const { return m_action; } - virtual void currentContextChanged(const SelectionContext &selectionContext) - { - m_selectionContext = selectionContext; - updateContext(); - } - - virtual void updateContext() - { - if (m_selectionContext.isValid()) { - m_action->setEnabled(isEnabled(m_selectionContext)); - m_action->setVisible(isVisible(m_selectionContext)); - } - } - protected: - const QString m_displayName; const QByteArray m_menuId; const int m_priority; - SelectionContext m_selectionContext; - QScopedPointer m_menu; - QAction *m_action; SelectionContextFunction m_enabled; SelectionContextFunction m_visibility; };