* applet browser's add button works

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=717892
This commit is contained in:
Ivan Čukić 2007-09-27 17:50:31 +00:00
parent ad15bab8c4
commit 8a811e46f7
8 changed files with 98 additions and 24 deletions

View File

@ -52,6 +52,20 @@ set(plasma_LIB_SRCS
widgets/widget.cpp
widgets/signalplotter.cpp
widgets/meter.cpp
appletbrowser.cpp
appletbrowser/appletbrowserwindow.cpp
appletbrowser/kcategorizeditemsview.cpp
appletbrowser/kcategorizeditemsviewdelegate.cpp
appletbrowser/kcategorizeditemsviewmodels.cpp
appletbrowser/plasmaappletitemmodel.cpp
)
kde4_add_ui_files (
plasma_LIB_SRCS
appletbrowser/kcategorizeditemsviewbase.ui
appletbrowser/appletbrowserwindowbase.ui
)
set(krunner_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/krunner/org.kde.krunner.Interface.xml)
@ -92,6 +106,7 @@ set(plasma_LIB_INCLUDES
abstractrunner.h
animator.h
applet.h
appletbrowser.h
configxml.h
containment.h
corona.h

View File

@ -36,6 +36,8 @@ AppletBrowserWindow::AppletBrowserWindow(Plasma::Containment * containment, QWid
void AppletBrowserWindow::init() {
setupUi(this);
connect(buttonAdd, SIGNAL(clicked()), this, SLOT(buttonAddClicked()));
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
this->addAction(quit);
@ -44,7 +46,7 @@ void AppletBrowserWindow::init() {
KCategorizedItemsViewModels::Filter("recommended", true));
appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
KCategorizedItemsViewModels::Filter("used", true));
// Filters: Special
m_filterModel.addFilter(i18n("All applets"),
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
@ -54,21 +56,21 @@ void AppletBrowserWindow::init() {
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
m_filterModel.addFilter(i18n("Used in past"),
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
m_filterModel.addSeparator(i18n("Categories:"));
// Filters: Categories
foreach (const QString& category, Plasma::Applet::knownCategories()) {
m_filterModel.addFilter(category,
KCategorizedItemsViewModels::Filter("category", category));
}
appletList->setFilterModel(& m_filterModel);
// Other models
appletList->setItemModel(& m_itemModel);
}
AppletBrowserWindow::~AppletBrowserWindow()
@ -78,4 +80,20 @@ AppletBrowserWindow::~AppletBrowserWindow()
delete m_proxyModel;*/
}
void AppletBrowserWindow::buttonAddClicked() {
kDebug() << "Button ADD clicked\n";
foreach (AbstractItem * item, appletList->selectedItems()) {
PlasmaAppletItem * selectedItem = (PlasmaAppletItem *) item;
kDebug() << "Adding applet " << selectedItem->name();
if (m_corona) {
kDebug() << " to corona\n";
m_corona->addApplet(selectedItem->pluginName());
} else if (m_containment) {
kDebug() << " to conatainment\n";
m_containment->addApplet(selectedItem->pluginName());
}
}
}
#include "appletbrowserwindow.moc"

View File

@ -33,12 +33,15 @@
class AppletBrowserWindow: public QDialog, public Ui::AppletBrowserWindowBase
{
//Q_OBJECT
Q_OBJECT
public:
explicit AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent = 0, Qt::WindowFlags f = 0);
virtual ~AppletBrowserWindow();
private slots:
void buttonAddClicked();
private:
void init();
Plasma::Corona * m_corona;

View File

@ -36,10 +36,10 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
this, SLOT(searchTermChanged(QString)));
connect(comboFilters, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterChanged(int)));
connect (itemsView, SIGNAL(activated(const QModelIndex &)),
this, SIGNAL(activated(const QModelIndex &)));
connect (itemsView, SIGNAL(clicked(const QModelIndex &)),
this, SIGNAL(clicked(const QModelIndex &)));
connect (itemsView, SIGNAL(entered(const QModelIndex &)),
@ -48,11 +48,11 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
this, SIGNAL(pressed(const QModelIndex &)));
itemsView->header()->setVisible(false);
itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this));
comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this));
itemsView->viewport()->setAttribute(Qt::WA_Hover);
QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this);
@ -118,5 +118,21 @@ 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 (QModelIndex index, itemsView->selectionModel()->selectedIndexes()) {
if (index.column() == 0) {
items << getItemByProxyIndex(index);
}
}
return items;
}
#include "kcategorizeditemsview.moc"

View File

@ -48,22 +48,24 @@ class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBas
{
Q_OBJECT
public:
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, QIcon * icon, const Filter & filter);
void clearEmblems();
QList < AbstractItem * > selectedItems() const;
protected slots:
void searchTermChanged(const QString &text);
void filterChanged(int index);
void resizeEvent ( QResizeEvent * event );
void resizeEvent ( QResizeEvent * event );
void paintEvent ( QPaintEvent * event );
Q_SIGNALS:
void activated ( const QModelIndex & index );
void clicked ( const QModelIndex & index );
@ -75,13 +77,14 @@ private:
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;
};

View File

@ -121,18 +121,18 @@ private:
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;
@ -140,7 +140,7 @@ private:
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);

View File

@ -49,6 +49,8 @@
#include "ksmserver_interface.h"
#include "screensaver_interface.h"
#include "appletbrowser.h"
namespace Plasma
{
@ -84,12 +86,14 @@ public:
QPixmap* bitmapBackground;
QString wallpaperPath;
QAction *engineExplorerAction;
QAction *appletBrowserAction;
QAction *runCommandAction;
QAction *lockAction;
QAction *logoutAction;
QSize size;
int screen;
bool immutable;
AppletBrowser *appletBrowser;
};
Containment::Containment(QGraphicsItem* parent,
@ -98,16 +102,19 @@ Containment::Containment(QGraphicsItem* parent,
: Applet(parent, serviceId, containmentId),
d(new Private)
{
d->appletBrowser = new AppletBrowser(this);
}
Containment::Containment(QObject* parent, const QVariantList& args)
: Applet(parent, args),
d(new Private)
{
d->appletBrowser = new AppletBrowser(this);
}
Containment::~Containment()
{
delete d->appletBrowser;
delete d;
}
@ -187,6 +194,13 @@ void Containment::launchExplorer()
KRun::run("plasmaengineexplorer", KUrl::List(), 0);
}
void Containment::launchAppletBrowser()
{
d->appletBrowser->show();
}
void Containment::runCommand()
{
if (!KAuthorized::authorizeKAction("run_command")) {
@ -244,10 +258,13 @@ QList<QAction*> Containment::contextActions()
// - pretty up the menu with separators
// - should we offer "Switch User" here?
if (!d->engineExplorerAction) {
if (!d->appletBrowserAction) {
d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer()));
d->appletBrowserAction = new QAction(i18n("Add applet"), this);
connect(d->appletBrowserAction, SIGNAL(triggered(bool)), this, SLOT(launchAppletBrowser()));
d->runCommandAction = new QAction(i18n("Run Command..."), this);
connect(d->runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
@ -263,6 +280,7 @@ QList<QAction*> Containment::contextActions()
QList<QAction*> actions;
actions.append(d->engineExplorerAction);
actions.append(d->appletBrowserAction);
if (KAuthorized::authorizeKAction("run_command")) {
actions.append(d->runCommandAction);

View File

@ -229,6 +229,7 @@ class PLASMA_EXPORT Containment : public Applet
*/
void appletDestroyed(QObject*);
void launchExplorer();
void launchAppletBrowser();
void runCommand();
void lockScreen();
void logout();