-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathNewPluginsDialog.cpp
115 lines (98 loc) · 4.09 KB
/
NewPluginsDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//-----------------------------------------------------------------------------
// File: NewPluginsDialog.cpp
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author: Esko Pekkarinen
// Date: 14.1.2014
//
// Description:
// Dialog for displaying new plugins.
//-----------------------------------------------------------------------------
#include "NewPluginsDialog.h"
#include <KactusAPI/include/IPlugin.h>
#include <KactusAPI/include/IGeneratorPlugin.h>
#include <KactusAPI/include/ISourceAnalyzerPlugin.h>
#include <KactusAPI/include/ImportPlugin.h>
#include "PluginInfoWidget.h"
#include <QPushButton>
#include <QVBoxLayout>
namespace
{
enum Roles
{
PLUGIN_POINTER_ROLE = Qt::UserRole, //<! Pointer to the plugin.
PLUGIN_STACK_INDEX_ROLE //<! Index of the plugin in detail stack.
};
}
//-----------------------------------------------------------------------------
// Function: NewPluginsDialog::NewPluginsDialog()
//-----------------------------------------------------------------------------
NewPluginsDialog::NewPluginsDialog(QWidget* parent)
: QDialog(parent),
pluginsList_(this),
detailsStack_(this),
buttonBox_(QDialogButtonBox::Ok, Qt::Horizontal, this)
{
setWindowTitle(tr("New plugins found"));
connect(buttonBox_.button(QDialogButtonBox::Ok), SIGNAL(clicked()),
this, SLOT(accept()), Qt::UniqueConnection);
connect(buttonBox_.button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
this, SLOT(reject()), Qt::UniqueConnection);
connect(&pluginsList_, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
this, SLOT(selectionChanged()), Qt::UniqueConnection);
setupLayout();
}
//-----------------------------------------------------------------------------
// Function: NewPluginsDialog::selectionChanged()
//-----------------------------------------------------------------------------
void NewPluginsDialog::selectionChanged()
{
int index = pluginsList_.currentItem()->data(PLUGIN_STACK_INDEX_ROLE).value<int>();
detailsStack_.setCurrentIndex(index);
}
//-----------------------------------------------------------------------------
// Function: NewPluginsDialog::addPlugin()
//-----------------------------------------------------------------------------
void NewPluginsDialog::addPlugin(IPlugin* plugin)
{
QListWidgetItem* item = new QListWidgetItem(plugin->getName() + " (" + plugin->getVersion() + ")");
item->setData(PLUGIN_POINTER_ROLE, QVariant::fromValue(static_cast<void*>(plugin)));
item->setData(PLUGIN_STACK_INDEX_ROLE, detailsStack_.count());
// Set icon for plugin.
IGeneratorPlugin* generator = dynamic_cast<IGeneratorPlugin*>(plugin);
if (generator != 0)
{
item->setIcon(generator->getIcon());
}
else if(dynamic_cast<ISourceAnalyzerPlugin*>(plugin) != 0)
{
item->setIcon(QIcon(":icons/common/graphics/plugin-source_analyzer.png"));
}
else if(dynamic_cast<ImportPlugin*>(plugin) != 0)
{
item->setIcon(QIcon(":icons/common/graphics/import.png"));
}
pluginsList_.addItem(item);
detailsStack_.addWidget(new PluginInfoWidget(plugin));
}
//-----------------------------------------------------------------------------
// Function: NewPluginsDialog::addPlugin()
//-----------------------------------------------------------------------------
void NewPluginsDialog::addPlugins(QList<IPlugin*> plugins)
{
foreach(IPlugin* plugin, plugins)
{
addPlugin(plugin);
}
}
//-----------------------------------------------------------------------------
// Function: NewPluginsDialog::setupLayout()
//-----------------------------------------------------------------------------
void NewPluginsDialog::setupLayout()
{
resize(400, 300);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(&pluginsList_, 1);
layout->addWidget(&detailsStack_);
layout->addWidget(&buttonBox_, 0, Qt::AlignHCenter);
}