1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*
|
---|
43 | TRANSLATOR qdesigner_internal::OrderDialog
|
---|
44 | */
|
---|
45 |
|
---|
46 | #include "orderdialog_p.h"
|
---|
47 | #include "iconloader_p.h"
|
---|
48 | #ifndef QT_NO_DRAGANDDROP
|
---|
49 | # include "ui_orderdialog.h"
|
---|
50 | #else
|
---|
51 | # include "ui_orderdialog_nodnd.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #include <QtDesigner/QExtensionManager>
|
---|
55 | #include <QtDesigner/QDesignerFormEditorInterface>
|
---|
56 | #include <QtDesigner/QDesignerContainerExtension>
|
---|
57 | #include <QtCore/QAbstractItemModel>
|
---|
58 | #include <QtCore/QModelIndex>
|
---|
59 | #include <QtGui/QPushButton>
|
---|
60 |
|
---|
61 | QT_BEGIN_NAMESPACE
|
---|
62 |
|
---|
63 | // OrderDialog: Used to reorder the pages of QStackedWidget and QToolBox.
|
---|
64 | // Provides up and down buttons as well as DnD via QAbstractItemView::InternalMove mode
|
---|
65 | namespace qdesigner_internal {
|
---|
66 |
|
---|
67 | OrderDialog::OrderDialog(QWidget *parent) :
|
---|
68 | QDialog(parent),
|
---|
69 | m_ui(new Ui::OrderDialog),
|
---|
70 | m_format(PageOrderFormat)
|
---|
71 | {
|
---|
72 | m_ui->setupUi(this);
|
---|
73 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
---|
74 | m_ui->upButton->setIcon(createIconSet(QString::fromUtf8("up.png")));
|
---|
75 | m_ui->downButton->setIcon(createIconSet(QString::fromUtf8("down.png")));
|
---|
76 | m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
---|
77 | connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(slotReset()));
|
---|
78 | // Catch the remove operation of a DnD operation in QAbstractItemView::InternalMove mode to enable buttons
|
---|
79 | // Selection mode is 'contiguous' to enable DnD of groups
|
---|
80 | connect(m_ui->pageList->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(slotEnableButtonsAfterDnD()));
|
---|
81 |
|
---|
82 | m_ui->upButton->setEnabled(false);
|
---|
83 | m_ui->downButton->setEnabled(false);
|
---|
84 | }
|
---|
85 |
|
---|
86 | OrderDialog::~OrderDialog()
|
---|
87 | {
|
---|
88 | delete m_ui;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void OrderDialog::setDescription(const QString &d)
|
---|
92 | {
|
---|
93 | m_ui->groupBox->setTitle(d);
|
---|
94 | }
|
---|
95 |
|
---|
96 | void OrderDialog::setPageList(const QWidgetList &pages)
|
---|
97 | {
|
---|
98 | // The QWidget* are stored in a map indexed by the old index.
|
---|
99 | // The old index is set as user data on the item instead of the QWidget*
|
---|
100 | // because DnD is enabled which requires the user data to serializable
|
---|
101 | m_orderMap.clear();
|
---|
102 | const int count = pages.count();
|
---|
103 | for (int i=0; i < count; ++i)
|
---|
104 | m_orderMap.insert(i, pages.at(i));
|
---|
105 | buildList();
|
---|
106 | }
|
---|
107 |
|
---|
108 | void OrderDialog::buildList()
|
---|
109 | {
|
---|
110 | m_ui->pageList->clear();
|
---|
111 | const OrderMap::const_iterator cend = m_orderMap.constEnd();
|
---|
112 | for (OrderMap::const_iterator it = m_orderMap.constBegin(); it != cend; ++it) {
|
---|
113 | QListWidgetItem *item = new QListWidgetItem();
|
---|
114 | const int index = it.key();
|
---|
115 | switch (m_format) {
|
---|
116 | case PageOrderFormat:
|
---|
117 | item->setText(tr("Index %1 (%2)").arg(index).arg(it.value()->objectName()));
|
---|
118 | break;
|
---|
119 | case TabOrderFormat:
|
---|
120 | item->setText(tr("%1 %2").arg(index+1).arg(it.value()->objectName()));
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | item->setData(Qt::UserRole, QVariant(index));
|
---|
124 | m_ui->pageList->addItem(item);
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (m_ui->pageList->count() > 0)
|
---|
128 | m_ui->pageList->setCurrentRow(0);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void OrderDialog::slotReset()
|
---|
132 | {
|
---|
133 | buildList();
|
---|
134 | }
|
---|
135 |
|
---|
136 | QWidgetList OrderDialog::pageList() const
|
---|
137 | {
|
---|
138 | QWidgetList rc;
|
---|
139 | const int count = m_ui->pageList->count();
|
---|
140 | for (int i=0; i < count; ++i) {
|
---|
141 | const int oldIndex = m_ui->pageList->item(i)->data(Qt::UserRole).toInt();
|
---|
142 | rc.append(m_orderMap.value(oldIndex));
|
---|
143 | }
|
---|
144 | return rc;
|
---|
145 | }
|
---|
146 |
|
---|
147 | void OrderDialog::on_upButton_clicked()
|
---|
148 | {
|
---|
149 | const int row = m_ui->pageList->currentRow();
|
---|
150 | if (row <= 0)
|
---|
151 | return;
|
---|
152 |
|
---|
153 | m_ui->pageList->insertItem(row - 1, m_ui->pageList->takeItem(row));
|
---|
154 | m_ui->pageList->setCurrentRow(row - 1);
|
---|
155 | }
|
---|
156 |
|
---|
157 | void OrderDialog::on_downButton_clicked()
|
---|
158 | {
|
---|
159 | const int row = m_ui->pageList->currentRow();
|
---|
160 | if (row == -1 || row == m_ui->pageList->count() - 1)
|
---|
161 | return;
|
---|
162 |
|
---|
163 | m_ui->pageList->insertItem(row + 1, m_ui->pageList->takeItem(row));
|
---|
164 | m_ui->pageList->setCurrentRow(row + 1);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void OrderDialog::slotEnableButtonsAfterDnD()
|
---|
168 | {
|
---|
169 | enableButtons(m_ui->pageList->currentRow());
|
---|
170 | }
|
---|
171 |
|
---|
172 | void OrderDialog::on_pageList_currentRowChanged(int r)
|
---|
173 | {
|
---|
174 | enableButtons(r);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void OrderDialog::enableButtons(int r)
|
---|
178 | {
|
---|
179 | m_ui->upButton->setEnabled(r > 0);
|
---|
180 | m_ui->downButton->setEnabled(r >= 0 && r < m_ui->pageList->count() - 1);
|
---|
181 | }
|
---|
182 |
|
---|
183 | QWidgetList OrderDialog::pagesOfContainer(const QDesignerFormEditorInterface *core, QWidget *container)
|
---|
184 | {
|
---|
185 | QWidgetList rc;
|
---|
186 | if (QDesignerContainerExtension* ce = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), container)) {
|
---|
187 | const int count = ce->count();
|
---|
188 | for (int i = 0; i < count ;i ++)
|
---|
189 | rc.push_back(ce->widget(i));
|
---|
190 | }
|
---|
191 | return rc;
|
---|
192 | }
|
---|
193 |
|
---|
194 | }
|
---|
195 |
|
---|
196 | QT_END_NAMESPACE
|
---|