summaryrefslogtreecommitdiffstats
path: root/sigtools/PluginModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigtools/PluginModel.cpp')
-rw-r--r--sigtools/PluginModel.cpp169
1 files changed, 0 insertions, 169 deletions
diff --git a/sigtools/PluginModel.cpp b/sigtools/PluginModel.cpp
deleted file mode 100644
index 176c6a68..00000000
--- a/sigtools/PluginModel.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2009 Ben Boeckel <MathStuf@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-// Header include
-#include "PluginModel.h"
-
-// Sigtools includes
-#include "ClassModel.h"
-#include "PluginTypeModel.h"
-
-// Sigencore includes
-#include <sigencore/plugins/ArenaPlugin.h>
-#include <sigencore/plugins/CanvasPlugin.h>
-
-// KDE includes
-#include <KColorScheme>
-#include <KGlobalSettings>
-#include <KIcon>
-#include <KMessageBox>
-#include <KPluginInfo>
-
-// Qt includes
-#include <QtGui/QPainter>
-
-using namespace Sigencore::Interfaces;
-using namespace Sigtools;
-
-PluginModel::PluginModel(KService::Ptr service, PluginTypeModel* parent) :
- BaseModel(parent),
- m_service(service),
- m_info(new KPluginInfo(m_service))
-{
- KPluginLoader loader(m_service->library());
- KPluginFactory *factory = loader.factory();
-
- if (!factory)
- {
- KMessageBox::error(NULL, QString("The plugin of type \"%1\" with name \"%2\" is not a valid Sigen plugin. The error was:\n%3").arg(m_service->serviceTypes()[0]).arg(m_service->name()).arg(loader.errorString()), "Plugin loading error");
- return;
- }
-
- const QStringList types = m_service->serviceTypes();
- foreach (const QString& type, types)
- {
- if (type == "Sigen/Arena")
- {
- ArenaPlugin* plugin = factory->create<ArenaPlugin>(this);
- if (plugin)
- {
- QStringList arenas = plugin->arenas();
- foreach (const QString& arena, arenas)
- m_classes.append(new ClassModel(plugin->icon(arena), arena, plugin->description(arena), this));
- }
- }
- else if (type == "Sigen/Canvas")
- {
- CanvasPlugin* plugin = factory->create<CanvasPlugin>(this);
- if (plugin)
- {
- QStringList canvases = plugin->canvases();
- foreach (const QString& canvas, canvases)
- m_classes.append(new ClassModel(plugin->icon(canvas), canvas, plugin->description(canvas), this));
- }
- }
- else
- KMessageBox::information(NULL, QString("The plugin type \"%1\" is not supported.").arg(m_service->type()), "Unsupported plugin type");
- }
-}
-
-int PluginModel::rowCount() const
-{
- return m_classes.size();
-}
-
-Qt::ItemFlags PluginModel::flags() const
-{
- return Qt::ItemIsEnabled;
-}
-
-BaseModel* PluginModel::childItem(const int row)
-{
- if ((0 <= row) && (row < m_classes.size()))
- return m_classes[row];
- return NULL;
-}
-
-int PluginModel::findChild(BaseModel* model) const
-{
- return m_classes.indexOf(qobject_cast<ClassModel*>(model));
-}
-
-void PluginModel::redraw(const int width) const
-{
- QFont regFont = KGlobalSettings::generalFont();
- QFontMetrics regMetrics(regFont);
- QFont smallFont = KGlobalSettings::smallestReadableFont();
- smallFont.setItalic(true);
- QFontMetrics smallMetrics(smallFont);
-
- QSize nameSize = regMetrics.size(0, m_info->name());
- QSize authorSize = smallMetrics.size(0, QString("by %1").arg(m_info->author()));
- QSize versionSize = regMetrics.size(0, m_info->version());
-
- int row1width;
- int row1height;
-
- row1height = qMax(nameSize.height(), qMax(authorSize.height(), versionSize.height()));
- row1width = row1height + nameSize.width() + authorSize.width() + versionSize.width();
-
- QSize websiteSize = smallMetrics.size(0, m_info->website());
-
- int maxWidth = qMax(qMax(row1width + 4 * horizSpacing, websiteSize.width()), width - 2 * borderWidth);
-
- QSize commentSize = smallMetrics.boundingRect(QRect(0, 0, maxWidth, 0), Qt::TextWordWrap, m_info->comment()).size();
-
- int maxHeight = row1height + websiteSize.height() + commentSize.height() + 2 * vertSpacing;
-
- int h = borderWidth;
- int w = borderWidth;
-
- m_pixmap = QPixmap(maxWidth + 2 * borderWidth, maxHeight + 2 * borderWidth);
- m_pixmap.fill(KStatefulBrush(KColorScheme::View, KColorScheme::NormalBackground).brush(QPalette::Normal).color());
- QPainter painter(&m_pixmap);
-
- painter.drawPixmap(w, h, KIcon(m_info->icon()).pixmap(row1height, row1height));
-
- w += row1height;
- w += horizSpacing;
-
- painter.drawText(QRect(QPoint(w, h), QSize(row1width - w, row1height)), Qt::AlignBottom | Qt::AlignLeft, m_info->name());
-
- w += nameSize.width();
- w += 2 * horizSpacing;
-
- painter.setFont(smallFont);
- painter.drawText(QRect(QPoint(w, h), QSize(row1width - w, row1height)), Qt::AlignBottom | Qt::AlignLeft, QString("by %1").arg(m_info->author()));
-
- w += authorSize.width();
- w += horizSpacing;
-
- painter.setFont(regFont);
- painter.drawText(QRect(QPoint(w, h), QSize(maxWidth - w, row1height)), Qt::AlignBottom | Qt::AlignRight, m_info->version());
-
- h += row1height;
- h += vertSpacing;
- w = borderWidth;
-
- painter.setFont(smallFont);
- painter.drawText(QRect(QPoint(w, h), websiteSize), Qt::AlignBottom | Qt::AlignLeft, m_info->website());
-
- h += websiteSize.height();
- h += vertSpacing;
-
- painter.drawText(QRect(QPoint(w, h), commentSize), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, m_info->comment());
-}