WindowController.cxx
Go to the documentation of this file.
1 
12 // for defects
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #include "Windows.h"
16 #endif
17 
18 // for version
19 #ifdef HAVE_CONFIG_H // for VERSION
20 #include "config.h"
21 #endif
22 
23 #include "WindowController.h"
24 
25 #include "CanvasView.h"
26 #include "CanvasWindow.h"
27 #include "Inspector.h"
28 
29 #include <qapplication.h>
30 #if QT_VERSION < 0x040000
31 #else
32 #include <QtGui/QDesktopWidget>
33 #endif
34 
35 #if QT_VERSION < 0x040000
36 #include <qassistantclient.h>
37 #else
38 #include <QtAssistant/QAssistantClient>
39 #endif
40 
41 #include <qdir.h>
42 
43 #include <algorithm>
44 
45 using std::find;
46 using std::list;
47 using std::mem_fun;
48 using std::for_each;
49 
50 using namespace hippodraw;
51 
53 std::string WindowController::s_version ( VERSION );
54 
55 const std::string & WindowController::version ()
56 {
57  return s_version;
58 }
59 
61  : m_active_window ( 0 ),
62  m_inspector ( 0 ),
63  m_assistant ( 0 ),
64  m_quit ( true )
65 {
66  s_instance = this;
67 }
68 
70 {
71  s_instance = 0;
72 }
73 
75 {
76  if ( s_instance == 0 ) {
78  }
79 
80  return s_instance;
81 }
82 
84 {
85  if ( m_inspector == 0 ) {
86  m_inspector = new Inspector ();
87  }
89 }
90 
92 {
93  unsigned int size = m_window_list.size ();
94  if ( size == 0 &&
95  m_quit == true ) {
96  window->inhibitClose ();
97  }
98  else if ( size == 1 ) {
99  CanvasWindow * w = m_window_list.front ();
100  w->inhibitClose ( false );
101  }
102 
103  m_window_list.push_back ( window );
104  positionCanvas ( window );
105  if ( m_inspector != 0 ) resizeCanvas ( window );
106  setCurrentCanvas ( window );
107 
108  CanvasView * view = window->getCanvasView ();
109  if ( m_inspector != 0 ) {
110  view->setInspector ( m_inspector );
111  moveInspector ( window );
112  }
113 
114 }
115 
116 void
119 {
120  if ( m_inspector != 0 ) {
121  QPoint w_pos = window -> pos ();
122  QSize w_size = window -> size ();
123  int pos = w_pos.x() + static_cast < int > ( 1.05 * w_size.width () );
124  w_pos.setX ( pos );
125  m_inspector -> move ( w_pos );
126  }
127 }
128 
129 void
132 {
133  m_quit = yes;
134 }
135 
139 void
142 {
143  m_window_list.remove ( window );
144  // window will delete itself.
145 
146  if ( m_window_list.size() == 1 &&
147  m_quit == true ) {
148  CanvasWindow * w = m_window_list.front();
149  w->inhibitClose ();
150  }
151  if ( m_window_list.empty() ) {
152  if ( m_inspector != 0 ) {
153  m_inspector -> hide ();
154  if ( m_quit == true ) {
155  m_inspector -> close ();
156  m_inspector = 0;
157  }
158  window->autosaveSettings();
159  m_window_list.clear ();
160  qApp->quit ();
161  }
162  }
163 }
164 
166 {
167  bool allhidden = true;
168 #ifdef ITERATOR_MEMBER_DEFECT
169  std::
170 #endif
171  list < CanvasWindow * > :: iterator first = m_window_list.begin ();
172  while ( first != m_window_list.end() ) {
173  CanvasWindow * w = *first++;
174  allhidden = w->isMinimized ();
175  if ( allhidden == false ) break;
176  }
177  if ( allhidden == true ) {
178  if ( m_inspector != 0 ) m_inspector->hide();
179  }
180 }
181 
183 {
184  if ( m_inspector != 0 ) m_inspector->show();
185 }
186 
188 {
189 #ifdef ITERATOR_MEMBER_DEFECT
190  std::
191 #endif
192  list < CanvasWindow * > :: iterator first = m_window_list.begin ();
193  bool ok = m_quit;
194 
195  if ( m_quit == true ) {
196  while ( first != m_window_list.end() ) {
197  CanvasWindow * window = *first++;
198  ok = window->allowClose ();
199  if ( ! ok ) break;
200  }
201  }
202 
203  return ok;
204 }
205 
206 void
209 {
210  if ( m_window_list.empty() == false ) {
211  for_each ( m_window_list.begin(), m_window_list.end(),
212  mem_fun ( &CanvasWindow::updateActions ) );
213  }
214 }
215 
216 void WindowController::closeAllWindows ( bool alsoDelete )
217 {
218 #ifdef ITERATOR_MEMBER_DEFECT
219  std::
220 #endif
221  list < CanvasWindow * > :: iterator first = m_window_list.begin ();
222  while ( first != m_window_list.end() ) {
223  CanvasWindow * window = *first++;
224  window -> setAllowClose ( true );
225  window->close ( alsoDelete );
226  }
227 
228  if ( m_inspector != 0 ) m_inspector -> close ( alsoDelete);
229 }
230 
231 #if QT_VERSION < 0x040000
233 #else
235 #endif
236 {
238  int screen = dt->primaryScreen ();
239 
240  return dt->screenGeometry ( screen );
241 }
242 
246 {
247  const QRect & rect = getScreenRect ();
248  QPoint p = rect.topLeft ();
249  if ( m_active_window != 0 ) {
250  p = m_active_window->pos();
251  QPoint offset ( 10, 10 );
252  p += offset;
253  }
254 
255 #ifdef __APPLE__
256  p.setY ( p.y() + 23 ); //To be under Apple menubar.
257 #endif
258 
259  window->move ( p );
260 }
261 void
264 {
265  if ( m_inspector == 0 ) return; // can't do it without inspector
266 
267  QPoint insp_pos = m_inspector -> pos ();
268  QSize w_size = window -> size ();
269 
270  const QRect & rect = getScreenRect ();
271  QSize s_size = rect.size ();
272  s_size *= 0.95;
273  QSize size = window -> sizeHint ();
274  size.setHeight ( s_size.height () );
275 
276  if ( w_size.width() > insp_pos.x () ) {
277  double x = insp_pos.x ();
278  double w = w_size.width ();
279  double scale = 0.90 * ( x / w );
280  CanvasView * cv = window -> getCanvasView ();
281  cv -> scaleBy ( scale );
282 
283  QSize size = window -> sizeHint ();
284  int width = static_cast < int > ( 0.95 * insp_pos.x () );
285  size.setWidth ( width );
286  window -> resize ( size );
287  }
288 }
289 
291 {
292  const QRect & rect = getScreenRect ();
293  QPoint pos = m_inspector->pos();
294  QSize size = m_inspector->size ();
295  int new_x = rect.width() - size.width();
296  pos.setX ( new_x );
297 #ifdef __APPLE__
298  pos.setY ( 23 ); //To be under Apple menubar.
299 #else
300  pos.setY ( 0 );
301 #endif
302 
303  m_inspector->move ( pos );
304 }
305 
307 {
308  m_active_window = canvas;
309 }
310 
312 {
313  return m_active_window;
314 }
315 
317 {
318  return m_inspector;
319 }
320 
321 void
324 {
325  createInspector ();
327  CanvasWindow * window = new CanvasWindow ();
328  window->setCaption ();
329 
330  window->show();
331 }
332 
333 void
336 {
337 #ifdef HAVE_HELP
338 #ifdef _MSC_VER
339  QString exe_path;
340 #endif
341  if ( m_assistant == 0 ) {
342 #ifdef _MSC_VER
343  // The following taken
344 //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulefilename.asp
345  LPCTSTR module = "qthippo.dll";
346  HMODULE handle = GetModuleHandle ( module );
347  int size = MAX_PATH;
348  TCHAR path[MAX_PATH];
349  DWORD count = GetModuleFileName ( handle, path, size );
350  exe_path = QDir ( path ).absPath();
351 
352  int pos = exe_path.findRev ( QString ( module ) );
353  exe_path.remove ( module ); // not trailing `/'
354  unsigned int len = exe_path.length();
355  exe_path.truncate( len -1 );
356  CanvasWindow * current = currentCanvas();
357  m_assistant = new QAssistantClient( exe_path , current );
358 #else
359  CanvasWindow * current = currentCanvas();
360  // QTDIR defined in Makefile
361  m_assistant = new QAssistantClient( QString ( QTDIR ), current );
362 #endif
363  }
364 
365 #ifdef _MSC_VER
366  QString docs_path = exe_path + "/doc";
367 #else
368  // `DOCS' defined in Makefile
369  QString docs_path = QDir ( DOCS ).absPath();
370 #endif
371 
372 #if QT_VERSION < 0x030200
373 #else
374  if ( m_assistant -> isOpen() == false ) {
375  QString adp = docs_path + QString ( "/hippodraw.adp" );
376  QStringList args;
377  args << "-profile"
378  << adp;
379  m_assistant -> setArguments ( args );
380  }
381 #endif
382  QString page ( "%1/assist_root.html" );
383  page = page.arg ( docs_path );
384  m_assistant ->
385  showPage ( page );
386 #endif // HAVE_HELP
387 }

Generated for HippoDraw Class Library by doxygen