// show but don't set into selColor, nor emit colorSelected void KColorDialog::KColorDialogPrivate::showColor(const QColor &color, const QString &name) { bRecursion = true; if (name.isEmpty()) colorName->setText(tr("-unnamed-")); else colorName->setText(name); patch->setColor(color); setRgbEdit(color); setHsvEdit(color); setHtmlEdit(color); switch (chooserMode()) { case ChooserSaturation: hsSelector->setValues(color.hue(), color.value()); valuePal->setValue(color.saturation()); break; case ChooserValue: hsSelector->setValues(color.hue(), color.saturation()); valuePal->setValue(color.value()); break; case ChooserRed: hsSelector->setValues(color.green(), color.blue()); valuePal->setValue(color.red()); break; case ChooserGreen: hsSelector->setValues(color.red(), color.blue()); valuePal->setValue(color.green()); break; case ChooserBlue: hsSelector->setValues(color.green(), color.red()); valuePal->setValue(color.blue()); break; case ChooserHue: default: hsSelector->setValues(color.saturation(), color.value()); valuePal->setValue(color.hue()); break; } bool blocked = valuePal->blockSignals(true); valuePal->setHue(color.hue()); valuePal->setSaturation(color.saturation()); valuePal->setColorValue(color.value()); valuePal->updateContents(); valuePal->blockSignals(blocked); valuePal->repaint(); blocked = hsSelector->blockSignals(true); hsSelector->setHue(color.hue()); hsSelector->setSaturation(color.saturation()); hsSelector->setColorValue(color.value()); hsSelector->updateContents(); hsSelector->blockSignals(blocked); hsSelector->repaint(); bRecursion = false; }
SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static ) : QSlider( q, _parent ), b_classic( _static ) { isSliding = false; f_buffering = 1.0; mHandleOpacity = 1.0; chapters = NULL; mHandleLength = -1; b_seekable = true; alternativeStyle = NULL; // prepare some static colors QPalette p = palette(); QColor background = p.color( QPalette::Active, QPalette::Window ); tickpointForeground = p.color( QPalette::Active, QPalette::WindowText ); tickpointForeground.setHsv( tickpointForeground.hue(), ( background.saturation() + tickpointForeground.saturation() ) / 2, ( background.value() + tickpointForeground.value() ) / 2 ); // set the background color and gradient QColor backgroundBase( p.window().color() ); backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) ); backgroundGradient.setColorAt( 1.0, backgroundBase ); // set the foreground color and gradient QColor foregroundBase( 50, 156, 255 ); foregroundGradient.setColorAt( 0.0, foregroundBase ); foregroundGradient.setColorAt( 1.0, foregroundBase.darker( 140 ) ); // prepare the handle's gradient handleGradient.setColorAt( 0.0, p.window().color().lighter( 120 ) ); handleGradient.setColorAt( 0.9, p.window().color().darker( 120 ) ); // prepare the handle's shadow gradient QColor shadowBase = p.shadow().color(); if( shadowBase.lightness() > 100 ) shadowBase = QColor( 60, 60, 60 ); // Palette's shadow is too bright shadowDark = shadowBase.darker( 150 ); shadowLight = shadowBase.lighter( 180 ); shadowLight.setAlpha( 50 ); /* Timer used to fire intermediate updatePos() when sliding */ seekLimitTimer = new QTimer( this ); seekLimitTimer->setSingleShot( true ); /* Tooltip bubble */ mTimeTooltip = new TimeTooltip( this ); mTimeTooltip->setMouseTracking( true ); /* Properties */ setRange( MINIMUM, MAXIMUM ); setSingleStep( 2 ); setPageStep( 10 ); setMouseTracking( true ); setTracking( true ); setFocusPolicy( Qt::NoFocus ); /* Use the new/classic style */ if( !b_classic ) { alternativeStyle = new SeekStyle; setStyle( alternativeStyle ); } /* Init to 0 */ setPosition( -1.0, 0, 0 ); secstotimestr( psz_length, 0 ); animHandle = new QPropertyAnimation( this, "handleOpacity", this ); animHandle->setDuration( FADEDURATION ); animHandle->setStartValue( 0.0 ); animHandle->setEndValue( 1.0 ); hideHandleTimer = new QTimer( this ); hideHandleTimer->setSingleShot( true ); hideHandleTimer->setInterval( FADEOUTDELAY ); CONNECT( this, sliderMoved( int ), this, startSeekTimer() ); CONNECT( seekLimitTimer, timeout(), this, updatePos() ); CONNECT( hideHandleTimer, timeout(), this, hideHandle() ); mTimeTooltip->installEventFilter( this ); }
void ColorLuminancePicker::setCol(const QColor& c) { setCol(c.hue(), c.saturation(), c.value()); }
State Transformation::apply(const State& s, ColorPool* colorPool) const { State s2(s); s2.matrix = s.matrix*matrix; if (absoluteColor) { // if the absolute hue is larger than 360, we will choose a random color. if (deltaH > 360) { QColor c = colorPool->drawColor(); s2.hsv = Vector3f(c.hue(), c.saturation()/255.0, c.value()/255.0); s2.alpha = 1.0; } else { s2.hsv = Vector3f(deltaH,scaleS,scaleV); s2.alpha = scaleAlpha; } } else { float h = s2.hsv[0] + deltaH; float sat = s2.hsv[1]*scaleS; float v = s2.hsv[2]*scaleV; float a = s2.alpha * scaleAlpha; if (sat<0) sat=0; if (v<0) v=0; if (a<0) a=0; if (sat>1) sat=1; if (v>1) v=1; if (a>1) a=1; while (h>360) h-=360; while (h<0) h+=360; s2.hsv = Vector3f(h,sat,v); s2.alpha = a; } if (strength) { /* // We will blend the two colors (in RGB space) QColor original = QColor::fromHsv((int)(s2.hsv[0]),(int)(s2.hsv[1]*255.0),(int)(s2.hsv[2]*255.0)); double r = original.red() + strength*blendColor.red(); double g = original.green() + strength*blendColor.green(); double b = original.blue() + strength*blendColor.blue(); if (r<0) r=0; if (g<0) g=0; if (b<0) b=0; double max = r; if (g>max) max = g; if (b>max) max = b; if (max > 255) { r = r * 255 / max; g = g * 255 / max; b = b * 255 / max; } QColor mixed(r,g,b); s2.hsv = Vector3f(mixed.hue(), mixed.saturation()/255.0,mixed.value()/255.0); */ // We will blend the two colors (in HSV space) Vector3f bl = Vector3f(blendColor.hue(), blendColor.saturation()/255.0,blendColor.value()/255.0); Vector3f b(s2.hsv[0]+strength*bl[0], s2.hsv[1]+strength*bl[1], s2.hsv[2]+strength*bl[2]); b = b/(1+strength); while (b[0] < 0) b[0]+= 360; while (b[0] > 360) b[0]-= 360; if (b[1]>1) b[1]=1; if (b[2]>1) b[2]=1; if (b[1]<0) b[1]=0; if (b[2]<0) b[2]=0; s2.hsv = b; } return s2; }
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawPrimitive(element, option, painter, widget); bool animating = (option->state & State_Animating); int state = option->state; QRect rect = option->rect; QRect oldRect; QRect newRect; if (widget && (element == PE_PanelButtonTool) && !animating) { QWidget *w = const_cast<QWidget *> (widget); int oldState = w->property("_q_stylestate").toInt(); oldRect = w->property("_q_stylerect").toRect(); newRect = w->rect(); w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); // Determine the animated transition bool doTransition = ((state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); if (oldRect != newRect) { doTransition = false; d->animator.stopAnimation(widget); } if (doTransition) { QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); Animation *anim = d->animator.widgetAnimation(widget); QStyleOption opt = *option; opt.state = (QStyle::State)oldState; opt.state |= State_Animating; startImage.fill(0); Transition *t = new Transition; t->setWidget(w); QPainter startPainter(&startImage); if (!anim) { drawPrimitive(element, &opt, &startPainter, widget); } else { anim->paint(&startPainter, &opt); d->animator.stopAnimation(widget); } QStyleOption endOpt = *option; endOpt.state |= State_Animating; t->setStartImage(startImage); d->animator.startAnimation(t); endImage.fill(0); QPainter endPainter(&endImage); drawPrimitive(element, &endOpt, &endPainter, widget); t->setEndImage(endImage); if (oldState & State_MouseOver) t->setDuration(150); else t->setDuration(75); t->setStartTime(QTime::currentTime()); } } switch (element) { case PE_IndicatorDockWidgetResizeHandle: painter->fillRect(option->rect, creatorTheme()->color(Theme::DockWidgetResizeHandleColor)); break; case PE_FrameDockWidget: QCommonStyle::drawPrimitive(element, option, painter, widget); break; case PE_PanelLineEdit: { painter->save(); // Fill the line edit background QRect filledRect = option->rect.adjusted(1, 1, -1, -1); painter->setBrushOrigin(filledRect.topLeft()); painter->fillRect(filledRect, option->palette.base()); if (option->state & State_Enabled) StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5); else StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5); if (option->state & State_HasFocus || option->state & State_MouseOver) { QColor hover = StyleHelper::baseColor(); if (state & State_HasFocus) hover.setAlpha(100); else hover.setAlpha(50); painter->setPen(QPen(hover, 1)); painter->drawRect(QRectF(option->rect).adjusted(1.5, 1.5, -1.5, -1.5)); } painter->restore(); } break; case PE_FrameStatusBarItem: break; case PE_PanelButtonTool: { Animation *anim = d->animator.widgetAnimation(widget); if (!animating && anim) { anim->paint(painter, option); } else { bool pressed = option->state & State_Sunken || option->state & State_On; QColor shadow(0, 0, 0, 30); painter->setPen(shadow); if (pressed) { QColor shade = option->palette.base().color(); shade.setHsv(shade.hue(), shade.saturation(), 255 - shade.value(), 40); painter->fillRect(rect, shade); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); } else if (option->state & State_Enabled && option->state & State_MouseOver) { painter->fillRect(rect, creatorTheme()->color(Theme::PanelButtonToolBackgroundColorHover)); } else if (widget && widget->property("highlightWidget").toBool()) { QColor shade(0, 0, 0, 128); painter->fillRect(rect, shade); } if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) { QColor highlight = option->palette.highlight().color(); highlight.setAlphaF(0.4); painter->setPen(QPen(highlight.lighter(), 1)); highlight.setAlphaF(0.3); painter->setBrush(highlight); painter->setRenderHint(QPainter::Antialiasing); const QRectF rect = option->rect; painter->drawRoundedRect(rect.adjusted(2.5, 2.5, -2.5, -2.5), 2, 2); } } } break; case PE_PanelStatusBar: { if (creatorTheme()->widgetStyle() == Theme::StyleDefault) { painter->save(); QLinearGradient grad = StyleHelper::statusBarGradient(rect); painter->fillRect(rect, grad); painter->setPen(QColor(255, 255, 255, 60)); painter->drawLine(rect.topLeft() + QPoint(0,1), rect.topRight()+ QPoint(0,1)); painter->setPen(StyleHelper::borderColor().darker(110)); //TODO: make themable painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } else { painter->fillRect(rect, creatorTheme()->color(Theme::PanelStatusBarBackgroundColor)); } } break; case PE_IndicatorToolBarSeparator: { QColor separatorColor = StyleHelper::borderColor(); separatorColor.setAlpha(100); painter->setPen(separatorColor); const int margin = 6; if (option->state & State_Horizontal) { const int offset = rect.width()/2; painter->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, rect.topLeft().y() + margin); } else { //Draw vertical separator const int offset = rect.height()/2; painter->setPen(QPen(option->palette.background().color().darker(110))); painter->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset, rect.topRight().x() - margin, rect.topRight().y() + offset); } } break; case PE_IndicatorToolBarHandle: { bool horizontal = option->state & State_Horizontal; painter->save(); QPainterPath path; int x = option->rect.x() + (horizontal ? 2 : 6); int y = option->rect.y() + (horizontal ? 6 : 2); static const int RectHeight = 2; if (horizontal) { while (y < option->rect.height() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < option->rect.width() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); x += 6; } } painter->setPen(Qt::NoPen); QColor dark = StyleHelper::borderColor(); dark.setAlphaF(0.4); QColor light = StyleHelper::baseColor(); light.setAlphaF(0.4); painter->fillPath(path, light); painter->save(); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); painter->translate(3, 3); painter->fillPath(path, light); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); } break; case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { StyleHelper::drawArrow(element, painter, option); } break; default: QProxyStyle::drawPrimitive(element, option, painter, widget); break; } }
void BaseLayer( QImage* img, QImage* canvas, int radius, double strength) /// /// Covers the canvas in large points. Hues are taken from the palette /// but no color distortion is added at this point. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to store the filtered image. /// /// @param radius /// The radius of the points being used for the pointillism algorithm /// (actual point radius used will be larger for this stage of the algorithm). /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { // Adjust the point radius based on the strength of the filter if(strength < 0.5) { int new_radius = (int)radius*strength*2; if(1.0*new_radius < radius*strength*2) new_radius++; radius = new_radius; if(radius < 3) radius = 3; } // Clear the depth buffer ready for drawing uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // Get a poisson disk sampling of the area, and repaint the sampled areas with a brush of small radius int spacing = radius*2; std::vector<QPoint> poisson = ImageProcessing::GetPoissonDisks(canvas->width(), canvas->height(), spacing); while(!poisson.empty()) { QPoint pos = poisson.back(); poisson.pop_back(); // Get the hue at this point and find the closest hue in the color palette QColor hsv = QColor(img->pixel(pos)).toHsv(); int hue = hsv.hue(); int sat = hsv.saturation(); int val = hsv.value(); hue = chevreul[ GetPaletteHuePosition( hue ) ]; // Paint a point of the chosen hue at a random depth value hsv.setHsv(hue, sat, val); int z = rand()%256; DrawRandomCircle(canvas, pos, hsv.toRgb(), radius, z, depth_buffer); } poisson.clear(); delete [] depth_buffer; }
// Hàm dùng lọc ảnh bằng các filter tương ứng QImage ExtraFiltersPlugin::filterImage(const QString &filter, const QImage &image, QWidget *parent) { // Chuyển đổi định dạng ảnh sang RGB 32-bit để các hàm làm việc như mong // đợi QImage original = image.convertToFormat(QImage::Format_RGB32); QImage result = original; if (filter == tr("Lật ngang")) { // Nếu filter là "Lật ngang" thì hoán đổi các pixel của ảnh theo chiều // ngang của ảnh for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { int pixel = original.pixel(original.width() - x - 1, y); result.setPixel(x, y, pixel); } } } else if (filter == tr("Lật dọc")) { // Nếu filter là "Lật dọc" thì hoán đổi các pixel của ảnh theo chiều // dọc của ảnh for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { int pixel = original.pixel(x, original.height() - y - 1); result.setPixel(x, y, pixel); } } } else if (filter == tr("Làm mờ")) { // Ta sẽ nhân từng điểm ảnh với ma trận tích chập để làm mờ // trừ các điểm ở biên. int kernel[5][5] = {{0, 0, 1, 0, 0}, {0, 1, 3, 1, 0}, {1, 3, 7, 3, 1}, {0, 1, 3, 1, 0}, {0, 0, 1, 0, 0} }; int kernelSize = 5; int sumKernel = 27; int r, g, b; int pixel; for (int x = kernelSize / 2; x < original.width() - (kernelSize / 2); ++x) { for (int y = kernelSize / 2; y < original.height() - (kernelSize / 2); ++y) { r = 0; g = 0; b = 0; // Tính tổng giá trị màu của điểm pixel và các điểm ảnh xung quanh for ( int i = -kernelSize / 2 ; i <= kernelSize / 2 ; ++i) { for ( int j = -kernelSize / 2 ; j <= kernelSize / 2 ; ++j) { pixel = original.pixel ( x + i , y + j ); r += qRed(pixel) * kernel[kernelSize / 2 + i][kernelSize / 2 + j] ; g += qGreen(pixel) * kernel[kernelSize / 2 + i][kernelSize / 2 + j]; b += qBlue(pixel) * kernel[kernelSize / 2 + i][kernelSize / 2 + j]; } } // Kiểm tra giá trị các màu trong khoảng giới hạn r = qBound ( 0 , r / sumKernel , 255 ); g = qBound ( 0 , g / sumKernel , 255 ); b = qBound ( 0 , b / sumKernel , 255 ); result.setPixel ( x, y, qRgba(r , g , b, qAlpha(pixel))); } } } else if (filter == tr("Ảnh nhị phân")) { // Nếu filter là "Ảnh nhị phân" thì bật QInputDialog lên cho người dùng // nhập vào giá trị ngưỡng, nằm trong khoảng 0 đến 255 bool ok; // Kiểm tra giá trị nhập int threshold = QInputDialog::getInt(parent, tr("Ảnh nhị phân"), tr("Nhập ngưỡng:"), 85, 0, 255, 1, &ok); // Đầu tiên ta chuyển ảnh về ảnh đa mức xám rồi so sánh từng pixel của // ảnh với giá trị ngưỡng. if (ok) { for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { int pixel = original.pixel(x, y); int gray = qGray(pixel); gray = gray > threshold ? 255 : 0; pixel = qRgb(gray, gray, gray); result.setPixel(x, y, pixel); } } } } else if (filter == tr("Ảnh âm bản")) { // Dùng hàm invertPixels() để đảo ngược các pixel. result.invertPixels(); } else if (filter == tr("Đảo màu (RGB->BGR)")) { // Dùng hàm rgbSwapped() để chuyển kênh màu của ảnh từ RGB sang BGR result = result.rgbSwapped(); } else if (filter == tr("Đa mức xám")) { // for (int y = 0; y < result.height(); ++y) { for (int x = 0; x < result.width(); ++x) { int pixel = result.pixel(x, y); int gray = qGray(pixel); int alpha = qAlpha(pixel); result.setPixel(x, y, qRgba(gray, gray, gray, alpha)); } } } else if (filter == tr("Độ sáng")) { // Nếu filter là "Độ sáng" thì bật QInputDialog lên cho người dùng // nhập vào giá trị ngưỡng, giá trị này trong khoảng -255 đến 255 bool ok; // Kiểm tra giá trị nhập int brighness = QInputDialog::getInt(parent, tr("Độ sáng"), tr("Nhập độ sáng:"), 10, -255, 255, 1, &ok); // Ta tăng hoặc giảm giá trị các màu của từng pixel if (ok) { int r, g, b; for (int x = 0; x < original.width(); x++) { for (int y = 0; y < original.height(); y++) { int pixel = original.pixel(x, y); r = qRed(pixel) + brighness; g = qGreen(pixel) + brighness; b = qBlue(pixel) + brighness; //Ta kiểm tra các giá trị mới trong khoảng cho phép. r = qBound(0, r, 255); g = qBound(0, g, 255); b = qBound(0, b, 255); result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel))); } } } } else if (filter == tr("Làm ấm")) { // Nếu filter là "Làm ấm" thì bật QInputDialog lên cho người dùng // nhập vào giá trị, giá trị này trong khoảng 1 đến 255 bool ok; // Kiểm tra giá trị nhập int delta = QInputDialog::getInt(parent, tr("Lầm ấm"), tr("Nhập mức độ ấm:"), 10, 1, 255, 1, &ok); // Hình sẽ trong ấm hơn nếu ta tăng độ vàng của ảnh, và màu vàng được // tổng hợp từ màu đỏ và xanh lục trong kênh màu RGB if (ok) { int r, g, b; for (int x = 0; x < original.width(); x++) { for (int y = 0; y < original.height(); y++) { int pixel = original.pixel(x, y); r = qRed(pixel) + delta; g = qGreen(pixel) + delta; b = qBlue(pixel); //Ta kiểm tra các giá trị mới trong khoảng cho phép. r = qBound(0, r, 255); g = qBound(0, g, 255); result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel))); } } } } else if (filter == tr("Làm mát...")) { // Nếu filter là "Làm mát" thì bật QInputDialog lên cho người dùng // nhập vào giá trị, giá trị này trong khoảng 1 đến 255 bool ok; // Kiểm tra giá trị nhập int delta = QInputDialog::getInt(parent, tr("Lầm mát"), tr("Nhập mức độ mát:"), 10, 1, 256, 1, &ok); // Hình sẽ có cảm giác mát hơn khi ta tăng giá trị kênh màu xanh lam if (ok) { int r, g, b; for (int x = 0; x < original.width(); x++) { for (int y = 0; y < original.height(); y++) { int pixel = original.pixel(x, y); r = qRed(pixel); g = qGreen(pixel); b = qBlue(pixel) + delta; //Ta kiểm tra giá trị mới trong khoảng cho phép. b = qBound(0, b, 255); result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel))); } } } } else if (filter == tr("Độ bão hòa")) { // Nếu filter là "Độ bão hòa" thì bật QInputDialog lên cho người dùng // nhập vào giá trị, giá trị này trong khoảng -255 đến 255 bool ok; // Kiểm tra giá trị nhập vào int delta = QInputDialog::getInt(parent, tr("Độ bão hòa"), tr("Nhập độ bão hòa:"), 10, -255, 255, 1, &ok); QColor newClolor; QColor oldColor; int h, s, l; // Ta chuyển hình về kênh màu HSL rồi sau đó tăng hoặc giảm kênh // saturation để tăng hoặc giảm độ bão hòa sau đó lại chuyển ảnh về RGB if (ok) { for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { oldColor = QColor(original.pixel(x, y)); newClolor = oldColor.toHsl(); h = newClolor.hue(); s = newClolor.saturation() + delta; l = newClolor.lightness(); // Ta kiểm tra giá trị mới trong khoảng cho phép s = qBound(0, s, 255); newClolor.setHsl(h, s, l); result.setPixel(x, y, qRgba(newClolor.red(), newClolor.green(), newClolor.blue(), newClolor.alpha())); } } } } return result; }
void Manager::initDefaults() { QPalette appPlt( QApplication::palette() ); beginGroup("IDE"); setDefault("startWithSession", "last"); beginGroup("interpreter"); setDefault("autoStart", true); endGroup(); setDefault("postWindow/scrollback", 1000); beginGroup("editor"); setDefault("spaceIndent", false); setDefault("indentWidth", 4); setDefault("stepForwardEvaluation", false); setDefault("lineWrap", true); setDefault("disableBlinkingCursor", false); setDefault("highlightBracketContents", true); setDefault("inactiveEditorFadeAlpha", 64); setDefault("insertMatchingTokens", false); setDefault("blinkDuration", 600); setDefault("font/family", "monospace"); setDefault("font/antialias", true); beginGroup("colors"); QTextCharFormat matchingBracketsFormat; matchingBracketsFormat.setForeground(Qt::red); matchingBracketsFormat.setBackground(QColor("#ffff7f")); matchingBracketsFormat.setFontWeight(QFont::Bold); setDefault("matchingBrackets", QVariant::fromValue(matchingBracketsFormat)); QTextCharFormat bracketMismatchFormat; bracketMismatchFormat.setBackground(QColor(150,0,0)); bracketMismatchFormat.setForeground(Qt::white); setDefault("mismatchedBrackets", QVariant::fromValue(bracketMismatchFormat)); QTextCharFormat evaluatedCodeFormat; evaluatedCodeFormat.setBackground(QColor("#F8A200")); evaluatedCodeFormat.setForeground(Qt::black); setDefault("evaluatedCode", QVariant::fromValue(evaluatedCodeFormat)); QTextCharFormat currentLineFormat; { QColor bkg = appPlt.color(QPalette::Base); int value = bkg.value(); if (value > 40) bkg.setHsv( bkg.hue(), bkg.saturation(), value - 11); else bkg.setHsv( bkg.hue(), bkg.saturation(), value + 20 ); currentLineFormat.setBackground(bkg.toRgb()); } setDefault("currentLine", QVariant::fromValue(currentLineFormat)); QTextCharFormat searchResultFormat; searchResultFormat.setBackground(appPlt.color(QPalette::Highlight).darker(200)); searchResultFormat.setForeground(appPlt.color(QPalette::HighlightedText).darker(200)); setDefault("searchResult", QVariant::fromValue(searchResultFormat)); endGroup(); // colors beginGroup("highlighting"); initHighlightingDefaults(); endGroup(); // highlighting endGroup(); // editor endGroup(); // IDE }
static void drawDial ( const QStyleOptionSlider *option, QPainter *painter ) { QPalette pal = option->palette; QColor buttonColor = pal.button().color(); const int width = option->rect.width(); const int height = option->rect.height(); const bool enabled = option->state & QStyle::State_Enabled; qreal r = qMin(width, height) / 2; r -= r/50; const qreal penSize = r/20.0; painter->save(); painter->setRenderHint(QPainter::Antialiasing); // Draw notches if (option->subControls & QStyle::SC_DialTickmarks) { painter->setPen(option->palette.dark().color().darker(120)); painter->drawLines(calcLines(option)); } // Cache dial background QString a = QString::fromLatin1("qdial"); QRect rect = option->rect; QPixmap internalPixmapCache; QImage imageCache; QPainter *p = painter; QString unique = uniqueName((a), option, option->rect.size()); int txType = painter->deviceTransform().type() | painter->worldTransform().type(); bool doPixmapCache = txType <= QTransform::TxTranslate; if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); } else { if (doPixmapCache) { rect.setRect(0, 0, option->rect.width(), option->rect.height()); imageCache = QImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); imageCache.fill(0); p = new QPainter(&imageCache); } //--BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); p->setRenderHint(QPainter::Antialiasing); const qreal d_ = r / 6; const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); buttonColor.setHsv(buttonColor .hue(), qMin(140, buttonColor .saturation()), qMax(180, buttonColor.value())); QColor shadowColor(0, 0, 0, 20); if (enabled) { // Drop shadow qreal shadowSize = qMax(1.0, penSize/2.0); QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, 2*shadowSize, 2*shadowSize); QRadialGradient shadowGradient(shadowRect.center().x(), shadowRect.center().y(), shadowRect.width()/2.0, shadowRect.center().x(), shadowRect.center().y()); shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); shadowGradient.setColorAt(qreal(1.0), Qt::transparent); p->setBrush(shadowGradient); p->setPen(Qt::NoPen); p->translate(shadowSize, shadowSize); p->drawEllipse(shadowRect); p->translate(-shadowSize, -shadowSize); // Main gradient QRadialGradient gradient(br.center().x() - br.width()/3, dy, br.width()*1.3, br.center().x(), br.center().y() - br.height()/2); gradient.setColorAt(0, buttonColor.lighter(110)); gradient.setColorAt(qreal(0.5), buttonColor); gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); gradient.setColorAt(1, buttonColor.darker(115)); p->setBrush(gradient); } else { p->setBrush(Qt::NoBrush); } p->setPen(QPen(buttonColor.darker(280))); p->drawEllipse(br); p->setBrush(Qt::NoBrush); p->setPen(buttonColor.lighter(110)); p->drawEllipse(br.adjusted(1, 1, -1, -1)); if (option->state & QStyle::State_HasFocus) { QColor highlight = pal.highlight().color(); highlight.setHsv(highlight.hue(), qMin(160, highlight.saturation()), qMax(230, highlight.value())); highlight.setAlpha(127); p->setPen(QPen(highlight, 2.0)); p->setBrush(Qt::NoBrush); p->drawEllipse(br.adjusted(-1, -1, 1, 1)); } //--END_STYLE_PIXMAPCACHE if (doPixmapCache) { p->end(); delete p; internalPixmapCache = QPixmap::fromImage(imageCache); painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); QPixmapCache::insert(unique, internalPixmapCache); } } QPointF dp = calcRadialPos(option, qreal(0.70)); buttonColor = buttonColor.lighter(104); buttonColor.setAlphaF(qreal(0.8)); const qreal ds = r/qreal(7.0); QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, dialRect.center().y() + dialRect.width(), dialRect.width()*2, dialRect.center().x(), dialRect.center().y()); dialGradient.setColorAt(1, buttonColor.darker(140)); dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); dialGradient.setColorAt(0, buttonColor.darker(110)); if (penSize > 3.0) { painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); } painter->setBrush(dialGradient); painter->setPen(QColor(255, 255, 255, 150)); painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); painter->setPen(QColor(0, 0, 0, 80)); painter->drawEllipse(dialRect); painter->restore(); }
static inline QColor invertColor(const QColor color) { QColor c = color.toHsv(); c.setHsv(c.hue(), c.saturation(), 255 - c.value()); return c; }
// Write CollectionBlock keywords bool UChromaSession::writeCollectionBlock(LineParser& parser, Collection* collection, Collection::CollectionType type, int indentLevel) { // Construct indent string char* indent = new char[indentLevel*2+1]; for (int n=0; n<indentLevel*2; ++n) indent[n] = ' '; indent[indentLevel*2] = '\0'; if (type == Collection::MasterCollection) parser.writeLineF("%s%s '%s'\n", indent, UChromaSession::inputBlock(UChromaSession::CollectionBlock), qPrintable(collection->name())); else if (type == Collection::FitCollection) parser.writeLineF("%s%s '%s'\n", indent, UChromaSession::collectionKeyword(UChromaSession::FitBlockKeyword), qPrintable(collection->name())); else if (type == Collection::ExtractedCollection) parser.writeLineF("%s%s '%s'\n", indent, UChromaSession::collectionKeyword(UChromaSession::SliceBlockKeyword), qPrintable(collection->name())); parser.writeLineF("%s %s \"%s\"\n", indent, UChromaSession::collectionKeyword(UChromaSession::DataDirectoryKeyword), qPrintable(collection->dataFileDirectory().absolutePath())); // -- Transforms parser.writeLineF("%s %s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::TransformXKeyword), stringBool(collection->transformEnabled(0)), qPrintable(collection->transformEquation(0))); parser.writeLineF("%s %s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::TransformYKeyword), stringBool(collection->transformEnabled(1)), qPrintable(collection->transformEquation(1))); parser.writeLineF("%s %s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::TransformZKeyword), stringBool(collection->transformEnabled(2)), qPrintable(collection->transformEquation(2))); // -- Interpolation parser.writeLineF("%s %s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::InterpolateKeyword), stringBool(collection->interpolate(0)), stringBool(collection->interpolate(2))); parser.writeLineF("%s %s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::InterpolateConstrainKeyword), stringBool(collection->interpolateConstrained(0)), stringBool(collection->interpolateConstrained(2))); parser.writeLineF("%s %s %f %f\n", indent, UChromaSession::collectionKeyword(UChromaSession::InterpolateStepKeyword), collection->interpolationStep(0), collection->interpolationStep(2)); // Colour Setup parser.writeLineF("%s %s '%s'\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourSourceKeyword), Collection::colourSource(collection->colourSource())); ColourScalePoint* csp; QColor colour; double value; // -- Single Colour colour = collection->colourScalePointColour(Collection::SingleColourSource); parser.writeLineF("%s %s %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourSingleKeyword), colour.red(), colour.green(), colour.blue(), colour.alpha()); // -- RGB Gradient colour = collection->colourScalePointColour(Collection::RGBGradientSource, 0); value = collection->colourScalePointValue(Collection::RGBGradientSource, 0); parser.writeLineF("%s %s %f %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourRGBGradientAKeyword), value, colour.red(), colour.green(), colour.blue(), colour.alpha()); colour = collection->colourScalePointColour(Collection::RGBGradientSource, 1); value = collection->colourScalePointValue(Collection::RGBGradientSource, 1); parser.writeLineF("%s %s %f %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourRGBGradientBKeyword), value, colour.red(), colour.green(), colour.blue(), colour.alpha()); // -- HSV Gradient colour = collection->colourScalePointColour(Collection::HSVGradientSource, 0); value = collection->colourScalePointValue(Collection::HSVGradientSource, 0); parser.writeLineF("%s %s %f %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourHSVGradientAKeyword), value, colour.hue(), colour.saturation(), colour.value(), colour.alpha()); colour = collection->colourScalePointColour(Collection::HSVGradientSource, 1); value = collection->colourScalePointValue(Collection::HSVGradientSource, 1); parser.writeLineF("%s %s %f %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourHSVGradientBKeyword), value, colour.hue(), colour.saturation(), colour.value(), colour.alpha()); // -- Custom Gradient for (csp = collection->customColourScalePoints(); csp != NULL; csp = csp->next) { parser.writeLineF("%s %s %f %i %i %i %i\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourCustomGradientKeyword), csp->value(), csp->colour().red(), csp->colour().green(), csp->colour().blue(), csp->colour().alpha()); } // -- Alpha control parser.writeLineF("%s %s '%s'\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourAlphaControlKeyword), Collection::alphaControl(collection->alphaControl())); parser.writeLineF("%s %s %f\n", indent, UChromaSession::collectionKeyword(UChromaSession::ColourAlphaFixedKeyword), collection->fixedAlpha()); // Display parser.writeLineF("%s %s %f '%s'\n", indent, UChromaSession::collectionKeyword(UChromaSession::LineStyleKeyword), collection->displayLineStyle().width(), LineStipple::stipple[collection->displayLineStyle().stipple()].name); parser.writeLineF("%s %s %f\n", indent, UChromaSession::collectionKeyword(UChromaSession::ShininessKeyword), collection->displaySurfaceShininess()); parser.writeLineF("%s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::StyleKeyword), Collection::displayStyle(collection->displayStyle())); parser.writeLineF("%s %s %s\n", indent, UChromaSession::collectionKeyword(UChromaSession::VisibleCollectionKeyword), stringBool(collection->visible())); // Loop over datasets for (DataSet* dataSet = collection->dataSets(); dataSet != NULL; dataSet = dataSet->next) writeDataSetBlock(parser, dataSet, indentLevel); // Write FitKernel data if present if (collection->fitKernel()) writeFitParametersBlock(parser, collection->fitKernel(), indentLevel); // Additional data // -- Fits for (Collection* fit = collection->fits(); fit != NULL; fit = fit->next) writeCollectionBlock(parser, fit, Collection::FitCollection, indentLevel+1); // -- Extracted Data for (Collection* extract = collection->slices(); extract != NULL; extract = extract->next) writeCollectionBlock(parser, extract, Collection::ExtractedCollection, indentLevel+1); parser.writeLineF("%s%s\n", indent, UChromaSession::collectionKeyword(UChromaSession::EndCollectionKeyword)); return true; }
void SectionViewWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.save(); MainFrame* pMainFrame = (MainFrame*)s_pMainFrame; QPen LinePen; LinePen.setColor(QColor(255,0,0)); LinePen.setWidth(2); painter.setPen(LinePen); painter.fillRect(rect(), pMainFrame->m_BackgroundColor); painter.setFont(pMainFrame->m_TextFont); if(m_bZoomIn&& !m_ZoomRect.isEmpty()) { QRect ZRect = m_ZoomRect.normalized(); QPen ZoomPen(QColor(100,100,100)); ZoomPen.setStyle(Qt::DashLine); painter.setPen(ZoomPen); painter.drawRect(ZRect); } if(m_bNeutralLine) { QPen NPen(m_NeutralColor); NPen.setStyle(GetStyle(m_NeutralStyle)); NPen.setWidth(m_NeutralWidth); painter.setPen(NPen); painter.drawLine(rect().right(), m_ptOffset.y(), rect().left(), m_ptOffset.y()); painter.drawLine(m_ptOffset.x(), rect().bottom(), m_ptOffset.x(), rect().top()); } if(!s_bCurrentOnly && m_pSail /* && m_pSail->IsSailcutSail()*/) { QColor clr = m_pSailSection->m_SCSpline.m_SplineColor; clr.setHsv(clr.hue(), (int)(clr.saturation()), (int)(clr.value()*.29)); QPen OtherPen(clr); OtherPen.setStyle(Qt::DashLine); OtherPen.setWidth(1.0); painter.setPen(OtherPen); for(int is=0; is<m_pSail->m_oaSection.size(); is++) { SailSection *pSection = (SailSection*)m_pSail->m_oaSection.at(is); if(pSection != m_pSailSection) { if(m_pSail->IsSailcutSail()) pSection->DrawSpline(painter, m_Scale,m_Scale*m_ScaleY, m_ptOffset, false); else { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); if(is!=index) pNSail->DrawFrame(is, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } } } if(m_pSailSection) { if(m_pSail->IsNURBSSail()) { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); QPen SplinePen; SplinePen.setStyle(GetStyle(m_pSailSection->m_SCSpline.m_Style)); SplinePen.setWidth(m_pSailSection->m_SCSpline.m_Width); SplinePen.setColor(m_pSailSection->m_SCSpline.m_SplineColor); painter.setPen(SplinePen); // if(index==0 || index==m_pSail->m_oaSection.size()-1) { pNSail->DrawFrame(index, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } m_pSailSection->DrawCtrlPoints(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } else { m_pSailSection->DrawSpline(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } QPen TextPen(pMainFrame->m_TextColor); painter.setPen(TextPen); PaintLegend(painter); QString str; str = QString("X-Scale = %1").arg(m_Scale/m_RefScale,4,'f',1); painter.drawText(5,10, str); str = QString("Y-Scale = %1").arg(m_ScaleY*m_Scale/m_RefScale,4,'f',1); painter.drawText(5,22, str); str = QString("x = %1").arg(m_MousePos.x,7,'f',4); painter.drawText(5,34, str); str = QString("y = %1").arg(m_MousePos.y,7,'f',4); painter.drawText(5,46, str); painter.restore(); }
QColor StyleHelper::borderColor(bool lightColored) { QColor result = baseColor(lightColored); result.setHsv(result.hue(), result.saturation(), result.value() / 2); return result; }
QColor StyleHelper::shadowColor(bool lightColored) { QColor result = baseColor(lightColored); result.setHsv(result.hue(), clamp(result.saturation() * 1.1), clamp(result.value() * 0.70)); return result; }
void MainLayer( QImage* img, QImage* canvas, int radius, double strength ) /// /// Paint the main pointillism layer, adding smaller details and more color distortion. /// Points are painted where the color error between the canvas and the original image /// is high. Color difference is based on color intensity (i.e. brightness) to avoid /// difference due to hue distortion. Saturation distortion and divisionism are applied /// in addition to palette restriction. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to be painted to. /// /// @param radius /// The radius of the points being painted. /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { // Adjust the point radius based on the strength of the filter if(strength < 0.5) { int new_radius = (int)radius*strength*2; if(1.0*new_radius < radius*strength*2) new_radius++; radius = new_radius; if(radius < 1) radius = 1; } // Get gray scale of original image uchar* gray = new uchar[img->width()*img->height()]; ImageProcessing::ConvertToOneChannel( img->bits(), gray, img->width(), img->height() ); // Blur the grayscale image uchar* smoothed_gray = new uchar[img->width()*img->height()]; int kernel = radius; if(kernel%2 == 0) kernel++; if(kernel < 3) kernel = 3; ImageProcessing::GaussianBlur( gray, smoothed_gray, img->width(), img->height(), 1, kernel ); delete [] gray; // Clear the depth buffer ready for painting uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // At each grid point, find maximum error based on difference // between intensity at canvas and intensity of blurred image // Paint stroke at this location for( int y = (int)radius/2; y < img->height(); y += radius ) { for( int x = (int)radius/2; x < img->width(); x += radius ) { int total_error = 0; int max_error = 0; QPoint max_error_at = QPoint(0, 0); // Get error of each pixel in the neighbourhood int min_x = x - radius/2; int min_y = y - radius/2; int max_x = x + radius/2; int max_y = y + radius/2; if(min_x < 0) min_x = 0; if(min_y < 0) min_y = 0; if(max_x >= img->width()) max_x = img->width() - 1; if(max_y >= img->height()) max_y = img->height() - 1; for( int j = min_y; j <= max_y; j++ ) { for( int i = min_x; i <= max_x; i++ ) { // Get error at this pixel int intensity = QColor(canvas->pixel( i, j )).toHsv().value(); int error = abs(intensity - smoothed_gray[j*img->width() + i]); // Update error stats total_error += error; if( error > max_error ) { max_error = error; max_error_at = QPoint( i, j ); } } } // If the total error is above a threshold // Paint a stroke at the area of max error if( total_error > 10*strength ) { QColor hsv = QColor(img->pixel( x, y )).toHsv(); int hue = hsv.hue(); int sat = hsv.saturation(); int v = hsv.value(); // Find closest hue in palette, make a method that does this int new_pos = GetPaletteHuePosition( hsv.hue() ); if( (rand()%100)/100.0 < strength ) { hue = GetRandomNeighbour(new_pos); } else { hue = chevreul[new_pos]; } sat = ChangeSaturation(sat, v, 0.35*strength, strength); hsv.setHsv( hue, sat, v ); int z = rand()%256; DrawRandomCircle(canvas, max_error_at, hsv.toRgb(), radius, z, depth_buffer); } } } delete [] smoothed_gray; delete [] depth_buffer; }
void drawDial(const QStyleOptionSlider *option, QPainter *painter) { QPalette pal = option->palette; QColor buttonColor = pal.button().color(); const int width = option->rect.width(); const int height = option->rect.height(); const bool enabled = option->state & QStyle::State_Enabled; qreal r = qMin(width, height) / 2; r -= r/50; const qreal penSize = r/20.0; painter->save(); // Draw notches if (option->subControls & QStyle::SC_DialTickmarks) { painter->setPen(option->palette.dark().color().darker(120)); painter->drawLines(QStyleHelper::calcLines(option)); } // Cache dial background BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); const qreal d_ = r / 6; const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); buttonColor.setHsv(buttonColor .hue(), qMin(140, buttonColor .saturation()), qMax(180, buttonColor.value())); QColor shadowColor(0, 0, 0, 20); if (enabled) { // Drop shadow qreal shadowSize = qMax(1.0, penSize/2.0); QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, 2*shadowSize, 2*shadowSize); QRadialGradient shadowGradient(shadowRect.center().x(), shadowRect.center().y(), shadowRect.width()/2.0, shadowRect.center().x(), shadowRect.center().y()); shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); shadowGradient.setColorAt(qreal(1.0), Qt::transparent); p->setBrush(shadowGradient); p->setPen(Qt::NoPen); p->translate(shadowSize, shadowSize); p->drawEllipse(shadowRect); p->translate(-shadowSize, -shadowSize); // Main gradient QRadialGradient gradient(br.center().x() - br.width()/3, dy, br.width()*1.3, br.center().x(), br.center().y() - br.height()/2); gradient.setColorAt(0, buttonColor.lighter(110)); gradient.setColorAt(qreal(0.5), buttonColor); gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); gradient.setColorAt(1, buttonColor.darker(115)); p->setBrush(gradient); } else { p->setBrush(Qt::NoBrush); } p->setPen(QPen(buttonColor.darker(280))); p->drawEllipse(br); p->setBrush(Qt::NoBrush); p->setPen(buttonColor.lighter(110)); p->drawEllipse(br.adjusted(1, 1, -1, -1)); if (option->state & QStyle::State_HasFocus) { QColor highlight = pal.highlight().color(); highlight.setHsv(highlight.hue(), qMin(160, highlight.saturation()), qMax(230, highlight.value())); highlight.setAlpha(127); p->setPen(QPen(highlight, 2.0)); p->setBrush(Qt::NoBrush); p->drawEllipse(br.adjusted(-1, -1, 1, 1)); } END_STYLE_PIXMAPCACHE QPointF dp = calcRadialPos(option, qreal(0.70)); buttonColor = buttonColor.lighter(104); buttonColor.setAlphaF(qreal(0.8)); const qreal ds = r/qreal(7.0); QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, dialRect.center().y() + dialRect.width(), dialRect.width()*2, dialRect.center().x(), dialRect.center().y()); dialGradient.setColorAt(1, buttonColor.darker(140)); dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); dialGradient.setColorAt(0, buttonColor.darker(110)); if (penSize > 3.0) { painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); } painter->setBrush(dialGradient); painter->setPen(QColor(255, 255, 255, 150)); painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); painter->setPen(QColor(0, 0, 0, 80)); painter->drawEllipse(dialRect); painter->restore(); }
void EdgeLayer(QImage* img, QImage* canvas, int radius, double hue_distortion, double strength) /// /// This final layer repaints over areas determined to be edges in order to bring smaller details /// that have been covered by points back into the picture. The same color distortions are used /// as in the main layer. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to be painted to. /// /// @param radius /// The radius of the points to be painted. /// /// @param hue_distortion /// Determines the strength of the hue distortion where 1.0 is very distorted and 0.0 is not distorted. /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { hue_distortion = hue_distortion*strength; if( strength < 0.5 ) { int new_radius = (int)radius*strength*2; if( 1.0*new_radius < radius*strength*2 ) new_radius++; radius = new_radius; if( radius < 1 ) radius = 1; } uchar* edges = new uchar[img->width()*img->height()]; ImageProcessing::CannyEdgeDetection( img->bits(), edges, img->width(), img->height(), 4 ); uchar* gray = new uchar[img->width()*img->height()]; ImageProcessing::ConvertToOneChannel( img->bits(), gray, img->width(), img->height()); uchar* smoothed_gray = new uchar[img->width()*img->height()]; int kernel = radius; if(kernel%2 == 0) kernel++; if(kernel < 3) kernel = 3; ImageProcessing::GaussianBlur( gray, smoothed_gray, img->width(), img->height(), 1, kernel ); delete [] gray; // Clear the depth buffer ready for painting uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // If there is an edge, find the greatest error in the edge's neighbourhood // and at a new stroke at this point. for( int y = 0; y < img->height(); y++ ) { for( int x = 0; x < img->width(); x++ ) { if( edges[y*img->width() + x] > 0 ) { // Find the brightest and and darkest spots in the neighbourhood int brightest = 0; int darkest = 255; QPoint brightest_pos = QPoint(0, 0); QPoint darkest_pos = QPoint(0, 0); for( int j = y - radius; j <= y + radius; j++ ) { for( int i = x - radius; i <= x + radius; i++ ) { if( i >= 0 && j >= 0 && i < img->width() && j < img->height() ) { int intensity = smoothed_gray[j*img->width() + i]; if(intensity > brightest) { brightest_pos = QPoint(i, j); brightest = intensity; } if(intensity < darkest) { darkest_pos = QPoint(i, j); darkest = intensity; } } } } // For each position in the neighbourhood, find if most spots // are closer to the brightest or darkest int dark = 0; int bright = 0; for( int j = y - radius; j <= y + radius; j++ ) { for( int i = x - radius; i <= x + radius; i++ ) { if( i >= 0 && j >= 0 && i < img->width() && j < img->height() ) { int intensity = smoothed_gray[j*img->width() + i]; int bright_diff = brightest - intensity; int dark_diff = intensity - darkest; if(bright_diff < dark_diff) { bright++; } else { dark++; } } } } // Paint at the side that needs defining QPoint new_point; if(bright < dark && bright != 0) { new_point = brightest_pos; } else if(dark != 0) { new_point = darkest_pos; } else { new_point = QPoint(x, y); } // Paint circle at this position QColor hsv = QColor(img->pixel( new_point )).toHsv(); int hue = hsv.hue(); int val = hsv.value(); int sat = hsv.saturation(); // Find closest hue in palette int new_pos = GetPaletteHuePosition( hsv.hue() ); if( ( rand()%100)/100.0 < strength ) { hue = GetRandomNeighbour( new_pos ); } else { hue = chevreul[new_pos]; } // Hue distortion double r = ( rand()%100 )/100.0; if( ( r < hue_distortion && new_pos != 8 ) || r < hue_distortion/3 ) { int n = ChangeHue(smoothed_gray[new_point.y()*img->width() + new_point.x()]/256.0)*2; if( n > -1 ) { new_pos = n; if( sat < 70 && val < 0.3 ) sat = 70; } hue = chevreul[new_pos]; } sat = ChangeSaturation( sat, val, 0.35*strength, strength ); int z = rand()%256; hsv.setHsv( hue, sat, val ); DrawRandomCircle( canvas, new_point, hsv.toRgb(), radius - 1, z, depth_buffer ); } } } delete [] smoothed_gray; delete [] edges; delete [] depth_buffer; }
bool navproCore::getStdDeviation(int rangeX, int rangeY, int *hue, int *sat, int *cb, int *cr) { QColor hsv; int i,j; *hue = 0; *sat = 0; *cb = 0; *cr = 0; if (rangeX < 0 || rangeX > image.width()) return false; if (rangeY < 0 || rangeY > image.height()) return false; for (i = posX; i < rangeX + posX; ++i) { for (j = posY; j < rangeY + posY; ++j) { hsv = QColor::fromRgb(image.pixel(i,j)); *hue += hsv.hue(); *sat += hsv.saturation(); *cb += RGB2CB(image.pixel(i,j)); *cr += RGB2CR(image.pixel(i,j)); } } //mean == average value int meanHue = *hue/(rangeX * rangeY); int meanSat = *sat/(rangeX * rangeY); int meanCb = *cb/(rangeX * rangeY); int meanCr = *cr/(rangeX * rangeY); //std::cout<<"mean: H: "<<meanHue<<" S: "<<meanSat<<" cb: "<<meanCb<<" cr: "<<meanCr<<std::endl; quint32 varianceHue = 0; quint32 varianceSat = 0; quint32 varianceCb = 0; quint32 varianceCr = 0; for (i = 0; i < rangeX; ++i) { for (j = 0; j < rangeY; ++j) { hsv = QColor::fromRgb(image.pixel(i,j)); varianceHue += qAbs(meanHue - hsv.hue()) * qAbs(meanHue - hsv.hue()); varianceSat += qAbs(meanSat - hsv.saturation()) * qAbs(meanSat - hsv.saturation()); varianceCb += qAbs(meanCb - RGB2CB(image.pixel(i,j))) * qAbs(meanHue - RGB2CB(image.pixel(i,j))); varianceCr += qAbs(meanCr - RGB2CR(image.pixel(i,j))) * qAbs(meanHue - RGB2CR(image.pixel(i,j))); } } *hue = qSqrt(varianceHue/(rangeX * rangeY)); *sat = qSqrt(varianceSat/(rangeX * rangeY)); *cb = qSqrt(varianceCb/(rangeX * rangeY)); *cr = qSqrt(varianceCr/(rangeX * rangeY)); //std::cout<<"variance: H: "<<varianceHue<<" S: "<<varianceSat<<" cb: "<<varianceCb<<" cr: "<<varianceCr<<std::endl; //std::cout<<"SD: H: "<<*hue<<" S: "<<*sat<<" cb: "<<*cb<<" cr: "<<*cr<<std::endl; return true; }
void LoadShotsWithinAVBox (MISC *misc, OPTIONS *options, nvMap *map, NV_I32_COORD2 targetPt) { NV_FLOAT64 dz; NV_INT32 xyz_x, xyz_y, xyz_z, lock_point; NV_I32_COORD2 llSquare, urSquare; int numShots = 0; NV_BOOL hitMax = NVFalse; QColor color; QColor GetAVShotColor (NV_INT32 index, MISC *misc, OPTIONS *options); if (misc->nearest_point != -1) { llSquare.x = targetPt.x - misc->avb.avInterfacePixelBuffer; llSquare.y = targetPt.y + misc->avb.avInterfacePixelBuffer; urSquare.x = targetPt.x + misc->avb.avInterfacePixelBuffer; urSquare.y = targetPt.y - misc->avb.avInterfacePixelBuffer; // load the target pt first lock_point = misc->nearest_point; // Get the screen coordinates of the primary cursor. Make sure it is within the AV ROI box. // It is possible that it could be outside in the event that everything within the AV box is deleted by the AV map->map_to_screen (1, &misc->data[lock_point].x, &misc->data[lock_point].y, &dz, &xyz_x, &xyz_y, &xyz_z); if ((xyz_x <= urSquare.x) && (xyz_x >= llSquare.x) && (xyz_y >= urSquare.y) && (xyz_y <= llSquare.y) && misc->data[lock_point].type == PFM_CZMIL_DATA) { misc->avb.shotArray[numShots].recordNumber = misc->data[lock_point].rec; misc->avb.shotArray[numShots].pfmHandle = misc->pfm_handle[misc->data[lock_point].pfm]; misc->avb.shotArray[numShots].fileNo = misc->data[lock_point].file; misc->avb.shotArray[numShots].type = misc->data[lock_point].type; // Save the master idx misc->avb.shotArray[numShots].masterIdx = lock_point; color = GetAVShotColor (lock_point, misc, options); misc->avb.shotArray[numShots].colorH = color.hue (); misc->avb.shotArray[numShots].colorS = color.saturation(); misc->avb.shotArray[numShots].colorV = color.value(); numShots++; } for (NV_INT32 i = 0 ; i < misc->abe_share->point_cloud_count ; i++) { if (i != lock_point) { // Check for single line display. if (!misc->num_lines || check_line (misc, misc->data[i].line)) { // Do not use null points. Do not use invalid points unless the // display_invalid flag is set. Do not check points that are not on the // display. if (!check_bounds (options, misc, i, NVTrue, misc->slice)) { map->map_to_screen (1, &misc->data[i].x, &misc->data[i].y, &dz, &xyz_x, &xyz_y, &xyz_z); // Check the area and the data type ('cause there might be mixed types in the editor). if ((xyz_x <= urSquare.x) && (xyz_x >= llSquare.x) && (xyz_y >= urSquare.y) && (xyz_y <= llSquare.y) && misc->data[i].type == PFM_CZMIL_DATA) { if (numShots == MAX_ATTRIBUTE_SHOTS) { hitMax = NVTrue; break; } misc->avb.shotArray[numShots].recordNumber = misc->data[i].rec; misc->avb.shotArray[numShots].subRecordNumber = misc->data[i].sub; misc->avb.shotArray[numShots].pfmHandle = misc->pfm_handle[misc->data[i].pfm]; misc->avb.shotArray[numShots].fileNo = misc->data[i].file; misc->avb.shotArray[numShots].masterIdx = i; misc->avb.shotArray[numShots].type = misc->data[i].type; color = GetAVShotColor (i, misc, options); misc->avb.shotArray[numShots].colorH = color.hue (); misc->avb.shotArray[numShots].colorS = color.saturation(); misc->avb.shotArray[numShots].colorV = color.value(); numShots++; } } } } } } misc->abeShare->lock (); for (int i = 0; i < numShots; i++) misc->abe_share->avShare.shots[i] = misc->avb.shotArray[i]; misc->abe_share->avShare.numShots = numShots; misc->abe_share->avShare.avNewData = NVTrue; misc->abe_share->avShare.hitMax = hitMax; misc->abeShare->unlock (); }
void tst_QColor::setHsv() { QColor color; for (int A = 0; A <= USHRT_MAX; ++A) { { // 0-255 int a = A >> 8; color.setHsv(0, 0, 0, a); QCOMPARE(color.alpha(), a); int h, s, v, a2; color.getHsv(&h, &s, &v, &a2); QCOMPARE(a2, a); } { // 0.0-1.0 qreal a = A / qreal(USHRT_MAX); color.setHsvF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a); qreal h, s, v, a2; color.getHsvF(&h, &s, &v, &a2); QCOMPARE(a2, a); } } for (int H = 0; H < 36000; ++H) { { // 0-255 int h = H / 100; color.setHsv(h, 0, 0, 0); QCOMPARE(color.hue(), h); int h2, s, v, a; color.getHsv(&h2, &s, &v, &a); QCOMPARE(h2, h); } { // 0.0-1.0 qreal h = H / 36000.0; color.setHsvF(h, 0.0, 0.0, 0.0); QCOMPARE(color.hueF(), h); qreal h2, s, v, a; color.getHsvF(&h2, &s, &v, &a); QCOMPARE(h2, h); } } for (int S = 0; S <= USHRT_MAX; ++S) { { // 0-255 int s = S >> 8; color.setHsv(0, s, 0, 0); QCOMPARE(color.saturation(), s); int h, s2, v, a; color.getHsv(&h, &s2, &v, &a); QCOMPARE(s2, s); } { // 0.0-1.0 qreal s = S / qreal(USHRT_MAX); color.setHsvF(0.0, s, 0.0, 0.0); QCOMPARE(color.saturationF(), s); qreal h, s2, v, a; color.getHsvF(&h, &s2, &v, &a); QCOMPARE(s2, s); } } for (int V = 0; V <= USHRT_MAX; ++V) { { // 0-255 int v = V >> 8; color.setHsv(0, 0, v, 0); QCOMPARE(color.value(), v); int h, s, v2, a; color.getHsv(&h, &s, &v2, &a); QCOMPARE(v2, v); } { // 0.0-1.0 qreal v = V / qreal(USHRT_MAX); color.setHsvF(0.0, 0.0, v, 0.0); QCOMPARE(color.valueF(), v); qreal h, s, v2, a; color.getHsvF(&h, &s, &v2, &a); QCOMPARE(v2, v); } } }