This file is indexed.

/usr/share/videoporama/DefZoomPointDlg.py is in videoporama 0.8.1-0ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# -*- coding: utf-8 -*-

# This file is part of Videoporama
# Videoporama is a program to make diaporama export in video file
# Copyright (C) 2007-2010  Olivier Ponchaut <opvg@numericable.be> - Dominique Levray

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
import Image
import random
from math import *
from __builtin__ import hex as hexp
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from GlobalDefines import *
from DefZoomPoint import *
from DocHelpDlg import *

#-------------------------------------------------------------------------------------------------------------
# A FAIRE
#   Faire les guides magnétiques
#   Eventuellement : ajouter des options :
#     Gérer les rotations de l'image
#-------------------------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------------------------------------------------------------------------
#class use to add interractive resize to QGraphicsRectItem object
#---------------------------------------------------------------------------------------------------------------------------------------------------------------
class QResizeGraphicsRectItem(QtGui.QGraphicsRectItem):
  
    def __init__(self,scene,RectItem,ZValue,TypeItem,xmax,ymax,ZoomPointDlg,parent=None):
      self.RectItem       = RectItem
      self.TypeItem       = TypeItem
      self.IsCapture      = False
      self.BlockRecursion = False       # Flag to stop recursion during resize
      self.ZoomPointDlg    = ZoomPointDlg

      x,y,w,h=self.CalcPosition(xmax,ymax)

      super(QResizeGraphicsRectItem,self).__init__(x,y,w,h,parent) #parent

      #define a pen for the rectangle
      col=QColor(255,0,0)
      pen=QPen(col)
      pen.setWidth(1)
      self.setPen(pen)
      
      #define Mouse cursor
      if self.TypeItem==0:    self.setCursor(Qt.SizeFDiagCursor)  #Upper-Left corner
      elif self.TypeItem==1:  self.setCursor(Qt.SizeBDiagCursor)  #Upper-Right corner
      elif self.TypeItem==2:  self.setCursor(Qt.SizeBDiagCursor)  #Bottom-Left corner
      elif self.TypeItem==3:  self.setCursor(Qt.SizeFDiagCursor)  #Bottom-Right corner

      #define Flags
      try :
        self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable  | QGraphicsItem.ItemSendsScenePositionChanges | QGraphicsItem.ItemSendsGeometryChanges)
      except :
        self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable) 
      self.setZValue(ZValue)
      
      #Add this item to the scene
      scene.addItem(self)

    def mousePressEvent(self, event):
      QGraphicsRectItem.mousePressEvent(self,event)
      self.IsCapture = True

    def mouseReleaseEvent(self, event):
      self.IsCapture = False
      QGraphicsRectItem.mouseReleaseEvent(self,event)

    def CalcPosition(self,xmax=-1,ymax=-1):
      ToMove=(xmax==-1 or ymax==-1)
      if ToMove:
        xmax = self.RectItem.scene().sceneRect().width()
        ymax = self.RectItem.scene().sceneRect().height()
      w = 3*(xmax/100)
      h = 3*(ymax/100)
      if self.TypeItem==0:      #Upper-Left corner
        x = self.RectItem.x*xmax
        y = self.RectItem.y*ymax
      elif self.TypeItem==1:    #Upper-Right corner
        x = self.RectItem.x*xmax+xmax*self.RectItem.zoom/100
        y = self.RectItem.y*ymax
      elif self.TypeItem==2:    #Bottom-Left corner
        x = self.RectItem.x*xmax
        y = self.RectItem.y*ymax+ymax*self.RectItem.zoom/100
      elif self.TypeItem==3:    #Bottom-Right corner
        x = self.RectItem.x*xmax+xmax*self.RectItem.zoom/100
        y = self.RectItem.y*ymax+ymax*self.RectItem.zoom/100
      x=x-w/2
      y=y-h/2
      if ToMove: 
        self.setPos(x,y)
        Rect=self.mapRectFromScene(QRectF(x,y,w,h))
        self.setRect(Rect)
      return x,y,w,h
      
    #function call each time a rectangle is move
    def itemChange(self, change, value):
      if (change == QtGui.QGraphicsItem.ItemPositionChange) :
        newpos = value.toPyObject()
        if self.IsCapture==True and self.BlockRecursion==False :
          self.BlockRecursion = True
          if self.TypeItem==0:    newpos=self.ResizeUpperLeft(newpos)     #Upper-Left corner
          elif self.TypeItem==1:  newpos=self.ResizeUpperRight(newpos)    #Upper-Right corner
          elif self.TypeItem==2:  newpos=self.ResizeBottomLeft(newpos)    #Bottom-Left corner
          elif self.TypeItem==3:  newpos=self.ResizeBottomRight(newpos)   #Bottom-Right corner
          self.BlockRecursion = False
        return newpos
      else :
        return QtGui.QGraphicsRectItem.itemChange(self, change, value)

    # Redefine paint to don't allow selection rectangle
    def paint(self,painter,option,widget=0):
      None

    #Resize from Upper-Left corner
    def ResizeUpperLeft(self,newpos) :
      x = newpos.x()
      y = newpos.y()
      #get max width and max height
      xmax = self.RectItem.scene().sceneRect().width()
      ymax = self.RectItem.scene().sceneRect().height()
      #calcul width and height
      w = 3*(xmax/100)
      h = 3*(ymax/100)
      #Magnetic guide
      if self.ZoomPointDlg.MagneticEdge.isChecked()==True:
        mw = 2*(xmax/100)
        mh = 2*(ymax/100)
        if self.ZoomPointDlg.MagnetX1!=-1 and x+(w/2)>(self.ZoomPointDlg.MagnetX1-mw) and x+(w/2)<(self.ZoomPointDlg.MagnetX1+mw) :
          x=self.ZoomPointDlg.MagnetX1-(w/2)
        if self.ZoomPointDlg.MagnetY1!=-1 and y+(h/2)>(self.ZoomPointDlg.MagnetY1-mh) and y+(h/2)<(self.ZoomPointDlg.MagnetY1+mh) :
          y=self.ZoomPointDlg.MagnetY1-(h/2)
          imgh=self.RectItem.BottomRight.pos().y()-h/2-y+h/2
          NewZoom=(imgh/ymax)*100
          imgw=xmax*NewZoom/100
          x=self.RectItem.BottomRight.pos().x()+w/2-imgw-w/2
      #get value of opposite resize corner
      blockx = self.RectItem.BottomRight.pos().x()-w
      blocky = self.RectItem.BottomRight.pos().y()-h
      #crop rectangle in the image
      if x<-(w/2): x=-w/2
      if x>blockx: x=blockx
      if y < -(h/2): y=-(h/2)
      if y>blocky: y=blocky
      #Last process : respect image geometry
      imgw = blockx-x
      if self.RectItem.IsImageWide==True:               #format 16/9
        imgh = (imgw/16)*9
        if blocky-imgh<-(h/2):
          imgh = blocky-y
          imgw = (imgh/9)*16
          x    = blockx-imgw
        else: 
          y = blocky-imgh
      else:                                             #format 4/3
        imgh = (imgw/4)*3
        if blocky-imgh<-(h/2):
          imgh = blocky-y
          imgw = (imgh/3)*4
          x    = blockx-imgw
        else: 
          y = blocky-imgh

      #Now, update RectItem
      imgw=(self.RectItem.BottomRight.pos().x()-x)
      imgh=(self.RectItem.BottomRight.pos().y()-y)
      self.RectItem.zoom=(imgw/xmax)*100
      self.RectItem.x=(x+(w/2))/xmax
      self.RectItem.y=(y+(h/2))/ymax
      self.RectItem.setPos(self.RectItem.x*xmax,self.RectItem.y*ymax)
      Rect=self.RectItem.mapRectFromScene(QRectF(self.RectItem.x*xmax,self.RectItem.y*ymax,imgw,imgh))
      self.RectItem.setRect(Rect)
      self.RectItem.ZoomPointDlg.SetupInterface()
      #return new value
      newpos.setX(x)
      newpos.setY(y)
      return newpos
      
    #Resize from Upper-Right corner
    def ResizeUpperRight(self,newpos) :
      x = newpos.x()
      y = newpos.y()
      #get max width and max height
      xmax = self.RectItem.scene().sceneRect().width()
      ymax = self.RectItem.scene().sceneRect().height()
      #calcul width and height
      w = 3*(xmax/100)
      h = 3*(ymax/100)
      #Magnetic guide
      if self.ZoomPointDlg.MagneticEdge.isChecked()==True:
        mw = 2*(xmax/100)
        mh = 2*(ymax/100)
        if self.ZoomPointDlg.MagnetX2!=-1 and x+(w/2)>(self.ZoomPointDlg.MagnetX2-mw) and x+(w/2)<(self.ZoomPointDlg.MagnetX2+mw) :
          x=self.ZoomPointDlg.MagnetX2-(w/2)
        if self.ZoomPointDlg.MagnetY1!=-1 and y+(h/2)>(self.ZoomPointDlg.MagnetY1-mh) and y+(h/2)<(self.ZoomPointDlg.MagnetY1+mh) :
          y=self.ZoomPointDlg.MagnetY1-(h/2)
          imgh=self.RectItem.BottomLeft.pos().y()-h/2-y+h/2
          NewZoom=(imgh/ymax)*100
          imgw=xmax*NewZoom/100
          x=self.RectItem.BottomLeft.pos().x()+w/2+imgw-w/2
      #get value of opposite resize corner
      blockx = self.RectItem.BottomLeft.pos().x()+w
      blocky = self.RectItem.BottomLeft.pos().y()-h
      #crop rectangle in the image
      if x<blockx: x=blockx
      if x>xmax-(w/2): x=xmax-(w/2)
      if y < -(h/2): y=-(h/2)
      if y>blocky: y=blocky
      #Last process : respect image geometry
      imgw = x-blockx
      if self.RectItem.IsImageWide==True:               #format 16/9
        imgh = (imgw/16)*9
        if blocky-imgh<-(h/2):
          imgh = blocky-y
          imgw = (imgh/9)*16
          x    = blockx+imgw
        else: 
          y = blocky-imgh
      else:                                             #format 4/3
        imgh = (imgw/4)*3
        if blocky-imgh<-(h/2):
          imgh = blocky-y
          imgw = (imgh/3)*4
          x    = blockx+imgw
        else: 
          y = blocky-imgh
      #Now, update RectItem
      imgw=(x-self.RectItem.BottomLeft.pos().x())
      imgh=(self.RectItem.BottomLeft.pos().y()-y)
      self.RectItem.zoom=(imgw/xmax)*100
      self.RectItem.y=(y+(h/2))/ymax
      self.RectItem.setPos(self.RectItem.x*xmax,self.RectItem.y*ymax)
      Rect=self.RectItem.mapRectFromScene(QRectF(self.RectItem.x*xmax,self.RectItem.y*ymax,imgw,imgh))
      self.RectItem.setRect(Rect)
      self.RectItem.ZoomPointDlg.SetupInterface()
      #return new value
      newpos.setX(x)
      newpos.setY(y)
      return newpos
      
    #Resize from Bottom-Left corner
    def ResizeBottomLeft(self,newpos) :
      x = newpos.x()
      y = newpos.y()
      #get max width and max height
      xmax = self.RectItem.scene().sceneRect().width()
      ymax = self.RectItem.scene().sceneRect().height()
      #calcul width and height
      w = 3*(xmax/100)
      h = 3*(ymax/100)
      #Magnetic guide
      if self.ZoomPointDlg.MagneticEdge.isChecked()==True:
        mw = 2*(xmax/100)
        mh = 2*(ymax/100)
        if self.ZoomPointDlg.MagnetX1!=-1 and x+(w/2)>(self.ZoomPointDlg.MagnetX1-mw) and x+(w/2)<(self.ZoomPointDlg.MagnetX1+mw) :
          x=self.ZoomPointDlg.MagnetX1-(w/2)
        if self.ZoomPointDlg.MagnetY2!=-1 and y+(h/2)>(self.ZoomPointDlg.MagnetY2-mh) and y+(h/2)<(self.ZoomPointDlg.MagnetY2+mh) :
          y=self.ZoomPointDlg.MagnetY2-(h/2)
          imgh=y+h/2-self.RectItem.UpperRight.pos().y()-h/2
          NewZoom=(imgh/ymax)*100
          imgw=xmax*NewZoom/100
          x=self.RectItem.UpperRight.pos().x()+w/2-imgw-w/2
      #get value of opposite resize corner
      blockx = self.RectItem.UpperRight.pos().x()-w
      blocky = self.RectItem.UpperRight.pos().y()+h
      #crop rectangle in the image
      if x<-(w/2): x=-w/2
      if x>blockx: x=blockx
      if y<blocky: y=blocky
      if y>ymax-(h/2): y=ymax-(h/2)
      #Last process : respect image geometry
      imgw = blockx-x
      if self.RectItem.IsImageWide==True:               #format 16/9
        imgh = (imgw/16)*9
        if imgh+blocky>ymax-(h/2):
          imgh = y-blocky
          imgw = (imgh/9)*16
          x    = blockx-imgw
        else: 
          y = blocky+imgh
      else:                                             #format 4/3
        imgh = (imgw/4)*3
        if imgh+blocky>ymax-(h/2):
          imgh = y-blocky
          imgw = (imgh/3)*4
          x    = blockx-imgw
        else: 
          y = blocky+imgh
      #Now, update RectItem
      imgw=(self.RectItem.UpperRight.pos().x()-x)
      imgh=(y-self.RectItem.UpperRight.pos().y())
      self.RectItem.zoom=(imgw/xmax)*100
      self.RectItem.x=(x+(w/2))/xmax
      self.RectItem.setPos(self.RectItem.x*xmax,self.RectItem.y*ymax)
      Rect=self.RectItem.mapRectFromScene(QRectF(self.RectItem.x*xmax,self.RectItem.y*ymax,imgw,imgh))
      self.RectItem.setRect(Rect)
      self.RectItem.ZoomPointDlg.SetupInterface()
      #return new value
      newpos.setX(x)
      newpos.setY(y)
      return newpos
      
    #Resize from Bottom-Right corner
    def ResizeBottomRight(self,newpos) :
      x = newpos.x()
      y = newpos.y()
      #get max width and max height
      xmax = self.RectItem.scene().sceneRect().width()
      ymax = self.RectItem.scene().sceneRect().height()
      #calcul width and height
      w = 3*(xmax/100)
      h = 3*(ymax/100)
      #Magnetic guide
      if self.ZoomPointDlg.MagneticEdge.isChecked()==True:
        mw = 2*(xmax/100)
        mh = 2*(ymax/100)
        if self.ZoomPointDlg.MagnetX2!=-1 and x+(w/2)>(self.ZoomPointDlg.MagnetX2-mw) and x+(w/2)<(self.ZoomPointDlg.MagnetX2+mw) :
          x=self.ZoomPointDlg.MagnetX2-(w/2)
        if self.ZoomPointDlg.MagnetY2!=-1 and y+(h/2)>(self.ZoomPointDlg.MagnetY2-mh) and y+(h/2)<(self.ZoomPointDlg.MagnetY2+mh) :
          y=self.ZoomPointDlg.MagnetY2-(h/2)
          imgh=y+h/2-self.RectItem.UpperLeft.pos().y()-h/2
          NewZoom=(imgh/ymax)*100
          imgw=xmax*NewZoom/100
          x=self.RectItem.UpperLeft.pos().x()+w/2+imgw-w/2
      #get value of opposite resize corner
      blockx = self.RectItem.UpperLeft.pos().x()+w
      blocky = self.RectItem.UpperLeft.pos().y()+h
      #crop rectangle in the image
      if x<blockx:      x=blockx
      if x>xmax-(w/2):  x=xmax-(w/2)
      if y<blocky:      y=blocky
      if y>ymax-(h/2):  y=ymax-(h/2)
      #Last process : respect image geometry
      imgw = x-blockx
      if self.RectItem.IsImageWide==True:               #format 16/9
        imgh = (imgw/16)*9
        if imgh+blocky>ymax-(h/2):
          imgh = y-blocky
          imgw = (imgh/9)*16
          x    = blockx+imgw
        else: 
          y = blocky+imgh
      else:                                             #format 4/3
        imgh = (imgw/4)*3
        if imgh+blocky>ymax-(h/2):
          imgh = y-blocky
          imgw = (imgh/3)*4
          x    = blockx+imgw
        else: 
          y = blocky+imgh
      #Now, update RectItem
      imgw=(x-self.RectItem.UpperLeft.pos().x())
      imgh=(y-self.RectItem.UpperLeft.pos().y())
      self.RectItem.zoom=(imgw/xmax)*100
      self.RectItem.setPos(self.RectItem.x*xmax,self.RectItem.y*ymax)
      Rect=self.RectItem.mapRectFromScene(QRectF(self.RectItem.x*xmax,self.RectItem.y*ymax,imgw,imgh))
      self.RectItem.setRect(Rect)
      self.RectItem.ZoomPointDlg.SetupInterface()
      #return new value
      newpos.setX(x)
      newpos.setY(y)
      return newpos

#---------------------------------------------------------------------------------------------------------------------------------------------------------------
#class use to crop rectangle into the image
#---------------------------------------------------------------------------------------------------------------------------------------------------------------
class QMyGraphicsRectItem(QtGui.QGraphicsRectItem):

    # x,y and zoom are always give in %
    def __init__(self,scene,ZValue,x,y,zoom,xmax,ymax,IsImageWide,ZoomPointDlg,parent=None):
      self.x               = x
      self.y               = y
      self.zoom            = float(zoom)
      self.ZoomPointDlg    = ZoomPointDlg
      self.IsImageWide     = IsImageWide
      self.BlockZoomChange = False            # flag to block zoom changing during change % to pixel
      self.IsCapture       = False

      #Init item
      super(QMyGraphicsRectItem,self).__init__(self.x*xmax,self.y*ymax,xmax*self.zoom/100,ymax*self.zoom/100,parent)
      self.setPos(self.x*xmax,self.y*ymax)
      Rect=self.mapRectFromScene(QRectF(self.x*xmax,self.y*ymax,xmax*self.zoom/100,ymax*self.zoom/100))
      self.setRect(Rect)

      #define Mouse cursor
      self.setCursor(Qt.SizeAllCursor)

      #define a pen for the rectangle
      col=QColor(255,0,0)
      pen=QPen(col)
      pen.setWidth(1)
      self.setPen(pen)

      #define Flags
      try :
        self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemSendsScenePositionChanges | QGraphicsItem.ItemSendsGeometryChanges)
      except :
        self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable)

      self.setZValue(ZValue)

      #Add this item to the scene and create resize box
      scene.addItem(self)
      self.UpperLeft  =QResizeGraphicsRectItem(scene,self,ZValue+1,0,xmax,ymax,self.ZoomPointDlg)
      self.UpperRight =QResizeGraphicsRectItem(scene,self,ZValue+1,1,xmax,ymax,self.ZoomPointDlg)
      self.BottomLeft =QResizeGraphicsRectItem(scene,self,ZValue+1,2,xmax,ymax,self.ZoomPointDlg)
      self.BottomRight=QResizeGraphicsRectItem(scene,self,ZValue+1,3,xmax,ymax,self.ZoomPointDlg)

    def paint(self,painter,option,widget=0):
      None

    def mousePressEvent(self, event):
      QGraphicsRectItem.mousePressEvent(self,event)
      self.IsCapture = True

    def mouseReleaseEvent(self, event):
      self.IsCapture = False
      QGraphicsRectItem.mouseReleaseEvent(self,event)

    #function call each time a rectangle is move
    def itemChange(self, change, value):
      if (change == QtGui.QGraphicsItem.ItemPositionChange) :
        newpos = value.toPyObject()
        if self.IsCapture==True:
          xmax = self.scene().sceneRect().width()
          ymax = self.scene().sceneRect().height()
          self.x = newpos.x()/xmax
          self.y = newpos.y()/ymax
          #calcul width and height
          w = float(float(xmax)*float(self.zoom)/100)
          if self.IsImageWide==True:                            #format 16/9
            h = float((w/16)*9)
            if h>ymax:
              h = float(float(ymax)*float(self.zoom)/100)
              w = float((h/9)*16)
          else:                                                 #format 4/3
            h = float((w/4)*3)
            if h>ymax:
              h = float(float(ymax)*float(self.zoom)/100)
              w = float((h/3)*4)
          #crop rectangle in the image
          if self.x*xmax < 0: self.x=0
          if self.x*xmax > xmax-w: self.x=(xmax-w)/xmax
          if self.y*ymax < 0: self.y=0
          if self.y*ymax > ymax-h: self.y=(ymax-h)/ymax

          if self.ZoomPointDlg.MagneticEdge.isChecked()==True:
            mw = 2*(xmax/100)
            mh = 2*(ymax/100)
            if self.ZoomPointDlg.MagnetX1!=-1 and self.x*xmax>(self.ZoomPointDlg.MagnetX1-mw) and self.x*xmax<(self.ZoomPointDlg.MagnetX1+mw) :
              self.x=self.ZoomPointDlg.MagnetX1/xmax
            if self.ZoomPointDlg.MagnetX2!=-1 and (self.x*xmax+w)>(self.ZoomPointDlg.MagnetX2-mw) and (self.x*xmax+w)<(self.ZoomPointDlg.MagnetX2+mw) :
              self.x=(self.ZoomPointDlg.MagnetX2-w)/xmax
            if self.ZoomPointDlg.MagnetY1!=-1 and self.y*ymax>(self.ZoomPointDlg.MagnetY1-mh) and self.y*ymax<(self.ZoomPointDlg.MagnetY1+mh) :
              self.y=self.ZoomPointDlg.MagnetY1/ymax
            if self.ZoomPointDlg.MagnetY2!=-1 and (self.y*ymax+h)>(self.ZoomPointDlg.MagnetY2-mh) and (self.y*ymax+h)<(self.ZoomPointDlg.MagnetY2+mh) :
              self.y=(self.ZoomPointDlg.MagnetY2-h)/ymax

          newpos.setX(self.x*xmax)
          newpos.setY(self.y*ymax)
          self.ZoomPointDlg.SetupInterface()
        return newpos
      else :
        return QtGui.QGraphicsRectItem.itemChange(self, change, value)
        
    #function call by videoporama class each time zoom is change
    def zoomChange(self, NewZoom):
      if self.BlockZoomChange == False :
        xmax = self.scene().sceneRect().width()
        ymax = self.scene().sceneRect().height()
        self.zoom = NewZoom
        Pos=self.scenePos()
        self.x=Pos.x()/xmax
        self.y=Pos.y()/ymax
        #calcul width and height
        w = float(float(xmax)*float(self.zoom)/100)
        if self.IsImageWide==True:                            #format 16/9
          h = float((w/16)*9)
          if h>ymax:
            h = float(float(ymax)*float(self.zoom)/100)
            w = float((h/9)*16)
        else:                                                 #format 4/3
          h = float((w/4)*3)
          if h>ymax:
            h = float(float(ymax)*float(self.zoom)/100)
            w = float((h/3)*4)
        #crop rectangle in the image
        if self.x*xmax < 0: self.x=0
        if self.x*xmax > xmax-w: self.x=(xmax-w)/xmax
        if self.y*ymax < 0: self.y=0
        if self.y*ymax > ymax-h: self.y=(ymax-h)/ymax
        #en deux temps : d'abord bouger pour que les équivalents item repasse à zéro !
        if Pos.x()!=self.x*xmax or Pos.y()!=self.y*ymax: self.setPos(self.x*xmax,self.y*ymax)
        #les coordonnées scene sont maintenant ok : on peu retailler
        Rect=self.mapRectFromScene(QRectF(self.x*xmax,self.y*ymax,w,h))
        self.setRect(Rect)
        self.ZoomPointDlg.SetupInterface()

#---------------------------------------------------------------------------------------------------------------------------------------------------------------
# DefZoomPoint dialog box
#---------------------------------------------------------------------------------------------------------------------------------------------------------------
class DefZoomPointDlg(QDialog,Ui_DefZoomPointDlg) : #OK QT4

    def __init__(self,timelineImage,item,VideoporamaInstance,parent=None):
      super(DefZoomPointDlg, self).__init__(parent)
      self.setupUi(self)
      self.setModal(True)
      self.StopMAJSpinbox      = False
      self.VideoporamaInstance = VideoporamaInstance
      self.timelineImage       = timelineImage
      self.item                = item
      self.scene               = None
      self.MagnetX1            = -1
      self.MagnetX2            = -1
      self.MagnetY1            = -1
      self.MagnetY2            = -1
      self.MagneticEdge.setChecked(True)

    def FirstInit(self):
      #Calc display width in system unit
      self.xmax =float(self.SceneBox.width())
      if self.VideoporamaInstance.imgformat==1 :
        self.ymax=(self.xmax/16)*9
      else :
        self.ymax=(self.xmax/4)*3
      if self.ymax>self.SceneBox.height() :
        self.ymax=float(self.SceneBox.height())
        if self.VideoporamaInstance.imgformat==1 :
          self.xmax=(self.ymax/9)*16
        else :
          self.xmax=(self.ymax/3)*4

      self.scene = QGraphicsScene()
      self.SceneBox.setScene(self.scene)
      self.SceneBox.setInteractive(True)
      self.scene.setSceneRect(QRectF(0,0,self.xmax,self.ymax))
      self.SceneBox.fitInView(QRectF(0,0,self.xmax,self.ymax),Qt.KeepAspectRatio)

      #--------------------------------------------------------------------
      # Set the QMyGraphicsRectItem
      #--------------------------------------------------------------------
      self.cadre=QMyGraphicsRectItem(self.scene,100,self.item.x,self.item.y,self.item.zoom,self.xmax,self.ymax,self.VideoporamaInstance.imgformat==1,self)

      #--------------------------------------------------------------------
      # Set handler
      #--------------------------------------------------------------------
      self.VideoporamaInstance.qtapp.connect(self.ZoomPointXValue,SIGNAL("valueChanged(double)"),self.ChgZoomPointXValue)
      self.VideoporamaInstance.qtapp.connect(self.ZoomPointYValue,SIGNAL("valueChanged(double)"),self.ChgZoomPointYValue)
      self.VideoporamaInstance.qtapp.connect(self.ZoomPointZoomValue,SIGNAL("valueChanged(double)"),self.ChgZoomPointZoomValue)
      self.VideoporamaInstance.qtapp.connect(self.Ok,SIGNAL("pressed()"),self.VideoporamaInstance.TableZoomPoint_DefZoomPointOk)
      self.VideoporamaInstance.qtapp.connect(self.Cancel,SIGNAL("pressed()"),self.onCancel)
      self.VideoporamaInstance.qtapp.connect(self.MagneticEdge,SIGNAL("stateChanged(int)"),self.ChgMagnetic)
      self.VideoporamaInstance.qtapp.connect(self.HelpBt,SIGNAL("pressed()"),self.onHelp)

      # Prepare image
      self.image,Unused = self.timelineImage.ToRenderImageForDisplay(0,self.xmax,self.ymax,0,0,0,0,True,DontRenderImageText=False,DontRenderZoomPointText=True)

      # Calc guides positions
      VirtX=float(self.item.ImageItem.RealImageSizeWidth)
      if self.VideoporamaInstance.imgformat==1 : VirtY=(VirtX/16)*9
      else :                                     VirtY=(VirtX/4)*3
      if VirtY<float(self.item.ImageItem.RealImageSizeHeight) :
        VirtY=float(self.item.ImageItem.RealImageSizeHeight)
        if self.VideoporamaInstance.imgformat==1 : VirtX=(VirtY/9)*16
        else :                                     VirtX=(VirtY/3)*4
        Ratio=float(self.ymax)/VirtY
      else :
        Ratio=float(self.xmax)/VirtX

      self.MagnetX1=-1
      self.MagnetX2=-1
      self.MagnetY1=-1
      self.MagnetY2=-1
      if (float(self.item.ImageItem.RealImageSizeWidth)*Ratio!=self.image.width()) :
        # bandes noires sur les cotés
        self.MagnetX1=(float(self.xmax)-(float(self.item.ImageItem.RealImageSizeWidth)*Ratio))/2
        self.MagnetX2=self.MagnetX1+(float(self.item.ImageItem.RealImageSizeWidth)*Ratio)
      if (float(self.item.ImageItem.RealImageSizeHeight)*Ratio!=self.image.height()) :
        # bandes noires en haut et en bas
        self.MagnetY1=(float(self.ymax)-(float(self.item.ImageItem.RealImageSizeHeight)*Ratio))/2
        self.MagnetY2=self.MagnetY1+(float(self.item.ImageItem.RealImageSizeHeight)*Ratio)

      self.SetupInterface()
      #Restore Window Size & Position (if needed)
      if self.VideoporamaInstance.RestoreWindowState=="1" and self.VideoporamaInstance.ZoomBoxWinRx>0:
        self.move(self.VideoporamaInstance.ZoomBoxWinRx,self.VideoporamaInstance.ZoomBoxWinRy)
        self.resize(self.VideoporamaInstance.ZoomBoxWinRw,self.VideoporamaInstance.ZoomBoxWinRh)
        if self.VideoporamaInstance.ZoomBoxIsMaximized!=0: self.showMaximized()

    def SaveWindowPosition(self):
      # Save Windows size/position on exit
      if self.isMaximized():  
        self.VideoporamaInstance.TextBoxIsMaximized=1
      else : 
        self.VideoporamaInstance.TextBoxIsMaximized=0
        if isWindows():
          size=self.frameGeometry()
          self.VideoporamaInstance.ZoomBoxWinRx = size.x()
          self.VideoporamaInstance.ZoomBoxWinRy = size.y()
          size=self.geometry()
        else:
          size=self.geometry()
          self.VideoporamaInstance.ZoomBoxWinRx = size.x()-1 #It's not good but X11 don't give the real information !
          self.VideoporamaInstance.ZoomBoxWinRy = size.y()-self.VideoporamaInstance.win.menuBar().height()-5 #It's not good but X11 don't give the real information !
        self.VideoporamaInstance.ZoomBoxWinRw = size.width()
        self.VideoporamaInstance.ZoomBoxWinRh = size.height()

    def onHelp(self):
      self.docw=DocHelp(self.VideoporamaInstance,self.VideoporamaInstance.qtapp.translate("Documentation","en-zoombox.html"),self)
      self.docw.show() 

    def onCancel(self):
      self.close()

    def closeEvent(self, CloseEvent):
      None

    def resizeEvent(self, event) :
      if self.scene!=None:
        #Calc display width in system unit
        self.xmax =float(self.SceneBox.width())
        if self.VideoporamaInstance.imgformat==1 :
          self.ymax=(self.xmax/16)*9
        else :
          self.ymax=(self.xmax/4)*3
        if self.ymax>self.SceneBox.height() :
          self.ymax=float(self.SceneBox.height())
          if self.VideoporamaInstance.imgformat==1 :
            self.xmax=(self.ymax/9)*16
          else :
            self.xmax=(self.ymax/3)*4

        self.scene.setSceneRect(QRectF(0,0,self.xmax,self.ymax))
        self.SceneBox.fitInView(QRectF(0,0,self.xmax,self.ymax),Qt.KeepAspectRatio)

        #Move and resize cadre item
        self.cadre.xmax=self.xmax
        self.cadre.ymax=self.ymax
        self.cadre.setPos(self.cadre.x*self.xmax,self.cadre.y*self.ymax)
        Rect=self.cadre.mapRectFromScene(QRectF(self.cadre.x*self.xmax,self.cadre.y*self.ymax,(self.cadre.zoom/100)*self.xmax,(self.cadre.zoom/100)*self.ymax))
        self.cadre.setRect(Rect)
        #Don't need to move Resize Rectangles because SetupInterface how do this job !

        # Update guides positions
        VirtX=float(self.item.ImageItem.RealImageSizeWidth)
        if self.VideoporamaInstance.imgformat==1 : VirtY=(VirtX/16)*9
        else :                                     VirtY=(VirtX/4)*3
        if VirtY<float(self.item.ImageItem.RealImageSizeHeight) :
          VirtY=float(self.item.ImageItem.RealImageSizeHeight)
          if self.VideoporamaInstance.imgformat==1 : VirtX=(VirtY/9)*16
          else :                                     VirtX=(VirtY/3)*4
          Ratio=float(self.ymax)/VirtY
        else :
          Ratio=float(self.xmax)/VirtX

        self.MagnetX1=-1
        self.MagnetX2=-1
        self.MagnetY1=-1
        self.MagnetY2=-1
        if (float(self.item.ImageItem.RealImageSizeWidth)*Ratio!=self.image.width()) :
          # bandes noires sur les cotés
          self.MagnetX1=(float(self.xmax)-(float(self.item.ImageItem.RealImageSizeWidth)*Ratio))/2
          self.MagnetX2=self.MagnetX1+(float(self.item.ImageItem.RealImageSizeWidth)*Ratio)
        if (float(self.item.ImageItem.RealImageSizeHeight)*Ratio!=self.image.height()) :
          # bandes noires en haut et en bas
          self.MagnetY1=(float(self.ymax)-(float(self.item.ImageItem.RealImageSizeHeight)*Ratio))/2
          self.MagnetY2=self.MagnetY1+(float(self.item.ImageItem.RealImageSizeHeight)*Ratio)

        # Prepare image
        self.image,Unused = self.timelineImage.ToRenderImageForDisplay(0,self.xmax,self.ymax,0,0,0,0,True,DontRenderImageText=False,DontRenderZoomPointText=True)
        # Update all
        self.SetupInterface()

    def SetupInterface(self):
      if self.StopMAJSpinbox: return
      self.StopMAJSpinbox=True
      if self.VideoporamaInstance.ConfDisplayUnit=="0" :
        # Define the value and max value (in %)
        self.ZoomPointXValue.setRange(0,99-self.cadre.zoom)
        self.ZoomPointXValue.setValue(self.cadre.x*100)
        self.ZoomPointXValue.setSingleStep(int(100/20)) 
        self.ZoomPointYValue.setRange(0,99-self.cadre.zoom)
        self.ZoomPointYValue.setValue(self.cadre.y*100)
        self.ZoomPointYValue.setSingleStep(int(100/20)) 
        self.ZoomPointZoomValue.setRange(1,100)
        self.ZoomPointZoomValue.setValue(self.cadre.zoom)
        self.ZoomPointZoomValue.setSingleStep(int(100/20)) 
        # Setup label associated with each edit
        self.ZoomPointXLabel.setText(self.VideoporamaInstance.qtapp.translate("main","%"))
        self.ZoomPointYLabel.setText(self.VideoporamaInstance.qtapp.translate("main","%"))
        self.ZoomPointZoomLabel.setText(self.VideoporamaInstance.qtapp.translate("main","%"))
      else :
        # Define the value and max value (in pixel)
        w=self.xmax*self.cadre.zoom/100
        h=self.ymax*self.cadre.zoom/100
        self.ZoomPointXValue.setRange(0,self.xmax-w)
        self.ZoomPointXValue.setValue(self.cadre.x*self.xmax)
        self.ZoomPointXValue.setSingleStep(int(self.xmax/20))
        self.ZoomPointYValue.setRange(0,self.ymax-h)
        self.ZoomPointYValue.setValue(self.cadre.y*self.ymax)
        self.ZoomPointYValue.setSingleStep(int(self.ymax/20))
        self.ZoomPointZoomValue.setRange(1,self.xmax)
        self.ZoomPointZoomValue.setValue(self.xmax*(self.cadre.zoom/100)) 
        self.ZoomPointZoomValue.setSingleStep(int(self.xmax/20)) 
        # Setup label associated with each edit
        self.ZoomPointXLabel.setText(self.VideoporamaInstance.qtapp.translate("main","Pix")+"/"+unicode(int(self.xmax-w)))
        self.ZoomPointYLabel.setText(self.VideoporamaInstance.qtapp.translate("main","Pix")+"/"+unicode(int(self.ymax-h)))
        self.ZoomPointZoomLabel.setText(self.VideoporamaInstance.qtapp.translate("main","Pix")+"/"+unicode(int(self.xmax)))

      # Repaint
      if self.scene!=None:
        # Remove old image if exist
        for item in self.scene.items() :
          if item.data(0).toString()=="image" :
            self.scene.removeItem(item)

        PixImage=QPixmap.fromImage(self.image).copy()

        # Draw selection rectangle for self.cadre
        p=QPainter(PixImage)

        # draw rect out of the rectangle
        p.setPen(Qt.NoPen)
        p.setBrush(QBrush(toqcolor(QString("555555").toInt(16)[0])))
        p.setOpacity(0.75)
        p.drawRect(QRectF(0,0,self.xmax,self.cadre.y*self.ymax))
        p.drawRect(QRectF(0,self.cadre.y*self.ymax,self.cadre.x*self.xmax,(self.cadre.zoom/100)*self.ymax))
        p.drawRect(QRectF(self.cadre.x*self.xmax+(self.cadre.zoom/100)*self.xmax,self.cadre.y*self.ymax,self.xmax,(self.cadre.zoom/100)*self.ymax))
        p.drawRect(QRectF(0,self.cadre.y*self.ymax+(self.cadre.zoom/100)*self.ymax,self.xmax,self.ymax))
        p.setOpacity(1)
        p.setBrush(Qt.NoBrush)

        # draw guides
        p.setCompositionMode(QPainter.RasterOp_SourceXorDestination)
        if self.MagneticEdge.isChecked()==True:
          col=QColor(255,0,0)
          pen=QPen(col)
          pen.setWidth(1)
          pen.setJoinStyle(Qt.RoundJoin)
          pen.setStyle(Qt.DotLine)
          p.setPen(pen)
          if self.MagnetX1!=-1: p.drawLine(self.MagnetX1,0,self.MagnetX1,self.ymax)
          if self.MagnetX2!=-1: p.drawLine(self.MagnetX2,0,self.MagnetX2,self.ymax)
          if self.MagnetY1!=-1: p.drawLine(0,self.MagnetY1,self.xmax,self.MagnetY1)
          if self.MagnetY2!=-1: p.drawLine(0,self.MagnetY2,self.xmax,self.MagnetY2)
        p.setCompositionMode(QPainter.CompositionMode_SourceOver)
        p.end()

        # Add image to the background of the scene
        im=self.scene.addPixmap(PixImage)
        im.setData(0,QVariant(QString("image")))
        im.setZValue(20)
        im.setPos(0,0)

      self.StopMAJSpinbox=False
      #Move Resize Rectangle
      self.cadre.UpperLeft.CalcPosition()
      self.cadre.UpperRight.CalcPosition()
      self.cadre.BottomLeft.CalcPosition()
      self.cadre.BottomRight.CalcPosition()

    def ChgMagnetic(self) :
      self.SetupInterface()

    def ChgZoomPointXValue(self,Value):
      if self.StopMAJSpinbox: return
      if self.VideoporamaInstance.ConfDisplayUnit=="0" : Value=Value/100         # Define value in %
      else :                                             Value=Value/self.ymax   # Define value in Pixel
      self.cadre.x=Value
      self.cadre.setPos(Value*self.xmax,self.cadre.y*self.ymax)
      Rect=self.cadre.mapRectFromScene(QRectF(self.cadre.x*self.xmax,self.cadre.y*self.ymax,self.xmax*self.cadre.zoom/100,self.ymax*self.cadre.zoom/100))
      self.cadre.setRect(Rect)
      self.SetupInterface()
      self.repaint()

    def ChgZoomPointYValue(self,Value):
      if self.StopMAJSpinbox: return
      if self.VideoporamaInstance.ConfDisplayUnit=="0" : Value=Value/100         # Define value in %
      else :                                             Value=Value/self.ymax   # Define value in Pixel
      self.cadre.y=Value
      self.cadre.setPos(self.cadre.x*self.xmax,Value*self.ymax)
      Rect=self.cadre.mapRectFromScene(QRectF(self.cadre.x*self.xmax,self.cadre.y*self.ymax,self.xmax*self.cadre.zoom/100,self.ymax*self.cadre.zoom/100))
      self.cadre.setRect(Rect)
      self.SetupInterface()
            
    def ChgZoomPointZoomValue(self,Value):
      if self.StopMAJSpinbox: return
      if self.VideoporamaInstance.ConfDisplayUnit=="0" :  None                        # Define value in %
      else:                                               Value=(Value/self.xmax)*100 # Define value in Pixel
      self.cadre.zoom=Value
      self.cadre.zoomChange(Value)
      self.SetupInterface()