author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 "actionrepository_p.h" |
|
43 |
#include "qtresourceview_p.h" |
|
44 |
#include "iconloader_p.h" |
|
45 |
#include "qdesigner_utils_p.h" |
|
46 |
||
47 |
#include <QtDesigner/QDesignerFormEditorInterface> |
|
48 |
#include <QtDesigner/QDesignerPropertySheetExtension> |
|
49 |
#include <QtDesigner/QExtensionManager> |
|
50 |
||
51 |
#include <QtGui/QDrag> |
|
52 |
#include <QtGui/QContextMenuEvent> |
|
53 |
#include <QtGui/QStandardItemModel> |
|
54 |
#include <QtGui/QToolButton> |
|
55 |
#include <QtGui/QPixmap> |
|
56 |
#include <QtGui/QAction> |
|
57 |
#include <QtGui/QHeaderView> |
|
58 |
#include <QtGui/QToolBar> |
|
59 |
#include <QtGui/QMenu> |
|
60 |
#include <QtGui/qevent.h> |
|
61 |
#include <QtCore/QSet> |
|
62 |
#include <QtCore/QDebug> |
|
63 |
||
64 |
Q_DECLARE_METATYPE(QAction*) |
|
65 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
namespace { |
|
69 |
enum { listModeIconSize = 16, iconModeIconSize = 24 }; |
|
70 |
} |
|
71 |
||
72 |
static const char *actionMimeType = "action-repository/actions"; |
|
73 |
static const char *plainTextMimeType = "text/plain"; |
|
74 |
||
75 |
static inline QAction *actionOfItem(const QStandardItem* item) |
|
76 |
{ |
|
77 |
return qvariant_cast<QAction*>(item->data(qdesigner_internal::ActionModel::ActionRole)); |
|
78 |
} |
|
79 |
||
80 |
namespace qdesigner_internal { |
|
81 |
||
82 |
// ----------- ActionModel |
|
83 |
ActionModel::ActionModel(QWidget *parent ) : |
|
84 |
QStandardItemModel(parent), |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
85 |
m_emptyIcon(emptyIcon()), |
0 | 86 |
m_core(0) |
87 |
{ |
|
88 |
QStringList headers; |
|
89 |
headers += tr("Name"); |
|
90 |
headers += tr("Used"); |
|
91 |
headers += tr("Text"); |
|
92 |
headers += tr("Shortcut"); |
|
93 |
headers += tr("Checkable"); |
|
94 |
headers += tr("ToolTip"); |
|
95 |
Q_ASSERT(NumColumns == headers.size()); |
|
96 |
setHorizontalHeaderLabels(headers); |
|
97 |
} |
|
98 |
||
99 |
void ActionModel::clearActions() |
|
100 |
{ |
|
101 |
removeRows(0, rowCount()); |
|
102 |
} |
|
103 |
||
104 |
int ActionModel::findAction(QAction *action) const |
|
105 |
{ |
|
106 |
const int rows = rowCount(); |
|
107 |
for (int i = 0; i < rows; i++) |
|
108 |
if (action == actionOfItem(item(i))) |
|
109 |
return i; |
|
110 |
return -1; |
|
111 |
} |
|
112 |
||
113 |
void ActionModel::update(int row) |
|
114 |
{ |
|
115 |
Q_ASSERT(m_core); |
|
116 |
// need to create the row list ... grrr.. |
|
117 |
if (row >= rowCount()) |
|
118 |
return; |
|
119 |
||
120 |
QStandardItemList list; |
|
121 |
for (int i = 0; i < NumColumns; i++) |
|
122 |
list += item(row, i); |
|
123 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
124 |
setItems(m_core, actionOfItem(list.front()), m_emptyIcon, list); |
0 | 125 |
} |
126 |
||
127 |
void ActionModel::remove(int row) |
|
128 |
{ |
|
129 |
qDeleteAll(takeRow(row)); |
|
130 |
} |
|
131 |
||
132 |
QModelIndex ActionModel::addAction(QAction *action) |
|
133 |
{ |
|
134 |
Q_ASSERT(m_core); |
|
135 |
QStandardItemList items; |
|
136 |
const Qt::ItemFlags flags = Qt::ItemIsSelectable|Qt::ItemIsDropEnabled|Qt::ItemIsDragEnabled|Qt::ItemIsEnabled; |
|
137 |
||
138 |
QVariant itemData; |
|
139 |
qVariantSetValue(itemData, action); |
|
140 |
||
141 |
for (int i = 0; i < NumColumns; i++) { |
|
142 |
QStandardItem *item = new QStandardItem; |
|
143 |
item->setData(itemData, ActionRole); |
|
144 |
item->setFlags(flags); |
|
145 |
items.push_back(item); |
|
146 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
147 |
setItems(m_core, action, m_emptyIcon, items); |
0 | 148 |
appendRow(items); |
149 |
return indexFromItem(items.front()); |
|
150 |
} |
|
151 |
||
152 |
// Find the associated menus and toolbars, ignore toolbuttons |
|
153 |
QWidgetList ActionModel::associatedWidgets(const QAction *action) |
|
154 |
{ |
|
155 |
QWidgetList rc = action->associatedWidgets(); |
|
156 |
for (QWidgetList::iterator it = rc.begin(); it != rc.end(); ) |
|
157 |
if (qobject_cast<const QMenu *>(*it) || qobject_cast<const QToolBar *>(*it)) { |
|
158 |
++it; |
|
159 |
} else { |
|
160 |
it = rc.erase(it); |
|
161 |
} |
|
162 |
return rc; |
|
163 |
} |
|
164 |
||
165 |
// shortcut is a fake property, need to retrieve it via property sheet. |
|
166 |
PropertySheetKeySequenceValue ActionModel::actionShortCut(QDesignerFormEditorInterface *core, QAction *action) |
|
167 |
{ |
|
168 |
QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), action); |
|
169 |
if (!sheet) |
|
170 |
return PropertySheetKeySequenceValue(); |
|
171 |
return actionShortCut(sheet); |
|
172 |
} |
|
173 |
||
174 |
PropertySheetKeySequenceValue ActionModel::actionShortCut(const QDesignerPropertySheetExtension *sheet) |
|
175 |
{ |
|
176 |
const int index = sheet->indexOf(QLatin1String("shortcut")); |
|
177 |
if (index == -1) |
|
178 |
return PropertySheetKeySequenceValue(); |
|
179 |
return qvariant_cast<PropertySheetKeySequenceValue>(sheet->property(index)); |
|
180 |
} |
|
181 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
182 |
void ActionModel::setItems(QDesignerFormEditorInterface *core, QAction *action, |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
183 |
const QIcon &defaultIcon, |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
184 |
QStandardItemList &sl) |
0 | 185 |
{ |
186 |
||
187 |
// Tooltip, mostly for icon view mode |
|
188 |
QString firstTooltip = action->objectName(); |
|
189 |
const QString text = action->text(); |
|
190 |
if (!text.isEmpty()) { |
|
191 |
firstTooltip += QLatin1Char('\n'); |
|
192 |
firstTooltip += text; |
|
193 |
} |
|
194 |
||
195 |
Q_ASSERT(sl.size() == NumColumns); |
|
196 |
||
197 |
QStandardItem *item = sl[NameColumn]; |
|
198 |
item->setText(action->objectName()); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
199 |
QIcon icon = action->icon(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
200 |
if (icon.isNull()) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
201 |
icon = defaultIcon; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
202 |
item->setIcon(icon); |
0 | 203 |
item->setToolTip(firstTooltip); |
204 |
item->setWhatsThis(firstTooltip); |
|
205 |
// Used |
|
206 |
const QWidgetList associatedDesignerWidgets = associatedWidgets(action); |
|
207 |
const bool used = !associatedDesignerWidgets.empty(); |
|
208 |
item = sl[UsedColumn]; |
|
209 |
item->setCheckState(used ? Qt::Checked : Qt::Unchecked); |
|
210 |
if (used) { |
|
211 |
QString usedToolTip; |
|
212 |
const QString separator = QLatin1String(", "); |
|
213 |
const int count = associatedDesignerWidgets.size(); |
|
214 |
for (int i = 0; i < count; i++) { |
|
215 |
if (i) |
|
216 |
usedToolTip += separator; |
|
217 |
usedToolTip += associatedDesignerWidgets.at(i)->objectName(); |
|
218 |
} |
|
219 |
item->setToolTip(usedToolTip); |
|
220 |
} else { |
|
221 |
item->setToolTip(QString()); |
|
222 |
} |
|
223 |
// text |
|
224 |
item = sl[TextColumn]; |
|
225 |
item->setText(action->text()); |
|
226 |
item->setToolTip(action->text()); |
|
227 |
// shortcut |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
const QString shortcut = actionShortCut(core, action).value().toString(QKeySequence::NativeText); |
0 | 229 |
item = sl[ShortCutColumn]; |
230 |
item->setText(shortcut); |
|
231 |
item->setToolTip(shortcut); |
|
232 |
// checkable |
|
233 |
sl[CheckedColumn]->setCheckState(action->isCheckable() ? Qt::Checked : Qt::Unchecked); |
|
234 |
// ToolTip. This might be multi-line, rich text |
|
235 |
QString toolTip = action->toolTip(); |
|
236 |
item = sl[ToolTipColumn]; |
|
237 |
item->setToolTip(toolTip); |
|
238 |
item->setText(toolTip.replace(QLatin1Char('\n'), QLatin1Char(' '))); |
|
239 |
} |
|
240 |
||
241 |
QMimeData *ActionModel::mimeData(const QModelIndexList &indexes ) const |
|
242 |
{ |
|
243 |
ActionRepositoryMimeData::ActionList actionList; |
|
244 |
||
245 |
QSet<QAction*> actions; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
246 |
foreach (const QModelIndex &index, indexes) |
0 | 247 |
if (QStandardItem *item = itemFromIndex(index)) |
248 |
if (QAction *action = actionOfItem(item)) |
|
249 |
actions.insert(action); |
|
250 |
return new ActionRepositoryMimeData(actions.toList(), Qt::CopyAction); |
|
251 |
} |
|
252 |
||
253 |
// Resource images are plain text. The drag needs to be restricted, however. |
|
254 |
QStringList ActionModel::mimeTypes() const |
|
255 |
{ |
|
256 |
return QStringList(QLatin1String(plainTextMimeType)); |
|
257 |
} |
|
258 |
||
259 |
QString ActionModel::actionName(int row) const |
|
260 |
{ |
|
261 |
return item(row, NameColumn)->text(); |
|
262 |
} |
|
263 |
||
264 |
bool ActionModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &) |
|
265 |
{ |
|
266 |
if (action != Qt::CopyAction) |
|
267 |
return false; |
|
268 |
||
269 |
QStandardItem *droppedItem = item(row, column); |
|
270 |
if (!droppedItem) |
|
271 |
return false; |
|
272 |
||
273 |
||
274 |
QtResourceView::ResourceType type; |
|
275 |
QString path; |
|
276 |
if (!QtResourceView::decodeMimeData(data, &type, &path) || type != QtResourceView::ResourceImage) |
|
277 |
return false; |
|
278 |
||
279 |
emit resourceImageDropped(path, actionOfItem(droppedItem)); |
|
280 |
return true; |
|
281 |
} |
|
282 |
||
283 |
QAction *ActionModel::actionAt(const QModelIndex &index) const |
|
284 |
{ |
|
285 |
if (!index.isValid()) |
|
286 |
return 0; |
|
287 |
QStandardItem *i = itemFromIndex(index); |
|
288 |
if (!i) |
|
289 |
return 0; |
|
290 |
return actionOfItem(i); |
|
291 |
} |
|
292 |
||
293 |
// helpers |
|
294 |
||
295 |
static bool handleImageDragEnterMoveEvent(QDropEvent *event) |
|
296 |
{ |
|
297 |
QtResourceView::ResourceType type; |
|
298 |
const bool rc = QtResourceView::decodeMimeData(event->mimeData(), &type) && type == QtResourceView::ResourceImage; |
|
299 |
if (rc) |
|
300 |
event->acceptProposedAction(); |
|
301 |
else |
|
302 |
event->ignore(); |
|
303 |
return rc; |
|
304 |
} |
|
305 |
||
306 |
static void handleImageDropEvent(const QAbstractItemView *iv, QDropEvent *event, ActionModel *am) |
|
307 |
{ |
|
308 |
const QModelIndex index = iv->indexAt(event->pos()); |
|
309 |
if (!index.isValid()) { |
|
310 |
event->ignore(); |
|
311 |
return; |
|
312 |
} |
|
313 |
||
314 |
if (!handleImageDragEnterMoveEvent(event)) |
|
315 |
return; |
|
316 |
||
317 |
am->dropMimeData(event->mimeData(), event->proposedAction(), index.row(), 0, iv->rootIndex()); |
|
318 |
} |
|
319 |
||
320 |
// Basically mimic QAbstractItemView's startDrag routine, except that |
|
321 |
// another pixmap is used, we don't want the whole row. |
|
322 |
||
323 |
void startActionDrag(QWidget *dragParent, ActionModel *model, const QModelIndexList &indexes, Qt::DropActions supportedActions) |
|
324 |
{ |
|
325 |
if (indexes.empty()) |
|
326 |
return; |
|
327 |
||
328 |
QDrag *drag = new QDrag(dragParent); |
|
329 |
QMimeData *data = model->mimeData(indexes); |
|
330 |
drag->setMimeData(data); |
|
331 |
if (ActionRepositoryMimeData *actionMimeData = qobject_cast<ActionRepositoryMimeData *>(data)) |
|
332 |
drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap(actionMimeData->actionList().front())); |
|
333 |
||
334 |
drag->start(supportedActions); |
|
335 |
} |
|
336 |
||
337 |
// ---------------- ActionTreeView: |
|
338 |
ActionTreeView::ActionTreeView(ActionModel *model, QWidget *parent) : |
|
339 |
QTreeView(parent), |
|
340 |
m_model(model) |
|
341 |
{ |
|
342 |
setDragEnabled(true); |
|
343 |
setAcceptDrops(true); |
|
344 |
setDropIndicatorShown(true); |
|
345 |
setDragDropMode(DragDrop); |
|
346 |
setModel(model); |
|
347 |
setRootIsDecorated(false); |
|
348 |
setTextElideMode(Qt::ElideMiddle); |
|
349 |
||
350 |
setModel(model); |
|
351 |
connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(slotActivated(QModelIndex))); |
|
352 |
connect(header(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(resizeColumnToContents(int))); |
|
353 |
||
354 |
setIconSize(QSize(listModeIconSize, listModeIconSize)); |
|
355 |
||
356 |
} |
|
357 |
||
358 |
QAction *ActionTreeView::currentAction() const |
|
359 |
{ |
|
360 |
return m_model->actionAt(currentIndex()); |
|
361 |
} |
|
362 |
||
363 |
void ActionTreeView::filter(const QString &text) |
|
364 |
{ |
|
365 |
const int rowCount = m_model->rowCount(); |
|
366 |
const bool empty = text.isEmpty(); |
|
367 |
const QModelIndex parent = rootIndex(); |
|
368 |
for (int i = 0; i < rowCount; i++) |
|
369 |
setRowHidden(i, parent, !empty && !m_model->actionName(i).contains(text, Qt::CaseInsensitive)); |
|
370 |
} |
|
371 |
||
372 |
void ActionTreeView::dragEnterEvent(QDragEnterEvent *event) |
|
373 |
{ |
|
374 |
handleImageDragEnterMoveEvent(event); |
|
375 |
} |
|
376 |
||
377 |
void ActionTreeView::dragMoveEvent(QDragMoveEvent *event) |
|
378 |
{ |
|
379 |
handleImageDragEnterMoveEvent(event); |
|
380 |
} |
|
381 |
||
382 |
void ActionTreeView::dropEvent(QDropEvent *event) |
|
383 |
{ |
|
384 |
handleImageDropEvent(this, event, m_model); |
|
385 |
} |
|
386 |
||
387 |
void ActionTreeView::focusInEvent(QFocusEvent *event) |
|
388 |
{ |
|
389 |
QTreeView::focusInEvent(event); |
|
390 |
// Make property editor display current action |
|
391 |
if (QAction *a = currentAction()) |
|
392 |
emit currentChanged(a); |
|
393 |
} |
|
394 |
||
395 |
void ActionTreeView::contextMenuEvent(QContextMenuEvent *event) |
|
396 |
{ |
|
397 |
emit contextMenuRequested(event, m_model->actionAt(indexAt(event->pos()))); |
|
398 |
} |
|
399 |
||
400 |
void ActionTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &/*previous*/) |
|
401 |
{ |
|
402 |
emit currentChanged(m_model->actionAt(current)); |
|
403 |
} |
|
404 |
||
405 |
void ActionTreeView::slotActivated(const QModelIndex &index) |
|
406 |
{ |
|
407 |
emit activated(m_model->actionAt(index)); |
|
408 |
} |
|
409 |
||
410 |
void ActionTreeView::startDrag(Qt::DropActions supportedActions) |
|
411 |
{ |
|
412 |
startActionDrag(this, m_model, selectedIndexes(), supportedActions); |
|
413 |
} |
|
414 |
||
415 |
// ---------------- ActionListView: |
|
416 |
ActionListView::ActionListView(ActionModel *model, QWidget *parent) : |
|
417 |
QListView(parent), |
|
418 |
m_model(model) |
|
419 |
{ |
|
420 |
setDragEnabled(true); |
|
421 |
setAcceptDrops(true); |
|
422 |
setDropIndicatorShown(true); |
|
423 |
setDragDropMode(DragDrop); |
|
424 |
setModel(model); |
|
425 |
setTextElideMode(Qt::ElideMiddle); |
|
426 |
connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(slotActivated(QModelIndex))); |
|
427 |
||
428 |
// We actually want 'Static' as the user should be able to |
|
429 |
// drag away actions only (not to rearrange icons). |
|
430 |
// We emulate that by not accepting our own |
|
431 |
// drag data. 'Static' causes the list view to disable drag and drop |
|
432 |
// on the viewport. |
|
433 |
setMovement(Snap); |
|
434 |
setViewMode(IconMode); |
|
435 |
setIconSize(QSize(iconModeIconSize, iconModeIconSize)); |
|
436 |
setGridSize(QSize(4 * iconModeIconSize, 2 * iconModeIconSize)); |
|
437 |
setSpacing(iconModeIconSize / 3); |
|
438 |
} |
|
439 |
||
440 |
QAction *ActionListView::currentAction() const |
|
441 |
{ |
|
442 |
return m_model->actionAt(currentIndex()); |
|
443 |
} |
|
444 |
||
445 |
void ActionListView::filter(const QString &text) |
|
446 |
{ |
|
447 |
const int rowCount = m_model->rowCount(); |
|
448 |
const bool empty = text.isEmpty(); |
|
449 |
for (int i = 0; i < rowCount; i++) |
|
450 |
setRowHidden(i, !empty && !m_model->actionName(i).contains(text, Qt::CaseInsensitive)); |
|
451 |
} |
|
452 |
||
453 |
void ActionListView::dragEnterEvent(QDragEnterEvent *event) |
|
454 |
{ |
|
455 |
handleImageDragEnterMoveEvent(event); |
|
456 |
} |
|
457 |
||
458 |
void ActionListView::dragMoveEvent(QDragMoveEvent *event) |
|
459 |
{ |
|
460 |
handleImageDragEnterMoveEvent(event); |
|
461 |
} |
|
462 |
||
463 |
void ActionListView::dropEvent(QDropEvent *event) |
|
464 |
{ |
|
465 |
handleImageDropEvent(this, event, m_model); |
|
466 |
} |
|
467 |
||
468 |
void ActionListView::focusInEvent(QFocusEvent *event) |
|
469 |
{ |
|
470 |
QListView::focusInEvent(event); |
|
471 |
// Make property editor display current action |
|
472 |
if (QAction *a = currentAction()) |
|
473 |
emit currentChanged(a); |
|
474 |
} |
|
475 |
||
476 |
void ActionListView::contextMenuEvent(QContextMenuEvent *event) |
|
477 |
{ |
|
478 |
emit contextMenuRequested(event, m_model->actionAt(indexAt(event->pos()))); |
|
479 |
} |
|
480 |
||
481 |
void ActionListView::currentChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/) |
|
482 |
{ |
|
483 |
emit currentChanged(m_model->actionAt(current)); |
|
484 |
} |
|
485 |
||
486 |
void ActionListView::slotActivated(const QModelIndex &index) |
|
487 |
{ |
|
488 |
emit activated(m_model->actionAt(index)); |
|
489 |
} |
|
490 |
||
491 |
void ActionListView::startDrag(Qt::DropActions supportedActions) |
|
492 |
{ |
|
493 |
startActionDrag(this, m_model, selectedIndexes(), supportedActions); |
|
494 |
} |
|
495 |
||
496 |
// ActionView |
|
497 |
ActionView::ActionView(QWidget *parent) : |
|
498 |
QStackedWidget(parent), |
|
499 |
m_model(new ActionModel(this)), |
|
500 |
m_actionTreeView(new ActionTreeView(m_model)), |
|
501 |
m_actionListView(new ActionListView(m_model)) |
|
502 |
{ |
|
503 |
addWidget(m_actionListView); |
|
504 |
addWidget(m_actionTreeView); |
|
505 |
// Wire signals |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
connect(m_actionTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*,QAction*)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
this, SIGNAL(contextMenuRequested(QContextMenuEvent*,QAction*))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
508 |
connect(m_actionListView, SIGNAL(contextMenuRequested(QContextMenuEvent*,QAction*)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
this, SIGNAL(contextMenuRequested(QContextMenuEvent*,QAction*))); |
0 | 510 |
|
511 |
// make it possible for vs integration to reimplement edit action dialog |
|
512 |
// [which it shouldn't do actually] |
|
513 |
connect(m_actionListView, SIGNAL(activated(QAction*)), this, SIGNAL(activated(QAction*))); |
|
514 |
connect(m_actionTreeView, SIGNAL(activated(QAction*)), this, SIGNAL(activated(QAction*))); |
|
515 |
||
516 |
connect(m_actionListView, SIGNAL(currentChanged(QAction*)),this, SLOT(slotCurrentChanged(QAction*))); |
|
517 |
connect(m_actionTreeView, SIGNAL(currentChanged(QAction*)),this, SLOT(slotCurrentChanged(QAction*))); |
|
518 |
||
519 |
connect(m_model, SIGNAL(resourceImageDropped(QString,QAction*)), |
|
520 |
this, SIGNAL(resourceImageDropped(QString,QAction*))); |
|
521 |
||
522 |
// sync selection models |
|
523 |
QItemSelectionModel *selectionModel = m_actionTreeView->selectionModel(); |
|
524 |
m_actionListView->setSelectionModel(selectionModel); |
|
525 |
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
|
526 |
this, SIGNAL(selectionChanged(QItemSelection,QItemSelection))); |
|
527 |
} |
|
528 |
||
529 |
int ActionView::viewMode() const |
|
530 |
{ |
|
531 |
return currentWidget() == m_actionListView ? IconView : DetailedView; |
|
532 |
} |
|
533 |
||
534 |
void ActionView::setViewMode(int lm) |
|
535 |
{ |
|
536 |
if (viewMode() == lm) |
|
537 |
return; |
|
538 |
||
539 |
switch (lm) { |
|
540 |
case IconView: |
|
541 |
setCurrentWidget(m_actionListView); |
|
542 |
break; |
|
543 |
case DetailedView: |
|
544 |
setCurrentWidget(m_actionTreeView); |
|
545 |
break; |
|
546 |
default: |
|
547 |
break; |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
void ActionView::slotCurrentChanged(QAction *action) |
|
552 |
{ |
|
553 |
// emit only for currently visible |
|
554 |
if (sender() == currentWidget()) |
|
555 |
emit currentChanged(action); |
|
556 |
} |
|
557 |
||
558 |
void ActionView::filter(const QString &text) |
|
559 |
{ |
|
560 |
m_actionTreeView->filter(text); |
|
561 |
m_actionListView->filter(text); |
|
562 |
} |
|
563 |
||
564 |
void ActionView::selectAll() |
|
565 |
{ |
|
566 |
m_actionTreeView->selectAll(); |
|
567 |
} |
|
568 |
||
569 |
void ActionView::clearSelection() |
|
570 |
{ |
|
571 |
m_actionTreeView->selectionModel()->clearSelection(); |
|
572 |
} |
|
573 |
||
574 |
void ActionView::setCurrentIndex(const QModelIndex &index) |
|
575 |
{ |
|
576 |
m_actionTreeView->setCurrentIndex(index); |
|
577 |
} |
|
578 |
||
579 |
QAction *ActionView::currentAction() const |
|
580 |
{ |
|
581 |
return m_actionListView->currentAction(); |
|
582 |
} |
|
583 |
||
584 |
void ActionView::setSelectionMode(QAbstractItemView::SelectionMode sm) |
|
585 |
{ |
|
586 |
m_actionTreeView->setSelectionMode(sm); |
|
587 |
m_actionListView->setSelectionMode(sm); |
|
588 |
} |
|
589 |
||
590 |
QAbstractItemView::SelectionMode ActionView::selectionMode() const |
|
591 |
{ |
|
592 |
return m_actionListView->selectionMode(); |
|
593 |
} |
|
594 |
||
595 |
QItemSelection ActionView::selection() const |
|
596 |
{ |
|
597 |
return m_actionListView->selectionModel()->selection(); |
|
598 |
} |
|
599 |
||
600 |
ActionView::ActionList ActionView::selectedActions() const |
|
601 |
{ |
|
602 |
ActionList rc; |
|
603 |
foreach (const QModelIndex &index, selection().indexes()) |
|
604 |
if (index.column() == 0) |
|
605 |
rc += actionOfItem(m_model->itemFromIndex(index)); |
|
606 |
return rc; |
|
607 |
} |
|
608 |
// ---------- ActionRepositoryMimeData |
|
609 |
ActionRepositoryMimeData::ActionRepositoryMimeData(QAction *a, Qt::DropAction dropAction) : |
|
610 |
m_dropAction(dropAction) |
|
611 |
{ |
|
612 |
m_actionList += a; |
|
613 |
} |
|
614 |
||
615 |
ActionRepositoryMimeData::ActionRepositoryMimeData(const ActionList &al, Qt::DropAction dropAction) : |
|
616 |
m_dropAction(dropAction), |
|
617 |
m_actionList(al) |
|
618 |
{ |
|
619 |
} |
|
620 |
||
621 |
QStringList ActionRepositoryMimeData::formats() const |
|
622 |
{ |
|
623 |
return QStringList(QLatin1String(actionMimeType)); |
|
624 |
} |
|
625 |
||
626 |
QPixmap ActionRepositoryMimeData::actionDragPixmap(const QAction *action) |
|
627 |
{ |
|
628 |
||
629 |
// Try to find a suitable pixmap. Grab either widget or icon. |
|
630 |
const QIcon icon = action->icon(); |
|
631 |
if (!icon.isNull()) |
|
632 |
return icon.pixmap(QSize(22, 22)); |
|
633 |
||
634 |
foreach (QWidget *w, action->associatedWidgets()) |
|
635 |
if (QToolButton *tb = qobject_cast<QToolButton *>(w)) |
|
636 |
return QPixmap::grabWidget(tb); |
|
637 |
||
638 |
// Create a QToolButton |
|
639 |
QToolButton *tb = new QToolButton; |
|
640 |
tb->setText(action->text()); |
|
641 |
tb->setToolButtonStyle(Qt::ToolButtonTextOnly); |
|
642 |
#ifdef Q_WS_WIN // Force alien off to make adjustSize() take the system minimumsize into account. |
|
643 |
tb->createWinId(); |
|
644 |
#endif |
|
645 |
tb->adjustSize(); |
|
646 |
const QPixmap rc = QPixmap::grabWidget(tb); |
|
647 |
tb->deleteLater(); |
|
648 |
return rc; |
|
649 |
} |
|
650 |
||
651 |
void ActionRepositoryMimeData::accept(QDragMoveEvent *event) const |
|
652 |
{ |
|
653 |
if (event->proposedAction() == m_dropAction) { |
|
654 |
event->acceptProposedAction(); |
|
655 |
} else { |
|
656 |
event->setDropAction(m_dropAction); |
|
657 |
event->accept(); |
|
658 |
} |
|
659 |
} |
|
660 |
||
661 |
} // namespace qdesigner_internal |
|
662 |
||
663 |
QT_END_NAMESPACE |