mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 15:00:26 +02:00
Fixed MessageBox and other modal dialogs on Qt.
git-svn-id: trunk@10186 -
This commit is contained in:
parent
ee60b9bdcc
commit
0e491cac43
@ -465,6 +465,13 @@ end;
|
||||
Params: DC, Str, Count, Rect, Flags
|
||||
Returns: If the string was drawn, or CalcRect run
|
||||
|
||||
if DT_CALCRECT is one of the Flags passed to this function, then:
|
||||
|
||||
* DrawText should not draw the text, but determine the size that would be required to write it.
|
||||
* If there are multiple lines of text, this function will keep Rect.Width fixed and
|
||||
expand Rect.Height to fit the text.
|
||||
* If there is one line of text, Rect is reduced or expanded to fit it.
|
||||
* The result will the height of the text.
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.DrawText(DC: HDC; Str: PChar; Count: Integer;
|
||||
var Rect: TRect; Flags: Cardinal): Integer;
|
||||
@ -484,22 +491,23 @@ begin
|
||||
|
||||
WideStr := UTF8Decode(Str);
|
||||
|
||||
if (Flags and DT_CALCRECT) = DT_CALCRECT then
|
||||
begin
|
||||
QtFontMetrics := TQtFontMetrics.Create(TQtDeviceContext(DC).font.Widget);
|
||||
try
|
||||
Result := QtFontMetrics.width(@WideStr);
|
||||
if Result < 30 then Result := 30;
|
||||
finally
|
||||
QtFontMetrics.Free;
|
||||
QtFontMetrics := TQtFontMetrics.Create(TQtDeviceContext(DC).font.Widget);
|
||||
try
|
||||
Result := QtFontMetrics.height;
|
||||
|
||||
if (Flags and DT_CALCRECT) = DT_CALCRECT then
|
||||
begin
|
||||
Rect.Right := Rect.Left + QtFontMetrics.width(@WideStr);
|
||||
Rect.Bottom := Rect.Top + QtFontMetrics.height;
|
||||
end;
|
||||
|
||||
Exit;
|
||||
|
||||
finally
|
||||
QtFontMetrics.Free;
|
||||
end;
|
||||
|
||||
TQtDeviceContext(DC).drawText(Rect.Left, Rect.Top, @WideStr);
|
||||
if (Flags and DT_CALCRECT) = DT_CALCRECT then Exit;
|
||||
|
||||
// if Rect.Right = 40 then raise Exception.create('Error');
|
||||
TQtDeviceContext(DC).drawText(Rect.Left, Rect.Top, @WideStr);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -231,7 +231,7 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSCustomForm.CloseModal(const ACustomForm: TCustomForm);
|
||||
begin
|
||||
inherited CloseModal(ACustomForm);
|
||||
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -269,33 +269,31 @@ end;
|
||||
Method: TQtWSCustomForm.ShowModal
|
||||
Params:
|
||||
Returns: Nothing
|
||||
|
||||
What we do here is put the entere window inside a QDialog component, because QDialog
|
||||
is the only Qt component with a exec method that won´t return until the dialog is closed,
|
||||
and that behavior makes implementing ShowModal much easier.
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
|
||||
var
|
||||
QtDialog: TQtDialog;
|
||||
begin
|
||||
{ QtDialog := TQtDialog.Create;
|
||||
try
|
||||
TQtWidget(ACustomForm.Handle).setParent(QtDialog.Widget);
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('Trace:> [TQtWSCustomForm.ShowModal]');
|
||||
{$endif}
|
||||
|
||||
QtDialog.exec;
|
||||
|
||||
if (ACustomForm.ModalResult = mrNone) then ACustomForm.ModalResult := mrCancel;
|
||||
|
||||
TQtWidget(ACustomForm.Handle).setParent(nil);
|
||||
finally
|
||||
QtDialog.Free;
|
||||
end}
|
||||
TQtWidget(ACustomForm.Handle).Hide;
|
||||
|
||||
TQtWidget(ACustomForm.Handle).setWindowModality(QtApplicationModal);
|
||||
|
||||
TQtWidget(ACustomForm.Handle).Hide;
|
||||
|
||||
TQtWidget(ACustomForm.Handle).Show;
|
||||
|
||||
{ This sleep is required, otherwise sometime the modal window will not show,
|
||||
effectively freezing the application }
|
||||
|
||||
Application.ProcessMessages;
|
||||
|
||||
Sleep(10);
|
||||
|
||||
Application.ProcessMessages;
|
||||
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('Trace:< [TQtWSCustomForm.ShowModal]');
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user