bool ScreenSelector::onMouseReleaseEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton && m_selectionInProgress == true ) { release(); // Give the frame buffer time to clear the selector window before // signaling the selection. QTimer::singleShot(100, this, SLOT(grabColor())); } return true; }
void KColorDialog::mouseMoveEvent(QMouseEvent *e) { if (d->bColorPicking) { d->_setColor(grabColor(e->globalPos())); return; } QWidget::mouseMoveEvent(e); }
void ColorPickerWidget::slotGetAverageColor() { disconnect(m_grabRectFrame, SIGNAL(getColor()), this, SLOT(slotGetAverageColor())); m_grabRect = m_grabRect.normalized(); int numPixel = m_grabRect.width() * m_grabRect.height(); int sumR = 0; int sumG = 0; int sumB = 0; // only show message for larger rects because of the overhead displayMessage creates if (numPixel > 40000) emit displayMessage(i18n("Requesting color information..."), 0); /* Only getting the image once for the whole rect results in a vast speed improvement. */ #ifdef Q_WS_X11 Window root = RootWindow(QX11Info::display(), QX11Info::appScreen()); m_image = XGetImage(QX11Info::display(), root, m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height(), -1, ZPixmap); #else QWidget *desktop = QApplication::desktop(); m_image = QPixmap::grabWindow(desktop->winId(), m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height()).toImage(); #endif for (int x = 0; x < m_grabRect.width(); ++x) { for (int y = 0; y < m_grabRect.height(); ++y) { QColor color = grabColor(QPoint(x, y), false); sumR += color.red(); sumG += color.green(); sumB += color.blue(); } // Warning: slows things down, so don't do it for every pixel (the inner for loop) if (numPixel > 40000) emit displayMessage(i18n("Requesting color information..."), (int)(x * m_grabRect.height() / (qreal)numPixel * 100)); } #ifdef Q_WS_X11 XDestroyImage(m_image); m_image = NULL; #endif if (numPixel > 40000) emit displayMessage(i18n("Calculated average color for rectangle."), -1); emit colorPicked(QColor(sumR / numPixel, sumG / numPixel, sumB / numPixel)); emit disableCurrentFilter(false); }
void KColorDialog::mouseReleaseEvent(QMouseEvent *e) { if (d->bColorPicking) { d->bColorPicking = false; /*#ifdef Q_WS_X11 kapp->removeX11EventFilter(d->filter); delete d->filter; d->filter = 0; #endif*/ releaseMouse(); releaseKeyboard(); d->_setColor(grabColor(e->globalPos())); return; } QWidget::mouseReleaseEvent(e); }
void KColorDialog::mouseReleaseEvent( TQMouseEvent *e ) { if (d->bColorPicking) { d->bColorPicking = false; #ifdef Q_WS_X11 tqt_set_x11_event_filter(d->oldfilter); d->oldfilter = 0; #endif releaseMouse(); releaseKeyboard(); _setColor( grabColor( e->globalPos() ) ); return; } KDialogBase::mouseReleaseEvent( e ); }
void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event) { if (m_filterActive) { closeEventFilter(); m_grabRect.setWidth(event->globalX() - m_grabRect.x()); m_grabRect.setHeight(event->globalY() - m_grabRect.y()); if (m_grabRect.width() * m_grabRect.height() == 0) { m_grabRectFrame->hide(); emit colorPicked(grabColor(event->globalPos())); emit disableCurrentFilter(false); } else { // delay because m_grabRectFrame does not hide immediately connect(m_grabRectFrame, SIGNAL(getColor()), this, SLOT(slotGetAverageColor())); m_grabRectFrame->hide(); } return; } QWidget::mouseReleaseEvent(event); }