consolidate creation code; use the layout; don't hide dialog if already hidden

fixes a few annoyances in the system tray
This commit is contained in:
Aaron Seigo 2011-08-03 16:44:37 +02:00
parent a18379e5d0
commit 5484609cd3
2 changed files with 34 additions and 38 deletions

View File

@ -86,58 +86,35 @@ void PopupApplet::setPopupIcon(const QIcon &icon)
return; return;
} }
if (!d->icon) { d->createIconWidget();
d->icon = new Plasma::IconWidget(icon, QString(), this); d->icon->setIcon(icon);
connect(d->icon, SIGNAL(clicked()), this, SLOT(internalTogglePopup()));
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setOrientation(Qt::Horizontal);
setLayout(layout);
} else {
d->icon->setIcon(icon);
}
} }
void PopupApplet::setPopupIcon(const QString &iconName) void PopupApplet::setPopupIcon(const QString &iconName)
{ {
// Attempt 1: is it in the plasmoid package?
if (package()) { if (package()) {
//Attempt1: is it in the plasmoid package?
const QString file = package()->filePath("images", iconName); const QString file = package()->filePath("images", iconName);
if (!file.isEmpty()) { if (!file.isEmpty()) {
setPopupIcon(KIcon(file)); setPopupIcon(KIcon(file));
return; return;
} }
//Attempt2: is it a svg in the icons directory?
} }
// Attempt 2: is it a svg in the icons directory?
QString name = QString("icons/") + iconName.split("-").first(); QString name = QString("icons/") + iconName.split("-").first();
if (!Plasma::Theme::defaultTheme()->imagePath(name).isEmpty()) { if (!Plasma::Theme::defaultTheme()->imagePath(name).isEmpty()) {
if (!d->icon) { d->createIconWidget();
d->icon = new Plasma::IconWidget(this); d->icon->setSvg(name, iconName);
d->icon->setSvg(name, iconName); if (d->icon->svg().isEmpty()) {
if (d->icon->svg().isEmpty()) { setPopupIcon(KIcon(iconName));
setPopupIcon(KIcon(iconName));
}
connect(d->icon, SIGNAL(clicked()), this, SLOT(internalTogglePopup()));
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setOrientation(Qt::Horizontal);
setLayout(layout);
} else {
d->icon->setSvg(name, iconName);
if (d->icon->svg().isEmpty()) {
setPopupIcon(KIcon(iconName));
}
} }
// Final Attempt: use KIcon
} else { return;
setPopupIcon(KIcon(iconName));
} }
// Final Attempt: use KIcon
setPopupIcon(KIcon(iconName));
} }
QIcon PopupApplet::popupIcon() const QIcon PopupApplet::popupIcon() const
@ -625,7 +602,7 @@ void PopupApplet::hidePopup()
d->delayedShowTimer.stop(); d->delayedShowTimer.stop();
Dialog *dialog = d->dialogPtr.data(); Dialog *dialog = d->dialogPtr.data();
if (dialog) { if (dialog && dialog->isVisible()) {
if (location() != Floating) { if (location() != Floating) {
dialog->animatedHide(locationToInverseDirection(location())); dialog->animatedHide(locationToInverseDirection(location()));
} else { } else {
@ -832,6 +809,24 @@ void PopupAppletPrivate::statusChangeWhileShown(Plasma::ItemStatus status)
preShowStatus = status; preShowStatus = status;
} }
void PopupAppletPrivate::createIconWidget()
{
if (icon) {
return;
}
icon = new Plasma::IconWidget(q);
QObject::connect(icon, SIGNAL(clicked()), q, SLOT(internalTogglePopup()));
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setOrientation(Qt::Horizontal);
layout->addItem(icon);
layout->setAlignment(icon, Qt::AlignCenter);
q->setLayout(layout);
}
void PopupAppletPrivate::restoreDialogSize() void PopupAppletPrivate::restoreDialogSize()
{ {
Plasma::Dialog *dialog = dialogPtr.data(); Plasma::Dialog *dialog = dialogPtr.data();

View File

@ -47,6 +47,7 @@ public:
KConfigGroup popupConfigGroup(); KConfigGroup popupConfigGroup();
void appletActivated(); void appletActivated();
void statusChangeWhileShown(Plasma::ItemStatus status); void statusChangeWhileShown(Plasma::ItemStatus status);
void createIconWidget();
PopupApplet *q; PopupApplet *q;