📄 ncreportdesignerdesignarea.cpp
字号:
QPainter p( this ); paintFocus( &p, false ); //clearSelection();/* if ( propertyWidget && !isMainContainer( propertyWidget ) && !isWidgetSelected( propertyWidget ) ) { QObject *opw = propertyWidget; propertyWidget = mainContainer(); if ( opw->isWidgetType() ) repaintSelection( (QWidget*)opw ); }*/}void NCReportDesignerDesignArea::resizeEvent( QResizeEvent * ){/* QWidget::resizeEvent( e ); if ( isVisible() ) formFile()->setModified( TRUE, FormFile::WNCReportDesignerDesignArea );#if defined(Q_WS_WIN32) windowsRepaintWorkaroundTimer->start( 100, TRUE );#endif}void NCReportDesignerDesignArea::windowsRepaintWorkaroundTimerTimeout(){#if defined(Q_WS_WIN32) QObjectList *l = queryList( "QWidget" ); for ( QObject *o = l->first(); o; o = l->next() ) { flickerfree_update( (QWidget*)o ); } flickerfree_update( this ); delete l;#endif*/}QPtrDict<QWidget> *NCReportDesignerDesignArea::widgets(){ return &insertedWidgets;}QWidget *NCReportDesignerDesignArea::designerWidget( QObject * ) const{/* if ( !o || !o->isWidgetType() ) return 0; QWidget *w = (QWidget*)o; while ( w && !isMainContainer( w ) && !insertedWidgets[ (void*)w ] || isCentralWidget( w ) ) w = (QWidget*)w->parent(); return w;*/ return 0;}void NCReportDesignerDesignArea::emitSelectionChanged(){/* selectionChangedTimer->stop(); selectionChangedTimer->start( 0, TRUE );*/}void NCReportDesignerDesignArea::updatePropertiesTimerDone(){/* if ( propertyWidget && mainWindow()->NCReportDesignerDesignArea() == this ) emit updateProperties( propertyWidget );*/}void NCReportDesignerDesignArea::showPropertiesTimerDone(){/* if ( propertyWidget && mainWindow()->NCReportDesignerDesignArea() == this ) emit showProperties( propertyWidget );*/}void NCReportDesignerDesignArea::selectionChangedTimerDone(){ emit selectionChanged();}void NCReportDesignerDesignArea::toolChanged(){ toolFixed = FALSE; int t = mwindow->currentTool(); if ( currTool == t )//&& t != ORDER_TOOL ) return; // tool cleanup switch ( currTool ) { case PointerTool: break; default: if ( insertParent ) endRectDraw(); break; } startWidget = endWidget = 0; widgetPressed = FALSE; drawRubber = FALSE; insertParent = 0; delete buffer; buffer = 0; currTool = t; if ( hasFocus() ) clearSelection( FALSE ); mainWindow()->statusBar()->clear(); // tool setup switch ( currTool ) { case PointerTool: restoreCursors( this, this ); break; default: mainWindow()->statusBar()->message( tr( "Click on the form to insert a %1..." ).arg( "xxx" ) ); setCursorToAll( CrossCursor, this ); //if ( mainWindow()->NCReportDesignerDesignArea() == this ) // emitShowProperties( mainContainer() ); break; }}void NCReportDesignerDesignArea::showOrderIndicators(){}void NCReportDesignerDesignArea::hideOrderIndicators(){}void NCReportDesignerDesignArea::updateOrderIndicators(){}void NCReportDesignerDesignArea::repositionOrderIndicators(){}void NCReportDesignerDesignArea::updateUndoInfo(){// commandHistory()->emitUndoRedo();}bool NCReportDesignerDesignArea::checkCustomWidgets(){ return TRUE;}int NCReportDesignerDesignArea::numSelectedWidgets() const{ return usedSelections.count();}void NCReportDesignerDesignArea::lowerWidgets(){ QWidgetList widgets; QPtrDictIterator<Selection> it( usedSelections ); for ( ; it.current(); ++it ) widgets.append( it.current()->widget() ); cmd_LowerCommand *cmd = new cmd_LowerCommand( tr( "Lower" ), this, widgets ); cmd->execute(); commandHistory()->addCommand( cmd );}void NCReportDesignerDesignArea::raiseWidgets(){ QWidgetList widgets; QPtrDictIterator<Selection> it( usedSelections ); for ( ; it.current(); ++it ) widgets.append( it.current()->widget() ); cmd_RaiseCommand *cmd = new cmd_RaiseCommand( tr( "Raise" ), this, widgets ); cmd->execute(); commandHistory()->addCommand( cmd );}QString NCReportDesignerDesignArea::copy(){ NCReportDesignerResourceHandler resource; resource.setDocument( document ); resource.setDesignArea( this ); resource.setMeasurement( m ); return resource.copy();}void NCReportDesignerDesignArea::paste( const QString &cb, QWidget *parent ){ NCReportDesignerResourceHandler resource; resource.setDocument( document ); resource.setDesignArea( this ); resource.setMeasurement( m ); resource.paste( cb, parent );}void NCReportDesignerDesignArea::selectAll(){ checkedSelectionsForMove = FALSE; blockSignals( TRUE ); QObjectList *l = queryList( "QWidget" ); if ( l ) { for ( QObject *o = l->first(); o; o = l->next() ) { if ( ( (QWidget*)o )->isVisibleTo( this ) && insertedWidgets[ (void*)o ] ) { selectWidget( (QWidget*)o ); } } delete l; } blockSignals( FALSE ); emitSelectionChanged();}int NCReportDesignerDesignArea::numVisibleWidgets() const{/* QPtrDictIterator<QWidget> it( insertedWidgets ); int visible = 0; for ( ; it.current(); ++it ) { if ( it.current()->isVisibleTo( (NCReportDesignerDesignArea*)this ) ) visible++; } return visible;*/ return 0;}bool NCReportDesignerDesignArea::allowMove( QWidget * ){/* w = w->parentWidget(); while ( w ) { if ( ( isMainContainer( w ) || insertedWidgets.find( w ) ) && WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) return TRUE; w = w->parentWidget(); }*/ return TRUE;}void NCReportDesignerDesignArea::editConnections(){/* buffer = 0; if ( !startWidget || !endWidget ) return; ConnectionDialog dlg( mwindow ); mainWindow()->statusBar()->message( tr( "Edit connections...") ); dlg.addConnection( startWidget, endWidget, QString::null, QString::null ); QTimer::singleShot( 0, &dlg, SLOT(ensureConnectionVisible()) ); dlg.exec();*/}void NCReportDesignerDesignArea::saveBackground(){/* if ( buffer ) delete buffer; buffer = new QPixmap( width(), height() ); *buffer = QPixmap::grabWindow( winId() );*/}void NCReportDesignerDesignArea::restoreConnectionLine(){/* if (!unclippedPainter || !buffer) // designer will occasionally crash if buffer is not tested to be non-zero return; int a =qAbs( startPos.x() - currentPos.x() ); int b = qAbs( startPos.y() - currentPos.y() ); QRect r( startPos, currentPos ); if ( a < 32 || b < 32 ) { // special case: vertical or horizontal line r = r.normalized(); unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, r.width() + 4, r.height() + 4 ); return; } if ( a <= 0 ) a = 1; if ( b <= 0 ) b = 1; int w, h; if ( b > a ) { h = 64; w = ( a * h ) / b; } else { w = 64; h = ( b * w ) / a; } int dx = 2 * w / 3; int dy = 2 * h / 3; QPoint p( startPos ); if ( r.x() > r.right() ) { dx = dx * -1; p.setX( p.x() - 64 ); r.moveBy( -64, 0 ); } if ( r.y() > r.bottom() ) { dy = dy * -1; p.setY( p.y() - 64 ); r.moveBy( 0, -64 ); } w = h = 64; r = r.normalized(); while ( r.contains( p ) ) { unclippedPainter->drawPixmap( p, *buffer, QRect( p, QSize( w, h ) ) ); unclippedPainter->setPen( Qt::red ); p.setX( p.x() + dx ); p.setY( p.y() + dy ); } unclippedPainter->drawPixmap( startPos.x() - 10, startPos.y() - 10, *buffer, startPos.x() - 10, startPos.y() - 10, 20, 20 );*/}void NCReportDesignerDesignArea::restoreRect( const QRect &rect ){ if (!unclippedPainter || !buffer) return; QRect r( rect ); r = r.normalize(); r = QRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, r.width() + 4, 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, 4, r.height() + 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() + r.height() - 3, *buffer, r.x() - 2, r.y() + r.height() - 3, r.width() + 4, 5 ); unclippedPainter->drawPixmap( r.x() + r.width() - 2, r.y(), *buffer, r.x() + r.width() - 2, r.y(), 4, r.height() + 4 );}void NCReportDesignerDesignArea::drawConnectionLine(){ if ( !unclippedPainter ) return; unclippedPainter->setPen( QPen( Qt::white, 2 ) ); unclippedPainter->drawLine( startPos, currentPos ); if ( validForBuddy ) unclippedPainter->setPen( QPen( Qt::darkRed, 1 ) ); else unclippedPainter->setPen( QPen( Qt::darkCyan, 1 ) ); unclippedPainter->drawLine( startPos, currentPos ); if ( validForBuddy ) unclippedPainter->setPen( QPen( Qt::darkGreen, 1 ) ); else unclippedPainter->setPen( QPen( Qt::magenta, 1 ) ); if ( startWidget ) { QWidget *s = (QWidget*)startWidget; QPoint p = mapToForm( s, QPoint(0,0) ); unclippedPainter->drawRect( QRect( p + QPoint( 2, 2 ), s->size() - QSize( 4, 4 ) ) ); } if ( endWidget ) { QWidget *e = (QWidget*)endWidget; QPoint p = mapToForm( e, QPoint(0,0) ); unclippedPainter->drawRect( QRect( p + QPoint( 2, 2 ), e->size() - QSize( 4, 4 ) ) ); }}void NCReportDesignerDesignArea::visibilityChanged(){ updateOrderIndicators(); repositionOrderIndicators();}/*! Maps \a pos in \a w's coordinates to the form's coordinate system. This is the equivalent to mapFromGlobal(w->mapToGlobal(pos) ) but avoids the two roundtrips to the X-Server on Unix/X11. */QPoint NCReportDesignerDesignArea::mapToForm( const QWidget* w, const QPoint& pos ) const{ QPoint p = pos; const QWidget* i = w; while ( i && !i->isTopLevel() && !isMainContainer( (QWidget*)i ) ) { p = i->mapToParent( p ); i = i->parentWidget(); } return mapFromGlobal( w->mapToGlobal( pos ) );}/*static int widgetDepth( QWidget *w ){ int d = -1; while ( w && !w->isTopLevel() ) { d++; w = w->parentWidget(); } return d;}static bool isChildOf( QWidget *c, QWidget *p ){ while ( c && !c->isTopLevel() ) { if ( c == p ) return TRUE; c = c->parentWidget(); } return FALSE;}*/bool NCReportDesignerDesignArea::isMainContainer( QObject *w ) const{ return w && w->isWidgetType() && ( w == (QWidget*)this || w == mainContainer() );}void NCReportDesignerDesignArea::setMainContainer( QWidget *w ){ bool resetPropertyWidget = isMainContainer( propertyWidget ); if ( mContainer ) insertedWidgets.remove( mContainer ); if ( propertyWidget == mContainer ) propertyWidget = 0; delete mContainer; mContainer = w; insertedWidgets.insert( mContainer, mContainer ); delete layout(); QHBoxLayout *l = new QHBoxLayout( this ); l->addWidget( w ); if ( resetPropertyWidget ) { QObject *opw = propertyWidget; propertyWidget = mContainer; if ( opw && opw->isWidgetType() ) repaintSelection( (QWidget*)opw ); }}void NCReportDesignerDesignArea::setActiveObject( QObject *o ){ //emitShowProperties( o ); propertyWidget = o;}void NCReportDesignerDesignArea::drawSizePreview( const QPoint &pos, const QString& text ){ unclippedPainter->save(); unclippedPainter->setPen( QPen( colorGroup().foreground(), 1 )); unclippedPainter->setRasterOp( CopyROP ); if ( !sizePreviewPixmap.isNull() ) unclippedPainter->drawPixmap( sizePreviewPos, sizePreviewPixmap ); if ( text.isNull() ) { sizePreviewPixmap = QPixmap(); // set null again unclippedPainter->restore(); return; } QRect r = fontMetrics().boundingRect( 0, 0, 0, 0, AlignCenter, text ); r = QRect( pos + QPoint( 10, 10 ), r.size() + QSize( 5, 5 ) ); checkGeometry( r ); sizePreviewPos = r.topLeft(); sizePreviewPixmap = QPixmap::grabWindow( winId(), r.x(), r.y(), r.width(), r.height() ); unclippedPainter->setBrush( QColor( 255, 255, 128 ) ); unclippedPainter->drawRect( r ); //unclippedPainter->drawEllipse( r ); unclippedPainter->drawText( r, AlignCenter, text ); unclippedPainter->restore();}void NCReportDesignerDesignArea::undo(){ commandHistory()->undo();}void NCReportDesignerDesignArea::redo(){ commandHistory()->redo();}NCReportDesignerCommandHistory *NCReportDesignerDesignArea::commandHistory(){ return &commands;}void NCReportDesignerDesignArea::paintFocus( QPainter *p, bool focusOn ){ if ( focusOn ) { QPen pen( Qt::blue, 0, Qt::DotLine ); p->setPen( pen ); } else p->setPen( backgroundColor() ); p->drawRect( 0,0,width(), height());}void NCReportDesignerDesignArea::runWidgetSettingsDialog( NCReportDesignerWidget *w, bool init ){ WProperty p_old( w->p ); //WProperty p_new; NCReportDesignerWidgetSetDialog *dia = new NCReportDesignerWidgetSetDialog( w, this, document, "wdialog", TRUE ); dia->setSaveToProperty( &(w->p) ); switch (dia->exec()) { case QDialog::Accepted: { if (init) { // at init mode don't need to call set command dia->saveSettings(); w->updateWidget(); break; } dia->saveSettings(); WProperty p_new( w->p ); cmd_SetPropertyCommand *cmd = new cmd_SetPropertyCommand( tr( "Set property" ), this, w, p_old, p_new ); commandHistory()->addCommand( cmd ); cmd->execute(); break; } } delete dia;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -