Exemplo n.º 1
0
void DrawZone::setZoom(double z)
{
	_zoom=z;
	imageRect.setHeight(myround(image.height()*_zoom));
	imageRect.setWidth(myround(image.width()*_zoom));
	zoomedImage=QPixmap(imageRect.width(),imageRect.height());
	QPainter p(&zoomedImage);
	p.scale(z,z);
	QPixmap pix;
	pix.convertFromImage(image);
	// if the picture has transparent areas,
	// fill them with Gimp like background
	if (pix.mask()) {
  	QPixmap backPix(32,32);
  	QPainter p2(&backPix);
  	p2.fillRect(0,0,32,32,QColor(156,149,156));
  	p2.fillRect(0,16,16,16,QColor(98,105,98));
  	p2.fillRect(16,0,16,16,QColor(98,105,98));
  	p2.flush();
  	p.setPen(QPen());
  	p.fillRect(imageRect.left(),imageRect.top(),imageRect.width(),imageRect.height(),QBrush(QColor("black"),backPix));
	}
	p.drawPixmap(imageRect.left(),imageRect.top(),pix);
	p.flush();
	resizeContents(visibleWidth()>imageRect.width() ? visibleWidth() : imageRect.width(),
								 visibleHeight()>imageRect.height() ? visibleHeight() : imageRect.height());
	repaintContents(0,0,contentsWidth(),contentsHeight(),true);
}
Exemplo n.º 2
0
// Ends adding "session" for the list, setting proper number of
// columns / rows, updating it, etc.
void FingerList::endSession()
{
	// num is overral number of chord fingerings. If it's 0 - then there are no
	// fingerings. In the appl array, indexes should be ranged from 0 to (num-1)
	setNumRows((num - 1) / perRow + 1);
	repaintContents();
}
Exemplo n.º 3
0
bool
KDateTable::setDate(const QDate& date_)
{
  bool changed=false;
  QDate temp;
  // -----
  if(!date_.isValid())
    {
      kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
      return false;
    }
  if(date!=date_)
    {
      date=date_;
      changed=true;
    }
  temp.setYMD(date.year(), date.month(), 1);
  firstday=temp.dayOfWeek();
  if(firstday==1) firstday=8;
  numdays=date.daysInMonth();
  if(date.month()==1)
    { // set to december of previous year
      temp.setYMD(date.year()-1, 12, 1);
    } else { // set to previous month
      temp.setYMD(date.year(), date.month()-1, 1);
    }
  numDaysPrevMonth=temp.daysInMonth();
  if(changed)
    {
      repaintContents(false);
    }
  emit(dateChanged(date));
  return true;
}
Exemplo n.º 4
0
void DigitView::update(DigitView* sender, QRect boundingRect)
{
  if (sender != this)
	{
    // do not use updateContents since that produces bad flicker. perhaps that
    // function is repainting the background, but our background is static
    if (m_zoom == 100)
		{
      repaintContents(boundingRect, false);
		}
		else
		{
      repaintContents(convertZoom(boundingRect, true), false);
		}
	}
}
Exemplo n.º 5
0
//==================================================================
void KCharSelectTable::setFont( const QString &_font )
{
    vFont = _font;
    repaintContents( false );

    setToolTips();
}
Exemplo n.º 6
0
/*
QWidget* KVocTrainTable::beginEdit(int row, int col, bool replace)
{
  if (KApplication::dcopClient()->isApplicationRegistered("kxkb"))
  {
    if (m_doc)
    {
      QString id = (col == KV_COL_ORG) ? m_doc->getOriginalIdent() : m_doc->getIdent(col - KV_EXTRA_COLS);

      if (langs)
      {
        QString kbLayout(langs->keyboardLayout(langs->indexShortId(id)));
        kdDebug() << "Keyboard Layout: " << kbLayout << endl;
        if (!kbLayout.isEmpty())
        {
          QByteArray data, replyData;
          QCString replyType;
          QDataStream arg(data, IO_WriteOnly);
          arg << kbLayout;

          if (!KApplication::dcopClient()->call("kxkb", "kxkb", "setLayout(QString)", data, replyType, replyData))
          {
            kdDebug() << "kxkb dcop error: beginEdit()" << endl;
          }
        }
      }
    }
  }
  return QTable::beginEdit(row, col, replace);
}

void KVocTrainTable::endEdit(int row, int col, bool accept, bool replace)
{
  QTable::endEdit(row, col, accept, replace);
}
*/
void KVocTrainTable::sortByColumn(int header, bool alpha) {
  if (header == KV_COL_MARK)
    return;

  if (header >= numRows()) {
    kdError() << "header >= numRows()\n";
    return;
  }

  if (m_doc && !m_doc->isAllowedSorting()) {
    KMessageBox::information(this, i18n("Sorting is currently turned off for this document.\n"
      "\nUse the document properties dialog to turn sorting on."), kapp->makeStdCaption(""));
    return;
  }

  QApplication::setOverrideCursor(waitCursor);

  clearSelection();

  bool sortdir = false;
  if (m_doc) {
    if (header >= KV_COL_ORG)
      sortdir = m_doc->sort(header-KV_EXTRA_COLS);
    else
      if (alpha)
        sortdir = m_doc->sortByLesson_alpha();
    else
      sortdir = m_doc->sortByLesson_index();
  }
  horizontalHeader()->setSortIndicator(header, sortdir);
  repaintContents();
  m_doc->setModified();
  emit currentChanged(currentRow(), currentColumn());
  QApplication::restoreOverrideCursor();
}
Exemplo n.º 7
0
void UIPageText::updateContents()
{
        int ch = contentsHeight();
        int vw = visibleWidth();

        ensureVisible( 0, ch, 0, 0 );
        repaintContents( 0, ch - 40, vw, 40, true );
}
Exemplo n.º 8
0
//==================================================================
void KCharSelectTable::setTableNum( int _tableNum )
{
    focusItem = QChar( _tableNum * 256 );

    vTableNum = _tableNum;
    repaintContents( false );

    setToolTips();
}
Exemplo n.º 9
0
void QSAEditor::doRecalc()
{
    document()->invalidate();
    Q3TextParagraph *p = document()->firstParagraph();
    while ( p ) {
	p->format();
	p = p->next();
    }
    ensureCursorVisible();
    repaintContents( false );
}
Exemplo n.º 10
0
void QEditor::refresh()
{
	getDocument()->invalidate();
    Q3TextParagraph* p = getDocument()->firstParagraph();
    while( p ){
        p->format();
	p = p->next();
    }
    getDocument()->removeSelection( ParenMatcher::Match );
    getDocument()->removeSelection( ParenMatcher::Mismatch );
    ensureCursorVisible();
    repaintContents( false );
}
Exemplo n.º 11
0
void FingerList::endSession()
{
    // num is overral number of chord fingerings. If it's 0 - then there are no
    // fingerings. In the appl array, indexes should be ranged from 0 to (num-1)
    setNumRows((num - 1) / perRow + 1);

#if QT_VERSION < 300
	setAutoUpdate(TRUE);
	repaint();
#else
    repaintContents(true);
#endif
}
Exemplo n.º 12
0
void FingerList::resizeEvent(QResizeEvent *e)
{
#if QT_VERSION < 300
	QTableView::resizeEvent(e);
#else
	QGridView::resizeEvent(e);
#endif
    perRow = width() / ICONCHORD;
    setNumCols(perRow);
    setNumRows((num - 1) / perRow + 1);
#if QT_VERSION >= 300
    repaintContents(true);
#endif
}
Exemplo n.º 13
0
void DrawZone::cancelDrawing()
{
  if (   (currentAction == DrawPolygon )
      || (currentAction == DrawRectangle )
      || (currentAction == DrawCircle )
     )
  {
    currentAction = None;
    QRect r = translateToZoom(currentArea->selectionRect());
    delete currentArea;
    currentArea = 0L;
    repaintContents(r,false);
    imageMapEditor->slotUpdateSelectionCoords();
  }
}
void 
PolicyViewClass::contentsMouseMoveEvent(QMouseEvent* event)
{
  if (isAddTransitionMode()) {
    
    // repaint last arrow
    QRect rect(arrowFrom_, arrowTo_);
    rect = rect.normalize();
    repaintContents(rect);

    // update arrow coordinates
    arrowTo_ = event->pos();

    // draw new arrow
    QPainter p(this->viewport());
    p.drawLine(contentsToViewport(arrowFrom_), contentsToViewport(arrowTo_));
  }
}
Exemplo n.º 15
0
void QtFileIconView::newDirectory()
{
    setAutoArrange( FALSE );
    selectAll( FALSE );
    if ( viewDir.mkdir( QString( "New Folder %1" ).arg( ++newFolderNum ) ) ) {
        QFileInfo *fi = new QFileInfo( viewDir, QString( "New Folder %1" ).arg( newFolderNum ) );
        QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) );
        item->setKey( QString( "000000%1" ).arg( fi->fileName() ) );
        delete fi;
        repaintContents( contentsX(), contentsY(), contentsWidth(), contentsHeight(), FALSE );
        ensureItemVisible( item );
        item->setSelected( TRUE, TRUE );
        setCurrentItem( item );
        repaintItem( item );
        qApp->processEvents();
        item->rename();
    }
    setAutoArrange( TRUE );
}
Exemplo n.º 16
0
//==================================================================
KCharSelectTable::KCharSelectTable( QWidget *parent, const char *name, const QString &_font,
				    const QChar &_chr, int _tableNum )
    : QGridView( parent, name ), vFont( _font ), vChr( _chr ),
      vTableNum( _tableNum ), vPos( 0, 0 ), focusItem( _chr ), focusPos( 0, 0 ), d(0)
{
    setBackgroundColor( colorGroup().base() );

    setCellWidth( 20 );
    setCellHeight( 25 );

    setNumCols( 32 );
    setNumRows( 8 );

    repaintContents( false );
    
    setToolTips();

    setFocusPolicy( QWidget::StrongFocus );
    setBackgroundMode( QWidget::NoBackground );
}
void 
PolicyViewClass::contentsMousePressEvent(QMouseEvent* event) 
{
  // jump out of add transition mode
  if (addTransitionMode) {
    // repaint last arrow
    QRect rect(arrowFrom_, arrowTo_);
    rect = rect.normalize();
    repaintContents(rect);
    addTransitionMode = false;
  }

  // right button -> popup menu //
  if (event->button() == RightButton) {
    picked_x = event->pos().x();               // save this for onAddPattern
    picked_y = event->pos().y();
    // popup menu //
    QPopupMenu menu;
    menu.insertItem("Add pattern", this, SLOT(onAddPattern()));
    menu.exec(QCursor::pos());
  }
}
Exemplo n.º 18
0
void CardView::repaintItem( const CardViewItem *item )
{
  repaintContents( QRect( item->d->x, item->d->y, d->mItemWidth, item->height() ) );
}
Exemplo n.º 19
0
void KDateTable::focusOutEvent( QFocusEvent *e )
{
    repaintContents(false);
    QGridView::focusOutEvent( e );
}
Exemplo n.º 20
0
/*!
    Repaints cell (\a row, \a column).

    If \a erase is TRUE, Qt erases the area of the cell before the
    paintCell() call; otherwise no erasing takes place.

    \sa QWidget::repaint()
*/
void QGridView::repaintCell( int row, int column, bool erase )
{
    repaintContents( cellGeometry( row, column ), erase );
}
Exemplo n.º 21
0
//==================================================================
void KCharSelectTable::setChar( const QChar &_chr )
{
    vChr = _chr;
    repaintContents( false );
}
Exemplo n.º 22
0
void DrawZone::contentsMouseMoveEvent(QMouseEvent *e)
{
  if ( ! imageMapEditor->isReadWrite())
     return;


		drawCurrent=e->pos();

		// If outside the image
		// set it to the border
		if (!imageRect.contains(drawCurrent)) {
  		if (drawCurrent.x()>imageRect.right())
  			drawCurrent.setX(imageRect.right());
  		if (drawCurrent.x()<imageRect.left())
  			drawCurrent.setX(imageRect.left());
  		if (drawCurrent.y()>imageRect.bottom())
  			drawCurrent.setY(imageRect.bottom());
  		if (drawCurrent.y()<imageRect.top())
  			drawCurrent.setY(imageRect.top());
		}

		// Translate to image coordinates
		drawCurrent-=imageRect.topLeft();
    QPoint zoomedPoint=drawCurrent;
		drawCurrent=translateFromZoom(drawCurrent);

		if (currentAction==DrawRectangle) {
			// To avoid flicker, only repaint the minimum rect
			QRect oldRect=translateToZoom(currentArea->rect());
			currentArea->setRect(QRect(drawStart,drawCurrent).normalize());
			QRect newRect=translateToZoom(currentArea->selectionRect());
			QRect r=oldRect | newRect;
			repaintContents(r,false);
			imageMapEditor->slotUpdateSelectionCoords( currentArea->rect() );
		} else
		if (currentAction==DrawCircle) {
			QRect oldRect=translateToZoom(currentArea->rect());

			// We don't want ellipses
			int maxDistance=myabs(drawStart.x()-drawCurrent.x()) >
											myabs(drawStart.y()-drawCurrent.y()) ?
											myabs(drawStart.x()-drawCurrent.x()) :
											myabs(drawStart.y()-drawCurrent.y()) ;

			int xDiff=maxDistance;
			int yDiff=maxDistance;

			if ( drawStart.x()-drawCurrent.x() > 0)
				xDiff=-xDiff;

			if ( drawStart.y()-drawCurrent.y() > 0)
				yDiff=-yDiff;

			QPoint endPoint( drawStart.x()+xDiff, drawStart.y()+yDiff);

			currentArea->setRect(QRect(drawStart,endPoint).normalize());
			QRect newRect=translateToZoom(currentArea->rect());
			QRect r=oldRect | newRect;
			repaintContents(r,false);
			imageMapEditor->slotUpdateSelectionCoords( currentArea->rect() );
		} else
		if ( currentAction==DrawPolygon ) {
			QRect oldRect=translateToZoom(currentArea->rect());
			currentArea->moveSelectionPoint(currentSelectionPoint,drawCurrent);
			QRect newRect=translateToZoom(currentArea->rect());
			QRect r=oldRect | newRect;
			repaintContents(r,false);
		} else
		if ( currentAction==DrawFreehand) {
			QRect oldRect=translateToZoom(currentArea->rect());
		  currentArea->insertCoord(currentArea->countSelectionPoints(), drawCurrent);
			QRect newRect=translateToZoom(currentArea->rect());
			QRect r=oldRect | newRect;
			repaintContents(r,false);
		} else
		if ( currentAction==MoveArea ) {
			QRect oldRect=translateToZoom(currentArea->selectionRect());
			currentArea->moveBy((drawCurrent-drawStart).x(),(drawCurrent-drawStart).y());
			QRect newRect=translateToZoom(currentArea->selectionRect());
			QRect r=oldRect | newRect;
			currentArea->setMoving(true);
			repaintContents(r,false);
			drawStart=drawCurrent;
			imageMapEditor->slotUpdateSelectionCoords();
		} else
		if ( currentAction==MoveSelectionPoint ) {
			QRect oldRect=translateToZoom(currentArea->selectionRect());
			currentArea->moveSelectionPoint(currentSelectionPoint,drawCurrent);
			QRect newRect=translateToZoom(currentArea->selectionRect());
			QRect r=oldRect | newRect;
			repaintContents(r,false);
			imageMapEditor->slotUpdateSelectionCoords();
		} else
	  if (currentAction==DoSelect) {

    	QRect r(drawStart.x(),drawStart.y(),drawCurrent.x()-drawStart.x(),drawCurrent.y()-drawStart.y());
    	r = r.normalize();
//    	r = translateFromZoom(r);
/*
    	AreaListIterator it=imageMapEditor->areaList();
  		for ( ; it.current() != 0L ; ++it )	{
    		if ( it.current()->rect().intersects(r) )
    		{
   				if (!it.current()->isSelected() )
    				imageMapEditor->selectWithoutUpdate( it.current() );
    		}
    		else
     		  if (it.current()->isSelected())
      			imageMapEditor->deselectWithoutUpdate( it.current() );
			}
*/
      // We don't have to repaint the hole selection rectangle
      // only the borders have to be repainted.
      // So we have to create 4 rectangles for every rectangle
      // which represent the borders and then repaint them.

      QRect lb,rb,tb,bb;
      createBorderRectangles(translateToZoom(r),lb,rb,tb,bb);
      repaintContents(lb,false);
      repaintContents(rb,false);
      repaintContents(tb,false);
      repaintContents(bb,false);

      createBorderRectangles(translateToZoom(oldSelectionRect),lb,rb,tb,bb);
      repaintContents(lb,false);
      repaintContents(rb,false);
      repaintContents(tb,false);
      repaintContents(bb,false);

//    	repaintContents(oldSelectionRect | r,false);
    	oldSelectionRect = r;
//    	repaintContents(translateToZoom(r),false);
//+			imageMapEditor->updateSelection();


//			QRect r(drawStart.x(),drawStart.y(),drawCurrent.x()-drawStart.x(),drawCurrent.y()-drawStart.y());
//			r = r.normalize();
//			QRect r2(drawStart.x(),drawStart.y(),drawOld.x()-drawStart.x(),drawOld.y()-drawStart.y());
//			r2 = r2.normalize();
//			r = translateToZoom(r | r2);
//			repaintContents(r,false);
  	} else
		if ( currentAction==None )
		{
			if ( imageMapEditor->selected() &&
					 imageMapEditor->selected()->onSelectionPoint(zoomedPoint,_zoom ))
			{
 				if (imageMapEditor->selected()->type()==Area::Polygon)
 				{
			    if ((imageMapEditor->currentToolType()==KImageMapEditor::RemovePoint) &&
			        (imageMapEditor->selected()->selectionPoints()->count()>3) )
			    {
		        viewport()->setCursor(RemovePointCursor);
			    }
			    else
			    {
 						viewport()->setCursor(pointingHandCursor);
 				  }
 				}
 				else
 				{
   				QPoint center=imageMapEditor->selected()->rect().center();
   				if (drawCurrent.x() < center.x()) {
   					if (drawCurrent.y() < center.y())
   						viewport()->setCursor(sizeFDiagCursor);
   					else
   						viewport()->setCursor(sizeBDiagCursor);
   				}
   				else {
   					if (drawCurrent.y() < center.y())
   						viewport()->setCursor(sizeBDiagCursor);
   					else
   						viewport()->setCursor(sizeFDiagCursor);
 					}
 				}
			} else
			if ( imageMapEditor->onArea(drawCurrent) )
			{
  			if (imageMapEditor->currentToolType()==KImageMapEditor::AddPoint)
  			{
			    viewport()->setCursor(AddPointCursor);
			  }
			  else
        {
				  viewport()->setCursor(sizeAllCursor);
        }
			}
			else
			if (imageMapEditor->currentToolType()==KImageMapEditor::Rectangle) {
			    viewport()->setCursor(RectangleCursor);
//          kdDebug() << "KImageMapEditor::DrawZone: viewport()->setCursor to Rectangle" << endl;
      }
			else
			if (imageMapEditor->currentToolType()==KImageMapEditor::Circle)
			    viewport()->setCursor(CircleCursor);
			else
			if (imageMapEditor->currentToolType()==KImageMapEditor::Polygon)
			    viewport()->setCursor(PolygonCursor);
			else
			if (imageMapEditor->currentToolType()==KImageMapEditor::Freehand)
			    viewport()->setCursor(FreehandCursor);
			else
		 		viewport()->setCursor(arrowCursor);

		}
		imageMapEditor->slotChangeStatusCoords(drawCurrent.x(),drawCurrent.y());
}
Exemplo n.º 23
0
void DrawZone::contentsMousePressEvent(QMouseEvent* e)
{
  if ( ! imageMapEditor->isReadWrite())
     return;

	drawStart=e->pos();
	// Check if it's on picture if not
	// move it to the picture's border
	if (!imageRect.contains(drawStart)) {
		if (drawStart.x()>imageRect.right())
			drawStart.setX(imageRect.right());
		if (drawStart.x()<imageRect.left())
			drawStart.setX(imageRect.left());
		if (drawStart.y()>imageRect.bottom())
			drawStart.setY(imageRect.bottom());
		if (drawStart.y()<imageRect.top())
			drawStart.setY(imageRect.top());
	}

	// Translate it to picture coordinates
	drawStart-=imageRect.topLeft();
  QPoint zoomedPoint = drawStart;
	drawStart=translateFromZoom(drawStart);
	delete oldArea;
	oldArea=0L;

	if (currentArea)
	{
		oldArea=currentArea->clone();
	}

	if ( currentAction==None ) {
		if (e->button()==RightButton)
		{
			if ( (currentArea=imageMapEditor->onArea(drawStart)) )
			{
  			if ( ! currentArea->isSelected())
  			{
  				imageMapEditor->deselectAll();
  				imageMapEditor->select(currentArea);
  			}
 				currentArea=imageMapEditor->selected();
  		}

  		imageMapEditor->slotShowMainPopupMenu(e->globalPos());

		}
		else
		if (e->button()==MidButton) {
			contentsMouseDoubleClickEvent(e);
		}
		else  // LeftClick on selectionpoint
		if ((currentArea=imageMapEditor->selected()) &&
			(currentSelectionPoint=currentArea->onSelectionPoint(zoomedPoint,_zoom)))
		{
			oldArea=currentArea->clone();

		  if ( (imageMapEditor->currentToolType() == KImageMapEditor::RemovePoint) &&
		       (imageMapEditor->selected()->selectionPoints()->count()>3) )
		  {
      	currentAction=RemovePoint;
		  }
		  else
		  {
  			currentAction=MoveSelectionPoint;
        currentArea->setMoving(true);
      }

		} else // leftclick not on selectionpoint but on area
		if ((currentArea=imageMapEditor->onArea(drawStart)))
		{
		  if ( imageMapEditor->currentToolType() == KImageMapEditor::AddPoint )
		  {
		    currentAction=AddPoint;
		    viewport()->setCursor(AddPointCursor);
   			oldArea=currentArea->clone();
		  }
		  else
		  {
  			currentAction=MoveArea;
  			viewport()->setCursor(sizeAllCursor);

  			if ( currentArea->isSelected() ) {
  				if ( (e->state() & ControlButton) )
   					imageMapEditor->deselect(currentArea);
   			} else
  			{
  				if ( (e->state() & ControlButton) )
  					imageMapEditor->select( currentArea );
  				else {
  					imageMapEditor->deselectAll();
  					imageMapEditor->select( currentArea );
  				}
  			}

  			currentArea = imageMapEditor->selected();
        currentArea->setMoving(true);

  			oldArea=currentArea->clone();
      }
  	}
		else  // leftclick on the background
		if ( (imageMapEditor->currentToolType()==KImageMapEditor::Rectangle) ||
		     (imageMapEditor->currentToolType()==KImageMapEditor::Circle) ||
		     (imageMapEditor->currentToolType()==KImageMapEditor::Polygon) ||
		     (imageMapEditor->currentToolType()==KImageMapEditor::Freehand))
		{
			currentArea=AreaCreator::create(imageMapEditor->currentToolType());

 		  currentArea->setRect(QRect(drawStart,drawStart));
 		  currentArea->setSelected(false);
 		  imageMapEditor->deselectAll();

			switch (imageMapEditor->currentToolType())	{
				case KImageMapEditor::Rectangle : currentAction=DrawRectangle; break;
				case KImageMapEditor::Circle : currentAction=DrawCircle; break;
				case KImageMapEditor::Polygon :
  					currentAction=DrawPolygon;
      			currentArea->addCoord(drawStart);
      			currentSelectionPoint=currentArea->selectionPoints()->last();
      			break;
        case KImageMapEditor::Freehand :
            currentAction=DrawFreehand;
      			//currentArea->addCoord(drawStart);
      			currentArea->setFinished(false);
 			  		break;
				default: break;
			}
		}
		else
  	// leftclicked with the arrow at an areafree position
		if (imageMapEditor->currentToolType()==KImageMapEditor::Selection)
  	{
  	  	currentArea=0L;
  	  	imageMapEditor->deselectAll();
  	  	// Start drawing a selection rectangle
  	  	currentAction=DoSelect;
  	  	oldSelectionRect = imageRect;
  	}
	} else
	if ( currentAction==DrawPolygon) {

	}

	QRect r;
	if (oldArea)
		r=oldArea->selectionRect();
	if (currentArea) {
		r= r | currentArea->selectionRect();
		repaintContents(translateToZoom(r),false);
	}


}
Exemplo n.º 24
0
void KWidgetListbox::showEvent(QShowEvent*)
{
  //kdDebug() << k_funcinfo << endl;
  repaintContents(false);
}
Exemplo n.º 25
0
void DrawZone::repaintArea(const Area & a) {
	repaintContents(translateToZoom(a.selectionRect()),false);
}
Exemplo n.º 26
0
void DrawZone::contentsMouseReleaseEvent(QMouseEvent *e) {
  if ( ! imageMapEditor->isReadWrite())
     return;

  QPoint drawEnd=e->pos();

	// Check if it's on picture if not
	// move it to the picture's border
	if (!imageRect.contains(drawEnd)) {
		if (drawEnd.x()>imageRect.right())
			drawEnd.setX(imageRect.right());
		if (drawEnd.x()<imageRect.left())
			drawEnd.setX(imageRect.left());
		if (drawEnd.y()>imageRect.bottom())
			drawEnd.setY(imageRect.bottom());
		if (drawEnd.y()<imageRect.top())
			drawEnd.setY(imageRect.top());
	}
	// Translate it to picture coordinates
	drawEnd-=imageRect.topLeft();
  QPoint zoomedPoint=drawEnd;

	drawEnd=translateFromZoom(drawEnd);

	if (currentAction==DrawCircle || currentAction==DrawRectangle) {
  		currentAction=None;
   		imageMapEditor->commandHistory()->addCommand(
   			new CreateCommand( imageMapEditor, currentArea ), true);
  } else
	if (currentAction==DrawPolygon) {
		// If the number of Polygonpoints is more than 2
		// and clicked on the first PolygonPoint or
		// the right Button was pressed the Polygon is finished
  	if ((currentArea->selectionPoints()->count()>2)
  		&& (currentArea->selectionPoints()->first()->contains(drawEnd)
  		 || (e->button()==RightButton)))
  	{
			currentArea->setFinished(true);
  		currentAction=None;
   		imageMapEditor->commandHistory()->addCommand(
   			new CreateCommand( imageMapEditor, currentArea ), true);
		} else
		{
   		currentArea->insertCoord(currentArea->countSelectionPoints()-1, drawEnd);
   		currentSelectionPoint=currentArea->selectionPoints()->last();
   	}
	} else
	if (currentAction==DrawFreehand)
	{
			currentArea->setFinished(true);
			currentArea->simplifyCoords();
  		currentAction=None;
   		imageMapEditor->commandHistory()->addCommand(
   			new CreateCommand( imageMapEditor, currentArea ), true);
	} else
	if (currentAction==MoveArea) {
	    QPoint p1 = oldArea->rect().topLeft();
	    QPoint p2 = imageMapEditor->selected()->rect().topLeft();

	    if (p1 != p2)
	    {
  			imageMapEditor->commandHistory()->addCommand(
	  			new MoveCommand( imageMapEditor, imageMapEditor->selected(), oldArea->rect().topLeft()),true);
  	  	imageMapEditor->slotAreaChanged(currentArea);
  	  } else
     	  imageMapEditor->updateSelection();

  		currentAction=None;
  } else
  if (currentAction==MoveSelectionPoint) {
			imageMapEditor->commandHistory()->addCommand(
				new ResizeCommand( imageMapEditor, imageMapEditor->selected(), oldArea),true);
  		imageMapEditor->slotAreaChanged(currentArea);
  		currentAction=None;
  } else
  if (currentAction==RemovePoint) {
     if (currentSelectionPoint==currentArea->onSelectionPoint(zoomedPoint,_zoom))
     {
       currentArea->removeSelectionPoint(currentSelectionPoint);

       imageMapEditor->commandHistory()->addCommand(
         new RemovePointCommand( imageMapEditor, imageMapEditor->selected(), oldArea),true);
    	 imageMapEditor->slotAreaChanged(currentArea);
     }
 		 currentAction=None;
  } else
  if (currentAction==AddPoint)
  {
      if (currentArea==imageMapEditor->onArea(drawEnd))
      {
        imageMapEditor->commandHistory()->addCommand(
          new AddPointCommand( imageMapEditor, imageMapEditor->selected(), drawEnd),true);
    		imageMapEditor->slotAreaChanged(currentArea);
  		}
   		currentAction=None;
  } else
  if (currentAction==DoSelect) {
  	currentAction=None;

   	QRect r(drawStart.x(),drawStart.y(),drawCurrent.x()-drawStart.x(),drawCurrent.y()-drawStart.y());
   	r = r.normalize();

    	AreaListIterator it=imageMapEditor->areaList();
  		for ( ; it.current() != 0L ; ++it )	{
    		if ( it.current()->rect().intersects(r) )
    		{
   				if (!it.current()->isSelected() )
    				imageMapEditor->selectWithoutUpdate( it.current() );
    		}
    		else
     		  if (it.current()->isSelected())
      			imageMapEditor->deselectWithoutUpdate( it.current() );
			}

    imageMapEditor->updateActionAccess();
  	imageMapEditor->updateSelection();
    repaintContents(imageRect,false);
  } else {
  	currentAction=None;
  }
	imageMapEditor->slotChangeStatusCoords(drawEnd.x(),drawEnd.y());
	if (currentArea)
	{
	  currentArea->setMoving(false);
		repaintArea(*currentArea);
	}
	delete oldArea;
	oldArea=0L;
//	repaintContents(0,0,contentsWidth(),contentsHeight(),false);
  imageMapEditor->slotUpdateSelectionCoords();
}
Exemplo n.º 27
0
void DrawZone::repaintRect(const QRect & r) {
	repaintContents(translateToZoom(r),false);
}