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 }
void hasBeenHidden()
Responds to hide event from a document window.
Inspector * m_inspector
The Inspector.
void updateActions()
Update the actions in all CanvasWindow objects.
void quitOnLastWindowClose(bool yes=true)
Sets the flag that determines if the application will be terminated when the last window is closed...
setHeight(int h)
primaryScreen() const
size() const
screenGeometry(int screen=-1) const
truncate(uint newLen)
width() const
QAssistantClient * m_assistant
The QtAssistant client.
void updateActions()
Update Action objects.
void positionCanvas(CanvasWindow *window)
Positions and sets the size of the window taking into account the size of the screen.
A concrete window class that contains the canvas and responds to menu item and tool bar events from t...
Definition: CanvasWindow.h:106
void moveInspector(CanvasWindow *window)
Move the Inspector next to the edge of the Window.
arg(long a, int fieldWidth=0, int base=10) const
std::list< CanvasWindow * > m_window_list
The list of CanvasWindow objects created by the application.
void unHide(CanvasWindow *window)
Responds to document window being shown.
bool m_quit
A flag that when set true will terminate the application when the last canvas window closes...
bool allowClose()
If document has changed and not saved, opens a dialog box for user to choose to save, discard or cancel.
hippodraw::CanvasWindow class interface.
Inspector * getInspector()
returns the Inspector.
void setCaption()
Sets the Windows title.
remove(uint index, uint len)
A derived class of InspectorBase class which is generated by the Qt designer.
Definition: Inspector.h:234
x() const
y() const
void newWindow(CanvasWindow *)
Registers the new CanvasWindow and finishes its initialization.
CanvasView * getCanvasView()
Returns the CanvasView object.
setWidth(int w)
A singleton class for keeping track the window components of HippoDraw.
void autosaveSettings()
Automatically save dock windows and recently opened files.
void setCurrentCanvas(CanvasWindow *canvas)
Sets the current canvas.
This class implements additional FigureEditor functionality particular to QtView objects.
Definition: CanvasView.h:96
CanvasWindow * m_active_window
The CanvasWindow object.
const QRect & getScreenRect()
Returns a rectangle of the screen.
hippodraw::WindowController class interface
void closeAllWindows(bool alsoDelete)
Closes all Windows.
hippodraw::CanvasView class interface
WindowController()
Private Constructor.
absPath() const
static WindowController * s_instance
The instance of the application.
void openAssistant()
Opens the QAssistant object.
static std::string s_version
The version number of HippoDraw.
intp size(numeric::array arr)
Definition: num_util.cpp:296
static WindowController * instance()
Returns the application instance.
hippodraw::Inspector class interface.
findRev(QChar c, int index=-1, bool cs=TRUE) const
#define VERSION
Definition: config.h:120
CanvasWindow * currentCanvas()
Returns a pointer to the current CanvasWindow.
width() const
void aboutToClose(CanvasWindow *window)
Removes the window from the window list.
void inhibitClose(bool yes=true)
If yes is true, sets a flag so that this object will not accept close events.
void setFirstWindow()
Sets up the first CanvasWindow object.
void createInspector()
Creates the Inspector object and positions it on the desktop.
height() const
bool okToQuit()
Queries application if it is OK to quit.
~WindowController()
The destructor.
topLeft() const
length() const
setX(int x)
setY(int y)
static const std::string & version()
Returns the version number of HippoDraw.
void resizeCanvas(CanvasWindow *window)
Resizes the CanvasWindow so that it doesn't overlap with the Inspector window.
void setInspector(Inspector *inspector)
Sets the Inspector object.
Definition: CanvasView.cxx:611
void positionInspector()
Positions the Inspector as far right as possible based on size of screen and width of Inspector...

Generated for HippoDraw Class Library by doxygen