mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 17:59:16 +02:00
Qt: implemented minimum column size for TListView. Fixed TListView.Columns.AutoSize. issue #27696
git-svn-id: trunk@48475 -
This commit is contained in:
parent
c02daaa84b
commit
997a2f114d
@ -184,6 +184,8 @@ type
|
||||
function DeliverMessage(var Msg; const AIsInputEvent: Boolean = False): LRESULT; virtual;
|
||||
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
|
||||
function getAcceptDropFiles: Boolean; virtual;
|
||||
{precise measure of text with widget''s current font when canvas.handle isn''t available}
|
||||
function measureText(AText: WideString; AFlags: cardinal): TRect;
|
||||
procedure SetNoMousePropagation(Sender: QWidgetH; const ANoMousePropagation: Boolean); virtual;
|
||||
procedure SetLCLFont(AFont: TQtFont);
|
||||
procedure SlotShow(vShow: Boolean); cdecl;
|
||||
@ -1370,6 +1372,8 @@ type
|
||||
function getResizeMode(AIndex: Integer): QHeaderViewResizeMode;
|
||||
procedure setResizeMode(AResizeMode: QHeaderViewResizeMode); overload;
|
||||
procedure setResizeMode(AIndex: Integer; AResizeMode: QHeaderViewResizeMode); overload;
|
||||
function sectionSize(AIndex: Integer): Integer;
|
||||
function sectionSizeHint(AIndex: Integer): Integer;
|
||||
procedure moveSection(AFromIndex: Integer; AToIndex: Integer);
|
||||
procedure resizeSection(ASection: Integer; ASize: Integer);
|
||||
procedure setHighlightSections(AValue: Boolean);
|
||||
@ -1455,6 +1459,8 @@ type
|
||||
function currentItem: QTreeWidgetItemH;
|
||||
procedure setCurrentItem(AItem: QTreeWidgetItemH);
|
||||
|
||||
function SetItemSizeHint(AItem: QTreeWidgetItemH;
|
||||
AColumn: integer; AText: widestring; AIconSize: integer): boolean;
|
||||
function getRow(AItem: QTreeWidgetItemH): integer;
|
||||
function headerItem: QTreeWidgetItemH;
|
||||
function itemAt(APoint: TPoint): QTreeWidgetItemH; overload;
|
||||
@ -2703,6 +2709,25 @@ begin
|
||||
Result := TQtMainWindow(Form.Handle).getAcceptDropFiles;
|
||||
end;
|
||||
|
||||
function TQtWidget.measureText(AText: WideString; AFlags: cardinal): TRect;
|
||||
var
|
||||
AMetrics: QFontMetricsH;
|
||||
AFont: QFontH;
|
||||
begin
|
||||
Result := Rect(0, 0, 0, 0);
|
||||
if Assigned(LCLObject) and Assigned(LCLObject.Font) and
|
||||
LCLObject.Font.HandleAllocated then
|
||||
AFont := TQtFont(LCLObject.Font.Reference.Handle).FHandle
|
||||
else
|
||||
AFont := QWidget_font(Widget);
|
||||
AMetrics := QFontMetrics_create(AFont);
|
||||
try
|
||||
QFontMetrics_boundingRect(AMetrics, @Result, @AText);
|
||||
finally
|
||||
QFontMetrics_destroy(AMetrics);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtWidget.SetNoMousePropagation(Sender: QWidgetH;
|
||||
const ANoMousePropagation: Boolean);
|
||||
begin
|
||||
@ -13123,7 +13148,7 @@ end;
|
||||
Params: None
|
||||
Returns: Nothing
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TQtHeaderView.SignalSectionClicked(logicalIndex: Integer) cdecl;
|
||||
procedure TQtHeaderView.SignalSectionClicked(logicalIndex: Integer); cdecl;
|
||||
var
|
||||
Msg: TLMNotify;
|
||||
NMLV: TNMListView;
|
||||
@ -13163,6 +13188,16 @@ begin
|
||||
QHeaderView_setResizeMode(QHeaderViewH(Widget), AIndex, AResizeMode);
|
||||
end;
|
||||
|
||||
function TQtHeaderView.sectionSize(AIndex: Integer): Integer;
|
||||
begin
|
||||
Result := QHeaderView_sectionSize(QHeaderViewH(Widget), AIndex);
|
||||
end;
|
||||
|
||||
function TQtHeaderView.sectionSizeHint(AIndex: Integer): Integer;
|
||||
begin
|
||||
Result := QHeaderView_sectionSizeHint(QHeaderViewH(Widget), AIndex);
|
||||
end;
|
||||
|
||||
procedure TQtHeaderView.moveSection(AFromIndex: Integer; AToIndex: Integer);
|
||||
begin
|
||||
QHeaderView_moveSection(QHeaderViewH(Widget), AFromIndex, AToIndex);
|
||||
@ -14066,8 +14101,7 @@ end;
|
||||
|
||||
procedure TQtTreeWidget.setMinColSize(ACol: Integer; const AValue: Integer);
|
||||
begin
|
||||
// QTreeWidgetItem_setSizeHint(headerItem, @Size, ACol);
|
||||
{$note QSizeH implementation missing for TQtTreeWidget.setMinColSize}
|
||||
QHeaderView_setMinimumSectionSize(QTreeView_header(QTreeViewH(Widget)), AValue);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -14117,6 +14151,32 @@ begin
|
||||
QTreeWidget_setCurrentItem(QTreeWidgetH(Widget), AItem);
|
||||
end;
|
||||
|
||||
function TQtTreeWidget.SetItemSizeHint(AItem: QTreeWidgetItemH;
|
||||
AColumn: integer; AText: widestring; AIconSize: integer): boolean;
|
||||
var
|
||||
R: TRect;
|
||||
ATextWidth: Integer;
|
||||
AMargin: Integer;
|
||||
i: Integer;
|
||||
ASizeHint: TSize;
|
||||
begin
|
||||
Result := False;
|
||||
R := measureText(AText, 0);
|
||||
ATextWidth := R.Right - R.Left;
|
||||
if AIconSize > 0 then
|
||||
begin
|
||||
AMargin := QStyle_pixelMetric(QApplication_style(), QStylePM_ButtonMargin, nil, Widget);
|
||||
if AColumn = 0 then
|
||||
ATextWidth += AIconSize + (AMargin * 2)
|
||||
else
|
||||
ATextWidth += AMargin;
|
||||
end;
|
||||
QTreeWidgetItem_sizeHint(AItem, @ASizeHint, AColumn);
|
||||
ASizeHint.cx := ATextWidth;
|
||||
QTreeWidgetItem_setSizeHint(AItem, AColumn, @ASizeHint);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TQtTreeWidget.getRow(AItem: QTreeWidgetItemH): integer;
|
||||
begin
|
||||
Result := QTreeWidget_indexOfTopLevelItem(QTreeWidgetH(Widget), AItem);
|
||||
|
@ -1426,6 +1426,7 @@ var
|
||||
AImages: TCustomImageList;
|
||||
AMetric: Integer;
|
||||
ASizeHint: TSize;
|
||||
AIconWidth: Integer;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ALV, 'ItemInsert') then
|
||||
Exit;
|
||||
@ -1461,6 +1462,15 @@ begin
|
||||
|
||||
QtTreeWidget.setItemData(TWI, 0, AItem);
|
||||
|
||||
if Assigned(TCustomListViewHack(ALV).SmallImages) then
|
||||
AIconWidth := TCustomListViewHack(ALV).SmallImages.Width
|
||||
else
|
||||
AIconWidth := 0;
|
||||
|
||||
{issue #27696 for autosized columns we must provide sizehint}
|
||||
if (ALV.ColumnCount > 0) and (ALV.Column[0].AutoSize) then
|
||||
QtTreeWidget.SetItemSizeHint(TWI, 0, Str, AIconWidth);
|
||||
|
||||
// issue #27043
|
||||
if (ALV.Items[AIndex].ImageIndex = -1) then
|
||||
begin
|
||||
@ -1488,6 +1498,9 @@ begin
|
||||
Str := GetUtf8String(AItem.Subitems.Strings[i]);
|
||||
QtTreeWidget.setItemText(TWI, i + 1, Str, AAlignment);
|
||||
QtTreeWidget.setItemData(TWI, i + 1, AItem);
|
||||
{issue #27696 for autosized columns we must provide sizehint}
|
||||
if (i + 1 < ALV.ColumnCount) and (ALV.Column[i + 1].AutoSize) then
|
||||
QtTreeWidget.SetItemSizeHint(TWI, i + 1, Str, AIconWidth);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1509,6 +1522,7 @@ var
|
||||
TWI: QTreeWidgetItemH;
|
||||
Str: WideString;
|
||||
AAlignment: QtAlignment;
|
||||
AIconWidth: integer;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
|
||||
Exit;
|
||||
@ -1532,6 +1546,15 @@ begin
|
||||
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
|
||||
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment] or QtAlignVCenter;
|
||||
QtTreeWidget.setItemText(TWI, ASubIndex, Str, AAlignment);
|
||||
{issue #27696 for autosized columns we must provide sizehint}
|
||||
if ALV.Column[ASubIndex].AutoSize then
|
||||
begin
|
||||
if Assigned(TCustomListViewHack(ALV).SmallImages) then
|
||||
AIconWidth := TCustomListViewHack(ALV).SmallImages.Width
|
||||
else
|
||||
AIconWidth := 0;
|
||||
QtTreeWidget.SetItemSizeHint(TWI, ASubIndex, Str, AIconWidth);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user