|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples 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 |
|
43 #include "interfaces.h" |
|
44 #include "plugindialog.h" |
|
45 |
|
46 #include <QPluginLoader> |
|
47 #include <QStringList> |
|
48 #include <QDir> |
|
49 |
|
50 #include <QLabel> |
|
51 #include <QGridLayout> |
|
52 #include <QPushButton> |
|
53 #include <QTreeWidget> |
|
54 #include <QTreeWidgetItem> |
|
55 #include <QHeaderView> |
|
56 |
|
57 PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames, |
|
58 QWidget *parent) : |
|
59 QDialog(parent), |
|
60 label(new QLabel), |
|
61 treeWidget(new QTreeWidget), |
|
62 okButton(new QPushButton(tr("OK"))) |
|
63 { |
|
64 treeWidget->setAlternatingRowColors(false); |
|
65 treeWidget->setSelectionMode(QAbstractItemView::NoSelection); |
|
66 treeWidget->setColumnCount(1); |
|
67 treeWidget->header()->hide(); |
|
68 |
|
69 okButton->setDefault(true); |
|
70 |
|
71 connect(okButton, SIGNAL(clicked()), this, SLOT(close())); |
|
72 |
|
73 QGridLayout *mainLayout = new QGridLayout; |
|
74 mainLayout->setColumnStretch(0, 1); |
|
75 mainLayout->setColumnStretch(2, 1); |
|
76 mainLayout->addWidget(label, 0, 0, 1, 3); |
|
77 mainLayout->addWidget(treeWidget, 1, 0, 1, 3); |
|
78 mainLayout->addWidget(okButton, 2, 1); |
|
79 setLayout(mainLayout); |
|
80 |
|
81 interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon), |
|
82 QIcon::Normal, QIcon::On); |
|
83 interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon), |
|
84 QIcon::Normal, QIcon::Off); |
|
85 featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon)); |
|
86 |
|
87 setWindowTitle(tr("Plugin Information")); |
|
88 findPlugins(path, fileNames); |
|
89 } |
|
90 |
|
91 //! [0] |
|
92 void PluginDialog::findPlugins(const QString &path, |
|
93 const QStringList &fileNames) |
|
94 { |
|
95 label->setText(tr("Plug & Paint found the following plugins\n" |
|
96 "(looked in %1):") |
|
97 .arg(QDir::toNativeSeparators(path))); |
|
98 |
|
99 const QDir dir(path); |
|
100 |
|
101 foreach (QObject *plugin, QPluginLoader::staticInstances()) |
|
102 populateTreeWidget(plugin, tr("%1 (Static Plugin)") |
|
103 .arg(plugin->metaObject()->className())); |
|
104 |
|
105 foreach (QString fileName, fileNames) { |
|
106 QPluginLoader loader(dir.absoluteFilePath(fileName)); |
|
107 QObject *plugin = loader.instance(); |
|
108 if (plugin) |
|
109 populateTreeWidget(plugin, fileName); |
|
110 } |
|
111 } |
|
112 //! [0] |
|
113 |
|
114 //! [1] |
|
115 void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text) |
|
116 { |
|
117 QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget); |
|
118 pluginItem->setText(0, text); |
|
119 treeWidget->setItemExpanded(pluginItem, true); |
|
120 |
|
121 QFont boldFont = pluginItem->font(0); |
|
122 boldFont.setBold(true); |
|
123 pluginItem->setFont(0, boldFont); |
|
124 |
|
125 if (plugin) { |
|
126 BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin); |
|
127 if (iBrush) |
|
128 addItems(pluginItem, "BrushInterface", iBrush->brushes()); |
|
129 |
|
130 ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin); |
|
131 if (iShape) |
|
132 addItems(pluginItem, "ShapeInterface", iShape->shapes()); |
|
133 |
|
134 FilterInterface *iFilter = |
|
135 qobject_cast<FilterInterface *>(plugin); |
|
136 if (iFilter) |
|
137 addItems(pluginItem, "FilterInterface", iFilter->filters()); |
|
138 } |
|
139 } |
|
140 //! [1] |
|
141 |
|
142 void PluginDialog::addItems(QTreeWidgetItem *pluginItem, |
|
143 const char *interfaceName, |
|
144 const QStringList &features) |
|
145 { |
|
146 QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem); |
|
147 interfaceItem->setText(0, interfaceName); |
|
148 interfaceItem->setIcon(0, interfaceIcon); |
|
149 |
|
150 foreach (QString feature, features) { |
|
151 if (feature.endsWith("...")) |
|
152 feature.chop(3); |
|
153 QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem); |
|
154 featureItem->setText(0, feature); |
|
155 featureItem->setIcon(0, featureIcon); |
|
156 } |
|
157 } |