PDA

View Full Version : Rotation on Qframe



Pharell
1st April 2008, 09:42
Hello,

I am using QT3 and am not so much fimiliar with the qt-programming. I have to make a rotation function on a qframe widget. I have my own rectangle class. The follow is what i have made but its not done correctly. Can someone please take a look at the code and give me some suggestion?


double View::Rotate(double a_dRotate)
{
MyRect m_Dev;
MyRect m_Form;
FRect m_Window;

int iWidth = m_Dev.Width();

QRect R = rect();
m_Form.Rect( R.left(), R.top(), R.right(), R.bottom() );

m_Dev.Width(m_Dev.Width() * a_dRotate);

if (m_Dev.Width() > 12000)
m_Dev.Width(12000);

if (m_Dev.Width() > 5000000)
m_Dev.Width(5000000);

if (m_Dev.Width() < 50)
m_Dev.Width(50);


m_Dev.Height( (double)m_Dev.Width() / ((double)m_Window.Width() / (double)m_Window.Height()) );
return ((double)m_Dev.Width() / (double)iWidth);
}

wysota
1st April 2008, 10:17
What exactly are you trying to rotate? Have you seen QWMatrix::rotate()?

Pharell
1st April 2008, 10:44
What exactly are you trying to rotate? Have you seen QWorldMatrix::rotate()?

A rectangle inside a qframe. I have seen QWorldMatrix but can i use it with QRECT?

wysota
1st April 2008, 11:01
Take a look at QWMatrix::mapRect().

Pharell
1st April 2008, 11:38
Take a look at QWMatrix::mapRect().

I have changed my code as follows but it doesnt work at all.



MyRect m_Dev;
MyRect m_Form;
QRect View = rect();
QWMatrix m;

int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );
m.mapRect(View);
m.rotate( -45.0 );

wysota
1st April 2008, 12:04
Because it doesn't work that way.


QWMatrix m;
m.rotate(-45);
QRect newRect = m.mapRect(rect());

Look closely what each method does and returns.

Pharell
1st April 2008, 12:42
Because it doesn't work that way.


QWMatrix m;
m.rotate(-45);
QRect newRect = m.mapRect(rect());

Look closely what each method does and returns.

Yep thnx alot. But i see stil some mis calculation in my methods i have one main class which has these two functions and it is XView: QFrame -


double XView::Rotate(double a_dRotate)
{
QWMatrix m;
m.rotate(22);
QRect newRect = m.mapRect(rect());
return a_dRotate;
}

void XView::Rotate(double a_dRotate, double x, double y)
{
double rotateView = Rotate(a_dRotate);

x *= rotateView;
y *= rotateView;
}

In my other class which is View: XView, i have a slot which should do the rotation and it is as follows:


void View::SlotRotate()
{

QRect View = rect();

//in this place the rectangle is calculated,
int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );


Rotate(22, x, y);
}

I see that its not working properly.

wysota
1st April 2008, 14:01
double XView::Rotate(double a_dRotate)
{
QWMatrix m;
m.rotate(22);
QRect newRect = m.mapRect(rect());
return a_dRotate;
}
This code does exactly nothing. You calculate a rectangle based on some other rectangle and return the argument the method was given as a parameter. If you pass it 4.0573 it will return 4.0573, etc.


In my other class which is View: XView, i have a slot which should do the rotation and it is as follows:



void View::SlotRotate()
{

QRect View = rect();

//in this place the rectangle is calculated,
int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );


Rotate(22, x, y);
}

I see that its not working properly.

What would you like the code to do? Because currently your Rotate() function is meaningless, it's a no-op. SlotRotate() is also meaningless - you create a bunch of variables which you never use.

Pharell
2nd April 2008, 11:06
Hello ppls,
I am still fighting with this rotation problem. When i debug i see that the coordinates are changing but the view is not changing. The qrect has normal (x1= 0, y1=0, x2 = 511, y2 = 469) after setting the rotate(180.0), these coordinates changes to = (x1= -511, y1 = -469, x2=0, y2= 0)


QWMatrix m;
QRect R;
m_Form.Rect( R.left(), R.top(), R.right(), R.bottom() );
m.rotate(180.0);
R = m.mapRect(rect());

wysota
2nd April 2008, 13:12
What do you do with "R" afterwards?

Pharell
2nd April 2008, 14:33
What do you do with "R" afterwards?

notting :( (i am really confused with it) i have send u the code of zoom yesterday and that code works fine that way. I call this function(Above code) with a slot.

wysota
2nd April 2008, 16:31
If you map a rectangle to another rectangle, there is no magic happening - the new rectangle ("R") gets coordinates calculated based on the matrix and the original rectangle. If you want to use the newly calculated rectangle, you have to actually write some code with it. Right now you are just creating a set of four coordinates in your computer's memory.