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 "abstractformwindow.h" |
30 | #include "inplace_editor.h" |
31 | |
32 | #include <QtDesigner/abstractformwindow.h> |
33 | #include <QtDesigner/abstractformwindowcursor.h> |
34 | #include <QtDesigner/propertysheet.h> |
35 | #include <QtDesigner/abstractformeditor.h> |
36 | #include <QtDesigner/abstractlanguage.h> |
37 | #include <QtDesigner/qextensionmanager.h> |
38 | |
39 | #include <QtCore/qvariant.h> |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | namespace qdesigner_internal { |
44 | |
45 | // ----------------- InPlaceEditor |
46 | |
47 | InPlaceEditor::InPlaceEditor(QWidget *widget, |
48 | TextPropertyValidationMode validationMode, |
49 | QDesignerFormWindowInterface *fw, |
50 | const QString& text, |
51 | const QRect& r) : |
52 | TextPropertyEditor(widget, EmbeddingInPlace, validationMode), |
53 | m_InPlaceWidgetHelper(this, widget, fw) |
54 | { |
55 | setAlignment(m_InPlaceWidgetHelper.alignment()); |
56 | setObjectName(QStringLiteral("__qt__passive_m_editor" )); |
57 | |
58 | setText(text); |
59 | selectAll(); |
60 | |
61 | setGeometry(QRect(widget->mapTo(widget->window(), r.topLeft()), r.size())); |
62 | setFocus(); |
63 | show(); |
64 | |
65 | connect(sender: this, signal: &TextPropertyEditor::editingFinished,receiver: this, slot: &QWidget::close); |
66 | } |
67 | |
68 | |
69 | // -------------- TaskMenuInlineEditor |
70 | |
71 | TaskMenuInlineEditor::(QWidget *w, TextPropertyValidationMode vm, |
72 | const QString &property, QObject *parent) : |
73 | QObject(parent), |
74 | m_vm(vm), |
75 | m_property(property), |
76 | m_widget(w), |
77 | m_managed(true) |
78 | { |
79 | } |
80 | |
81 | void TaskMenuInlineEditor::() |
82 | { |
83 | m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_widget); |
84 | if (m_formWindow.isNull()) |
85 | return; |
86 | m_managed = m_formWindow->isManaged(widget: m_widget); |
87 | // Close as soon as a different widget is selected |
88 | connect(sender: m_formWindow.data(), signal: &QDesignerFormWindowInterface::selectionChanged, |
89 | receiver: this, slot: &TaskMenuInlineEditor::updateSelection); |
90 | |
91 | // get old value |
92 | QDesignerFormEditorInterface *core = m_formWindow->core(); |
93 | const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(manager: core->extensionManager(), object: m_widget); |
94 | const int index = sheet->indexOf(name: m_property); |
95 | if (index == -1) |
96 | return; |
97 | m_value = qvariant_cast<PropertySheetStringValue>(v: sheet->property(index)); |
98 | const QString oldValue = m_value.value(); |
99 | |
100 | m_editor = new InPlaceEditor(m_widget, m_vm, m_formWindow, oldValue, editRectangle()); |
101 | connect(sender: m_editor.data(), signal: &InPlaceEditor::textChanged, receiver: this, slot: &TaskMenuInlineEditor::updateText); |
102 | } |
103 | |
104 | void TaskMenuInlineEditor::(const QString &text) |
105 | { |
106 | // In the [rare] event we are invoked on an unmanaged widget, |
107 | // do not use the cursor selection |
108 | m_value.setValue(text); |
109 | if (m_managed) { |
110 | m_formWindow->cursor()->setProperty(name: m_property, value: QVariant::fromValue(value: m_value)); |
111 | } else { |
112 | m_formWindow->cursor()->setWidgetProperty(widget: m_widget, name: m_property, value: QVariant::fromValue(value: m_value)); |
113 | } |
114 | } |
115 | |
116 | void TaskMenuInlineEditor::() |
117 | { |
118 | if (m_editor) |
119 | m_editor->deleteLater(); |
120 | } |
121 | |
122 | } |
123 | |
124 | QT_END_NAMESPACE |
125 | |