static void drawRectBox(QPainter *painter, const QRect &rect, bool start, bool end,
                        const QPalette &pal)
{
    painter->save();
    painter->setRenderHint(QPainter::Antialiasing, false);

    QRgb b = pal.base().color().rgb();
    QRgb h = pal.highlight().color().rgb();
    QColor c = StyleHelper::mergedColors(b,h, 50);

    QLinearGradient grad(rect.topLeft(), rect.topRight());
    grad.setColorAt(0, c.lighter(110));
    grad.setColorAt(1, c.lighter(130));
    QColor outline = c;

    painter->fillRect(rect, grad);
    painter->setPen(outline);
    if (start)
        painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() -  QPoint(1, 0));
    if (end)
        painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() -  QPoint(1, 0));

    painter->drawLine(rect.topRight() + QPoint(0, start ? 1 : 0), rect.bottomRight() - QPoint(0, end ? 1 : 0));
    painter->drawLine(rect.topLeft() + QPoint(0, start ? 1 : 0), rect.bottomLeft() - QPoint(0, end ? 1 : 0));

    painter->restore();
}
Example #2
0
void SpreadSheet::updateColor(QTableWidgetItem *item)
{
    QPixmap pix(16, 16);
    QColor col;
    if (item)
        col = item->backgroundColor();
    if (!col.isValid())
        col = palette().base().color();

    QPainter pt(&pix);
    pt.fillRect(0, 0, 16, 16, col);

    QColor lighter = col.light();
    pt.setPen(lighter);
    QPoint lightFrame[] = { QPoint(0, 15), QPoint(0, 0), QPoint(15, 0) };
    pt.drawPolyline(lightFrame, 3);

    pt.setPen(col.dark());
    QPoint darkFrame[] = { QPoint(1, 15), QPoint(15, 15), QPoint(15, 1) };
    pt.drawPolyline(darkFrame, 3);

    pt.end();

    colorAction->setIcon(pix);
}
Example #3
0
static QColor Vec3ToQColor(idVec3 v) {
    QColor c;
    c.setRed( static_cast<int>(v.x * 255) );
    c.setGreen( static_cast<int>(v.y * 255) );
    c.setBlue( static_cast<int>(v.z * 255) );
    return c;
}
Example #4
0
// -----------------------------------------------------------
void QucsSettingsDialog::slotBGColorDialog()
{
    QColor c = QColorDialog::getColor(
                   BGColorButton->paletteBackgroundColor(), this);
    if(c.isValid())
        BGColorButton->setPaletteBackgroundColor(c);
}
void addVertices(vector<float>& vertices, vector<float>& colors,
                 Vec2D<float> point, Vec2D<float> v1, QColor color,
                 float z = 0.0) {
  Vec2D<float> normal = v1;
  swap(normal.x, normal.y);
  normal.x *= -1;
  normal.normalize();

  Vec2D<float> p1 = point + normal * LINE_WIDTH;
  Vec2D<float> p2 = point - normal * LINE_WIDTH;

  for (int i = 0; i < 2; i++) {
    colors.push_back(color.redF());
    colors.push_back(color.greenF());
    colors.push_back(color.blueF());
    colors.push_back( (color.greenF() + color.redF()) *0.3f  );
  }

  vertices.push_back(p1.x);
  vertices.push_back(p1.y);
  vertices.push_back(z);

  vertices.push_back(p2.x);
  vertices.push_back(p2.y);
  vertices.push_back(z);
}
void PianoScene::setColorFromPolicy(PianoKey* key, int vel)
{
    QColor c;
#if defined(PALETTE_SUPPORT)
    switch (m_palette->paletteId()) {
    case PAL_SINGLE:
        c = m_palette->getColor(0);
        break;
    case PAL_DOUBLE:
        c = m_palette->getColor(key->getType());
        break;
    case PAL_CHANNELS:
        c = m_palette->getColor(m_channel);
        break;
    case PAL_SCALE:
        c = m_palette->getColor(key->getDegree());
    }
#else
    c = QApplication::palette().highlight().color();
#endif
    if (m_velocityTint && c.isValid()) {
        QBrush h(c.lighter(200 - vel));
        key->setPressedBrush(h);
    }
}
Example #7
0
void TerminalSettings::on_cursorBtn_clicked()
{
    QColor clr = QColorDialog::getColor(m_colors[COLOR_CURSOR], this);
    if(!clr.isValid())
        return;
    setBtnColor(ui->cursorBtn, clr, COLOR_CURSOR);
}
Example #8
0
void FileTransferWidget::paintEvent(QPaintEvent * event)
{
	QPainter * p = new QPainter(viewport());
	QStyleOptionViewItem option = viewOptions();
	QRect rect = event->rect();

#ifdef COMPILE_PSEUDO_TRANSPARENCY
	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->save();
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(rect, col);
		p->restore();
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = g_pFileTransferWindow->isDocked() ? viewport()->mapTo(g_pMainWindow, rect.topLeft()) : viewport()->mapTo(g_pFileTransferWindow, rect.topLeft());
		p->drawTiledPixmap(rect, *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	else
	{
#endif
		//FIXME this is not the treewindowlist
		p->fillRect(rect, KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground));
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	}
#endif
	delete p;

	//call paint on all childrens
	KviTalTableWidget::paintEvent(event);
}
Example #9
0
void caMessageButton::setBackground(QColor c)
{
    thisBackColor = c;
    thisHoverColor = c.lighter(120);
    thisBorderColor = c.darker(150);
    setColors(thisBackColor, thisForeColor, thisHoverColor, thisBorderColor, thisDisabledForeColor);
}
Example #10
0
void QDirectFBPixmapData::fill(const QColor &color)
{
    if (!serialNumber())
        return;

    Q_ASSERT(dfbSurface);

    alpha |= (color.alpha() < 255);

    if (alpha && isOpaqueFormat(imageFormat)) {
        QSize size;
        dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
        screen->releaseDFBSurface(dfbSurface);
        imageFormat = screen->alphaPixmapFormat();
        d = QDirectFBScreen::depth(imageFormat);
        dfbSurface = screen->createDFBSurface(size, screen->alphaPixmapFormat(), QDirectFBScreen::TrackSurface);
        setSerialNumber(++global_ser_no);
        if (!dfbSurface) {
            qWarning("QDirectFBPixmapData::fill()");
            invalidate();
            return;
        }
    }

    dfbSurface->Clear(dfbSurface, color.red(), color.green(), color.blue(), color.alpha());
}
void ScripterPrefsGui::setColor()
{
	QPushButton* button = (QPushButton*) sender();

	QColor oldColor;
	if (button == textButton)    oldColor = syntaxColors->textColor;
	if (button == commentButton) oldColor = syntaxColors->commentColor;
 	if (button == keywordButton) oldColor = syntaxColors->keywordColor;
 	if (button == errorButton)   oldColor = syntaxColors->errorColor;
 	if (button == signButton)    oldColor = syntaxColors->signColor;
 	if (button == stringButton)  oldColor = syntaxColors->stringColor;
 	if (button == numberButton)  oldColor = syntaxColors->numberColor;

	QColor color = QColorDialog::getColor(oldColor, this);
	if (color.isValid())
	{
		setButtonIcon(button, color);

		if (button == textButton)    syntaxColors->textColor = color;
		if (button == commentButton) syntaxColors->commentColor = color;
 		if (button == keywordButton) syntaxColors->keywordColor = color;
 		if (button == errorButton)   syntaxColors->errorColor = color;
 		if (button == signButton)    syntaxColors->signColor = color;
 		if (button == stringButton)  syntaxColors->stringColor = color;
 		if (button == numberButton)  syntaxColors->numberColor = color;
	}
}
Example #12
0
bool isDarkTheme()
{
    QPalette pal = QApplication::palette();
    // QPalette::Base is used for the background of the Treeview
    QColor color = pal.color(QPalette::Active, QPalette::Base);
    return (color.lightness() < 127);
}
Example #13
0
void TextInput::paintEvent(QPaintEvent* event)
{
    QLineEdit::paintEvent(event);

    if (!d.hint.isEmpty()) {
        QStyleOptionFrameV2 option;
        initStyleOption(&option);

        QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
        int left, top, right, bottom;
        getTextMargins(&left, &top, &right, &bottom);
        left += qMax(0, -fontMetrics().minLeftBearing());
        r.adjust(left, top, -right, -bottom);
        r.adjust(hMargin, vMargin, -hMargin, -vMargin);

        QString txt = text();
        if (!txt.isEmpty()) {
            if (!txt.endsWith(" "))
                txt += " ";
            r.adjust(fontMetrics().width(txt), 0, 0, 0);
        }

        QPainter painter(this);
        QColor color = palette().text().color();
        color.setAlpha(128);
        painter.setPen(color);

        QString hint = fontMetrics().elidedText(d.hint, Qt::ElideRight, r.width());
        painter.drawText(r, alignment(), hint);
    }
}
Example #14
0
QColor R_s_k_2::get_color(float value) const
{
  float hue = 240.0*(1.0 - value);
  QColor color;
  color.setHsv(hue, 255, 255);
  return color;
}
Example #15
0
void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    if (!doc)
        return;

    painter->setClipRect(boundingRect());

    // draw selection
    QAbstractTextDocumentLayout::PaintContext ctx;
    QAbstractTextDocumentLayout::Selection sel;

    if (hasSelection())
    {
        sel.cursor = QTextCursor(doc);
        sel.cursor.setPosition(getSelectionStart());
        sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor);
    }

    const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91);
    sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
    sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
    ctx.selections.append(sel);
    ctx.palette.setColor(QPalette::Text, color);

    // draw text
    doc->documentLayout()->draw(painter, ctx);
}
void MyProgressIndicator::paintEvent(QPaintEvent * /*event*/)
{
    if (!m_displayedWhenStopped && !isAnimated())
         return;

     qreal width = qMin(this->width()/2, this->height()/2);

     QPainter p(this);
     p.setRenderHint(QPainter::Antialiasing);

     qreal outerRadius = (width-1)*mSizePara;
     qreal innerRadius = (width-1)*mSizePara*0.38;

     qreal capsuleHeight = outerRadius - innerRadius;
     qreal capsuleWidth  = (width > 32 ) ? capsuleHeight *.23 : capsuleHeight *.35;
     qreal capsuleRadius = capsuleWidth/2;

     for (int i=0; i<12; i++)
     {
         QColor color = m_color;
         color.setAlphaF(1.0f - (i/12.0f));
         p.setPen(Qt::NoPen);

         p.setBrush(color);
         p.save();
         p.translate(rect().center());
         p.rotate(m_angle - i*30.0f);
         p.drawRoundedRect(-capsuleWidth*0.5, -(innerRadius+capsuleHeight), capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius);
         p.restore();
     }
}
Example #17
0
void TabOrderEditor::paintEvent(QPaintEvent *e)
{
    QPainter p(this);
    p.setClipRegion(e->region());

    int cur = m_current_index - 1;
    if (m_beginning == false && cur < 0)
        cur = m_tab_order_list.size() - 1;

    for (int i = 0; i < m_tab_order_list.size(); ++i) {
        QWidget *widget = m_tab_order_list.at(i);
        if (!isWidgetVisible(widget))
            continue;

        const QRect r = indicatorRect(i);

        QColor c = Qt::darkGreen;
        if (i == cur)
            c = Qt::red;
        else if (i > cur)
            c = Qt::blue;
        p.setPen(c);
        c.setAlpha(BG_ALPHA);
        p.setBrush(c);
        p.drawRect(fixRect(r));

        p.setPen(Qt::white);
        p.drawText(r, QString::number(i + 1), QTextOption(Qt::AlignCenter));
    }
}
Example #18
0
void OBSPropertiesView::AddColor(obs_property_t *prop, QFormLayout *layout,
		QLabel *&label)
{
	QPushButton *button     = new QPushButton;
	QLabel      *colorLabel = new QLabel;
	const char  *name       = obs_property_name(prop);
	long long   val         = obs_data_get_int(settings, name);
	QColor      color       = color_from_int(val);

	button->setText(QTStr("Basic.PropertiesWindow.SelectColor"));

	colorLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	colorLabel->setText(color.name(QColor::HexArgb));
	colorLabel->setPalette(QPalette(color));
	colorLabel->setAutoFillBackground(true);
	colorLabel->setAlignment(Qt::AlignCenter);

	QHBoxLayout *subLayout = new QHBoxLayout;
	subLayout->setContentsMargins(0, 0, 0, 0);

	subLayout->addWidget(colorLabel);
	subLayout->addWidget(button);

	WidgetInfo *info = new WidgetInfo(this, prop, colorLabel);
	connect(button, SIGNAL(clicked()), info, SLOT(ControlChanged()));
	children.emplace_back(info);

	label = new QLabel(QT_UTF8(obs_property_description(prop)));
	layout->addRow(label, subLayout);
}
Example #19
0
void TerminalSettings::on_textBtn_clicked()
{
    QColor clr = QColorDialog::getColor(m_colors[COLOR_TEXT], this);
    if(!clr.isValid())
        return;
    setBtnColor(ui->textBtn, clr, COLOR_TEXT);
}
Example #20
0
bool WidgetInfo::ColorChanged(const char *setting)
{
	const char *desc = obs_property_description(property);
	long long  val   = obs_data_get_int(view->settings, setting);
	QColor     color = color_from_int(val);

	QColorDialog::ColorDialogOptions options =
		QColorDialog::ShowAlphaChannel;

	/* The native dialog on OSX has all kinds of problems, like closing
	 * other open QDialogs on exit, and
	 * https://bugreports.qt-project.org/browse/QTBUG-34532
	 */
#ifdef __APPLE__
	options |= QColorDialog::DontUseNativeDialog;
#endif

	color = QColorDialog::getColor(color, view, QT_UTF8(desc), options);

	if (!color.isValid())
		return false;

	QLabel *label = static_cast<QLabel*>(widget);
	label->setText(color.name(QColor::HexArgb));
	label->setPalette(QPalette(color));

	obs_data_set_int(view->settings, setting, color_to_int(color));

	return true;
}
Example #21
0
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
    QPainter painter(lineNumberArea);
    QColor q = QColor();
    q.setNamedColor("#323232");
    QColor q2 = QColor();
    q2.setNamedColor("#247EAF");
    painter.fillRect(event->rect(), q);

    QTextBlock block = firstVisibleBlock();
    int blockNumber = block.blockNumber();
    int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
    int bottom = top + (int) blockBoundingRect(block).height();

    while (block.isValid() && top <= event->rect().bottom()) {
        if (block.isVisible() && bottom >= event->rect().top()) {
            QString number = QString::number(blockNumber + 1);
            painter.setPen(q2);
            painter.drawText(0, top, lineNumberArea->width()-5 , fontMetrics().height(),
                             Qt::AlignRight, number);
        }

        block = block.next();
        top = bottom;
        bottom = top + (int) blockBoundingRect(block).height();
        ++blockNumber;
    }
}
Example #22
0
void tst_QColor::achromaticHslHue()
{
    QColor color = Qt::black;

    QColor hsl = color.toHsl();
    QCOMPARE(hsl.hslHue(), -1);
}
Example #23
0
// -----------------------------------------------------------
void QucsSettingsDialog::slotColorTask()
{
    QColor c = QColorDialog::getColor(
                   ColorTask->paletteForegroundColor(), this);
    if(c.isValid())
        ColorTask->setPaletteForegroundColor(c);
}
Example #24
0
void ColorPopup::colorSelected(int id)
{
    if (id == CUSTOM_COLOR){
        hide();
        QWidget *top = NULL;
        if (parent())
            top = static_cast<QWidget*>(parent())->topLevelWidget();
#ifdef USE_KDE
        QColor c = m_color;
        if (KColorDialog::getColor(c, top) != KColorDialog::Accepted){
            close();
            return;
        }
#else
        QColor c = QColorDialog::getColor(m_color, top);
        if (!c.isValid()){
            close();
            return;
        }
#endif
        emit colorChanged(c);
        close();
    }else{
        emit colorChanged(QColor(colors[id]));
        close();
    }
}
Example #25
0
KHCY::KHCY(const QColor &color)
{
    qreal r = gamma(color.redF());
    qreal g = gamma(color.greenF());
    qreal b = gamma(color.blueF());
    a = color.alphaF();

    // luma component
    y = lumag(r, g, b);

    // hue component
    qreal p = qMax(qMax(r, g), b);
    qreal n = qMin(qMin(r, g), b);
    qreal d = 6.0 * (p - n);
    if (n == p) {
        h = 0.0;
    } else if (r == p) {
        h = ((g - b) / d);
    } else if (g == p) {
        h = ((b - r) / d) + (1.0 / 3.0);
    } else {
        h = ((r - g) / d) + (2.0 / 3.0);
    }

    // chroma component
    if (r == g && g == b) {
        c = 0.0;
    } else {
        c = qMax((y - n) / y, (p - y) / (1 - y));
    }
}
Example #26
0
void QgsLabelingGui::updatePreview()
{
  scrollPreview();
  lblFontPreview->setFont( mRefFont );
  QFont previewFont = lblFontPreview->font();
  if ( mFontSizeUnitComboBox->currentIndex() == 1 )
  {
    // TODO: maybe match current map zoom level instead?
    previewFont.setPointSize( 24 );
    groupBox_mPreview->setTitle( tr( "Sample @ 24 pts (using map units)" ) );
  }
  else
  {
    previewFont.setPointSize( mFontSizeSpinBox->value() );
    groupBox_mPreview->setTitle( tr( "Sample" ) );
  }
  lblFontPreview->setFont( previewFont );

  QColor prevColor = btnTextColor->color();
  prevColor.setAlphaF(( 100.0 - ( double )( mFontTranspSpinBox->value() ) ) / 100.0 );
  lblFontPreview->setTextColor( prevColor );
  if ( chkBuffer->isChecked() )
  {
    QColor buffColor = btnBufferColor->color();
    buffColor.setAlphaF(( 100.0 - ( double )( mBufferTranspSpinBox->value() ) ) / 100.0 );
    lblFontPreview->setBuffer( spinBufferSize->value(), buffColor );
  }
  else
  {
    lblFontPreview->setBuffer( 0, Qt::white );
  }
}
Example #27
0
void ColorDelegate::paint(QPainter *painter,
                          const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    QStyledItemDelegate::paint(painter, option, index);

    const QVariant displayData =
            index.model()->data(index, ObjectTypesModel::ColorRole);
    const QColor color = displayData.value<QColor>();
    const QRect rect = option.rect.adjusted(4, 4, -4, -4);

    const QPen linePen(color, 2);
    const QPen shadowPen(Qt::black, 2);

    QColor brushColor = color;
    brushColor.setAlpha(50);
    const QBrush fillBrush(brushColor);

    // Draw the shadow
    painter->setPen(shadowPen);
    painter->setBrush(QBrush());
    painter->drawRect(rect.translated(QPoint(1, 1)));

    painter->setPen(linePen);
    painter->setBrush(fillBrush);
    painter->drawRect(rect);
}
Example #28
0
void SearchResultWidget::currentRowColumnChanged(int currentRow, int /*currentColumn*/, int previousRow, int /*previousColumn*/)
{
    if (currentRow == previousRow) {
        return;
    }
    for (int col = 0; col < 3; ++col) {
        QTableWidgetItem* previousRowItem = searchTable->item(previousRow, col);
        QTableWidgetItem* currentRowItem = searchTable->item(currentRow, col);
        if (previousRowItem && col != 0) {
            QColor color = previousRowItem->data(Qt::UserRole + 15).value<QColor>();
            if (color.isValid()) {
                previousRowItem->setBackgroundColor(color);
            }
        }

        if (currentRowItem) {
            QString text = currentRowItem->text();
            if (col == 2 && !viewedItems.contains(text)) {
                viewedItems << text;
            }
            currentRowItem->setData(Qt::UserRole + 15, currentRowItem->backgroundColor());
            currentRowItem->setBackgroundColor(QColor(Qt::green).lighter(170));
        }
    }
}
Example #29
0
Window::Window()
{
    QGridLayout *mainLayout = new QGridLayout;

    for (int i = 0; i < NumRows; ++i) {
        for (int j = 0; j < NumColumns; ++j) {
            QColor clearColor;
            clearColor.setHsv(((i * NumColumns) + j) * 255
                              / (NumRows * NumColumns - 1),
                              255, 63);

            glWidgets[i][j] = new GLWidget(0, 0);
            glWidgets[i][j]->setClearColor(clearColor);
            glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
            mainLayout->addWidget(glWidgets[i][j], i, j);

            connect(glWidgets[i][j], SIGNAL(clicked()),
                    this, SLOT(setCurrentGlWidget()));
        }
    }
    setLayout(mainLayout);

    currentGlWidget = glWidgets[0][0];

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
    timer->start(20);

    setWindowTitle(tr("Textures"));
}
Example #30
0
void QMdPushButton::paintEvent(QPaintEvent *event){
    QPushButton::paintEvent(event);
    if (!showbusyspin&&!spin)
        return;
    int width = qMin(this->width(), this->height());
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);

    int outerRadius = (width-1)/3;
    int innerRadius = (width-1)/3/3;

    int capsuleHeight = outerRadius - innerRadius;
    int capsuleWidth  = (width > 32 ) ? capsuleHeight /4 : capsuleHeight /3;
    int capsuleRadius = capsuleWidth/2;

    for (int i=0; i<12; i++)
    {
        QColor color = busyspincolor;
        color.setAlphaF(1.0f - (i/12.0f));
        p.setPen(Qt::NoPen);
        p.setBrush(color);
        p.save();
        p.translate(rect().center());
        p.rotate(angle - i*30.0f);
        p.drawRoundedRect(-capsuleWidth*0.5, -(innerRadius+capsuleHeight), capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius);
        p.restore();
    }

}