Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
util.cpp
1 
2 #include "util.h"
3 
4 
5 QTransform RectMapTransform( QRectF source, QRectF target )
6 {
7  qreal x1 = source.left();
8  qreal y1 = source.top();
9  qreal x2 = source.right();
10  qreal y2 = source.bottom();
11  qreal x1P = target.left();
12  qreal y1P = target.top();
13  qreal x2P = target.right();
14  qreal y2P = target.bottom();
15 
16  QTransform matrix;
17  if ( ( x1 != x2 ) && ( y1 != y2 ) )
18  {
19  matrix = QTransform( ( x2P - x1P ) / ( x2 - x1 ), // scale x
20  0,
21  0,
22  ( y2P - y1P ) / ( y2 - y1 ), // scale y
23  ( x1P * x2 - x2P * x1 ) / ( x2 - x1 ), // dx
24  ( y1P * y2 - y2P * y1 ) / ( y2 - y1 ) ); // dy
25  }
26  else
27  {
28  matrix.reset();
29  }
30  return matrix;
31 }
32 
33 SignalBlocker::SignalBlocker( QObject* o )
34  : mObject( o ),
35  mBlocked( o && o->blockSignals( true ) )
36 {}
37 
38 SignalBlocker::~SignalBlocker()
39 {
40  if ( mObject )
41  mObject->blockSignals( mBlocked );
42 }