1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
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
** 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.
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
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
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
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.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
152
154
void restoreSettings();
153
155
void saveSettings();
154
156
void updateActions();
157
void filterOutResources();
156
159
QPixmap makeThumbnail(const QPixmap &pix) const;
158
161
QDesignerFormEditorInterface *m_core;
159
162
QtResourceModel *m_resourceModel;
160
163
QToolBar *m_toolBar;
164
qdesigner_internal::FilterWidget *m_filterWidget;
161
165
QTreeWidget *m_treeWidget;
162
166
QListWidget *m_listWidget;
163
167
QSplitter *m_splitter;
164
QMap<QString, QStringList> m_pathToContents; // full path to contents file names
168
QMap<QString, QStringList> m_pathToContents; // full path to contents file names (full path to its resource filenames)
169
QMap<QString, QString> m_pathToParentPath; // full path to full parent path
170
QMap<QString, QStringList> m_pathToSubPaths; // full path to full sub paths
165
171
QMap<QString, QTreeWidgetItem *> m_pathToItem;
166
172
QMap<QTreeWidgetItem *, QString> m_itemToPath;
167
173
QMap<QString, QListWidgetItem *> m_resourceToItem;
387
401
QPair<QString, QTreeWidgetItem *> pathToParentItem = pathToParentItemQueue.dequeue();
388
402
const QString path = pathToParentItem.first;
389
403
QTreeWidgetItem *item = createPath(path, pathToParentItem.second);
390
QStringList subPaths = pathToSubPaths.value(path);
404
QStringList subPaths = m_pathToSubPaths.value(path);
391
405
QStringListIterator itSubPaths(subPaths);
392
406
while (itSubPaths.hasNext())
393
407
pathToParentItemQueue.enqueue(qMakePair(itSubPaths.next(), item));
411
void QtResourceViewPrivate::filterOutResources()
413
QMap<QString, bool> pathToMatchingContents; // true means the path has any matching contents
414
QMap<QString, bool> pathToVisible; // true means the path has to be shown
416
// 1) we go from root path recursively.
417
// 2) we check every path if it contains at least one matching resource - if empty we add it
418
// to pathToMatchingContents and pathToVisible with false, if non empty
419
// we add it with true and change every parent path in pathToVisible to true.
420
// 3) we hide these items which has pathToVisible value false.
422
const bool matchAll = m_filterPattern.isEmpty();
423
const QString root(QLatin1Char(':'));
425
QQueue<QString> pathQueue;
426
pathQueue.enqueue(root);
427
while (!pathQueue.isEmpty()) {
428
const QString path = pathQueue.dequeue();
430
QStringList fileNames = m_pathToContents.value(path);
431
QStringListIterator it(fileNames);
432
bool hasContents = matchAll;
433
if (!matchAll) { // the case filter is not empty - we check if the path contains anything
434
while (it.hasNext()) {
435
QString fileName = it.next();
436
hasContents = fileName.contains(m_filterPattern, Qt::CaseInsensitive);
437
if (hasContents) // the path contains at least one resource which matches the filter
442
pathToMatchingContents[path] = hasContents;
443
pathToVisible[path] = hasContents;
445
if (hasContents) { // if the path is going to be shown we need to show all its parent paths
446
QString parentPath = m_pathToParentPath.value(path);
447
while (!parentPath.isEmpty()) {
448
QString p = parentPath;
449
if (pathToVisible.value(p)) // parent path is already shown, we break the loop
451
pathToVisible[p] = true;
452
parentPath = m_pathToParentPath.value(p);
456
QStringList subPaths = m_pathToSubPaths.value(path); // we do the same for children paths
457
QStringListIterator itSubPaths(subPaths);
458
while (itSubPaths.hasNext())
459
pathQueue.enqueue(itSubPaths.next());
462
// we setup here new path and resource to be activated
463
const QString currentPath = m_itemToPath.value(m_treeWidget->currentItem());
464
QString newCurrentPath = currentPath;
465
QString currentResource = m_itemToResource.value(m_listWidget->currentItem());
467
bool searchForNewPathWithContents = true;
469
if (!currentPath.isEmpty()) { // if the currentPath is empty we will search for a new path too
470
QMap<QString, bool>::ConstIterator it = pathToMatchingContents.constFind(currentPath);
471
if (it != pathToMatchingContents.constEnd() && it.value()) // the current item has contents, we don't need to search for another path
472
searchForNewPathWithContents = false;
475
if (searchForNewPathWithContents) {
476
// we find the first path with the matching contents
477
QMap<QString, bool>::ConstIterator itContents = pathToMatchingContents.constBegin();
478
while (itContents != pathToMatchingContents.constEnd()) {
479
if (itContents.value()) {
480
newCurrentPath = itContents.key(); // the new path will be activated
488
QFileInfo fi(currentResource);
489
if (!fi.fileName().contains(m_filterPattern, Qt::CaseInsensitive)) { // the case when the current resource is filtered out
490
const QStringList fileNames = m_pathToContents.value(newCurrentPath);
491
QStringListIterator it(fileNames);
492
while (it.hasNext()) { // we try to select the first matching resource from the newCurrentPath
493
QString fileName = it.next();
494
if (fileName.contains(m_filterPattern, Qt::CaseInsensitive)) {
495
QDir dirPath(newCurrentPath);
496
currentResource = dirPath.absoluteFilePath(fileName); // the new resource inside newCurrentPath will be activated
503
QTreeWidgetItem *newCurrentItem = m_pathToItem.value(newCurrentPath);
504
if (currentPath != newCurrentPath)
505
m_treeWidget->setCurrentItem(newCurrentItem);
507
slotCurrentPathChanged(newCurrentItem); // trigger filtering on the current path
509
QListWidgetItem *currentResourceItem = m_resourceToItem.value(currentResource);
510
if (currentResourceItem) {
511
m_listWidget->setCurrentItem(currentResourceItem);
512
m_listWidget->scrollToItem(currentResourceItem);
515
QMapIterator<QString, bool> it(pathToVisible); // hide all paths filtered out
516
while (it.hasNext()) {
517
const QString path = it.next().key();
518
QTreeWidgetItem *item = m_pathToItem.value(path);
520
item->setHidden(!it.value());
397
524
QTreeWidgetItem *QtResourceViewPrivate::createPath(const QString &path, QTreeWidgetItem *parent)
399
526
QTreeWidgetItem *item = 0;
418
545
void QtResourceViewPrivate::createResources(const QString &path)
547
const bool matchAll = m_filterPattern.isEmpty();
421
QStringList files = m_pathToContents.value(path);
422
QStringListIterator it(files);
550
QStringList fileNames = m_pathToContents.value(path);
551
QStringListIterator it(fileNames);
423
552
while (it.hasNext()) {
424
QString file = it.next();
425
QString filePath = dir.absoluteFilePath(file);
426
QFileInfo fi(filePath);
428
QListWidgetItem *item = new QListWidgetItem(fi.fileName(), m_listWidget);
429
const QPixmap pix = QPixmap(filePath);
431
item->setToolTip(filePath);
433
item->setIcon(QIcon(makeThumbnail(pix)));
434
const QSize size = pix.size();
435
item->setToolTip(QtResourceView::tr("Size: %1 x %2\n%3").arg(size.width()).arg(size.height()).arg(filePath));
553
QString fileName = it.next();
554
const bool showProperty = matchAll || fileName.contains(m_filterPattern, Qt::CaseInsensitive);
556
QString filePath = dir.absoluteFilePath(fileName);
557
QFileInfo fi(filePath);
559
QListWidgetItem *item = new QListWidgetItem(fi.fileName(), m_listWidget);
560
const QPixmap pix = QPixmap(filePath);
562
item->setToolTip(filePath);
564
item->setIcon(QIcon(makeThumbnail(pix)));
565
const QSize size = pix.size();
566
item->setToolTip(QtResourceView::tr("Size: %1 x %2\n%3").arg(size.width()).arg(size.height()).arg(filePath));
568
item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
569
item->setData(Qt::UserRole, filePath);
570
m_itemToResource[item] = filePath;
571
m_resourceToItem[filePath] = item;
437
item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
438
item->setData(Qt::UserRole, filePath);
439
m_itemToResource[item] = filePath;
440
m_resourceToItem[filePath] = item;
451
583
d_ptr->q_ptr = this;
453
d_ptr->m_editResourcesAction = new QAction(qdesigner_internal::createIconSet(QLatin1String("edit.png")), tr("Edit Resources..."), this);
585
QIcon editIcon = QIcon::fromTheme("document-properties", qdesigner_internal::createIconSet(QLatin1String("edit.png")));
586
d_ptr->m_editResourcesAction = new QAction(editIcon, tr("Edit Resources..."), this);
454
587
d_ptr->m_toolBar->addAction(d_ptr->m_editResourcesAction);
455
588
connect(d_ptr->m_editResourcesAction, SIGNAL(triggered()), this, SLOT(slotEditResources()));
456
589
d_ptr->m_editResourcesAction->setEnabled(false);
458
d_ptr->m_reloadResourcesAction = new QAction(qdesigner_internal::createIconSet(QLatin1String("reload.png")), tr("Reload"), this);
591
QIcon refreshIcon = QIcon::fromTheme("view-refresh", qdesigner_internal::createIconSet(QLatin1String("reload.png")));
592
d_ptr->m_reloadResourcesAction = new QAction(refreshIcon, tr("Reload"), this);
459
594
d_ptr->m_toolBar->addAction(d_ptr->m_reloadResourcesAction);
460
595
connect(d_ptr->m_reloadResourcesAction, SIGNAL(triggered()), this, SLOT(slotReloadResources()));
461
596
d_ptr->m_reloadResourcesAction->setEnabled(false);
463
d_ptr->m_copyResourcePathAction = new QAction(qdesigner_internal::createIconSet(QLatin1String("editcopy.png")), tr("Copy Path"), this);
598
QIcon copyIcon = QIcon::fromTheme("edit-copy", qdesigner_internal::createIconSet(QLatin1String("editcopy.png")));
599
d_ptr->m_copyResourcePathAction = new QAction(copyIcon, tr("Copy Path"), this);
464
600
connect(d_ptr->m_copyResourcePathAction, SIGNAL(triggered()), this, SLOT(slotCopyResourcePath()));
465
601
d_ptr->m_copyResourcePathAction->setEnabled(false);
603
//d_ptr->m_filterWidget = new qdesigner_internal::FilterWidget(0, qdesigner_internal::FilterWidget::LayoutAlignNone);
604
d_ptr->m_filterWidget = new qdesigner_internal::FilterWidget(d_ptr->m_toolBar);
605
d_ptr->m_toolBar->addWidget(d_ptr->m_filterWidget);
606
connect(d_ptr->m_filterWidget, SIGNAL(filterChanged(QString)), this, SLOT(slotFilterChanged(QString)));
467
608
d_ptr->m_splitter = new QSplitter;
468
609
d_ptr->m_splitter->setChildrenCollapsible(false);
469
610
d_ptr->m_splitter->addWidget(d_ptr->m_treeWidget);