Adjust the look of the native StandatdTableView

- The header should be within the frame
 - Use the NativeStandardListViewItem so we have the right alternative
   row coloring and hover
This commit is contained in:
Olivier Goffart 2023-01-23 11:34:26 +01:00 committed by Olivier Goffart
parent aad6cbbe07
commit fabebaa009
2 changed files with 73 additions and 39 deletions

View file

@ -146,6 +146,13 @@ impl Item for NativeStandardListViewItem {
qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &option, painter->get(), widget);
qApp->style()->drawControl(QStyle::CE_ItemViewItem, &option, painter->get(), widget);
engine->setSystemClip(old_clip);
// Qt is seriously bugged, setSystemClip will be scaled by the scale factor
auto actual_clip = engine->systemClip();
if (actual_clip != old_clip) {
QSizeF s2 = actual_clip.boundingRect().size();
QSizeF s1 = old_clip.boundingRect().size();
engine->setSystemClip(old_clip * QTransform::fromScale(s1.width() / s2.width(), s1.height() / s2.height()));
}
});
}
}

View file

@ -265,7 +265,6 @@ export component StandardTableView {
callback sort-ascending(int);
callback sort-descending(int);
private property <length> min-header-height: 42px;
out property <int> current-sort-column: -1;
in-out property <[TableColumn]> columns;
in property <[[StandardListViewItem]]> rows;
@ -289,11 +288,74 @@ export component StandardTableView {
current-sort-column = index;
}
VerticalLayout {
HorizontalLayout {
scroll-view := NativeScrollView {
vertical-max: fli.viewport-height > fli.height ? fli.viewport-height - fli.height : 0phx;
vertical-page-size: fli.height;
horizontal-max: fli.viewport-width > fli.width ? fli.viewport-width - fli.width : 0phx;
horizontal-page-size: fli.width;
fli := Flickable {
x: scroll-view.native-padding-left;
width: scroll-view.width - scroll-view.native-padding-left - scroll-view.native-padding-right;
y: scroll-view.native-padding-top + header.height;
height: scroll-view.height - self.y - scroll-view.native-padding-bottom;
interactive: false;
viewport-y <=> scroll-view.vertical-value;
viewport-x <=> scroll-view.horizontal-value;
VerticalLayout {
alignment: start;
for row[i] in rows : Rectangle {
row-ta := TouchArea {}
HorizontalLayout {
for cell[index] in row : Rectangle {
horizontal-stretch: columns[index].horizontal-stretch;
min-width: columns[index].min-width;
preferred-width: columns[index].min-width;
HorizontalLayout {
if cell.editable : NativeStandardListViewItem {
index: i;
//is-selected: root.current-item == i;
has-hover: row-ta.has-hover;
LineEditInner {
text: cell.text;
edited => {
cell.text = self.text;
}
}
}
if !cell.editable : NativeStandardListViewItem {
item: cell;
index: i;
//is-selected: root.current-item == i;
has-hover: row-ta.has-hover;
}
}
}
}
}
}
}
}
header := Rectangle {
clip: true;
height: header-layout.preferred-height;
x: scroll-view.native-padding-left;
y: scroll-view.native-padding-top;
width: fli.width;
header-layout := HorizontalLayout {
width: max(self.preferred-width, parent.width);
x: fli.viewport-x;
for column[index] in columns : NativeTableHeaderSection {
item: column;
horizontal-stretch: column.horizontal-stretch;
min-width: columns[index].min-width;
preferred-width: columns[index].min-width;
TouchArea {
clicked => {
@ -302,41 +364,6 @@ export component StandardTableView {
}
}
}
scroll-view := ScrollView {
vertical-stretch: 1;
VerticalLayout {
alignment: start;
for row[i] in rows : HorizontalLayout {
for cell[index] in row : HorizontalBox {
horizontal-stretch: columns[index].horizontal-stretch;
min-width: columns[index].min-width;
min-height: root.min-header-height;
Rectangle {
line-edit := LineEditInner {
opacity: self.has-focus ? 1.0 : 0.0;
visible: cell.editable;
text: cell.text;
edited => {
cell.text = self.text;
}
}
if(!cell.editable || !line-edit.has-focus) : Text {
font-size: line-edit.font-size;
width: 100%;
height: 100%;
overflow: elide;
vertical-alignment: center;
text: cell.text;
}
}
}
}
}
}
}
}