Qt: implemented psOwnerDraw for TQtStatusBar panels.

git-svn-id: trunk@25816 -
This commit is contained in:
zeljko 2010-06-01 16:53:42 +00:00
parent 8de24d2ca4
commit 2a52b833dc
2 changed files with 134 additions and 12 deletions

View File

@ -1304,13 +1304,26 @@ type
procedure setInvertedAppearance(invert: Boolean);
end;
{ TQtStatusBarPanel }
TQtStatusBarPanel = class(TQtFrame)
private
FId: Integer;
procedure DrawItem(Sender: QObjectH; Event: QEventH);
protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
property ID: Integer read FId write FId;
end;
{ TQtStatusBar }
TQtStatusBar = class(TQtWidget)
protected
function CreateWidget(const AParams: TCreateParams): QWidgetH; override;
public
Panels: array of QLabelH;
Panels: array of TQtStatusBarPanel;
procedure showMessage(text: PWideString; timeout: Integer = 0);
procedure addWidget(AWidget: QWidgetH; AStretch: Integer = 0);
procedure removeWidget(AWidget: QWidgetH);
@ -10323,6 +10336,98 @@ begin
QProgressBar_reset(QProgressBarH(Widget));
end;
{ TQtStatusBarPanel }
function TQtStatusBarPanel.CreateWidget(const AParams: TCreateParams
): QWidgetH;
var
Parent: QWidgetH;
begin
// Creates the widget
{$ifdef VerboseQt}
WriteLn('TQtStatusBarPanel.Create');
{$endif}
if AParams.WndParent <> 0 then
Parent := TQtWidget(AParams.WndParent).GetContainerWidget
else
Parent := nil;
Result := QLabel_create(Parent);
QWidget_setAttribute(Result, QtWA_NoMousePropagation);
end;
procedure TQtStatusBarPanel.DrawItem(Sender: QObjectH; Event: QEventH);
var
Msg: TLMDrawItems;
AStruct: TPaintStruct;
ItemStruct: PDrawItemStruct;
P: TPoint;
begin
{$ifdef VerboseQt}
WriteLn('TQtWidget.DrawItem ', dbgsName(LCLObject));
{$endif}
if CanSendLCLMessage and (LCLObject is TWinControl) then
begin
FillChar(Msg, SizeOf(Msg), #0);
Msg.Msg := LM_DRAWITEM;
FillChar(AStruct, SizeOf(TPaintStruct), 0);
FillChar(ItemStruct, SizeOf(TDrawItemStruct), 0);
New(ItemStruct);
with PaintData do
begin
PaintWidget := QWidgetH(Sender);
ClipRegion := QPaintEvent_Region(QPaintEventH(Event));
if ClipRect = nil then
New(ClipRect);
QPaintEvent_Rect(QPaintEventH(Event), ClipRect);
end;
ItemStruct^.itemID := ID;
ItemStruct^._hDC := BeginPaint(THandle(Self), AStruct);
FContext := ItemStruct^._hDC;
ItemStruct^.rcItem := PaintData.ClipRect^;
ItemStruct^.hwndItem := HWND(Self);
Msg.Ctl := LCLObject.Handle;
Msg.DrawItemStruct := ItemStruct;
P := getClientOffset;
inc(P.X, FScrollX);
inc(P.Y, FScrollY);
TQtDeviceContext(FContext).translate(P.X, P.Y);
// send paint message
try
try
LCLObject.WindowProc(TLMessage(Msg));
finally
Dispose(PaintData.ClipRect);
Fillchar(FPaintData, SizeOf(FPaintData), 0);
FContext := 0;
EndPaint(THandle(Self), AStruct);
Dispose(ItemStruct);
end;
except
Application.HandleException(nil);
end;
end;
end;
function TQtStatusBarPanel.EventFilter(Sender: QObjectH; Event: QEventH
): Boolean; cdecl;
begin
Result := False;
QEvent_accept(Event);
if LCLObject = nil then
exit;
if HasPaint and (QEvent_type(Event) = QEventPaint) then
begin
DrawItem(Sender, Event);
Result := True;
end;
end;
{ TQtStatusBar }
function TQtStatusBar.CreateWidget(const AParams: TCreateParams): QWidgetH;

View File

@ -445,11 +445,16 @@ var
begin
if length(Widget.Panels) > 0 then
begin
Widget.setUpdatesEnabled(False);
for i := High(Widget.Panels) downto 0 do
begin
Widget.removeWidget(Widget.Panels[i]);
QLabel_destroy(Widget.Panels[i]);
Widget.removeWidget(Widget.Panels[i].Widget);
Widget.Panels[i].DetachEvents;
QLabel_destroy(QLabelH(Widget.Panels[i].Widget));
Widget.Panels[i].Widget := nil;
Widget.Panels[i].Free;
end;
Widget.setUpdatesEnabled(True);
SetLength(Widget.Panels, 0);
end;
end;
@ -468,17 +473,23 @@ begin
end else
if AStatusBar.Panels.Count > 0 then
begin
Widget.setUpdatesEnabled(False);
SetLength(Widget.Panels, AStatusBar.Panels.Count);
for i := 0 to AStatusBar.Panels.Count - 1 do
begin
Str := GetUtf8String(AStatusBar.Panels[i].Text);
Widget.Panels[i] := QLabel_create(@Str, Widget.Widget);
//QLabel_setTextInteractionFlags(Widget.Panels[i], QtNoTextInteraction);
QLabel_setAlignment(Widget.Panels[i],
Widget.Panels[i] := TQtStatusBarPanel.CreateFrom(AStatusBar,
QLabel_create(@Str, Widget.Widget));
Widget.Panels[i].HasPaint := AStatusBar.Panels[i].Style = psOwnerDraw;
Widget.Panels[i].ID := AStatusBar.Panels[i].ID;
QLabel_setText(QLabelH(Widget.Panels[i].Widget), @Str);
QLabel_setAlignment(QLabelH(Widget.Panels[i].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[i].Alignment]);
QWidget_setMinimumWidth(Widget.Panels[i], AStatusBar.Panels[i].Width);
Widget.addWidget(Widget.Panels[i], ord(i = AStatusBar.Panels.Count - 1));
QWidget_setMinimumWidth(Widget.Panels[i].Widget, AStatusBar.Panels[i].Width);
Widget.Panels[i].AttachEvents;
Widget.addWidget(Widget.Panels[i].Widget, ord(i = AStatusBar.Panels.Count - 1));
end;
Widget.setUpdatesEnabled(True);
end;
end;
@ -501,8 +512,12 @@ begin
end;
class procedure TQtWSStatusBar.DestroyHandle(const AWinControl: TWinControl);
var
QtStatusBar: TQtStatusBar;
begin
TQtStatusBar(AWinControl.Handle).Release;
QtStatusBar := TQtStatusBar(AWinControl.Handle);
ClearPanels(QtStatusBar);
QtStatusBar.Release;
end;
class procedure TQtWSStatusBar.PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer);
@ -525,9 +540,11 @@ begin
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := GetUtf8String(AStatusBar.Panels[PanelIndex].Text);
QLabel_setText(QtStatusBar.Panels[PanelIndex], @Str);
QLabel_setAlignment(QtStatusBar.Panels[PanelIndex],
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
QLabel_setAlignment(QLabelH(QtStatusBar.Panels[PanelIndex].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[PanelIndex].Alignment]);
QWidget_setMinimumWidth(QtStatusBar.Panels[PanelIndex].Widget,
AStatusBar.Panels[PanelIndex].Width);
end;
end;
end;
@ -548,7 +565,7 @@ begin
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := GetUtf8String(AStatusBar.Panels[PanelIndex].Text);
QLabel_setText(QtStatusBar.Panels[PanelIndex], @Str);
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
end;
end;
end;