summaryrefslogtreecommitdiffstats
path: root/sigtools
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-26 07:04:03 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-03-26 07:04:03 -0400
commitc85460780f94a01fb885f237efdf8f78e4202ec1 (patch)
tree4130f231e1df34db48c5ce63def888e731468c03 /sigtools
parent57d34ec1e6e410bcea8a7b17a0cd66437fd0d905 (diff)
downloadsigen-c85460780f94a01fb885f237efdf8f78e4202ec1.tar.gz
sigen-c85460780f94a01fb885f237efdf8f78e4202ec1.tar.xz
sigen-c85460780f94a01fb885f237efdf8f78e4202ec1.zip
Drawing routines (adapted from KPluginSelector)
Diffstat (limited to 'sigtools')
-rw-r--r--sigtools/PluginTreeDelegate.cpp94
-rw-r--r--sigtools/PluginTreeDelegate.h1
2 files changed, 94 insertions, 1 deletions
diff --git a/sigtools/PluginTreeDelegate.cpp b/sigtools/PluginTreeDelegate.cpp
index bf039bc8..41216b02 100644
--- a/sigtools/PluginTreeDelegate.cpp
+++ b/sigtools/PluginTreeDelegate.cpp
@@ -15,38 +15,130 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ * Drawing code adapted from KPluginSelector (2009-03-26)
+ *
+ * Copyright (C) 2007, 2006 Rafael Fernández López <ereslibre@kde.org>
+ * Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org>
+ */
+
// Header include
#include "PluginTreeDelegate.h"
// Sigtools includes
+#include "PluginLoader.h"
#include "PluginTree.h"
// KDE includes
+#include <KApplication>
+#include <KAboutApplicationDialog>
#include <KCategorizedView>
+#include <KCategorizedSortFilterProxyModel>
+#include <KPluginInfo>
+#include <KPushButton>
+#include <KService>
+
+// Qt includes
+#include <QtGui/QPainter>
+
+static const int margins = 3;
using namespace Sigtools;
PluginTreeDelegate::PluginTreeDelegate(KCategorizedView* view, PluginTree* tree) :
- KWidgetItemDelegate(view, tree)
+ KWidgetItemDelegate(view, tree),
+ m_about(new KPushButton)
+{
+ m_about->setIcon(KIcon("dialog-information"));
+}
+
+PluginTreeDelegate::~PluginTreeDelegate()
{
+ delete m_about;
}
void PluginTreeDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
+ if (!index.isValid())
+ return;
+
+ KApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
+
+ int iconSize = option.rect.height() - 2 * margins;
+ painter->drawPixmap(QRect(margins + option.rect.left(), margins + option.rect.top(), iconSize, iconSize), KIconLoader::global()->loadIcon(index.model()->data(index, Qt::DecorationRole).toString(), KIconLoader::Desktop, iconSize));
+
+ QRect contentsRect(2 * margins + iconSize + option.rect.left(), margins + option.rect.top(), option.rect.width() - 5 * margins - iconSize - m_about->sizeHint().width(), option.rect.height() - 2 * margins);
+
+ painter->save();
+
+ if (option.state & QStyle::State_Selected)
+ painter->setPen(option.palette.highlightedText().color());
+
+ QFont font = option.font;
+ font.setBold(true);
+ QFontMetrics fmTitle(font);
+ painter->setFont(font);
+ painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignTop, fmTitle.elidedText(index.model()->data(index, Qt::DisplayRole).toString(), Qt::ElideRight, contentsRect.width()));
+
+ painter->setFont(option.font);
+ painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignBottom, option.fontMetrics.elidedText(index.model()->data(index, Qt::UserRole).toString(), Qt::ElideRight, contentsRect.width()));
+
+ painter->restore();
}
QSize PluginTreeDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
+ QFont font = option.font;
+ font.setBold(true);
+ QFontMetrics fmTitle(font);
+ const QSize nameSize = fmTitle.size(0, index.model()->data(index, Qt::DisplayRole).toString());
+ const QSize descSize = option.fontMetrics.size(0, index.model()->data(index, Qt::UserRole).toString());
+
+ return QSize(qMax(nameSize.width(), descSize.width()) + KIconLoader::SizeMedium, qMax(int(KIconLoader::SizeMedium), nameSize.height() + descSize.height()) + 2 * margins);
}
QList<QWidget*> PluginTreeDelegate::createItemWidgets() const
{
+ QList<QWidget*> widgetList;
+ KPushButton *aboutPushButton = new KPushButton;
+ aboutPushButton->setIcon(KIcon("dialog-information"));
+ connect(aboutPushButton, SIGNAL(clicked(bool)), this, SLOT(aboutClicked()));
+
+ setBlockedEventTypes(aboutPushButton, QList<QEvent::Type>() << QEvent::MouseButtonPress << QEvent::MouseButtonRelease << QEvent::MouseButtonDblClick);
+
+ widgetList << aboutPushButton;
+ return widgetList;
}
void PluginTreeDelegate::updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index) const
{
+ Q_UNUSED(index)
+ QSize aboutSize = widgets[0]->sizeHint();
+ widgets[0]->resize(aboutSize);
+ widgets[0]->move(option.rect.width() - margins - aboutSize.width(), (option.rect.height() - aboutSize.height()) / 2);
}
void PluginTreeDelegate::aboutClicked()
{
+ const QModelIndex index = focusedIndex();
+ const QAbstractItemModel* model = index.model();
+ const QString type = model->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
+ const QString cname = model->data(index, Qt::DisplayRole).toString();
+ KService::Ptr service = PluginLoader::service(type, cname);
+ KPluginInfo info(service);
+ const QString name = info.name();
+ const QStringList authors = info.author().split(',');
+ const QStringList emails = info.email().split(',');
+ KAboutData aboutData(name.toUtf8(), name.toUtf8(), ki18n(name.toUtf8()), info.version().toUtf8(), ki18n(info.comment().toUtf8()), KAboutLicense::byKeyword(info.license()).key(), ki18n(QByteArray()), ki18n(QByteArray()), info.website().toLatin1());
+ aboutData.setProgramIconName(info.icon());
+ if (authors.count() == emails.count())
+ {
+ for (int i = 0; i < authors.count(); ++i)
+ {
+ if (!authors[i].isEmpty())
+ aboutData.addAuthor(ki18n(authors[i].toUtf8()), ki18n(QByteArray()), emails[i].toUtf8(), 0);
+ }
+ }
+ KAboutApplicationDialog aboutPlugin(&aboutData, itemView());
+ aboutPlugin.exec();
}
diff --git a/sigtools/PluginTreeDelegate.h b/sigtools/PluginTreeDelegate.h
index 7e38cd51..dee56dfb 100644
--- a/sigtools/PluginTreeDelegate.h
+++ b/sigtools/PluginTreeDelegate.h
@@ -38,6 +38,7 @@ class SIGTOOLS_NO_EXPORT PluginTreeDelegate : public KWidgetItemDelegate
public:
PluginTreeDelegate(KCategorizedView* view, PluginTree* tree);
+ ~PluginTreeDelegate();
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;