コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: echown/Sliders
void MainWindow::update(){
    // we draw by using a QImage - turn it into a Pixmap, then put it on a label
    QImage img(200, 200, QImage::Format_RGB32);
    bool display;
    /* Our color wheel has a radius of 100.  Loop through the rectangle
      looking for pixels within that radius. For good pixels we calculate
      the H value based on the angle from the origin.  The S value is
      set according to the distance / radius, and the V is fixed (but
      settable by a slider).
     */
    for (int i = 0; i < 200; i++)
    {
        for (int j = 0; j < 200; j++)
        {
            float dist = sqrt((i - 100) * (i - 100) + (j - 100) * (j - 100));
            if (dist < 100.0)
            {
                display = true;
                float s = dist / 100.0f;
                float h = atan2(i - 100, j - 100) / (2.0f * 3.14156);
                if (h < 0)
                {
                    h = 1.0f + h;
                }
                // Since H is an angle the math is modulo.
                if (hMax > hMin)
                {
                    if (hMin > h || hMax < h)
                    {
                        display = false;
                    }
                } else if (hMin > h && hMax < h )
                {
                    display = false;
                }
                if (s < sMin || s > sMax)
                {
                    display = false;
                }
                QColor c;
                if (display)
                {
                    c.setHsvF(h, s, zValue);
                } else{
                    c.setHsvF(0.0, 0.0, 1.0f);
                }
                img.setPixel(i, j, c.rgb());
            }
        }
    }
    QPixmap pix;
    pix.convertFromImage(img);
    ui->colwheel->setPixmap(pix);
    ui->colwheel->repaint();

}
コード例 #2
0
ファイル: palette.cpp プロジェクト: Dakror/voxie
void ColorSpace::paintEvent(QPaintEvent * event)
{
    int w = width();
    int h = height();

    if (!pix || pix->height() != h || pix->width() != w) {
        delete pix;
        QImage img(w, h, QImage::Format_RGB32);
        unsigned int * pixel = (unsigned int*)img.scanLine(0);
        for (int y = 0; y < h; y++) {
            const unsigned int * end = pixel + w;
            int x = 0;
            while (pixel < end) {
                QColor c;
                float sat = float(x) / float(w);
                float val = 1.0f - float(y) / float(h);
                c.setHsvF(hue, sat, val);
                *pixel = c.rgb();
                pixel++;
                x++;
            }
        }
        pix = new QPixmap(QPixmap::fromImage(img));
    }

    QPainter p(this);
    p.drawPixmap(0, 0, *pix);

    int p_x = int(sat * w);
    int p_y = int((1.0f - val) * h);
    draw_pointer(p_x, p_y, p);
}
コード例 #3
0
QColor ImageUtilities::computeAverageColor(const QImage& image)
{
    long int rtotal = 0, gtotal = 0, btotal = 0;
    float total = 0.0f;
    // always sample 100x100 pixels
    int samplePoints = 100;
    int stepX = std::max(image.width() / samplePoints, 1);
    int stepY = std::max(image.height() / samplePoints, 1);

    for (int y = 0; y < image.height(); y += stepY) {
        for (int x = 0; x < image.width(); x += stepX) {
            QColor color = QColor::fromRgba(image.pixel(x, y));

            float saturation = (qMax (color.red(), qMax (color.green(), color.blue())) -
                                qMin (color.red(), qMin (color.green(), color.blue()))) / 255.0f;
            float relevance = .1 + .9 * (color.alpha() / 255.0f) * saturation;

            rtotal += (unsigned char) (color.red() * relevance);
            gtotal += (unsigned char) (color.green() * relevance);
            btotal += (unsigned char) (color.blue() * relevance);

            total += relevance * 255;
        }
    }

    QColor hsv = QColor::fromRgbF(rtotal / total, gtotal / total, btotal / total).toHsv();

    /* Background color is the base color with 0.90f HSV value */
    hsv.setHsvF(hsv.hueF(),
                (hsv.saturationF() > .15f) ? 0.65f : hsv.saturationF(),
                0.90f);
    return hsv;
}
コード例 #4
0
ファイル: map.cpp プロジェクト: jgorges/mindandiron
void MapOverview::ReceiveObstacleMap(std::vector<Eigen::Vector2d> points)
{
    if(mCore != nullptr)
        delete mCore;

    mCore = new QGraphicsItemGroup();
    mCore->setPos(mRobotInstance->pos());
    mCore->setRotation(mRobotInstance->rotation());

    int id = 0;

    for(const auto& imagePt : points)
    {
        QColor color;
        color.setHsvF( (static_cast<double>(id)/points.size()) , 1.0, 1.0);

        auto rect = new QGraphicsRectItem(imagePt.x(), imagePt.y(), 5.0 / 512.0, 5.0 / 512.0);
        rect->setPen(QPen(color, 0));
        mCore->addToGroup(rect);

        id++;
    }

    //std::cout << "Receiving obstacle list with " << id << " items.\n";

    //mCore->setPos(mRobotInstance->pos());
    //mCore->setRotation(mRobotInstance->rotation());

    scene.addItem(mCore);
}
コード例 #5
0
ファイル: minacurve.cpp プロジェクト: da1l6/minotor
MinaCurve::MinaCurve(QObject *object) :
    MinoAnimation(object)
{
    _generatorCurve = new MinoPropertyEasingCurve(this, true);
    _generatorCurve->setObjectName("curve");
    _generatorCurve->setLabel("Curve");

    _generatorAccel = new MinoPropertyEasingCurve(this);
    _generatorAccel->setObjectName("acceleration");
    _generatorAccel->setLabel("Accel.");
    // Please note that curve have not been tested with all parameters:
    // Theses following lines are here to show how to add curve type to selector
    _generatorAccel->addEasingCurveType(QEasingCurve::Linear);
    _generatorAccel->addEasingCurveType(QEasingCurve::OutInBack);
    _generatorAccel->addEasingCurveType(QEasingCurve::InOutBounce);
    _generatorAccel->addEasingCurveType(QEasingCurve::InOutQuart);
    _generatorAccel->setEasingCurveType(QEasingCurve::Linear);

    QColor color;
    color.setHsvF(0.4, 1.0, 1.0);
    for (int i=0;i<_boundingRect.width();i++)
    {
        _items.append(_scene->addLine(i,_boundingRect.height(),i,5,QPen(color)));
        _itemGroup.addToGroup(_items[i]);
    }

    QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(this);
    blur->setBlurRadius(1.1);
    _itemGroup.setGraphicsEffect(blur);
    _itemGroup.setVisible(false);
}
コード例 #6
0
// run - paint the QImage
void timeConsumingThread::run()
{
   int i_ctr = 60;
   int j_ctr = 60;
   QImage myQImage(i_ctr, j_ctr, QImage::Format_RGB32);
   QPainter painter(&myQImage);
   for (int nMainCounter = 0; nMainCounter < 1000; nMainCounter++)
   {
    for (int i=0; i<i_ctr; i++)
    {
      for (int j=0; j<j_ctr; j++)
      {
         double hue = (double)(i + j + i*j)/361200.0;
         QColor myColor;
         myColor.setHsvF(hue, 1.0, 1.0, 1.0);
         painter.setPen(myColor);
         painter.drawPoint(i, j);
      }
    }   
    // emit theImage(myQImage);
    int x = GetRNDValue(0, 600);
    int y = GetRNDValue(0, 600);
    emit theImage(QRect(x, y, i_ctr, j_ctr), myQImage);
   }
}
コード例 #7
0
ファイル: dnotificationwidget.cpp プロジェクト: KDE/digikam
static QColor darkShade(QColor c)
{
    qreal contrast = 0.7; // taken from kcolorscheme for the dark shade
    qreal darkAmount;

    if (c.lightnessF() < 0.006)
    {
        /* too dark */
        darkAmount = 0.02 + 0.40 * contrast;
    }
    else if (c.lightnessF() > 0.93)
    {
        /* too bright */
        darkAmount = -0.06 - 0.60 * contrast;
    }
    else
    {
        darkAmount = (-c.lightnessF()) * (0.55 + contrast * 0.35);
    }

    qreal v = c.lightnessF() + darkAmount;
    v       = v > 0.0 ? (v < 1.0 ? v : 1.0) : 0.0;
    c.setHsvF(c.hslHueF(), c.hslSaturationF(), v);
    return c;
}
コード例 #8
0
ファイル: Gradient.C プロジェクト: Tyf0n/IQmol
QColor Function::interpolateHSV(double delta, QColor const& col1, QColor const& col2) const
{
   if (delta <= 0.0) return col1;
   if (delta >= 1.0) return col2;

   double h1, h2, s1, s2, v1, v2;
   col1.getHsvF(&h1, &s1, &v1);
   col2.getHsvF(&h2, &s2, &v2);

   if (h1 < 0.0) h1 = h2;
   if (h2 < 0.0) h2 = h1;
   if (h1 < 0.0 && h2 < 0.0) { h1 = 0.0; h2 = 0.0; }

   s1 += delta*(s2-s1);
   v1 += delta*(v2-v1);

   // For hue we need to work out which direction we are going on the wheel.
   double dh(h2-h1);
   if (dh > 0.5) {
      dh -= 1.0;
   }else if(dh < -0.5) {
      dh += 1.0;
   }


   h1 += delta*dh;
   if (h1 > 1.0) h1 -= 1.0;
   if (h1 < 0.0) h1 += 1.0;

   QColor color;
   color.setHsvF(h1, s1, v1);
   return color;
}
コード例 #9
0
ファイル: palette.cpp プロジェクト: Dakror/voxie
void ColorSlider::paintEvent(QPaintEvent * event)
{
    int w = width();
    int h = height();

    if (!pix || pix->width() != w) {
        delete pix;
        QImage img(w, 1, QImage::Format_RGB32);
        unsigned int * pixel = (unsigned int*)img.scanLine(0);
        const unsigned int * end = pixel + w;
        int x = 0;
        while (pixel < end) {
            QColor c;
            float hue = float(x) / float(w);
            c.setHsvF(hue, 1.0f, 1.0f);
            *pixel = c.rgb();
            pixel++;
            x++;
        }
        pix = new QPixmap(QPixmap::fromImage(img));
    }

    QPainter p(this);
    p.drawPixmap(0, 0, w, h, *pix);

    int p_x = int(value * w);
    draw_pointer(p_x, h / 2, p);
}
コード例 #10
0
ファイル: classitem.cpp プロジェクト: fvacek/quickbox
QColor ClassItem::color() const
{
	auto dt = data();
	int hue = dt.firstCode() % 100;
	QColor c;
	c.setHsvF(hue / 100., 1, 1);
	return c;
}
コード例 #11
0
void QtGradientStopsControllerPrivate::slotChangeAlpha(int color)
{
    QColor c = m_ui->alphaColorLine->color();
    if (m_ui->hsvRadioButton->isChecked())
        c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), (qreal)color / 255);
    else
        c.setAlpha(color);
    slotChangeAlpha(c);
}
コード例 #12
0
void QtGradientStopsControllerPrivate::slotChangeHue(int color)
{
    QColor c = m_ui->hueColorLine->color();
    if (m_ui->hsvRadioButton->isChecked())
        c.setHsvF((qreal)color / 360.0, c.saturationF(), c.valueF(), c.alphaF());
    else
        c.setRed(color);
    slotChangeHue(c);
}
コード例 #13
0
ファイル: worker.cpp プロジェクト: MakSim345/QT-Dev
void Worker::run()
{
    // Note: this is never called directly. It is called by Qt once the 
    // thread environment has been set up        
    // random.seed();
    int n = stars;
    int m_width = m_size.width();
    int m_height= m_size.height();
        
    do {
        QImage image = QImage(outerRadius * 2, outerRadius * 2, QImage::Format_ARGB32);
        image.fill(qRgba(255, 255, 256, 0));
            
        int x = GetRNDValue(0, m_width);
        int y = GetRNDValue(0, m_height);
        
        int angle = GetRNDValue(0, 360);
        int red = GetRNDValue(0, 256);
        
        int green = GetRNDValue(0, 256);
        int blue = GetRNDValue(0, 256);
        int alpha = GetRNDValue(0, 256);
        /*
        QPainter *painter = new QPainter();
        painter->begin(&image);
        painter->setRenderHint(QPainter::Antialiasing);
        painter->setPen(Qt::NoPen);
        painter->setBrush(QColor(red, green, blue, alpha));
        painter->translate(outerRadius, outerRadius);
        painter->rotate(angle);
        painter->drawPath(path);
        painter->end();
        */       

        //-----------
       QImage myQImage(60, 60, QImage::Format_RGB32);
       QPainter painter1(&myQImage);
        for (int i=0; i<60; i++)
        {
            for (int j=0; j<60; j++)
            {
                double hue = (double)(i + j + i*j)/361200.0;
                QColor myColor;
                myColor.setHsvF(hue, 1.0, 1.0, 1.0);
                painter1.setPen(myColor);
                painter1.drawPoint(i, j);
            }
        }
        //-----------

        emit output (QRect(x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2), myQImage);
        
        sleep(0.01);
        n --;
        qDebug("Iteration number %d\n", n);
    } while ((!exiting) && (n > 0));
}
コード例 #14
0
void Plotter::neighbourhoodLegendEntry(int id, QString name)
{
    neighbourhoodPlotter->addGraph(neighbourhoodPlotter->xAxis, neighbourhoodPlotter->yAxis);
    QColor color;
    double hue = id / 10.0;
    color.setHsvF(hue, 1, 1);
    neighbourhoodPlotter->graph(id)->setPen(QPen(color));
    neighbourhoodPlotter->graph(id)->setName(name);
}
コード例 #15
0
void Line::paint(QPainter *qp) {
	QColor qc;
	double r,E;
	r=findR(*_iP_lne[0],*_iP_lne[1]);
	E=(_length-r)*fabs(_length-r)/1000;//-1,+1
	if(E>1) E=1;
	else if(E<-1) E=-1;
	qc.setHsvF(0.5 + 0.4*E,fabs(E),1.0);
	qp->setPen(QPen(qc));
	qp->drawLine((*_iP_lne[0])->getX(0),(*_iP_lne[0])->getX(1),(*_iP_lne[1])->getX(0),(*_iP_lne[1])->getX(1));
}
コード例 #16
0
ファイル: prefdialog.cpp プロジェクト: vakkov/ColorCode
QColor PrefDialog::Desaturate(QColor c)
{
    qreal h;
    qreal s;
    qreal v;
    qreal a;
    c.getHsvF(&h, &s, &v, &a);

    v = qMin((0.8 + v * 0.2), 1.0);
    c.setHsvF(h, (s * 0.2), v, 1.0);
    return c;
}
コード例 #17
0
bool BitDisplayFilter::drawCTU  (FilterContext *pcContext, QPainter *pcPainter,
                                ComCU *pcCTU, double dScale, QRect *pcScaledArea)
{
    int iClip = VALUE_CLIP(0,240,pcCTU->getBitCount());

    QColor cFill;
    double dHue = (240-iClip)/360.0;
    cFill.setHsvF(dHue, 1.0, 1.0, 0.6);
    pcPainter->setBrush(QBrush(cFill));
    pcPainter->setPen(Qt::NoPen);
    pcPainter->drawRect(*pcScaledArea);
    return true;
}
コード例 #18
0
void BasicOpenGLView::paintGL()
{
    // given our timer, this should be 20
    int elapsed = mAnimationTimer.elapsed();

    float secondsElapsed = elapsed * 0.001f;

	// JB: removed light position/colour change
    mLightPos.x = sin(secondsElapsed) * 20.0f;
    mLightPos.z = cos(secondsElapsed) * 20.0f;
    mLightPos.y = cos(secondsElapsed * 0.5f) * 20.0f;

    QColor curColor;
    curColor.setHsvF(fabs(cos(secondsElapsed / 20.0f)), 1.0, 1.0);

    mLightCol.x = curColor.redF();
    mLightCol.y = curColor.greenF();
    mLightCol.z = curColor.blueF();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if(mRenderOrtho)
    {
        float mAspectRatio = ((float)this->width()) / this->height();
        mProjectionMatrix.ortho(-mDistance,
                                mDistance,
                                mDistance * mAspectRatio,
                                -mDistance * mAspectRatio,
                                -0.1,
                                -500.0);
    }

    std::map<std::string, Geometry *>::iterator it = mGeometries.begin();

    while (it != mGeometries.end())
    {
        it->second->createModelMatrix(mUsePostMultiply);
        it->second->draw(mProjectionMatrix,
                         mViewMatrix,
                         mUsePostMultiply,
                         mLightPos,
                         mLightCol,
                         mTextureHandle,
                         mBumpTextureHandle,
                         mAlphaTextureHandle,
                         mProgram);
        ++it;
    }

}
コード例 #19
0
bool BitDisplayFilter::drawCTU  (FilterContext *pcContext, QPainter *pcPainter,
                                ComCU *pcCTU, double dScale, QRect *pcScaledArea)
{
    ///TODO fix m_iLCUAvgBit should be used here
    int iClip = VALUE_CLIP(240,359,pcCTU->getBitCount()/(m_iLCUAvgBit*5.0)*(359-240)+240);

    QColor cFill;
    double dHue = iClip/360.0;
    cFill.setHsvF(dHue, 1.0, 1.0, 0.6);
    pcPainter->setBrush(QBrush(cFill));
    pcPainter->setPen(Qt::NoPen);
    pcPainter->drawRect(*pcScaledArea);
    return true;
}
コード例 #20
0
void KnotRendererBatch::themeChangedHandler()
{
    /*
     * We exlude colors that are too dark (but light colors are probably OK)
     * lighter() multiplies a factor to the value, so it's not good enough to deal with potential pure black
     * Force the value to be at least 0.2 seems to make more sense
     */
    
    QColor color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::ViewBackgroundColor);
    if (color.valueF() < 0.2)
        color.setHsvF(color.hueF(), color.saturationF(), 0.2);
    
    emit colorRequest(color);
    geometryChangedHandler();
}
コード例 #21
0
ファイル: paintings.cpp プロジェクト: tiltit/lightweaver
QVector<QColor*>* MainWindow::computeGoldenRatioColors(double startHue,double saturation, double value, int size) 
{
	int i;
	double h = startHue;
	QVector<QColor*> *v = new QVector<QColor*>;

	for(i=0;i!=size;++i) {
		QColor *color = new QColor(255,255,255);
		h = fmod( startHue + (0.618033988749895 * i), 1.0);
		color->setHsvF(h, saturation, value);
		v->push_back(color);
	}

	return v;
}
コード例 #22
0
void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color)
{
    QtGradientStop *stop = m_model->currentStop();
    if (!stop)
        return;
    m_model->changeStop(stop, color);
    QList<QtGradientStop *> stops = m_model->selectedStops();
    QListIterator<QtGradientStop *> itStop(stops);
    while (itStop.hasNext()) {
        QtGradientStop *s = itStop.next();
        if (s != stop) {
            QColor c = s->color();
            if (m_ui->hsvRadioButton->isChecked()) {
                c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), color.alphaF());
                int hue = c.hue();
                if (hue == 360 || hue == -1)
                    c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
            } else {
                c.setRgbF(c.redF(), c.greenF(), c.blueF(), color.alphaF());
            }
            m_model->changeStop(s, c);
        }
    }
}
コード例 #23
0
			void ChatTab::GenerateColors ()
			{
				const qreal lower = 50. / 360.;
				const qreal higher = 180. / 360.;
				const qreal delta = 25. / 360.;

				const qreal alpha = BgColor_.alphaF ();

				qreal s = BgColor_.saturationF ();
				s += 15 * (1 - s) / 16;
				qreal v = BgColor_.valueF ();
				v = 0.95 - v / 2;

				qreal h = BgColor_.hueF ();

				QColor color;
				for (qreal d = lower; d <= higher; d += delta)
				{
					color.setHsvF (Fix (h + d), s, v, alpha);
					NickColors_ << color;
					color.setHsvF (Fix (h - d), s, v, alpha);
					NickColors_ << color;
				}
			}
コード例 #24
0
ファイル: Qt_colors.cpp プロジェクト: erdoukki/radium
void GFX_SetBrightness(struct Tracker_Windows *tvisual, float how_much){
  EditorWidget *editorwidget=(EditorWidget *)tvisual->os_visual.widget;
  if(is_starting_up)
    return;
  return;
#if 0
  float threshold = QColor(SETTINGS_read_string(talloc_format("color%d",15),"#d0d5d0")).valueF();
  
  for(int i=0;i<15;i++){
    QColor color = QColor(SETTINGS_read_string(talloc_format("color%d",i),"#d0d5d0"));
      
    //QColor color = editorwidget->colors[i];
    float value = color.valueF();
    if (value > threshold)
      color = color.lighter(scale(how_much, 0, 1, 0, 200));
    else
      color = color.darker(scale(how_much, 0, 1, 0, 200));

    if (i!=11)
      setColor((enum ColorNums)i, color.rgb());
    printf("value for %d: %f\n",i,value);
    //color.setLightntess(lightness
  }
#else
  
  how_much = scale(how_much,0,1,-1,1);

  for(int i=0;i<16;i++){
    QColor color = QColor(SETTINGS_read_string(talloc_format("color%d",i),"#d0d5d0"));

    qreal h,s,v,a;
    color.getHsvF(&h,&s,&v,&a);

    float value = R_BOUNDARIES(0,v+how_much,1);
    color.setHsvF(h, s, value, a);
    
    //QColor color = editorwidget->colors[i];
    setColor((enum ColorNums)i, color.rgb());
    
    printf("value for %d: %f. s: %f, how_much: %f\n",i,value,s,how_much);
    //color.setLightntess(lightness
  }
#endif
  
  updateAll(editorwidget);
  tvisual->must_redraw = true;
}
コード例 #25
0
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel):
        QWidget(),
    m_declarativeView(new QDeclarativeView(this)),
    m_statesEditorView(statesEditorView),
    m_imageProvider(0)
{
    m_imageProvider = new Internal::StatesEditorImageProvider;
    m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
    m_declarativeView->engine()->addImageProvider(
            QLatin1String("qmldesigner_stateseditor"), m_imageProvider);

    m_declarativeView->setAcceptDrops(false);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(m_declarativeView.data());

    m_declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);

    m_declarativeView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel);
    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_declarativeView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    // Work around ASSERT in the internal QGraphicsScene that happens when
    // the scene is created + items set dirty in one event loop run (BAUHAUS-459)
    //QApplication::processEvents();

    m_declarativeView->setSource(QUrl("qrc:/stateseditor/stateslist.qml"));

    if (!m_declarativeView->rootObject())
        throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__);

    m_declarativeView->setFocusPolicy(Qt::ClickFocus);
    QApplication::sendEvent(m_declarativeView->scene(), new QEvent(QEvent::WindowActivate));

    connect(m_declarativeView->rootObject(), SIGNAL(currentStateInternalIdChanged()), statesEditorView, SLOT(synchonizeCurrentStateFromWidget()));
    connect(m_declarativeView->rootObject(), SIGNAL(createNewState()), statesEditorView, SLOT(createNewState()));
    connect(m_declarativeView->rootObject(), SIGNAL(deleteState(int)), statesEditorView, SLOT(removeState(int)));

    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));

    setWindowTitle(tr("States", "Title of Editor widget"));
}
コード例 #26
0
ファイル: nickcolorer.cpp プロジェクト: viking/smirch-qt
QColor NickColorer::colorFor(const IrcSender &sender)
{
  QSettings settings;
  QColor result;

  settings.beginGroup("nickcolors");
  if (settings.contains(sender.name())) {
    result.setNamedColor(settings.value(sender.name()).toString());
  }
  else {
    qreal hue = (qreal) qrand() / (qreal) RAND_MAX;
    hue += GOLDEN_RATIO_CONJ;
    hue = hue - (qint8) hue;
    result.setHsvF(hue, 0.60, 0.95);
    settings.setValue(sender.name(), result.name());
  }
  return result;
}
コード例 #27
0
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel)
    : QWidget(),
      m_quickView(new QQuickView()),
      m_statesEditorView(statesEditorView),
      m_imageProvider(0),
      m_qmlSourceUpdateShortcut(0)
{
    m_imageProvider = new Internal::StatesEditorImageProvider;
    m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());

    m_quickView->engine()->addImageProvider(QLatin1String("qmldesigner_stateseditor"), m_imageProvider);
    m_quickView->engine()->addImportPath(statesEditorResourcesPath());

    //m_quickView->setAcceptDrops(false);

    m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F4), this);
    connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));

    QVBoxLayout *layout = new QVBoxLayout(this);
    setMinimumHeight(160);
    layout->setMargin(0);
    layout->setSpacing(0);
    QWidget *container = createWindowContainer(m_quickView.data());
    layout->addWidget(container);

    m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);

    m_quickView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel);
    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_quickView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    m_quickView->rootContext()->setContextProperty("canAddNewStates", true);

    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));

    setWindowTitle(tr("States", "Title of Editor widget"));

    // init the first load of the QML UI elements
    reloadQmlSource();
}
コード例 #28
0
ファイル: colourscale.cpp プロジェクト: trisyoungs/uchroma
// Get colour for value v
QColor ColourScaleDelta::colour(double value, bool useHSV) const
{
    // Clamp 'v' to range 0.0 - 1.0 to span range of delta
    double clampv = (value - start_) / delta_;
    if (clampv < 0.0) clampv = 0.0;
    else if (clampv > 1.0) clampv = 1.0;
    QColor col;
    if (useHSV)
    {
        col.setHsvF(startColour_.hue() + deltaColourF_[0] * clampv, startColour_.saturationF() + deltaColourF_[1] * clampv, startColour_.valueF() + deltaColourF_[2] * clampv);
    }
    else
    {
        col.setRedF(startColour_.redF() + deltaColourF_[0] * clampv);
        col.setGreenF(startColour_.greenF() + deltaColourF_[1] * clampv);
        col.setBlueF(startColour_.blueF() + deltaColourF_[2]* clampv);
    }
    col.setAlphaF(startColour_.alphaF() + deltaColourF_[3] * clampv);
    return col;
}
コード例 #29
0
void medAlgorithmPaintToolbox::generateLabelColorMap(unsigned int numLabels)
{
    medImageMaskAnnotationData::ColorMapType colorMap;
    typedef medImageMaskAnnotationData::ColorMapType::value_type PairType;

    QColor tmpColor;
    double realHueValue = 0;
    double factor = (1.0 + sqrt(5.0)) / 2.0;
    for (unsigned int i = 0;i < numLabels;++i)
    {
        tmpColor.setHsvF(realHueValue,1.0,1.0);
        colorMap.push_back(PairType(i+1 , tmpColor));

        realHueValue += 1.0 / factor;
        if (realHueValue > 1.0)
            realHueValue -= 1.0;
    }

    m_labelColorMap = colorMap;
}
コード例 #30
0
void drawSelectionBackground(QPainter *painter, const QStyleOption &option)
{
    QWidget colorReference;

    painter->save();
    QLinearGradient gradient;
    QColor highlightColor = colorReference.palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    gradient.setColorAt(0, highlightColor.lighter(130));
    gradient.setColorAt(1, highlightColor.darker(130));
    gradient.setStart(option.rect.topLeft());
    gradient.setFinalStop(option.rect.bottomLeft());
    painter->fillRect(option.rect, gradient);
    painter->setPen(highlightColor.lighter());
    painter->drawLine(option.rect.topLeft(),option.rect.topRight());
    painter->setPen(highlightColor.darker());
    painter->drawLine(option.rect.bottomLeft(),option.rect.bottomRight());
    painter->restore();
}