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

libplasma

toolbox.cpp

Go to the documentation of this file.
00001 
00002 /*
00003  *   Copyright 2007 by Aaron Seigo <aseigo@kde.org>
00004  *   Copyright 2008 by Marco Martin <notmart@gmail.com>
00005  *
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU Library General Public License as
00008  *   published by the Free Software Foundation; either version 2, or
00009  *   (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details
00015  *
00016  *   You should have received a copy of the GNU Library General Public
00017  *   License along with this program; if not, write to the
00018  *   Free Software Foundation, Inc.,
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  */
00021 
00022 #include "toolbox_p.h"
00023 
00024 #include <QAction>
00025 #include <QGraphicsSceneHoverEvent>
00026 #include <QPainter>
00027 #include <QRadialGradient>
00028 
00029 #include <KColorScheme>
00030 #include <KDebug>
00031 
00032 #include <plasma/theme.h>
00033 #include "widgets/icon.h"
00034 
00035 namespace Plasma
00036 {
00037 
00038 class ToolBoxPrivate
00039 {
00040 public:
00041     ToolBoxPrivate()
00042       : size(50),
00043       iconSize(32, 32),
00044       hidden(false),
00045       showing(false),
00046       orientation(Qt::Horizontal)
00047     {}
00048 
00049     int size;
00050     QSize iconSize;
00051     bool hidden;
00052     bool showing;
00053     Qt::Orientation orientation;
00054 };
00055 
00056 ToolBox::ToolBox(QGraphicsItem *parent)
00057     : QGraphicsItem(parent),
00058       d(new ToolBoxPrivate)
00059 {
00060     setAcceptsHoverEvents(true);
00061 }
00062 
00063 ToolBox::~ToolBox()
00064 {
00065     delete d;
00066 }
00067 
00068 void ToolBox::addTool(QAction *action)
00069 {
00070     if (!action) {
00071         return;
00072     }
00073 
00074     Plasma::Icon *tool = new Plasma::Icon(this);
00075 
00076     tool->setAction(action);
00077     tool->setDrawBackground(true);
00078     tool->setOrientation(Qt::Horizontal);
00079     QSizeF iconSize = tool->sizeFromIconSize(22);
00080     tool->setMinimumSize(iconSize);
00081     tool->setMaximumSize(iconSize);
00082     tool->resize(tool->size());
00083 
00084     tool->hide();
00085     const int height = static_cast<int>(tool->boundingRect().height());
00086     tool->setPos(QPoint( d->size*2,-height));
00087     tool->setZValue(zValue() + 1);
00088 
00089     //make enabled/disabled tools appear/disappear instantly
00090     connect(tool, SIGNAL(changed()), this, SLOT(updateToolBox()));
00091 }
00092 
00093 void ToolBox::updateToolBox()
00094 {
00095     if ( d->showing) {
00096         d->showing = false;
00097         showToolBox();
00098     }
00099 }
00100 
00101 void ToolBox::removeTool(QAction *action)
00102 {
00103     foreach (QGraphicsItem *child, QGraphicsItem::children()) {
00104         //kDebug() << "checking tool" << child << child->data(ToolName);
00105         Plasma::Icon *tool = dynamic_cast<Plasma::Icon*>(child);
00106         if (tool && tool->action() == action) {
00107             //kDebug() << "tool found!";
00108             tool->deleteLater();
00109             break;
00110         }
00111     }
00112 }
00113 
00114 int ToolBox::size() const
00115 {
00116     return  d->size;
00117 }
00118 
00119 void ToolBox::setSize(const int newSize)
00120 {
00121     d->size = newSize;
00122 }
00123 
00124 QSize ToolBox::iconSize() const
00125 {
00126     return d->iconSize;
00127 }
00128 
00129 void ToolBox::setIconSize(const QSize newSize)
00130 {
00131     d->iconSize = newSize;
00132 }
00133 
00134 bool ToolBox::showing() const
00135 {
00136     return  d->showing;
00137 }
00138 
00139 void ToolBox::setShowing(const bool show)
00140 {
00141     d->showing = show;
00142 }
00143 
00144 Qt::Orientation ToolBox::orientation() const
00145 {
00146     return d->orientation;
00147 }
00148 
00149 void ToolBox::setOrientation( Qt::Orientation orient )
00150 {
00151      d->orientation = orient;
00152 }
00153 
00154 void ToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
00155 {
00156     event->accept();
00157 }
00158 
00159 void ToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
00160 {
00161     if (boundingRect().contains(event->pos())) {
00162         emit toggled();
00163     }
00164 }
00165 
00166 } // plasma namespace
00167 
00168 #include "toolbox_p.moc"
00169 

libplasma

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

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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