{
Q_OBJECT
public:
CCanGraphicsItem
( int x,
int y,
QString strText
) : m_rect
( 10,
10,
200,
100 ), m_color
( QColor(255,
255,
255,
255) ) {
m_strText = strText;
setPos( x, y );
}
{
// painter->setRenderHint(QPainter::Antialiasing, true);
painter->setFont( *m_pFont );
painter->setPen(Qt::SolidLine);
painter->setBrush(m_color);
painter->drawRoundRect( m_rect );//10, 10, 100, 100);
painter->drawText( 20, 20, 190, 90, Qt::AlignCenter, m_strText );//, m_rect );
}
QRectF boundingRect
() const { return m_rect;
}
signals:
void ShowOptions();
protected:
{
emit ShowOptions();
}
{
}
};
class CCanGraphicsItem : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
CCanGraphicsItem( int x, int y, QString strText ) : m_rect( 10, 10, 200, 100 ), m_color( QColor(255,255,255,255) )
{
m_strText = strText;
setPos( x, y );
m_pFont = new QFont("Times", 20, QFont::Bold );
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// painter->setRenderHint(QPainter::Antialiasing, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
painter->setFont( *m_pFont );
painter->setPen(Qt::SolidLine);
painter->setBrush(m_color);
painter->drawRoundRect( m_rect );//10, 10, 100, 100);
painter->drawText( 20, 20, 190, 90, Qt::AlignCenter, m_strText );//, m_rect );
}
QRectF boundingRect() const { return m_rect; }
signals:
void ShowOptions();
protected:
void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event )
{
QMessageBox::information(0, "This", m_strText );
emit ShowOptions();
}
void contextMenuEvent(QContextMenuEvent *event)
{
}
QRectF m_rect;
QColor m_color;
QString m_strText;
QFont* m_pFont;
};
To copy to clipboard, switch view to plain text mode
void CanScene
::AddBoxItem( int x,
int y,
QString strText, ITEMS item
) {
switch( item )
{
case CAN :
addItem( pItem = new CCanGraphicsItem( x, y, strText ) );
QObject::connect( pItem,
SIGNAL(ShowOptions
()),
this,
SLOT(ShowCanOptions
()) );
break;
// etc...
}
}
void CanScene::AddBoxItem( int x, int y, QString strText, ITEMS item )
{
QGraphicsItem* pItem = NULL;
switch( item )
{
case CAN :
addItem( pItem = new CCanGraphicsItem( x, y, strText ) );
QObject::connect( pItem, SIGNAL(ShowOptions()),this,SLOT(ShowCanOptions()) );
break;
// etc...
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks