| 131 | } |
| 132 | |
| 133 | void QmitkPopupColorChooser::popup(QWidget *parent, const QPoint &point, const mitk::Color *color) |
| 134 | { |
| 135 | m_popupParent = parent; |
| 136 | if (m_popupParent) |
| 137 | { |
| 138 | QPoint newPos; |
| 139 | |
| 140 | if (color) |
| 141 | { |
| 142 | QColor qcolor((int)((*color)[0] * 255.0), (int)((*color)[1] * 255.0), (int)((*color)[2] * 255.0)); |
| 143 | int h, s, v; |
| 144 | qcolor.getHsv(&h, &s, &v); |
| 145 | |
| 146 | if (h == -1) // set by Qt if color is achromatic ( but this widget does not display grays ) |
| 147 | h = 10; // red |
| 148 | |
| 149 | int x, y; |
| 150 | float cellwidth = (float)width() / (float)(m_Steps); |
| 151 | |
| 152 | if (s > v) // restrict to the colors we can display |
| 153 | { // left side, ramp from v = 255/m_Steps to v = 255 |
| 154 | s = 255; |
| 155 | x = (int)((((float)v / 255.0) * ((float)m_Steps2) - 1.0) * cellwidth + cellwidth / 2); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | v = 255; |
| 160 | x = (int)(((1.0 - ((float)s / 255.0)) * ((float)m_Steps2)) * cellwidth + cellwidth / 2 |
| 161 | |
| 162 | + |
| 163 | width() / 2); |
| 164 | } |
| 165 | |
| 166 | y = (int)((float)h / 360.0 * (float)m_Steps * cellwidth); |
| 167 | |
| 168 | m_OriginalColor.setHsv(h, s, v); |
| 169 | |
| 170 | // move to color |
| 171 | newPos.setX(point.x() - x); |
| 172 | newPos.setY(point.y() - y); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | // center widget |
| 177 | m_OriginalColor.setHsv(-1, 0, 0); |
| 178 | |
| 179 | newPos.setX(point.x() - width() / 2); |
| 180 | newPos.setY(point.y() - height() / 2); |
| 181 | } |
| 182 | move(m_popupParent->mapToGlobal(newPos)); |
| 183 | } |
| 184 | |
| 185 | show(); |
| 186 | raise(); |
| 187 | grabMouse(); |
| 188 | grabKeyboard(); |
| 189 | } |
| 190 |
no outgoing calls