Merged revision(s) 49361-49362 #04bb74e7d0-#04bb74e7d0 from trunk:

Qt: proper clear of message in QStatusBar. Patch by David Jenkins. issue #28307
........
Qt: fixed items sizing in TListView.Also, added center alignment of text for vsIcon viewstyle.Patch by David Jenkins, modified by me. issue #28212
........

git-svn-id: branches/fixes_1_4@49446 -
This commit is contained in:
maxim 2015-06-25 20:41:36 +00:00
parent 6d3c46e16b
commit 92fc45400d
2 changed files with 24 additions and 74 deletions

View File

@ -1461,8 +1461,6 @@ 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;
@ -1911,6 +1909,7 @@ implementation
uses
Buttons,
math,
qtCaret,
qtproc,
qtprivate,
@ -5167,7 +5166,7 @@ class procedure TQtWidget.removeProperty(AObject: QObjectH; APropName: PAnsiChar
var
AVariant: QVariantH;
begin
AVariant := QVariant_create(QVariantInvalid);
AVariant := QVariant_create;
QObject_setProperty(AObject, APropName, AVariant);
QVariant_destroy(AVariant);
end;
@ -12573,7 +12572,10 @@ var
begin
Item := QListWidgetItem_create(AText, nil, QListWidgetItemType);
if Checkable then
QListWidgetItem_setCheckState(Item, QtUnChecked);
QListWidgetItem_setCheckState(Item, QtUnChecked)
else
if (ViewStyle = Ord(vsIcon)) and not (FChildOfComplexWidget = ccwComboBox) then
QListWidgetItem_setTextAlignment(Item, QtAlignHCenter);
QListWidget_insertItem(QListWidgetH(Widget), AIndex, Item);
end;
@ -14190,33 +14192,6 @@ 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;
ASizeHint: TSize;
begin
Result := False;
if AIconSize = 0 then
exit;
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);
@ -14350,7 +14325,7 @@ var
v: QVariantH;
begin
if Data = nil then
v := QVariant_create(QVariantInvalid)
v := QVariant_create
else
v := QVariant_create(Int64({%H-}PtrUInt(Data)));
QTreeWidgetItem_setData(AItem, AColumn, ARole, v);
@ -17781,10 +17756,14 @@ procedure TQtAbstractItemView.ItemDelegateSizeHint(
var
Msg: TLMMeasureItem;
MeasureItemStruct: TMeasureItemStruct;
decorationSize: TSize;
Metric: Integer;
begin
QStyleOptionViewItem_decorationSize(option, @decorationSize);
Metric := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameVMargin, nil, nil) * 2;
MeasureItemStruct.itemID := UINT(QModelIndex_row(index));
MeasureItemStruct.itemWidth := UINT(Size^.cx);
MeasureItemStruct.itemHeight := UINT(Size^.cy);
MeasureItemStruct.itemHeight := UINT(Max(Size^.cy, (decorationSize.cy + Metric)));
Msg.Msg := LM_MEASUREITEM;
Msg.MeasureItemStruct := @MeasureItemStruct;
DeliverMessage(Msg);

View File

@ -557,9 +557,8 @@ var
Str: WideString;
i: Integer;
begin
Str := '';
//clean up. http://bugs.freepascal.org/view.php?id=18683
Widget.showMessage(@Str);
// issues #18683 and #28307
QStatusBar_clearMessage(QStatusBarH(Widget.Widget));
ClearPanels(Widget);
if AStatusBar.SimplePanel then
begin
@ -1467,27 +1466,6 @@ begin
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
AImages := TCustomListViewHack(ALV).LargeImages;
if not Assigned(AImages) then
AImages := TCustomListViewHack(ALV).SmallImages;
if Assigned(AImages) then
begin
AMetric := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameVMargin, nil, nil) * 2;
QTreeWidgetItem_sizeHint(TWI, @ASizeHint, 0);
ASizeHint.cy := AImages.Height + AMetric;
QTreeWidgetItem_setSizeHint(TWI, 0, @ASizeHint);
for i := 0 to AItem.SubItems.Count - 1 do
QTreeWidgetItem_setSizeHint(TWI, i + 1, @ASizeHint);
end;
end;
for i := 0 to AItem.SubItems.Count - 1 do
begin
AAlignment := QtAlignLeft or QtAlignVCenter;
@ -1498,9 +1476,6 @@ 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;
@ -1522,7 +1497,6 @@ var
TWI: QTreeWidgetItemH;
Str: WideString;
AAlignment: QtAlignment;
AIconWidth: integer;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
Exit;
@ -1531,7 +1505,10 @@ begin
begin
if ASubIndex >0 Then exit;
QtListWidget := TQtListWidget(ALV.Handle);
AAlignment := QtAlignLeft;
if not QtListWidget.Checkable and (TCustomListViewHack(ALV).ViewStyle = vsIcon) then
AAlignment := QtAlignHCenter
else
AAlignment := QtAlignLeft;
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment];
QtListWidget.setItemText(AIndex, AText, AAlignment);
@ -1546,17 +1523,6 @@ 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 (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex >= 0) and
(ASubIndex < TCustomListViewHack(ALV).Columns.Count) and
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;
@ -2302,9 +2268,14 @@ begin
end;
vsList, vsReport:
begin
x := GetPixelMetric(QStylePM_ListViewIconSize, nil, ItemViewWidget);
x := 0;
Size.cx := x;
Size.cy := x;
if Assigned(TCustomListViewHack(ALV).SmallImages) then
begin
Size.cy := TCustomListViewHack(ALV).SmallImages.Height;
Size.cx := TCustomListViewHack(ALV).SmallImages.Width;
end;
TQtAbstractItemView(ALV.Handle).OwnerDrawn :=
TCustomListViewHack(ALV).IsCustomDrawn(dtControl, cdPrePaint) or
(TCustomListViewHack(ALV).OwnerDraw and