Esempio n. 1
0
/*
 * FloatRoundedRect geometry for this test. Corner radii are in parens, x and y intercepts
 * for the elliptical corners are noted. The rectangle itself is at 0,0 with width and height 100.
 *
 *         (10, 15)  x=10      x=90 (10, 20)
 *                (--+---------+--)
 *           y=15 +--|         |-+ y=20
 *                |               |
 *                |               |
 *           y=85 + -|         |- + y=70
 *                (--+---------+--)
 *       (25, 15)  x=25      x=80  (20, 30)
 */
TEST(FloatRoundedRectTest, ellipticalCorners)
{
    FloatSize cornerSize(10, 20);
    FloatRoundedRect::Radii cornerRadii;
    cornerRadii.setTopLeft(FloatSize(10, 15));
    cornerRadii.setTopRight(FloatSize(10, 20));
    cornerRadii.setBottomLeft(FloatSize(25, 15));
    cornerRadii.setBottomRight(FloatSize(20, 30));

    FloatRoundedRect r(FloatRect(0, 0, 100, 100), cornerRadii);

    EXPECT_EQ(r.radii(), FloatRoundedRect::Radii(FloatSize(10, 15), FloatSize(10, 20), FloatSize(25, 15), FloatSize(20, 30)));
    EXPECT_EQ(r, FloatRoundedRect(FloatRect(0, 0, 100, 100), cornerRadii));

    EXPECT_EQ(FloatRect(0, 0, 10, 15), r.topLeftCorner());
    EXPECT_EQ(FloatRect(90, 0, 10, 20), r.topRightCorner());
    EXPECT_EQ(FloatRect(0, 85, 25, 15), r.bottomLeftCorner());
    EXPECT_EQ(FloatRect(80, 70, 20, 30), r.bottomRightCorner());

    TEST_INTERCEPTS(r, 5, 2.5464401, 96.61438);
    TEST_INTERCEPTS(r, 15, 0, 99.682457);
    TEST_INTERCEPTS(r, 20, 0, 100);
    TEST_INTERCEPTS(r, 50, 0, 100);
    TEST_INTERCEPTS(r, 70, 0, 100);
    TEST_INTERCEPTS(r, 85, 0, 97.320511);
    TEST_INTERCEPTS(r, 95, 6.3661003, 91.05542);

    float minXIntercept;
    float maxXIntercept;

    EXPECT_FALSE(r.xInterceptsAtY(-1, minXIntercept, maxXIntercept));
    EXPECT_FALSE(r.xInterceptsAtY(101, minXIntercept, maxXIntercept));
}
void PhotoCropper::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    QRect myRect(0,0,this->width(), this->height());
    painter.drawImage(myRect, img); // first just draw the original image
    if (mode>0) {
        // unless mode 0 (no selection), probably want to:
        // 1. Dim the entire image
        painter.fillRect(myRect, dimColor);
        // 2. Draw selected area normal color
        painter.drawImage(currentCrop, img, cropInOrig());
        // 3. Draw handle type things around the edges0
        // (for now, a little white square at each corner)
        QPoint corners[] = {QPoint(currentCrop.left(), currentCrop.top()),
                            QPoint(currentCrop.right(), currentCrop.top()),
                            QPoint(currentCrop.left(), currentCrop.bottom()),
                            QPoint(currentCrop.right(), currentCrop.bottom())};
        QPoint adj(5, 5); // corner handles start 5 pixels up and left of corner point
        QPoint cornerSize(10, 10); // 10x10 pixels total
        for(int i=0; i<4; i++)
            painter.fillRect(QRect(corners[i]-adj, cornerSize), Qt::white);
    }
}
	void Graphics2D::drawWindowType(Vector2D const& dstP, Size2D const& dstS, WindowType type)
	{
		Vector2D frontP(32*type, 0), backP;
		Vector2D backS; // background image size

		Image const& sys = getSystemGraphic();

		switch(type) {
			case WINDOW:
				backP(32*0, 0);
				backS = 32;
				break;
			case CURSOR_0: case CURSOR_1:
				backP(frontP[0] + CORNER, frontP[1] + CORNER);
				backS = NON_FRAME;
				break;
			default:
				return;
		}
		// draw wallpaper and side frame
		switch( getOwner().getProject().wallpaperType() ) {
			case model::Wallpaper::TILE: {
			// draw wallpaper
				// draw wallpaper aligned space
				Size2D align = dstS / backS;
				Size2D remainS = dstS % backS;
				Vector2D remainP = align * backS;
				Size2D it;
				for(it[0] = 0; it[0] < align[0]; it[0]++) {
				for(it[1] = 0; it[1] < align[1]; it[1]++) {
					drawImage(sys, dstP + backS*it, backP, backS);
				}
				}
				// draw wallpaper unaligned space
				if(!remainS[0]) {
					for(it[1] = 0; it[1] < align[1]; it[1]++) {
						drawImage(sys,
							Vector2D(dstP[0] + remainP[0], dstP[1] + backS[1]*it[1]),
							backP, Size2D(remainS[0], backS[1])
						);
					}
				}
				if(!remainS[1]) {
					for(it[0] = 0; it[0] < align[0]; it[0]++) {
						drawImage(sys,
							Vector2D(dstP[0] + backS[0]*it[0], dstS[1] + remainP[1]),
							backP, Size2D(backS[0], remainS[1])
						);
					}
				}
				if( (!remainS[0]) && (!remainS[1]) ) {
					drawImage(sys, dstS + remainP, backP, remainS);
				}
			// draw side frame
				// draw top and bottom frame aligned
				align( (dstS[0]-FRAME_W*2) / FRAME_L, (dstS[1]-FRAME_W*2) / FRAME_L);
				for(it[0] = 0; it[0] < align[0]; it[0]++) {
					// top frame
					drawImage(sys,
						Vector2D(dstP[0] + FRAME_W + FRAME_L * it[0], dstP[1]),
						Vector2D(frontP[0]+FRAME_W, frontP[1]),
						Size2D(FRAME_L, FRAME_W)
					);
					// bottom frame
					drawImage(sys,
						Vector2D(dstP[0] + FRAME_W + FRAME_L * it[0], dstP[1] + dstS[1]-FRAME_W),
						Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
						Size2D(FRAME_L, FRAME_W)
					);
				}
				// draw left and bottom frame aligned
				for(it[1] = 0; it[1] < align[1]; it[1]++) {
					// draw left
					drawImage(sys,
						Vector2D(dstP[0], dstP[1]+FRAME_W + FRAME_L*it[1]),
						Vector2D(frontP[0], frontP[1]+FRAME_W),
						Size2D(FRAME_W, FRAME_L)
					);
					// draw right
					drawImage(sys,
						Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+FRAME_W + FRAME_L*it[1]),
						Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
						Size2D(FRAME_W, FRAME_L)
					);
				}
				// draw frame unaligned
				remainS( (dstS[0]-FRAME_W*2) % FRAME_L, (dstS[1]-FRAME_W*2) % FRAME_L );
				remainP(align[0] * FRAME_L + FRAME_W, align[1] * FRAME_L + FRAME_W);
				// top frame
				drawImage(sys,
					Vector2D(dstP[0]+remainP[0], dstP[1]),
					Vector2D(frontP[0]+FRAME_W, frontP[1]),
					Size2D(remainS[0], FRAME_W)
				);
				// bottom frame
				drawImage(sys,
					Vector2D(dstP[0]+remainP[0], dstP[1] + dstS[1]-FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
					Size2D(remainS[0], FRAME_W)
				);
				// left frame
				drawImage(sys,
					Vector2D(dstP[0], dstP[1]+remainP[1]),
					Vector2D(frontP[0], frontP[1]+FRAME_W),
					Size2D(FRAME_W, remainS[1])
				);
				// right frame
				drawImage(sys,
					Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+remainP[1]),
					Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
					Size2D(FRAME_W, remainS[1])
				);
			} break;
			case model::Wallpaper::ZOOM: {
				// draw wallpaper
				drawImage(sys, dstP, dstS, backP, backS);
				// draw top frame
				drawImage(sys,
					Vector2D(dstP[0]+FRAME_W, dstP[1]),
					Size2D(dstS[0]-FRAME_W, FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]),
					Size2D(FRAME_L, FRAME_W)
				);
				// draw left frame
				drawImage(sys,
					Vector2D(dstP[0], dstP[1]+FRAME_W),
					Size2D(FRAME_W, dstS[1]-FRAME_W),
					Vector2D(frontP[0], frontP[1]+FRAME_W),
					Size2D(FRAME_W, FRAME_L)
				);
				// draw right frame
				drawImage(sys,
					Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+FRAME_W),
					Size2D(FRAME_W, dstS[1]-FRAME_W),
					Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
					Size2D(FRAME_W, FRAME_L)
				);
				// draw bottom frame
				drawImage(sys,
					Vector2D(dstP[0]+FRAME_W, dstP[1] + dstS[1]-FRAME_W),
					Size2D(dstS[0]-FRAME_W, FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
					Size2D(FRAME_L, FRAME_W)
				);
			} break;
			default: rpg2k_assert(false);
		}

		Vector2D cornerSize(CORNER, CORNER);
		// draw corner frame
		drawImage(sys, dstP, frontP, cornerSize);
		drawImage(sys,
			Vector2D(dstP[0] + dstS[0] - CORNER, dstP[1]),
			Vector2D(frontP[0] + C_AND_N, frontP[1]), cornerSize
		);
		drawImage(sys,
			Vector2D(dstP[0], dstP[1] + dstS[1] - CORNER),
			Vector2D(frontP[0], frontP[1] + C_AND_N), cornerSize
		);
		drawImage(sys,
			Vector2D(dstP[0] + dstS[0] - CORNER, dstP[1] + dstS[1] -CORNER),
			Vector2D(frontP[0] + C_AND_N, frontP[1] + C_AND_N), cornerSize
		);
	}
Esempio n. 4
0
void InternalToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (!m_movable || (!m_dragging && boundingRect().contains(event->pos()))) {
        return;
    }

    m_dragging = true;
    m_userMoved = true;
    const QPoint newPos = mapToParent(event->pos()).toPoint();
    const QPoint curPos = pos().toPoint();

    const QSize cSize = cornerSize();
    const QSize fHeight = fullHeight();
    const QSize fWidth = fullWidth();
    const int h = fHeight.height();
    const int w = fWidth.width();

    const int areaWidth = parentWidget()->size().width();
    const int areaHeight = parentWidget()->size().height();

    int x = curPos.x();
    int y = curPos.y();

    // jump to the nearest desktop border
    int distanceToLeft = newPos.x() - m_dragStartRelative.x();
    int distanceToRight = areaWidth - w - distanceToLeft;
    int distanceToTop = newPos.y() - m_dragStartRelative.y();
    int distanceToBottom = areaHeight - h - distanceToTop;

    int distancetoHorizontalMiddle = qAbs((newPos.x() + boundingRect().size().width()/2) - areaWidth/2 - m_dragStartRelative.x());
    int distancetoVerticalMiddle = qAbs((newPos.y() + boundingRect().size().height()/2) - areaHeight/2 - m_dragStartRelative.y());

    if (distancetoHorizontalMiddle < 10) {
        x = areaWidth/2 - boundingRect().size().width()/2;
    } else if (distancetoVerticalMiddle < 10) {
        y = areaHeight/2 - boundingRect().size().height()/2;
    } else {
        // decide which border is the nearest
        if (distanceToLeft < distanceToTop && distanceToLeft < distanceToRight &&
            distanceToLeft < distanceToBottom ) {
            x = 0;
            y = (newPos.y() - m_dragStartRelative.y());
        } else if (distanceToRight < distanceToTop && distanceToRight < distanceToLeft &&
                distanceToRight < distanceToBottom) {
            x = areaWidth - w;
            y = (newPos.y() - m_dragStartRelative.y());
        } else if (distanceToTop < distanceToLeft && distanceToTop < distanceToRight &&
                distanceToTop < distanceToBottom ) {
            y = 0;
            x = (newPos.x() - m_dragStartRelative.x());
        } else if (distanceToBottom < distanceToLeft && distanceToBottom < distanceToRight &&
                distanceToBottom < distanceToTop) {
            y = areaHeight - h;
            x = (newPos.x() - m_dragStartRelative.x());
        }
    }


    x = qBound(0, x, areaWidth - w);
    y = qBound(0, y, areaHeight - h);

    Corner newCorner = corner();
    if (x == 0) {
        if (y == 0) {
            newCorner = TopLeft;
        } else if (areaHeight - cSize.height() < newPos.y()) {
            y = areaHeight - cSize.height();
            newCorner = BottomLeft;
        } else {
            newCorner = Left;
        }
    } else if (y == 0) {
        if (areaWidth - cSize.width() < newPos.x()) {
            x = areaWidth - cSize.width();
            newCorner = TopRight;
        } else {
            newCorner = Top;
        }
    } else if (x + w >= areaWidth) {
        if (areaHeight - cSize.height() < newPos.y()) {
            y = areaHeight - cSize.height();
            x = areaWidth - cSize.width();
            newCorner = BottomRight;
        } else {
            x = areaWidth - fHeight.width();
            newCorner = Right;
        }
    } else {
        y = areaHeight - fWidth.height();
        newCorner = Bottom;
    }

    if (newCorner != corner()) {
        prepareGeometryChange();
        setCorner(newCorner);
    }

    setPos(x, y);
}