func (w *CodeEdit) paintLineArea(event *ui.QPaintEvent) { painter := ui.NewQPainterWithPaintDevice(w.lineArea) defer painter.Delete() painter.FillRectWithRectColor(w.lineArea.Rect(), ui.NewQColorWithGlobalcolor(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.NewQColorWithGlobalcolor(ui.Qt_black)) painter.DrawTextWithXYWidthHeightFlagsTextRect(0, int32(top), w.lineArea.Width(), int32(height), int32(ui.Qt_AlignRight), strconv.Itoa(int(blockNumber)), ui.NewQRect()) } block = block.Next() top = bottom bottom = top + w.edit.BlockBoundingRect(block).Height() blockNumber++ } }
func (w *WigglyWidget) OnPaintEvent(e *ui.QPaintEvent) bool { w.PaintEvent(e) merics := ui.NewQFontMetrics(w.Font()) defer merics.Delete() x := (w.Width() - merics.WidthWithString(w.text)) / 2 y := (w.Height() + merics.Ascent() - merics.Descent()) / 2 color := ui.NewQColor() defer color.Delete() painter := ui.NewQPainterWithPaintDevice(w) defer painter.Delete() for i, s := range w.text { index := (w.step + i) % 16 color.SetHsv((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 }