From 8a811e46f70c1d3f501c4ff893f7601c1803ec7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=C4=8Cuki=C4=87?= Date: Thu, 27 Sep 2007 17:50:31 +0000 Subject: [PATCH] * applet browser's add button works svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=717892 --- CMakeLists.txt | 15 +++++++++++ appletbrowser/appletbrowserwindow.cpp | 28 +++++++++++++++++---- appletbrowser/appletbrowserwindow.h | 5 +++- appletbrowser/kcategorizeditemsview.cpp | 26 +++++++++++++++---- appletbrowser/kcategorizeditemsview.h | 19 ++++++++------ appletbrowser/kcategorizeditemsviewmodels.h | 8 +++--- containment.cpp | 20 ++++++++++++++- containment.h | 1 + 8 files changed, 98 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2af317f13..a96c2b1b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/appletbrowser/appletbrowserwindow.cpp b/appletbrowser/appletbrowserwindow.cpp index 393ba7c6c..4701f311a 100644 --- a/appletbrowser/appletbrowserwindow.cpp +++ b/appletbrowser/appletbrowserwindow.cpp @@ -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" diff --git a/appletbrowser/appletbrowserwindow.h b/appletbrowser/appletbrowserwindow.h index 1d0300658..c82e17122 100644 --- a/appletbrowser/appletbrowserwindow.h +++ b/appletbrowser/appletbrowserwindow.h @@ -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; diff --git a/appletbrowser/kcategorizeditemsview.cpp b/appletbrowser/kcategorizeditemsview.cpp index 0be5a4c0a..800ff82f1 100644 --- a/appletbrowser/kcategorizeditemsview.cpp +++ b/appletbrowser/kcategorizeditemsview.cpp @@ -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" diff --git a/appletbrowser/kcategorizeditemsview.h b/appletbrowser/kcategorizeditemsview.h index 25109eca9..f7fa5cec6 100644 --- a/appletbrowser/kcategorizeditemsview.h +++ b/appletbrowser/kcategorizeditemsview.h @@ -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; }; diff --git a/appletbrowser/kcategorizeditemsviewmodels.h b/appletbrowser/kcategorizeditemsviewmodels.h index b039105a2..92ea8368a 100644 --- a/appletbrowser/kcategorizeditemsviewmodels.h +++ b/appletbrowser/kcategorizeditemsviewmodels.h @@ -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); diff --git a/containment.cpp b/containment.cpp index c22b8910e..cf8d13a72 100644 --- a/containment.cpp +++ b/containment.cpp @@ -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 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 Containment::contextActions() QList actions; actions.append(d->engineExplorerAction); + actions.append(d->appletBrowserAction); if (KAuthorized::authorizeKAction("run_command")) { actions.append(d->runCommandAction); diff --git a/containment.h b/containment.h index 9dac8a530..5c27a412a 100644 --- a/containment.h +++ b/containment.h @@ -229,6 +229,7 @@ class PLASMA_EXPORT Containment : public Applet */ void appletDestroyed(QObject*); void launchExplorer(); + void launchAppletBrowser(); void runCommand(); void lockScreen(); void logout();