move the applet browser stuff into the two shells that actually use it (desktop and overlay) so that we can unburden libplasma from it; makes me a lot more comfortable talking about BC with a straight face. a new browser may end up going back in post-4.2 however
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=871492
This commit is contained in:
parent
725c0c3137
commit
e7357ffa7d
@ -25,13 +25,6 @@ set(plasma_LIB_SRCS
|
||||
animationdriver.cpp
|
||||
animator.cpp
|
||||
applet.cpp
|
||||
appletbrowser.cpp
|
||||
appletbrowser/customdragtreeview.cpp
|
||||
appletbrowser/kcategorizeditemsview.cpp
|
||||
appletbrowser/kcategorizeditemsviewdelegate.cpp
|
||||
appletbrowser/kcategorizeditemsviewmodels.cpp
|
||||
appletbrowser/openwidgetassistant.cpp
|
||||
appletbrowser/plasmaappletitemmodel.cpp
|
||||
configxml.cpp
|
||||
containment.cpp
|
||||
context.cpp
|
||||
@ -102,11 +95,6 @@ set(plasma_LIB_SRCS
|
||||
# TEST_INCLUDES
|
||||
#)
|
||||
|
||||
kde4_add_ui_files (
|
||||
plasma_LIB_SRCS
|
||||
appletbrowser/kcategorizeditemsviewbase.ui
|
||||
)
|
||||
|
||||
if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
||||
MESSAGE(STATUS "Adding support for OpenGL applets to libplasma")
|
||||
set(plasma_LIB_SRCS
|
||||
@ -151,7 +139,6 @@ set(plasma_LIB_INCLUDES
|
||||
animationdriver.h
|
||||
animator.h
|
||||
applet.h
|
||||
appletbrowser.h
|
||||
configxml.h
|
||||
containment.h
|
||||
context.h
|
||||
@ -226,7 +213,6 @@ includes/AbstractRunner
|
||||
includes/AnimationDriver
|
||||
includes/Animator
|
||||
includes/Applet
|
||||
includes/AppletBrowser
|
||||
includes/AppletScript
|
||||
includes/CheckBox
|
||||
includes/ComboBox
|
||||
|
@ -1,481 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "plasma/appletbrowser.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
#include <KAction>
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <KMenu>
|
||||
#include <KPageWidgetItem>
|
||||
#include <KPushButton>
|
||||
#include <KServiceTypeTrader>
|
||||
#include <KStandardAction>
|
||||
|
||||
#include "plasma/applet.h"
|
||||
#include "plasma/corona.h"
|
||||
#include "plasma/containment.h"
|
||||
#include "plasma/appletbrowser/kcategorizeditemsview_p.h"
|
||||
#include "plasma/appletbrowser/plasmaappletitemmodel_p.h"
|
||||
#include "plasma/appletbrowser/openwidgetassistant_p.h"
|
||||
#include "plasma/private/packages_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AppletBrowserWidgetPrivate
|
||||
{
|
||||
public:
|
||||
AppletBrowserWidgetPrivate(AppletBrowserWidget *w)
|
||||
: q(w),
|
||||
containment(0),
|
||||
appletList(0),
|
||||
config("plasmarc"),
|
||||
configGroup(&config, "Applet Browser"),
|
||||
itemModel(configGroup, w),
|
||||
filterModel(w)
|
||||
{
|
||||
}
|
||||
|
||||
void initFilters();
|
||||
void init();
|
||||
void initRunningApplets();
|
||||
void containmentDestroyed();
|
||||
|
||||
/**
|
||||
* Tracks a new running applet
|
||||
*/
|
||||
void appletAdded(Plasma::Applet *applet);
|
||||
|
||||
/**
|
||||
* A running applet is no more
|
||||
*/
|
||||
void appletRemoved(Plasma::Applet *applet);
|
||||
|
||||
AppletBrowserWidget *q;
|
||||
QString application;
|
||||
Plasma::Containment *containment;
|
||||
KCategorizedItemsView *appletList;
|
||||
QHash<QString, int> runningApplets; // applet name => count
|
||||
//extra hash so we can look up the names of deleted applets
|
||||
QHash<Plasma::Applet *,QString> appletNames;
|
||||
|
||||
KConfig config;
|
||||
KConfigGroup configGroup;
|
||||
|
||||
PlasmaAppletItemModel itemModel;
|
||||
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
|
||||
};
|
||||
|
||||
void AppletBrowserWidgetPrivate::initFilters()
|
||||
{
|
||||
filterModel.clear();
|
||||
|
||||
filterModel.addFilter(i18n("All Widgets"),
|
||||
KCategorizedItemsViewModels::Filter(), KIcon("plasma"));
|
||||
|
||||
// Recommended emblems and filters
|
||||
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]caption");
|
||||
QMapIterator<QString, QString> i(configGroup.entryMap());
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!rx.exactMatch(i.key())) {
|
||||
continue;
|
||||
}
|
||||
//kDebug() << "These are the key/vals in rc file " << rx.cap(1) << "\n";
|
||||
|
||||
QString id = rx.cap(1);
|
||||
QString caption = configGroup.readEntry("recommended." + id + ".caption");
|
||||
QString icon = configGroup.readEntry("recommended." + id + ".icon");
|
||||
QString plugins = configGroup.readEntry("recommended." + id + ".plugins");
|
||||
|
||||
appletList->addEmblem(i18n("Recommended by %1", caption), KIcon(icon),
|
||||
KCategorizedItemsViewModels::Filter("recommended." + id, true));
|
||||
filterModel.addFilter(i18n("Recommended by %1", caption),
|
||||
KCategorizedItemsViewModels::Filter("recommended." + id, true),
|
||||
KIcon(icon));
|
||||
}
|
||||
|
||||
// Filters: Special
|
||||
filterModel.addFilter(i18n("My Favorite Widgets"),
|
||||
KCategorizedItemsViewModels::Filter("favorite", true),
|
||||
KIcon("bookmarks"));
|
||||
filterModel.addFilter(i18n("Widgets I Have Used Before"),
|
||||
KCategorizedItemsViewModels::Filter("used", true),
|
||||
KIcon("view-history"));
|
||||
filterModel.addFilter(i18n("Currently Running Widgets"),
|
||||
KCategorizedItemsViewModels::Filter("running", true),
|
||||
KIcon("view-history"));
|
||||
|
||||
filterModel.addSeparator(i18n("Categories:"));
|
||||
|
||||
foreach (const QString &category, Plasma::Applet::listCategories(application)) {
|
||||
filterModel.addFilter(category,
|
||||
KCategorizedItemsViewModels::Filter("category", category));
|
||||
}
|
||||
}
|
||||
|
||||
AppletBrowserWidget::AppletBrowserWidget(QWidget * parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f),
|
||||
d(new AppletBrowserWidgetPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
AppletBrowserWidget::~AppletBrowserWidget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void AppletBrowserWidgetPrivate::init()
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(q);
|
||||
|
||||
appletList = new KCategorizedItemsView(q);
|
||||
QObject::connect(appletList, SIGNAL(doubleClicked(const QModelIndex &)), q, SLOT(addApplet()));
|
||||
layout->addWidget(appletList);
|
||||
|
||||
// Other Emblems
|
||||
appletList->addEmblem(i18n("Widgets I Have Used Before"), KIcon("view-history"),
|
||||
KCategorizedItemsViewModels::Filter("used", true));
|
||||
|
||||
initFilters();
|
||||
appletList->setFilterModel(&filterModel);
|
||||
|
||||
// Other models
|
||||
appletList->setItemModel(&itemModel);
|
||||
initRunningApplets();
|
||||
|
||||
q->setLayout(layout);
|
||||
}
|
||||
|
||||
void AppletBrowserWidgetPrivate::initRunningApplets()
|
||||
{
|
||||
//get applets from corona, count them, send results to model
|
||||
if (!containment) {
|
||||
return;
|
||||
}
|
||||
|
||||
//kDebug() << runningApplets.count();
|
||||
Plasma::Corona *c = containment->corona();
|
||||
|
||||
//we've tried our best to get a corona
|
||||
//we don't want just one containment, we want them all
|
||||
if (!c) {
|
||||
kDebug() << "can't happen";
|
||||
return;
|
||||
}
|
||||
|
||||
appletNames.clear();
|
||||
runningApplets.clear();
|
||||
QList<Containment*> containments = c->containments();
|
||||
foreach (Containment *containment, containments) {
|
||||
QObject::connect(containment, SIGNAL(appletAdded(Plasma::Applet*,QPointF)), q, SLOT(appletAdded(Plasma::Applet*)));
|
||||
QObject::connect(containment, SIGNAL(appletRemoved(Plasma::Applet*)), q, SLOT(appletRemoved(Plasma::Applet*)));
|
||||
|
||||
foreach (Applet *applet, containment->applets()) {
|
||||
runningApplets[applet->name()]++;
|
||||
}
|
||||
}
|
||||
|
||||
//kDebug() << runningApplets;
|
||||
itemModel.setRunningApplets(runningApplets);
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::setApplication(const QString &app)
|
||||
{
|
||||
d->application = app;
|
||||
d->initFilters();
|
||||
d->itemModel.setApplication(app);
|
||||
|
||||
//FIXME: AFAIK this shouldn't be necessary ... but here it is. need to find out what in that
|
||||
// maze of models and views is screwing up
|
||||
d->appletList->setItemModel(&d->itemModel);
|
||||
|
||||
//kDebug() << d->runningApplets;
|
||||
d->itemModel.setRunningApplets(d->runningApplets);
|
||||
}
|
||||
|
||||
QString AppletBrowserWidget::application()
|
||||
{
|
||||
return d->application;
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::setContainment(Plasma::Containment *containment)
|
||||
{
|
||||
if (d->containment != containment) {
|
||||
if (d->containment) {
|
||||
d->containment->disconnect(this);
|
||||
}
|
||||
|
||||
d->containment = containment;
|
||||
|
||||
if (d->containment) {
|
||||
connect(d->containment, SIGNAL(destroyed(QObject*)), this, SLOT(containmentDestroyed()));
|
||||
}
|
||||
|
||||
d->initRunningApplets();
|
||||
}
|
||||
}
|
||||
|
||||
Containment *AppletBrowserWidget::containment() const
|
||||
{
|
||||
return d->containment;
|
||||
}
|
||||
|
||||
void AppletBrowserWidgetPrivate::containmentDestroyed()
|
||||
{
|
||||
containment = 0;
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::addApplet()
|
||||
{
|
||||
if (!d->containment) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AbstractItem *item, d->appletList->selectedItems()) {
|
||||
PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) item;
|
||||
//kDebug() << "Adding applet " << selectedItem->name() << "to containment";
|
||||
d->containment->addApplet(selectedItem->pluginName(), selectedItem->arguments());
|
||||
}
|
||||
}
|
||||
|
||||
void AppletBrowserWidgetPrivate::appletAdded(Plasma::Applet *applet)
|
||||
{
|
||||
QString name = applet->name();
|
||||
//kDebug() << name;
|
||||
|
||||
runningApplets[name]++;
|
||||
appletNames.insert(applet, name);
|
||||
itemModel.setRunningApplets(name, runningApplets[name]);
|
||||
}
|
||||
|
||||
void AppletBrowserWidgetPrivate::appletRemoved(Plasma::Applet *applet)
|
||||
{
|
||||
//kDebug() << (QObject*)applet;
|
||||
Plasma::Applet *a = (Plasma::Applet *)applet; //don't care if it's valid, just need the address
|
||||
|
||||
QString name = appletNames.take(a);
|
||||
|
||||
int count = 0;
|
||||
if (runningApplets.contains(name)) {
|
||||
count = runningApplets[name] - 1;
|
||||
|
||||
if (count < 1) {
|
||||
runningApplets.remove(name);
|
||||
} else {
|
||||
runningApplets[name] = count;
|
||||
}
|
||||
}
|
||||
|
||||
itemModel.setRunningApplets(name, count);
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::destroyApplets(const QString &name)
|
||||
{
|
||||
if (!d->containment) {
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::Corona *c = d->containment->corona();
|
||||
|
||||
//we've tried our best to get a corona
|
||||
//we don't want just one containment, we want them all
|
||||
if (!c) {
|
||||
kDebug() << "can't happen";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Containment *containment, c->containments()) {
|
||||
QList<Applet*> applets = containment->applets();
|
||||
foreach (Applet *applet, applets) {
|
||||
if (applet->name() == name) {
|
||||
d->appletNames.remove(applet);
|
||||
applet->disconnect(this);
|
||||
applet->destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d->runningApplets.remove(name);
|
||||
d->itemModel.setRunningApplets(name, 0);
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::downloadWidgets(const QString &type)
|
||||
{
|
||||
//kDebug() << type;
|
||||
PackageStructure *installer = 0;
|
||||
|
||||
if (!type.isEmpty()) {
|
||||
QString constraint = QString("'%1' == [X-KDE-PluginInfo-Name]").arg(type);
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure",
|
||||
constraint);
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
kDebug() << "could not find requested PackageStructure plugin" << type;
|
||||
} else {
|
||||
KService::Ptr service = offers.first();
|
||||
QString error;
|
||||
installer = service->createInstance<Plasma::PackageStructure>(topLevelWidget(),
|
||||
QVariantList(), &error);
|
||||
|
||||
if (installer) {
|
||||
connect(installer, SIGNAL(newWidgetBrowserFinished()),
|
||||
installer, SLOT(deleteLater()));
|
||||
} else {
|
||||
kDebug() << "found, but could not load requested PackageStructure plugin" << type
|
||||
<< "; reported error was" << error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!installer) {
|
||||
// we don't need to delete the default Applet::packageStructure as that
|
||||
// belongs to the applet
|
||||
installer = new PlasmoidPackage();
|
||||
}
|
||||
|
||||
installer->createNewWidgetBrowser(this);
|
||||
}
|
||||
|
||||
void AppletBrowserWidget::openWidgetFile()
|
||||
{
|
||||
// TODO: if we already have one of these showing and the user clicks to
|
||||
// add it again, show the same window?
|
||||
OpenWidgetAssistant *assistant = new OpenWidgetAssistant(topLevelWidget());
|
||||
assistant->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
assistant->show();
|
||||
}
|
||||
|
||||
class AppletBrowserPrivate
|
||||
{
|
||||
public:
|
||||
void init(AppletBrowser *browser);
|
||||
void populateWidgetsMenu();
|
||||
|
||||
AppletBrowser *q;
|
||||
AppletBrowserWidget *widget;
|
||||
QMenu *widgetsMenu;
|
||||
};
|
||||
|
||||
void AppletBrowserPrivate::populateWidgetsMenu()
|
||||
{
|
||||
if (!widgetsMenu->actions().isEmpty()) {
|
||||
// already populated.
|
||||
return;
|
||||
}
|
||||
|
||||
QSignalMapper *mapper = new QSignalMapper(q);
|
||||
QObject::connect(mapper, SIGNAL(mapped(QString)), widget, SLOT(downloadWidgets(QString)));
|
||||
|
||||
QAction *action = new QAction(KIcon("applications-internet"),
|
||||
i18n("Download New Plasma Widgets"), q);
|
||||
QObject::connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map()));
|
||||
mapper->setMapping(action, QString());
|
||||
widgetsMenu->addAction(action);
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure");
|
||||
foreach (const KService::Ptr service, offers) {
|
||||
//kDebug() << service->property("X-Plasma-ProvidesWidgetBrowser");
|
||||
if (service->property("X-Plasma-ProvidesWidgetBrowser").toBool()) {
|
||||
QAction *action = new QAction(KIcon("applications-internet"),
|
||||
i18n("Download New %1", service->name()), q);
|
||||
widgetsMenu->addAction(action);
|
||||
mapper->setMapping(action, service->property("X-KDE-PluginInfo-Name").toString());
|
||||
}
|
||||
}
|
||||
|
||||
widgetsMenu->addSeparator();
|
||||
|
||||
action = new QAction(KIcon("package-x-generic"),
|
||||
i18n("Install A Widget From A Local File..."), q);
|
||||
QObject::connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile()));
|
||||
widgetsMenu->addAction(action);
|
||||
}
|
||||
|
||||
void AppletBrowserPrivate::init(AppletBrowser *browser)
|
||||
{
|
||||
q = browser;
|
||||
widget = new AppletBrowserWidget(q);
|
||||
|
||||
q->setMainWidget(widget);
|
||||
q->setWindowTitle(i18n("Widgets"));
|
||||
|
||||
q->setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
|
||||
q->setButtonText(KDialog::Apply, i18n("Add Widget"));
|
||||
q->setButtonText(KDialog::User1, i18n("Install New Widgets"));
|
||||
|
||||
widgetsMenu = new KMenu(i18n("Get New Widgets"), q);
|
||||
QObject::connect(widgetsMenu, SIGNAL(aboutToShow()), q, SLOT(populateWidgetsMenu()));
|
||||
q->button(KDialog::User1)->setMenu(widgetsMenu);
|
||||
|
||||
q->setButtonToolTip(KDialog::Close, i18n("Close the dialog"));
|
||||
q->setButtonWhatsThis(KDialog::Close, i18n("<qt>When clicking <b>Close</b>, this dialog will be closed with no further action taken.</qt>"));
|
||||
q->setButtonToolTip(KDialog::Apply, i18n("Add selected widgets"));
|
||||
q->setButtonWhatsThis(KDialog::Apply, i18n("<qt>When clicking <b>Add Widget</b>, the selected widgets will be added to your desktop.</qt>"));
|
||||
q->setButtonToolTip(KDialog::User1, i18n("Install new widgets"));
|
||||
q->setButtonWhatsThis(KDialog::User1, i18n("<qt>Selecting <b>Get New Widgets</b> will show a window that allows you to download new widgets directly from the Internet, while Install From File allows you to add new widgets from files you have on disk.</qt>"));
|
||||
|
||||
QObject::connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet()));
|
||||
|
||||
q->setInitialSize(QSize(400, 600));
|
||||
KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog");
|
||||
q->restoreDialogSize(cg);
|
||||
}
|
||||
|
||||
AppletBrowser::AppletBrowser(QWidget * parent, Qt::WindowFlags f)
|
||||
: KDialog(parent, f),
|
||||
d(new AppletBrowserPrivate)
|
||||
{
|
||||
d->init(this);
|
||||
}
|
||||
|
||||
AppletBrowser::~AppletBrowser()
|
||||
{
|
||||
KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog");
|
||||
saveDialogSize(cg);
|
||||
}
|
||||
|
||||
void AppletBrowser::setApplication(const QString &app)
|
||||
{
|
||||
d->widget->setApplication(app);
|
||||
}
|
||||
|
||||
QString AppletBrowser::application()
|
||||
{
|
||||
return d->widget->application();
|
||||
}
|
||||
|
||||
void AppletBrowser::setContainment(Plasma::Containment *containment)
|
||||
{
|
||||
d->widget->setContainment(containment);
|
||||
}
|
||||
|
||||
Containment *AppletBrowser::containment() const
|
||||
{
|
||||
return d->widget->containment();
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "appletbrowser.moc"
|
120
appletbrowser.h
120
appletbrowser.h
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_APPLETBROWSER_H
|
||||
#define PLASMA_APPLETBROWSER_H
|
||||
|
||||
#include <KDE/KDialog>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Corona;
|
||||
class Containment;
|
||||
class Applet;
|
||||
class AppletBrowserPrivate;
|
||||
class AppletBrowserWidgetPrivate;
|
||||
|
||||
class PLASMA_EXPORT AppletBrowserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppletBrowserWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~AppletBrowserWidget();
|
||||
|
||||
void setApplication(const QString &application = QString());
|
||||
QString application();
|
||||
|
||||
/**
|
||||
* Changes the current default containment to add applets to
|
||||
*
|
||||
* @arg containment the new default
|
||||
*/
|
||||
void setContainment(Plasma::Containment *containment);
|
||||
|
||||
/**
|
||||
* @return the current default containment to add applets to
|
||||
*/
|
||||
Containment *containment() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Adds currently selected applets
|
||||
*/
|
||||
void addApplet();
|
||||
|
||||
/**
|
||||
* Destroy all applets with this name
|
||||
*/
|
||||
void destroyApplets(const QString &name);
|
||||
|
||||
/**
|
||||
* Launches a download dialog to retrieve new applets from the Internet
|
||||
*
|
||||
* @arg type the type of widget to download; an empty string means the default
|
||||
* Plasma widgets will be accessed, any other value should map to a
|
||||
* PackageStructure PluginInfo-Name entry that provides a widget browser.
|
||||
*/
|
||||
void downloadWidgets(const QString &type = QString());
|
||||
|
||||
/**
|
||||
* Opens a file dialog to open a widget from a local file
|
||||
*/
|
||||
void openWidgetFile();
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void appletAdded(Plasma::Applet*))
|
||||
Q_PRIVATE_SLOT(d, void appletRemoved(Plasma::Applet*))
|
||||
Q_PRIVATE_SLOT(d, void containmentDestroyed())
|
||||
|
||||
AppletBrowserWidgetPrivate * const d;
|
||||
};
|
||||
|
||||
class PLASMA_EXPORT AppletBrowser: public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppletBrowser(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~AppletBrowser();
|
||||
|
||||
void setApplication(const QString &application = QString());
|
||||
QString application();
|
||||
|
||||
/**
|
||||
* Changes the current default containment to add applets to
|
||||
*
|
||||
* @arg containment the new default
|
||||
*/
|
||||
void setContainment(Plasma::Containment *containment);
|
||||
|
||||
/**
|
||||
* @return the current default containment to add applets to
|
||||
*/
|
||||
Containment *containment() const;
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void populateWidgetsMenu())
|
||||
AppletBrowserPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif /*APPLETBROWSERWINDOW_H_*/
|
@ -1,16 +0,0 @@
|
||||
* Bug [LOW]: items deselect if a user changes one
|
||||
of the stars of selected items
|
||||
|
||||
Not before it goes into plasma:
|
||||
* Adding multiple items
|
||||
* Dragging the schreenshots of plasmoids
|
||||
* Customized recommended by
|
||||
* GHNS
|
||||
|
||||
Done:
|
||||
* Bug [MEDIUM]: items select when the star is clicked
|
||||
* Feedback on hovering the star
|
||||
* The rest of the dialog - buttons, etc.
|
||||
* Separate (visually) special and normal categories
|
||||
* Applets without an icon - default icon, category icon
|
||||
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kcategorizeditemsview_p.h"
|
||||
|
||||
#define PIX_SIZE 64
|
||||
#define MAX_OFFSET 16
|
||||
#define MAX_COUNT 5
|
||||
|
||||
CustomDragTreeView::CustomDragTreeView(QWidget * parent)
|
||||
: QTreeView(parent) {}
|
||||
|
||||
void CustomDragTreeView::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
Q_UNUSED(supportedActions);
|
||||
|
||||
// TODO: calculate real size for pixmap - using the icon sizes, not fixed
|
||||
// like now
|
||||
|
||||
if (!m_view) {
|
||||
return;
|
||||
}
|
||||
|
||||
QModelIndexList indexes = selectedIndexes();
|
||||
if (indexes.count() > 0) {
|
||||
QMimeData *data = model()->mimeData(indexes);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = PIX_SIZE + (qMin(MAX_COUNT, indexes.count()) * MAX_OFFSET);
|
||||
int off = MAX_OFFSET;
|
||||
if (indexes.count() > MAX_COUNT) {
|
||||
off = (MAX_OFFSET * MAX_COUNT) / indexes.count();
|
||||
}
|
||||
|
||||
//kDebug() << "Size: " << size << " Off: " << off << "\n";
|
||||
|
||||
QPixmap pixmap(size, size);
|
||||
pixmap.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent
|
||||
QPainter painter(&pixmap);
|
||||
QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
|
||||
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
if (index.column() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * item =
|
||||
m_view->getItemByProxyIndex(index);
|
||||
|
||||
if (item) {
|
||||
rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE)));
|
||||
//painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes
|
||||
item->icon().paint(&painter, rect);
|
||||
rect.moveTopLeft(rect.topLeft() + QPoint(off, off));
|
||||
}
|
||||
}
|
||||
painter.end();
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setMimeData(data);
|
||||
drag->start(supportedActions);
|
||||
//drag->setHotSpot(d->pressedPosition - rect.topLeft());
|
||||
//if (drag->start(supportedActions) == Qt::MoveAction)
|
||||
// d->clearOrRemove();
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CUSTOMDRAGTREEVIEW_P_H
|
||||
#define PLASMA_CUSTOMDRAGTREEVIEW_P_H
|
||||
|
||||
#include <QTreeView>
|
||||
#include "kcategorizeditemsviewmodels_p.h"
|
||||
|
||||
class KCategorizedItemsView;
|
||||
|
||||
class CustomDragTreeView: public QTreeView
|
||||
{
|
||||
public:
|
||||
CustomDragTreeView(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void startDrag(Qt::DropActions supportedActions);
|
||||
|
||||
private:
|
||||
KCategorizedItemsView *m_view;
|
||||
|
||||
friend class KCategorizedItemsView;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,217 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kcategorizeditemsview_p.h"
|
||||
#include "kcategorizeditemsviewdelegate_p.h"
|
||||
|
||||
#include <KIcon>
|
||||
#include <KDebug>
|
||||
#include <KAction>
|
||||
#include <KStandardAction>
|
||||
|
||||
#define UNIVERSAL_PADDING 6
|
||||
|
||||
KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f), m_modelCategories(NULL), m_modelFilters(NULL),
|
||||
m_modelItems(NULL), m_modelFilterItems(NULL), m_delegate(NULL),
|
||||
m_viewWidth(0)
|
||||
{
|
||||
setupUi(this);
|
||||
itemsView->m_view = this;
|
||||
|
||||
textSearch->setClickMessage(i18n("Enter search phrase here"));
|
||||
|
||||
textSearch->setFocus();
|
||||
|
||||
connect(textSearch, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(searchTermChanged(QString)));
|
||||
connect(comboFilters, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(filterChanged(int)));
|
||||
|
||||
// we filter "activated" signals to re-emit them only when wanted
|
||||
connect(itemsView, SIGNAL(activated(const QModelIndex &)),
|
||||
this, SLOT(itemActivated(const QModelIndex &)));
|
||||
connect(itemsView, SIGNAL(doubleClicked(const QModelIndex &)),
|
||||
this, SLOT(itemDoubleClicked(const QModelIndex &)));
|
||||
|
||||
connect (itemsView, SIGNAL(clicked(const QModelIndex &)),
|
||||
this, SIGNAL(clicked(const QModelIndex &)));
|
||||
connect (itemsView, SIGNAL(entered(const QModelIndex &)),
|
||||
this, SIGNAL(entered(const QModelIndex &)));
|
||||
connect (itemsView, SIGNAL(pressed(const QModelIndex &)),
|
||||
this, SIGNAL(pressed(const QModelIndex &)));
|
||||
|
||||
itemsView->header()->setVisible(false);
|
||||
|
||||
itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this));
|
||||
//itemsView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
|
||||
connect (m_delegate, SIGNAL(destroyApplets(const QString)),
|
||||
parent, SLOT(destroyApplets(const QString)));
|
||||
|
||||
comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this));
|
||||
|
||||
itemsView->viewport()->setAttribute(Qt::WA_Hover);
|
||||
itemsView->setAlternatingRowColors(true);
|
||||
|
||||
QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this);
|
||||
addAction(find);
|
||||
}
|
||||
|
||||
KCategorizedItemsView::~KCategorizedItemsView()
|
||||
{
|
||||
delete m_modelFilterItems;
|
||||
delete m_delegate;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::resizeEvent (QResizeEvent *event)
|
||||
{
|
||||
updateColumnsWidth();
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
bool KCategorizedItemsView::event (QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::PolishRequest:
|
||||
case QEvent::Polish:
|
||||
updateColumnsWidth(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setFilterModel(QStandardItemModel *model)
|
||||
{
|
||||
comboFilters->setModel(model);
|
||||
m_modelFilters = model;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setItemModel(QStandardItemModel *model)
|
||||
{
|
||||
if (!m_modelFilterItems) {
|
||||
m_modelFilterItems = new DefaultItemFilterProxyModel(this);
|
||||
connect(m_modelFilterItems, SIGNAL(searchTermChanged(QString)),
|
||||
this, SLOT(slotSearchTermChanged(QString)));
|
||||
}
|
||||
|
||||
m_modelItems = model;
|
||||
m_modelFilterItems->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_modelFilterItems->setDynamicSortFilter(true);
|
||||
m_modelFilterItems->setSourceModel(m_modelItems);
|
||||
m_modelFilterItems->sort(0);
|
||||
|
||||
itemsView->setModel(m_modelFilterItems);
|
||||
|
||||
if (m_modelFilterItems->rowCount()) {
|
||||
itemsView->verticalScrollBar()->setSingleStep(itemsView->sizeHintForRow(0));
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::searchTermChanged(const QString &text)
|
||||
{
|
||||
kDebug() << "EVENT\n" << text;
|
||||
if (m_modelFilterItems) {
|
||||
m_modelFilterItems->setSearch(text);
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::filterChanged(int index)
|
||||
{
|
||||
if (m_modelFilterItems) {
|
||||
QVariant data = m_modelFilters->item(index)->data();
|
||||
m_modelFilterItems->setFilter(qVariantValue<KCategorizedItemsViewModels::Filter>(data));
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::itemActivated(const QModelIndex &index)
|
||||
{
|
||||
// don't emit activated signal for "favicon" and "remove applet"
|
||||
// columns so double clicking on these columns won't unexpectedly
|
||||
// add an applet to the containment
|
||||
if (index.column() == 1 || index.column() == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit activated(index);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::itemDoubleClicked(const QModelIndex &index)
|
||||
{
|
||||
// don't emit activated signal for "favicon" and "remove applet"
|
||||
// columns so double clicking on these columns won't unexpectedly
|
||||
// add an applet to the containment
|
||||
if (index.column() == 1 || index.column() == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit doubleClicked(index);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::slotSearchTermChanged(const QString &term)
|
||||
{
|
||||
updateColumnsWidth();
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::updateColumnsWidth(bool force)
|
||||
{
|
||||
m_viewWidth = itemsView->viewport()->width();
|
||||
|
||||
if (force) {
|
||||
m_viewWidth -= style()->pixelMetric(QStyle::PM_ScrollBarExtent) + UNIVERSAL_PADDING;
|
||||
}
|
||||
|
||||
itemsView->setColumnWidth(0, m_delegate->columnWidth(0, m_viewWidth));
|
||||
itemsView->setColumnWidth(1, m_delegate->columnWidth(1, m_viewWidth));
|
||||
itemsView->setColumnWidth(2, m_delegate->columnWidth(2, m_viewWidth));
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::addEmblem(const QString &title, const QIcon &icon,
|
||||
const Filter &filter)
|
||||
{
|
||||
m_emblems[title] = QPair<Filter, QIcon>(filter, icon);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::clearEmblems()
|
||||
{
|
||||
m_emblems.clear();
|
||||
}
|
||||
|
||||
AbstractItem *KCategorizedItemsView::getItemByProxyIndex(const QModelIndex &index) const
|
||||
{
|
||||
return (AbstractItem *)m_modelItems->itemFromIndex(m_modelFilterItems->mapToSource(index));
|
||||
}
|
||||
|
||||
QList <AbstractItem *> KCategorizedItemsView::selectedItems() const
|
||||
{
|
||||
QList <AbstractItem *> items;
|
||||
foreach (const QModelIndex &index, itemsView->selectionModel()->selectedIndexes()) {
|
||||
if (index.column() == 0) {
|
||||
items << getItemByProxyIndex(index);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
#include "kcategorizeditemsview_p.moc"
|
||||
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_KCATEGORIZEDITEMSVIEW_P_H
|
||||
#define PLASMA_KCATEGORIZEDITEMSVIEW_P_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtCore/QtCore>
|
||||
|
||||
#include "kcategorizeditemsviewmodels_p.h"
|
||||
|
||||
#include "ui_kcategorizeditemsviewbase.h"
|
||||
|
||||
using namespace KCategorizedItemsViewModels;
|
||||
class KCategorizedItemsViewDelegate;
|
||||
|
||||
/**
|
||||
* QT4 View Widget for displaying a list of categorized items with special
|
||||
* filtering capabilities.
|
||||
*
|
||||
* To use it, you need to implement KCategorizedItemsView::AbstractItem
|
||||
*
|
||||
* For convenience, there are default implementations of category model
|
||||
* (DefaultCategoryModel), filters model (DefaultFilterModel) and the
|
||||
* default item mode (DefaultItemModel), but you do not need to use them.
|
||||
*
|
||||
* One constraint is that DefaultItemModel *must* hold the items that
|
||||
* are subclassed from KCategorizedItemsView::AbstractItem
|
||||
*
|
||||
*/
|
||||
class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit KCategorizedItemsView(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~KCategorizedItemsView();
|
||||
|
||||
void setFilterModel(QStandardItemModel *model); ///< Sets the filters model
|
||||
void setItemModel(QStandardItemModel *model); ///< Sets the item model, as mentioned items must implement AbstractItem class
|
||||
|
||||
void addEmblem(const QString &title, const QIcon &icon, const Filter &filter);
|
||||
void clearEmblems();
|
||||
|
||||
QList < AbstractItem * > selectedItems() const;
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent (QResizeEvent *event) ;
|
||||
virtual bool event (QEvent *event);
|
||||
|
||||
protected slots:
|
||||
void searchTermChanged(const QString &text);
|
||||
void filterChanged(int index);
|
||||
|
||||
private slots:
|
||||
void itemActivated(const QModelIndex &index);
|
||||
void itemDoubleClicked(const QModelIndex &index);
|
||||
void slotSearchTermChanged(const QString &term);
|
||||
|
||||
Q_SIGNALS:
|
||||
void activated(const QModelIndex &index);
|
||||
void clicked(const QModelIndex &index);
|
||||
void doubleClicked(const QModelIndex &index);
|
||||
void entered(const QModelIndex &index);
|
||||
void pressed(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
void updateColumnsWidth(bool force = false);
|
||||
|
||||
QStandardItemModel *m_modelCategories;
|
||||
QStandardItemModel *m_modelFilters;
|
||||
QStandardItemModel *m_modelItems;
|
||||
|
||||
DefaultItemFilterProxyModel *m_modelFilterItems;
|
||||
KCategorizedItemsViewDelegate *m_delegate;
|
||||
|
||||
int m_viewWidth;
|
||||
|
||||
QMap < QString, QPair < Filter, QIcon > > m_emblems;
|
||||
AbstractItem *getItemByProxyIndex(const QModelIndex &index) const;
|
||||
|
||||
friend class KCategorizedItemsViewDelegate;
|
||||
friend class CustomDragTreeView;
|
||||
};
|
||||
|
||||
//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter)
|
||||
|
||||
#endif
|
@ -1,156 +0,0 @@
|
||||
<ui version="4.0" >
|
||||
<class>KCategorizedItemsViewBase</class>
|
||||
<widget class="QWidget" name="KCategorizedItemsViewBase" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>487</width>
|
||||
<height>528</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="leftMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboFilters" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="KLineEdit" name="textSearch" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frame" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="showClearButton" stdset="0" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line" >
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="CustomDragTreeView" name="itemsView" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="editTriggers" >
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="dragEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode" >
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
</property>
|
||||
<property name="selectionMode" >
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="indentation" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rootIsDecorated" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>klineedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>CustomDragTreeView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>appletbrowser/customdragtreeview_p.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>comboFilters</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>comboFilters</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>textSearch</receiver>
|
||||
<slot>clear()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>438</x>
|
||||
<y>14</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>438</x>
|
||||
<y>38</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -1,369 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kcategorizeditemsviewdelegate_p.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QtCore/QtCore>
|
||||
|
||||
#include <KIconLoader>
|
||||
|
||||
#include "kcategorizeditemsview_p.h"
|
||||
|
||||
#define FAV_ICON_SIZE 24
|
||||
#define EMBLEM_ICON_SIZE 16
|
||||
#define UNIVERSAL_PADDING 6
|
||||
#define FADE_LENGTH 32
|
||||
#define MAIN_ICON_SIZE 48
|
||||
#define DROPDOWN_PADDING 2
|
||||
#define DROPDOWN_SEPARATOR_HEIGHT 32
|
||||
|
||||
KCategorizedItemsViewDelegate::KCategorizedItemsViewDelegate(QObject * parent)
|
||||
: QItemDelegate(parent), m_favoriteIcon("bookmarks"),
|
||||
m_favoriteAddIcon("list-add"), m_removeIcon("list-remove"),
|
||||
m_onFavoriteIconItem(NULL)
|
||||
{
|
||||
m_parent = (KCategorizedItemsView *) parent;
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
KCategorizedItemsViewModels::AbstractItem * item = getItemByProxyIndex(index);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStyleOptionViewItemV4 opt(option);
|
||||
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
|
||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
|
||||
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
paintColMain(painter, option, item);
|
||||
break;
|
||||
case 1:
|
||||
paintColFav(painter, option, item);
|
||||
break;
|
||||
case 2:
|
||||
paintColRemove(painter, option, item);
|
||||
break;
|
||||
default:
|
||||
kDebug() << "unexpected column";
|
||||
}
|
||||
}
|
||||
|
||||
int KCategorizedItemsViewDelegate::calcItemHeight(const QStyleOptionViewItem &option) const
|
||||
{
|
||||
// Painting main column
|
||||
QFont titleFont = option.font;
|
||||
titleFont.setBold(true);
|
||||
titleFont.setPointSize(titleFont.pointSize() + 2);
|
||||
|
||||
int textHeight = QFontInfo(titleFont).pixelSize() + QFontInfo(option.font).pixelSize();
|
||||
//kDebug() << textHeight << qMax(textHeight, MAIN_ICON_SIZE) + 2 * UNIVERSAL_PADDING;
|
||||
return qMax(textHeight, MAIN_ICON_SIZE) + 2 * UNIVERSAL_PADDING;
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColMain(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
const int left = option.rect.left();
|
||||
const int top = option.rect.top();
|
||||
const int width = option.rect.width();
|
||||
const int height = calcItemHeight(option);
|
||||
|
||||
bool leftToRight = (painter->layoutDirection() == Qt::LeftToRight);
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
|
||||
QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))?
|
||||
option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
|
||||
|
||||
// Painting main column
|
||||
QFont titleFont = option.font;
|
||||
titleFont.setBold(true);
|
||||
titleFont.setPointSize(titleFont.pointSize() + 2);
|
||||
|
||||
QPixmap pixmap(width, height);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter p(&pixmap);
|
||||
p.translate(-option.rect.topLeft());
|
||||
|
||||
QLinearGradient gradient;
|
||||
|
||||
QString title = item->name();
|
||||
QString description = item->description();
|
||||
|
||||
// Painting
|
||||
|
||||
// Text
|
||||
int textInner = 2 * UNIVERSAL_PADDING + MAIN_ICON_SIZE;
|
||||
|
||||
p.setPen(foregroundColor);
|
||||
p.setFont(titleFont);
|
||||
p.drawText(left + (leftToRight ? textInner : 0),
|
||||
top, width - textInner, height / 2,
|
||||
Qt::AlignBottom | Qt::AlignLeft, title);
|
||||
p.setFont(option.font);
|
||||
p.drawText(left + (leftToRight ? textInner : 0),
|
||||
top + height / 2,
|
||||
width - textInner, height / 2,
|
||||
Qt::AlignTop | Qt::AlignLeft, description);
|
||||
|
||||
// Main icon
|
||||
item->icon().paint(
|
||||
&p,
|
||||
leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE,
|
||||
top + UNIVERSAL_PADDING,
|
||||
MAIN_ICON_SIZE,
|
||||
MAIN_ICON_SIZE,
|
||||
Qt::AlignCenter, iconMode);
|
||||
|
||||
// Counting the number of emblems for this item
|
||||
int emblemCount = 0;
|
||||
QPair < Filter, QIcon > emblem;
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
++emblemCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Gradient part of the background - fading of the text at the end
|
||||
if (leftToRight) {
|
||||
gradient = QLinearGradient(left + width - UNIVERSAL_PADDING - FADE_LENGTH, 0,
|
||||
left + width - UNIVERSAL_PADDING, 0);
|
||||
gradient.setColorAt(0, Qt::white);
|
||||
gradient.setColorAt(1, Qt::transparent);
|
||||
} else {
|
||||
gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
|
||||
left + UNIVERSAL_PADDING + FADE_LENGTH, 0);
|
||||
gradient.setColorAt(0, Qt::transparent);
|
||||
gradient.setColorAt(1, Qt::white);
|
||||
}
|
||||
|
||||
QRect paintRect = option.rect;
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p.fillRect(paintRect, gradient);
|
||||
|
||||
if (leftToRight) {
|
||||
gradient.setStart(
|
||||
left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - FADE_LENGTH, 0);
|
||||
gradient.setFinalStop(
|
||||
left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
} else {
|
||||
gradient.setStart(
|
||||
left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
gradient.setFinalStop(
|
||||
left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + FADE_LENGTH, 0);
|
||||
}
|
||||
paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2);
|
||||
p.fillRect(paintRect, gradient);
|
||||
|
||||
// Emblems icons
|
||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
int emblemLeft = leftToRight ? (left + width - EMBLEM_ICON_SIZE) : left; // - FAV_ICON_SIZE - 2 * UNIVERSAL_PADDING
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
emblem.second.paint(&p,
|
||||
emblemLeft, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
if (leftToRight) {
|
||||
emblemLeft -= UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
|
||||
} else {
|
||||
emblemLeft += UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
p.end();
|
||||
|
||||
painter->drawPixmap(option.rect.topLeft(), pixmap);
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColFav(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
int left = option.rect.left();
|
||||
int top = option.rect.top();
|
||||
int width = option.rect.width();
|
||||
|
||||
// Painting favorite icon column
|
||||
|
||||
if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == item) {
|
||||
m_onFavoriteIconItem = NULL;
|
||||
}
|
||||
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
if (!item->isFavorite()) {
|
||||
iconMode = QIcon::Disabled;
|
||||
} else if (option.state & QStyle::State_MouseOver) {
|
||||
iconMode = QIcon::Active;
|
||||
}
|
||||
|
||||
m_favoriteIcon.paint(
|
||||
painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING,
|
||||
top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE,
|
||||
FAV_ICON_SIZE,
|
||||
Qt::AlignCenter,
|
||||
iconMode);
|
||||
|
||||
const KIcon &icon = (item->isFavorite())? m_removeIcon : m_favoriteAddIcon;
|
||||
|
||||
if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item)) {
|
||||
icon.paint(
|
||||
painter,
|
||||
left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING,
|
||||
top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE,
|
||||
EMBLEM_ICON_SIZE,
|
||||
Qt::AlignCenter,
|
||||
iconMode);
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColRemove(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
// Painting remove icon column
|
||||
int running = item->running();
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
|
||||
int left = option.rect.left();
|
||||
int top = option.rect.top();
|
||||
int width = option.rect.width();
|
||||
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
iconMode = QIcon::Active;
|
||||
}
|
||||
|
||||
m_removeIcon.paint(painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
if (running == 1) {
|
||||
return;
|
||||
}
|
||||
//paint number
|
||||
QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))?
|
||||
option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
|
||||
painter->setPen(foregroundColor);
|
||||
painter->setFont(option.font);
|
||||
painter->drawText(
|
||||
left + UNIVERSAL_PADDING, //FIXME might be wrong
|
||||
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
|
||||
width - 2 * UNIVERSAL_PADDING, MAIN_ICON_SIZE / 2,
|
||||
Qt::AlignCenter, QString::number(running));
|
||||
}
|
||||
|
||||
bool KCategorizedItemsViewDelegate::editorEvent(
|
||||
QEvent *event, QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
KCategorizedItemsViewModels::AbstractItem *item = getItemByProxyIndex(index);
|
||||
if (index.column() == 1) {
|
||||
m_onFavoriteIconItem = item;
|
||||
item->setFavorite(!item->isFavorite());
|
||||
return true;
|
||||
} else if (index.column() == 2 && item->running()) {
|
||||
item->setRunning(0);
|
||||
emit destroyApplets(item->name());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
int width = (index.column() == 0) ? 0 : FAV_ICON_SIZE;
|
||||
return QSize(width, calcItemHeight(option));
|
||||
}
|
||||
|
||||
int KCategorizedItemsViewDelegate::columnWidth (int column, int viewWidth) const {
|
||||
if (column != 0) {
|
||||
return FAV_ICON_SIZE + 2 * UNIVERSAL_PADDING;
|
||||
} else {
|
||||
return viewWidth - 2 * columnWidth(1, viewWidth);
|
||||
}
|
||||
}
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem *KCategorizedItemsViewDelegate::getItemByProxyIndex(
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
return (AbstractItem *)m_parent->m_modelItems->itemFromIndex(m_parent->m_modelFilterItems->mapToSource(index));
|
||||
}
|
||||
|
||||
// KCategorizedItemsViewFilterDelegate
|
||||
|
||||
KCategorizedItemsViewFilterDelegate::KCategorizedItemsViewFilterDelegate(QObject *parent)
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
kDebug() << "KCategorizedItemsViewFilterDelegate(QObject *parent)\n";
|
||||
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewFilterDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (index.flags() & Qt::ItemIsEnabled) {
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
} else {
|
||||
QStyleOptionViewItem separatorOption(option);
|
||||
int height = QItemDelegate::sizeHint(option, index).height() + 2 * DROPDOWN_PADDING;
|
||||
|
||||
separatorOption.state &= ~(QStyle::State_Selected |
|
||||
QStyle::State_MouseOver |
|
||||
QStyle::State_HasFocus);
|
||||
separatorOption.rect.setTop(
|
||||
separatorOption.rect.top() + separatorOption.rect.height() - height);
|
||||
separatorOption.rect.setHeight(height);
|
||||
QItemDelegate::paint(painter, separatorOption, index);
|
||||
/*painter->drawLine(
|
||||
option.rect.left(),
|
||||
option.rect.top() + 1,
|
||||
option.rect.left() + option.rect.width(),
|
||||
option.rect.top() + 1);*/
|
||||
}
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewFilterDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QSize size = QItemDelegate::sizeHint(option, index);
|
||||
if (index.flags() & Qt::ItemIsEnabled) {
|
||||
size.setHeight(size.height() + 2 * DROPDOWN_PADDING);
|
||||
} else {
|
||||
size.setHeight(DROPDOWN_SEPARATOR_HEIGHT);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
#include "kcategorizeditemsviewdelegate_p.moc"
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_KCATEGORIZEDITEMSVIEWDELEGATE_P_H
|
||||
#define PLASMA_KCATEGORIZEDITEMSVIEWDELEGATE_P_H
|
||||
|
||||
#include <QtCore/QtCore>
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include "kcategorizeditemsviewmodels_p.h"
|
||||
|
||||
class KCategorizedItemsView;
|
||||
|
||||
namespace KCategorizedItemsViewModels {
|
||||
class AbstractItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate for displaying the items
|
||||
*/
|
||||
class KCategorizedItemsViewDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
int columnWidth (int column, int viewWidth) const;
|
||||
|
||||
bool editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index);
|
||||
|
||||
Q_SIGNALS:
|
||||
void destroyApplets(const QString name);
|
||||
private:
|
||||
|
||||
KCategorizedItemsView *m_parent;
|
||||
KIcon m_favoriteIcon;
|
||||
KIcon m_favoriteAddIcon;
|
||||
KIcon m_removeIcon;
|
||||
|
||||
mutable KCategorizedItemsViewModels::AbstractItem *m_onFavoriteIconItem;
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem *getItemByProxyIndex(const QModelIndex & index) const;
|
||||
void paintColMain(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColFav(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColRemove(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
|
||||
int calcItemHeight(const QStyleOptionViewItem &option) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delegate for displaying the filters/categories
|
||||
*/
|
||||
class KCategorizedItemsViewFilterDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewFilterDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif /*KCATEGORIZEDITEMSVIEWDELEGATE_H_*/
|
@ -1,270 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kcategorizeditemsviewmodels_p.h"
|
||||
#include <klocale.h>
|
||||
|
||||
namespace KCategorizedItemsViewModels {
|
||||
|
||||
// AbstractItem
|
||||
|
||||
QString AbstractItem::name() const
|
||||
{
|
||||
return text();
|
||||
}
|
||||
|
||||
QString AbstractItem::description() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool AbstractItem::isFavorite() const
|
||||
{
|
||||
return passesFiltering(Filter("favorite", true));
|
||||
}
|
||||
|
||||
int AbstractItem::running() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AbstractItem::matches(const QString &pattern) const
|
||||
{
|
||||
return
|
||||
name().contains(pattern, Qt::CaseInsensitive) ||
|
||||
description().contains(pattern, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
// DefaultFilterModel
|
||||
|
||||
DefaultFilterModel::DefaultFilterModel(QObject *parent) :
|
||||
QStandardItemModel(0, 1, parent)
|
||||
{
|
||||
setHeaderData(1, Qt::Horizontal, i18n("Filters"));
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addFilter(const QString &caption, const Filter &filter, const KIcon &icon)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem *item = new QStandardItem(caption);
|
||||
item->setData(qVariantFromValue<Filter>(filter));
|
||||
if (!icon.isNull()) {
|
||||
item->setIcon(icon);
|
||||
}
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addSeparator(const QString &caption)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem *item = new QStandardItem(caption);
|
||||
item->setEnabled(false);
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
}
|
||||
|
||||
// DefaultItemFilterProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::DefaultItemFilterProxyModel(QObject *parent) :
|
||||
QSortFilterProxyModel(parent), m_innerModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
{
|
||||
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(sourceModel);
|
||||
|
||||
if (!model) {
|
||||
kWarning() << "Expecting a QStandardItemModel!";
|
||||
return;
|
||||
}
|
||||
|
||||
m_innerModel.setSourceModel(model);
|
||||
QSortFilterProxyModel::setSourceModel(&m_innerModel);
|
||||
}
|
||||
|
||||
QStandardItemModel *DefaultItemFilterProxyModel::sourceModel() const
|
||||
{
|
||||
return m_innerModel.sourceModel();
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::columnCount(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 3;
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
return m_innerModel.data(index, (index.column() == 1), role);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
QStandardItemModel *model = (QStandardItemModel *) sourceModel();
|
||||
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
|
||||
AbstractItem *item = (AbstractItem *) model->itemFromIndex(index);
|
||||
//kDebug() << "ITEM " << (item ? "IS NOT " : "IS") << " NULL\n";
|
||||
|
||||
return
|
||||
(m_filter.first.isEmpty() || item->passesFiltering(m_filter)) &&
|
||||
(m_searchPattern.isEmpty() || item->matches(m_searchPattern));
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
return
|
||||
sourceModel()->data(left).toString().localeAwareCompare(
|
||||
sourceModel()->data(right).toString()) < 0;
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSearch(const QString &pattern)
|
||||
{
|
||||
m_searchPattern = pattern;
|
||||
invalidateFilter();
|
||||
emit searchTermChanged(pattern);
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setFilter(const Filter &filter)
|
||||
{
|
||||
m_filter = filter;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
// DefaultItemFilterProxyModel::InnerProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::InnerProxyModel::InnerProxyModel(QObject *parent) :
|
||||
QAbstractItemModel(parent), m_sourceModel(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Qt::ItemFlags DefaultItemFilterProxyModel::InnerProxyModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return 0;
|
||||
}
|
||||
return m_sourceModel->flags(index);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex &index, bool favoriteColumn, int role) const
|
||||
{
|
||||
Q_UNUSED(favoriteColumn);
|
||||
return data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return QVariant();
|
||||
}
|
||||
return m_sourceModel->data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_UNUSED(orientation);
|
||||
Q_UNUSED(role);
|
||||
return QVariant(section);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return 0;
|
||||
}
|
||||
return m_sourceModel->rowCount(parent);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setData(
|
||||
const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return false;
|
||||
}
|
||||
return m_sourceModel->setData(index, value, role);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData(
|
||||
int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
Q_UNUSED(section);
|
||||
Q_UNUSED(value);
|
||||
Q_UNUSED(orientation);
|
||||
Q_UNUSED(role);
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::index(
|
||||
int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
if (!m_sourceModel) {
|
||||
return QModelIndex();
|
||||
}
|
||||
return m_sourceModel->index(row, 0, parent);
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return QModelIndex();
|
||||
}
|
||||
return m_sourceModel->parent(index);
|
||||
}
|
||||
|
||||
QMimeData *DefaultItemFilterProxyModel::InnerProxyModel::mimeData(
|
||||
const QModelIndexList &indexes) const
|
||||
{
|
||||
if (!m_sourceModel) {
|
||||
return NULL;
|
||||
}
|
||||
return m_sourceModel->mimeData(indexes);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::columnCount(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 3; //FIXME: a hardcoded magic number that appears in two places CANNOT be good
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(QStandardItemModel *sourceModel)
|
||||
{
|
||||
m_sourceModel = sourceModel;
|
||||
}
|
||||
|
||||
QStandardItemModel *DefaultItemFilterProxyModel::InnerProxyModel::sourceModel() const
|
||||
{
|
||||
return m_sourceModel;
|
||||
}
|
||||
|
||||
// DefaultItemModel
|
||||
|
||||
DefaultItemModel::DefaultItemModel(QObject *parent) :
|
||||
QStandardItemModel(parent) {}
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H
|
||||
#define PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtCore/QtCore>
|
||||
#include <KIcon>
|
||||
#include <KDebug>
|
||||
namespace KCategorizedItemsViewModels {
|
||||
|
||||
typedef QPair<QString, QVariant> Filter;
|
||||
|
||||
/**
|
||||
* Abstract class that needs to be implemented and used with the ItemModel
|
||||
*/
|
||||
class AbstractItem : public QStandardItem
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns a localized string - name of the item
|
||||
*/
|
||||
virtual QString name() const;
|
||||
|
||||
/**
|
||||
* Returns a localized string - description of the item
|
||||
*/
|
||||
virtual QString description() const;
|
||||
|
||||
/**
|
||||
* Returns if the item is flagged as favorite
|
||||
* Default implementation checks if the item passes the Filter("favorite", "1") filter
|
||||
*/
|
||||
virtual bool isFavorite() const;
|
||||
|
||||
/**
|
||||
* Returns the item's number of running applets
|
||||
* Default implementation just returns 0
|
||||
*/
|
||||
virtual int running() const;
|
||||
|
||||
/**
|
||||
* Returns if the item contains string specified by pattern.
|
||||
* Default implementation checks whether name or description contain the
|
||||
* string (not needed to be exactly that string)
|
||||
*/
|
||||
virtual bool matches(const QString &pattern) const;
|
||||
|
||||
/**
|
||||
* sets the favorite flag for the item
|
||||
*/
|
||||
virtual void setFavorite(bool favorite) = 0;
|
||||
/**
|
||||
* sets the number of running applets for the item
|
||||
*/
|
||||
virtual void setRunning(int count) = 0;
|
||||
|
||||
/**
|
||||
* Returns if the item passes the filter specified
|
||||
*/
|
||||
virtual bool passesFiltering(const Filter &filter) const = 0;
|
||||
private:
|
||||
};
|
||||
|
||||
/**
|
||||
* The default implementation of the model containing filters
|
||||
*/
|
||||
class DefaultFilterModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultFilterModel(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Adds a filter to the model
|
||||
* @param caption The localized string to be displayed as a name of the filter
|
||||
* @param filter The filter structure
|
||||
*/
|
||||
void addFilter(const QString &caption, const Filter &filter, const KIcon &icon = KIcon());
|
||||
|
||||
/**
|
||||
* Adds a separator to the model
|
||||
* @param caption The localized string to be displayed as a name of the separator
|
||||
*/
|
||||
void addSeparator(const QString &caption);
|
||||
};
|
||||
|
||||
/**
|
||||
* Default filter proxy model.
|
||||
*/
|
||||
class DefaultItemFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DefaultItemFilterProxyModel(QObject *parent = 0);
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
void setSearch(const QString &pattern);
|
||||
void setFilter(const Filter &filter);
|
||||
|
||||
void setSourceModel(QAbstractItemModel *sourceModel);
|
||||
|
||||
QStandardItemModel *sourceModel() const;
|
||||
|
||||
int columnCount(const QModelIndex &index) const;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void searchTermChanged(const QString &term);
|
||||
|
||||
private:
|
||||
|
||||
class InnerProxyModel : public QAbstractItemModel
|
||||
{
|
||||
public:
|
||||
InnerProxyModel(QObject *parent = 0);
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
QVariant data(const QModelIndex &index, bool favoriteColumn,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation,
|
||||
const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &index) const;
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
|
||||
void setSourceModel(QStandardItemModel *sourceModel);
|
||||
QStandardItemModel *sourceModel() const;
|
||||
|
||||
private:
|
||||
QStandardItemModel *m_sourceModel;
|
||||
};
|
||||
|
||||
Filter m_filter;
|
||||
QString m_searchPattern;
|
||||
InnerProxyModel m_innerModel;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The default implementation of the model containing items. It /is/ QStandardItemModel
|
||||
*/
|
||||
class DefaultItemModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultItemModel(QObject *parent = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(KCategorizedItemsViewModels::Filter)
|
||||
|
||||
#endif /*KCATEGORIZEDITEMSVIEWMODELS_H_*/
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "plasma/appletbrowser/openwidgetassistant_p.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <KDebug>
|
||||
#include <kfilewidget.h>
|
||||
#include <KListWidget>
|
||||
#include <KMessageBox>
|
||||
#include <KService>
|
||||
#include <KServiceTypeTrader>
|
||||
#include <KStandardDirs>
|
||||
|
||||
#include "plasma/packagestructure.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
OpenWidgetAssistant::OpenWidgetAssistant(QWidget *parent)
|
||||
: KAssistantDialog(parent),
|
||||
m_fileDialog(0),
|
||||
m_filePageWidget(0)
|
||||
{
|
||||
QWidget *selectWidget = new QWidget(this);
|
||||
QVBoxLayout *selectLayout = new QVBoxLayout(selectWidget);
|
||||
QLabel *selectLabel = new QLabel(selectWidget);
|
||||
selectLabel->setText(i18n("Select the type of widget to install from the list below."));
|
||||
m_widgetTypeList = new KListWidget(selectWidget);
|
||||
m_widgetTypeList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
//m_widgetTypeList->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
connect(m_widgetTypeList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(next()));
|
||||
connect(m_widgetTypeList, SIGNAL(itemSelectionChanged ()), this, SLOT(slotItemChanged()));
|
||||
|
||||
QString constraint("'Applet' in [X-Plasma-ComponentTypes] and exist [X-Plasma-PackageFormat]");
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint);
|
||||
|
||||
QListWidgetItem * item = new QListWidgetItem(KIcon("plasma"), i18n("Plasmoid: Native plasma widget"), m_widgetTypeList);
|
||||
item->setSelected(true);
|
||||
m_widgetTypeList->setCurrentItem(item);
|
||||
|
||||
foreach (const KService::Ptr &offer, offers) {
|
||||
QString text(offer->name());
|
||||
if (!offer->comment().isEmpty()) {
|
||||
text.append(": ").append(offer->comment());
|
||||
}
|
||||
|
||||
item = new QListWidgetItem(text, m_widgetTypeList);
|
||||
item->setData(PackageStructureRole, offer->property("X-KDE-PluginInfo-Name"));
|
||||
|
||||
if (!offer->icon().isEmpty()) {
|
||||
item->setIcon(KIcon(offer->icon()));
|
||||
}
|
||||
}
|
||||
|
||||
selectLayout->addWidget(selectLabel);
|
||||
selectLayout->addWidget(m_widgetTypeList);
|
||||
|
||||
m_typePage = new KPageWidgetItem(selectWidget, i18n("Install New Widget From File"));
|
||||
m_typePage->setIcon(KIcon("plasma"));
|
||||
addPage(m_typePage);
|
||||
|
||||
m_filePageWidget = new QWidget(this);
|
||||
m_filePage = new KPageWidgetItem(m_filePageWidget, i18n("Select File"));
|
||||
addPage(m_filePage);
|
||||
|
||||
connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(prepPage(KPageWidgetItem*,KPageWidgetItem*)));
|
||||
enableButton(KDialog::Help, false);
|
||||
//connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelpClicked() ) );
|
||||
m_widgetTypeList->setFocus();
|
||||
resize(QSize(560, 400).expandedTo(minimumSizeHint()));
|
||||
}
|
||||
|
||||
void OpenWidgetAssistant::slotItemChanged()
|
||||
{
|
||||
enableButton(KDialog::User2, !m_widgetTypeList->selectedItems().isEmpty());
|
||||
}
|
||||
|
||||
void OpenWidgetAssistant::prepPage(KPageWidgetItem *current, KPageWidgetItem *before)
|
||||
{
|
||||
Q_UNUSED(before);
|
||||
if (m_widgetTypeList->selectedItems().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (current != m_filePage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_fileDialog) {
|
||||
QVBoxLayout *layout = new QVBoxLayout(m_filePageWidget);
|
||||
m_fileDialog = new KFileWidget(KUrl(), m_filePageWidget);
|
||||
m_fileDialog->setOperationMode(KFileWidget::Opening);
|
||||
m_fileDialog->setMode(KFile::File | KFile::ExistingOnly);
|
||||
connect(this, SIGNAL(user1Clicked()), m_fileDialog, SLOT(slotOk()));
|
||||
connect(m_fileDialog, SIGNAL(accepted()), this, SLOT(finished()));
|
||||
//m_fileDialog->setWindowFlags(Qt::Widget);
|
||||
layout->addWidget(m_fileDialog);
|
||||
}
|
||||
|
||||
QListWidgetItem *item = m_widgetTypeList->selectedItems().first();
|
||||
Q_ASSERT(item);
|
||||
|
||||
QString type = item->data(PackageStructureRole).toString();
|
||||
|
||||
m_fileDialog->setFilter(QString());
|
||||
if (!type.isEmpty()) {
|
||||
QString constraint = QString("'%1' == [X-KDE-PluginInfo-Name]").arg(type);
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure", constraint);
|
||||
|
||||
kDebug() << "looking for a Plasma/PackageStructure with" << constraint << type;
|
||||
Q_ASSERT(offers.count() > 0);
|
||||
|
||||
m_packageStructureService = offers.first();
|
||||
QStringList mimes = m_packageStructureService->property("X-Plasma-PackageFileMimetypes").toStringList();
|
||||
|
||||
if (mimes.count() > 0) {
|
||||
m_fileDialog->setMimeFilter(mimes);
|
||||
} else {
|
||||
QString filter = m_packageStructureService->property("X-Plasma-PackageFileFilter").toString();
|
||||
if (!filter.isEmpty()) {
|
||||
m_fileDialog->setFilter(+ '|' + m_packageStructureService->name());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QStringList mimes;
|
||||
mimes << "application/x-plasma";
|
||||
m_fileDialog->setMimeFilter(mimes);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenWidgetAssistant::slotHelpClicked()
|
||||
{
|
||||
//enable it when doc will created
|
||||
}
|
||||
|
||||
void OpenWidgetAssistant::finished()
|
||||
{
|
||||
m_fileDialog->accept(); // how interesting .. accept() must be called before the state is set
|
||||
QString packageFilePath = m_fileDialog->selectedFile();
|
||||
if (packageFilePath.isEmpty()) {
|
||||
//TODO: user visible error handling
|
||||
kDebug() << "hm. no file path?";
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << "selected uri is" << packageFilePath << "of type" << m_fileDialog->currentFilter();
|
||||
PackageStructure *installer = 0;
|
||||
if (m_packageStructureService) {
|
||||
QString error;
|
||||
installer = m_packageStructureService->createInstance<Plasma::PackageStructure>(0, QVariantList(), &error);
|
||||
if (!installer) {
|
||||
kDebug() << "Could not load requested PackageStructure installer "
|
||||
<< m_packageStructureService << ". Error given: " << error;
|
||||
KMessageBox::error(
|
||||
this,
|
||||
i18n("Could not load the required installer %1. "
|
||||
"The error given was: %2",
|
||||
m_packageStructureService, error),
|
||||
i18n("Installation Failure"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
installer = new PackageStructure;
|
||||
}
|
||||
|
||||
QString root = KStandardDirs::locateLocal("data", "plasma/plasmoids/");
|
||||
kDebug() << "installing" << packageFilePath << "to root dir of" << root;
|
||||
|
||||
if (!installer->installPackage(packageFilePath, root)) {
|
||||
KMessageBox::error(this, i18n("Installing the package %1 failed.", packageFilePath),
|
||||
i18n("Installation Failure"));
|
||||
}
|
||||
|
||||
delete installer;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#include "openwidgetassistant_p.moc"
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_OPENWIDGETASSISTANT_P_H
|
||||
#define PLASMA_OPENWIDGETASSISTANT_P_H
|
||||
|
||||
#include <KAssistantDialog>
|
||||
#include <KService>
|
||||
|
||||
class KFileWidget;
|
||||
class KListWidget;
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class OpenWidgetAssistant : public KAssistantDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum {
|
||||
PackageStructureRole = Qt::UserRole + 1
|
||||
};
|
||||
|
||||
OpenWidgetAssistant(QWidget *parent);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void prepPage(KPageWidgetItem *current, KPageWidgetItem *before);
|
||||
void finished();
|
||||
void slotHelpClicked();
|
||||
void slotItemChanged();
|
||||
|
||||
private:
|
||||
KPageWidgetItem *m_typePage;
|
||||
KPageWidgetItem *m_filePage;
|
||||
KFileWidget *m_fileDialog;
|
||||
QWidget *m_filePageWidget;
|
||||
KListWidget *m_widgetTypeList;
|
||||
KService::Ptr m_packageStructureService;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif
|
@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "plasmaappletitemmodel_p.h"
|
||||
|
||||
#include <KSycoca>
|
||||
|
||||
PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel *model,
|
||||
const QMap<QString, QVariant>& info,
|
||||
FilterFlags flags,
|
||||
QMap<QString, QVariant> *extraAttrs)
|
||||
: QObject(model), m_model(model)
|
||||
{
|
||||
QMap<QString, QVariant> attrs(info);
|
||||
|
||||
attrs.insert("favorite", flags & Favorite ? true : false);
|
||||
attrs.insert("used", flags & Used ? true : false);
|
||||
//attrs.insert("recommended", flags & Recommended ? true : false);
|
||||
if (extraAttrs) {
|
||||
attrs.unite(* extraAttrs);
|
||||
}
|
||||
setText(info["name"].toString() + " - "+ info["category"].toString());
|
||||
setData(attrs);
|
||||
setIcon(qvariant_cast<QIcon>(info["icon"]));
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::name() const
|
||||
{
|
||||
return data().toMap()["name"].toString();
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::pluginName() const
|
||||
{
|
||||
return data().toMap()["pluginName"].toString();
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::description() const
|
||||
{
|
||||
return data().toMap()["description"].toString();
|
||||
}
|
||||
|
||||
int PlasmaAppletItem::running() const
|
||||
{
|
||||
return data().toMap()["runningCount"].toInt();
|
||||
}
|
||||
|
||||
void PlasmaAppletItem::setFavorite(bool favorite)
|
||||
{
|
||||
QMap<QString, QVariant> attrs = data().toMap();
|
||||
attrs.insert("favorite", favorite ? true : false);
|
||||
setData(QVariant(attrs));
|
||||
|
||||
QString pluginName = attrs["pluginName"].toString();
|
||||
m_model->setFavorite(pluginName, favorite);
|
||||
}
|
||||
|
||||
void PlasmaAppletItem::setRunning(int count)
|
||||
{
|
||||
QMap<QString, QVariant> attrs = data().toMap();
|
||||
attrs.insert("running", count > 0); //bool for the filter
|
||||
attrs.insert("runningCount", count);
|
||||
setData(QVariant(attrs));
|
||||
}
|
||||
|
||||
bool PlasmaAppletItem::passesFiltering(
|
||||
const KCategorizedItemsViewModels::Filter & filter) const
|
||||
{
|
||||
return data().toMap()[filter.first] == filter.second;
|
||||
}
|
||||
|
||||
QVariantList PlasmaAppletItem::arguments() const
|
||||
{
|
||||
return qvariant_cast<QVariantList>(data().toMap()["arguments"]);
|
||||
}
|
||||
|
||||
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) :
|
||||
KCategorizedItemsViewModels::DefaultItemModel(parent),
|
||||
m_configGroup(configGroup)
|
||||
{
|
||||
m_used = m_configGroup.readEntry("used").split(',');
|
||||
m_favorites = m_configGroup.readEntry("favorites").split(',');
|
||||
connect(KSycoca::self(), SIGNAL(databaseChanged()), this, SLOT(populateModel()));
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::populateModel()
|
||||
{
|
||||
clear();
|
||||
//kDebug() << "populating model, our application is" << m_application;
|
||||
|
||||
// Recommended emblems and filters
|
||||
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]plugins");
|
||||
QMapIterator<QString, QString> i(m_configGroup.entryMap());
|
||||
QMap < QString, QMap < QString, QVariant > > extraPluginAttrs;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!rx.exactMatch(i.key())) {
|
||||
continue;
|
||||
}
|
||||
QString id = rx.cap(1);
|
||||
|
||||
foreach (const QString &plugin, i.value().split(',')) {
|
||||
extraPluginAttrs[plugin]["recommended." + id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: get recommended, favorite, used, etc out of listAppletInfo()
|
||||
//kDebug() << "number of applets is"
|
||||
// << Plasma::Applet::listAppletInfo(QString(), m_application).count();
|
||||
foreach (const KPluginInfo &info, Plasma::Applet::listAppletInfo(QString(), m_application)) {
|
||||
//kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool();
|
||||
if (info.property("NoDisplay").toBool()) {
|
||||
// we don't want to show the hidden category
|
||||
continue;
|
||||
}
|
||||
//kDebug() << info.pluginName() << " is the name of the plugin\n";
|
||||
|
||||
QMap<QString, QVariant> attrs;
|
||||
attrs.insert("name", info.name());
|
||||
attrs.insert("pluginName", info.pluginName());
|
||||
attrs.insert("description", info.comment());
|
||||
attrs.insert("category", info.category());
|
||||
attrs.insert("icon",
|
||||
static_cast<QIcon>(KIcon(info.icon().isEmpty() ?
|
||||
"application-x-plasma" : info.icon())));
|
||||
|
||||
appendRow(new PlasmaAppletItem(this, attrs,((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) | ((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter), &(extraPluginAttrs[info.pluginName()])));
|
||||
}
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::setRunningApplets(const QHash<QString, int> &apps)
|
||||
{
|
||||
//foreach item, find that string and set the count
|
||||
for (int r=0; r<rowCount(); ++r) {
|
||||
QStandardItem *i = item(r);
|
||||
PlasmaAppletItem *p = dynamic_cast<PlasmaAppletItem *>(i);
|
||||
if (p) {
|
||||
p->setRunning(apps.value(p->name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::setRunningApplets(const QString &name, int count)
|
||||
{
|
||||
for (int r=0; r<rowCount(); ++r) {
|
||||
QStandardItem *i = item(r);
|
||||
PlasmaAppletItem *p = dynamic_cast<PlasmaAppletItem *>(i);
|
||||
if (p && p->name() == name) {
|
||||
p->setRunning(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStringList PlasmaAppletItemModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << QLatin1String("text/x-plasmoidservicename");
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData *PlasmaAppletItemModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
kDebug() << "GETTING MIME DATA\n";
|
||||
if (indexes.count() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QStringList types = mimeTypes();
|
||||
|
||||
if (types.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QMimeData *data = new QMimeData();
|
||||
|
||||
QString format = types.at(0);
|
||||
|
||||
QByteArray appletNames;
|
||||
int lastRow = -1;
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
if (index.row() == lastRow) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lastRow = index.row();
|
||||
PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) itemFromIndex(index);
|
||||
appletNames += '\n' + selectedItem->pluginName().toUtf8();
|
||||
//kDebug() << selectedItem->pluginName() << index.column() << index.row();
|
||||
}
|
||||
|
||||
data->setData(format, appletNames);
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::setFavorite(const QString &plugin, bool favorite)
|
||||
{
|
||||
if (favorite) {
|
||||
if (!m_favorites.contains(plugin)) {
|
||||
m_favorites.append(plugin);
|
||||
}
|
||||
} else {
|
||||
if (m_favorites.contains(plugin)) {
|
||||
m_favorites.removeAll(plugin);
|
||||
}
|
||||
}
|
||||
m_configGroup.writeEntry("favorites", m_favorites.join(","));
|
||||
m_configGroup.sync();
|
||||
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::setApplication(const QString &app)
|
||||
{
|
||||
m_application = app;
|
||||
populateModel();
|
||||
}
|
||||
|
||||
QString &PlasmaAppletItemModel::Application()
|
||||
{
|
||||
return m_application;
|
||||
}
|
||||
|
||||
#include <plasmaappletitemmodel_p.moc>
|
||||
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library/Lesser General Public License
|
||||
* version 2, or (at your option) any later version, as published by the
|
||||
* Free Software Foundation
|
||||
*
|
||||
* 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 Library/Lesser General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_PLASMAAPPLETITEMMODEL_P_H
|
||||
#define PLASMA_PLASMAAPPLETITEMMODEL_P_H
|
||||
|
||||
#include <KPluginInfo>
|
||||
|
||||
#include <plasma/applet.h>
|
||||
|
||||
#include "kcategorizeditemsview_p.h"
|
||||
|
||||
class PlasmaAppletItemModel;
|
||||
|
||||
/**
|
||||
* Implementation of the KCategorizedItemsViewModels::AbstractItem
|
||||
*/
|
||||
class PlasmaAppletItem : public QObject, public KCategorizedItemsViewModels::AbstractItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum FilterFlag {
|
||||
NoFilter = 0,
|
||||
Favorite = 1,
|
||||
Used = 2
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
|
||||
|
||||
PlasmaAppletItem(PlasmaAppletItemModel *model, const QMap<QString, QVariant>& info, FilterFlags flags = NoFilter, QMap<QString, QVariant> *extraAttrs = NULL);
|
||||
|
||||
virtual QString name() const;
|
||||
QString pluginName() const;
|
||||
virtual QString description() const;
|
||||
virtual int running() const;
|
||||
virtual void setFavorite(bool favorite);
|
||||
//set how many instances of this applet are running
|
||||
virtual void setRunning(int count);
|
||||
virtual bool passesFiltering(
|
||||
const KCategorizedItemsViewModels::Filter & filter) const;
|
||||
virtual QVariantList arguments() const;
|
||||
|
||||
private:
|
||||
PlasmaAppletItemModel * m_model;
|
||||
};
|
||||
|
||||
class PlasmaAppletItemModel :
|
||||
public KCategorizedItemsViewModels::DefaultItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent = 0);
|
||||
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
|
||||
void setFavorite(const QString &plugin, bool favorite);
|
||||
void setApplication(const QString &app);
|
||||
void setRunningApplets(const QHash<QString, int> &apps);
|
||||
void setRunningApplets(const QString &name, int count);
|
||||
|
||||
QString &Application();
|
||||
|
||||
private:
|
||||
QString m_application;
|
||||
QStringList m_favorites;
|
||||
QStringList m_used;
|
||||
KConfigGroup m_configGroup;
|
||||
|
||||
private slots:
|
||||
void populateModel();
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags)
|
||||
|
||||
#endif /*PLASMAAPPLETSMODEL_H_*/
|
@ -1 +0,0 @@
|
||||
#include "../../plasma/appletbrowser.h"
|
@ -14,7 +14,7 @@ PLASMA_UNIT_TESTS(
|
||||
plasmoidpackagetest
|
||||
)
|
||||
|
||||
set(appletbrowser_SRCS appletbrowser.cpp)
|
||||
kde4_add_executable(plasmaappletbrowser ${appletbrowser_SRCS})
|
||||
target_link_libraries(plasmaappletbrowser plasma ${KDE4_KDEUI_LIBS})
|
||||
#set(appletbrowser_SRCS appletbrowser.cpp)
|
||||
#kde4_add_executable(plasmaappletbrowser ${appletbrowser_SRCS})
|
||||
#target_link_libraries(plasmaappletbrowser plasma ${KDE4_KDEUI_LIBS})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user