1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtWidgets/qaction.h>
30
31#include "tabordereditor_plugin.h"
32#include "tabordereditor_tool.h"
33
34#include <QtDesigner/abstractformeditor.h>
35#include <QtDesigner/abstractformwindow.h>
36#include <QtDesigner/abstractformwindowmanager.h>
37
38QT_BEGIN_NAMESPACE
39
40using namespace qdesigner_internal;
41
42TabOrderEditorPlugin::TabOrderEditorPlugin() = default;
43
44TabOrderEditorPlugin::~TabOrderEditorPlugin() = default;
45
46bool TabOrderEditorPlugin::isInitialized() const
47{
48 return m_initialized;
49}
50
51void TabOrderEditorPlugin::initialize(QDesignerFormEditorInterface *core)
52{
53 Q_ASSERT(!isInitialized());
54
55 m_action = new QAction(tr(s: "Edit Tab Order"), this);
56 m_action->setObjectName(QStringLiteral("_qt_edit_tab_order_action"));
57 QIcon icon = QIcon::fromTheme(QStringLiteral("designer-edit-tabs"),
58 fallback: QIcon(core->resourceLocation() + QStringLiteral("/tabordertool.png")));
59 m_action->setIcon(icon);
60 m_action->setEnabled(false);
61
62 setParent(core);
63 m_core = core;
64 m_initialized = true;
65
66 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::formWindowAdded,
67 receiver: this, slot: &TabOrderEditorPlugin::addFormWindow);
68
69 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::formWindowRemoved,
70 receiver: this, slot: &TabOrderEditorPlugin::removeFormWindow);
71
72 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
73 receiver: this, slot: &TabOrderEditorPlugin::activeFormWindowChanged);
74}
75
76void TabOrderEditorPlugin::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
77{
78 m_action->setEnabled(formWindow != nullptr);
79}
80
81QDesignerFormEditorInterface *TabOrderEditorPlugin::core() const
82{
83 return m_core;
84}
85
86void TabOrderEditorPlugin::addFormWindow(QDesignerFormWindowInterface *formWindow)
87{
88 Q_ASSERT(formWindow != nullptr);
89 Q_ASSERT(m_tools.contains(formWindow) == false);
90
91 TabOrderEditorTool *tool = new TabOrderEditorTool(formWindow, this);
92 m_tools[formWindow] = tool;
93 connect(sender: m_action, signal: &QAction::triggered, receiver: tool->action(), slot: &QAction::trigger);
94 formWindow->registerTool(tool);
95}
96
97void TabOrderEditorPlugin::removeFormWindow(QDesignerFormWindowInterface *formWindow)
98{
99 Q_ASSERT(formWindow != nullptr);
100 Q_ASSERT(m_tools.contains(formWindow) == true);
101
102 TabOrderEditorTool *tool = m_tools.value(akey: formWindow);
103 m_tools.remove(akey: formWindow);
104 disconnect(sender: m_action, signal: &QAction::triggered, receiver: tool->action(), slot: &QAction::trigger);
105 // ### FIXME disable the tool
106
107 delete tool;
108}
109
110QAction *TabOrderEditorPlugin::action() const
111{
112 return m_action;
113}
114
115QT_END_NAMESPACE
116

source code of qttools/src/designer/src/components/tabordereditor/tabordereditor_plugin.cpp