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 "listwidget_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/qstyleoption.h> |
40 | |
41 | #include <QtCore/qcoreevent.h> |
42 | #include <QtCore/qvariant.h> |
43 | #include <QtCore/qdebug.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | using namespace qdesigner_internal; |
48 | |
49 | ListWidgetTaskMenu::(QListWidget *button, QObject *parent) |
50 | : QDesignerTaskMenu(button, parent), |
51 | m_listWidget(button) |
52 | { |
53 | m_editItemsAction = new QAction(this); |
54 | m_editItemsAction->setText(tr(s: "Edit Items..." )); |
55 | connect(sender: m_editItemsAction, signal: &QAction::triggered, receiver: this, slot: &ListWidgetTaskMenu::editItems); |
56 | m_taskActions.append(t: m_editItemsAction); |
57 | |
58 | QAction *sep = new QAction(this); |
59 | sep->setSeparator(true); |
60 | m_taskActions.append(t: sep); |
61 | } |
62 | |
63 | ListWidgetTaskMenu::() = default; |
64 | |
65 | QAction *ListWidgetTaskMenu::() const |
66 | { |
67 | return m_editItemsAction; |
68 | } |
69 | |
70 | QList<QAction*> ListWidgetTaskMenu::() const |
71 | { |
72 | return m_taskActions + QDesignerTaskMenu::taskActions(); |
73 | } |
74 | |
75 | void ListWidgetTaskMenu::() |
76 | { |
77 | m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_listWidget); |
78 | if (m_formWindow.isNull()) |
79 | return; |
80 | |
81 | Q_ASSERT(m_listWidget != nullptr); |
82 | |
83 | ListWidgetEditor dlg(m_formWindow, m_listWidget->window()); |
84 | ListContents oldItems = dlg.fillContentsFromListWidget(listWidget: m_listWidget); |
85 | if (dlg.exec() == QDialog::Accepted) { |
86 | ListContents items = dlg.contents(); |
87 | if (items != oldItems) { |
88 | ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow); |
89 | cmd->init(listWidget: m_listWidget, oldItems, items); |
90 | cmd->setText(tr(s: "Change List Contents" )); |
91 | m_formWindow->commandHistory()->push(cmd); |
92 | } |
93 | } |
94 | } |
95 | |
96 | void ListWidgetTaskMenu::() |
97 | { |
98 | if (m_editor) |
99 | m_editor->deleteLater(); |
100 | } |
101 | |
102 | QT_END_NAMESPACE |
103 | |