source: projectionDesigner/trunk/projdesigner/src/gui/plugindialog.cpp @ 425

Last change on this file since 425 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 4.4 KB
RevLine 
[4]1/****************************************************************************
2**
3** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
4**
5** This file is part of the example classes of the Qt Toolkit.
6**
7** This file may be used under the terms of the GNU General Public
8** License version 2.0 as published by the Free Software Foundation
9** and appearing in the file LICENSE.GPL included in the packaging of
10** this file.  Please review the following information to ensure GNU
11** General Public Licensing requirements will be met:
12** http://www.trolltech.com/products/qt/opensource.html
13**
14** If you are unsure which license is appropriate for your use, please
15** review the following information:
16** http://www.trolltech.com/products/qt/licensing.html or contact the
17** sales department at sales@trolltech.com.
18**
19** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21**
22****************************************************************************/
23
24#include <QtGui>
25
26#include "interfaces.h"
27#include "plugindialog.h"
28
29PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames,
30                           QWidget *parent)
31    : QDialog(parent)
32{
33    label = new QLabel;
34
35    treeWidget = new QTreeWidget;
36    treeWidget->setAlternatingRowColors(false);
37    treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
38    treeWidget->setColumnCount(1);
39    treeWidget->header()->hide();
40
41    okButton = new QPushButton(tr("OK"));
42    okButton->setDefault(true);
43
44    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
45
46    QGridLayout *mainLayout = new QGridLayout;
47    mainLayout->setColumnStretch(0, 1);
48    mainLayout->setColumnStretch(2, 1);
49    mainLayout->addWidget(label, 0, 0, 1, 3);
50    mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
51    mainLayout->addWidget(okButton, 2, 1);
52    setLayout(mainLayout);
53
54    interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
55                            QIcon::Normal, QIcon::On);
56    interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
57                            QIcon::Normal, QIcon::Off);
58    featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
59
60    setWindowTitle(tr("Plugin Information"));
61    findPlugins(path, fileNames);
62}
63
64void PluginDialog::findPlugins(const QString &path,
65                               const QStringList &fileNames)
66{
67    label->setText(tr("ProjDesigner found the following plugins\n"
68                      "(looked in %1):")
69                   .arg(QDir::toNativeSeparators(path)));
70
71    QDir dir(path);
72
73    foreach (QObject *plugin, QPluginLoader::staticInstances())
74        populateTreeWidget(plugin, tr("%1 (Static Plugin)")
75                                                                                                         .arg(plugin->metaObject()->className()));
76
77    foreach (QString fileName, fileNames) {
78        QPluginLoader loader(dir.absoluteFilePath(fileName));
79        QObject *plugin = loader.instance();
80        if (plugin)
81            populateTreeWidget(plugin, fileName);
82    }
83}
84
85void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
86{
87    QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget);
88    pluginItem->setText(0, text);
89    treeWidget->setItemExpanded(pluginItem, true);
90
91    QFont boldFont = pluginItem->font(0);
92    boldFont.setBold(true);
93    pluginItem->setFont(0, boldFont);
94
95    if (plugin) {
96        ProjectorInterface *projector_plugin =
97                qobject_cast<ProjectorInterface*>(plugin);
98        if (projector_plugin)
99                                                addItems(pluginItem, "ProjectorInterface", projector_plugin->projectors());
100        SceneInterface *scene_plugin =
101                qobject_cast<SceneInterface*>(plugin);
102        if (scene_plugin)
103                                                addItems(pluginItem, "SceneInterface", scene_plugin->scenes());
104    }
105}
106
107void PluginDialog::addItems(QTreeWidgetItem *pluginItem,
108                            const char *interfaceName,
109                            const QStringList &features)
110{
111    QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem);
112    interfaceItem->setText(0, interfaceName);
113    interfaceItem->setIcon(0, interfaceIcon);
114
115    foreach (QString feature, features) {
116        if (feature.endsWith("..."))
117            feature.chop(3);
118        QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem);
119        featureItem->setText(0, feature);
120        featureItem->setIcon(0, featureIcon);
121    }
122}
Note: See TracBrowser for help on using the repository browser.