0028316: Coding Rules - Elimilate confusing aliases of Standard_Real type in V3d_View
[occt.git] / samples / qt / Common / src / OcctWindow.cxx
CommitLineData
de6273a3 1#include <OcctWindow.h>
2
92efcf78 3IMPLEMENT_STANDARD_RTTIEXT(OcctWindow,Aspect_Window)
4
de6273a3 5// =======================================================================
6// function : OcctWindow
7// purpose :
8// =======================================================================
9OcctWindow::OcctWindow ( QWidget* theWidget, const Quantity_NameOfColor theBackColor )
10: Aspect_Window(),
11 myWidget( theWidget )
12{
13 SetBackground (theBackColor);
14 myXLeft = myWidget->rect().left();
15 myYTop = myWidget->rect().top();
16 myXRight = myWidget->rect().right();
17 myYBottom = myWidget->rect().bottom();
18}
19
20// =======================================================================
21// function : Destroy
22// purpose :
23// =======================================================================
24void OcctWindow::Destroy()
25{
26 myWidget = NULL;
27}
28
29// =======================================================================
30// function : NativeParentHandle
31// purpose :
32// =======================================================================
33Aspect_Drawable OcctWindow::NativeParentHandle() const
34{
35 QWidget* aParentWidget = myWidget->parentWidget();
36 if ( aParentWidget != NULL )
37 return (Aspect_Drawable)aParentWidget->winId();
38 else
39 return 0;
40}
41
42// =======================================================================
43// function : NativeHandle
44// purpose :
45// =======================================================================
46Aspect_Drawable OcctWindow::NativeHandle() const
47{
48 return (Aspect_Drawable)myWidget->winId();
49}
50
51// =======================================================================
52// function : IsMapped
53// purpose :
54// =======================================================================
55Standard_Boolean OcctWindow::IsMapped() const
56{
57 return !( myWidget->isMinimized() || myWidget->isHidden() );
58}
59
60// =======================================================================
61// function : Map
62// purpose :
63// =======================================================================
64void OcctWindow::Map() const
65{
66 myWidget->show();
67 myWidget->update();
68}
69
70// =======================================================================
71// function : Unmap
72// purpose :
73// =======================================================================
74void OcctWindow::Unmap() const
75{
76 myWidget->hide();
77 myWidget->update();
78}
79
80// =======================================================================
81// function : DoResize
82// purpose :
83// =======================================================================
84Aspect_TypeOfResize OcctWindow::DoResize() const
85{
86 int aMask = 0;
87 Aspect_TypeOfResize aMode = Aspect_TOR_UNKNOWN;
88
89 if ( !myWidget->isMinimized() )
90 {
91 if ( Abs ( myWidget->rect().left() - myXLeft ) > 2 ) aMask |= 1;
92 if ( Abs ( myWidget->rect().right() - myXRight ) > 2 ) aMask |= 2;
93 if ( Abs ( myWidget->rect().top() - myYTop ) > 2 ) aMask |= 4;
94 if ( Abs ( myWidget->rect().bottom() - myYBottom ) > 2 ) aMask |= 8;
95
96 switch ( aMask )
97 {
98 case 0:
99 aMode = Aspect_TOR_NO_BORDER;
100 break;
101 case 1:
102 aMode = Aspect_TOR_LEFT_BORDER;
103 break;
104 case 2:
105 aMode = Aspect_TOR_RIGHT_BORDER;
106 break;
107 case 4:
108 aMode = Aspect_TOR_TOP_BORDER;
109 break;
110 case 5:
111 aMode = Aspect_TOR_LEFT_AND_TOP_BORDER;
112 break;
113 case 6:
114 aMode = Aspect_TOR_TOP_AND_RIGHT_BORDER;
115 break;
116 case 8:
117 aMode = Aspect_TOR_BOTTOM_BORDER;
118 break;
119 case 9:
120 aMode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
121 break;
122 case 10:
123 aMode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
124 break;
125 default:
126 break;
127 } // end switch
128
129 *( ( Standard_Integer* )&myXLeft ) = myWidget->rect().left();
130 *( ( Standard_Integer* )&myXRight ) = myWidget->rect().right();
131 *( ( Standard_Integer* )&myYTop ) = myWidget->rect().top();
132 *( ( Standard_Integer* )&myYBottom) = myWidget->rect().bottom();
133 }
134
135 return aMode;
136}
137
138// =======================================================================
139// function : Ratio
140// purpose :
141// =======================================================================
ee2be2a8 142Standard_Real OcctWindow::Ratio() const
de6273a3 143{
144 QRect aRect = myWidget->rect();
ee2be2a8 145 return Standard_Real( aRect.right() - aRect.left() ) / Standard_Real( aRect.bottom() - aRect.top() );
de6273a3 146}
147
148// =======================================================================
149// function : Size
150// purpose :
151// =======================================================================
152void OcctWindow::Size ( Standard_Integer& theWidth, Standard_Integer& theHeight ) const
153{
154 QRect aRect = myWidget->rect();
155 theWidth = aRect.right();
156 theHeight = aRect.bottom();
157}
158
159// =======================================================================
160// function : Position
161// purpose :
162// =======================================================================
163void OcctWindow::Position ( Standard_Integer& theX1, Standard_Integer& theY1,
164 Standard_Integer& theX2, Standard_Integer& theY2 ) const
165{
166 theX1 = myWidget->rect().left();
167 theX2 = myWidget->rect().right();
168 theY1 = myWidget->rect().top();
169 theY2 = myWidget->rect().bottom();
170}