clickable identities: mark 1
This commit is contained in:
parent
8409b2bef4
commit
dbd646230c
|
@ -2,35 +2,80 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/therecipe/qt/core"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() { QIdentityListModel_QmlRegisterType2("CustomQmlTypes", 1, 0, "QIdentityListModel") }
|
||||
|
||||
// TODO: register QObj of Item
|
||||
|
||||
const (
|
||||
Name = int(core.Qt__UserRole) + 1<<iota
|
||||
Onion
|
||||
Pcolor
|
||||
Color
|
||||
ButtonType
|
||||
)
|
||||
|
||||
const (
|
||||
identity = iota
|
||||
unlock
|
||||
add
|
||||
)
|
||||
|
||||
|
||||
type IdentityListItem struct {
|
||||
name, onion, pcolor string
|
||||
|
||||
name, onion, color string
|
||||
buttonType int
|
||||
|
||||
/*core.QObject
|
||||
|
||||
//name, onion, color string
|
||||
//buttonType int
|
||||
_ string `property:"name"`
|
||||
_ string `property:"onion"`
|
||||
_ string `property:"color"`
|
||||
_ int `property:"buttonType"`
|
||||
|
||||
_ func() `signal:"identityClick,auto"`
|
||||
_ func() `signal:"unlockClick,auto"`
|
||||
_ func() `signal:"addClick,auto"`
|
||||
_ func() `signal:"unknownClick,auto"`*/
|
||||
}
|
||||
|
||||
/*
|
||||
func NewIdentityListItemValues(name, onion, color string, buttonType int) *IdentityListItem {
|
||||
i := NewIdentityListItem(nil)
|
||||
i.SetName(name)
|
||||
i.SetOnion(onion)
|
||||
i.SetColor(color)
|
||||
i.SetButtonType(buttonType)
|
||||
return i
|
||||
}
|
||||
*/
|
||||
|
||||
type QIdentityListModel struct {
|
||||
core.QAbstractListModel
|
||||
|
||||
_ int `property:"typeIdentity"`
|
||||
_ int `property:"typeUnlock"`
|
||||
_ int `property:"typeAdd"`
|
||||
|
||||
_ func() `constructor:"init"`
|
||||
|
||||
_ func() `signal:"remove,auto"`
|
||||
_ func(obj []*core.QVariant) `signal:"add,auto"`
|
||||
_ func(name string, onion string, pcolor string) `signal:"edit,auto"`
|
||||
_ func(string) `signal:"clickIdentity,auto"`
|
||||
|
||||
//_ func() `signal:"remove,auto"`
|
||||
//_ func(obj []*core.QVariant) `signal:"add,auto"`
|
||||
//_ func(name string, onion string, color string) `signal:"edit,auto"`
|
||||
|
||||
modelData []IdentityListItem
|
||||
}
|
||||
|
||||
func (m *QIdentityListModel) init() {
|
||||
m.modelData = []IdentityListItem{}
|
||||
m.SetTypeIdentity(identity)
|
||||
m.SetTypeUnlock(unlock)
|
||||
m.SetTypeAdd(add)
|
||||
|
||||
m.ConnectRoleNames(m.roleNames)
|
||||
m.ConnectRowCount(m.rowCount)
|
||||
|
@ -41,7 +86,8 @@ func (m *QIdentityListModel) roleNames() map[int]*core.QByteArray {
|
|||
return map[int]*core.QByteArray{
|
||||
Name: core.NewQByteArray2("Name", -1),
|
||||
Onion: core.NewQByteArray2("Onion", -1),
|
||||
Pcolor: core.NewQByteArray2("Pcolor", -1),
|
||||
Color: core.NewQByteArray2("Color", -1),
|
||||
ButtonType: core.NewQByteArray2("ButtonType", -1),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,37 +102,37 @@ func (m *QIdentityListModel) data(index *core.QModelIndex, role int) *core.QVari
|
|||
return core.NewQVariant14(item.name)
|
||||
case Onion:
|
||||
return core.NewQVariant14(item.onion)
|
||||
case Pcolor:
|
||||
return core.NewQVariant14(item.pcolor)
|
||||
case Color:
|
||||
return core.NewQVariant14(item.color)
|
||||
case ButtonType:
|
||||
return core.NewQVariant7(item.buttonType)
|
||||
}
|
||||
return core.NewQVariant()
|
||||
}
|
||||
|
||||
func (m *QIdentityListModel) remove() {
|
||||
/*func (m *QIdentityListModel) remove() {
|
||||
if len(m.modelData) == 0 {
|
||||
return
|
||||
}
|
||||
m.BeginRemoveRows(core.NewQModelIndex(), len(m.modelData)-1, len(m.modelData)-1)
|
||||
m.modelData = m.modelData[:len(m.modelData)-1]
|
||||
m.EndRemoveRows()
|
||||
}
|
||||
}*/
|
||||
|
||||
func (m *QIdentityListModel) add(item []*core.QVariant) {
|
||||
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
|
||||
m.modelData = append(m.modelData, IdentityListItem{ item[0].ToString(), item[1].ToString(), item[2].ToString()})
|
||||
m.EndInsertRows()
|
||||
}
|
||||
|
||||
func (m *QIdentityListModel) AddItem(i IdentityListItem) {
|
||||
func (m *QIdentityListModel) Add(i IdentityListItem) {
|
||||
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
|
||||
m.modelData = append(m.modelData, i)
|
||||
m.EndInsertRows()
|
||||
}
|
||||
|
||||
func (m *QIdentityListModel) edit(name string, onion string, pcolor string) {
|
||||
func (m *QIdentityListModel) clickIdentity(s string) {
|
||||
fmt.Println("clickIdentity: '" + s + "'")
|
||||
}
|
||||
|
||||
/*func (m *QIdentityListModel) edit(name string, onion string, pcolor string) {
|
||||
if len(m.modelData) == 0 {
|
||||
return
|
||||
}
|
||||
m.modelData[len(m.modelData)-1] = IdentityListItem{name, onion, pcolor}
|
||||
m.DataChanged(m.Index(len(m.modelData)-1, 0, core.NewQModelIndex()), m.Index(len(m.modelData)-1, 1, core.NewQModelIndex()), []int{Name, Onion, Pcolor})
|
||||
}
|
||||
}*/
|
15
main.go
15
main.go
|
@ -34,7 +34,7 @@ func (qCwtchApp *QmlCwtchApp) init() {
|
|||
|
||||
var cwtchApp app.Application
|
||||
|
||||
func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp) error {
|
||||
func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp, identityList *QIdentityListModel) error {
|
||||
|
||||
torPath, err := exec.LookPath("tor")
|
||||
if err != nil {
|
||||
|
@ -72,6 +72,14 @@ func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp) error
|
|||
|
||||
|
||||
|
||||
/*identityList.Add(*NewIdentityListItemValues("alice", "1234567890abcdef", "red", identity))
|
||||
identityList.Add( *NewIdentityListItemValues( "unlock", "", "#af921d", unlock))
|
||||
identityList.Add( *NewIdentityListItemValues("add", "", "#e0e0e0", add))*/
|
||||
|
||||
identityList.Add( IdentityListItem{"alice", "1234567890abcdef", "red", identity})
|
||||
identityList.Add( IdentityListItem{"unlock", "", "#af921d", unlock})
|
||||
identityList.Add( IdentityListItem{"add", "", "#e0e0e0", add})
|
||||
|
||||
<-doneChan
|
||||
|
||||
return nil
|
||||
|
@ -94,8 +102,7 @@ func main() {
|
|||
|
||||
var qCwtchApp = NewQmlCwtchApp(nil)
|
||||
var identityList = NewQIdentityListModel(nil)
|
||||
alice := IdentityListItem{"alice", "1234567890abcdef", "red"}
|
||||
identityList.AddItem(alice)
|
||||
|
||||
|
||||
//qCwtchApp.SetIdentities(append(qCwtchApp.Identities(), alice))*/
|
||||
|
||||
|
@ -116,7 +123,7 @@ func main() {
|
|||
//engine.Load(core.QUrl_FromLocalFile("./qml/main.qml"))
|
||||
engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
|
||||
|
||||
go InitCwtch(engine, qCwtchApp)
|
||||
go InitCwtch(engine, qCwtchApp, identityList)
|
||||
// start the main Qt event loop
|
||||
// and block until app.Exit() is called
|
||||
// or the window is closed by the user
|
||||
|
|
|
@ -51,13 +51,13 @@ Window {
|
|||
ListElement {type: "bulletin"; title: "Game Discussions"; groupid: "cc45892408123879273ec2a435cc4234"}
|
||||
}
|
||||
|
||||
Connections {
|
||||
/*Connections {
|
||||
target: cwtchApp
|
||||
|
||||
onIdentitiesChanged: { /*ProfilesColumn.model = cwtchApp.identities ;
|
||||
profilesColumn.update();*/
|
||||
onIdentitiesChanged: { ProfilesColumn.model = cwtchApp.identities ;
|
||||
profilesColumn.update();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,32 +7,53 @@ Rectangle {
|
|||
|
||||
property alias model: list.model
|
||||
|
||||
Text { color: "white"; text: "length: " + cwtchApp.identities.length }
|
||||
|
||||
|
||||
ListView {
|
||||
id: list
|
||||
//height: parent.height
|
||||
width: parent.width
|
||||
anchors.fill: parent
|
||||
|
||||
//highlight: Rectangle { border-color: "white"; radius: 5 }
|
||||
highlight: Item { Rectangle { width: 4; height: 100; color: "white"; radius: 2} }
|
||||
|
||||
delegate: Component {
|
||||
id: profileDelegate
|
||||
//highlight: highlightBar
|
||||
//highlightFollowsCurrentItem: false
|
||||
|
||||
delegate: profileDelegate
|
||||
|
||||
Item {
|
||||
height: 100
|
||||
width: 100
|
||||
|
||||
Column {
|
||||
Rectangle { width: 80; height: 80; color: Pcolor }
|
||||
Text { color: "#a0a0a0"; text: Name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: profileDelegate
|
||||
|
||||
Item {
|
||||
height: 100
|
||||
width: 100
|
||||
|
||||
Column {
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
|
||||
Rectangle { y: 10; width: 80; height: 80; color: model.Color }
|
||||
Text { color: "#a0a0a0"; text: Name }
|
||||
}
|
||||
|
||||
|
||||
MouseArea {
|
||||
id: profile_mousearea
|
||||
z: 1
|
||||
hoverEnabled: false
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
list.currentIndex = index
|
||||
list.model.clickIdentity(model.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue