#include <QmitkColorPropertyEditor.h>
Signals | |
| void | colorSelected (QColor) |
| Call to popup this widget. parent determines popup position. | |
Public Member Functions | |
| QmitkPopupColorChooser (QWidget *parent=0, unsigned int steps=16, unsigned int size=150) | |
| virtual | ~QmitkPopupColorChooser () |
| void | setSteps (int) |
| virtual void | popup (QWidget *parent, const QPoint &point, const mitk::Color *=0) |
Protected Member Functions | |
| virtual void | keyReleaseEvent (QKeyEvent *) |
| virtual void | mouseMoveEvent (QMouseEvent *) |
| virtual void | mouseReleaseEvent (QMouseEvent *) |
| virtual void | closeEvent (QCloseEvent *) |
| virtual void | paintEvent (QPaintEvent *) |
| void | drawGradient (QPainter *p) |
Definition at line 28 of file QmitkColorPropertyEditor.h.
| QmitkPopupColorChooser::QmitkPopupColorChooser | ( | QWidget * | parent = 0, |
| unsigned int | steps = 16, |
||
| unsigned int | size = 150 |
||
| ) |
Definition at line 29 of file QmitkColorPropertyEditor.cpp.
References setSteps(), and TRUE.
: QFrame (parent, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint),
my_parent(parent)
{
setSteps(steps);
setLineWidth(2);
setMouseTracking ( TRUE );
//setMargin(0);
//setAutoMask( FALSE );
setFrameStyle ( QFrame::Panel | QFrame::Raised );
setLineWidth( 1 );
ensurePolished();
resize(size, size);
hide();
}
| QmitkPopupColorChooser::~QmitkPopupColorChooser | ( | ) | [virtual] |
Definition at line 48 of file QmitkColorPropertyEditor.cpp.
{
}
| void QmitkPopupColorChooser::closeEvent | ( | QCloseEvent * | e ) | [protected, virtual] |
Definition at line 116 of file QmitkColorPropertyEditor.cpp.
{
e->accept ();
releaseKeyboard();
releaseMouse();
if (!m_popupParent) return;
// remember that we (as a popup) might recieve the mouse release
// event instead of the popupParent. This is due to the fact that
// the popupParent popped us up in its mousePressEvent handler. To
// avoid the button remaining in pressed state we simply send a
// faked mouse button release event to it.
// Maleike: parent should not pop us on MouseRelease!
QMouseEvent me( QEvent::MouseButtonRelease, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
QApplication::sendEvent ( m_popupParent, &me );
}
| void QmitkPopupColorChooser::colorSelected | ( | QColor | ) | [signal] |
Call to popup this widget. parent determines popup position.
Referenced by keyReleaseEvent(), and mouseMoveEvent().
| void QmitkPopupColorChooser::drawGradient | ( | QPainter * | p ) | [protected] |
Definition at line 218 of file QmitkColorPropertyEditor.cpp.
Referenced by paintEvent().
{
p->setWindow( 0, 0, m_Steps-1, m_Steps ); // defines coordinate system
p->setPen( Qt::NoPen );
QColor c;
for ( unsigned int h = 0; h < m_Steps; ++h )
{
for ( unsigned int v = 1; v < m_Steps2; ++v )
{
c.setHsv( h*m_HStep, 255, v*m_VStep ); // rainbow effect
p->setBrush( c ); // solid fill with color c
p->drawRect( v-1, h, m_Steps2, m_Steps ); // draw the rectangle
}
for ( unsigned int s = 0; s < m_Steps2; ++s )
{
c.setHsv( h*m_HStep, 255 - s*m_SStep, 255 ); // rainbow effect
p->setBrush( c ); // solid fill with color c
p->drawRect( m_Steps2+s-1, h, m_Steps2, m_Steps ); // draw the rectangle
}
}
}
| void QmitkPopupColorChooser::keyReleaseEvent | ( | QKeyEvent * | ) | [protected, virtual] |
Definition at line 61 of file QmitkColorPropertyEditor.cpp.
References colorSelected().
{
emit colorSelected( m_OriginalColor );
close();
}
| void QmitkPopupColorChooser::mouseMoveEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Definition at line 67 of file QmitkColorPropertyEditor.cpp.
References colorSelected(), and int().
{
double x(e->pos().x());
double y(e->pos().y());
x /= width();
if ( x >= 0.0 )
{
//x = (int)(x / (1.0/m_Steps)) * (1.0/m_Steps); // div stepsize * stepsize
x = (int)(x * (float)(m_Steps-1)) / (float)(m_Steps-1); // same as above
if (x > 1.0) x = 1.0;
if (x < 0.0) x = 0.0;
}
y /= height();
if (y >= 1.0) y = 0.9;
if (y < 0.0) y = 0.0;
y = (int)(y * (float)m_Steps) / (float)m_Steps;
m_H = static_cast<int>( y * 359.0 );
if ( x >= 0.5 )
{
m_S = static_cast<int>( (1.0 - x) * 511.0 );
if ( m_S > 255 ) m_S = 255;
m_V = 255;
}
else
{
m_S = 255;
if ( x < 0.0 )
m_V = 0;
else
{
m_V = static_cast<int>( x * 511.0 + 511.0 / (float)(m_Steps-1) );
if ( m_V > 255 ) m_V = 255;
}
}
QColor color;
color.setHsv(m_H, m_S, m_V);
emit colorSelected( color );
}
| void QmitkPopupColorChooser::mouseReleaseEvent | ( | QMouseEvent * | ) | [protected, virtual] |
Definition at line 111 of file QmitkColorPropertyEditor.cpp.
{
close ();
}
| void QmitkPopupColorChooser::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
Definition at line 212 of file QmitkColorPropertyEditor.cpp.
References drawGradient().
{
QPainter painter(this);
drawGradient( &painter );
}
| void QmitkPopupColorChooser::popup | ( | QWidget * | parent, |
| const QPoint & | point, | ||
| const mitk::Color * | color = 0 |
||
| ) | [virtual] |
Definition at line 135 of file QmitkColorPropertyEditor.cpp.
References int().
Referenced by QmitkColorPropertyEditor::mousePressEvent().
{
m_popupParent = parent;
if (m_popupParent)
{
QPoint newPos;
if (color)
{
QColor qcolor( (int)((*color)[0] * 255.0) , (int)((*color)[1] * 255.0) , (int)((*color)[2] * 255.0) );
int h,s,v;
qcolor.getHsv(&h, &s, &v);
if ( h == -1 ) // set by Qt if color is achromatic ( but this widget does not display grays )
h = 10; // red
int x, y;
float cellwidth = (float)width() / (float)(m_Steps);
if ( s > v ) // restrict to the colors we can display
{ // left side, ramp from v = 255/m_Steps to v = 255
s = 255;
x = (int)(
(
((float)v / 255.0)
*
((float)m_Steps2)
-
1.0
)
*
cellwidth
+ cellwidth/2
);
}
else
{
v = 255;
x = (int)(
(
(1.0 - ((float)s / 255.0))
*
((float)m_Steps2)
)
*
cellwidth
+ cellwidth/2
+ width() / 2
);
}
y = (int)( (float)h/360.0 * (float)m_Steps * cellwidth );
m_OriginalColor.setHsv(h,s,v);
// move to color
newPos.setX( point.x() - x );
newPos.setY( point.y() - y );
}
else
{
// center widget
m_OriginalColor.setHsv(-1, 0, 0);
newPos.setX( point.x() - width() / 2 );
newPos.setY( point.y() - height() / 2 );
}
move ( m_popupParent->mapToGlobal( newPos ) );
}
show();
raise();
grabMouse();
grabKeyboard();
}
| void QmitkPopupColorChooser::setSteps | ( | int | steps ) |
Definition at line 52 of file QmitkColorPropertyEditor.cpp.
Referenced by QmitkPopupColorChooser().
{
m_Steps = steps;
m_Steps2 = m_Steps / 2;
m_HStep = 360 / m_Steps;
m_SStep = 512 / m_Steps;
m_VStep = 512 / m_Steps;
}
1.7.2