Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QDiffusionImagingSplashScreen.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 
18 #include <QtGui>
19 #include <iostream>
20 
22  : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::SplashScreen), backgroundImage(image)
23 {
24  setAttribute(Qt::WA_TranslucentBackground);
25  resize(image.size());
26  resizeEvent(NULL);
27 }
28 
30 {
31 }
32 
34 {
35  return backgroundImage.size();
36 }
37 
39 {
40  QPainter painter(this);
41  painter.drawImage(rect(), backgroundImage);
42 }
43 
45 {
47 }
48 
49 QRegion QDiffusionImagingSplashScreen::createMaskRegion(const QImage &image, bool posMask)
50 {
51  if (image.isNull())
52  return QRegion();
53 
54  if (image.depth() != 32)
55  {
56  QImage img32 = image.convertToFormat(QImage::Format_RGB32);
57  return createMaskRegion(img32, posMask);
58  }
59 
60  int width = image.width();
61  int height = image.height();
62  QRegion retVal;
63 
64  for (int y = 0; y < height; ++y)
65  {
66  // guarented to be 32 bit by the check above
67  QRgb *currLine = (QRgb *)image.scanLine(y);
68  int xstart = -1;
69  int xcurr = -1;
70  QRgb *currVal = currLine;
71  for (int x = 0; x < width; ++x, ++currVal)
72  {
73  int alpha = qAlpha(*currVal);
74  if ((posMask && alpha != 0) || (!posMask && alpha == 0))
75  {
76  // on non-alpha pixel
77  if (xstart == -1)
78  {
79  // remember start of non-alpha line-segment (if necessary)
80  xstart = x;
81  }
82  xcurr = x;
83  }
84  else // alpha-pixel
85  if (xcurr != -1) // if this alpha pixel is following a non-alpha line-segment
86  {
87  retVal += QRegion(xstart, y, xcurr - xstart + 1, 1);
88  xstart = -1;
89  xcurr = -1;
90  }
91  }
92  if (xcurr != -1)
93  {
94  retVal += QRegion(xstart, y, xcurr - xstart + 1, 1);
95  }
96  }
97 
98  return retVal;
99 }
100 
102 {
103  QWidget::mouseReleaseEvent(mouseEvent);
104  hide();
105 }
QDiffusionImagingSplashScreen(const QImage &image, QWidget *parent=0)
QRegion createMaskRegion(const QImage &image, bool posMask=true)
virtual void paintEvent(QPaintEvent *paintEvent)
virtual void mouseReleaseEvent(QMouseEvent *mouseEvent)
virtual void resizeEvent(QResizeEvent *resizeEvent)