mirror of
https://github.com/muesli/telephant
synced 2024-11-13 23:37:11 +00:00
Show a horizontal scroll-bar when we run out of space
This commit is contained in:
parent
055881d488
commit
fe1e83cf24
4 changed files with 56 additions and 28 deletions
25
panemodel.go
25
panemodel.go
|
@ -7,6 +7,7 @@ import (
|
||||||
// Model Roles
|
// Model Roles
|
||||||
const (
|
const (
|
||||||
PaneName = int(core.Qt__UserRole) + 1<<iota
|
PaneName = int(core.Qt__UserRole) + 1<<iota
|
||||||
|
PaneSticky
|
||||||
MsgModel
|
MsgModel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,14 +28,16 @@ type PaneModel struct {
|
||||||
type Pane struct {
|
type Pane struct {
|
||||||
core.QObject
|
core.QObject
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Model *MessageModel
|
Sticky bool
|
||||||
|
Model *MessageModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PaneModel) init() {
|
func (m *PaneModel) init() {
|
||||||
m.SetRoles(map[int]*core.QByteArray{
|
m.SetRoles(map[int]*core.QByteArray{
|
||||||
PaneName: core.NewQByteArray2("panename", -1),
|
PaneName: core.NewQByteArray2("panename", -1),
|
||||||
MsgModel: core.NewQByteArray2("msgmodel", -1),
|
PaneSticky: core.NewQByteArray2("panesticky", -1),
|
||||||
|
MsgModel: core.NewQByteArray2("msgmodel", -1),
|
||||||
})
|
})
|
||||||
|
|
||||||
m.ConnectData(m.data)
|
m.ConnectData(m.data)
|
||||||
|
@ -72,6 +75,10 @@ func (m *PaneModel) data(index *core.QModelIndex, role int) *core.QVariant {
|
||||||
{
|
{
|
||||||
return core.NewQVariant14(p.Name)
|
return core.NewQVariant14(p.Name)
|
||||||
}
|
}
|
||||||
|
case PaneSticky:
|
||||||
|
{
|
||||||
|
return core.NewQVariant11(p.Sticky)
|
||||||
|
}
|
||||||
case MsgModel:
|
case MsgModel:
|
||||||
{
|
{
|
||||||
return p.Model.ToVariant()
|
return p.Model.ToVariant()
|
||||||
|
@ -97,8 +104,14 @@ func (m *PaneModel) roleNames() map[int]*core.QByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PaneModel) addPane(p *Pane) {
|
func (m *PaneModel) addPane(p *Pane) {
|
||||||
m.BeginInsertRows(core.NewQModelIndex(), len(m.Panes()), len(m.Panes()))
|
// add pane before the last pane, which is always the notifications pane
|
||||||
m.SetPanes(append(m.Panes(), p))
|
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]))
|
||||||
|
}
|
||||||
m.EndInsertRows()
|
m.EndInsertRows()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,13 @@ import QtQuick.Layouts 1.3
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
property int idx
|
property int idx
|
||||||
property string name
|
property string name
|
||||||
|
property bool sticky
|
||||||
property variant messageModel
|
property variant messageModel
|
||||||
|
|
||||||
MessageList {
|
MessageList {
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.minimumWidth: 320
|
||||||
|
|
||||||
id: messagePane
|
id: messagePane
|
||||||
anchors.margins: 16
|
anchors.margins: 16
|
||||||
|
@ -33,6 +35,7 @@ ColumnLayout {
|
||||||
verticalAlignment: Label.AlignVCenter
|
verticalAlignment: Label.AlignVCenter
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
|
visible: !sticky
|
||||||
z: 3
|
z: 3
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.rightMargin: 24
|
anchors.rightMargin: 24
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import QtQuick 2.4
|
import QtQuick 2.4
|
||||||
import QtQuick.Controls 2.1
|
import QtQuick.Controls 2.5
|
||||||
import QtQuick.Controls.Material 2.1
|
import QtQuick.Controls.Material 2.1
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ ApplicationWindow {
|
||||||
color: Material.color(Material.Grey, Material.Shade900)
|
color: Material.color(Material.Grey, Material.Shade900)
|
||||||
}
|
}
|
||||||
|
|
||||||
minimumWidth: 790
|
minimumWidth: 600
|
||||||
minimumHeight: 590
|
minimumHeight: 590
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
@ -268,24 +268,33 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout {
|
ScrollView {
|
||||||
id: maingrid
|
id: mainscroll
|
||||||
// columns: accountBridge.panes.length
|
|
||||||
rows: 1
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 0
|
ScrollBar.horizontal.policy: contentWidth > width ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
|
||||||
columnSpacing: 0
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
||||||
rowSpacing: 0
|
contentWidth: Math.max(maingrid.implicitWidth, width)
|
||||||
|
|
||||||
Repeater {
|
GridLayout {
|
||||||
model: accountBridge.panes
|
id: maingrid
|
||||||
MessagePane {
|
// columns: accountBridge.panes.length
|
||||||
Layout.row: 0
|
rows: 1
|
||||||
Layout.column: index
|
anchors.fill: parent
|
||||||
|
anchors.margins: 0
|
||||||
|
columnSpacing: 0
|
||||||
|
rowSpacing: 0
|
||||||
|
|
||||||
idx: index
|
Repeater {
|
||||||
name: model.panename
|
model: accountBridge.panes
|
||||||
messageModel: model.msgmodel
|
MessagePane {
|
||||||
|
Layout.row: 0
|
||||||
|
Layout.column: index
|
||||||
|
|
||||||
|
idx: index
|
||||||
|
name: model.panename
|
||||||
|
sticky: model.panesticky
|
||||||
|
messageModel: model.msgmodel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
telephant.go
13
telephant.go
|
@ -244,18 +244,21 @@ func runApp(config Config) {
|
||||||
// setupMastodon starts a new Mastodon client and sets up event handling & models for it
|
// setupMastodon starts a new Mastodon client and sets up event handling & models for it
|
||||||
func setupMastodon(config Account) {
|
func setupMastodon(config Account) {
|
||||||
tc = mastodon.NewAccount(config.Instance, config.Token, config.ClientID, config.ClientSecret)
|
tc = mastodon.NewAccount(config.Instance, config.Token, config.ClientID, config.ClientSecret)
|
||||||
|
|
||||||
postModel := NewMessageModel(nil)
|
postModel := NewMessageModel(nil)
|
||||||
|
|
||||||
|
// Notifications model must the first model to be added
|
||||||
|
// It will always be displayed right-most
|
||||||
{
|
{
|
||||||
var pane = NewPane(nil)
|
var pane = NewPane(nil)
|
||||||
pane.Name = "Messages"
|
pane.Name = "Notifications"
|
||||||
pane.Model = postModel
|
pane.Sticky = true
|
||||||
|
pane.Model = notificationModel
|
||||||
paneModel.AddPane(pane)
|
paneModel.AddPane(pane)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var pane = NewPane(nil)
|
var pane = NewPane(nil)
|
||||||
pane.Name = "Notifications"
|
pane.Name = "Messages"
|
||||||
pane.Model = notificationModel
|
pane.Model = postModel
|
||||||
paneModel.AddPane(pane)
|
paneModel.AddPane(pane)
|
||||||
}
|
}
|
||||||
accountBridge.SetPanes(paneModel)
|
accountBridge.SetPanes(paneModel)
|
||||||
|
|
Loading…
Reference in a new issue