14 #include <QApplication> 15 #include <QCloseEvent> 16 #include <QDesktopWidget> 18 #include <QMouseEvent> 25 : QFrame(parent, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint),
31 setMouseTracking(
true);
33 setFrameStyle(QFrame::Panel | QFrame::Raised);
48 m_Steps2 = m_Steps / 2;
49 m_HStep = 360 / m_Steps;
50 m_SStep = 512 / m_Steps;
51 m_VStep = 512 / m_Steps;
62 double x(e->pos().x());
63 double y(e->pos().y());
68 x = (int)(x * (
float)(m_Steps - 1)) / (float)(m_Steps - 1);
80 y = (int)(y * (
float)m_Steps) / (
float)m_Steps;
82 m_H =
static_cast<int>(y * 359.0);
85 m_S =
static_cast<int>((1.0 - x) * 511.0);
97 m_V =
static_cast<int>(x * 511.0 + 511.0 / (float)(m_Steps - 1));
104 color.setHsv(m_H, m_S, m_V);
130 QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0, 0), QPoint(0, 0), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
131 QApplication::sendEvent(m_popupParent, &me);
136 m_popupParent = parent;
143 QColor qcolor((
int)((*color)[0] * 255.0), (
int)((*color)[1] * 255.0), (
int)((*color)[2] * 255.0));
145 qcolor.getHsv(&h, &s, &v);
151 float cellwidth = (float)width() / (float)(m_Steps);
156 x = (int)((((
float)v / 255.0) * ((float)m_Steps2) - 1.0) * cellwidth + cellwidth / 2);
161 x = (int)(((1.0 - ((
float)s / 255.0)) * ((
float)m_Steps2)) * cellwidth + cellwidth / 2
167 y = (int)((
float)h / 360.0 * (float)m_Steps * cellwidth);
169 m_OriginalColor.setHsv(h, s, v);
172 newPos.setX(point.x() - x);
173 newPos.setY(point.y() - y);
178 m_OriginalColor.setHsv(-1, 0, 0);
180 newPos.setX(point.x() - width() / 2);
181 newPos.setY(point.y() - height() / 2);
183 move(m_popupParent->mapToGlobal(newPos));
194 QPainter painter(
this);
200 p->setWindow(0, 0, m_Steps - 1, m_Steps);
201 p->setPen(Qt::NoPen);
204 for (
unsigned int h = 0; h < m_Steps; ++h)
206 for (
unsigned int v = 1; v < m_Steps2; ++v)
208 c.setHsv(h * m_HStep, 255, v * m_VStep);
210 p->drawRect(v - 1, h, m_Steps2, m_Steps);
212 for (
unsigned int s = 0; s < m_Steps2; ++s)
214 c.setHsv(h * m_HStep, 255 - s * m_SStep, 255);
216 p->drawRect(m_Steps2 + s - 1, h, m_Steps2, m_Steps);
232 if (QApplication::desktop()->isVirtualDesktop())
233 scr = QApplication::desktop()->screenNumber(parent->mapToGlobal(pos()));
235 scr = QApplication::desktop()->screenNumber(parent);
273 c.getRgb(&r, &g, &b);
~QmitkColorPropertyEditor() override
void onColorSelected(QColor)
The ColorProperty class RGB color property.
void mouseReleaseEvent(QMouseEvent *) override
void mousePressEvent(QMouseEvent *) override
static RenderingManager * GetInstance()
static QmitkPopupColorChooser * colorChooser
const mitk::Color & GetColor() const
QmitkColorPropertyEditor(const mitk::ColorProperty *, QWidget *parent)
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)