javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/qt/graphicscontextimpl.cpp
changeset 80 d6dafc5d983f
parent 67 63b81d807542
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
   186 /*
   186 /*
   187  *  Copy area from currently bound target to given image target
   187  *  Copy area from currently bound target to given image target
   188  *  NOTE: This covers currently only Images
   188  *  NOTE: This covers currently only Images
   189  */
   189  */
   190 void GraphicsContextImpl::copyArea(Image* aImage, int aX, int aY)
   190 void GraphicsContextImpl::copyArea(Image* aImage, int aX, int aY)
   191 {
   191     {
   192     GFX_LOG_FUNC_CALL();
   192     GFX_LOG_FUNC_CALL();
   193 
   193 
   194     switch (mSurface.getType()) {
   194     switch (mSurface.getType()) {
   195         case ETypeWidget:
   195         case ETypeWidget:
   196         case ETypeBuffer:
   196         case ETypeBuffer:
   197         {
   197         {
   198             QWidget* widget = 0;
   198             QWidget* widget = 0;
   199             if (mSurface.getType() == ETypeWidget)
   199             if (mSurface.getType() == ETypeWidget)
   200             {
   200                 {
   201                 widget = mSurface.getWidget();
   201                 widget = mSurface.getWidget();
   202             }
   202                 }
   203             else // ETypeBuffer
   203             else // ETypeBuffer
   204             {
   204                 {
   205                 widget = static_cast<QWidget*>(reinterpret_cast<QObject*>(mSurface.getBufferFlushTarget()));
   205                 widget = static_cast<QWidget*>(reinterpret_cast<QObject*>(mSurface.getBufferFlushTarget()));
   206             }
   206                 }
   207 
   207 
   208             if (widget)
   208             if (widget)
   209             {
   209                 {
   210                 // Determine the smallest area needed to grab, don't grab anything we don't need
   210                 // Determine the smallest area needed to grab, don't grab anything we don't need
   211                 const int widgetGrabWidth = widget->width() - aX;
   211                 const int widgetGrabWidth = widget->width() - aX;
   212                 const int widgetGrabHeight = widget->height() - aY;
   212                 const int widgetGrabHeight = widget->height() - aY;
   213                 const int imageGrabWidth = aImage->getWidth();
   213                 const int imageGrabWidth = aImage->getWidth();
   214                 const int imageGrabHeight = aImage->getHeight();
   214                 const int imageGrabHeight = aImage->getHeight();
   279                     }
   279                     }
   280             }
   280             }
   281             break;
   281             break;
   282         }
   282         }
   283         case ETypeImage:
   283         case ETypeImage:
   284         {
   284             {
   285             TImageType type = mSurface.getImageType();
   285             TImageType type = mSurface.getImageType();
   286 
   286             QPaintDevice* target = NULL;
       
   287             if(aImage->type() == EPixmap)
       
   288                 {
       
   289                 target = aImage->getPixmap();
       
   290                 }
       
   291             else if(aImage->type() == EImage) 
       
   292                 {
       
   293                 target = aImage->getImage();
       
   294                 }
       
   295             
   287             if (type == EPixmap)
   296             if (type == EPixmap)
   288             {
   297                 {
   289                 QPixmap* source = mSurface.getPixmap();
   298                 QPixmap* source = mSurface.getPixmap();
   290                 QPixmap* target = aImage->getPixmap();
       
   291                 QRect sourceRect(aX, aY, target->width(), target->height());
   299                 QRect sourceRect(aX, aY, target->width(), target->height());
   292                 QRect targetRect(0, 0, target->width(), target->height());
   300                 QRect targetRect(0, 0, target->width(), target->height());
   293 
   301 
   294                 // If copying on itself then don't try to create two QPainters
   302                 // If copying on itself then don't try to create two QPainters
   295                 // for the same paint device
   303                 // for the same paint device
   296                 if(target == source)
   304                 if(target == source)
   297                 {
   305                     {
   298                     drawPixmapCheckOverlap(*mPainter, *target, targetRect, *source, sourceRect);
   306                     drawPixmapCheckOverlap(*mPainter, *target, targetRect, *source, sourceRect);
   299                 }
   307                     }
   300                 else
   308                 else
   301                 {
   309                     {
   302                     QPainter painter(target);
   310                     QPainter painter(target);
   303                     drawPixmapCheckOverlap(painter, *target, targetRect, *source, sourceRect);
   311                     drawPixmapCheckOverlap(painter, *target, targetRect, *source, sourceRect);
       
   312                     }
   304                 }
   313                 }
   305             }
   314             else if(type == EImage) 
       
   315                 {
       
   316                 QImage* source = mSurface.getImage();
       
   317                 QRect sourceRect(aX, aY, target->width(), target->height());
       
   318                 QRect targetRect(0, 0, target->width(), target->height());
       
   319 
       
   320                 // If copying on itself then don't try to create two QPainters
       
   321                 // for the same paint device
       
   322                 if(target == source)
       
   323                     {
       
   324                     drawImageCheckOverlap(*mPainter, *target, targetRect, *source, sourceRect);
       
   325                     }
       
   326                 else
       
   327                     {
       
   328                     QPainter painter(target);
       
   329                     drawImageCheckOverlap(painter, *target, targetRect, *source, sourceRect);
       
   330                     }
       
   331                 }
   306             else
   332             else
   307             {
   333                 {
   308                 Q_ASSERT_X(false, "Graphics", "CopyArea image type not recognized");
   334                 Q_ASSERT_X(false, "Graphics", "CopyArea image type not recognized");
   309             }
   335                 }
   310             break;
   336             break;
   311         }
   337             }
   312         default:
   338         default:
   313             Q_ASSERT_X(false, "Graphics", "Surface type not recognized");
   339             Q_ASSERT_X(false, "Graphics", "Surface type not recognized");
   314             break;
   340             break;
   315     }
   341     }
   316 }
   342 }
   434         }
   460         }
   435         case ETypeImage:
   461         case ETypeImage:
   436         {
   462         {
   437             // first obtain native image type of current target (QPixmap/QImage)
   463             // first obtain native image type of current target (QPixmap/QImage)
   438             TImageType type = mSurface.getImageType();
   464             TImageType type = mSurface.getImageType();
   439 
   465             QRect sourceRect = QRect(aSrcX, aSrcY, aWidth, aHeight);
   440 
   466             QRect targetRect = QRect(aDestX, aDestY, aWidth, aHeight);
       
   467             
   441             if (type == EPixmap)
   468             if (type == EPixmap)
   442             {
   469             {
   443                 QRect sourceRect = QRect(aSrcX, aSrcY, aWidth, aHeight);
       
   444                 QRect targetRect = QRect(aDestX, aDestY, aWidth, aHeight);
       
   445                 drawPixmapCheckOverlap(*mPainter, *mSurface.getBindable(), targetRect, *mSurface.getPixmap(), sourceRect);
   470                 drawPixmapCheckOverlap(*mPainter, *mSurface.getBindable(), targetRect, *mSurface.getPixmap(), sourceRect);
       
   471             }
       
   472             else if (type == EImage)
       
   473             {
       
   474                 drawImageCheckOverlap(*mPainter, *mSurface.getBindable(), targetRect, *mSurface.getImage(), sourceRect);
   446             }
   475             }
   447             else
   476             else
   448             {
   477             {
   449                 Q_ASSERT_X(false, "Graphics", "CopyArea image type not recognized");
   478                 Q_ASSERT_X(false, "Graphics", "CopyArea image type not recognized");
   450             }
   479             }
   484 {
   513 {
   485     TImageType type = aImage->type();
   514     TImageType type = aImage->type();
   486     switch (type)
   515     switch (type)
   487     {
   516     {
   488         case EPixmap:
   517         case EPixmap:
   489             mPainter->drawPixmap(x, y, *(aImage->getPixmap()));
   518             mPainter->drawPixmap(x, y, *(aImage->getConstPixmap()));
       
   519             break;
       
   520         case EImage:
       
   521             mPainter->drawImage(QPoint(x,y), *(aImage->getConstImage()));
   490             break;
   522             break;
   491         default:
   523         default:
   492             Q_ASSERT_X(false, "Graphics", "Image type not recognized");
   524             Q_ASSERT_X(false, "Graphics", "Image type not recognized");
   493             break;
   525             break;
   494     }
   526     }
   508     }
   540     }
   509     TImageType type = aImage->type();
   541     TImageType type = aImage->type();
   510     switch (type)
   542     switch (type)
   511     {
   543     {
   512         case EPixmap:
   544         case EPixmap:
   513             mPainter->drawPixmap(QRect(aTx ,aTy, aTw, aTh), *(aImage->getPixmap()), QRect(aSx, aSy, aSw, aSh));
   545             mPainter->drawPixmap(QRect(aTx ,aTy, aTw, aTh), *(aImage->getConstPixmap()), QRect(aSx, aSy, aSw, aSh));
       
   546             break;
       
   547         case EImage:
       
   548             mPainter->drawImage(QRect(aTx ,aTy, aTw, aTh), *(aImage->getConstImage()), QRect(aSx, aSy, aSw, aSh));
   514             break;
   549             break;
   515         default:
   550         default:
   516             Q_ASSERT_X(false, "Graphics", "Image type not recognized");
   551             Q_ASSERT_X(false, "Graphics", "Image type not recognized");
   517             break;
   552             break;
   518     }
   553     }