Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/framework/dockwindow/qml/Muse/Dock/DockPanelTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ StyledTabButton {

property alias contextMenuModel: contextMenuButton.menuModel

property bool isCutOff: false

signal handleContextMenuItemRequested(string itemId)

readonly property real actualHeight: 34
Expand Down Expand Up @@ -109,7 +111,7 @@ StyledTabButton {
}

Rectangle {
visible: root.width < root.implicitWidth
visible: root.isCutOff

anchors.top: root.top
anchors.right: root.right
Expand All @@ -119,7 +121,6 @@ StyledTabButton {

width: 20

opacity: 0.7
gradient: Gradient {
orientation: Qt.Horizontal

Expand All @@ -129,7 +130,7 @@ StyledTabButton {
}
GradientStop {
position: 1.0
color: backgroundRect.color
color: Utils.colorWithAlpha(backgroundRect.color, 0.7)
}
}
}
Expand Down
59 changes: 36 additions & 23 deletions src/framework/dockwindow/qml/Muse/Dock/DockTabBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,42 +90,55 @@ Rectangle {
spacing: 0

readonly property real availableWidth: root.width + 1 // + 1, because we don't need to see the rightmost separator
readonly property real implicitWidthOfActiveTab: currentItem ? currentItem.implicitWidth : 0
readonly property real implicitWidthOfAllTabsTogether: {
let result = 0
let items = tabs.contentItem.children

for (let i in items) {
let item = items[i]
if (item && item.implicitWidth) {
result += item.implicitWidth
}

onAvailableWidthChanged: { layoutTabs() }

property bool layoutTabsScheduled: false

function layoutTabs() {
if (!layoutTabsScheduled) {
Qt.callLater(doLayoutTabs)
layoutTabsScheduled = true
}
}

function doLayoutTabs() {
layoutTabsScheduled = false

let implicitWidthOfActiveTab = currentItem?.implicitWidth ?? 0
let implicitWidthOfAllTabsTogether = 0

for (let tab of contentItem.children) {
implicitWidthOfAllTabsTogether += tab?.implicitWidth ?? 0
}

return result
const enoughSpace = implicitWidthOfAllTabsTogether <= availableWidth;
for (let tab of contentItem.children) {
if (tab.isCurrent || enoughSpace) {
tab.width = tab.implicitWidth
tab.isCutOff = false
} else {
tab.width = (availableWidth - implicitWidthOfActiveTab)
/ (implicitWidthOfAllTabsTogether - implicitWidthOfActiveTab)
* tab.implicitWidth
tab.isCutOff = true
}
}
}

delegate: DockPanelTab {
text: model.title
isCurrent: root.currentIndex === model.index
contextMenuModel: model.contextMenu

width: {
var w
if (isCurrent || tabs.implicitWidthOfAllTabsTogether <= tabs.availableWidth) {
w = implicitWidth
} else {
w = (tabs.availableWidth - tabs.implicitWidthOfActiveTab)
/ (tabs.implicitWidthOfAllTabsTogether - tabs.implicitWidthOfActiveTab)
* implicitWidth
}
return w
}

navigation.name: text
navigation.panel: root.navigationPanel
navigation.order: model.index * 2 // NOTE '...' button will have +1 order

Component.onCompleted: { tabs.layoutTabs() }

onImplicitWidthChanged: { tabs.layoutTabs() }

onNavigationTriggered: {
root.tabClicked(model.index)
}
Expand Down
Loading