예제 #1
0
파일: drawtest.go 프로젝트: Kelimion/go-qt5
func main() {
	qt5.Main(func() {
		w := qt5.NewWidget()

		w.OnPaintEvent(func(e *qt5.PaintEvent) {
			paint := qt5.NewPainter()
			defer paint.Close()
			paint.Begin(w)
			pen := qt5.NewPen()
			pen.SetColor(color.RGBA{255, 128, 0, 0})
			pen.SetWidth(2)
			fmt.Println(pen, pen.Color(), pen.Width())
			paint.SetPen(pen)
			brush := qt5.NewBrush()
			brush.SetStyle(qt5.SolidPattern)
			brush.SetColor(color.RGBA{128, 128, 0, 255})
			paint.SetBrush(brush)
			paint.DrawRect(qt5.Rect{10, 10, 100, 100})
		})

		w.SetSize(qt5.Size{400, 400})
		w.Show()

		qt5.Run()
	})
}
예제 #2
0
파일: main.go 프로젝트: richardfontana/lime
func newQLimeView(v *backend.View) *QLimeView {
	log4go.Debug("new_QLimeView entered")
	defer log4go.Debug("new_QLimeView exited")
	var ret QLimeView
	ret.Widget = qt5.NewWidget()
	ret.v = v
	ret.Widget.OnPaintEvent(func(ev *qt5.PaintEvent) {
		p := qt5.NewPainter()
		defer p.Close()
		p.Begin(ret)
		b := v.Buffer()
		ps := p.Font().PointSize()

		pen := qt5.NewPen()
		p.SetPen(pen)
		brush := qt5.NewBrush()
		brush.SetStyle(qt5.SolidPattern)
		def := scheme.Settings[0]
		p.SetBrush(brush)
		f := p.Font()
		f.SetFixedPitch(true)
		p.SetFont(f)

		brush.SetColor(color.RGBA(def.Settings["background"]))
		p.DrawRect(ev.Rect())
		is_widget, ok := v.Settings().Get("is_widget", false).(bool)
		is_widget = ok && is_widget
		pen.SetColor(color.RGBA(def.Settings["background"]))
		p.SetPen(pen)

		for y := 0; y < 20; y++ {
			pos := b.TextPoint(y, 0)
			line := b.Line(pos)

			if is_widget {
				p.DrawText(qt5.Point{0, (y + 1) * (ps + 2)}, b.Substr(line))
			} else {
				for line.Contains(pos) {
					scope := primitives.Region{pos, pos}
					sn := v.ScopeName(pos)
					for line.Contains(pos) {
						pos++
						if v.ScopeName(pos) != sn {
							scope.B = pos
							break
						}
					}
					is := line.Intersection(scope)
					c := color.RGBA(def.Settings["foreground"])
					s := scheme.ClosestMatchingSetting(sn)
					if v, ok := s.Settings["foreground"]; ok {
						c = color.RGBA(v)
					}
					pen.SetColor(c)
					p.SetPen(pen)
					_, col := b.RowCol(line.A)
					p.DrawText(qt5.Point{col * ps / 2, (y + 1) * (ps + 2)}, b.Substr(is))
					line.A = is.End()
				}
			}
		}
	})
	ret.Widget.OnResizeEvent(func(ev *qt5.ResizeEvent) {
		if w, ok := v.Settings().Get("is_widget", false).(bool); ok && !w {
			ret.Widget.SetMinimumSize(qt5.Size{600, 100})
		}
	})
	v.Settings().Set("lime.qt.widget", &ret)
	return &ret
}