github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/client/GUI/lists/delegates.go (about)

     1  package lists
     2  
     3  import (
     4  	"strconv"
     5  
     6  	dm "github.com/benoitkugler/goACVE/server/core/datamodel"
     7  	rd "github.com/benoitkugler/goACVE/server/core/rawdata"
     8  
     9  	"github.com/therecipe/qt/core"
    10  	"github.com/therecipe/qt/gui"
    11  	"github.com/therecipe/qt/widgets"
    12  )
    13  
    14  type DelegateSuviCamps struct {
    15  	*widgets.QStyledItemDelegate
    16  }
    17  
    18  func NewDelegateSuviCamps() DelegateSuviCamps {
    19  	d := DelegateSuviCamps{widgets.NewQStyledItemDelegate(nil)}
    20  	d.ConnectPaint(d.paint)
    21  	return d
    22  }
    23  
    24  func (d DelegateSuviCamps) paint(painter *gui.QPainter, option *widgets.QStyleOptionViewItem, index *core.QModelIndex) {
    25  	if rd.Field(index.Data(int(core.Qt__UserRole)).ToInt(nil)) == dm.CampRemplissage {
    26  		p, err := strconv.Atoi(index.Data(int(core.Qt__DisplayRole)).ToString())
    27  		if err != nil {
    28  			return
    29  		}
    30  		if p > 100 {
    31  			p = 100
    32  		}
    33  		rs, vs, bs := 30, 64, 55    // start
    34  		re, ve, be := 153, 242, 200 // end
    35  		color := gui.NewQColor3(rs+p*(re-rs)/100, vs+p*(ve-vs)/100, bs+p*(be-bs)/100, 255)
    36  		brush := gui.NewQBrush3(color, core.Qt__SolidPattern)
    37  
    38  		painter.Save()
    39  		painter.SetPen(gui.NewQPen4(brush, 0.5, core.Qt__SolidLine,
    40  			core.Qt__RoundCap, core.Qt__RoundJoin))
    41  		painter.SetBackgroundMode(core.Qt__OpaqueMode)
    42  		painter.SetBackground(brush)
    43  		painter.SetBrush(brush)
    44  		rect := option.Rect()
    45  		rect.SetWidth(rect.Width() * p / 100)
    46  		painter.DrawRoundedRect3(rect, 5, 5, core.Qt__AbsoluteSize)
    47  		painter.Restore()
    48  	} else {
    49  		d.PaintDefault(painter, option, index)
    50  	}
    51  }