22 #include <QtGui/QPainter>
23 #include <QtGui/QGraphicsScene>
24 #include <QtGui/QGraphicsSceneMouseEvent>
27 #include <KIconLoader>
29 #include <Plasma/Applet>
30 #include <Plasma/PaintUtils>
36 :
Handle(containment, applet),
44 :
Handle(containment, group),
58 m_location = NoLocation;
61 m_widgetPos = w->pos();
62 m_widgetSize = w->size();
63 w->installEventFilter(
this);
67 m_configureIcons =
new Plasma::Svg(
this);
68 m_configureIcons->setImagePath(
"widgets/configuration-icons");
69 m_configureIcons->setContainsMultipleImages(
true);
75 w->removeEventFilter(
this);
76 w->setPos(m_widgetPos);
89 if (event->type() == QEvent::GraphicsSceneHoverLeave) {
90 if (!fullRect().contains(static_cast<QGraphicsSceneHoverEvent *>(event)->pos())) {
93 }
else if (event->type() == QEvent::GraphicsSceneMove) {
94 QGraphicsSceneMoveEvent *e =
static_cast<QGraphicsSceneMoveEvent *
>(event);
95 m_widgetPos = e->newPos();
103 switch (m_location) {
105 return QRectF(-SIZE, 0, SIZE, m_widgetSize.height());
108 return QRectF(0, -SIZE, m_widgetSize.width(), SIZE);
111 return QRectF(m_widgetSize.width(), 0, SIZE, m_widgetSize.height());
114 return QRectF(0, m_widgetSize.height(), m_widgetSize.width(), SIZE);
123 if (isHorizontal()) {
124 const qreal width = m_widgetSize.width() / 2.;
125 QRectF left(0, 0, width, m_widgetSize.height());
126 QRectF right(width, 0, width, m_widgetSize.height());
127 if (left.contains(hoverPos)) {
129 }
else if (right.contains(hoverPos)) {
133 const qreal height = m_widgetSize.height() / 2.;
134 QRectF top(0, 0, m_widgetSize.width(), height);
135 QRectF bottom(0, height, m_widgetSize.width(), height);
136 if (top.contains(hoverPos)) {
138 }
else if (bottom.contains(hoverPos)) {
143 widget()->removeEventFilter(
this);
144 switch (m_location) {
146 widget()->setPos(m_widgetPos + QPointF(SIZE, 0));
150 widget()->setPos(m_widgetPos + QPointF(0, SIZE));
154 widget()->setPos(m_widgetPos + QPointF(-SIZE, 0));
158 widget()->setPos(m_widgetPos + QPointF(0, -SIZE));
165 widget()->installEventFilter(
this);
168 bool GridHandle::isHorizontal()
const
171 return rect.width() >= rect.height();
176 m_widgetSize =
widget()->size();
181 if (event->button() == Qt::LeftButton) {
182 m_lastButton = mapToButton(event->pos());
184 m_startPos =
event->pos();
200 QPointF p(event->pos() - m_startPos);
201 widget()->moveBy(p.x(), p.y());
211 if (event->button() != Qt::LeftButton) {
218 if (button != m_lastButton) {
230 m_widgetPos =
widget()->pos();
246 applet()->showConfigurationInterface();
255 applet()->runAssociatedApplication();
267 QRectF GridHandle::fullRect()
const
274 if (!fullRect().contains(event->pos())) {
282 const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
283 QRectF iconRect(
boundingRect().topLeft() + QPointF(2, 2), iconSize);
285 if ((
applet() &&
applet()->hasConfigurationInterface()) || (
group() &&
group()->hasConfigurationInterface())) {
286 if (iconRect.contains(pos)) {
290 if (isHorizontal()) {
291 iconRect.translate(0, iconSize.height());
293 iconRect.translate(iconSize.width(), 0);
297 if (
applet() &&
applet()->hasValidAssociatedApplication()) {
298 if (iconRect.contains(pos)) {
303 if (isHorizontal()) {
304 iconRect.moveTo(
boundingRect().bottomLeft() - QPointF(-2, iconSize.height() + 2));
306 iconRect.moveTo(
boundingRect().topRight() - QPointF(iconSize.width() + 2, -2));
309 if (iconRect.contains(pos)) {
317 bool GridHandle::enoughRoom()
319 const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
320 int buttonsCount = 2;
322 if ((
applet() &&
applet()->hasConfigurationInterface()) || (
group() &&
group()->hasConfigurationInterface())) {
326 if (
applet() &&
applet()->hasValidAssociatedApplication()) {
330 return ((isHorizontal() &&
boundingRect().height() > buttonsCount * iconSize.height()) ||
331 (!isHorizontal() &&
boundingRect().width() > buttonsCount * iconSize.width()));
340 painter->setPen(Qt::NoPen);
341 painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
343 QPainterPath p = Plasma::PaintUtils::roundedRectangle(rect.adjusted(1, 1, -2, -2), 4);
344 QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
347 painter->fillPath(p, c);
360 shiftC = QPointF(2, 2);
363 shiftD = QPointF(2, 2);
366 shiftMx = QPointF(2, 2);
372 const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
373 QRectF iconRect(
boundingRect().topLeft() + QPointF(2, 2), iconSize);
375 if ((
applet() &&
applet()->hasConfigurationInterface()) || (
group() &&
group()->hasConfigurationInterface())) {
376 m_configureIcons->paint(painter, iconRect.translated(shiftC),
"configure");
377 if (isHorizontal()) {
378 iconRect.translate(0, iconSize.height());
380 iconRect.translate(iconSize.width(), 0);
384 if (
applet() &&
applet()->hasValidAssociatedApplication()) {
385 m_configureIcons->paint(painter, iconRect.translated(shiftMx),
"maximize");
388 if (isHorizontal()) {
389 iconRect.moveTo(
boundingRect().bottomLeft() - QPointF(-2, iconSize.height() + 2));
391 iconRect.moveTo(
boundingRect().topRight() - QPointF(iconSize.width() + 2, -2));
393 m_configureIcons->paint(painter, iconRect.translated(shiftD),
"close");
396 #include "gridhandle.moc"
bool eventFilter(QObject *obj, QEvent *event)
GridHandle(GroupingContainment *containment, Plasma::Applet *applet)
void disappearDone(Handle *self)
virtual void showConfigurationInterface()
Lets the user interact with the Group options.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual void detachWidget()
void setHoverPos(const QPointF &hoverPos)
void setMovingWidget(QGraphicsWidget *widget)
Call this function when an Applet or a Group is being moved by the user.
GroupingContainment * containment() const
Plasma::Applet * applet() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
AbstractGroup * group() const
QGraphicsWidget * widget() const
QRectF boundingRect() const
The base Containment class.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void destroy()
Destroy this Groups and its children, deleting the configurations too.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void widgetMoved(QGraphicsWidget *widget)
void mousePressEvent(QGraphicsSceneMouseEvent *event)