+ removeEventFilter(this);
+}
+
+bool ColorPickerWidget::eventFilter(QObject *object, QEvent *event)
+{
+ // Close color picker on any key press
+ if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride) {
+ closeEventFilter();
+ emit disableCurrentFilter(false);
+ event->setAccepted(true);
+ return true;
+ }
+ return QObject::eventFilter(object, event);
+
+}
+
+QColor ColorPickerWidget::grabColor(const QPoint &p, bool destroyImage)
+{
+#ifdef Q_WS_X11
+ /*
+ we use the X11 API directly in this case as we are not getting back a valid
+ return from QPixmap::grabWindow in the case where the application is using
+ an argb visual
+ */
+ if( !qApp->desktop()->geometry().contains( p ))
+ return QColor();
+ unsigned long xpixel;
+ if (m_image == NULL) {
+ Window root = RootWindow(QX11Info::display(), QX11Info::appScreen());
+ m_image = XGetImage(QX11Info::display(), root, p.x(), p.y(), 1, 1, -1, ZPixmap);
+ xpixel = XGetPixel(m_image, 0, 0);
+ } else {
+ xpixel = XGetPixel(m_image, p.x(), p.y());
+ }
+ if (destroyImage) {
+ XDestroyImage(m_image);
+ m_image = 0;
+ }
+ XColor xcol;
+ xcol.pixel = xpixel;
+ xcol.flags = DoRed | DoGreen | DoBlue;
+ XQueryColor(QX11Info::display(),
+ DefaultColormap(QX11Info::display(), QX11Info::appScreen()),
+ &xcol);
+ return QColor::fromRgbF(xcol.red / 65535.0, xcol.green / 65535.0, xcol.blue / 65535.0);
+#else
+ if (m_image.isNull()) {
+ QWidget *desktop = QApplication::desktop();
+ QPixmap pm = QPixmap::grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
+ QImage i = pm.toImage();
+ return i.pixel(0, 0);
+ } else {
+ return m_image.pixel(p.x(), p.y());
+ }
+#endif