//TODO: Let GL generate the texture using an FBO void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const { int pos = 0; QGradientStops s = gradient.stops(); QVector<uint> colors(s.size()); for (int i = 0; i < s.size(); ++i) colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian) bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation); uint alpha = qRound(opacity * 256); uint current_color = ARGB_COMBINE_ALPHA(colors[0], alpha); qreal incr = 1.0 / qreal(size); qreal fpos = 1.5 * incr; colorTable[pos++] = ARGB2RGBA(qPremultiply(current_color)); while (fpos <= s.first().first) { colorTable[pos] = colorTable[pos - 1]; pos++; fpos += incr; } if (colorInterpolation) current_color = qPremultiply(current_color); for (int i = 0; i < s.size() - 1; ++i) { qreal delta = 1/(s[i+1].first - s[i].first); uint next_color = ARGB_COMBINE_ALPHA(colors[i+1], alpha); if (colorInterpolation) next_color = qPremultiply(next_color); while (fpos < s[i+1].first && pos < size) { int dist = int(256 * ((fpos - s[i].first) * delta)); int idist = 256 - dist; if (colorInterpolation) colorTable[pos] = ARGB2RGBA(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)); else colorTable[pos] = ARGB2RGBA(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist))); ++pos; fpos += incr; } current_color = next_color; } Q_ASSERT(s.size() > 0); uint last_color = ARGB2RGBA(qPremultiply(ARGB_COMBINE_ALPHA(colors[s.size() - 1], alpha))); for (;pos < size; ++pos) colorTable[pos] = last_color; // Make sure the last color stop is represented at the end of the table colorTable[size-1] = last_color; }
GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity) { quint64 hash_val = 0; QGradientStops stops = gradient.stops(); for (int i = 0; i < stops.size() && i <= 2; i++) hash_val += stops[i].second.rgba(); const QMutexLocker lock(&m_mutex); QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(hash_val); if (it == cache.constEnd()) return addCacheElement(hash_val, gradient, opacity); else { do { const CacheInfo &cache_info = it.value(); if (cache_info.stops == stops && cache_info.opacity == opacity && cache_info.interpolationMode == gradient.interpolationMode()) { return cache_info.texId; } ++it; } while (it != cache.constEnd() && it.key() == hash_val); // an exact match for these stops and opacity was not found, create new cache return addCacheElement(hash_val, gradient, opacity); } }
void TransferFunctionEditor::setColorMapStops( const QGradientStops& stops ) { QPolygonF redPoints, greenPoints, bluePoints, alphaPoints; const double redCMHt = _redWidget->height(); const double greenCMHt = _greenWidget->height(); const double blueCMHt = _blueWidget->height(); const double alphaCMHt = _alphaWidget->height(); for( int32_t i = 0; i < stops.size(); ++i ) { double position = stops.at( i ).first; QRgb color = stops.at( i ).second.rgba(); redPoints << QPointF( position * _redWidget->width(), redCMHt - qRed(color) * redCMHt / 255 ); greenPoints << QPointF( position * _greenWidget->width(), greenCMHt - qGreen(color) * greenCMHt / 255 ); bluePoints << QPointF( position * _blueWidget->width(), blueCMHt - qBlue(color) * blueCMHt / 255 ); alphaPoints << QPointF( position * _alphaWidget->width(), alphaCMHt - qAlpha(color) * alphaCMHt / 255 ); } _redWidget->setPoints( redPoints ); _greenWidget->setPoints( greenPoints ); _blueWidget->setPoints( bluePoints ); _alphaWidget->setPoints( alphaPoints ); }
MythImage* MythPainter::GetImageFromRect(const QRect &area, int radius, int ellipse, const QBrush &fillBrush, const QPen &linePen) { if (area.width() <= 0 || area.height() <= 0) return NULL; uint64_t hash1 = ((0xfff & (uint64_t)area.width())) + ((0xfff & (uint64_t)area.height()) << 12) + ((0xff & (uint64_t)fillBrush.style()) << 24) + ((0xff & (uint64_t)linePen.width()) << 32) + ((0xff & (uint64_t)radius) << 40) + ((0xff & (uint64_t)linePen.style()) << 48) + ((0xff & (uint64_t)ellipse) << 56); uint64_t hash2 = ((0xffffffff & (uint64_t)linePen.color().rgba())) + ((0xffffffff & (uint64_t)fillBrush.color().rgba()) << 32); QString incoming("R"); if (fillBrush.style() == Qt::LinearGradientPattern && fillBrush.gradient()) { const QLinearGradient *gradient = static_cast<const QLinearGradient*>(fillBrush.gradient()); if (gradient) { incoming = QString::number( ((0xfff & (uint64_t)gradient->start().x())) + ((0xfff & (uint64_t)gradient->start().y()) << 12) + ((0xfff & (uint64_t)gradient->finalStop().x()) << 24) + ((0xfff & (uint64_t)gradient->finalStop().y()) << 36)); QGradientStops stops = gradient->stops(); for (int i = 0; i < stops.size(); i++) { incoming += QString::number( ((0xfff * (uint64_t)(stops[i].first * 100))) + ((uint64_t)stops[i].second.rgba() << 12)); } } } incoming += QString::number(hash1) + QString::number(hash2); if (m_StringToImageMap.contains(incoming)) { m_StringExpireList.remove(incoming); m_StringExpireList.push_back(incoming); return m_StringToImageMap[incoming]; } MythImage *im = GetFormatImage(); if (im) { DrawRectPriv(im, area, radius, ellipse, fillBrush, linePen); m_SoftwareCacheSize += (im->bytesPerLine() * im->height()); m_StringToImageMap[incoming] = im; m_StringExpireList.push_back(incoming); ExpireImages(m_MaxSoftwareCacheSize); } return im; }
void saveGradientStops(QTextStream &str, const QGradient *g) { QGradientStops stops = g->stops(); if (g->interpolationMode() == QGradient::ColorInterpolation) { bool constantAlpha = true; int alpha = stops.at(0).second.alpha(); for (int i = 1; i < stops.size(); ++i) constantAlpha &= (stops.at(i).second.alpha() == alpha); if (!constantAlpha) { const qreal spacing = qreal(0.02); QGradientStops newStops; QRgb fromColor = PREMUL(stops.at(0).second.rgba()); QRgb toColor; for (int i = 0; i + 1 < stops.size(); ++i) { int parts = qCeil((stops.at(i + 1).first - stops.at(i).first) / spacing); newStops.append(stops.at(i)); toColor = PREMUL(stops.at(i + 1).second.rgba()); if (parts > 1) { qreal step = (stops.at(i + 1).first - stops.at(i).first) / parts; for (int j = 1; j < parts; ++j) { QRgb color = INV_PREMUL(INTERPOLATE_PIXEL_256(fromColor, 256 - 256 * j / parts, toColor, 256 * j / parts)); newStops.append(QGradientStop(stops.at(i).first + j * step, QColor::fromRgba(color))); } } fromColor = toColor; } newStops.append(stops.back()); stops = newStops; } } foreach(QGradientStop stop, stops) { QString color = QString::fromLatin1("#%1%2%3") .arg(stop.second.red(), 2, 16, QLatin1Char('0')) .arg(stop.second.green(), 2, 16, QLatin1Char('0')) .arg(stop.second.blue(), 2, 16, QLatin1Char('0')); str << QLatin1String(" <stop offset=\"")<< stop.first << QLatin1String("\" ") << QLatin1String("stop-color=\"") << color << QLatin1String("\" ") << QLatin1String("stop-opacity=\"") << stop.second.alphaF() <<QLatin1String("\" />\n"); }
bool GradientStopEditor::setStops( const QGradientStops &s ) { int countStops = s.size(); if( countStops < 2 ) return false; values.clear(); positions.clear(); switch( stopChannel ) { case redChannel: for( int i = 0; i < countStops; i++ ) { positions << s[ i ].first; values << s[ i ].second.red(); } break; case greenChannel: for( int i = 0; i < countStops; i++ ) { positions << s[ i ].first; values << s[ i ].second.green(); } break; case blueChannel: for( int i = 0; i < countStops; i++ ) { positions << s[ i ].first; values << s[ i ].second.blue(); } break; case composite: for( int i = 0; i < countStops; i++ ) { positions << s[ i ].first; values << s[ i ].second.alpha(); } break; } if( positions[ 0 ] != 0.0 ) positions[ 0 ] = 0.0; if( positions[ countStops - 1 ] != 1.0 ) positions[ countStops - 1 ] = 1.0; generateBackground( true ); update(); return true; }
QGradientStops QQuickGradient::gradientStops() const { QGradientStops stops; for (int i = 0; i < m_stops.size(); ++i){ int j = 0; while (j < stops.size() && stops.at(j).first < m_stops[i]->position()) j++; stops.insert(j, QGradientStop(m_stops.at(i)->position(), m_stops.at(i)->color())); } return stops; }
void GradientSliderWidget::SetGradientStops(QGradientStops newStops) { QList<uint> keys = sliders.keys(); for (int i=0; i<keys.size(); ++i) { RemoveSlider(keys[i]); } if (newStops.size() >= 2) { for (int i=0; i<newStops.size(); ++i) { unsigned int newSlider = AddSlider(); SetSliderValue(newSlider, minValue + (1.0-newStops[i].first) * (maxValue-minValue)); SetSliderColor(newSlider, newStops[i].second); } } else { CreateDefaultSliders(); } UpdateGradientStops(); }
void ColorMapWidget::setGradientStops( const QGradientStops& stops ) { if( _channel != lexis::render::ColorMap::Channel::alpha ) return; _gradient = QLinearGradient( 0.0f, 0.0f, width(), 0.0f ); for( int i = 0; i < stops.size(); ++i ) _gradient.setColorAt( stops.at( i ).first, stops.at( i ).second ); _background = QImage(); _generateBackground(); }
QGradientStops MeshGenerator::resampleGradientStops(QGradientStops stops) { QColor colorMap[256]; int startj, endj; for(int i=0; i<stops.size(); i++) { float pos = stops[i].first; QColor color = stops[i].second; endj = pos*255; colorMap[endj] = color; if (i > 0) { QColor colStart, colEnd; colStart = colorMap[startj]; colEnd = colorMap[endj]; float rb,gb,bb,ab, re,ge,be,ae; rb = colStart.red(); gb = colStart.green(); bb = colStart.blue(); ab = colStart.alpha(); re = colEnd.red(); ge = colEnd.green(); be = colEnd.blue(); ae = colEnd.alpha(); for (int j=startj+1; j<endj; j++) { float frc = (float)(j-startj)/(float)(endj-startj); float r,g,b,a; r = rb + frc*(re-rb); g = gb + frc*(ge-gb); b = bb + frc*(be-bb); a = ab + frc*(ae-ab); colorMap[j] = QColor(r, g, b, a); } } startj = endj; } QGradientStops newStops; for (int i=0; i<256; i++) { float pos = (float)i/255.0f; newStops << QGradientStop(pos, colorMap[i]); } return newStops; }
bool GradientStopsEditor::setStops( const QGradientStops &s ) { int countStops = s.size(); if( countStops < 2 ) return false; bool oldValueOfHandleSignals = handleSignals; handleSignals = false; r.setStops( s ); g.setStops( s ); b.setStops( s ); c.setStops( s ); c.setCompositeGradientStops( s ); handleSignals = oldValueOfHandleSignals; emit stopsChanged( s ); return true; }
void ShadeWidget::setGradientStops(const QGradientStops &stops) { if (m_shade_type == ARGBShade) { m_alpha_gradient = QLinearGradient(0, 0, width(), 0); for (int i=0; i<stops.size(); ++i) { QColor c = stops.at(i).second; m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue())); } m_shade = QImage(); generateShade(); update(); } }
QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) { Q_UNUSED(data); Q_D(QQuickRectangle); if (width() <= 0 || height() <= 0 || (d->color.alpha() == 0 && (!d->pen || d->pen->width() == 0 || d->pen->color().alpha() == 0))) { delete oldNode; return 0; } QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode); if (!rectangle) rectangle = d->sceneGraphContext()->createRectangleNode(); rectangle->setRect(QRectF(0, 0, width(), height())); rectangle->setColor(d->color); if (d->pen && d->pen->isValid()) { rectangle->setPenColor(d->pen->color()); rectangle->setPenWidth(d->pen->width()); rectangle->setAligned(d->pen->pixelAligned()); } else { rectangle->setPenWidth(0); } rectangle->setRadius(d->radius); rectangle->setAntialiasing(d->antialiasing); QGradientStops stops; if (d->gradient) { QList<QQuickGradientStop *> qxstops = d->gradient->m_stops; for (int i = 0; i < qxstops.size(); ++i){ int j = 0; while (j < stops.size() && stops.at(j).first < qxstops[i]->position()) j++; stops.insert(j, QGradientStop(qxstops.at(i)->position(), qxstops.at(i)->color())); } } rectangle->setGradientStops(stops); rectangle->update(); return rectangle; }
void GradientStopEditor::setCompositeGradientStops( const QGradientStops &s ) { if( stopChannel == composite ) { compositeGradient = QLinearGradient( 0, 0, width(), 0 ); QGradientStops newStops; int countStops = s.size(); for( int i = 0; i < countStops; i++ ) { QColor c( s[ i ].second ); c.setAlpha( 255 ); newStops << QGradientStop( s[ i ].first, c ); } //newStops << compositeGradient.stops(); compositeGradient.setStops( newStops ); generateBackground( true ); update(); } }
void GradientEditor::setGradientStops(const QGradientStops &stops) { QPolygonF pts_red, pts_green, pts_blue, pts_alpha; qreal h_red = m_red_shade->height(); qreal h_green = m_green_shade->height(); qreal h_blue = m_blue_shade->height(); qreal h_alpha = m_alpha_shade->height(); for (int i=0; i<stops.size(); ++i) { qreal pos = stops.at(i).first; QRgb color = stops.at(i).second.rgba(); pts_red << QPointF(pos * m_red_shade->width(), h_red - qRed(color) * h_red / 255); pts_green << QPointF(pos * m_green_shade->width(), h_green - qGreen(color) * h_green / 255); pts_blue << QPointF(pos * m_blue_shade->width(), h_blue - qBlue(color) * h_blue / 255); pts_alpha << QPointF(pos * m_alpha_shade->width(), h_alpha - qAlpha(color) * h_alpha / 255); } set_shade_points(pts_red, m_red_shade); set_shade_points(pts_green, m_green_shade); set_shade_points(pts_blue, m_blue_shade); set_shade_points(pts_alpha, m_alpha_shade); }
bool PathGroups::keyPressEvent(QKeyEvent *event) { for(int i=0; i<m_paths.count(); i++) { if (m_paths[i]->grabsMouse()) { if (event->key() == Qt::Key_G) { m_paths[i]->removeFromMouseGrabberPool(); return true; } if (event->key() == Qt::Key_C) { bool b = m_paths[i]->closed(); m_paths[i]->setClosed(!b); return true; } else if (event->key() == Qt::Key_P) { bool b = m_paths[i]->showPoints(); m_paths[i]->setShowPoints(!b); return true; } else if (event->key() == Qt::Key_L) { bool b = m_paths[i]->showLength(); m_paths[i]->setShowLength(!b); return true; } else if (event->key() == Qt::Key_X) { m_paths[i]->setMoveAxis(PathGroupGrabber::MoveX); return true; } else if (event->key() == Qt::Key_Y) { if (event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::MetaModifier) m_paths[i]->redo(); else m_paths[i]->setMoveAxis(PathGroupGrabber::MoveY); return true; } else if (event->key() == Qt::Key_Z) { if (event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::MetaModifier) m_paths[i]->undo(); else m_paths[i]->setMoveAxis(PathGroupGrabber::MoveZ); return true; } else if (event->key() == Qt::Key_W) { m_paths[i]->setMoveAxis(PathGroupGrabber::MoveAll); return true; } else if (event->key() == Qt::Key_S) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float radx = m_paths[i]->getRadX(idx); if (event->modifiers() & Qt::ShiftModifier) radx--; else radx++; radx = qMax(1.0f, radx); m_paths[i]->setRadX(idx, radx, m_sameForAll); return true; } } else if (event->key() == Qt::Key_T) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float rady = m_paths[i]->getRadY(idx); if (event->modifiers() & Qt::ShiftModifier) rady--; else rady++; rady = qMax(1.0f, rady); m_paths[i]->setRadY(idx, rady, m_sameForAll); } else // switch to tube mode { if (event->modifiers() & Qt::ShiftModifier) { m_paths[i]->loadCaption(); } else { bool b = m_paths[i]->tube(); m_paths[i]->setTube(!b); } } return true; } else if (event->key() == Qt::Key_A) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float a = m_paths[i]->getAngle(idx); if (event->modifiers() & Qt::ShiftModifier) a--; else a++; m_paths[i]->setAngle(idx, a, m_sameForAll); return true; } } else if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Backtab) { m_paths[i]->removeFromMouseGrabberPool(); m_paths.removeAt(i); return true; } if (event->key() == Qt::Key_Space) { PropertyEditor propertyEditor; QMap<QString, QVariantList> plist; QVariantList vlist; vlist.clear(); vlist << QVariant("double"); vlist << QVariant(m_paths[i]->opacity()); vlist << QVariant(0.0); vlist << QVariant(1.0); vlist << QVariant(0.1); // singlestep vlist << QVariant(1); // decimals plist["opacity"] = vlist; vlist.clear(); vlist << QVariant("colorgradient"); QGradientStops stops = m_paths[i]->stops(); for(int s=0; s<stops.size(); s++) { float pos = stops[s].first; QColor color = stops[s].second; int r = color.red(); int g = color.green(); int b = color.blue(); int a = color.alpha(); vlist << QVariant(pos); vlist << QVariant(r); vlist << QVariant(g); vlist << QVariant(b); vlist << QVariant(a); } plist["color"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->filterPathLen()); plist["filter on length"] = vlist; float vmin, vmax; m_paths[i]->userPathlenMinmax(vmin, vmax); vlist.clear(); vlist << QVariant("string"); vlist << QVariant(QString("%1 %2").arg(vmin).arg(vmax)); plist["length bounds"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->scaleType()); plist["scale type"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->depthcue()); plist["depthcue"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->segments()); vlist << QVariant(1); vlist << QVariant(100); plist["smoothness"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->sections()); vlist << QVariant(1); vlist << QVariant(100); plist["sections"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->sparseness()); vlist << QVariant(1); vlist << QVariant(100); plist["sparseness"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->separation()); vlist << QVariant(0); vlist << QVariant(10); plist["screen separation"] = vlist; vlist.clear(); vlist << QVariant("combobox"); vlist << QVariant(m_paths[i]->capType()); vlist << QVariant("flat"); vlist << QVariant("round"); vlist << QVariant("arrow"); plist["cap style"] = vlist; vlist.clear(); vlist << QVariant("combobox"); vlist << QVariant(m_paths[i]->arrowDirection()); vlist << QVariant("forward"); vlist << QVariant("backward"); plist["arrow direction"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->animate()); plist["animate"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->allowInterpolate()); plist["interpolate"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->animateSpeed()); vlist << QVariant(10); vlist << QVariant(100); plist["animation speed"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->arrowForAll()); plist["arrows for all"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_sameForAll); plist["same for all"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->clip()); plist["clip"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->allowEditing()); plist["allow editing"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->blendMode()); plist["blend with volume"] = vlist; vlist.clear(); plist["command"] = vlist; vlist.clear(); QFile helpFile(":/pathgroups.help"); if (helpFile.open(QFile::ReadOnly)) { QTextStream in(&helpFile); QString line = in.readLine(); while (!line.isNull()) { if (line == "#begin") { QString keyword = in.readLine(); QString helptext; line = in.readLine(); while (!line.isNull()) { helptext += line; helptext += "\n"; line = in.readLine(); if (line == "#end") break; } vlist << keyword << helptext; } line = in.readLine(); } } plist["commandhelp"] = vlist; vlist.clear(); QString mesg; float pmin, pmax; m_paths[i]->pathlenMinmax(pmin, pmax); mesg = QString("min/max path lengths : %1 %2\n").arg(pmin).arg(pmax); float mins,maxs; mins = m_paths[i]->minScale(); maxs = m_paths[i]->maxScale(); mesg += QString("min/max scale : %1 %2\n").arg(mins).arg(maxs); vlist << mesg; plist["message"] = vlist; QStringList keys; keys << "color"; keys << "opacity"; keys << "depthcue"; keys << "gap"; keys << "filter on length"; keys << "length bounds"; keys << "scale type"; keys << "gap"; keys << "smoothness"; keys << "sections"; keys << "sparseness"; keys << "screen separation"; keys << "gap"; keys << "cap style"; keys << "arrow direction"; keys << "arrows for all"; keys << "gap"; keys << "animate"; keys << "interpolate"; keys << "animation speed"; keys << "gap"; keys << "same for all"; keys << "clip"; keys << "blend with volume"; keys << "allow editing"; keys << "command"; keys << "commandhelp"; keys << "message"; propertyEditor.set("Path Group Parameters", plist, keys); QMap<QString, QPair<QVariant, bool> > vmap; if (propertyEditor.exec() == QDialog::Accepted) vmap = propertyEditor.get(); else return true; keys = vmap.keys(); for(int ik=0; ik<keys.count(); ik++) { QPair<QVariant, bool> pair = vmap.value(keys[ik]); if (pair.second) { if (keys[ik] == "color") { QGradientStops stops = propertyEditor.getGradientStops(keys[ik]); m_paths[i]->setStops(stops); } else if (keys[ik] == "opacity") m_paths[i]->setOpacity(pair.first.toDouble()); else if (keys[ik] == "scale type") m_paths[i]->setScaleType(pair.first.toBool()); else if (keys[ik] == "sections") m_paths[i]->setSections(pair.first.toInt()); else if (keys[ik] == "smoothness") m_paths[i]->setSegments(pair.first.toInt()); else if (keys[ik] == "sparseness") m_paths[i]->setSparseness(pair.first.toInt()); else if (keys[ik] == "screen separation") m_paths[i]->setSeparation(pair.first.toInt()); else if (keys[ik] == "depthcue") m_paths[i]->setDepthcue(pair.first.toBool()); else if (keys[ik] == "animate") m_paths[i]->setAnimate(pair.first.toBool()); else if (keys[ik] == "interpolate") m_paths[i]->setAllowInterpolate(pair.first.toBool()); else if (keys[ik] == "animation speed") m_paths[i]->setAnimateSpeed(pair.first.toInt()); else if (keys[ik] == "cap style") m_paths[i]->setCapType(pair.first.toInt()); else if (keys[ik] == "arrow direction") m_paths[i]->setArrowDirection(pair.first.toInt()); else if (keys[ik] == "arrows for all") m_paths[i]->setArrowForAll(pair.first.toBool()); else if (keys[ik] == "same for all") { m_sameForAll = pair.first.toBool(); m_paths[i]->setSameForAll(m_sameForAll); } else if (keys[ik] == "clip") m_paths[i]->setClip(pair.first.toBool()); else if (keys[ik] == "allow editing") m_paths[i]->setAllowEditing(pair.first.toBool()); else if (keys[ik] == "blend with volume") m_paths[i]->setBlendMode(pair.first.toBool()); else if (keys[ik] == "filter on length") m_paths[i]->setFilterPathLen(pair.first.toBool()); else if (keys[ik] == "length bounds") { QString vstr = pair.first.toString(); QStringList vl = vstr.split(" ", QString::SkipEmptyParts); if (vl.count() == 2) m_paths[i]->setUserPathlenMinmax(vl[0].toDouble(), vl[1].toDouble()); } } } QString cmd = propertyEditor.getCommandString(); if (!cmd.isEmpty()) processCommand(i, cmd); updateGL(); } } } return true; }
static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas ) { painter->save(); const QPainterPath borderClip = canvas->borderPath( canvas->rect() ); if ( !borderClip.isEmpty() ) painter->setClipPath( borderClip, Qt::IntersectClip ); const QBrush &brush = canvas->palette().brush( canvas->backgroundRole() ); if ( brush.style() == Qt::TexturePattern ) { QPixmap pm( canvas->size() ); qwtFillPixmap( canvas, pm ); painter->drawPixmap( 0, 0, pm ); } else if ( brush.gradient() ) { QVector<QRect> rects; if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) { rects += canvas->rect(); } else { rects = painter->clipRegion().rects(); } #if 1 bool useRaster = false; if ( painter->paintEngine()->type() == QPaintEngine::X11 ) { // Qt 4.7.1: gradients on X11 are broken ( subrects + // QGradient::StretchToDeviceMode ) and horrible slow. // As workaround we have to use the raster paintengine. // Even if the QImage -> QPixmap translation is slow // it is three times faster, than using X11 directly useRaster = true; } #endif if ( useRaster ) { QImage::Format format = QImage::Format_RGB32; const QGradientStops stops = brush.gradient()->stops(); for ( int i = 0; i < stops.size(); i++ ) { if ( stops[i].second.alpha() != 255 ) { // don't use Format_ARGB32_Premultiplied. It's // recommended by the Qt docs, but QPainter::drawImage() // is horrible slow on X11. format = QImage::Format_ARGB32; break; } } QImage image( canvas->size(), format ); QPainter p( &image ); p.setPen( Qt::NoPen ); p.setBrush( brush ); p.drawRects( rects ); p.end(); painter->drawImage( 0, 0, image ); } else { painter->setPen( Qt::NoPen ); painter->setBrush( brush ); painter->drawRects( rects ); } } else { painter->setPen( Qt::NoPen ); painter->setBrush( brush ); painter->drawRects( painter->clipRegion().rects() ); } painter->restore(); }
bool MeshGenerator::getValues(int &depth, int &fillValue, bool &checkForMore, bool &lookInside, QGradientStops &stops, bool doBorder, int &chan, bool &avgColor) { chan = 0; depth = 1; fillValue = -1; checkForMore = true; lookInside = false; avgColor = false; m_useTagColors = false; m_scaleModel = 1.0; QGradientStops vstops; vstops << QGradientStop(0.0, QColor(50 ,50 ,50 ,255)) << QGradientStop(0.5, QColor(200,150,100,255)) << QGradientStop(1.0, QColor(255,255,255,255)); if (doBorder) fillValue = 0; PropertyEditor propertyEditor; QMap<QString, QVariantList> plist; QVariantList vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(avgColor); plist["average color"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_useTagColors); plist["apply tag colors"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(chan); vlist << QVariant(0); vlist << QVariant(2); plist["mop channel"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(depth); vlist << QVariant(0); vlist << QVariant(200); plist["depth"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(fillValue); vlist << QVariant(-1); vlist << QVariant(255); plist["fillvalue"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(checkForMore); plist["greater"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(lookInside); plist["look inside"] = vlist; vlist.clear(); vlist << QVariant("float"); vlist << QVariant(m_scaleModel); vlist << QVariant(0.001); vlist << QVariant(1.0); vlist << QVariant(0.005); // singlestep vlist << QVariant(3); // decimals plist["scale"] = vlist; vlist.clear(); vlist << QVariant("colorgradient"); for(int s=0; s<vstops.size(); s++) { float pos = vstops[s].first; QColor color = vstops[s].second; int r = color.red(); int g = color.green(); int b = color.blue(); int a = color.alpha(); vlist << QVariant(pos); vlist << QVariant(r); vlist << QVariant(g); vlist << QVariant(b); vlist << QVariant(a); } plist["color gradient"] = vlist; vlist.clear(); QFile helpFile(":/mesh.help"); if (helpFile.open(QFile::ReadOnly)) { QTextStream in(&helpFile); QString line = in.readLine(); while (!line.isNull()) { if (line == "#begin") { QString keyword = in.readLine(); QString helptext; line = in.readLine(); while (!line.isNull()) { helptext += line; helptext += "\n"; line = in.readLine(); if (line == "#end") break; } vlist << keyword << helptext; } line = in.readLine(); } } plist["commandhelp"] = vlist; vlist.clear(); QString mesg; mesg += "File : "+m_vfm->fileName()+"\n"; int d = m_vfm->depth(); int w = m_vfm->width(); int h = m_vfm->height(); mesg += QString("Volume Size : %1 %2 %3\n").arg(h).arg(w).arg(d); mesg += QString("Data Min : %1 %2 %3\n").arg(m_dataMin.x).arg(m_dataMin.y).arg(m_dataMin.z); mesg += QString("Data Max : %1 %2 %3\n").arg(m_dataMax.x).arg(m_dataMax.y).arg(m_dataMax.z); if (m_voxelType > 0) mesg += "\n ** Only opacity based surface generation available for unsigned short data **\n"; mesg += "\n* You can keep on working while this process is running.\n"; vlist << mesg; plist["message"] = vlist; QStringList keys; keys << "average color"; keys << "apply tag colors"; keys << "mop channel"; keys << "isosurface value"; keys << "depth"; keys << "fillvalue"; keys << "scale"; keys << "greater"; keys << "look inside"; keys << "color gradient"; keys << "commandhelp"; keys << "message"; propertyEditor.set("Mesh Repainting Parameters", plist, keys); QMap<QString, QPair<QVariant, bool> > vmap; if (propertyEditor.exec() == QDialog::Accepted) vmap = propertyEditor.get(); else return false; for(int ik=0; ik<keys.count(); ik++) { QPair<QVariant, bool> pair = vmap.value(keys[ik]); if (pair.second) { if (keys[ik] == "average color") avgColor = pair.first.toBool(); else if (keys[ik] == "apply tag colors") m_useTagColors = pair.first.toBool(); else if (keys[ik] == "mop channel") chan = pair.first.toInt(); else if (keys[ik] == "color gradient") vstops = propertyEditor.getGradientStops(keys[ik]); else if (keys[ik] == "scale") m_scaleModel = pair.first.toFloat(); else if (keys[ik] == "depth") depth = pair.first.toInt(); else if (keys[ik] == "fillvalue") fillValue = pair.first.toInt(); else if (keys[ik] == "greater") checkForMore = pair.first.toBool(); else if (keys[ik] == "look inside") lookInside = pair.first.toBool(); } } stops = resampleGradientStops(vstops); return true; }
void TagColorEditor::askGradientChoice() { QString homePath = QDir::homePath(); QFileInfo sfi(homePath, ".drishtigradients.xml"); QString stopsflnm = sfi.absoluteFilePath(); if (!sfi.exists()) copyGradientFile(stopsflnm); QDomDocument document; QFile f(stopsflnm); if (f.open(QIODevice::ReadOnly)) { document.setContent(&f); f.close(); } QStringList glist; QDomElement main = document.documentElement(); QDomNodeList dlist = main.childNodes(); for(int i=0; i<dlist.count(); i++) { if (dlist.at(i).nodeName() == "gradient") { QDomNodeList cnode = dlist.at(i).childNodes(); for(int j=0; j<cnode.count(); j++) { QDomElement dnode = cnode.at(j).toElement(); if (dnode.nodeName() == "name") glist << dnode.text(); } } } bool ok; QString gstr = QInputDialog::getItem(0, "Color Gradient", "Color Gradient", glist, 0, false, &ok); if (!ok) return; int cno = -1; for(int i=0; i<dlist.count(); i++) { if (dlist.at(i).nodeName() == "gradient") { QDomNodeList cnode = dlist.at(i).childNodes(); for(int j=0; j<cnode.count(); j++) { QDomElement dnode = cnode.at(j).toElement(); if (dnode.tagName() == "name" && dnode.text() == gstr) { cno = i; break; } } } } if (cno < 0) return; QGradientStops stops; QDomNodeList cnode = dlist.at(cno).childNodes(); for(int j=0; j<cnode.count(); j++) { QDomElement de = cnode.at(j).toElement(); if (de.tagName() == "gradientstops") { QString str = de.text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count()/5; j++) { float pos, r,g,b,a; pos = strlist[5*j].toFloat(); r = strlist[5*j+1].toInt(); g = strlist[5*j+2].toInt(); b = strlist[5*j+3].toInt(); a = strlist[5*j+4].toInt(); stops << QGradientStop(pos, QColor(r,g,b,a)); } } } int mapSize = QInputDialog::getInt(0, "Number of Colors", "Number of Colors", 50, 2, 255, 1, &ok); if (!ok) mapSize = 50; QGradientStops gstops; gstops = StaticFunctions::resampleGradientStops(stops, mapSize); uchar *colors = Global::tagColors(); for(int i=0; i<gstops.size(); i++) { float pos = gstops[i].first; QColor color = gstops[i].second; int r = color.red(); int g = color.green(); int b = color.blue(); colors[4*i+0] = r; colors[4*i+1] = g; colors[4*i+2] = b; } setColors(); }
QList<SplineInformation> SplineInformation::interpolate(QList<SplineInformation> splineInfo1, QList<SplineInformation> splineInfo2, float frc) { QList<SplineInformation> splineInfo; for(int i=0; i<qMin(splineInfo1.size(), splineInfo2.size()); i++) { splineInfo.append(interpolate(splineInfo1[i], splineInfo2[i], frc)); } int st = splineInfo.size(); for(int i=st; i<splineInfo1.size(); i++) { QGradientStops stops = splineInfo1[i].gradientStops(); QGradientStops newStops; for(int j=0; j<stops.size(); j++) { float pos = stops[j].first; QColor col = stops[j].second; float r,g,b,a; r = col.red(); g = col.green(); b = col.blue(); a = (1-frc)*col.alpha(); col = QColor(r,g,b,a); newStops << QGradientStop(pos, col); } SplineInformation sinfo; sinfo.setName(splineInfo1[i].name()); sinfo.setOn(splineInfo1[i].on()); sinfo.setPoints(splineInfo1[i].points()); sinfo.setNormalWidths(splineInfo1[i].normalWidths()); sinfo.setNormalRotations(splineInfo1[i].normalRotations()); sinfo.setGradientStops(newStops); splineInfo.append(sinfo); } st = splineInfo.size(); for(int i=st; i<splineInfo2.size(); i++) { QGradientStops stops = splineInfo2[i].gradientStops(); QGradientStops newStops; for(int j=0; j<stops.size(); j++) { float pos = stops[j].first; QColor col = stops[j].second; float r,g,b,a; r = col.red(); g = col.green(); b = col.blue(); a = frc*col.alpha(); col = QColor(r,g,b,a); newStops << QGradientStop(pos, col); } SplineInformation sinfo; sinfo.setName(splineInfo2[i].name()); sinfo.setOn(splineInfo2[i].on()); sinfo.setPoints(splineInfo2[i].points()); sinfo.setNormalWidths(splineInfo2[i].normalWidths()); sinfo.setNormalRotations(splineInfo2[i].normalRotations()); sinfo.setGradientStops(newStops); splineInfo.append(sinfo); } return splineInfo; }
QGradientStops SplineInformation::interpolateGradientStops(QGradientStops stops1, QGradientStops stops2, float frc) { QVector<float> pos; for(int i=0; i<stops1.size(); i++) pos.append(stops1[i].first); for(int i=0; i<stops2.size(); i++) { float pos2 = stops2[i].first; bool flag = true; for(int j=0; j<stops1.size(); j++) { if (fabs(pos[j] - pos2) < 0.0001) { flag = false; break; } } if (flag) pos.append(pos2); } qSort(pos.begin(), pos.end()); QGradientStops gradStops1 = StaticFunctions::resampleGradientStops(stops1); QGradientStops gradStops2 = StaticFunctions::resampleGradientStops(stops2); QGradientStops gradStops; int gsize = gradStops1.size()-1; for(int i=0; i<pos.size(); i++) { int idx = pos[i]*gsize; QColor color1 = gradStops1[idx].second; QColor color2 = gradStops2[idx].second; // linear interpolation of colors float rb,gb,bb,ab, re,ge,be,ae; rb = color1.red(); gb = color1.green(); bb = color1.blue(); ab = color1.alpha(); re = color2.red(); ge = color2.green(); be = color2.blue(); ae = color2.alpha(); float r,g,b,a; r = rb + frc*(re-rb); g = gb + frc*(ge-gb); b = bb + frc*(be-bb); a = ab + frc*(ae-ab); QColor color = QColor(r,g,b,a); gradStops << QGradientStop(pos[i], color); } return gradStops; }
int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject) { const QGradient *gradient = b.gradient(); if (!gradient) return 0; QTransform inv = matrix.inverted(); QPointF page_rect[4] = { inv.map(QPointF(0, 0)), inv.map(QPointF(width_, 0)), inv.map(QPointF(0, height_)), inv.map(QPointF(width_, height_)) }; bool opaque = b.isOpaque(); QByteArray shader; QByteArray alphaShader; if (gradient->type() == QGradient::LinearGradient) { const QLinearGradient *lg = static_cast<const QLinearGradient *>(gradient); shader = QPdf::generateLinearGradientShader(lg, page_rect); if (!opaque) alphaShader = QPdf::generateLinearGradientShader(lg, page_rect, true); } else { // ############# return 0; } int shaderObject = addXrefEntry(-1); write(shader); QByteArray str; QPdf::ByteStream s(&str); s << "<<\n" "/Type /Pattern\n" "/PatternType 2\n" "/Shading " << shaderObject << "0 R\n" "/Matrix [" << matrix.m11() << matrix.m12() << matrix.m21() << matrix.m22() << matrix.dx() << matrix.dy() << "]\n"; s << ">>\n" "endobj\n"; int patternObj = addXrefEntry(-1); write(str); currentPage->patterns.append(patternObj); if (!opaque) { bool ca = true; QGradientStops stops = gradient->stops(); int a = stops.at(0).second.alpha(); for (int i = 1; i < stops.size(); ++i) { if (stops.at(i).second.alpha() != a) { ca = false; break; } } if (ca) { *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha()); } else { int alphaShaderObject = addXrefEntry(-1); write(alphaShader); QByteArray content; QPdf::ByteStream c(&content); c << "/Shader" << alphaShaderObject << "sh\n"; QByteArray form; QPdf::ByteStream f(&form); f << "<<\n" "/Type /XObject\n" "/Subtype /Form\n" "/BBox [0 0 " << width_ << height_ << "]\n" "/Group <</S /Transparency >>\n" "/Resources <<\n" "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n" ">>\n"; f << "/Length " << content.length() << "\n" ">>\n" "stream\n" << content << "endstream\n" "endobj\n"; int softMaskFormObject = addXrefEntry(-1); write(form); *gStateObject = addXrefEntry(-1); xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n" "endobj\n", softMaskFormObject); currentPage->graphicStates.append(*gStateObject); } } return patternObj; }