Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "QmitkApplicationCursor.h"
14 
15 #include <qapplication.h>
16 #include <qcursor.h>
17 #include <qpixmap.h>
18 
19 #include <iostream>
20 
22 {
24 }
25 
26 void QmitkApplicationCursor::PushCursor(std::istream &cursorStream, int hotspotX, int hotspotY)
27 {
28  if (cursorStream)
29  {
30  cursorStream.seekg(0, std::ios::end);
31  std::ios::pos_type length = cursorStream.tellg();
32  cursorStream.seekg(0, std::ios::beg);
33 
34  auto data = new char[length];
35  cursorStream.read(data, length);
36  QPixmap pixmap;
37  pixmap.loadFromData(QByteArray::fromRawData(data, length));
38  QCursor cursor(pixmap, hotspotX, hotspotY); // no test for validity in QPixmap(xpm)!
39  QApplication::setOverrideCursor(cursor);
40  delete[] data;
41  }
42 }
43 
44 void QmitkApplicationCursor::PushCursor(const char *XPM[], int hotspotX, int hotspotY)
45 {
46  QPixmap pixmap(XPM);
47  QCursor cursor(pixmap, hotspotX, hotspotY); // no test for validity in QPixmap(xpm)!
48  QApplication::setOverrideCursor(cursor);
49 }
50 
52 {
53  QApplication::restoreOverrideCursor();
54 }
55 
57 {
58  mitk::Point2I mp;
59  QPoint qp = QCursor::pos();
60  mp[0] = qp.x();
61  mp[1] = qp.y();
62  return mp;
63 }
64 
66 {
67  static bool selfCall = false;
68  if (selfCall)
69  return; // this is to avoid recursive calls
70  selfCall = true;
71  QCursor::setPos(p[0], p[1]);
72  selfCall = false;
73 }
static void RegisterImplementation(ApplicationCursorImplementation *implementation)
To be called by a toolkit specific ApplicationCursorImplementation.
const mitk::Point2I GetCursorPosition() override
Get absolute mouse position on screen.
void SetCursorPosition(const mitk::Point2I &) override
Set absolute mouse position on screen.
void PopCursor() override
Restore the previous cursor.
void PushCursor(const char *XPM[], int hotspotX, int hotspotY) override
Change the current application cursor.