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