2019-05-13 20:42:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/therecipe/qt/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Model Roles
|
|
|
|
const (
|
|
|
|
PaneName = int(core.Qt__UserRole) + 1<<iota
|
2019-05-14 02:20:27 +00:00
|
|
|
PaneSticky
|
2019-05-13 20:42:03 +00:00
|
|
|
MsgModel
|
|
|
|
)
|
|
|
|
|
|
|
|
// PaneModel holds a collection of panes
|
|
|
|
type PaneModel struct {
|
|
|
|
core.QAbstractListModel
|
|
|
|
|
|
|
|
_ func() `constructor:"init"`
|
|
|
|
|
|
|
|
_ map[int]*core.QByteArray `property:"roles"`
|
|
|
|
_ []*Pane `property:"panes"`
|
|
|
|
|
|
|
|
_ func(*Pane) `slot:"addPane"`
|
|
|
|
_ func(row int) `slot:"removePane"`
|
2019-05-15 03:01:47 +00:00
|
|
|
_ func() `slot:"clear"`
|
2019-05-13 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pane represents a single pane
|
|
|
|
type Pane struct {
|
|
|
|
core.QObject
|
|
|
|
|
2019-05-14 02:20:27 +00:00
|
|
|
Name string
|
|
|
|
Sticky bool
|
|
|
|
Model *MessageModel
|
2019-05-13 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) init() {
|
|
|
|
m.SetRoles(map[int]*core.QByteArray{
|
2019-05-14 02:20:27 +00:00
|
|
|
PaneName: core.NewQByteArray2("panename", -1),
|
|
|
|
PaneSticky: core.NewQByteArray2("panesticky", -1),
|
|
|
|
MsgModel: core.NewQByteArray2("msgmodel", -1),
|
2019-05-13 20:42:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
m.ConnectData(m.data)
|
|
|
|
m.ConnectSetData(m.setData)
|
|
|
|
m.ConnectRowCount(m.rowCount)
|
|
|
|
m.ConnectColumnCount(m.columnCount)
|
|
|
|
m.ConnectRoleNames(m.roleNames)
|
|
|
|
|
|
|
|
m.ConnectAddPane(m.addPane)
|
|
|
|
m.ConnectRemovePane(m.removePane)
|
2019-05-15 03:01:47 +00:00
|
|
|
m.ConnectClear(m.clear)
|
2019-05-13 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) setData(index *core.QModelIndex, value *core.QVariant, role int) bool {
|
|
|
|
if !index.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// var p = m.Panes()[len(m.Panes())-1-index.Row()]
|
|
|
|
m.DataChanged(index, index, []int{Editing})
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) data(index *core.QModelIndex, role int) *core.QVariant {
|
|
|
|
if !index.IsValid() {
|
|
|
|
return core.NewQVariant()
|
|
|
|
}
|
|
|
|
if index.Row() >= len(m.Panes()) {
|
|
|
|
return core.NewQVariant()
|
|
|
|
}
|
|
|
|
|
|
|
|
var p = m.Panes()[index.Row()]
|
|
|
|
switch role {
|
|
|
|
case PaneName:
|
|
|
|
{
|
2019-09-04 02:27:37 +00:00
|
|
|
return core.NewQVariant1(p.Name)
|
2019-05-13 20:42:03 +00:00
|
|
|
}
|
2019-05-14 02:20:27 +00:00
|
|
|
case PaneSticky:
|
|
|
|
{
|
2019-09-04 02:27:37 +00:00
|
|
|
return core.NewQVariant1(p.Sticky)
|
2019-05-14 02:20:27 +00:00
|
|
|
}
|
2019-05-13 20:42:03 +00:00
|
|
|
case MsgModel:
|
|
|
|
{
|
|
|
|
return p.Model.ToVariant()
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return core.NewQVariant()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) rowCount(parent *core.QModelIndex) int {
|
|
|
|
return len(m.Panes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) columnCount(parent *core.QModelIndex) int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) roleNames() map[int]*core.QByteArray {
|
|
|
|
return m.Roles()
|
|
|
|
}
|
|
|
|
|
2019-05-15 03:01:47 +00:00
|
|
|
func (m *PaneModel) clear() {
|
|
|
|
m.BeginResetModel()
|
|
|
|
m.SetPanes([]*Pane{})
|
|
|
|
m.EndResetModel()
|
|
|
|
}
|
|
|
|
|
2019-05-13 20:42:03 +00:00
|
|
|
func (m *PaneModel) addPane(p *Pane) {
|
2019-05-14 02:20:27 +00:00
|
|
|
// add pane before the last pane, which is always the notifications pane
|
|
|
|
if len(m.Panes()) == 0 {
|
|
|
|
m.BeginInsertRows(core.NewQModelIndex(), 0, 0)
|
|
|
|
m.SetPanes(append(m.Panes(), p))
|
|
|
|
} else {
|
|
|
|
m.BeginInsertRows(core.NewQModelIndex(), len(m.Panes())-1, len(m.Panes())-1)
|
|
|
|
m.SetPanes(append(m.Panes()[:len(m.Panes())-1], p, m.Panes()[len(m.Panes())-1]))
|
|
|
|
}
|
2019-05-13 20:42:03 +00:00
|
|
|
m.EndInsertRows()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PaneModel) removePane(row int) {
|
|
|
|
m.BeginRemoveRows(core.NewQModelIndex(), row, row)
|
|
|
|
m.SetPanes(append(m.Panes()[:row], m.Panes()[row+1:]...))
|
|
|
|
m.EndRemoveRows()
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
PaneModel_QRegisterMetaType()
|
|
|
|
Pane_QRegisterMetaType()
|
|
|
|
}
|