Ejemplo n.º 1
0
func (w *CodeEdit) paintLineArea(event *ui.QPaintEvent) {
	painter := ui.NewPainterWithPaintDevice(w.lineArea)
	defer painter.Delete()
	painter.FillRectWithRectColor(w.lineArea.Rect(), ui.NewColorWithGlobalcolor(ui.Qt_lightGray))

	block := w.edit.FirstVisibleBlock()
	blockNumber := block.BlockNumber() + 1
	top := w.edit.BlockBoundingGeometry(block).Translated(w.edit.ContentOffset()).Top()
	bottom := top + w.edit.BlockBoundingRect(block).Height()
	height := w.lineArea.FontMetrics().Height()
	for block.IsValid() && int32(top) < event.Rect().Bottom() {
		if block.IsVisible() && int32(bottom) >= event.Rect().Top() {
			painter.SetPen(ui.NewColorWithGlobalcolor(ui.Qt_black))
			painter.DrawTextWithXYWidthHeightFlagsTextRect(0, int32(top), w.lineArea.Width(), int32(height), int32(ui.Qt_AlignRight), strconv.Itoa(int(blockNumber)), ui.NewRect())
		}
		block = block.Next()
		top = bottom
		bottom = top + w.edit.BlockBoundingRect(block).Height()
		blockNumber++
	}
}
Ejemplo n.º 2
0
func (w *WigglyWidget) OnPaintEvent(e *ui.QPaintEvent) bool {
	w.PaintEvent(e)
	merics := ui.NewFontMetrics(w.Font())
	defer merics.Delete()

	x := (w.Width() - merics.WidthWithString(w.text)) / 2
	y := (w.Height() + merics.Ascent() - merics.Descent()) / 2

	color := ui.NewColor()
	defer color.Delete()

	painter := ui.NewPainterWithPaintDevice(w)
	defer painter.Delete()

	for i, s := range w.text {
		index := (w.step + i) % 16
		color.SetHsv(int32(15-index)*16, 255, 191, 255)
		painter.SetPen(color)
		painter.DrawTextWithXYText(x, y-((sineTablep[index]*merics.Height())/400), string(s))
		x += merics.Width(s)
	}
	return true
}