Exemplo n.º 1
0
    public override void Paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
    {
        // Body
        painter.SetBrush(color);
        painter.DrawEllipse(-10, -20, 20, 40);

        // Eyes
        painter.SetBrush(Qt.GlobalColor.white);
        painter.DrawEllipse(-10, -17, 8, 8);
        painter.DrawEllipse(2, -17, 8, 8);

        // Nose
        painter.SetBrush(Qt.GlobalColor.black);
        painter.DrawEllipse(new QRectF(-2, -22, 4, 4));

        // Pupils
        painter.DrawEllipse(new QRectF(-8.0 + mouseEyeDirection, -17, 4, 4));
        painter.DrawEllipse(new QRectF(4.0 + mouseEyeDirection, -17, 4, 4));

        // Ears
        painter.SetBrush(Scene().CollidingItems(this).Count == 0 ? Qt.GlobalColor.darkYellow : Qt.GlobalColor.red);
        painter.DrawEllipse(-17, -12, 16, 16);
        painter.DrawEllipse(1, -12, 16, 16);

        // Tail
        QPainterPath path = new QPainterPath(new QPointF(0, 20));

        path.CubicTo(-5, 22, -5, 22, 0, 25);
        path.CubicTo(5, 27, 5, 32, 0, 30);
        path.CubicTo(-5, 32, -5, 42, 0, 35);
        painter.SetBrush(Qt.BrushStyle.NoBrush);
        painter.DrawPath(path);
    }
Exemplo n.º 2
0
    public QPainterPath Shape()
    {
        QPainterPath path = new QPainterPath();

        path.AddRect(-10, -20, 20, 40);
        return(path);
    }
Exemplo n.º 3
0
        void DrawShapes(QPainter painter)
        {
            painter.SetRenderHint(QPainter.RenderHint.Antialiasing);
            painter.Pen   = new QPen(new QBrush(new QColor("Gray")), 1);
            painter.Brush = new QColor("Gray");

            var path = new QPainterPath();

            path.MoveTo(5, 5);
            path.CubicTo(40, 5, 50, 50, 99, 99);
            path.CubicTo(5, 99, 50, 50, 5, 5);
            painter.DrawPath(path);

            painter.DrawPie(130, 20, 90, 60, 30 * 16, 120 * 16);
            painter.DrawChord(240, 30, 90, 60, 0, 16 * 180);
            var rectangle = new QRect(new QPoint(20, 120), new QSize(80, 50));

            painter.DrawRoundedRect(rect: rectangle, xRadius: 10, yRadius: 10);

            // to be implemented
            //var points = new List<QPoint>();
            //points.Add ( new QPoint ( 130, 140 ) );
            //points.Add ( new QPoint ( 180, 170 ) );
            //points.Add ( new QPoint ( 180, 140 ) );
            //points.Add ( new QPoint ( 220, 110 ) );
            //points.Add ( new QPoint ( 140, 100 ) );

            //// http://doc.qt.io/qt-5/qpolygon.html#QPolygon-2 , we should be able to pase point list
            //var polygon = new QPolygon(points);
            //painter.DrawPolygon ( polygon );

            // this is workaround for DrawPolygon
            unsafe
            {
                var polygon = new QPolygon();
                var points  = new int[] { 130, 140, 180, 170, 180, 140, 220, 110, 140, 100 };
                fixed(int *point = points)
                {
                    polygon.SetPoints(points.Length / 2, ref *point);
                }

                painter.DrawPolygon(polygon);
            }

            painter.DrawRect(250, 110, 60, 60);

            var baseline  = new QPointF(20, 250);
            var font      = new QFont("Georgia", 55);
            var forntPath = new QPainterPath();

            forntPath.AddText(baseline, font, "Q");
            painter.DrawPath(forntPath);

            painter.DrawEllipse(140, 200, 60, 60);
            painter.DrawEllipse(240, 200, 90, 60);
        }
Exemplo n.º 4
0
        public static void DrawAvatar(QPainter painter, int width, int height, QPixmap avatarPixmap)
        {
            QPainterPath path = new QPainterPath();

            // Draw a rect without corners.
            path.MoveTo(0, 1);
            path.LineTo(1, 1);
            path.LineTo(1, 0);
            path.LineTo(width - 1, 0);
            path.LineTo(width, 1);
            path.LineTo(width, height - 1);
            path.LineTo(width - 1, height - 1);
            path.LineTo(width - 1, height);
            path.LineTo(1, height);
            path.LineTo(1, height - 1);
            path.LineTo(0, height - 1);
            path.LineTo(0, 1);

            QLinearGradient g1 = new QLinearGradient(0, 0, 0, height);

            g1.SetColorAt(0, new QColor("#888781"));
            g1.SetColorAt(1, new QColor("#abaaa8"));
            QBrush b1 = new QBrush(g1);

            painter.FillPath(path, b1);
            painter.FillRect(1, 1, width - 2, height - 2, new QBrush(Qt.GlobalColor.black));

            // Darken the corners...
            var b2 = new QBrush(new QColor(61, 61, 61, 102));

            painter.FillRect(0, 0, 3, 3, b2);
            painter.FillRect(width - 3, 0, 3, 3, b2);
            painter.FillRect(0, width - 3, 3, 3, b2);
            painter.FillRect(width - 3, width - 3, 3, 3, b2);

            painter.DrawPixmap(2, 2, width - 4, height - 4, avatarPixmap);
        }
            public override void Paint(Qyoto.QPainter painter, Qyoto.QStyleOptionGraphicsItem option, Qyoto.QWidget widget)
            {
                painter.SetOpacity(m_Opacity);

                var color = m_Grid.Palette.Color(QPalette.ColorRole.Text);

                // Group Name
                painter.SetFont(m_Font);
                painter.SetPen(new QPen(color));

                string text = null;

                if (m_Grid.ShowGroupCounts)
                {
                    text = String.Format("{0} ({1}/{2})",
                                         m_GroupName,
                                         m_Grid.Model.NumOnlineItemsInGroup(m_GroupName),
                                         m_Grid.Model.NumItemsInGroup(m_GroupName));
                }
                else
                {
                    text = m_GroupName;
                }

                painter.DrawText(BoundingRect(), text);

                int arrowX = m_Grid.IconPadding + m_Metrics.Width(text) + 4;
                int arrowY = 5;

                // Group expander arrow
                painter.Save();
                painter.Translate(arrowX, arrowY);
                QPainterPath path = new QPainterPath();

                if (IsExpanded)
                {
                    path.MoveTo(0, 0);
                    path.LineTo(4, 0);
                    path.LineTo(2, 2);
                    path.LineTo(0, 0);
                }
                else
                {
                    path.MoveTo(2, 0);
                    path.LineTo(2, 4);
                    path.LineTo(0, 2);
                    path.LineTo(2, 0);
                }
                painter.SetPen(new QPen(color));
                painter.SetBrush(new QBrush(color));
                painter.DrawPath(path);
                painter.Restore();

                m_ArrowRect = new QRectF(arrowX, 0, 4, m_Grid.HeaderHeight);

                if (ItemOver)
                {
                    painter.SetPen(new QPen(new QColor("red")));
                    painter.DrawRect(BoundingRect());
                }
            }