18 #include <QApplication>
19 #include <QCloseEvent>
20 #include <QDesktopWidget>
22 #include <QMouseEvent>
29 : QFrame(parent, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint),
35 setMouseTracking(
true);
37 setFrameStyle(QFrame::Panel | QFrame::Raised);
52 m_Steps2 = m_Steps / 2;
53 m_HStep = 360 / m_Steps;
54 m_SStep = 512 / m_Steps;
55 m_VStep = 512 / m_Steps;
66 double x(e->pos().x());
67 double y(e->pos().y());
72 x = (int)(x * (
float)(m_Steps - 1)) / (float)(m_Steps - 1);
84 y = (int)(y * (
float)m_Steps) / (
float)m_Steps;
86 m_H =
static_cast<int>(y * 359.0);
89 m_S =
static_cast<int>((1.0 - x) * 511.0);
101 m_V =
static_cast<int>(x * 511.0 + 511.0 / (float)(m_Steps - 1));
108 color.setHsv(m_H, m_S, m_V);
134 QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0, 0), QPoint(0, 0), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
135 QApplication::sendEvent(m_popupParent, &me);
140 m_popupParent = parent;
147 QColor qcolor((
int)((*color)[0] * 255.0), (
int)((*color)[1] * 255.0), (
int)((*color)[2] * 255.0));
149 qcolor.getHsv(&h, &s, &v);
155 float cellwidth = (float)width() / (float)(m_Steps);
160 x = (int)((((
float)v / 255.0) * ((float)m_Steps2) - 1.0) * cellwidth + cellwidth / 2);
165 x = (int)(((1.0 - ((
float)s / 255.0)) * ((
float)m_Steps2)) * cellwidth + cellwidth / 2
171 y = (int)((
float)h / 360.0 * (float)m_Steps * cellwidth);
173 m_OriginalColor.setHsv(h, s, v);
176 newPos.setX(point.x() - x);
177 newPos.setY(point.y() - y);
182 m_OriginalColor.setHsv(-1, 0, 0);
184 newPos.setX(point.x() - width() / 2);
185 newPos.setY(point.y() - height() / 2);
187 move(m_popupParent->mapToGlobal(newPos));
198 QPainter painter(
this);
204 p->setWindow(0, 0, m_Steps - 1, m_Steps);
205 p->setPen(Qt::NoPen);
208 for (
unsigned int h = 0; h < m_Steps; ++h)
210 for (
unsigned int v = 1; v < m_Steps2; ++v)
212 c.setHsv(h * m_HStep, 255, v * m_VStep);
214 p->drawRect(v - 1, h, m_Steps2, m_Steps);
216 for (
unsigned int s = 0; s < m_Steps2; ++s)
218 c.setHsv(h * m_HStep, 255 - s * m_SStep, 255);
220 p->drawRect(m_Steps2 + s - 1, h, m_Steps2, m_Steps);
236 if (QApplication::desktop()->isVirtualDesktop())
237 scr = QApplication::desktop()->screenNumber(parent->mapToGlobal(pos()));
239 scr = QApplication::desktop()->screenNumber(parent);
277 c.getRgb(&r, &g, &b);
void onColorSelected(QColor)
The ColorProperty class RGB color property.
virtual void mouseReleaseEvent(QMouseEvent *) override
virtual void mousePressEvent(QMouseEvent *) override
static RenderingManager * GetInstance()
static QmitkPopupColorChooser * colorChooser
QmitkColorPropertyEditor(const mitk::ColorProperty *, QWidget *parent)
const mitk::Color & GetColor() const
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
const mitk::ColorProperty * m_ColorProperty
static int colorChooserRefCount
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
virtual ~QmitkColorPropertyEditor()