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 "signalsloteditor_tool.h"
30 #include "signalsloteditor.h"
31 
32 #include <QtDesigner/private/ui4_p.h>
33 #include <QtDesigner/abstractformwindow.h>
34 
35 #include <QtWidgets/qaction.h>
36 #include <QtCore/qdebug.h>
37 
38 QT_BEGIN_NAMESPACE
39 
40 using namespace qdesigner_internal;
41 
SignalSlotEditorTool(QDesignerFormWindowInterface * formWindow,QObject * parent)42 SignalSlotEditorTool::SignalSlotEditorTool(QDesignerFormWindowInterface *formWindow, QObject *parent)
43     : QDesignerFormWindowToolInterface(parent),
44       m_formWindow(formWindow),
45       m_action(new QAction(tr("Edit Signals/Slots"), this))
46 {
47 }
48 
49 SignalSlotEditorTool::~SignalSlotEditorTool() = default;
50 
core() const51 QDesignerFormEditorInterface *SignalSlotEditorTool::core() const
52 {
53     return m_formWindow->core();
54 }
55 
formWindow() const56 QDesignerFormWindowInterface *SignalSlotEditorTool::formWindow() const
57 {
58     return m_formWindow;
59 }
60 
handleEvent(QWidget * widget,QWidget * managedWidget,QEvent * event)61 bool SignalSlotEditorTool::handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event)
62 {
63     Q_UNUSED(widget);
64     Q_UNUSED(managedWidget);
65     Q_UNUSED(event);
66 
67     return false;
68 }
69 
editor() const70 QWidget *SignalSlotEditorTool::editor() const
71 {
72     if (!m_editor) {
73         Q_ASSERT(formWindow() != nullptr);
74         m_editor = new qdesigner_internal::SignalSlotEditor(formWindow(), nullptr);
75         connect(formWindow(), &QDesignerFormWindowInterface::mainContainerChanged,
76                 m_editor.data(), &SignalSlotEditor::setBackground);
77         connect(formWindow(), &QDesignerFormWindowInterface::changed,
78                 m_editor.data(), &SignalSlotEditor::updateBackground);
79     }
80 
81     return m_editor;
82 }
83 
action() const84 QAction *SignalSlotEditorTool::action() const
85 {
86     return m_action;
87 }
88 
activated()89 void SignalSlotEditorTool::activated()
90 {
91     m_editor->enableUpdateBackground(true);
92 }
93 
deactivated()94 void SignalSlotEditorTool::deactivated()
95 {
96     m_editor->enableUpdateBackground(false);
97 }
98 
saveToDom(DomUI * ui,QWidget *)99 void SignalSlotEditorTool::saveToDom(DomUI *ui, QWidget*)
100 {
101     ui->setElementConnections(m_editor->toUi());
102 }
103 
loadFromDom(DomUI * ui,QWidget * mainContainer)104 void SignalSlotEditorTool::loadFromDom(DomUI *ui, QWidget *mainContainer)
105 {
106     m_editor->fromUi(ui->elementConnections(), mainContainer);
107 }
108 
109 QT_END_NAMESPACE
110