Context menu added to bring item front/send to back/delete added
git-svn-id: https://svn.code.sf.net/p/qlscribe/svn/trunk@33 cac9541e-1b8d-4bfa-827e-589bba606050
This commit is contained in:
@@ -204,6 +204,9 @@ void QCDScene::contextMenuEvent( QGraphicsSceneContextMenuEvent *mouseEvent )
|
||||
item->setSelected( true );
|
||||
QMenu menu;
|
||||
menu.addAction( tr( "edit..." ), this, SLOT( onMenuEdit() ) );
|
||||
menu.addAction( tr( "bring to Front" ), this, SLOT( onMenuToFront() ) );
|
||||
menu.addAction( tr( "send to Back" ), this, SLOT( onMenuToBack() ) );
|
||||
menu.addAction( tr( "delete" ), this, SLOT( onMenuDelete() ) );
|
||||
menu.exec( mouseEvent->screenPos() );
|
||||
}
|
||||
|
||||
@@ -215,3 +218,43 @@ void QCDScene::onMenuEdit()
|
||||
QGraphicsItem *item = list.front();
|
||||
QShapeFactory::instance().edit( item, 0 );
|
||||
}
|
||||
|
||||
void QCDScene::onMenuToFront()
|
||||
{
|
||||
sendItemTo( true );
|
||||
}
|
||||
|
||||
void QCDScene::onMenuToBack()
|
||||
{
|
||||
sendItemTo( false );
|
||||
}
|
||||
|
||||
void QCDScene::onMenuDelete()
|
||||
{
|
||||
QList<QGraphicsItem *> list = selectedItems();
|
||||
if( list.empty() )
|
||||
return;
|
||||
QGraphicsItem *item = list.front();
|
||||
removeItem( item );
|
||||
delete item;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void QCDScene::sendItemTo( bool front )
|
||||
{
|
||||
if ( selectedItems().isEmpty())
|
||||
return;
|
||||
|
||||
QGraphicsItem *selectedItem = selectedItems().first();
|
||||
QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems();
|
||||
|
||||
qreal zValue = 0;
|
||||
foreach( QGraphicsItem *item, overlapItems ) {
|
||||
if( front && item->zValue() >= zValue )
|
||||
zValue = item->zValue() + 0.1;
|
||||
|
||||
if( !front && item->zValue() <= zValue )
|
||||
zValue = item->zValue() - 0.1;
|
||||
}
|
||||
selectedItem->setZValue( zValue );
|
||||
}
|
||||
|
||||
@@ -49,10 +49,14 @@ protected:
|
||||
|
||||
private slots:
|
||||
void onMenuEdit();
|
||||
void onMenuToFront();
|
||||
void onMenuToBack();
|
||||
void onMenuDelete();
|
||||
|
||||
private:
|
||||
void write( QXmlStreamWriter &writer );
|
||||
void read( QXmlStreamReader &reader );
|
||||
void sendItemTo( bool front );
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
|
||||
+2
-1
@@ -83,7 +83,8 @@ void QCDView::closeEvent( QCloseEvent *event )
|
||||
inline
|
||||
void drawCircle( QPainter *painter, double radi )
|
||||
{
|
||||
painter->drawEllipse( -radi, -radi, radi * 2, radi * 2 );
|
||||
painter->drawEllipse( int( -radi ), int( -radi ),
|
||||
int( radi * 2 ), int( radi * 2 ) );
|
||||
}
|
||||
|
||||
void QCDView::drawCD( QPainter *painter, const QRectF & rect, bool alpha )
|
||||
|
||||
Reference in New Issue
Block a user