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