Esempio n. 1
0
/*!
   Adjust the plot axes scales

   \param oldSize Previous size of the canvas
   \param newSize New size of the canvas
*/
void QwtPlotRescaler::rescale(
    const QSize &oldSize, const QSize &newSize ) const
{
    if ( newSize.isEmpty() )
        return;

    QwtInterval intervals[QwtPlot::axisCnt];
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
        intervals[axis] = interval( axis );

    const int refAxis = referenceAxis();
    intervals[refAxis] = expandScale( refAxis, oldSize, newSize );

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( aspectRatio( axis ) > 0.0 && axis != refAxis )
            intervals[axis] = syncScale( axis, intervals[refAxis], newSize );
    }

    updateScales( intervals );
}
void
TransitionWidget::resizeEvent(QResizeEvent* /*event*/)
{
	updateScales();
}
// Note: with no antialiasing, the coordinates in QPointF are rounded to the nearest integer.
void
TransitionWidget::paintEvent(QPaintEvent*)
{
	if (pointList_ == nullptr) {
		return;
	}

	QPainter painter(this);
	painter.setFont(QFont("monospace"));

	if (dataUpdated_) {
		QFontMetrics fm = painter.fontMetrics();
		textYOffset_ = 0.5 * fm.ascent();
		leftMargin_ = MARGIN + TEXT_MARGIN + fm.width(transitionYLabels[0]);
		updateScales();

		dataUpdated_ = false;
	}

	if (special_) {
		// Gray area.
		painter.fillRect(QRectF(QPointF(leftMargin_, MARGIN + 7.0 * yStep_), QPointF(leftMargin_ + graphWidth_, MARGIN + 14.0 * yStep_)), Qt::gray);

		// Y labels.
		for (unsigned int i = 0; i < specialTransitionYLabels.size(); ++i) {
			double y = MARGIN + i * yStep_ + textYOffset_;
			painter.drawText(QPointF(MARGIN, y), specialTransitionYLabels[i]);
			painter.drawText(QPointF(leftMargin_ + graphWidth_ + TEXT_MARGIN, y), specialTransitionYLabels[i]);
		}
	} else {
		// Gray areas.
		painter.fillRect(QRectF(QPointF(leftMargin_, MARGIN), QPointF(leftMargin_ + graphWidth_, MARGIN + 2.0 * yStep_)), Qt::gray);
		painter.fillRect(QRectF(QPointF(leftMargin_, MARGIN + 12.0 * yStep_), QPointF(leftMargin_ + graphWidth_, MARGIN + 14.0 * yStep_)), Qt::gray);

		// Y labels.
		for (unsigned int i = 0; i < transitionYLabels.size(); ++i) {
			double y = MARGIN + i * yStep_ + textYOffset_;
			painter.drawText(QPointF(MARGIN, y), transitionYLabels[i]);
			painter.drawText(QPointF(leftMargin_ + graphWidth_ + TEXT_MARGIN, y), transitionYLabels[i]);
		}
	}
	// Horizontal lines.
	for (int i = 0; i < 15; ++i) {
		double y = MARGIN + i * yStep_;
		painter.drawLine(QPointF(leftMargin_, y), QPointF(leftMargin_ + graphWidth_, y));
	}

	QPen pen;
	QPen pen2;
	pen2.setWidth(2);

	painter.setRenderHint(QPainter::Antialiasing);

	// Lines.
	if (!pointList_->empty()) {
		painter.setPen(pen2);

		QPointF prevP(0.5 + timeToX(0.0), 0.5 + valueToY(0.0));

		for (unsigned int i = 0, size = pointList_->size(); i < size; ++i) {
			const auto& point = (*pointList_)[i];
			QPointF p(0.5 + timeToX(point.time), 0.5 + valueToY(point.value));
			painter.drawLine(prevP, p);

			prevP = p;
			if (i != size - 1) {
				if (point.type != (*pointList_)[i + 1].type) {
					prevP.setY(0.5 + valueToY(0.0));
				}
			}
		}

		QPointF p(0.5 + timeToX(ruleDuration_), 0.5 + valueToY(special_ ? 0.0 : 100.0));
		painter.drawLine(prevP, p);

		painter.setPen(pen);
	}

	painter.setBrush(QBrush(Qt::black));

	// Points.
	if (!pointList_->empty()) {
		for (auto& point : *pointList_) {
			double x = 0.5 + timeToX(point.time);
			double y = 0.5 + valueToY(point.value);
			switch (point.type) {
			case TRMControlModel::Transition::Point::TYPE_DIPHONE:
				drawDiPoint(painter, x, y);
				break;
			case TRMControlModel::Transition::Point::TYPE_TRIPHONE:
				drawTriPoint(painter, x, y);
				break;
			case TRMControlModel::Transition::Point::TYPE_TETRAPHONE:
				drawTetraPoint(painter, x, y);
				break;
			default:
				break;
			}
		}
	}

	// Posture markers.
	double yMarker = 0.5 + 0.5 * yStep_ + textYOffset_;
	switch (transitionType_) {
	case TRMControlModel::Transition::TYPE_DIPHONE:
		drawDiPoint(painter, 0.5 + timeToX(ruleDuration_), yMarker);
		break;
	case TRMControlModel::Transition::TYPE_TRIPHONE:
		drawDiPoint( painter, 0.5 + timeToX(mark1_)       , yMarker);
		drawTriPoint(painter, 0.5 + timeToX(ruleDuration_), yMarker);
		break;
	case TRMControlModel::Transition::TYPE_TETRAPHONE:
		drawDiPoint(   painter, 0.5 + timeToX(mark1_)       , yMarker);
		drawTriPoint(  painter, 0.5 + timeToX(mark2_)       , yMarker);
		drawTetraPoint(painter, 0.5 + timeToX(ruleDuration_), yMarker);
		break;
	default:
		break;
	}

	painter.setBrush(QBrush());
	painter.setRenderHint(QPainter::Antialiasing, false);

	// Posture vertical lines.
	double yPosture1 = special_ ? valueToY(-140.0) : valueToY(-20.0);
	double yPosture2 = special_ ? valueToY( 140.0) : valueToY(120.0);

	double x = timeToX(0.0);
	painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));

	switch (transitionType_) {
	case TRMControlModel::Transition::TYPE_DIPHONE:
		x = timeToX(ruleDuration_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		break;
	case TRMControlModel::Transition::TYPE_TRIPHONE:
		x = timeToX(mark1_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		x = timeToX(ruleDuration_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		break;
	case TRMControlModel::Transition::TYPE_TETRAPHONE:
		x = timeToX(mark1_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		x = timeToX(mark2_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		x = timeToX(ruleDuration_);
		painter.drawLine(QPointF(x, yPosture1), QPointF(x, yPosture2));
		break;
	default:
		break;
	}

	if (!pointList_->empty()) {
		if (!special_) {
			// Slopes.
			double y1 = MARGIN + 15.0 * yStep_;
			double y2 = y1 + yStep_;
			double yText = y2 - 0.5 * yStep_ + textYOffset_;
			for (unsigned int i = 0, end = pointList_->size() - 1; i < end; ++i) {
				const auto& point1 = (*pointList_)[i];
				if (point1.hasSlope) {
					const auto& point2 = (*pointList_)[i + 1];
					painter.setPen(Qt::gray);
					painter.drawRect(QRectF(QPointF(timeToX(point1.time), y1), QPointF(timeToX(point2.time), y2)));
					painter.setPen(Qt::black);

					painter.drawText(
						QPointF(timeToX(point1.time) + SLOPE_TEXT_MARGIN, yText),
						QString("%1").arg(point1.slope, 0, 'f', 1));
				}
			}
		}

		// Selected point.
		if (selectedPointIndex_ >= 0 && static_cast<std::size_t>(selectedPointIndex_) < pointList_->size()) {
			const auto& point = (*pointList_)[selectedPointIndex_];
			double x = timeToX(point.time);
			double y = valueToY(point.value);
			painter.drawRect(QRectF(
				 QPointF(x - SELECTION_SIZE, y - SELECTION_SIZE),
				 QPointF(x + SELECTION_SIZE, y + SELECTION_SIZE)));
		}
	}
}
Esempio n. 4
0
/**
 * Called everytime we press a key on the keyboard
 * in window - the focused window
 * in key    - which key?
 * in scancode
 * in action - One of GFLW_PRESS, GLFW_REPEAT or GLFW_RELEASE
 */
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
    switch (key) {
        case GLFW_KEY_W:
            input.wPressed = action == GLFW_PRESS ? true: ((action == GLFW_RELEASE) ? false: input.wPressed);
            camera.move_angle =  action == GLFW_PRESS ? 0:camera.move_angle;
            break;
        case GLFW_KEY_S:
            input.sPressed = action == GLFW_PRESS ? true: ((action == GLFW_RELEASE) ? false: input.sPressed);
            camera.move_angle =  action == GLFW_PRESS ? 180:camera.move_angle;
            break;
        case GLFW_KEY_A:
            input.aPressed = action == GLFW_PRESS ? true: ((action == GLFW_RELEASE) ? false: input.aPressed);
            camera.move_angle =  action == GLFW_PRESS ? -90:camera.move_angle;
            break;
        case GLFW_KEY_D:
            input.dPressed = action == GLFW_PRESS ? true: ((action == GLFW_RELEASE) ? false: input.dPressed);
            camera.move_angle =  action == GLFW_PRESS ? 90:camera.move_angle;
            break;
        case GLFW_KEY_PAGE_UP:
            if (action == GLFW_PRESS) {
                switch (state) {
                    case STATE_POSITION: cursor.Y = grid.heightValue += 1.0f;updateGridHeight(&grid, &cursor); break;
                    case STATE_SCALE:break;
                    case STATE_ORIENTATION:
                        cursor.roll += 45.0f;
                        calculateCursorRotations(&cursor);break;
                }
            }
            break;
        case GLFW_KEY_PAGE_DOWN:
            if (action == GLFW_PRESS) {
                switch (state) {
                    case STATE_POSITION:
                        cursor.Y = grid.heightValue -= 1.0f;
                        updateGridHeight(&grid, &cursor);
                        break;
                    case STATE_SCALE:break;
                    case STATE_ORIENTATION:
                        cursor.roll -= 45.0f;
                        calculateCursorRotations(&cursor);
                        break;
                }
            }
            break;

        case GLFW_KEY_UP:
            if(action == GLFW_PRESS || action == GLFW_REPEAT) {
                switch (state) {
                    case STATE_POSITION:
                        cursor.Z += 1.0f;
                        break;
                    case STATE_SCALE:
                        cursor.Xs += 0.2f;
                        updateScales(&cursor);
                        break;
                    case STATE_ORIENTATION:
                        cursor.pitch += 45.0f;
                        calculateCursorRotations(&cursor);
                        break;
                }
            }
            break;
        case GLFW_KEY_DOWN:
            if(action == GLFW_PRESS || action == GLFW_REPEAT)
            {
                switch (state) {
                    case STATE_POSITION:
                        cursor.Z -= 1.0f;
                        break;
                    case STATE_SCALE:
                        cursor.Xs -= 0.2f;
                        updateScales(&cursor);
                        break;
                    case STATE_ORIENTATION:
                        cursor.pitch -= 45.0f;
                        calculateCursorRotations(&cursor);
                        break;
                }
            }
            break;
        case GLFW_KEY_LEFT:
            if(action == GLFW_PRESS || action == GLFW_REPEAT)
            {
                switch (state) {
                    case STATE_POSITION:
                        cursor.X += 1.0f;
                        break;
                    case STATE_SCALE:
                        cursor.Zs += 0.2f;
                        updateScales(&cursor);
                        break;
                    case STATE_ORIENTATION:
                        cursor.yaw += 45.0f;
                        calculateCursorRotations(&cursor);
                        break;
                }
            }
            break;
        case GLFW_KEY_RIGHT:
            if(action == GLFW_PRESS || action == GLFW_REPEAT)
            {
                switch (state) {
                    case STATE_POSITION:
                        cursor.X -= 1.0f;
                        break;
                    case STATE_SCALE:
                        cursor.Zs -= 0.2f;
                        updateScales(&cursor);
                        break;
                    case STATE_ORIENTATION:
                        cursor.yaw -= 45.0f;
                        calculateCursorRotations(&cursor);
                        break;
                }
            }
            break;
        case GLFW_KEY_ENTER: {

            //create a new wall and place it into walls vector.
            Wall wall = {};
            wall.position = vec3(cursor.X, cursor.Y, cursor.Z);
            wall.orientation = vec3(cursor.pitch, cursor.yaw, cursor.roll);
            wall.scale = vec3(cursor.Xs, cursor.Ys, cursor.Zs);
            wall.T = translate(identity_mat4(), vec3(-wall.position.v[0], wall.position.v[1], -wall.position.v[2]));
            walls.push_back(wall);
        }
            break;
        case GLFW_KEY_1:state = STATE_POSITION;   break;
        case GLFW_KEY_2:state = STATE_ORIENTATION;break;
        case GLFW_KEY_3:state = STATE_SCALE;      break;
    }
}
Esempio n. 5
0
void QgsScaleComboBox::setAllowNull( bool allowNull )
{
  mAllowNull = allowNull;
  lineEdit()->setClearButtonEnabled( allowNull );
  updateScales();
}