Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkApplicationCursor.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkApplicationCursor.h"
18 
19 #include <qapplication.h>
20 #include <qcursor.h>
21 #include <qpixmap.h>
22 
23 #include <iostream>
24 
26 {
28 }
29 
30 void QmitkApplicationCursor::PushCursor(std::istream &cursorStream, int hotspotX, int hotspotY)
31 {
32  if (cursorStream)
33  {
34  cursorStream.seekg(0, std::ios::end);
35  std::ios::pos_type length = cursorStream.tellg();
36  cursorStream.seekg(0, std::ios::beg);
37 
38  auto data = new char[length];
39  cursorStream.read(data, length);
40  QPixmap pixmap;
41  pixmap.loadFromData(QByteArray::fromRawData(data, length));
42  QCursor cursor(pixmap, hotspotX, hotspotY); // no test for validity in QPixmap(xpm)!
43  QApplication::setOverrideCursor(cursor);
44  delete[] data;
45  }
46 }
47 
48 void QmitkApplicationCursor::PushCursor(const char *XPM[], int hotspotX, int hotspotY)
49 {
50  QPixmap pixmap(XPM);
51  QCursor cursor(pixmap, hotspotX, hotspotY); // no test for validity in QPixmap(xpm)!
52  QApplication::setOverrideCursor(cursor);
53 }
54 
56 {
57  QApplication::restoreOverrideCursor();
58 }
59 
61 {
62  mitk::Point2I mp;
63  QPoint qp = QCursor::pos();
64  mp[0] = qp.x();
65  mp[1] = qp.y();
66  return mp;
67 }
68 
70 {
71  static bool selfCall = false;
72  if (selfCall)
73  return; // this is to avoid recursive calls
74  selfCall = true;
75  QCursor::setPos(p[0], p[1]);
76  selfCall = false;
77 }
static void RegisterImplementation(ApplicationCursorImplementation *implementation)
To be called by a toolkit specific ApplicationCursorImplementation.
virtual const mitk::Point2I GetCursorPosition() override
Get absolute mouse position on screen.
virtual void SetCursorPosition(const mitk::Point2I &) override
Set absolute mouse position on screen.
virtual void PopCursor() override
Restore the previous cursor.
virtual void PushCursor(const char *XPM[], int hotspotX, int hotspotY) override
Change the current application cursor.