1
/*****************************************************************
3
Copyright (c) 2007, 2006 Rafael Fernández López <ereslibre@kde.org>
4
Copyright (c) 2004-2005 Aaron J. Seigo <aseigo@kde.org>
5
Copyright (c) 2004 Zack Rusin <zrusin@kde.org>
6
Sami Kyostil <skyostil@kempele.fi>
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
15
The above copyright notice and this permission notice shall be included in
16
all copies or substantial portions of the Software.
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
******************************************************************/
27
#include <QApplication>
31
#include <Qt3Support/Q3SimpleRichText>
38
#include "appletinfo.h"
39
#include "kickerSettings.h"
40
#include "addappletvisualfeedback.h"
41
#include "addappletvisualfeedback.moc"
44
#define DEFAULT_FRAMES_PER_SECOND 30
46
AddAppletVisualFeedback::AddAppletVisualFeedback(const QModelIndex& index,
47
QListView* theListView,
48
const QWidget* target,
49
Plasma::Position direction)
50
: QWidget(0, Qt::X11BypassWindowManagerHint),
52
m_direction(direction),
59
AppletInfo *appletData = static_cast<AppletInfo*>(index.internalPointer());
61
m_icon = KIcon(appletData->icon()).pixmap(QSize(64, 64));
63
setObjectName("animtt");
64
setFocusPolicy(Qt::NoFocus);
65
setAttribute(Qt::WA_NoSystemBackground, true);
66
connect(&m_moveTimer, SIGNAL(timeout()), SLOT(swoopCloser()));
68
QString m = "<qt><h3>" + i18n("%1 Added", appletData->name());
70
if (appletData->name() != appletData->comment())
72
m += "</h3><p>" + appletData->comment() + "</p></qt>";
75
m_richText = new Q3SimpleRichText(m, font());
76
m_richText->setWidth(400);
80
m_destination = Plasma::popupPosition(m_direction, this, m_target);
81
QPoint startAt = theListView->visualRect(index).topLeft();
82
startAt = theListView->mapToGlobal(startAt);
85
m_frames = (m_destination - startAt).manhattanLength() / 20;
86
m_moveTimer.start(10);
91
void AddAppletVisualFeedback::paintEvent(QPaintEvent * e)
100
p.drawPixmap(e->rect().topLeft(), m_pixmap, e->rect());
103
void AddAppletVisualFeedback::mousePressEvent(QMouseEvent *)
110
void AddAppletVisualFeedback::makeMask()
112
QPainter maskPainter(&m_mask);
114
m_mask.fill(Qt::color0);
116
maskPainter.setBrush(Qt::color1);
117
maskPainter.setPen(Qt::color1);
118
maskPainter.drawRoundRect(m_mask.rect(), 1600 / m_mask.rect().width(),
119
1600 / m_mask.rect().height());
124
void AddAppletVisualFeedback::displayInternal()
126
// determine text rectangle
127
QRect textRect(0, 0, 0, 0);
131
textRect.setWidth(m_richText->widthUsed());
132
textRect.setHeight(m_richText->height());
134
textRect.translate(-textRect.left(), -textRect.top());
135
textRect.adjust(0, 0, 2, 2);
138
int margin = KDialog::marginHint();
139
int height = qMax(m_icon.height(), textRect.height()) + 2 * margin;
140
int textX = m_icon.isNull() ? margin : 2 + m_icon.width() + 2 * margin;
145
width += textRect.width() + margin;
148
// resize pixmap, mask and widget
149
m_mask = QBitmap(width, height);
150
m_pixmap = QPixmap(width, height);
151
resize(width, height);
155
move(Plasma::popupPosition(m_direction, this, m_target));
158
// create and set transparency mask
162
QPainter bufferPainter(&m_pixmap);
163
bufferPainter.setPen(Qt::black);
164
bufferPainter.setBrush(palette().window());
165
bufferPainter.drawRoundRect(0, 0, width, height,
166
1600 / width, 1600 / height);
168
// draw icon if present
169
if (!m_icon.isNull())
171
bufferPainter.drawPixmap(margin,
174
m_icon.width(), m_icon.height());
179
int textY = (height - textRect.height()) / 2;
182
QPalette pal = palette();
183
pal.setColor(QPalette::Text, pal.window().color().dark(115));
184
int shadowOffset = QApplication::isRightToLeft() ? -1 : 1;
185
m_richText->draw(&bufferPainter, 5 + textX + shadowOffset,
186
textY + 1, QRect(), pal);
190
m_richText->draw(&bufferPainter, 5 + textX, textY, rect(), pal);
194
void AddAppletVisualFeedback::swoopCloser()
196
if (m_destination.isNull() || m_frames == 0)
201
QPoint loc = geometry().topLeft();
202
bool isLeft = m_destination.x() > loc.x();
203
if (loc.x() != m_destination.x())
205
int newX = loc.x() + ((m_destination.x() - loc.x()) / m_frames * 2);
206
if ((m_destination.x() > newX) != isLeft)
208
newX = m_destination.x();
213
if (loc.y() != m_destination.y())
215
loc.setY(loc.y() + ((m_destination.y() - loc.y()) / m_frames));
225
QTimer::singleShot(2000, this, SLOT(deleteLater()));
229
void AddAppletVisualFeedback::internalUpdate()