Qt: now we keep track of fonts changing and respect ParentFont property.fixes issue #19695

git-svn-id: trunk@33309 -
This commit is contained in:
zeljko 2011-11-04 18:16:04 +00:00
parent 46b87ff94d
commit 15e82e2123
4 changed files with 111 additions and 7 deletions

View File

@ -830,6 +830,7 @@ function QtDefaultContext: TQtDeviceContext;
function QtScreenContext: TQtDeviceContext; function QtScreenContext: TQtDeviceContext;
procedure AssignQtFont(FromFont: QFontH; ToFont: QFontH); procedure AssignQtFont(FromFont: QFontH; ToFont: QFontH);
function IsFontEqual(AFont1, AFont2: TQtFont): Boolean;
implementation implementation
@ -941,6 +942,28 @@ begin
QFont_setStyleStrategy(ToFont, QFont_styleStrategy(FromFont)); QFont_setStyleStrategy(ToFont, QFont_styleStrategy(FromFont));
end; end;
function IsFontEqual(AFont1, AFont2: TQtFont): Boolean;
var
AInfo1, AInfo2: TQtFontInfo;
begin
Result := False;
if (AFont1 = nil) or (AFont2 = nil) then
exit;
if (AFont1.FHandle = nil) or (AFont2.FHandle = nil) then
exit;
AInfo1 := AFont1.FontInfo;
AInfo2 := AFont2.FontInfo;
if (AInfo1 = nil) or (AInfo2 = nil) then
exit;
Result := (AInfo1.Family = AInfo2.Family) and (AInfo1.Bold = AInfo2.Bold) and
(AInfo1.Italic = AInfo2.Italic) and (AInfo1.FixedPitch = AInfo2.FixedPitch) and
(AInfo1.Underline = AInfo2.Underline) and (AInfo1.Overline = AInfo2.OverLine) and
(AInfo1.PixelSize = AInfo2.PixelSize) and (AInfo1.PointSize = AInfo2.PointSize) and
(AInfo1.StrikeOut = AInfo2.StrikeOut) and (AInfo1.Weight = AInfo2.Weight) and
(AInfo1.RawMode = AInfo2.RawMode) and (AInfo1.Style = AInfo2.Style) and
(AInfo1.StyleHint = AInfo2.StyleHint);
end;
{ TQtFontInfo } { TQtFontInfo }
function TQtFontInfo.GetBold: Boolean; function TQtFontInfo.GetBold: Boolean;
@ -2939,12 +2962,8 @@ begin
SelFont := AFont; SelFont := AFont;
if (AFont.FHandle <> nil) and (Widget <> nil) then if (AFont.FHandle <> nil) and (Widget <> nil) then
begin begin
if not FOwnPainter then QFnt := QPainter_font(Widget);
begin AssignQtFont(AFont.FHandle, QFnt);
QFnt := QPainter_font(Widget);
AssignQtFont(AFont.FHandle, QFnt);
end else
QPainter_setFont(Widget, QFontH(AFont.FHandle));
vFont.Angle := AFont.Angle; vFont.Angle := AFont.Angle;
end; end;
end; end;

View File

@ -106,6 +106,8 @@ type
TQtWidget = class(TQtObject, IUnknown) TQtWidget = class(TQtObject, IUnknown)
private private
FWidgetState: TQtWidgetStates; FWidgetState: TQtWidgetStates;
FWidgetDefaultFont: TQtFont;
FWidgetLCLFont: TQtFont;
FWidgetNeedFontColorInitialization: Boolean; FWidgetNeedFontColorInitialization: Boolean;
FChildOfComplexWidget: TChildOfComplexWidget; FChildOfComplexWidget: TChildOfComplexWidget;
FOwnWidget: Boolean; FOwnWidget: Boolean;
@ -185,6 +187,7 @@ type
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
function getAcceptDropFiles: Boolean; virtual; function getAcceptDropFiles: Boolean; virtual;
procedure SetNoMousePropagation(Sender: QWidgetH; const ANoMousePropagation: Boolean); virtual; procedure SetNoMousePropagation(Sender: QWidgetH; const ANoMousePropagation: Boolean); virtual;
procedure SetLCLFont(AFont: TQtFont);
procedure SlotShow(vShow: Boolean); cdecl; procedure SlotShow(vShow: Boolean); cdecl;
function SlotClose: Boolean; cdecl; virtual; function SlotClose: Boolean; cdecl; virtual;
procedure SlotDestroy; cdecl; procedure SlotDestroy; cdecl;
@ -929,9 +932,11 @@ type
FParentShowPassed: PtrInt; FParentShowPassed: PtrInt;
{$endif} {$endif}
FEditingFinishedHook: QAbstractSpinBox_hookH; FEditingFinishedHook: QAbstractSpinBox_hookH;
FLineEditHook: QObject_hookH;
// parts // parts
FLineEdit: QLineEditH; FLineEdit: QLineEditH;
function GetLineEdit: QLineEditH; function GetLineEdit: QLineEditH;
function LineEditEventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
protected protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override; function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
// IQtEdit implementation // IQtEdit implementation
@ -1429,6 +1434,7 @@ type
public public
constructor Create(const AParent: QWidgetH); overload; constructor Create(const AParent: QWidgetH); overload;
public public
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
function addMenu(AMenu: QMenuH): QActionH; function addMenu(AMenu: QMenuH): QActionH;
function insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH; function insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH;
function getGeometry: TRect; override; function getGeometry: TRect; override;
@ -1768,6 +1774,8 @@ begin
FDefaultCursor := QCursor_create(); FDefaultCursor := QCursor_create();
QWidget_cursor(Widget, FDefaultCursor); QWidget_cursor(Widget, FDefaultCursor);
FWidgetLCLFont := nil;
FWidgetDefaultFont := TQtFont.Create(QWidget_font(AWidget));
// set Handle->QWidget map // set Handle->QWidget map
setProperty(Widget, 'lclwidget', Int64(PtrUInt(Self))); setProperty(Widget, 'lclwidget', Int64(PtrUInt(Self)));
@ -1799,6 +1807,10 @@ begin
// retrieve default cursor on create // retrieve default cursor on create
FDefaultCursor := QCursor_create(); FDefaultCursor := QCursor_create();
QWidget_cursor(Widget, FDefaultCursor); QWidget_cursor(Widget, FDefaultCursor);
FWidgetDefaultFont := TQtFont.Create(QWidget_font(Widget));
FWidgetLCLFont := nil;
// apply initial position and size // apply initial position and size
move(FParams.X, FParams.Y); move(FParams.X, FParams.Y);
@ -1863,6 +1875,11 @@ begin
if HasCaret then if HasCaret then
DestroyCaret; DestroyCaret;
if Assigned(FWidgetDefaultFont) then
FreeThenNil(FWidgetDefaultFont);
if Assigned(FWidgetLCLFont) then
FreeThenNil(FWidgetLCLFont);
if FPalette <> nil then if FPalette <> nil then
begin begin
FPalette.Free; FPalette.Free;
@ -2180,7 +2197,15 @@ begin
case QEvent_type(Event) of case QEvent_type(Event) of
QEventFontChange: QEventFontChange:
begin begin
//TODO: for issue #19695 //explanation for this event usage: issue #19695
if not (qtwsFontUpdating in WidgetState) and
not LCLObject.IsParentFont then
begin
if Assigned(FWidgetLCLFont) then
AssignQtFont(FWidgetLCLFont.FHandle, QWidget_font(QWidgetH(Sender)))
else
AssignQtFont(FWidgetDefaultFont.FHandle, QWidget_font(QWidgetH(Sender)));
end;
end; end;
QEventEnabledChange: QEventEnabledChange:
begin begin
@ -2345,6 +2370,25 @@ begin
QWidget_setAttribute(Sender, QtWA_NoMousePropagation, ANoMousePropagation); QWidget_setAttribute(Sender, QtWA_NoMousePropagation, ANoMousePropagation);
end; end;
{------------------------------------------------------------------------------
Function: TQtWidget.SetLCLFont
Params: None
Returns: Nothing
Sets FWidgetLCLFont , font which is different from FWidgetDefaultFont
so we can keep track over it inside QEventFontChange.
This routine does nothing if called outside of TQtWSControl.SetFont,
since qtwdFontUpdating must be in WidgetState
------------------------------------------------------------------------------}
procedure TQtWidget.SetLCLFont(AFont: TQtFont);
begin
if not (qtwsFontUpdating in FWidgetState) then
exit;
if Assigned(FWidgetLCLFont) then
FreeThenNil(FWidgetLCLFont);
if not IsFontEqual(FWidgetDefaultFont, AFont) and (AFont.FHandle <> nil) then
FWidgetLCLFont := TQtFont.Create(AFont.FHandle);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtWidget.SlotShow Function: TQtWidget.SlotShow
Params: None Params: None
@ -5141,6 +5185,7 @@ begin
// The main window takes care of the menubar handle // The main window takes care of the menubar handle
if MenuBar <> nil then if MenuBar <> nil then
begin begin
MenuBar.DetachEvents;
MenuBar.Widget := nil; MenuBar.Widget := nil;
MenuBar.Free; MenuBar.Free;
end; end;
@ -8431,6 +8476,8 @@ begin
if (FDropList <> nil) and (Sender = FDropList.Widget) then if (FDropList <> nil) and (Sender = FDropList.Widget) then
begin begin
if QEvent_type(Event) = QEventFontChange then
Result := inherited EventFilter(Sender, Event);
QEvent_ignore(Event); QEvent_ignore(Event);
exit; exit;
end; end;
@ -8602,9 +8649,23 @@ function TQtAbstractSpinBox.GetLineEdit: QLineEditH;
begin begin
if FLineEdit = nil then if FLineEdit = nil then
FLineEdit := QLCLAbstractSpinBox_lineEditHandle(QAbstractSpinBoxH(Widget)); FLineEdit := QLCLAbstractSpinBox_lineEditHandle(QAbstractSpinBoxH(Widget));
if Assigned(FLineEdit) and not Assigned(FLineEditHook) then
begin
FLineEditHook := QObject_hook_create(FLineEdit);
QObject_hook_hook_events(FLineEditHook, @LineEditEventFilter);
end;
Result := FLineEdit; Result := FLineEdit;
end; end;
function TQtAbstractSpinBox.LineEditEventFilter(Sender: QObjectH; Event: QEventH
): Boolean; cdecl;
begin
Result := False;
QEvent_accept(Event);
if QEvent_type(Event) = QEventFontChange then
Result := EventFilter(QWidgetH(Sender), Event);
end;
function TQtAbstractSpinBox.CreateWidget(const AParams: TCreateParams): QWidgetH; function TQtAbstractSpinBox.CreateWidget(const AParams: TCreateParams): QWidgetH;
var var
Parent: QWidgetH; Parent: QWidgetH;
@ -8613,6 +8674,7 @@ begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('TQtAbstractSpinBox.Create'); WriteLn('TQtAbstractSpinBox.Create');
{$endif} {$endif}
FLineEditHook := nil;
if AParams.WndParent <> 0 then if AParams.WndParent <> 0 then
Parent := TQtWidget(AParams.WndParent).GetContainerWidget Parent := TQtWidget(AParams.WndParent).GetContainerWidget
else else
@ -8792,6 +8854,12 @@ begin
QAbstractSpinBox_hook_destroy(FEditingFinishedHook); QAbstractSpinBox_hook_destroy(FEditingFinishedHook);
FEditingFinishedHook := nil; FEditingFinishedHook := nil;
end; end;
if FLineEditHook <> nil then
begin
QObject_hook_destroy(FLineEditHook);
FLineEditHook := nil;
end;
inherited DetachEvents; inherited DetachEvents;
end; end;
@ -8862,6 +8930,7 @@ begin
FParentShowPassed := 0; FParentShowPassed := 0;
{$endif} {$endif}
FValue := 0; FValue := 0;
FLineEditHook := nil;
if AParams.WndParent <> 0 then if AParams.WndParent <> 0 then
Parent := TQtWidget(AParams.WndParent).GetContainerWidget Parent := TQtWidget(AParams.WndParent).GetContainerWidget
else else
@ -8941,6 +9010,7 @@ begin
{$ifdef CPU64 and not WIN64} {$ifdef CPU64 and not WIN64}
FParentShowPassed := 0; FParentShowPassed := 0;
{$endif} {$endif}
FLineEditHook := nil;
if AParams.WndParent <> 0 then if AParams.WndParent <> 0 then
Parent := TQtWidget(AParams.WndParent).GetContainerWidget Parent := TQtWidget(AParams.WndParent).GetContainerWidget
else else
@ -11586,6 +11656,8 @@ begin
Widget := CreateWidget(FParams); Widget := CreateWidget(FParams);
setProperty(Widget, 'lclwidget', Int64(PtrUInt(Self))); setProperty(Widget, 'lclwidget', Int64(PtrUInt(Self)));
QtWidgetSet.AddHandle(Self); QtWidgetSet.AddHandle(Self);
FWidgetDefaultFont := TQtFont.Create(QWidget_font(Widget));
FWidgetLCLFont := nil;
end; end;
constructor TQtMenu.Create(const AMenuItem: TMenuItem); constructor TQtMenu.Create(const AMenuItem: TMenuItem);
@ -11989,6 +12061,8 @@ constructor TQtMenuBar.Create(const AParent: QWidgetH);
begin begin
Create; Create;
Widget := QMenuBar_create(AParent); Widget := QMenuBar_create(AParent);
FWidgetDefaultFont := TQtFont.Create(QWidget_font(Widget));
FWidgetLCLFont := nil;
FHeight := getHeight; FHeight := getHeight;
FVisible := False; FVisible := False;
FIsApplicationMainMenu := False; FIsApplicationMainMenu := False;
@ -11998,6 +12072,15 @@ begin
setVisible(FVisible); setVisible(FVisible);
end; end;
function TQtMenuBar.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
cdecl;
begin
Result := False;
QEvent_accept(Event);
if (QEvent_type(Event) = QEventFontChange) then
AssignQtFont(FWidgetDefaultFont.FHandle, QWidget_font(QWidgetH(Sender)));
end;
function TQtMenuBar.addMenu(AMenu: QMenuH): QActionH; function TQtMenuBar.addMenu(AMenu: QMenuH): QActionH;
begin begin
if not FVisible then if not FVisible then

View File

@ -578,6 +578,7 @@ begin
QtWidget.BeginUpdate; QtWidget.BeginUpdate;
QtWidget.WidgetState := QtWidget.WidgetState + [qtwsFontUpdating]; QtWidget.WidgetState := QtWidget.WidgetState + [qtwsFontUpdating];
try try
QtWidget.SetLCLFont(TQtFont(AFont.Reference.Handle));
QtWidget.setFont(TQtFont(AFont.Reference.Handle).FHandle); QtWidget.setFont(TQtFont(AFont.Reference.Handle).FHandle);
// tscrollbar, ttrackbar etc. // tscrollbar, ttrackbar etc.

View File

@ -197,6 +197,7 @@ begin
// Sets Various Events // Sets Various Events
QtMainWindow.AttachEvents; QtMainWindow.AttachEvents;
QtMainWindow.MenuBar.AttachEvents;
if (AForm.FormStyle in [fsMDIChild]) and if (AForm.FormStyle in [fsMDIChild]) and
(Application.MainForm.FormStyle = fsMdiForm) and (Application.MainForm.FormStyle = fsMdiForm) and