2
* Copyright 20010 by Marco Martin <notmart@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor,
17
* Boston, MA 02110-1301 USA
20
#include "panelapplethandle.h"
21
#include "toolbutton.h"
24
#include <QApplication>
27
#include <QPropertyAnimation>
30
#include <KWindowSystem>
32
#include <Plasma/Applet>
33
#include <Plasma/Containment>
34
#include <Plasma/Corona>
36
#include <Plasma/Theme>
37
#include <Plasma/WindowEffects>
39
PanelAppletHandle::PanelAppletHandle(QWidget *parent, Qt::WindowFlags f)
40
: Plasma::Dialog(parent, f)
42
m_icons = new Plasma::Svg(this);
43
m_icons->setImagePath("widgets/configuration-icons");
44
KWindowSystem::setType(winId(), NET::Dock);
45
setWindowFlags(Qt::X11BypassWindowManagerHint);
48
m_hideTimer = new QTimer(this);
49
m_hideTimer->setSingleShot(true);
50
connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide()));
52
m_layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
53
m_layout->setContentsMargins(0, 0, 0, 0);
54
m_configureButton = new ToolButton(this);
55
m_configureButton->setIcon(m_icons->pixmap("configure"));
56
connect(m_configureButton, SIGNAL(clicked()), this, SLOT(configureApplet()));
58
m_layout->addWidget(m_configureButton);
59
m_layout->addStretch(10);
60
m_title = new QLabel(this);
61
m_layout->addWidget(m_title);
62
m_layout->addStretch(0);
64
m_closeButton = new ToolButton(this);
65
m_closeButton->setIcon(m_icons->pixmap("close"));
66
m_layout->addWidget(m_closeButton);
67
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeApplet()));
69
m_moveAnimation = new QPropertyAnimation(this, "pos", this);
72
resize(minimumSizeHint());
74
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updatePalette()));
78
PanelAppletHandle::~PanelAppletHandle()
82
void PanelAppletHandle::updatePalette()
84
QPalette p = m_title->palette();
85
p.setColor(QPalette::WindowText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
86
m_title->setPalette(p);
89
void PanelAppletHandle::setApplet(Plasma::Applet *applet)
91
if (applet == m_applet.data()) {
95
Plasma::Applet *oldApplet = m_applet.data();
97
disconnect(oldApplet, SIGNAL(destroyed()), this, SLOT(appletDestroyed()));
104
m_title->setText(applet->name());
105
m_layout->activate();
106
resize(minimumSizeHint());
108
if (QApplication::layoutDirection() == Qt::RightToLeft) {
109
m_layout->setDirection(QBoxLayout::RightToLeft);
111
m_layout->setDirection(QBoxLayout::LeftToRight);
114
QAction *configAction = applet->action("configure");
115
m_configureButton->setVisible(configAction && configAction->isEnabled());
117
connect(applet, SIGNAL(destroyed()), this, SLOT(appletDestroyed()));
123
void PanelAppletHandle::moveToApplet()
125
Plasma::Applet *applet = m_applet.data();
129
Plasma::Containment *containment = applet->containment();
130
if (!containment || !containment->corona()) {
135
m_moveAnimation->setStartValue(pos());
136
m_moveAnimation->setEndValue(containment->corona()->popupPosition(applet, size(), Qt::AlignCenter));
137
m_moveAnimation->setDuration(250);
138
m_moveAnimation->start();
140
move(applet->containment()->corona()->popupPosition(applet, size(), Qt::AlignCenter));
141
Plasma::WindowEffects::slideWindow(this, applet->location());
146
void PanelAppletHandle::startHideTimeout()
148
m_hideTimer->start(800);
149
Plasma::Applet *applet = m_applet.data();
151
Plasma::WindowEffects::slideWindow(this, applet->location());
155
void PanelAppletHandle::configureApplet()
157
Plasma::Applet *applet = m_applet.data();
159
applet->showConfigurationInterface();
163
void PanelAppletHandle::closeApplet()
165
Plasma::Applet *applet = m_applet.data();
171
void PanelAppletHandle::appletDestroyed()
173
Plasma::Applet *applet = m_applet.data();
175
disconnect(applet, SIGNAL(destroyed()), this, SLOT(appletDestroyed()));
181
void PanelAppletHandle::enterEvent(QEvent *event)
188
void PanelAppletHandle::leaveEvent(QEvent *event)
192
m_hideTimer->start(800);
195
void PanelAppletHandle::mousePressEvent(QMouseEvent *event)
197
Plasma::Applet *applet = m_applet.data();
199
emit mousePressed(applet, event);
203
void PanelAppletHandle::mouseMoveEvent(QMouseEvent *event)
205
Plasma::Applet *applet = m_applet.data();
207
emit mouseMoved(applet, event);
211
void PanelAppletHandle::mouseReleaseEvent(QMouseEvent *event)
213
Plasma::Applet *applet = m_applet.data();
215
emit mouseReleased(applet, event);
220
#include "panelapplethandle.moc"