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 "listwidgeteditor.h" |
30 | #include <designerpropertymanager.h> |
31 | #include <abstractformbuilder.h> |
32 | |
33 | #include <QtDesigner/abstractsettings.h> |
34 | #include <QtDesigner/abstractformeditor.h> |
35 | |
36 | #include <QtWidgets/qcombobox.h> |
37 | #include <QtWidgets/qgroupbox.h> |
38 | #include <QtWidgets/qdialogbuttonbox.h> |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | using namespace qdesigner_internal; |
43 | |
44 | ListWidgetEditor::ListWidgetEditor(QDesignerFormWindowInterface *form, |
45 | QWidget *parent) |
46 | : QDialog(parent) |
47 | { |
48 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
49 | QDialogButtonBox *buttonBox = new QDialogButtonBox; |
50 | buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); |
51 | connect(sender: buttonBox, signal: &QDialogButtonBox::accepted, receiver: this, slot: &QDialog::accept); |
52 | connect(sender: buttonBox, signal: &QDialogButtonBox::rejected, receiver: this, slot: &QDialog::reject); |
53 | |
54 | m_itemsEditor = new ItemListEditor(form, nullptr); |
55 | m_itemsEditor->layout()->setContentsMargins(QMargins()); |
56 | m_itemsEditor->setNewItemText(tr(s: "New Item" )); |
57 | |
58 | QFrame *sep = new QFrame; |
59 | sep->setFrameStyle(QFrame::HLine | QFrame::Sunken); |
60 | |
61 | QBoxLayout *box = new QVBoxLayout(this); |
62 | box->addWidget(m_itemsEditor); |
63 | box->addWidget(sep); |
64 | box->addWidget(buttonBox); |
65 | |
66 | // Numbers copied from itemlisteditor.ui |
67 | // (Automatic resizing doesn't work because ui has parent). |
68 | resize(w: 550, h: 360); |
69 | } |
70 | |
71 | static AbstractItemEditor::PropertyDefinition listBoxPropList[] = { |
72 | { .role: Qt::DisplayPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerStringTypeId, .name: "text" }, |
73 | { .role: Qt::DecorationPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerIconTypeId, .name: "icon" }, |
74 | { .role: Qt::ToolTipPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerStringTypeId, .name: "toolTip" }, |
75 | { .role: Qt::StatusTipPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerStringTypeId, .name: "statusTip" }, |
76 | { .role: Qt::WhatsThisPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerStringTypeId, .name: "whatsThis" }, |
77 | { .role: Qt::FontRole, .type: QVariant::Font, .typeFunc: nullptr, .name: "font" }, |
78 | { .role: Qt::TextAlignmentRole, .type: 0, .typeFunc: DesignerPropertyManager::designerAlignmentTypeId, .name: "textAlignment" }, |
79 | { .role: Qt::BackgroundRole, .type: QVariant::Brush, .typeFunc: nullptr, .name: "background" }, |
80 | { .role: Qt::ForegroundRole, .type: QVariant::Brush, .typeFunc: nullptr, .name: "foreground" }, |
81 | { .role: ItemFlagsShadowRole, .type: 0, .typeFunc: QtVariantPropertyManager::flagTypeId, .name: "flags" }, |
82 | { .role: Qt::CheckStateRole, .type: 0, .typeFunc: QtVariantPropertyManager::enumTypeId, .name: "checkState" }, |
83 | { .role: 0, .type: 0, .typeFunc: nullptr, .name: nullptr } |
84 | }; |
85 | |
86 | ListContents ListWidgetEditor::fillContentsFromListWidget(QListWidget *listWidget) |
87 | { |
88 | setWindowTitle(tr(s: "Edit List Widget" )); |
89 | |
90 | ListContents retVal; |
91 | retVal.createFromListWidget(listWidget, editor: false); |
92 | retVal.applyToListWidget(listWidget: m_itemsEditor->listWidget(), iconCache: m_itemsEditor->iconCache(), editor: true); |
93 | |
94 | m_itemsEditor->setupEditor(object: listWidget, propDefs: listBoxPropList); |
95 | |
96 | return retVal; |
97 | } |
98 | |
99 | static AbstractItemEditor::PropertyDefinition comboBoxPropList[] = { |
100 | { .role: Qt::DisplayPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerStringTypeId, .name: "text" }, |
101 | { .role: Qt::DecorationPropertyRole, .type: 0, .typeFunc: DesignerPropertyManager::designerIconTypeId, .name: "icon" }, |
102 | { .role: 0, .type: 0, .typeFunc: nullptr, .name: nullptr } |
103 | }; |
104 | |
105 | ListContents ListWidgetEditor::fillContentsFromComboBox(QComboBox *comboBox) |
106 | { |
107 | setWindowTitle(tr(s: "Edit Combobox" )); |
108 | |
109 | ListContents retVal; |
110 | retVal.createFromComboBox(listWidget: comboBox); |
111 | retVal.applyToListWidget(listWidget: m_itemsEditor->listWidget(), iconCache: m_itemsEditor->iconCache(), editor: true); |
112 | |
113 | m_itemsEditor->setupEditor(object: comboBox, propDefs: comboBoxPropList); |
114 | |
115 | return retVal; |
116 | } |
117 | |
118 | ListContents ListWidgetEditor::contents() const |
119 | { |
120 | ListContents retVal; |
121 | retVal.createFromListWidget(listWidget: m_itemsEditor->listWidget(), editor: true); |
122 | return retVal; |
123 | } |
124 | |
125 | QT_END_NAMESPACE |
126 | |