Commit 76612279 authored by Jörg Schummer's avatar Jörg Schummer Committed by Kai Koehne
Browse files

QmlDesigner.ItemLibrary: fixed eliding text

- also removed tabs from Qml files
parent 1bb65f40
......@@ -101,13 +101,13 @@ Item {
Text {
id: text
elide: ElideMiddle
elide: Text.ElideMiddle
anchors.top: itemIcon.bottom
anchors.topMargin: style.cellVerticalSpacing
anchors.left: parent.left
anchors.leftMargin: style.cellHorizontalMargin
anchors.right: parent.right
anchors.rightMargin: style.cellHorizontalMargin
anchors.leftMargin: style.cellHorizontalMargin
anchors.right: parent.right
anchors.rightMargin: style.cellHorizontalMargin
width: style.textWidth
height: style.textHeight
......
......@@ -31,28 +31,28 @@ import Qt 4.6
/* The view displaying the item grid.
The following Qml context properties have to be set:
- listmodel itemLibraryModel
- int itemLibraryIconWidth
- int itemLibraryIconHeight
itemLibraryModel has to have the following structure:
ListModel {
ListElement {
int sectionLibId
string sectionName
list sectionEntries: [
ListElement {
int itemLibId
string itemName
pixmap itemPixmap
},
...
]
}
...
}
The following Qml context properties have to be set:
- listmodel itemLibraryModel
- int itemLibraryIconWidth
- int itemLibraryIconHeight
itemLibraryModel has to have the following structure:
ListModel {
ListElement {
int sectionLibId
string sectionName
list sectionEntries: [
ListElement {
int itemLibId
string itemName
pixmap itemPixmap
},
...
]
}
...
}
*/
Rectangle {
......@@ -79,149 +79,149 @@ Rectangle {
color: style.backgroundColor
/* workaround: without this, a completed drag and drop operation would
result in the drag being continued when QmlView re-gains
focus */
result in the drag being continued when QmlView re-gains
focus */
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
if (!pressed)
stopDragAndDrop()
}
}
signal selectionUpdated(int itemSectionIndex)
property int selectedItemLibId: -1
property int selectionSectionLibId: -1
function setSelection(itemLibId) {
selectedItemLibId = itemLibId
selectionSectionLibId = itemLibraryModel.getSectionLibId(itemLibId)
selectionUpdated(itemLibraryModel.getItemSectionIndex(itemLibId))
}
function unsetSelection() {
selectedItemLibId = -1
selectionSectionLibId = -1
selectionUpdated(-1)
}
Connections {
target: itemLibraryModel
onVisibilityChanged: {
if (itemLibraryModel.isItemVisible(selectedItemLibId))
setSelection(selectedItemLibId)
else
unsetSelection()
}
}
/* the following 3 properties are calculated here for performance
reasons and then passed to the section views */
property int entriesPerRow: Math.max(1, Math.floor((itemsFlickable.width - 2) / style.cellWidth))
property int cellWidth: Math.floor((itemsFlickable.width - 2) / entriesPerRow)
property int cellHeight: style.cellHeight
Component {
id: sectionDelegate
SectionView {
id: section
entriesPerRow: itemsView.entriesPerRow
cellWidth: itemsView.cellWidth
cellHeight: itemsView.cellHeight
width: itemsFlickable.width
itemHighlight: selector
property bool containsSelection: (selectionSectionLibId == sectionLibId)
onItemSelected: {
itemsView.setSelection(itemLibId)
itemsView.itemSelected(itemLibId)
}
onItemDragged: {
section.itemSelected(itemLibId)
itemsView.itemDragged(itemLibId)
}
Connections {
target: itemsView
onExpandAllEntries: section.expand()
onSelectionUpdated: {
if (containsSelection) {
section.setSelection(itemSectionIndex)
section.focusSelection(itemsFlickable)
} else
section.unsetSelection()
}
}
Component {
id: selector
Selector {
x: containsSelection? section.currentItem.x:0
y: containsSelection? section.currentItem.y:0
width: itemsView.cellWidth
height: itemsView.cellHeight
visible: containsSelection
}
}
}
}
Flickable {
id: itemsFlickable
anchors.top: parent.top
anchors.topMargin: 3
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: scrollbar.left
overShoot: false
interactive: false
contentHeight: col.height
/* Limit the content position. Without this, resizing would get the
content position out of scope regarding the scrollbar. */
function limitContentPos() {
if (contentY < 0)
contentY = 0;
else {
var maxContentY = Math.max(0, contentHeight - height)
if (contentY > maxContentY)
contentY = maxContentY;
}
}
onHeightChanged: limitContentPos()
onContentHeightChanged: limitContentPos()
Column {
id: col
Repeater {
model: itemLibraryModel // to be set in Qml context
delegate: sectionDelegate
if (!pressed)
stopDragAndDrop()
}
}
}
}
Scrollbar {
id: scrollbar
anchors.top: parent.top
anchors.topMargin: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: 2
anchors.left: parent.right
anchors.leftMargin: -10
anchors.right: parent.right
flickable: itemsFlickable
}
}
signal selectionUpdated(int itemSectionIndex)
property int selectedItemLibId: -1
property int selectionSectionLibId: -1
function setSelection(itemLibId) {
selectedItemLibId = itemLibId
selectionSectionLibId = itemLibraryModel.getSectionLibId(itemLibId)
selectionUpdated(itemLibraryModel.getItemSectionIndex(itemLibId))
}
function unsetSelection() {
selectedItemLibId = -1
selectionSectionLibId = -1
selectionUpdated(-1)
}
Connections {
target: itemLibraryModel
onVisibilityChanged: {
if (itemLibraryModel.isItemVisible(selectedItemLibId))
setSelection(selectedItemLibId)
else
unsetSelection()
}
}
/* the following 3 properties are calculated here for performance
reasons and then passed to the section views */
property int entriesPerRow: Math.max(1, Math.floor((itemsFlickable.width - 2) / style.cellWidth))
property int cellWidth: Math.floor((itemsFlickable.width - 2) / entriesPerRow)
property int cellHeight: style.cellHeight
Component {
id: sectionDelegate
SectionView {
id: section
entriesPerRow: itemsView.entriesPerRow
cellWidth: itemsView.cellWidth
cellHeight: itemsView.cellHeight
width: itemsFlickable.width
itemHighlight: selector
property bool containsSelection: (selectionSectionLibId == sectionLibId)
onItemSelected: {
itemsView.setSelection(itemLibId)
itemsView.itemSelected(itemLibId)
}
onItemDragged: {
section.itemSelected(itemLibId)
itemsView.itemDragged(itemLibId)
}
Connections {
target: itemsView
onExpandAllEntries: section.expand()
onSelectionUpdated: {
if (containsSelection) {
section.setSelection(itemSectionIndex)
section.focusSelection(itemsFlickable)
} else
section.unsetSelection()
}
}
Component {
id: selector
Selector {
x: containsSelection? section.currentItem.x:0
y: containsSelection? section.currentItem.y:0
width: itemsView.cellWidth
height: itemsView.cellHeight
visible: containsSelection
}
}
}
}
Flickable {
id: itemsFlickable
anchors.top: parent.top
anchors.topMargin: 3
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: scrollbar.left
overShoot: false
interactive: false
contentHeight: col.height
/* Limit the content position. Without this, resizing would get the
content position out of scope regarding the scrollbar. */
function limitContentPos() {
if (contentY < 0)
contentY = 0;
else {
var maxContentY = Math.max(0, contentHeight - height)
if (contentY > maxContentY)
contentY = maxContentY;
}
}
onHeightChanged: limitContentPos()
onContentHeightChanged: limitContentPos()
Column {
id: col
Repeater {
model: itemLibraryModel // to be set in Qml context
delegate: sectionDelegate
}
}
}
Scrollbar {
id: scrollbar
anchors.top: parent.top
anchors.topMargin: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: 2
anchors.left: parent.right
anchors.leftMargin: -10
anchors.right: parent.right
flickable: itemsFlickable
}
}
......@@ -65,6 +65,6 @@ Item {
// the following depend on the actual shape of the item delegate
property int cellWidth: textWidth + 2 * cellHorizontalMargin
property int cellHeight: itemLibraryIconHeight + textHeight +
2 * cellVerticalMargin + cellVerticalSpacing
2 * cellVerticalMargin + cellVerticalSpacing
}
......@@ -39,7 +39,7 @@ Item {
property var flickable
function reset() {
handle.y = 0
handle.y = 0
}
// internal
......@@ -60,16 +60,16 @@ Item {
}
function updateHandle() {
handle.updateFlickable = false
handle.updateFlickable = false
if (flickable)
handle.y = scrollHeight * Math.min(
flickable.contentY / (flickable.contentHeight - flickable.height),
1)
else
handle.y = 0
if (flickable)
handle.y = scrollHeight * Math.min(
flickable.contentY / (flickable.contentHeight - flickable.height),
1)
else
handle.y = 0
handle.updateFlickable = true
handle.updateFlickable = true
}
onHeightChanged: updateHandle()
......@@ -103,38 +103,38 @@ Item {
anchors.left: parent.left
anchors.leftMargin: 1
anchors.right: parent.right
// anchors.rightMargin: 1
height: Math.max(width, bar.height * Math.min(1, flickable.height / flickable.contentHeight))
// anchors.rightMargin: 1
height: Math.max(width, bar.height * Math.min(1, flickable.height / flickable.contentHeight))
property bool updateFlickable: true
property bool updateFlickable: true
onYChanged: {
if (updateFlickable)
flickable.contentY = Math.max(0, flickable.contentHeight * y / bar.height)
}
Rectangle {
width: parent.height - 1
height: parent.width
y: 1 - height
rotation: 90
transformOrigin: Item.BottomLeft
onYChanged: {
if (updateFlickable)
flickable.contentY = Math.max(0, flickable.contentHeight * y / bar.height)
}
gradient: Gradient {
GradientStop { position: 0.0; color: style.scrollbarGradientStartColor }
GradientStop { position: 1.0; color: style.scrollbarGradientEndColor }
Rectangle {
width: parent.height - 1
height: parent.width
y: 1 - height
rotation: 90
transformOrigin: Item.BottomLeft
gradient: Gradient {
GradientStop { position: 0.0; color: style.scrollbarGradientStartColor }
GradientStop { position: 1.0; color: style.scrollbarGradientEndColor }
}
}
MouseArea {
anchors.fill: parent
drag.target: parent
drag.axis: "YAxis"
drag.minimumY: 0
drag.maximumY: scrollHeight
}
}
}
MouseArea {
anchors.fill: parent
drag.target: parent
drag.axis: "YAxis"
drag.minimumY: 0
drag.maximumY: scrollHeight
}
}
MouseArea {
anchors.left: parent.left
......
......@@ -53,34 +53,34 @@ Column {
function setSelection(itemSectionIndex)
{
gridView.currentIndex = itemSectionIndex
gridView.currentIndex = itemSectionIndex
}
function unsetSelection()
{
gridView.currentIndex = -1
gridView.currentIndex = -1
}
function focusSelection(flickable) {
var pos = -1;
var pos = -1;
if (!gridView.currentItem)
return;
if (!gridView.currentItem)
return;
var currentItemX = sectionView.x + gridFrame.x + gridView.x + gridView.currentItem.x;
var currentItemY = sectionView.y + gridFrame.y + gridView.y + gridView.currentItem.y
- gridView.contentY; // workaround: GridView reports wrong contentY
var currentItemX = sectionView.x + gridFrame.x + gridView.x + gridView.currentItem.x;
var currentItemY = sectionView.y + gridFrame.y + gridView.y + gridView.currentItem.y
- gridView.contentY; // workaround: GridView reports wrong contentY
if (currentItemY < flickable.contentY)
pos = Math.max(0, currentItemY)
if (currentItemY < flickable.contentY)
pos = Math.max(0, currentItemY)
else if ((currentItemY + gridView.currentItem.height) >
(flickable.contentY + flickable.height - 1))
pos = Math.min(Math.max(0, flickable.contentHeight - flickable.height),
currentItemY + gridView.currentItem.height - flickable.height + 1)
else if ((currentItemY + gridView.currentItem.height) >
(flickable.contentY + flickable.height - 1))
pos = Math.min(Math.max(0, flickable.contentHeight - flickable.height),
currentItemY + gridView.currentItem.height - flickable.height + 1)
if (pos >= 0)
flickable.contentY = pos
if (pos >= 0)
flickable.contentY = pos
}
// internal
......@@ -93,8 +93,8 @@ Column {
ItemView {
id: item
width: cellWidth
height: cellHeight
width: cellWidth
height: cellHeight
onItemPressed: sectionView.itemSelected(itemLibId)
onItemDragged: sectionView.itemDragged(itemLibId)
......@@ -134,7 +134,7 @@ Column {
text: sectionName // to be set by model
color: style.sectionTitleTextColor
elide: Text.ElideMiddle
elide: Text.ElideMiddle
}
MouseArea {
anchors.fill: parent
......@@ -162,11 +162,11 @@ Column {
Connections {
target: itemLibraryModel // to be set in Qml context
onSectionVisibilityChanged: {
/* workaround: reset model in order to get the grid view
updated properly under all conditions */
if (changedSectionLibId == sectionLibId)
gridView.model = sectionEntries
}
/* workaround: reset model in order to get the grid view
updated properly under all conditions */
if (changedSectionLibId == sectionLibId)
gridView.model = sectionEntries
}
}
anchors.fill: parent
......@@ -177,24 +177,24 @@ Column {
cellHeight: sectionView.cellHeight
model: sectionEntries // to be set by model
delegate: itemDelegate
highlight: itemHighlight
highlight: itemHighlight
interactive: false
highlightFollowsCurrentItem: false
}
states: [
State {
name: "shrunk"
PropertyChanges {
target: gridFrame
height: 0
opacity: 0
}
PropertyChanges {
target: arrow
rotation: -90
}
State {
name: "shrunk"
PropertyChanges {
target: gridFrame
height: 0
opacity: 0
}
PropertyChanges {
target: arrow
rotation: -90
}