The API changed for rotations, requiring another argument for positions.
[contacts_plasmoid.git] / omniitem.cpp
blobf5c6377960538e0e22825383f589112d8068264c
1 /////////////////////////////////////////////////////////////////////////
2 // omniitem.cpp //
3 // //
4 // Copyright(C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>//
5 // Copyright(C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>//
6 // //
7 // This library is free software; you can redistribute it and/or //
8 // modify it under the terms of the GNU Lesser General Public //
9 // License as published by the Free Software Foundation; either //
10 // version 2.1 of the License, or (at your option) any later version. //
11 // //
12 // This library is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
15 // Lesser General Public License for more details. //
16 // //
17 // You should have received a copy of the GNU Lesser General Public //
18 // License along with this library; if not, write to the Free Software //
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA //
20 // 02110-1301 USA //
21 /////////////////////////////////////////////////////////////////////////
22 #include "omniitem.h"
24 #include <QDebug>
25 #include <QPainter>
27 OmniItem::OmniItem( QGraphicsItem *parent)
28 : QGraphicsWidget(parent)
30 setAcceptedMouseButtons(Qt::LeftButton);
31 setAcceptHoverEvents(true);
32 setMinimumSize(0,0);
33 setFlag(QGraphicsItem::ItemClipsToShape, true);
36 OmniItem::OmniItem(OmniItem &item)
38 setMinimumSize( 0,0 );
39 setFlag( QGraphicsItem::ItemClipsToShape, true );
40 setFlag( ItemIgnoresParentOpacity );
41 setGeometry( item.geometry() );
42 setPos( 0, 0 );
43 mText = item.mText;
44 mPixmap = item.mPixmap;
45 hasHoverEnter = true;
48 OmniItem::~OmniItem()
52 void OmniItem::setPixmapPath( const QString &pixmapPath)
54 if ( !mPixmap.load( pixmapPath ) )
55 qDebug("error loading pixmap");
58 void OmniItem::setText( const QString &text)
60 mText = text;
63 void OmniItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
66 Q_UNUSED(option);
67 Q_UNUSED(widget);
69 QPen pen;
70 pen.setCapStyle( Qt::FlatCap );
71 pen.setWidth(2);
72 if ( hasHoverEnter ) {
73 pen.setColor(Qt::darkGray);
74 painter->setPen( pen );
75 painter->setBrush( Qt::white );
76 painter->drawRoundedRect(QRectF(rect().x(), rect().y(), rect().width(), rect().height() - 10), 20, 20);
78 } else {
79 pen.setColor(Qt::lightGray);
80 painter->setPen( pen );
81 painter->drawRoundedRect(QRectF(rect().x(), rect().y(), rect().width(), rect().height() - 10), 20, 20);
85 QRectF geometryTemporary;
86 if (!geometry().width())
87 return;
89 geometryTemporary.setX(mPixmap.width()+20);
90 geometryTemporary.setY(mPixmap.height()/2);
91 geometryTemporary.setWidth(130);
92 geometryTemporary.setHeight(40);
93 painter->drawPixmap(mPixmap.rect(), mPixmap);
95 pen.setColor(Qt::black);
96 painter->setPen( pen );
97 painter->drawText(geometryTemporary, Qt::AlignCenter, mText);
101 void OmniItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
103 Q_UNUSED(event);
104 emit clicked();
107 void OmniItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
109 Q_UNUSED(event);
110 hasHoverEnter = true;
111 update();
114 void OmniItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
116 Q_UNUSED(event);
117 hasHoverEnter = false;
118 update();