[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/applets/systemtray/ui
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2009-05-06 17:32:40
Message-ID: 1241631160.098740.29161.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 964454 by aseigo:
always show the info/job item so things don't jostle around; it becomes a "tristate" \
that busy-runs when there are jobs, an arrow+count when there are notifications only \
and a disabled info icon when empty. probably could use some more prettifying, but \
this gets us a lot closer
M +25 -31 applet.cpp
M +1 -2 applet.h
M +109 -22 extendertask.cpp
M +5 -5 extendertask.h
M +8 -22 taskarea.cpp
M +0 -1 taskarea.h
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/applet.cpp \
#964453:964454 @@ -204,7 +204,10 @@
}
}
+ bool createExtenderTask = false;
+
if (globalCg.readEntry("ShowJobs", true)) {
+ createExtenderTask = true;
createJobGroups();
Private::s_manager->registerJobProtocol();
@@ -212,28 +215,33 @@
this, SLOT(addJob(SystemTray::Job*)));
connect(Private::s_manager, SIGNAL(jobRemoved(SystemTray::Job*)),
this, SLOT(finishJob(SystemTray::Job*)));
-
- //there might still be completed jobs in the tray, in which case we directly \
want to show
- //the extender task spinner.
- if (extender()->group("completedJobsGroup") &&
- !extender()->group("completedJobsGroup")->items().isEmpty()) {
- if (!d->extenderTask) {
- d->extenderTask = new SystemTray::ExtenderTask(this, \
Private::s_manager, extender());
- d->extenderTask->setIcon("help-about");
- }
- Private::s_manager->addTask(d->extenderTask);
- }
}
if (globalCg.readEntry("ShowNotifications", true)) {
+ createExtenderTask = true;
Private::s_manager->registerNotificationProtocol();
connect(Private::s_manager, \
SIGNAL(notificationAdded(SystemTray::Notification*)), this, \
SLOT(addNotification(SystemTray::Notification*))); }
+ initExtenderTask(createExtenderTask);
d->taskArea->syncTasks(Private::s_manager->tasks());
}
+void Applet::initExtenderTask(bool create)
+{
+ if (create) {
+ if (!d->extenderTask) {
+ d->extenderTask = new SystemTray::ExtenderTask(this, Private::s_manager, \
extender()); + d->extenderTask->setIcon("help-about");
+ Private::s_manager->addTask(d->extenderTask);
+ }
+ } else {
+ delete d->extenderTask;
+ d->extenderTask = 0;
+ }
+}
+
void Applet::constraintsEvent(Plasma::Constraints constraints)
{
setBackgroundHints(NoBackground);
@@ -279,8 +287,6 @@
void Applet::checkSizes()
{
- d->taskArea->checkSizes();
-
qreal leftMargin, topMargin, rightMargin, bottomMargin;
d->background->getMargins(leftMargin, topMargin, rightMargin, bottomMargin);
setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin);
@@ -482,30 +488,34 @@
KConfigGroup globalCg = globalConfig();
globalCg.writeEntry("ShowJobs", d->notificationUi.showJobs->isChecked());
globalCg.writeEntry("ShowNotifications", \
d->notificationUi.showNotifications->isChecked()); + bool createExtenderTask = \
false;
disconnect(Private::s_manager, SIGNAL(jobAdded(SystemTray::Job*)),
this, SLOT(addJob(SystemTray::Job*)));
if (d->notificationUi.showJobs->isChecked()) {
createJobGroups();
+ createExtenderTask = true;
Private::s_manager->registerJobProtocol();
connect(Private::s_manager, SIGNAL(jobAdded(SystemTray::Job*)),
this, SLOT(addJob(SystemTray::Job*)));
} else {
- Private::s_manager->unregisterJobProtocol();
+ Private::s_manager->unregisterJobProtocol();
}
disconnect(Private::s_manager, \
SIGNAL(notificationAdded(SystemTray::Notification*)), this, \
SLOT(addNotification(SystemTray::Notification*))); if \
(d->notificationUi.showNotifications->isChecked()) { + createExtenderTask = \
true; Private::s_manager->registerNotificationProtocol();
connect(Private::s_manager, \
SIGNAL(notificationAdded(SystemTray::Notification*)), this, \
SLOT(addNotification(SystemTray::Notification*))); } else {
- Private::s_manager->unregisterNotificationProtocol();
+ Private::s_manager->unregisterNotificationProtocol();
}
+ initExtenderTask(createExtenderTask);
d->shownCategories.clear();
globalCg.writeEntry("ShowApplicationStatus", \
d->notificationUi.showApplicationStatus->isChecked()); @@ -589,22 +599,6 @@
}
-void Applet::popupEvent(bool visibility)
-{
- Q_UNUSED(visibility)
-
- if (!(Private::s_manager->jobs().isEmpty() &&
- Private::s_manager->notifications().isEmpty() &&
- extender()->group("completedJobsGroup")->items().isEmpty())) {
- if (!d->extenderTask) {
- d->extenderTask = new SystemTray::ExtenderTask(this, Private::s_manager, \
extender());
- d->extenderTask->setIcon("help-about");
- }
-
- Private::s_manager->addTask(d->extenderTask);
- }
-}
-
void Applet::timerEvent(QTimerEvent *event)
{
if (event->timerId() != d->timerId) {
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/applet.h #964453:964454
@@ -57,8 +57,6 @@
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); }
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); }
- void popupEvent(bool show);
-
void timerEvent(QTimerEvent *event);
private slots:
@@ -73,6 +71,7 @@
private:
void createJobGroups();
+ void initExtenderTask(bool create);
class Private;
Private* const d;
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/extendertask.cpp \
#964453:964454 @@ -17,13 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
-#include "../core/manager.h"
-#include "../core/job.h"
#include "extendertask.h"
#include <fixx11h.h>
+#include <QtGui/QPainter>
+#include <QtGui/QTextOption>
#include <QtGui/QWidget> // QWIDGETSIZE_MAX
-#include <QtGui/QTextOption>
#include <plasma/extender.h>
#include <plasma/extenderitem.h>
@@ -33,11 +32,99 @@
#include <plasma/widgets/busywidget.h>
#include <KIcon>
+#include <KGlobalSettings>
+#include "../core/manager.h"
+#include "../core/job.h"
+
namespace SystemTray
{
+class ExtenderTaskBusyWidget : public Plasma::BusyWidget
+{
+public:
+ enum State { Empty, Info, Running };
+
+ ExtenderTaskBusyWidget(Plasma::PopupApplet *parent)
+ : Plasma::BusyWidget(parent),
+ m_icon("dialog-information"),
+ m_state(Empty),
+ m_svg(new Plasma::Svg(this)),
+ m_systray(parent)
+ {
+ setAcceptsHoverEvents(true);
+ m_svg->setImagePath("widgets/tasks");
+ setRunning(false);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget \
*widget = 0) + {
+ if (m_state == Running) {
+ Plasma::BusyWidget::paint(painter, option, widget);
+ return;
+ }
+
+ if (m_state == Empty) {
+ //TODO: something nicer perhaps .. right now we just paint a centered, \
disabled 'i' icon + QPixmap pixmap = m_icon.pixmap(size().toSize(), \
QIcon::Disabled); + QPoint p(qMax(qreal(0), (size().width() - \
pixmap.width()) / 2), + qMax(qreal(0), (size().height() - \
pixmap.height()) / 2)); + painter->drawPixmap(p, pixmap);
+
+ return;
+ }
+
+ QFont font(KGlobalSettings::smallestReadableFont());
+ painter->setFont(font);
+ QRectF r = rect();
+
+ if (m_svg && m_svg->hasElement(expanderElement())) {
+ QFontMetrics fm(font);
+ QSizeF arrowSize(m_svg->elementSize(expanderElement()));
+ QRectF arrowRect(r.center() - QPointF(arrowSize.width() / 2, \
arrowSize.height() + fm.xHeight() / 2), arrowSize); + \
m_svg->paint(painter, arrowRect, expanderElement()); +
+ r.setTop(arrowRect.bottom());
+ painter->drawText(r, Qt::AlignHCenter|Qt::AlignTop, label());
+ } else {
+ painter->drawText(r, Qt::AlignCenter, label());
+ }
+ }
+
+ void setState(State state)
+ {
+ if (m_state == state) {
+ return;
+ }
+
+ m_state = state;
+ setRunning(m_state == Running);
+ update();
+ }
+
+ QString expanderElement() const
+ {
+ switch (m_systray->location()) {
+ case Plasma::TopEdge:
+ return "group-expander-top";
+ case Plasma::RightEdge:
+ return "group-expander-right";
+ case Plasma::LeftEdge:
+ return "group-expander-left";
+ case Plasma::BottomEdge:
+ default:
+ return "group-expander-bottom";
+ }
+ }
+
+private:
+ KIcon m_icon;
+ State m_state;
+ Plasma::Svg *m_svg;
+ Plasma::PopupApplet *m_systray;
+};
+
class ExtenderTask::Private
{
public:
@@ -59,11 +146,8 @@
foreach (Job *job, manager->jobs()) {
if (job->state() == Job::Running) {
runningJobs++;
- break;
- }
- if (job->state() == Job::Suspended) {
+ } else if (job->state() == Job::Suspended) {
pausedJobs++;
- break;
}
}
@@ -73,20 +157,19 @@
group->setTitle(i18np("%1 Recently Completed Job:", "%1 Recently \
Completed Jobs:", completedJobs));
}
- int total= manager->jobs().count() + manager->notifications().count() + \
completedJobs;
- if (manager->jobs().isEmpty() &&
- manager->notifications().isEmpty() &&
- group && group->items().isEmpty()) {
+ int total = manager->jobs().count() + manager->notifications().count() + \
completedJobs; +
+ if (!total) {
systemTray->hidePopup();
- delete q;
- return;
- } else if (runningJobs > 0) {
- busyWidget->setRunning(true);
+ busyWidget->setState(ExtenderTaskBusyWidget::Empty);
+ busyWidget->setLabel(QString());
+ } else if (runningJobs) {
+ busyWidget->setState(ExtenderTaskBusyWidget::Running);
busyWidget->setLabel(QString("%1/%2").arg(QString::number(total - \
runningJobs))
.arg(QString::number(total)));
} else {
- busyWidget->setRunning(false);
+ busyWidget->setState(ExtenderTaskBusyWidget::Info);
busyWidget->setLabel(QString::number(total));
}
@@ -95,25 +178,31 @@
if (runningJobs > 0) {
tooltipContent += i18np("%1 running job", "%1 running jobs", \
runningJobs) + "<br>"; }
+
if (pausedJobs > 0) {
tooltipContent += i18np("%1 suspended job", "%1 suspended jobs", \
pausedJobs) + "<br>"; }
+
if (!manager->notifications().isEmpty()) {
tooltipContent += i18np("%1 notification", "%1 notifications",
manager->notifications().count()) + "<br>";
}
+ if (tooltipContent.isEmpty()) {
+ tooltipContent = i18n("No active jobs or notifications");
+ }
+
Plasma::ToolTipContent data(i18n("Notifications and jobs"),
tooltipContent,
KIcon("help-about"));
- Plasma::ToolTipManager::self()->setContent(systemTray, data);
+ Plasma::ToolTipManager::self()->setContent(busyWidget, data);
}
Task *q;
QString typeId;
QString iconName;
QIcon icon;
- Plasma::BusyWidget *busyWidget;
+ ExtenderTaskBusyWidget *busyWidget;
Plasma::PopupApplet *systemTray;
Manager *manager;
Plasma::Extender *extender;
@@ -141,7 +230,7 @@
connect(extender, SIGNAL(itemDetached(Plasma::ExtenderItem*)),
this, SLOT(updateTask()));
- d->busyWidget = new Plasma::BusyWidget(systemTray);
+ d->busyWidget = new ExtenderTaskBusyWidget(systemTray);
d->busyWidget->setMinimumSize(22, 22);
d->busyWidget->setMaximumSize(26, QWIDGETSIZE_MAX);
connect(d->busyWidget, SIGNAL(clicked()), systemTray, SLOT(togglePopup()));
@@ -153,7 +242,7 @@
ExtenderTask::~ExtenderTask()
{
emit taskDeleted(d->typeId);
- Plasma::ToolTipManager::self()->unregisterWidget(d->systemTray);
+ delete d->busyWidget;
delete d;
}
@@ -178,14 +267,12 @@
return i18n("Show or hide notifications and jobs");
}
-
QString ExtenderTask::typeId() const
{
//FIXME: what should we return here?
return "toggle_extender";
}
-
QIcon ExtenderTask::icon() const
{
return d->icon;
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/extendertask.h \
#964453:964454 @@ -44,10 +44,10 @@
virtual ~ExtenderTask();
bool isValid() const;
- virtual bool isEmbeddable() const;
- virtual QString name() const;
- virtual QString typeId() const;
- virtual QIcon icon() const;
+ bool isEmbeddable() const;
+ QString name() const;
+ QString typeId() const;
+ QIcon icon() const;
void setIcon(const QString &icon);
bool isHideable() const;
@@ -55,7 +55,7 @@
void taskDeleted(QString typeId);
protected:
- virtual QGraphicsWidget* createWidget(Plasma::Applet *applet);
+ QGraphicsWidget* createWidget(Plasma::Applet *applet);
private:
class Private;
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/taskarea.cpp \
#964453:964454 @@ -206,16 +206,6 @@
}
}
-//TODO: check if is still necessary with 4.5
-void TaskArea::checkSizes()
-{
- d->topLayout->updateGeometry();
-
- QSizeF s = d->topLayout->effectiveSizeHint(Qt::PreferredSize);
-
- setPreferredSize(s);
-}
-
void TaskArea::removeTask(Task *task)
{
foreach (QGraphicsWidget *widget, task->associatedWidgets()) {
@@ -295,14 +285,14 @@
QGraphicsWidget *applet = dynamic_cast<QGraphicsWidget *>(parentItem());
if (applet) {
- qreal left, top, right, bottom;
- applet->getContentsMargins(&left, &top, &right, &bottom);
+ qreal left, top, right, bottom;
+ applet->getContentsMargins(&left, &top, &right, &bottom);
- if (o == Qt::Horizontal) {
- d->topLayout->setSpacing(right);
- } else {
- d->topLayout->setSpacing(bottom);
- }
+ if (o == Qt::Horizontal) {
+ d->topLayout->setSpacing(right);
+ } else {
+ d->topLayout->setSpacing(bottom);
+ }
}
}
@@ -325,11 +315,7 @@
d->unhider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
}
- //FIXME
- //d->topLayout->removeItem(d->taskLayout);
d->topLayout->insertItem(0, d->unhider);
- //d->topLayout->addItem(d->unhider);
- //d->topLayout->addItem(d->taskLayout);
connect(d->unhider, SIGNAL(clicked()), this, SLOT(toggleHiddenItems()));
emit sizeHintChanged(Qt::PreferredSize);
@@ -343,7 +329,7 @@
if (!d->showingHidden && d->topLayout->orientation() == Qt::Vertical) {
d->unhider->setSvg("widgets/systemtray", "expander-up");
- } else if(d->showingHidden && d->topLayout->orientation() == Qt::Vertical){
+ } else if(d->showingHidden && d->topLayout->orientation() == Qt::Vertical) {
d->unhider->setSvg("widgets/systemtray", "expander-down");
}else if (d->showingHidden || QApplication::layoutDirection() == \
Qt::RightToLeft) { d->unhider->setSvg("widgets/systemtray", "expander-right");
--- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/ui/taskarea.h \
#964453:964454 @@ -49,7 +49,6 @@
int leftEasement() const;
int rightEasement() const;
void setOrientation(Qt::Orientation);
- void checkSizes();
public slots:
void addTask(SystemTray::Task *task);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic