コード例 #1
1
ファイル: colorpickeritem.cpp プロジェクト: bmatherly/shotcut
void ScreenSelector::grabColor()
{
    m_selectionRect = m_selectionRect.normalized();
    QDesktopWidget* desktop = QApplication::desktop();
    int screenNum = desktop->screenNumber(m_selectionRect.topLeft());
    QScreen* screen = QGuiApplication::screens()[screenNum];
    QPixmap screenGrab = screen->grabWindow(desktop->winId(),
        m_selectionRect.x(), m_selectionRect.y(), m_selectionRect.width(), m_selectionRect.height());
    QImage image = screenGrab.toImage();
    int numPixel = image.width() * image.height();
    int sumR = 0;
    int sumG = 0;
    int sumB = 0;

    for (int x = 0; x < image.width(); ++x) {
        for (int y = 0; y < image.height(); ++y) {
            QColor color = image.pixel(x, y);
            sumR += color.red();
            sumG += color.green();
            sumB += color.blue();
        }
    }

    QColor avgColor(sumR / numPixel, sumG / numPixel, sumB / numPixel);
    emit colorPicked(avgColor);
}
コード例 #2
0
ファイル: colorpickeritem.cpp プロジェクト: bmatherly/shotcut
ColorPickerItem::ColorPickerItem(QObject* parent)
    : QObject(parent)
{
    connect(this, SIGNAL(pickColor()), &m_selector, SLOT(startSelection()));
    connect(&m_selector, SIGNAL(colorPicked(QColor)), SIGNAL(colorPicked(QColor)));
    connect(&m_selector, SIGNAL(cancelled()), SIGNAL(cancelled()));
}
コード例 #3
0
void MColorComboBoxViewPrivate::_q_popupDisappeared()
{
    Q_Q(MColorComboBoxView);

    q->disconnect(popupWidget(), SIGNAL(disappeared()), q, SLOT(_q_popupDisappeared()));
    q->disconnect(colorWidget(), SIGNAL(colorPicked()), q, SLOT(_q_colorPicked()));
}
コード例 #4
0
void MColorComboBoxViewPrivate::_q_popupDisappeared()
{
    Q_Q(MColorComboBoxView);

    QObject::disconnect(controller, SIGNAL(dismissed()), popupWidget(), SLOT(reject()));
    q->disconnect(popupWidget(), SIGNAL(disappeared()), q, SLOT(_q_popupDisappeared()));
    q->disconnect(colorWidget(), SIGNAL(colorPicked()), q, SLOT(_q_colorPicked()));
}
コード例 #5
0
ファイル: ValueSlider.cpp プロジェクト: atdyer/SMT
void ValueSlider::setColor(const QColor &c)
{
	currentColor.setHsv(c.hue(), c.saturation(), c.value());
	trianglePoint = QPoint(contentsRect().width()-triangleWidth, ValToY(currentColor.value()));
	emit colorPicked(currentColor);
	BuildPixMap();
	update();
}
コード例 #6
0
ファイル: colorgridview.cpp プロジェクト: evansf/Qt-Plus
void ColorGridView::initContextMenu()
{
    menu.addAction(tr("Pick"), this,SLOT(colorPicked()));
    menu.addAction(tr("Drop From Wheel"),this,SLOT(colorDroped()));
    menu.addAction(tr("Clear"),this,SLOT(colorCleared()));
    menu.addAction(tr("Cancel"));
    connect(&menu,SIGNAL(aboutToHide()),this,SLOT(repaint()));
}
コード例 #7
0
void MRichTextEditDialogsManager::initTextStylingDialog()
{
    selectedFontSize = -1;
    selectedFontFamily = QString();
    selectedFontColor = QColor();

    if (dialogs.textStyles.first) {
        return;
    }
    //% "Text styles"
    dialogs.textStyles.first = new MDialog(qtTrId("qtn_comm_text_styles"),M::DoneButton);
    dialogs.textStyles.second = false;

    QGraphicsWidget *centralWidget = dialogs.textStyles.first->centralWidget();
    MLayout *layout = new MLayout(centralWidget);
    MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Vertical);

    // Initialize Font Family combo box
    QFontDatabase fontDatabase;
    QStringList fontFamilyValues = fontDatabase.families();

    // NOTE: black listing some ill-behaving fonts temporarily
    fontFamilyValues.removeAll("Webdings");
    fontFamilyValues.removeAll("Wingdings");

    fontFamilyCombo = new MComboBox(centralWidget);
    //% "Font"
    fontFamilyCombo->setTitle(qtTrId("qtn_comm_font"));
    QStringListModel *fontModel = new QStringListModel(centralWidget);
    fontModel->setStringList(fontFamilyValues);
    fontFamilyCombo->setItemModel(fontModel);
    policy->addItem(fontFamilyCombo);

    connect(fontFamilyCombo, SIGNAL(activated(QString)),
            this, SLOT(rememberFontFamily(QString)));

    // Initialize Font Size combo box
    fontSizeCombo = new MComboBox(centralWidget);
    //% "Font size"
    fontSizeCombo->setTitle(qtTrId("qtn_comm_font_size"));
    QStringListModel *sizeModel = new QStringListModel(centralWidget);
    fontSizeCombo->setItemModel(sizeModel);
    policy->addItem(fontSizeCombo);
    connect(fontSizeCombo, SIGNAL(activated(QString)),
            this, SLOT(rememberFontSize()));

    // Initialize Font Color item
    fontColorCombo = new MColorComboBox(centralWidget);
    //% "Font color"
    fontColorCombo->setTitle(qtTrId("qtn_comm_font_color_combobox"));
    policy->addItem(fontColorCombo);
    connect(fontColorCombo, SIGNAL(colorPicked(QColor)),
            this, SLOT(rememberFontColor(QColor)));

    // Selections are applied at pressing button "Done"
    connect(dialogs.textStyles.first, SIGNAL(accepted()),
            this, SLOT(applySelection()));
}
コード例 #8
0
void MColorComboBoxViewPrivate::_q_showPopup()
{
    Q_Q(MColorComboBoxView);

    popupWidget()->setTitle(q->model()->title());
    colorWidget()->setSelectedColor(q->model()->color());

    q->connect(popupWidget(), SIGNAL(disappeared()), q, SLOT(_q_popupDisappeared()));
    q->connect(colorWidget(), SIGNAL(colorPicked()), q, SLOT(_q_colorPicked()));
    popupWidget()->appear();
}
コード例 #9
0
ファイル: ColorPickerPushButton.cpp プロジェクト: JobstM/ogs
void ColorPickerPushButton::mouseReleaseEvent(QMouseEvent* e)
{
	Q_UNUSED(e);
	QColor newColor = QColorDialog::getColor(_color, NULL, "Choose a color");
	if (!newColor.isValid())
		return;

	setColor(newColor);

	emit colorPicked(_color);
}
コード例 #10
0
ファイル: colorpickerscene.cpp プロジェクト: Nach0z/IdealIRC
void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    QRgb rgb;

    try {
      rgb = pm.toImage().pixel( event->scenePos().toPoint() );
    }
    catch (...) {
        rgb = QColor(Qt::black).rgb();
    }

    emit colorPicked(QColor(rgb));
}
コード例 #11
0
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);
}
コード例 #12
0
ファイル: canvasmodel.cpp プロジェクト: LionsPhil/Drawpile
void CanvasModel::pickColor(int x, int y, int layer, int diameter)
{
	QColor color;
	if(layer>0) {
		const paintcore::Layer *l = m_layerstack->getLayer(layer);
		if(layer)
			color = l->colorAt(x, y, diameter);
	} else {
		color = m_layerstack->colorAt(x, y, diameter);
	}

	if(color.isValid() && color.alpha()>0) {
		color.setAlpha(255);
		emit colorPicked(color);
	}
}
コード例 #13
0
ファイル: colorsicon.cpp プロジェクト: VojtechVitek/spaint
void ColorsIcon::pickColor(QPalette::ColorRole role)
{
   // TODO: QColorDialog is bugged. Corrupts alpha when no adjustment occurs.
   QColorDialog dlg;
   dlg.setOption(QColorDialog::DontUseNativeDialog);
   dlg.setOption(QColorDialog::ShowAlphaChannel);
   dlg.setCurrentColor(role == QPalette::Foreground ? mPen : mBrush);
   dlg.setWindowTitle(role == QPalette::Foreground ?
                      tr("Select pen color") :
                      tr("Select brush color"));

   // Execute dialog
   if(dlg.exec() == QDialog::Accepted) {

      // Emit color change
      emit colorPicked(role, dlg.currentColor());
   }
}
コード例 #14
0
ファイル: ValueSlider.cpp プロジェクト: atdyer/SMT
void ValueSlider::mousePressEvent(QMouseEvent *event)
{
	if (event->button() == Qt::LeftButton)
	{
		QPoint point = event->pos();
		int val = ValFromY(point.y() - contentsRect().y());
		if (val < minVal || val > maxVal)
		{
			return;
		}
		currentColor.setHsv(currentColor.hue(), currentColor.saturation(), val);
		emit colorPicked(currentColor);
		emit valuePicked(currentColor.value());
		trianglePoint = QPoint(contentsRect().width()-triangleWidth, point.y());
		update();
	} else {
		QFrame::mousePressEvent(event);
	}
}
コード例 #15
0
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);
}
コード例 #16
0
/*!
 *  Constructs a rich text edit with a given \a parent
 */
QwwRichTextEdit::QwwRichTextEdit(QWidget *parent) : QTextEdit(parent){
    currentList = 0;
    m_options = Style | Alignment | FontFamily | FontSize | Color;
    tb = new QToolBar(this);
    tb->setIconSize(QSize(24,24));

#ifndef WW_NO_COLORBUTTON
    colorButton = new QwwColorButton(this);
    colorButton->setShowName(false);
    colorButton->setFlat(true);
    colorButton->setFocusPolicy(Qt::NoFocus);
    m_actions[ColorAction] = tb->addWidget(colorButton);
    connect(colorButton, SIGNAL(colorPicked(QColor)), this, SLOT(setColor(QColor)));
#endif
    fcb = new QFontComboBox(this);
    m_actions[FontFamilyAction] = tb->addWidget(fcb);
    connect(fcb, SIGNAL(activated(int)), this, SLOT(setFont_h()));
    fsp = new QComboBox(this);
    m_actions[FontSizeAction] = tb->addWidget(fsp);
    connect(fsp, SIGNAL(activated(const QString &)), this, SLOT(setFont_h()));
    foreach(int s, QFontDatabase::standardSizes())
    fsp->addItem(QString::number(s));

	m_actions[BoldAction] = new QAction(wwWidgets::icon("format-text-bold", QIcon(rsrcPath + "/textbold.png")), tr("Bold"), this);
    m_actions[BoldAction]->setCheckable(true);
    tb->addAction(m_actions[BoldAction]);
    connect(m_actions[BoldAction], SIGNAL(triggered(bool)), this, SLOT(setBold(bool)));
	m_actions[ItalicAction] = new QAction(wwWidgets::icon("format-text-italic", QIcon(rsrcPath + "/textitalic.png")), tr("Italic"), this);
    m_actions[ItalicAction]->setCheckable(true);
    tb->addAction(m_actions[ItalicAction]);

    connect(m_actions[ItalicAction], SIGNAL(triggered(bool)), this, SLOT(setItalic(bool)));
	m_actions[UnderlineAction] = new QAction(wwWidgets::icon("format-text-underline", QIcon(rsrcPath + "/textunder.png")), tr("Underline"), this);
    m_actions[UnderlineAction]->setCheckable(true);
    tb->addAction(m_actions[UnderlineAction]);

    cB = tb->addSeparator();
    connect(m_actions[UnderlineAction], SIGNAL(triggered(bool)), this, SLOT(setUnderline(bool)));
	al = new QAction(wwWidgets::icon("format-justify-left", QIcon(rsrcPath + "/textleft.png")), tr("Align left"), this);
	ar = new QAction(wwWidgets::icon("format-justify-right", QIcon(rsrcPath + "/textright.png")), tr("Align right"), this);
	ac = new QAction(wwWidgets::icon("format-justify-center", QIcon(rsrcPath + "/textcenter.png")), tr("Center"), this);
	aj = new QAction(wwWidgets::icon("format-justify-fill", QIcon(rsrcPath + "/textjustify.png")), tr("Justify"), this);
    QActionGroup *alignmentGroup = new QActionGroup(this);
    al->setCheckable(true);
    ar->setCheckable(true);
    ac->setCheckable(true);
    aj->setCheckable(true);
    alignmentGroup->addAction(al);
    alignmentGroup->addAction(ar);
    alignmentGroup->addAction(ac);
    alignmentGroup->addAction(aj);
    tb->addAction(al);
    tb->addAction(ac);
    tb->addAction(ar);
    tb->addAction(aj);
    tb->addSeparator();

    connect(alignmentGroup, SIGNAL(triggered(QAction *)), this, SLOT(changeAlignment(QAction*)));

	li = new QAction(wwWidgets::icon("format-list-unordered", QIcon(rsrcPath + "/list-unordered.png")), tr("List"), this);
    tb->addAction(li);
    li->setCheckable(true);
    connect(li, SIGNAL(toggled(bool)), this, SLOT(setList(bool)));



    setViewportMargins(0, tb->sizeHint().height()+1, 0, 0);
    setContentsMargins(0, tb->sizeHint().height(), 0, 0);
    connect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
            this, SLOT(updateCurrentCharFormat(const QTextCharFormat &)));
    connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateCurrentBlockFormat()));
    updateCurrentBlockFormat();
    updateCurrentCharFormat(textCursor().charFormat());
  }
コード例 #17
0
ファイル: overlay.cpp プロジェクト: VojtechVitek/spaint
      d->layout->addItem(icon);
      connect(icon, SIGNAL(selected(GraphicsIcon*)), this, SLOT(selectIcon(GraphicsIcon*)));
   }

   // Append number icon
   NumberIcon* thickness = new NumberIcon(this);
   d->layout->addItem(thickness);
   connect(thickness, SIGNAL(numberShifted(int)),
           this,      SLOT(changeThickness(int)));
   connect(this,      SIGNAL(thicknessChanged(int)),
           thickness, SLOT(setNumber(int)));

   // Append colors icon
   d->colors = new ColorsIcon(this);
   d->layout->addItem(d->colors);
   connect(d->colors, SIGNAL(colorPicked(QPalette::ColorRole,QColor)),
           this,   SLOT(changeColor(QPalette::ColorRole,QColor)));
   connect(this,   SIGNAL(colorChanged(QPalette::ColorRole,QColor)),
           d->colors, SLOT(setColor(QPalette::ColorRole,QColor)));

   // Connect thickness to color
   connect(this,      SIGNAL(colorChanged(QPalette::ColorRole,QColor)),
           thickness, SLOT(setColor(QPalette::ColorRole,QColor)));
}

Overlay::~Overlay()
{
   delete d;
}

Canvas::Tool Overlay::tool()
コード例 #18
0
ファイル: colorgriditem.cpp プロジェクト: CandyFace/pencil
void ColorGridItem::onColorPicked()
{
    emit colorPicked(this->gridId_, this->color_);
}
コード例 #19
0
ファイル: colorpicker.cpp プロジェクト: abom/watchntouch
void ColorPicker::mousePressEvent(QMouseEvent *e)
{
    emit colorPicked(m_colorWheelPixmap.toImage().pixel(e->x(), e->y()));
    qWarning() << "color" << m_colorWheelPixmap.toImage().pixel(e->x(), e->y()) << "coords" << e->pos();
}