void ColorWheel::mouseMoveEvent(QMouseEvent *event) { lastPos = event->pos(); if( !mouseDown ) return; if(wheelRegion.contains(lastPos) && inWheel){ QColor color = posColor(lastPos); hueChanged(color.hue()); }else if(squareRegion.contains(lastPos) && inSquare){ QColor color = posColor(lastPos); svChanged(color); }else{ // TODO: due with cursor out of region after press // int length = qMin(width(), height()); // QPoint center(length/2, length/2); // int R = qSqrt(qPow(qAbs(lastPos.x()), 2) // + qPow(qAbs(lastPos.y()), 2)); // if(inWheel){ // int r = length / 2; // r += qSqrt(qPow(center.x(), 2) + qPow(center.y(), 2)); // int x0 = r/R * qAbs(lastPos.x()); // int y0 = r/R * qAbs(lastPos.y()); // QColor color = posColor(QPoint(x0, y0)); // hueChanged(color.hue()); // }else if(inSquare){ // // // } } }
void ColorWheel::mouseMoveEvent(QMouseEvent* e) { lastPos_ = e->pos(); if (!mouseDown_) return; if (wheelRegion_.contains(lastPos_) && inWheel_) { QColor color = posColor(lastPos_); hueChanged(color.hue()); } else if (squareRegion_.contains(lastPos_) && inSquare_) { QColor color = posColor(lastPos_); svChanged(color); } else { int length = qMin(width(), height()); QPoint center(length/2, length/2); if (inWheel_) { int r = length / 2; double x0 = lastPos_.x()-center.x(); double y0 = lastPos_.y()-center.y(); double vNorm = qSqrt(qPow(x0,2)+qPow(y0,2)); double x1 = r*(x0/vNorm); double y1 = r*(y0/vNorm); x1 += center.x(); y1 += center.y(); QColor color = posColor(QPoint(x1, y1)); hueChanged(color.hue()); } else if (inSquare_) { int w = qMin(width(), height()); // radius of outer circle qreal r = w/2-margin_; // radius of inner circle qreal ir = r-wheelWidth_; // left corner of square qreal m = w/2.0-ir/qSqrt(2); float x0 = 0.0f; float y0 = 0.0f; float w0 = squareRegion_.boundingRect().width(); if (lastPos_.x() > m + w0) x0 = m + w0; else if (lastPos_.x() < m) x0 = m; else x0 = lastPos_.x(); if (lastPos_.y() > m + w0) y0 = m + w0; else if (lastPos_.y() < m) y0 = m; else y0 = lastPos_.y(); QColor color = posColor(QPoint(x0, y0)); svChanged(color); } } }
void ColorWheel::mousePressEvent(QMouseEvent *event) { lastPos = event->pos(); if(wheelRegion.contains(lastPos)){ inWheel = true; inSquare = false; QColor color = posColor(lastPos); hueChanged(color.hue()); }else if(squareRegion.contains(lastPos)){ inWheel = false; inSquare = true; QColor color = posColor(lastPos); svChanged(color); } mouseDown = true; }
void ColorWheel::mousePressEvent(QMouseEvent* e) { lastPos_ = e->pos(); if (wheelRegion_.contains(lastPos_)) { inWheel_ = true; inSquare_ = false; QColor color = posColor(lastPos_); if (e->button()==Qt::RightButton) hueChanged(color.hue()); else setColor(color); } else if (squareRegion_.contains(lastPos_)) { inWheel_ = false; inSquare_ = true; QColor color = posColor(lastPos_); svChanged(color); } mouseDown_ = true; }
Model::Model(const aligned_vector3f &positions, const aligned_vector3f &colors, bool centerAndScale, int mode, float size) : SceneObject(), mode(mode), positions(positions) { aligned_vectorPosColor posAndColors; for (uint i = 0; i < positions.size(); ++i) { posAndColors.push_back(PositionColor(positions[i], colors[i])); } VBOInfo posColor(0,-1,sizeof(Vector3f)); vbo = shared_ptr<VBO>(new VBO(posAndColors, posColor, GL_STATIC_DRAW)); if (centerAndScale) init(size); else { center.setZero(3); scale = 1.0; } }