⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncreportdesignerdesignarea.cpp

📁 基于QT的报表工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
										sizePreviewLabel->adjustSize();					QRect lg( mapFromGlobal( e->globalPos() ) + QPoint( 16, 16 ), sizePreviewLabel->size() );					//checkGeometry( lg );					sizePreviewLabel->setGeometry( lg );					sizePreviewLabel->raise();					sizePreviewLabel->show();					#if defined(Q_WS_WIN32)						//windowsRepaintWorkaroundTimer->start( 100, TRUE );					#endif				} else { // if we don't need to move, do some indication					QRect lg( mapFromGlobal( e->globalPos() ) + QPoint( 16, 16 ), sizePreviewLabel->size() );					//checkGeometry( lg );					sizePreviewLabel->move( lg.x(), lg.y() );				}						oldPressPos += ( p - w->pos() );			} else if ( drawRubber ) { // draw rubber if we are in rubber-selection mode				continueRectDraw( mapFromGlobal( e->globalPos() ), e->globalPos(), this, Rubber );			}			break;		default:			if ( insertParent ) // draw insert rect				continueRectDraw( w->mapFromGlobal( e->globalPos() ), e->globalPos(), w, Insert );			break;	}	}void NCReportDesignerDesignArea::handleMouseRelease( QMouseEvent *e, QWidget *w ){	if ( e->button() != Qt::LeftButton )		return;	switch ( currTool ) {		case PointerTool:			if ( widgetPressed && allowMove( w ) ) { // we moved the widget				sizePreviewLabel->hide();				if ( moving.isEmpty() || w->pos() == *moving.find(w) )					break;								QWidgetList widgets; // collect the widgets and its old and new positions which have been moved				QValueList<QPoint> oldPos, newPos;				QMapConstIterator<QWidget*,QPoint> it = moving.begin();				for ( it = moving.begin(); it != moving.end(); ++it ) {					widgets.append( it.key() );					oldPos.append( *it );					newPos.append( it.key()->pos() );				}				// add move command, don't execute it, this is just a summary of the operations we did during the move-event handling				commandHistory()->addCommand( new cmd_MoveCommand( tr( "Move" ), this, widgets, oldPos, newPos, insertParent, insertParent ) );				document->setModified( TRUE );										} else if ( drawRubber ) { // we were drawing a rubber selection				endRectDraw(); // get rid of the rectangle				blockSignals( TRUE );				selectWidgets(); // select widgets which intersect the rect				blockSignals( FALSE );				emitSelectionChanged(); // inform about selection changes			}			break;		default: // any insert widget tool is active			if ( insertParent ) { // we should insert the new widget now				endRectDraw();				insertWidget(); // insert report widget			}			break;	}	widgetPressed = FALSE;	drawRubber = FALSE;	insertParent = 0;	delete buffer;	buffer = 0;}void NCReportDesignerDesignArea::handleKeyPress( QKeyEvent *e, QWidget *w ){	e->ignore();	//checkSelectionsTimer->stop();	//if ( !checkedSelectionsForMove && ( e->key() == Key_Left ||	 e->key() == Key_Right ||  e->key() == Key_Up ||  e->key() == Key_Down ) && propertyWidget->isWidgetType() )	//	checkSelectionsForMove( (QWidget*)propertyWidget );	//checkSelectionsTimer->start( 1000, TRUE );	if ( e->key() == Key_Left || e->key() == Key_Right || e->key() == Key_Up || e->key() == Key_Down ) {		QWidgetList widgets;		QValueList<QPoint> oldPos, newPos;		for ( Selection *s = selections.first(); s; s = selections.next() ) {			if ( s->isUsed() ) {				int dx = 0, dy = 0;				bool control = e->state() & ControlButton;				switch ( e->key() ) {					case Key_Left: {						e->accept();						if ( control )							dx = -1;						else							dx = -grid().x();					} break;					case Key_Right: {						e->accept();						if ( control )							dx = 1;						else							dx = grid().x();					} break;					case Key_Up: {						e->accept();						if ( control )							dy = -1;						else							dy = -grid().y();					} break;					case Key_Down: {						e->accept();						if ( control )							dy = 1;						else							dy = grid().y();					} break;					default:						break;				}				widgets.append( s->widget() );				oldPos.append( s->widget()->pos() );				newPos.append( s->widget()->pos() + QPoint( dx, dy ) );			}		}		if ( !widgets.isEmpty() ) {			cmd_MoveCommand *cmd = new cmd_MoveCommand( tr( "Move" ), this, widgets, oldPos, newPos, 0, 0 );			commandHistory()->addCommand( cmd, TRUE );			cmd->execute();		}	} else if ( e->key() == Key_Delete ) {		deleteWidgets();	}	if ( !e->isAccepted() ) {		QObjectList *l = queryList( "QWidget" );		if ( !l )			return;		if ( l->find( w ) != -1 )			e->accept();		delete l;	}	}void NCReportDesignerDesignArea::handleKeyRelease( QKeyEvent *e, QWidget * ){	e->ignore();}void NCReportDesignerDesignArea::selectWidget( QObject *o, bool select ){	if ( !o->isWidgetType() )		return;	QWidget *w = (QWidget*)o;	if ( select ) {/*		QObject *opw = propertyWidget;		propertyWidget = w;		if ( opw->isWidgetType() )			repaintSelection( (QWidget*)opw );*/		Selection *s = usedSelections.find( w );		if ( s ) {			s->show();			return;		}		for ( Selection *s2 = selections.first(); s2; s2 = selections.next() ) {			if ( !s2->isUsed() ) {				s = s2;			}		}		if ( !s ) {			s = new Selection( this, &usedSelections );			selections.append( s );		}		s->setWidget( w );		emitSelectionChanged();	} else {		Selection *s = usedSelections.find( w );		if ( s )			s->setWidget( 0 );/*		QObject *opw = propertyWidget;		if ( !usedSelections.isEmpty() )			propertyWidget = QPtrDictIterator<WidgetSelection>( usedSelections ).current()->widget();		else			propertyWidget = mainContainer();		if ( opw->isWidgetType() )			repaintSelection( (QWidget*)opw );		if ( !isPropertyShowingBlocked() )			emitShowProperties( propertyWidget );*/		emitSelectionChanged();	}	}QPoint NCReportDesignerDesignArea::grid() const{	if ( !mainWindow() || !mainWindow()->snapGrid() )		return QPoint( 1, 1 );	return mainWindow()->grid();}void NCReportDesignerDesignArea::updateSelection( QWidget *w ){	Selection *s = usedSelections[ w ];	if ( !w->isVisibleTo( this ) )		selectWidget( w, FALSE );	else if ( s )		s->updateGeometry();}void NCReportDesignerDesignArea::raiseSelection( QWidget *w ){	Selection *s = usedSelections[ w ];	if ( s )		s->show();}void NCReportDesignerDesignArea::repaintSelection( QWidget *w ){	Selection *s = usedSelections[ w ];	if ( s )		s->update();}void NCReportDesignerDesignArea::clearSelection( bool ){/*	QHashIterator<QWidget*,Selection*> it( usedSelections );	while ( it.hasNext() ) {		it.next();		it.value()->setWidget( 0, FALSE );	}*/	QPtrDictIterator<Selection> it( usedSelections );	for ( ; it.current(); ++it )		it.current()->setWidget( 0, FALSE );	usedSelections.clear();	emitSelectionChanged();}void NCReportDesignerDesignArea::startRectDraw( const QPoint &p, const QPoint &global, QWidget *, RectType t ){	QPoint pos( p );	pos = mapFromGlobal( global );	oldRectValid = FALSE;	beginUnclippedPainter( TRUE );	if ( t == Rubber ) {		QPen pen( Qt::black, 0, Qt::DotLine );		unclippedPainter->setPen( pen );	} 	if ( t == Insert )		rectAnchor = gridPoint( pos );	else if ( t == Rubber )		rectAnchor = pos;	currRect = QRect( rectAnchor, QPoint( 0, 0 ) );	if ( t == Insert )		drawSizePreview( pos, tr("Use Size Hint") );}void NCReportDesignerDesignArea::continueRectDraw( const QPoint &p, const QPoint &global, QWidget *, RectType t ){	QPoint pos =p;	pos = mapFromGlobal( global );	QPoint p2;	if ( t == Insert )		p2 = gridPoint( pos );	else if ( t == Rubber )		p2 = pos;	QRect r( rectAnchor, p2 );	r = r.normalize();	if ( currRect == r ) {		QString t = tr( "%1/%2" );		t = t.arg( r.width() - 1 ).arg( r.height() - 1 );		drawSizePreview( pos, t );		return;	}	if ( oldRectValid )		unclippedPainter->drawRect( currRect );	if ( r.width() > 1 || r.height() > 1 ) {		oldRectValid = TRUE;		currRect = r;		if ( t == Insert ) {			QString t = tr( "%1/%2" );			t = t.arg( r.width() - 1 ).arg( r.height() - 1 );			drawSizePreview( pos, t );		}		unclippedPainter->setClipRegion( QRegion( rect() ).subtract( QRect( sizePreviewPos, sizePreviewPixmap.size() ) ) );		unclippedPainter->drawRect( currRect );		unclippedPainter->setClipping( FALSE );	} else {		oldRectValid = FALSE;		if ( t == Insert )			drawSizePreview( pos, tr("Use Size Hint") );	}}void NCReportDesignerDesignArea::endRectDraw(){	if ( !unclippedPainter )		return;	if ( oldRectValid )		unclippedPainter->drawRect( currRect );	drawSizePreview( QPoint(-1,-1), QString::null );	endUnclippedPainter();}void NCReportDesignerDesignArea::selectWidgets(){	QObjectList *l = queryList( "QWidget" );	if ( l ) {		for ( QObject *o = l->first(); o; o = l->next() ) {			if ( ( (QWidget*)o )->isVisibleTo( this ) && insertedWidgets[ (void*)o ] ) {			//if (::qt_cast<NCReportDesignerWidget*>(o) ) {				QPoint p = ( (QWidget*)o )->mapToGlobal( QPoint(0,0) );				p = mapFromGlobal( p );				QRect r( p, ( (QWidget*)o )->size() );				if ( r.intersects( currRect ) && !r.contains( currRect ) )					selectWidget( (QWidget*)o );			}		}		delete l;	}	emitSelectionChanged();}bool NCReportDesignerDesignArea::isWidgetSelected( QObject *w ){	if ( w->isWidgetType() )		return usedSelections.find( (QWidget*)w ) != 0;	return FALSE; // #### do stuff for QObjects}void NCReportDesignerDesignArea::moveSelectedWidgets( int dx, int dy ){	QPtrDictIterator<Selection> it( usedSelections );	for ( ; it.current(); ++it ) {		Selection *s = it.current();		QWidget *w = s->widget();		w->move( w->x() + dx, w->y() + dy );		s->updateGeometry();		//updateChildSelections( w );	}}void NCReportDesignerDesignArea::checkSelectionsForMove( QWidget * ){	checkedSelectionsForMove = TRUE;	QObjectList *l = queryList( "QWidget", 0, FALSE, FALSE );	moving.clear();	if ( l ) {		QPtrDictIterator<Selection> it( usedSelections );		Selection *sel;		while ( ( sel = it.current() ) != 0 ) {			//if ( it.current()->widget() == mainContainer() )			//if ( it.current()->widget() == this )			//	continue;			++it;			if ( l->find( sel->widget() ) == -1 ) {				sel->setWidget( 0 );			} else {				moving.insert( sel->widget(), sel->widget()->pos() );				//sel->widget()->raise();				//raiseChildSelections( sel->widget() );				//raiseSelection( sel->widget() );			}		}		delete l;	}}void NCReportDesignerDesignArea::deleteWidgets(){	QWidgetList widgets;	QPtrDictIterator<Selection> it( usedSelections );	for ( ; it.current(); ++it ) {		//QWidget *tb = 0;		widgets.append( it.current()->widget() );	}	if ( widgets.isEmpty() )		return;	cmd_DeleteCommand *cmd = new cmd_DeleteCommand( tr("Delete"), this, widgets );	commandHistory()->addCommand( cmd );	cmd->execute();}void NCReportDesignerDesignArea::editAdjustSize(){}void NCReportDesignerDesignArea::alignWidgets( Qt::AlignmentFlags af ){/*	checkSelectionsForMove( 0 );	if ( moving.isEmpty() || w->pos() == *moving.find(w) )		break;					QWidgetList widgets; // collect the widgets and its old and new positions which have been moved	QValueList<QPoint> oldPos, newPos;	QMapConstIterator<QWidget*,QPoint> it = moving.begin();	for ( it = moving.begin(); it != moving.end(); ++it ) {		widgets.append( it.key() );		oldPos.append( *it );		newPos.append( it.key()->pos() );	}*/		QWidgetList widgets;	QValueList<QPoint> oldPos, newPos;	int cnt =0;	QWidget *baseWidget = 0;	QPtrDictIterator<Selection> it( usedSelections );	int nx=0,ny=0;	QPoint npos(0,0);	for ( ; it.current(); ++it ) {		QWidget *sw = it.current()->widget();		if ( cnt == 0 ) { // base widget			baseWidget = sw;		}		switch ( af ) {			case Qt::AlignTop: {				nx = sw->pos().x(); 	// original x coord				ny = baseWidget->pos().y();				break;			}			case Qt::AlignBottom: {				nx = sw->pos().x(); 	// original x coord				ny = baseWidget->pos().y()+baseWidget->height() - sw->height();				break;			}			case Qt::AlignLeft: {				nx = baseWidget->pos().x();				ny = sw->y();				break;			}			case Qt::AlignRight: {				nx = baseWidget->pos().x() + baseWidget->width() - sw->width();				ny = sw->y();				break;			}			case Qt::AlignHCenter: {				nx = sw->pos().x(); 	// original x coord				ny = baseWidget->pos().y() + baseWidget->height()/2 - sw->height()/2;				break;			}			case Qt::AlignVCenter: {				nx = baseWidget->pos().x() + baseWidget->width()/2 - sw->width()/2;				ny = sw->pos().y(); 	// original y coord				break;			}			default: break;		}		if ( cnt>0 ) {	// move only non 'base' widgets			oldPos.append( sw->pos() );			newPos.append( QPoint( nx,ny ) );			widgets.append( sw );		}		cnt++;	}	if ( widgets.isEmpty() )		return;		// add move command, don't execute it, this is just a summary of the operations we did during the move-event handling	cmd_MoveCommand *cmd = new cmd_MoveCommand( tr( "Align" ), this, widgets, oldPos, newPos, 0, 0 );	commandHistory()->addCommand( cmd, TRUE );	cmd->execute();		//commandHistory()->addCommand( new cmd_MoveCommand( tr( "Align" ), this, widgets, oldPos, newPos, this, this ) );				}QWidgetList NCReportDesignerDesignArea::selectedWidgets() const{	QWidgetList widgets;	QPtrDictIterator<Selection> it( usedSelections );	for ( ; it.current(); ++it )		widgets.append( it.current()->widget() );	return widgets;}void NCReportDesignerDesignArea::widgetChanged( QObject *w ){	if ( w->isWidgetType() )		updateSelection( (QWidget*)w );    // ########## do QObject stuff}QLabel *NCReportDesignerDesignArea::sizePreview() const{	if ( !sizePreviewLabel ) {		( (NCReportDesignerDesignArea*)this )->sizePreviewLabel = new QLabel( (NCReportDesignerDesignArea*)this, "sizePreviewLabel", Qt::WStyle_StaysOnTop );		( (NCReportDesignerDesignArea*)this )->sizePreviewLabel->hide();		//( (NCReportDesignerDesignArea*)this )->sizePreviewLabel->setBackgroundColor( QColor( 255, 255, 128 ) );		( (NCReportDesignerDesignArea*)this )->sizePreviewLabel->setFrameStyle( QFrame::Plain | QFrame::Box );	}	return sizePreviewLabel;}void NCReportDesignerDesignArea::invalidCheckedSelections(){	checkedSelectionsForMove = FALSE;}void NCReportDesignerDesignArea::checkGeometry( QRect &r ){	if ( !rect().contains( r ) ) {		if ( r.left() < rect().left() )			r.moveTopLeft( QPoint( 0, r.top() ) );		if ( r.right() > rect().right()  )			r.moveBottomRight( QPoint( rect().right(), r.bottom() ) );		if ( r.top() < rect().top() )			r.moveTopLeft( QPoint( r.left(), rect().top() ) );		if ( r.bottom() > rect().bottom()  )			r.moveBottomRight( QPoint( r.right(), rect().bottom() ) );	}}void NCReportDesignerDesignArea::focusInEvent( QFocusEvent * ){	QPainter p( this );	paintFocus( &p, true );}void NCReportDesignerDesignArea::focusOutEvent( QFocusEvent * ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -