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:
ruglory
2009-01-31 00:26:33 +00:00
parent e0f6307fd4
commit 79813e4a8a
3 changed files with 49 additions and 1 deletions
+43
View File
@@ -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 );
}
+4
View File
@@ -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
View File
@@ -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 )