• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

desktoptoolbox.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 by Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2008 by Marco Martin <notmart@gmail.com>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "desktoptoolbox_p.h"
00022 
00023 #include <QGraphicsSceneHoverEvent>
00024 #include <QPainter>
00025 #include <QRadialGradient>
00026 #include <QGraphicsView>
00027 #include <QAction>
00028 
00029 #include <kcolorscheme.h>
00030 #include <kdebug.h>
00031 #include <kiconloader.h>
00032 
00033 #include <plasma/theme.h>
00034 #include <plasma/paintutils.h>
00035 #include <plasma/framesvg.h>
00036 
00037 #include <plasma/applet.h>
00038 #include <plasma/containment.h>
00039 #include <plasma/widgets/iconwidget.h>
00040 
00041 namespace Plasma
00042 {
00043 
00044 class EmptyGraphicsItem : public QGraphicsItem
00045 {
00046     public:
00047         EmptyGraphicsItem(QGraphicsItem *parent)
00048             : QGraphicsItem(parent),
00049               m_toolbar(false)
00050         {
00051             setAcceptsHoverEvents(true);
00052             m_background = new Plasma::FrameSvg();
00053             m_toolbarBackground = new Plasma::FrameSvg();
00054 
00055             m_toolbarBackground->setImagePath("widgets/background");
00056             m_background->setImagePath("widgets/translucentbackground");
00057 
00058             m_toolbarBackground->setEnabledBorders(FrameSvg::LeftBorder|FrameSvg::RightBorder|FrameSvg::BottomBorder);
00059             m_background->setEnabledBorders(FrameSvg::AllBorders);
00060         }
00061 
00062         ~EmptyGraphicsItem()
00063         {
00064             delete m_background;
00065             delete m_toolbarBackground;
00066         }
00067 
00068         QRectF boundingRect() const
00069         {
00070             return QRectF(QPointF(0, 0), m_rect.size());
00071         }
00072 
00073         QRectF rect() const
00074         {
00075             return m_rect;
00076         }
00077 
00078         void setIsToolbar(bool toolbar)
00079         {
00080             m_toolbar = toolbar;
00081         }
00082 
00083         bool isToolbar() const
00084         {
00085             return m_toolbar;
00086         }
00087 
00088         void getContentsMargins(qreal &left, qreal &top, qreal &right, qreal &bottom)
00089         {
00090             if (m_toolbar) {
00091                 m_toolbarBackground->getMargins(left, top, right, bottom);
00092             } else {
00093                 m_background->getMargins(left, top, right, bottom);
00094             }
00095         }
00096 
00097         QRectF contentsRect() const
00098         {
00099             qreal left, top, right, bottom;
00100 
00101             if (m_toolbar) {
00102                 m_toolbarBackground->getMargins(left, top, right, bottom);
00103             } else {
00104                 m_background->getMargins(left, top, right, bottom);
00105             }
00106             return m_rect.adjusted(left, top, -right, -bottom);
00107         }
00108 
00109         void setRect(const QRectF &rect)
00110         {
00111             if (m_rect == rect)
00112                 return;
00113             //kDebug() << "setting rect to" << rect;
00114             prepareGeometryChange();
00115             m_rect = rect;
00116             setPos(m_rect.topLeft());
00117             if (m_toolbar) {
00118                 m_toolbarBackground->resizeFrame(m_rect.size());
00119             } else {
00120                 m_background->resizeFrame(m_rect.size());
00121             }
00122         }
00123 
00124         void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
00125         {
00126             if (m_toolbar) {
00127                 m_toolbarBackground->paintFrame(p);
00128             } else {
00129                 m_background->paintFrame(p);
00130             }
00131         }
00132 
00133     private:
00134         bool m_toolbar;
00135         QRectF m_rect;
00136         Plasma::FrameSvg *m_toolbarBackground;
00137         Plasma::FrameSvg *m_background;
00138 };
00139 
00140 // used with QGrahphicsItem::setData
00141 static const int ToolName = 7001;
00142 
00143 class DesktopToolBoxPrivate
00144 {
00145 public:
00146     DesktopToolBoxPrivate(DesktopToolBox *toolbox)
00147       : q(toolbox),
00148         background(0),
00149         containment(0),
00150         icon("plasma"),
00151         toolBacker(0),
00152         animCircleId(0),
00153         animHighlightId(0),
00154         animCircleFrame(0),
00155         animHighlightFrame(0),
00156         hovering(0)
00157     {}
00158 
00159     void adjustBackgroundBorders()
00160     {
00161         switch (q->corner()) {
00162           case ToolBox::TopRight:
00163             background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder);
00164             break;
00165         case ToolBox::Top:
00166             background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
00167             break;
00168         case ToolBox::TopLeft:
00169             background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::RightBorder);
00170             break;
00171         case ToolBox::Left:
00172             background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
00173             break;
00174         case ToolBox::Right:
00175             background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
00176             break;
00177         case ToolBox::BottomLeft:
00178             background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::RightBorder);
00179             break;
00180         case ToolBox::Bottom:
00181             background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
00182             break;
00183         case ToolBox::BottomRight:
00184         default:
00185             background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder);
00186             break;
00187         }
00188     }
00189 
00190     DesktopToolBox *q;
00191     Plasma::FrameSvg *background;
00192     Containment *containment;
00193     KIcon icon;
00194     EmptyGraphicsItem *toolBacker;
00195     int animCircleId;
00196     int animHighlightId;
00197     qreal animCircleFrame;
00198     qreal animHighlightFrame;
00199     QRect shapeRect;
00200     QColor fgColor;
00201     QColor bgColor;
00202     bool hovering : 1;
00203 };
00204 
00205 DesktopToolBox::DesktopToolBox(Containment *parent)
00206     : ToolBox(parent),
00207       d(new DesktopToolBoxPrivate(this))
00208 {
00209     d->background = new Plasma::FrameSvg(this);
00210     d->background->setImagePath("widgets/toolbox");
00211 
00212     d->containment = parent;
00213     setZValue(10000000);
00214 
00215     setIsMovable(true);
00216     updateTheming();
00217 
00218     connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
00219             this, SLOT(toolMoved(QGraphicsItem*)));
00220     connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
00221     connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
00222             this, SLOT(updateTheming()));
00223 }
00224 
00225 DesktopToolBox::~DesktopToolBox()
00226 {
00227     delete d;
00228 }
00229 
00230 QSize DesktopToolBox::cornerSize() const
00231 {
00232     d->background->setEnabledBorders(FrameSvg::AllBorders);
00233     qreal left, top, right, bottom;
00234     d->background->getMargins(left, top, right, bottom);
00235     d->adjustBackgroundBorders();
00236 
00237     return QSize(size() + left, size() + bottom);
00238 }
00239 
00240 QSize DesktopToolBox::fullWidth() const
00241 {
00242     d->background->setEnabledBorders(FrameSvg::AllBorders);
00243     qreal left, top, right, bottom;
00244     d->background->getMargins(left, top, right, bottom);
00245     d->adjustBackgroundBorders();
00246 
00247     int extraSpace = 0;
00248     if (!d->containment->activity().isNull()) {
00249         extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
00250     }
00251 
00252     return QSize(size() + left + right + extraSpace, size() + bottom);
00253 }
00254 
00255 QSize DesktopToolBox::fullHeight() const
00256 {
00257     d->background->setEnabledBorders(FrameSvg::AllBorders);
00258     qreal left, top, right, bottom;
00259     d->background->getMargins(left, top, right, bottom);
00260     d->adjustBackgroundBorders();
00261 
00262     int extraSpace = 0;
00263     if (!d->containment->activity().isNull()) {
00264         extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
00265     }
00266 
00267     return QSize(size() + left, size() + top + bottom + extraSpace);
00268 }
00269 
00270 QRectF DesktopToolBox::boundingRect() const
00271 {
00272     int extraSpace = size();
00273 
00274     d->adjustBackgroundBorders();
00275 
00276     //keep space for the label and a character more
00277     if (!d->containment->activity().isNull()) {
00278         extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
00279     }
00280 
00281     qreal left, top, right, bottom;
00282     d->background->getMargins(left, top, right, bottom);
00283 
00284     QRectF rect;
00285 
00286     //disable text at corners
00287     if (corner() == TopLeft || corner() == TopRight || corner() == BottomLeft || corner() == BottomRight) {
00288         rect = QRectF(0, 0, size()+left+right, size()+top+bottom);
00289     } else if (corner() == Left || corner() == Right) {
00290         rect = QRectF(0, 0, size()+left+right, size()+extraSpace+top+bottom);
00291     //top or bottom
00292     } else {
00293         rect = QRectF(0, 0, size()+extraSpace+left+right, size()+top+bottom);
00294     }
00295 
00296     return rect;
00297 }
00298 
00299 void DesktopToolBox::updateTheming()
00300 {
00301     d->bgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
00302     d->fgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
00303 }
00304 
00305 void DesktopToolBox::toolTriggered(bool)
00306 {
00307     QAction *action = qobject_cast<QAction *>(sender());
00308 
00309     if (showing() && (!action || !action->autoRepeat())) {
00310         emit toggled();
00311     }
00312 }
00313 
00314 void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00315 {
00316     Q_UNUSED(option)
00317     Q_UNUSED(widget)
00318 
00319     if (isToolbar()){
00320         return;
00321     }
00322 
00323     QPainterPath p = shape();
00324 
00325     QPoint iconPos;
00326     QRect backgroundRect;
00327     const QRectF rect = boundingRect();
00328     const QSize icons = iconSize();
00329 
00330     QString cornerElement;
00331 
00332     switch (corner()) {
00333     case TopLeft:
00334         cornerElement = "desktop-northwest";
00335         break;
00336     case TopRight:
00337         cornerElement = "desktop-northeast";
00338         break;
00339     case BottomRight:
00340         cornerElement = "desktop-southeast";
00341         break;
00342     case BottomLeft:
00343         cornerElement = "desktop-southwest";
00344         break;
00345     default:
00346         break;
00347     }
00348 
00349     QString activityName;
00350 
00351     QSize textSize;
00352     if (cornerElement.isNull()) {
00353         activityName = d->containment->activity();
00354         textSize =  Plasma::Theme::defaultTheme()->fontMetrics().size(Qt::TextSingleLine, activityName+"x");
00355     }
00356 
00357     d->adjustBackgroundBorders();
00358 
00359     d->background->resizeFrame(rect.size());
00360 
00361     if (!cornerElement.isNull()) {
00362         d->background->paint(painter, rect, cornerElement);
00363     } else {
00364         d->background->paintFrame(painter, rect.topLeft());
00365     }
00366 
00367 
00368     QRect iconRect;
00369     QRect textRect;
00370 
00371     if (corner() == Left || corner() == Right) {
00372         Qt::Alignment alignment;
00373 
00374         if (activityName.isNull()) {
00375             alignment = Qt::Alignment(Qt::AlignCenter);
00376         } else {
00377             alignment = Qt::Alignment(Qt::AlignHCenter|Qt::AlignTop);
00378         }
00379 
00380         iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
00381 
00382         QRect boundRect(QPoint(d->background->contentsRect().top(),
00383                                d->background->contentsRect().left()),
00384                         QSize(d->background->contentsRect().height(),
00385                               d->background->contentsRect().width()));
00386 
00387         textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, boundRect);
00388         textRect.moveTopLeft(textRect.topLeft() + QPoint(rect.top(), rect.left()));
00389     } else {
00390         Qt::Alignment alignment;
00391 
00392         if (activityName.isNull()) {
00393             alignment = Qt::Alignment(Qt::AlignCenter);
00394         } else {
00395             alignment = Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter);
00396         }
00397 
00398         iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
00399 
00400         textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, d->background->contentsRect().toRect());
00401         textRect.moveTopLeft(textRect.topLeft() + rect.topLeft().toPoint());
00402     }
00403 
00404     iconRect.moveTopLeft(iconRect.topLeft() + rect.topLeft().toPoint());
00405 
00406 
00407     iconPos = iconRect.topLeft();
00408 
00409     const qreal progress = d->animHighlightFrame;
00410 
00411     if (qFuzzyCompare(qreal(1.0), progress)) {
00412         d->icon.paint(painter, QRect(iconPos, iconSize()));
00413     } else if (qFuzzyCompare(qreal(1.0), 1 + progress)) {
00414         d->icon.paint(painter, QRect(iconPos, iconSize()),
00415                       Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
00416     } else {
00417         QPixmap disabled = d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off);
00418         QPixmap enabled = d->icon.pixmap(iconSize());
00419         QPixmap result = PaintUtils::transition(
00420             d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off),
00421             d->icon.pixmap(iconSize()), progress);
00422         painter->drawPixmap(QRect(iconPos, iconSize()), result);
00423     }
00424 
00425     if (!cornerElement.isNull() || activityName.isNull()) {
00426         return;
00427     }
00428 
00429     QColor textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
00430     QColor shadowColor;
00431     QPoint shadowOffset;
00432 
00433     if (qGray(textColor.rgb()) > 192) {
00434         shadowColor = Qt::black;
00435         shadowOffset = QPoint(1,1);
00436     } else {
00437         shadowColor = Qt::white;
00438         shadowOffset = QPoint(0,0);
00439     }
00440 
00441     QPixmap shadowText = Plasma::PaintUtils::shadowText(activityName, textColor, shadowColor, shadowOffset);
00442 
00443     painter->save();
00444     if (corner() == Left || corner() == Right) {
00445         painter->rotate(90);
00446         painter->translate(textRect.left(), -textRect.top()-textRect.height());
00447         painter->drawPixmap(QPoint(0,0), shadowText);
00448     } else {
00449         painter->drawPixmap(textRect.topLeft(), shadowText);
00450     }
00451 
00452     painter->restore();
00453 }
00454 
00455 QPainterPath DesktopToolBox::shape() const
00456 {
00457     const QRectF rect = boundingRect();
00458     const int w = rect.width();
00459     const int h = rect.height();
00460 
00461     QPainterPath path;
00462     switch (corner()) {
00463     case BottomLeft:
00464         path.moveTo(rect.bottomLeft());
00465         path.arcTo(QRectF(rect.left() - w, rect.top(), w * 2, h * 2), 0, 90);
00466         break;
00467     case BottomRight:
00468         path.moveTo(rect.bottomRight());
00469         path.arcTo(QRectF(rect.left(), rect.top(), w * 2, h * 2), 90, 90);
00470         break;
00471     case TopRight:
00472         path.moveTo(rect.topRight());
00473         path.arcTo(QRectF(rect.left(), rect.top() - h, w * 2, h * 2), 180, 90);
00474         break;
00475     case TopLeft:
00476         path.arcTo(QRectF(rect.left() - w, rect.top() - h, w * 2, h * 2), 270, 90);
00477         break;
00478     default:
00479         path.addRect(rect);
00480         break;
00481     }
00482 
00483     return path;
00484 }
00485 
00486 void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00487 {
00488     if (showing() || d->hovering) {
00489         QGraphicsItem::hoverEnterEvent(event);
00490         return;
00491     }
00492     Plasma::Animator *animdriver = Plasma::Animator::self();
00493     if (d->animHighlightId) {
00494         animdriver->stopCustomAnimation(d->animHighlightId);
00495     }
00496     d->hovering = true;
00497     d->animHighlightId =
00498         animdriver->customAnimation(
00499             10, 240, Plasma::Animator::EaseInCurve, this, "animateHighlight");
00500 
00501     QGraphicsItem::hoverEnterEvent(event);
00502 }
00503 
00504 void DesktopToolBox::showToolBox()
00505 {
00506     setFlag(ItemIgnoresTransformations, isToolbar());
00507 
00508     if (showing() && !isToolbar())
00509         return;
00510 
00511     // put tools 5px from icon edge
00512     const int iconWidth = KIconLoader::SizeMedium;
00513     int x;
00514     int y;
00515     switch (corner()) {
00516     case TopRight:
00517         x = (int)boundingRect().right() - iconWidth - 5;
00518         y = (int)boundingRect().top() + 10;
00519         break;
00520     case Top:
00521         x = (int)boundingRect().center().x() - iconWidth;
00522         y = (int)boundingRect().top() + iconWidth + 10;
00523         break;
00524     case TopLeft:
00525         x = (int)boundingRect().left() + iconWidth + 5;
00526         y = (int)boundingRect().top() + 10;
00527         break;
00528     case Left:
00529         x = (int)boundingRect().left() + iconWidth + 5;
00530         y = (int)boundingRect().center().y() - iconWidth;
00531         break;
00532     case Right:
00533         x = (int)boundingRect().right() - iconWidth - 5;
00534         y = (int)boundingRect().center().y() - iconWidth;
00535         break;
00536     case BottomLeft:
00537         x = (int)boundingRect().left() + iconWidth + 5;
00538         y = (int)boundingRect().bottom() - 5;
00539         break;
00540     case Bottom:
00541         x = (int)boundingRect().center().x() - iconWidth;
00542         y = (int)boundingRect().bottom() - iconWidth - 5;
00543         break;
00544     case BottomRight:
00545     default:
00546         x = (int)boundingRect().right() - iconWidth - 5;
00547         y = (int)boundingRect().bottom() - iconWidth - 5;
00548         break;
00549     }
00550 
00551     int startY = y;
00552 
00553     // find our theoretical X and Y end coordinates
00554 
00555     int maxWidth = 0;
00556     int maxHeight = 0;
00557     int totalWidth = 0;
00558 
00559     foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
00560         if (tool == d->toolBacker) {
00561             continue;
00562         }
00563 
00564         Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
00565         if (tool->isEnabled()) {
00566             tool->show();
00567             //kDebug() << tool << "is enabled";
00568             y += 5;
00569             QSize toolSize = tool->boundingRect().size().toSize();
00570             totalWidth += toolSize.width() + 5;
00571 
00572             maxWidth = qMax(toolSize.width(), maxWidth);
00573             maxHeight = qMax(toolSize.height(), maxHeight);
00574             y += static_cast<int>(tool->boundingRect().height());
00575         }
00576 
00577         if (icon) {
00578             if (viewTransform().m11() != Plasma::scalingFactor(Plasma::OverviewZoom) &&
00579                 (viewTransform().m11() == Plasma::scalingFactor(Plasma::DesktopZoom) ||
00580                  icon->action() == d->containment->action("add sibling containment") ||
00581                  icon->action() == d->containment->action("add widgets"))) {
00582                 icon->setText(icon->action()->text());
00583             } else {
00584                 icon->setText(QString());
00585             }
00586         }
00587     }
00588 
00589     if (corner() == TopRight || corner() == Right || corner() == BottomRight) {
00590         x -= maxWidth;
00591     }
00592 
00593     //y += 5;
00594 
00595 
00596     if (!d->toolBacker) {
00597         d->toolBacker = new EmptyGraphicsItem(this);
00598         d->toolBacker->setZValue(zValue() + 1);
00599     }
00600 
00601     qreal left, top, right, bottom;
00602     d->toolBacker->getContentsMargins(left, top, right, bottom);
00603 
00604     // the rect the tools back should have
00605     QRectF backerRect = QRectF(QPointF(x, startY), QSizeF(maxWidth + left+right, y - startY + top + bottom));
00606 
00607 
00608     d->toolBacker->setIsToolbar(isToolbar());
00609 
00610 
00611     if (isToolbar()) {
00612         QPointF topRight;
00613 
00614         //could that cast ever fail?
00615         if (d->containment) {
00616             topRight = viewTransform().map(mapFromParent(d->containment->boundingRect().bottomRight()));
00617         } else {
00618             topRight = boundingRect().topRight();
00619         }
00620 
00621 
00622         backerRect.setSize(QSize(totalWidth+left+right, maxHeight+top+bottom));
00623         backerRect.moveTopRight(topRight);
00624     } else {
00625         //kDebug() << "starting at" <<  x << startY;
00626 
00627         // now check that is actually fits within the parent's boundaries
00628         backerRect = mapToParent(backerRect).boundingRect();
00629         QSizeF parentSize = parentWidget()->size();
00630         if (backerRect.x() < 5) {
00631             backerRect.moveLeft(5);
00632         } else if (backerRect.right() > parentSize.width() - 5) {
00633             backerRect.moveRight(parentSize.width() - 5);
00634         }
00635 
00636         if (backerRect.y() < 5) {
00637             backerRect.moveTop(5);
00638         } else if (backerRect.bottom() > parentSize.height() - 5) {
00639             backerRect.moveBottom(parentSize.height() - 5);
00640         }
00641 
00642         // re-map our starting points back to our coordinate system
00643         backerRect = mapFromParent(backerRect).boundingRect();
00644     }
00645     x = backerRect.x() + left;
00646     y = backerRect.y() + top;
00647 
00648     // now move the items
00649     Plasma::Animator *animdriver = Plasma::Animator::self();
00650     foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
00651         if (tool == d->toolBacker) {
00652             continue;
00653         }
00654 
00655         Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
00656         const QSize iconSizeHint = icon->sizeFromIconSize(KIconLoader::SizeSmallMedium).toSize();
00657 
00658         //force max size if we aren't zooming
00659         if (viewTransform().m11() == 1) {
00660             icon->resize(maxWidth, iconSizeHint.height());
00661         } else {
00662             icon->resize(iconSizeHint);
00663         }
00664 
00665         if (tool->isEnabled()) {
00666             if (isToolbar()) {
00667                 //kDebug() << tool << "is enabled";
00668                 x += 5;
00669                 //kDebug() << "let's show and move" << tool << tool->boundingRect();
00670                 tool->show();
00671                 tool->setPos(QPoint(x, y));
00672                 x += static_cast<int>(tool->boundingRect().width());
00673             } else {
00674                 //kDebug() << tool << "is enabled";
00675                 y += 5;
00676                 //kDebug() << "let's show and move" << tool << tool->boundingRect();
00677                 tool->show();
00678                 animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
00679                 //x += 0;
00680                 y += static_cast<int>(tool->boundingRect().height());
00681             }
00682         } else if (tool->isVisible()) {
00683             // disabled, but visible, so hide it!
00684             const int height = static_cast<int>(tool->boundingRect().height());
00685             if (isToolbar()) {
00686                 tool->hide();
00687             } else {
00688                 animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, toolPosition(height));
00689             }
00690         }
00691     }
00692 
00693     d->toolBacker->setRect(backerRect);
00694     d->toolBacker->show();
00695 
00696     if (d->animCircleId) {
00697         animdriver->stopCustomAnimation(d->animCircleId);
00698     }
00699 
00700     setShowing(true);
00701 }
00702 
00703 void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00704 {
00705     //kDebug() << event->pos() << event->scenePos()
00706     //         << d->toolBacker->rect().contains(event->scenePos().toPoint());
00707     if (!d->hovering || showing() || isToolbar()) {
00708         QGraphicsItem::hoverLeaveEvent(event);
00709         return;
00710     }
00711 
00712     Plasma::Animator *animdriver = Plasma::Animator::self();
00713     if (d->animHighlightId) {
00714         animdriver->stopCustomAnimation(d->animHighlightId);
00715     }
00716     d->hovering = false;
00717     d->animHighlightId =
00718         animdriver->customAnimation(
00719             10, 240, Plasma::Animator::EaseOutCurve, this, "animateHighlight");
00720 
00721     QGraphicsItem::hoverLeaveEvent(event);
00722 }
00723 
00724 void DesktopToolBox::hideToolBox()
00725 {
00726     if (!showing()) {
00727         return;
00728     }
00729 
00730     Plasma::Animator *animdriver = Plasma::Animator::self();
00731     foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
00732         if (tool == d->toolBacker) {
00733             continue;
00734         }
00735 
00736         const int height = static_cast<int>(tool->boundingRect().height());
00737         if (isToolbar()) {
00738             tool->setPos(toolPosition(height));
00739             tool->hide();
00740         } else {
00741             animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, toolPosition(height));
00742         }
00743     }
00744 
00745     if (d->animCircleId) {
00746         animdriver->stopCustomAnimation(d->animCircleId);
00747     }
00748 
00749     setShowing(false);
00750 
00751     if (d->toolBacker) {
00752         d->toolBacker->hide();
00753     }
00754 }
00755 
00756 void DesktopToolBox::animateHighlight(qreal progress)
00757 {
00758     if (d->hovering) {
00759         d->animHighlightFrame = progress;
00760     } else {
00761         d->animHighlightFrame = 1.0 - progress;
00762     }
00763 
00764     if (progress >= 1) {
00765         d->animHighlightId = 0;
00766     }
00767 
00768     update();
00769 }
00770 
00771 void DesktopToolBox::toolMoved(QGraphicsItem *item)
00772 {
00773     //kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
00774     if (!showing() &&
00775         QGraphicsItem::children().indexOf(static_cast<Plasma::Applet*>(item)) != -1) {
00776         item->hide();
00777     }
00778 }
00779 
00780 void DesktopToolBox::toggle()
00781 {
00782     if (isToolbar()) {
00783         return;
00784     }
00785 
00786     if (showing()) {
00787         hideToolBox();
00788     } else {
00789         showToolBox();
00790     }
00791 }
00792 
00793 } // plasma namespace
00794 
00795 #include "desktoptoolbox_p.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal