42
46
EmptyGraphicsItem(QGraphicsItem *parent)
43
: QGraphicsItem(parent)
47
: QGraphicsItem(parent),
45
50
setAcceptsHoverEvents(true);
51
m_background = new Plasma::FrameSvg();
52
m_toolbarBackground = new Plasma::FrameSvg();
54
m_toolbarBackground->setImagePath("widgets/background");
55
m_background->setImagePath("widgets/translucentbackground");
57
m_toolbarBackground->setEnabledBorders(FrameSvg::LeftBorder|FrameSvg::RightBorder|FrameSvg::BottomBorder);
58
m_background->setEnabledBorders(FrameSvg::AllBorders);
64
delete m_toolbarBackground;
48
67
QRectF boundingRect() const
77
void setIsToolbar(bool toolbar)
82
bool isToolbar() const
87
void getContentsMargins(qreal &left, qreal &top, qreal &right, qreal &bottom)
90
m_toolbarBackground->getMargins(left, top, right, bottom);
92
m_background->getMargins(left, top, right, bottom);
96
QRectF contentsRect() const
98
qreal left, top, right, bottom;
101
m_toolbarBackground->getMargins(left, top, right, bottom);
103
m_background->getMargins(left, top, right, bottom);
105
return m_rect.adjusted(left, top, -right, -bottom);
58
108
void setRect(const QRectF &rect)
60
110
//kDebug() << "setting rect to" << rect;
61
111
prepareGeometryChange();
63
setPos(rect.topLeft());
113
setPos(m_rect.topLeft());
115
m_toolbarBackground->resizeFrame(m_rect.size());
117
m_background->resizeFrame(m_rect.size());
66
121
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
70
//p->drawRect(boundingRect());
71
p->setRenderHints(QPainter::Antialiasing);
72
p->translate(0.5, 0.5);
73
//TODO: use Plasma::Theme, and a gradient for the brush!
74
p->setPen(QPen(Qt::white, 1));
75
p->setBrush(QColor(0, 0, 0, 160));
76
QPainterPath path = PaintUtils::roundedRectangle(boundingRect(), 10);
124
m_toolbarBackground->paintFrame(p);
126
m_background->paintFrame(p);
133
Plasma::FrameSvg *m_toolbarBackground;
134
Plasma::FrameSvg *m_background;
84
137
// used with QGrahphicsItem::setData
151
218
QPainterPath p = shape();
154
221
QPointF gradientCenter;
155
222
const QRectF rect = boundingRect();
156
223
const QSize icons = iconSize();
158
226
switch (corner()) {
160
228
iconPos = QPoint((int)rect.right() - icons.width() + 2, 2);
161
229
gradientCenter = rect.topRight();
164
233
iconPos = QPoint(rect.center().x() - icons.width() / 2, 2);
165
234
gradientCenter = QPoint(rect.center().x(), rect.y());
236
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
168
239
iconPos = QPoint(2, 2);
169
240
gradientCenter = rect.topLeft();
172
244
iconPos = QPoint(2, rect.center().y() - icons.height() / 2);
173
245
gradientCenter = QPointF(rect.left(), rect.center().y());
247
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
176
250
iconPos = QPoint((int)rect.right() - icons.width() + 2,
177
251
rect.center().y() - icons.height() / 2);
178
252
gradientCenter = QPointF(rect.right(), rect.center().y());
254
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
181
257
iconPos = QPoint(2, rect.bottom() - icons.height() - 2);
182
258
gradientCenter = rect.bottomLeft();
185
262
iconPos = QPoint(rect.center().x() - icons.width() / 2,
186
263
rect.bottom() - icons.height() - 2);
187
264
gradientCenter = QPointF(rect.center().x(), rect.bottom());
266
d->background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
189
268
case BottomRight:
191
270
iconPos = QPoint((int)rect.right() - icons.width() + 2,
192
271
(int)rect.bottom() - icons.height() - 2);
193
272
gradientCenter = rect.bottomRight();
197
d->bgColor.setAlpha(64);
198
d->fgColor.setAlpha(64);
199
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
200
gradient.setFocalPoint(gradientCenter);
201
gradient.setColorAt(0, d->bgColor);
202
gradient.setColorAt(.87, d->bgColor);
203
gradient.setColorAt(.97, d->fgColor);
204
d->fgColor.setAlpha(0);
205
gradient.setColorAt(1, d->fgColor);
207
painter->setPen(Qt::NoPen);
208
painter->setRenderHint(QPainter::Antialiasing, true);
209
painter->setBrush(gradient);
210
painter->drawPath(p);
278
d->bgColor.setAlpha(64);
279
d->fgColor.setAlpha(64);
280
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
281
gradient.setFocalPoint(gradientCenter);
282
gradient.setColorAt(0, d->bgColor);
283
gradient.setColorAt(.87, d->bgColor);
284
gradient.setColorAt(.97, d->fgColor);
285
d->fgColor.setAlpha(0);
286
gradient.setColorAt(1, d->fgColor);
288
painter->setPen(Qt::NoPen);
289
painter->setRenderHint(QPainter::Antialiasing, true);
290
painter->setBrush(gradient);
291
painter->drawPath(p);
294
d->background->resizeFrame(rect.size());
295
d->background->paintFrame(painter);
213
298
const qreal progress = d->animHighlightFrame;
325
403
case BottomRight:
327
x = (int)boundingRect().right() - maxwidth - iconWidth - 5;
405
x = (int)boundingRect().right() - iconWidth - 5;
328
406
y = (int)boundingRect().bottom() - iconWidth - 5;
336
//kDebug() << "starting at" << startX << startY;
337
412
// find our theoretical X and Y end coordinates
338
418
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
339
419
if (tool == d->toolBacker) {
423
Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
425
if (viewTransform().m11() != Plasma::scalingFactor(Plasma::OverviewZoom) &&
426
(viewTransform().m11() == Plasma::scalingFactor(Plasma::DesktopZoom) ||
427
icon->action() == d->containment->action("add sibling containment") ||
428
icon->action() == d->containment->action("add widgets"))) {
429
icon->setText(icon->action()->text());
430
icon->resize(icon->sizeFromIconSize(22));
432
icon->setText(QString());
433
icon->resize(icon->sizeFromIconSize(22));
343
437
if (tool->isEnabled()) {
344
438
//kDebug() << tool << "is enabled";
346
//kDebug() << "let's show and move" << tool << tool->boundingRect();
440
QSize toolSize = tool->boundingRect().size().toSize();
441
totalWidth += toolSize.width() + 5;
443
maxWidth = qMax(toolSize.width(), maxWidth);
444
maxHeight = qMax(toolSize.height(), maxHeight);
349
445
y += static_cast<int>(tool->boundingRect().height());
449
if (corner() == TopRight || corner() == Right || corner() == BottomRight) {
353
454
// the rect the tools back should have
354
QRectF backerRect = QRectF(QPointF(startX, startY), QSizeF(maxwidth + 10, y - startY));
356
// now check that is actually fits within the parent's boundaries
357
backerRect = mapToParent(backerRect).boundingRect();
358
QSizeF parentSize = parentWidget()->size();
359
if (backerRect.x() < 5) {
360
backerRect.moveLeft(5);
361
} else if (backerRect.right() > parentSize.width() - 5) {
362
backerRect.moveRight(parentSize.width() - 5);
365
if (backerRect.y() < 5) {
366
backerRect.moveTop(5);
367
} else if (backerRect.bottom() > parentSize.height() - 5) {
368
backerRect.moveBottom(parentSize.height() - 5);
371
// re-map our starting points back to our coordinate system
372
backerRect = mapFromParent(backerRect).boundingRect();
455
QRectF backerRect = QRectF(QPointF(x, startY), QSizeF(maxWidth + 10, y - startY));
457
if (!d->toolBacker) {
458
d->toolBacker = new EmptyGraphicsItem(this);
461
d->toolBacker->setIsToolbar(isToolbar());
466
//could that cast ever fail?
467
if (d->containment) {
468
topRight = viewTransform().map(mapFromParent(d->containment->boundingRect().bottomRight()));
470
topRight = boundingRect().topRight();
473
qreal left, top, right, bottom;
474
d->toolBacker->getContentsMargins(left, top, right, bottom);
477
backerRect.setSize(QSize(totalWidth+left+right, maxHeight+top+bottom));
478
backerRect.moveTopRight(topRight);
480
//kDebug() << "starting at" << x << startY;
482
// now check that is actually fits within the parent's boundaries
483
backerRect = mapToParent(backerRect).boundingRect();
484
QSizeF parentSize = parentWidget()->size();
485
if (backerRect.x() < 5) {
486
backerRect.moveLeft(5);
487
} else if (backerRect.right() > parentSize.width() - 5) {
488
backerRect.moveRight(parentSize.width() - 5);
491
if (backerRect.y() < 5) {
492
backerRect.moveTop(5);
493
} else if (backerRect.bottom() > parentSize.height() - 5) {
494
backerRect.moveBottom(parentSize.height() - 5);
497
// re-map our starting points back to our coordinate system
498
backerRect = mapFromParent(backerRect).boundingRect();
373
500
x = backerRect.x() + 5;
374
501
y = backerRect.y();
383
510
if (tool->isEnabled()) {
384
//kDebug() << tool << "is enabled";
386
//kDebug() << "let's show and move" << tool << tool->boundingRect();
388
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
390
y += static_cast<int>(tool->boundingRect().height());
512
//kDebug() << tool << "is enabled";
514
//kDebug() << "let's show and move" << tool << tool->boundingRect();
516
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
518
x += static_cast<int>(tool->boundingRect().width());
520
//kDebug() << tool << "is enabled";
522
//kDebug() << "let's show and move" << tool << tool->boundingRect();
524
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
526
y += static_cast<int>(tool->boundingRect().height());
391
528
} else if (tool->isVisible()) {
392
529
// disabled, but visible, so hide it!
393
530
const int height = static_cast<int>(tool->boundingRect().height());