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 "combobox_taskmenu.h" |
30 | #include "listwidgeteditor.h" |
31 | #include "qdesigner_utils_p.h" |
32 | #include <qdesigner_command_p.h> |
33 | |
34 | #include <QtDesigner/abstractformwindow.h> |
35 | |
36 | #include <QtWidgets/qaction.h> |
37 | #include <QtWidgets/qstyle.h> |
38 | #include <QtWidgets/qlineedit.h> |
39 | #include <QtWidgets/qfontcombobox.h> |
40 | #include <QtWidgets/qstyleoption.h> |
41 | |
42 | #include <QtCore/qcoreevent.h> |
43 | #include <QtCore/qvariant.h> |
44 | #include <QtCore/qdebug.h> |
45 | |
46 | QT_BEGIN_NAMESPACE |
47 | |
48 | using namespace qdesigner_internal; |
49 | |
50 | ComboBoxTaskMenu::(QComboBox *button, QObject *parent) |
51 | : QDesignerTaskMenu(button, parent), |
52 | m_comboBox(button) |
53 | { |
54 | m_editItemsAction = new QAction(this); |
55 | m_editItemsAction->setText(tr(s: "Edit Items..." )); |
56 | connect(sender: m_editItemsAction, signal: &QAction::triggered, receiver: this, slot: &ComboBoxTaskMenu::editItems); |
57 | m_taskActions.append(t: m_editItemsAction); |
58 | |
59 | QAction *sep = new QAction(this); |
60 | sep->setSeparator(true); |
61 | m_taskActions.append(t: sep); |
62 | } |
63 | |
64 | ComboBoxTaskMenu::() = default; |
65 | |
66 | QAction *ComboBoxTaskMenu::() const |
67 | { |
68 | return m_editItemsAction; |
69 | } |
70 | |
71 | QList<QAction*> ComboBoxTaskMenu::() const |
72 | { |
73 | return m_taskActions + QDesignerTaskMenu::taskActions(); |
74 | } |
75 | |
76 | void ComboBoxTaskMenu::() |
77 | { |
78 | m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_comboBox); |
79 | if (m_formWindow.isNull()) |
80 | return; |
81 | |
82 | Q_ASSERT(m_comboBox != nullptr); |
83 | |
84 | ListWidgetEditor dlg(m_formWindow, m_comboBox->window()); |
85 | ListContents oldItems = dlg.fillContentsFromComboBox(comboBox: m_comboBox); |
86 | if (dlg.exec() == QDialog::Accepted) { |
87 | ListContents items = dlg.contents(); |
88 | if (items != oldItems) { |
89 | ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow); |
90 | cmd->init(comboBox: m_comboBox, oldItems, items); |
91 | cmd->setText(tr(s: "Change Combobox Contents" )); |
92 | m_formWindow->commandHistory()->push(cmd); |
93 | } |
94 | } |
95 | } |
96 | |
97 | ComboBoxTaskMenuFactory::(const QString &iid, QExtensionManager *extensionManager) : |
98 | ExtensionFactory<QDesignerTaskMenuExtension, QComboBox, ComboBoxTaskMenu>(iid, extensionManager) |
99 | { |
100 | } |
101 | |
102 | QComboBox *ComboBoxTaskMenuFactory::(QObject *qObject) const |
103 | { |
104 | QComboBox *combo = qobject_cast<QComboBox*>(object: qObject); |
105 | if (!combo) |
106 | return nullptr; |
107 | if (qobject_cast<QFontComboBox*>(object: combo)) |
108 | return nullptr; |
109 | return combo; |
110 | } |
111 | |
112 | void ComboBoxTaskMenu::() |
113 | { |
114 | if (m_editor) |
115 | m_editor->deleteLater(); |
116 | } |
117 | |
118 | QT_END_NAMESPACE |
119 | |