Example #1
0
void KisColorSelector::mouseMoveEvent(QMouseEvent* event)
{
    QPointF dragPos           = mapCoord(event->posF(), m_renderArea);
    qint8   clickedLightPiece = getLightIndex(event->posF());
    
    if (clickedLightPiece >= 0) {
        setLight(getLight(event->posF()), m_relativeLight);
        m_selectedLightPiece = clickedLightPiece;
        setSelectedColor(m_selectedColor, m_selectedColorIsFgColor, true);
    }
    
    if (m_clickedRing < 0)
        return;
    
    if (getNumPieces() > 1) {
        float angle     = std::atan2(dragPos.x(), dragPos.y()) - std::atan2(m_clickPos.x(), m_clickPos.y());
        float dist      = std::sqrt(dragPos.x()*dragPos.x() + dragPos.y()*dragPos.y()) * 0.80f;
        float threshold = 5.0f * (1.0f-(dist*dist));
        
        if (qAbs(angle * TO_DEG) >= threshold || m_mouseMoved) {
            bool selectedRingMoved = true;
            
            if (m_pressedButtons & Qt::RightButton) {
                selectedRingMoved                 = m_clickedRing == m_selectedRing;
                m_colorRings[m_clickedRing].angle = m_colorRings[m_clickedRing].tmpAngle + angle;
            }
            else for(int i=0; i<getNumRings(); ++i)
                m_colorRings[i].angle = m_colorRings[i].tmpAngle + angle;
            
            if (selectedRingMoved) {
                KisColor color = m_colorRings[m_clickedRing].tmpColor;
                Radian   angle = m_colorRings[m_clickedRing].getMovedAngel() + (color.getH()*PI2);
                color.setH(angle.scaled(0.0f, 1.0f));
                color.setX(getLight(m_light, color.getH(), m_relativeLight));
                
                m_selectedPiece = getHueIndex(angle, m_colorRings[m_clickedRing].getShift());
                setSelectedColor(color, m_selectedColorIsFgColor, true);
            }
            
            m_mouseMoved = true;
        }
    }
    else {
        Radian angle = std::atan2(dragPos.x(), dragPos.y()) - RAD_90;
        m_selectedColor.setH(angle.scaled(0.0f, 1.0f));
        m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), m_relativeLight));
        setSelectedColor(m_selectedColor, m_selectedColorIsFgColor, true);
    }
    
    update();
}
Example #2
0
KisColor::KisColor(const KisColor& color, KisColor::Type type)
{
    if(color.getType() == type)
        initHSX(type, color.getH(), color.getS(), color.getX(), color.getA());
    else
        initRGB(type, color.getR(), color.getG(), color.getB(), color.getA());
}
Example #3
0
KisColor::KisColor(const KisColor& color)
{
    initHSX(color.getType(), color.getH(), color.getS(), color.getX(), color.getA());
}