QString ScColor::nameRGB(const ScribusDoc* doc) { if ((m_Model != colorModelRGB) && (!doc)) qDebug("calling nameRGB with a cmyk color"); int r, g, b; RGBColor rgb; QString tmp, name = CommonStrings::None; ScColorEngine::getRGBValues(*this, doc, rgb); rgb.getValues(r, g, b); name="#"; tmp.setNum(r, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; tmp.setNum(g, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; tmp.setNum(b, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; return name; }
QPalette CMYKChoose::sliderPix(int farbe) { RGBColor rgb; CMYKColor cmyk; QImage image0 = QImage(255, 10, QImage::Format_ARGB32); QPainter p; p.begin(&image0); p.setPen(Qt::NoPen); int r, g, b, c, m, y, k; QColor tmp; for (int x = 0; x < 255; x += 5) { if (Farbe.getColorModel() == colorModelCMYK) { ScColorEngine::getCMYKValues(Farbe, m_doc, cmyk); cmyk.getValues(c, m, y, k); if (dynamic) { switch (farbe) { case 180: tmp = ScColorEngine::getDisplayColorGC(ScColor(x, m, y, k), m_doc); break; case 300: tmp = ScColorEngine::getDisplayColorGC(ScColor(c, x, y, k), m_doc); break; case 60: tmp = ScColorEngine::getDisplayColorGC(ScColor(c, m, x, k), m_doc); break; } p.setBrush(tmp); } else { switch (farbe) { case 180: tmp = ScColorEngine::getDisplayColorGC(ScColor(x, 0, 0, 0), m_doc); break; case 300: tmp = ScColorEngine::getDisplayColorGC(ScColor(0, x, 0, 0), m_doc); break; case 60: tmp = ScColorEngine::getDisplayColorGC(ScColor(0, 0, x, 0), m_doc); break; } p.setBrush(tmp); } } else if (Farbe.getColorModel() == colorModelRGB) { ScColorEngine::getRGBValues(Farbe, m_doc, rgb); rgb.getValues(r, g, b); if (dynamic) { switch (farbe) { case 0: tmp = ScColorEngine::getDisplayColorGC(ScColor(x, g, b), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(r, x, b), m_doc); break; case 240: tmp = ScColorEngine::getDisplayColorGC(ScColor(r, g, x), m_doc); break; } p.setBrush(tmp); } else { switch (farbe) { case 0: tmp = ScColorEngine::getDisplayColorGC(ScColor(x, 0, 0), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(0, x, 0), m_doc); break; case 240: tmp = ScColorEngine::getDisplayColorGC(ScColor(0, 0, x), m_doc); break; } p.setBrush(tmp); } } else if (Farbe.getColorModel() == colorModelLab) { double L, a, b; double val = static_cast<double>(x) / 255.0; Farbe.getLab(&L, &a, &b); if (isHLC) { QLineF lin; lin.setP1(QPointF(0.0, 0.0)); lin.setP2(QPointF(a, b)); double H = lin.angle(); double C = lin.length(); double tmpA, tmpB; if (dynamic) { switch (farbe) { case 0: lin = QLineF::fromPolar(C, -360 * val); tmpA = lin.p2().x(); tmpB = lin.p2().y(); tmp = ScColorEngine::getDisplayColorGC(ScColor(L, tmpA, tmpB), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(100 * val, a, b), m_doc); break; case 240: lin = QLineF::fromPolar(128 * val, H); tmpA = lin.p2().x(); tmpB = lin.p2().y(); tmp = ScColorEngine::getDisplayColorGC(ScColor(L, tmpA, tmpB), m_doc); break; } p.setBrush(tmp); } else { switch (farbe) { case 0: lin = QLineF::fromPolar(128, -360 * val); tmpA = lin.p2().x(); tmpB = lin.p2().y(); tmp = ScColorEngine::getDisplayColorGC(ScColor(100.0, tmpA, tmpB), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(100 * val, 0.0, 0.0), m_doc); break; case 240: lin = QLineF::fromPolar(128 * val, 0); tmpA = lin.p2().x(); tmpB = lin.p2().y(); tmp = ScColorEngine::getDisplayColorGC(ScColor(100.0, tmpA, tmpB), m_doc); break; } p.setBrush(tmp); } } else { if (dynamic) { switch (farbe) { case 0: tmp = ScColorEngine::getDisplayColorGC(ScColor(100 * val, a, b), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(L, 256 * val - 128.0, b), m_doc); break; case 240: tmp = ScColorEngine::getDisplayColorGC(ScColor(L, a, 256 * val - 128.0), m_doc); break; } p.setBrush(tmp); } else { switch (farbe) { case 0: tmp = ScColorEngine::getDisplayColorGC(ScColor(100 * val, 0.0, 0.0), m_doc); break; case 120: tmp = ScColorEngine::getDisplayColorGC(ScColor(100.0, 256 * val - 128.0, 0.0), m_doc); break; case 240: tmp = ScColorEngine::getDisplayColorGC(ScColor(100.0, 0.0, 256 * val - 128.0), m_doc); break; } } p.setBrush(tmp); } } p.drawRect(x, 0, 5, 10); } p.end(); QPalette pal; pal.setBrush(QPalette::Window, QBrush(image0)); return pal; }
void CMYKChoose::setValues() { CyanSp->blockSignals(true); CyanSL->blockSignals(true); MagentaSp->blockSignals(true); MagentaSL->blockSignals(true); YellowSp->blockSignals(true); YellowSL->blockSignals(true); BlackSp->blockSignals(true); BlackSL->blockSignals(true); if (Farbe.getColorModel() == colorModelCMYK) { CMYKColor cmyk; int cc, cm, cy, ck; ScColorEngine::getCMYKValues(Farbe, m_doc, cmyk); cmyk.getValues(cc, cm, cy, ck); CyanSp->setValue(cc / 2.55); CyanSL->setValue(qRound(cc / 2.55) * 1000.0); MagentaSp->setValue(cm / 2.55); MagentaSL->setValue(qRound(cm / 2.55) * 1000.0); YellowSp->setValue(cy / 2.55); YellowSL->setValue(qRound(cy / 2.55) * 1000.0); BlackSp->setValue(ck / 2.55); BlackSL->setValue(qRound(ck / 2.55) * 1000.0); if (dynamic) { CyanSL->setPalette(sliderPix(180)); MagentaSL->setPalette(sliderPix(300)); YellowSL->setPalette(sliderPix(60)); BlackSL->setPalette(sliderBlack()); } } else if (Farbe.getColorModel() == colorModelRGB) { RGBColor rgb; int r, g, b; ScColorEngine::getRGBValues(Farbe, m_doc, rgb); rgb.getValues(r, g, b); CyanSp->setValue(static_cast<double>(r)); CyanSL->setValue(r * 1000.0); MagentaSp->setValue(static_cast<double>(g)); MagentaSL->setValue(g * 1000.0); YellowSp->setValue(static_cast<double>(b)); YellowSL->setValue(b * 1000.0); int h, s, v; ScColorEngine::getRGBColor(Farbe, m_doc).getHsv(&h, &s, &v); BlackComp = 255 - v; if (dynamic) { CyanSL->setPalette(sliderPix(0)); MagentaSL->setPalette(sliderPix(120)); YellowSL->setPalette(sliderPix(240)); } } else if (Farbe.getColorModel() == colorModelLab) { double L, a, b; Farbe.getLab(&L, &a, &b); if (isHLC) { MagentaSp->setValue(L); MagentaSL->setValue(L * 1000.0); QLineF lin; lin.setP1(QPointF(0.0, 0.0)); lin.setP2(QPointF(a, b)); CyanSp->setValue(360 - lin.angle()); CyanSL->setValue(360 - lin.angle() * 1000.0); YellowSp->setValue(lin.length()); YellowSL->setValue(lin.length() * 1000.0); } else { CyanSp->setValue(L); CyanSL->setValue(L * 1000.0); MagentaSp->setValue(a); MagentaSL->setValue(a * 1000.0); YellowSp->setValue(b); YellowSL->setValue(b * 1000.0); } if (dynamic) { CyanSL->setPalette(sliderPix(0)); MagentaSL->setPalette(sliderPix(120)); YellowSL->setPalette(sliderPix(240)); } } CyanSp->blockSignals(false); CyanSL->blockSignals(false); MagentaSp->blockSignals(false); MagentaSL->blockSignals(false); YellowSp->blockSignals(false); YellowSL->blockSignals(false); BlackSp->blockSignals(false); BlackSL->blockSignals(false); }