1 /////////////////////////////////////////////////////////////////////////
4 // Copyright(C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>//
5 // Copyright(C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>//
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. //
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. //
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 //
21 /////////////////////////////////////////////////////////////////////////
27 OmniItem::OmniItem( QGraphicsItem
*parent
)
28 : QGraphicsWidget(parent
)
30 setAcceptedMouseButtons(Qt::LeftButton
);
31 setAcceptHoverEvents(true);
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() );
44 mPixmap
= item
.mPixmap
;
52 void OmniItem::setPixmapPath( const QString
&pixmapPath
)
54 if ( !mPixmap
.load( pixmapPath
) )
55 qDebug("error loading pixmap");
58 void OmniItem::setText( const QString
&text
)
63 void OmniItem::paint ( QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
70 pen
.setCapStyle( Qt::FlatCap
);
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);
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())
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
)
107 void OmniItem::hoverEnterEvent ( QGraphicsSceneHoverEvent
* event
)
110 hasHoverEnter
= true;
114 void OmniItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent
* event
)
117 hasHoverEnter
= false;