[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: Re: [Panel-devel] Applet Manager Dialog
From: Chani <chanika () gmail ! com>
Date: 2007-12-09 8:42:35
Message-ID: 200712091642.55963.chanika () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
On December 8, 2007 18:43:11 Sven Burmeister wrote:
> On Samstag, 8. Dezember 2007, Chani wrote:
> > http://chani.ccdevnet.org/sshots/appletbrowser3.png
> >
> > I'm kinda thinking that there isn't really space to just toss a 'remove'
> > link in there without reorganising or resizing stuff a bit...
>
> What about removing the "remove (2)" and replacing it by a bin-icon. If
> there is only one instance of the applet it gets removed when the bin is
I decided to do this, and put it in its own column to solve the space issue.
the only problem is that I don't actually have such an icon, so right now I'm
just copying the 'favourite' icon. :)
http://chani.ccdevnet.org/sshots/appletbrowser4.png
> clicked. If there are more instances of the same applet, a little pop-up
> lists the entries and if possible some sort of data that makes it easier to
> identify which entry links to which applet. One could make the
> corresponding applet blink on hovering the entry in the list or supply its
> coordinates if any of these possibilities is available.
I think that might be kinda complicated and hard. if someone else wants to add
it, go right ahead, but I'm just aiming for a 'remove all' button right now.
I just hope people don't have too much trouble understanding that the icon
means "remove all".
>
> Another possibility is to replace the "add applet" button by a "remove
> applet" button when the user picks the list of active applets from the
> drop-down.
nah, changing the behaviour of a button based on one filter seems like a
recipe for accidental deletion.
--
This message brought to you by evyl bananas, and the number 3.
www.chani3.com
["appletbrowser.diff" (text/x-diff)]
Index: appletbrowser.h
===================================================================
--- appletbrowser.h (revision 746168)
+++ appletbrowser.h (working copy)
@@ -29,6 +29,7 @@
class Corona;
class Containment;
+class Applet;
class PLASMA_EXPORT AppletBrowserWidget : public QWidget
{
@@ -48,12 +49,28 @@
void addApplet();
/**
+ * Tracks a new running applet
+ */
+ void appletAdded(Plasma::Applet* applet);
+
+ /**
+ * A running applet is no more
+ */
+ void appletDestroyed(QObject* applet);
+
+ /**
+ * Destroy all applets with this name
+ */
+ void destroyApplets(const QString name);
+
+ /**
* Launches a download dialog to retrieve new applets from the Internet
*/
void downloadApplets();
private:
void init();
+ void initRunningApplets();
class Private;
Private * const d;
bool m_showButtons;
Index: appletbrowser.cpp
===================================================================
--- appletbrowser.cpp (revision 746168)
+++ appletbrowser.cpp (working copy)
@@ -27,6 +27,7 @@
#include "plasma/corona.h"
#include "plasma/containment.h"
+#include "plasma/applet.h"
#include "plasma/appletbrowser/plasmaappletitemmodel_p.h"
#include "plasma/appletbrowser/kcategorizeditemsview_p.h"
@@ -48,11 +49,16 @@
}
void initFilters();
+ //update the itemModel on our running applets
+ void updateRunningApplets();
QString application;
Plasma::Corona *corona;
Plasma::Containment *containment;
KCategorizedItemsView *appletList;
+ QMultiHash<QString,Plasma::Applet*> runningApplets;
+ //extra hash so we can look up the names of deleted applets
+ QHash<Plasma::Applet*,QString> appletNames;
KConfig config;
KConfigGroup configGroup;
@@ -96,6 +102,9 @@
filterModel.addFilter(i18n("Widgets I Have Used Before"),
KCategorizedItemsViewModels::Filter("used", true),
new KIcon("history"));
+ filterModel.addFilter(i18n("Currently Running Widgets"),
+ KCategorizedItemsViewModels::Filter("running", true),
+ new KIcon("history"));
filterModel.addSeparator(i18n("Categories:"));
@@ -105,7 +114,17 @@
}
}
+void AppletBrowserWidget::Private::updateRunningApplets()
+{
+ QHash<QString,int> appCount;
+ foreach (QString key, runningApplets.uniqueKeys()) {
+ appCount[key]=runningApplets.count(key);
+ }
+ kDebug() << appCount;
+ itemModel.setRunningApplets(appCount);
+}
+
AppletBrowserWidget::AppletBrowserWidget(Plasma::Corona * corona, bool showButtons, \
QWidget * parent, Qt::WindowFlags f) : QWidget(parent, f),
d(new Private(corona, 0, this)),
@@ -161,8 +180,40 @@
// Other models
d->appletList->setItemModel(&d->itemModel);
+ initRunningApplets();
}
+void AppletBrowserWidget::initRunningApplets()
+{
+//get applets from corona, count them, send results to model
+ kDebug() << d->runningApplets.count();
+ QHash<QString,int> appCount;
+ Plasma::Corona *c=d->corona;
+ if (!c && d->containment) {
+ 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;
+ }
+ QList<Containment*>containments=c->containments();
+ foreach (Containment * containment,containments) {
+ connect(containment, SIGNAL(appletAdded(Plasma::Applet*)), this, \
SLOT(appletAdded(Plasma::Applet*))); + //TODO track containments too?
+ QList<Applet*>applets=containment->applets();
+ foreach (Applet *applet,applets) {
+ d->runningApplets.insert(applet->name(), applet);
+ d->appletNames.insert(applet, applet->name());
+ connect(applet, SIGNAL(destroyed(QObject*)), this, \
SLOT(appletDestroyed(QObject*))); + appCount[applet->name()]++;
+ }
+ }
+ kDebug() << appCount;
+ d->itemModel.setRunningApplets(appCount);
+}
+
void AppletBrowserWidget::setApplication(const QString& app)
{
@@ -173,6 +224,11 @@
//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);
+ //FIXME: I don't know if this is needed, and if it is then I don't know if
+ //I'll need to worry about too many containments sending add signals
+ //initRunningApplets();
+ //perhaps I'll need to send the model a list of running apps, but not update my \
own settings. + d->updateRunningApplets();
}
QString AppletBrowserWidget::application()
@@ -199,6 +255,37 @@
}
}
+void AppletBrowserWidget::appletAdded(Plasma::Applet* applet)
+{
+ QString name = applet->name();
+ kDebug() << name;
+ d->runningApplets.insert(name, applet);
+ d->appletNames.insert(applet, name);
+ connect(applet, SIGNAL(destroyed(QObject*)), this, \
SLOT(appletDestroyed(QObject*))); + d->itemModel.setRunningApplets(name, \
d->runningApplets.count(name)); +}
+
+void AppletBrowserWidget::appletDestroyed(QObject* applet)
+{
+ kDebug() << applet;
+ Plasma::Applet* a = (Plasma::Applet*)applet; //don't care if it's valid, just \
need the address + QString name = d->appletNames.take(a);
+ //if !name, was the applet not found or was the name actually ""?
+ d->runningApplets.remove(name, a);
+ d->itemModel.setRunningApplets(name, d->runningApplets.count(name));
+}
+
+void AppletBrowserWidget::destroyApplets(QString name)
+{
+ foreach (Plasma::Applet* app, d->runningApplets.values(name)) {
+ //FIXME I have a hard time believing this is safe without QPointer
+ app->disconnect(this); //don't need to be told it's being destroyed
+ app->destroy();
+ d->appletNames.remove(app);
+ }
+ d->runningApplets.remove(name);
+}
+
void AppletBrowserWidget::downloadApplets()
{
//TODO: implement
Index: appletbrowser/kcategorizeditemsviewmodels_p.h
===================================================================
--- appletbrowser/kcategorizeditemsviewmodels_p.h (revision 746168)
+++ appletbrowser/kcategorizeditemsviewmodels_p.h (working copy)
@@ -51,6 +51,12 @@
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)
@@ -61,6 +67,10 @@
* 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
Index: appletbrowser/kcategorizeditemsviewdelegate.cpp
===================================================================
--- appletbrowser/kcategorizeditemsviewdelegate.cpp (revision 746168)
+++ appletbrowser/kcategorizeditemsviewdelegate.cpp (working copy)
@@ -47,156 +47,223 @@
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
+ KCategorizedItemsViewModels::AbstractItem * item =
+ getItemByProxyIndex(index);
+ if (!item) return;
+
// Preparing needed data for painting
int left = option.rect.left();
int top = option.rect.top();
int width = option.rect.width();
int height = option.rect.height();
+
+ QColor backgroundColor = (option.state.testFlag(QStyle::State_Selected))?
+ option.palette.color(QPalette::Highlight):option.palette.color(QPalette::Base);
+
+ // Base Background
+ painter->fillRect(option.rect, QBrush(backgroundColor));
+
+//TODO
+//what might need to know we made an extra column?
+
+ 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";
+ }
+
+ // Dividing line
+ backgroundColor = option.palette.color(QPalette::Highlight);
+ backgroundColor.setAlpha(100);
+ painter->setPen(backgroundColor);
+ painter->drawLine(left, top + height - 1, left + width, top + height - 1);
+
+}
+
+void KCategorizedItemsViewDelegate::paintColMain(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();
+
bool leftToRight = (painter->layoutDirection() == Qt::LeftToRight);
-
QIcon::Mode iconMode = QIcon::Normal;
QColor backgroundColor = (option.state.testFlag(QStyle::State_Selected))?
option.palette.color(QPalette::Highlight):option.palette.color(QPalette::Base);
QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))?
- option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
+ option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
- KCategorizedItemsViewModels::AbstractItem * item =
- getItemByProxyIndex(index);
- if (!item) return;
+ // Painting main column
+ QStyleOptionViewItem local_option_title(option);
+ QStyleOptionViewItem local_option_normal(option);
- // Base Background
- painter->fillRect(option.rect, QBrush(backgroundColor));
+ local_option_title.font.setBold(true);
+ local_option_title.font.setPointSize(local_option_title.font.pointSize() + 2);
- if (index.column() == 0) {
- // Painting main column
- QStyleOptionViewItem local_option_title(option);
- QStyleOptionViewItem local_option_normal(option);
+ QLinearGradient gradient;
- local_option_title.font.setBold(true);
- local_option_title.font.setPointSize(local_option_title.font.pointSize() + \
2); + QString title = item->name();
+ QString description = item->description();
- QLinearGradient gradient;
+ // Painting
- QString title = item->name();
- QString description = item->description();
+ // Text
+ int textInner = 2 * UNIVERSAL_PADDING + MAIN_ICON_SIZE;
- // Painting
-
- // Text
- int textInner = 2 * UNIVERSAL_PADDING + MAIN_ICON_SIZE;
-
- painter->setPen(foregroundColor);
- painter->setFont(local_option_title.font);
- painter->drawText(
+ painter->setPen(foregroundColor);
+ painter->setFont(local_option_title.font);
+ painter->drawText(
left + (leftToRight ? textInner : 0),
top + UNIVERSAL_PADDING,
width - textInner, MAIN_ICON_SIZE / 2,
Qt::AlignBottom | Qt::AlignLeft, title);
- painter->setFont(local_option_normal.font);
- painter->drawText(
+ painter->setFont(local_option_normal.font);
+ painter->drawText(
left + (leftToRight ? textInner : 0),
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
width - textInner, MAIN_ICON_SIZE / 2,
Qt::AlignTop | Qt::AlignLeft, description);
- // Main icon
- item->icon().paint(painter,
- leftToRight ? left + UNIVERSAL_PADDING : left + width - \
UNIVERSAL_PADDING - MAIN_ICON_SIZE, + // Main icon
+ item->icon().paint(painter,
+ 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;
- }
+ // 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, + // 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(1, backgroundColor);
- backgroundColor.setAlpha(0);
- gradient.setColorAt(0, backgroundColor);
- } else {
- gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
+ gradient.setColorAt(1, backgroundColor);
+ backgroundColor.setAlpha(0);
+ gradient.setColorAt(0, backgroundColor);
+ } else {
+ gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
left + UNIVERSAL_PADDING + FADE_LENGTH, 0);
- gradient.setColorAt(0, backgroundColor);
- backgroundColor.setAlpha(0);
- gradient.setColorAt(1, backgroundColor);
+ gradient.setColorAt(0, backgroundColor);
+ backgroundColor.setAlpha(0);
+ gradient.setColorAt(1, backgroundColor);
- }
+ }
- QRect paintRect = option.rect;
- painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
- painter->fillRect(paintRect, gradient);
+ QRect paintRect = option.rect;
+ painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
+ painter->fillRect(paintRect, gradient);
- if (leftToRight) {
- gradient.setStart(left + width
+ if (leftToRight) {
+ gradient.setStart(left + width
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - \
FADE_LENGTH, 0);
- gradient.setFinalStop(left + width
+ gradient.setFinalStop(left + width
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
- } else {
- gradient.setStart(left + UNIVERSAL_PADDING
+ } else {
+ gradient.setStart(left + UNIVERSAL_PADDING
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
- gradient.setFinalStop(left + UNIVERSAL_PADDING
+ gradient.setFinalStop(left + UNIVERSAL_PADDING
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + \
FADE_LENGTH, 0);
- }
- paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2);
- painter->fillRect(paintRect, gradient);
+ }
+ paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2);
+ painter->fillRect(paintRect, gradient);
- // Emblems icons
- 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(painter,
+ // Emblems icons
+ 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(painter,
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;
- }
+ if (leftToRight) {
+ emblemLeft -= UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
+ } else {
+ emblemLeft += UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
}
}
+ }
+}
- } else {
- // Painting favorite icon column
+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();
- KCategorizedItemsViewModels::AbstractItem * item =
- getItemByProxyIndex(index);
+ // Painting favorite icon column
- if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == \
item)
- m_onFavoriteIconItem = NULL;
+ 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;
- }
+ 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,
+ 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_favoriteRemoveIcon : & \
m_favoriteAddIcon; + const KIcon * icon = (item->isFavorite())? & \
m_favoriteRemoveIcon : & m_favoriteAddIcon;
- if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != \
item))
- icon->paint(painter,
+ 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;
}
- // Dividing line
- backgroundColor = option.palette.color(QPalette::Highlight);
- backgroundColor.setAlpha(100);
- painter->setPen(backgroundColor);
- painter->drawLine(left, top + height - 1, left + width, top + height - 1);
+ 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;
+ }
+
+ //FIXME need an icon
+ m_favoriteIcon.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,
@@ -204,11 +271,17 @@
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
- if (index.column() == 1 && event->type() == QEvent::MouseButtonPress) {
- (m_onFavoriteIconItem = getItemByProxyIndex(index))
- ->setFavorite(!getItemByProxyIndex(index)->isFavorite());
-
- return true;
+ if (event->type() == QEvent::MouseButtonPress) {
+ KCategorizedItemsViewModels::AbstractItem * item = \
getItemByProxyIndex(index); + if (index.column() == 1) {
+ (m_onFavoriteIconItem = 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);
@@ -220,15 +293,15 @@
Q_UNUSED(option);
//Q_UNUSED(index);
- //option.
+ //FIXME what if remove col isn't the width of fav col?
int width = (index.column() == 0) ? 0 : FAV_ICON_SIZE;
return QSize(width, MAIN_ICON_SIZE + 2 * UNIVERSAL_PADDING);
}
int KCategorizedItemsViewDelegate::columnWidth (int column, int viewWidth) const {
- if (column == 1) {
+ if (column != 0) { //FIXME same as above
return FAV_ICON_SIZE + 2 * UNIVERSAL_PADDING;
- } else return viewWidth - columnWidth(1, viewWidth);
+ } else return viewWidth - 2 * columnWidth(1, viewWidth);
}
Index: appletbrowser/customdragtreeview.cpp
===================================================================
--- appletbrowser/customdragtreeview.cpp (revision 746168)
+++ appletbrowser/customdragtreeview.cpp (working copy)
@@ -56,7 +56,7 @@
QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
foreach (QModelIndex index, indexes) {
- if (index.column() == 1) continue;
+ if (index.column() != 0) continue;
KCategorizedItemsViewModels::AbstractItem * item =
m_view->getItemByProxyIndex(index);
Index: appletbrowser/plasmaappletitemmodel.cpp
===================================================================
--- appletbrowser/plasmaappletitemmodel.cpp (revision 746168)
+++ appletbrowser/plasmaappletitemmodel.cpp (working copy)
@@ -49,6 +49,11 @@
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();
@@ -69,6 +74,14 @@
}
}
+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
{
@@ -138,6 +151,29 @@
}
}
+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 = (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 = (PlasmaAppletItem *)i;
+ if (p && p->name() == name) {
+ p->setRunning(count);
+ }
+ }
+}
+
QStringList PlasmaAppletItemModel::mimeTypes() const
{
QStringList types;
Index: appletbrowser/plasmaappletitemmodel_p.h
===================================================================
--- appletbrowser/plasmaappletitemmodel_p.h (revision 746168)
+++ appletbrowser/plasmaappletitemmodel_p.h (working copy)
@@ -47,7 +47,10 @@
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;
@@ -68,6 +71,8 @@
void setFavorite(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:
Index: appletbrowser/kcategorizeditemsviewdelegate_p.h
===================================================================
--- appletbrowser/kcategorizeditemsviewdelegate_p.h (revision 746168)
+++ appletbrowser/kcategorizeditemsviewdelegate_p.h (working copy)
@@ -52,6 +52,8 @@
const QStyleOptionViewItem &option,
const QModelIndex &index);
+Q_SIGNALS:
+ void destroyApplets(const QString name);
private:
KCategorizedItemsView * m_parent;
@@ -63,6 +65,12 @@
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; };
/**
Index: appletbrowser/kcategorizeditemsview.cpp
===================================================================
--- appletbrowser/kcategorizeditemsview.cpp (revision 746168)
+++ appletbrowser/kcategorizeditemsview.cpp (working copy)
@@ -55,6 +55,9 @@
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);
@@ -80,6 +83,7 @@
m_viewWidth = itemsView->viewport()->width();
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::setFilterModel(QStandardItemModel * model)
Index: appletbrowser/kcategorizeditemsviewmodels.cpp
===================================================================
--- appletbrowser/kcategorizeditemsviewmodels.cpp (revision 746168)
+++ appletbrowser/kcategorizeditemsviewmodels.cpp (working copy)
@@ -38,6 +38,11 @@
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); @@ -101,7 +106,7 @@
int DefaultItemFilterProxyModel::columnCount(const QModelIndex& index) const
{
Q_UNUSED(index);
- return 2;
+ return 3;
}
QVariant DefaultItemFilterProxyModel::data(const QModelIndex & index, int role) \
const @@ -234,7 +239,7 @@
const QModelIndex& index) const
{
Q_UNUSED(index);
- return 2;
+ return 3; //FIXME: a hardcoded magic number that appears in two places CANNOT be \
good }
void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(
Index: appletbrowser/kcategorizeditemsview_p.h
===================================================================
--- appletbrowser/kcategorizeditemsview_p.h (revision 746168)
+++ appletbrowser/kcategorizeditemsview_p.h (working copy)
@@ -72,6 +72,7 @@
void doubleClicked ( const QModelIndex & index );
void entered ( const QModelIndex & index );
void pressed ( const QModelIndex & index );
+// void destroyApplets ( const QString name );
private:
QStandardItemModel * m_modelCategories;
["signature.asc" (application/pgp-signature)]
_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic