Improvements for modal dialogs on qt.

git-svn-id: trunk@10162 -
This commit is contained in:
sekelsenmat 2006-11-02 19:56:33 +00:00
parent 062208ae24
commit 2448617cd6
5 changed files with 66 additions and 15 deletions

View File

@ -97,14 +97,30 @@ begin
QApplication_Exec;
end;
{------------------------------------------------------------------------------
Method: TQtWidgetSet.AppWaitMessage
Params: None
Returns: Nothing
Waits until a message arrives, processes that and returns control out of the function
Utilized on Modal dialogs
------------------------------------------------------------------------------}
procedure TQtWidgetSet.AppWaitMessage;
begin
QCoreApplication_processEvents(QEventLoopWaitForMoreEvents);
end;
{------------------------------------------------------------------------------
Method: TQtWidgetSet.AppWaitMessage
Params: None
Returns: Nothing
Processes all messages on the quoue
------------------------------------------------------------------------------}
procedure TQtWidgetSet.AppProcessMessages;
begin
QCoreApplication_processEvents();
end;
{------------------------------------------------------------------------------

View File

@ -31,7 +31,7 @@ uses
// Free Pascal
Classes, SysUtils, Types,
// LCL
Forms, Controls, LCLType, LCLProc, Menus;
Menus, LCLProc;
type
{ TQtAction }
@ -103,6 +103,7 @@ type
destructor Destroy; override;
public
function height: Integer;
function width(p1: PWideString): Integer;
end;
{ TQtBrush }
@ -129,7 +130,7 @@ type
vFont: TQtFont;
vImage: QImageH;
public
constructor Create(WidgetHandle: HWND); virtual;
constructor Create(WidgetHandle: THandle); virtual;
destructor Destroy; override;
public
procedure drawRect(x1: Integer; y1: Integer; w: Integer; h: Integer);
@ -217,7 +218,7 @@ begin
Handle := QImage_create(AData, width, height, format);
{$ifdef VerboseQt}
WriteLn('TQtImage.Create Result:', dbgs(Handle));
WriteLn('TQtImage.Create Result:', Integer(Handle));
{$endif}
end;
@ -398,6 +399,11 @@ begin
Result := QFontMetrics_height(Widget);
end;
function TQtFontMetrics.width(p1: PWideString): Integer;
begin
Result := QFontMetrics_width(Widget, p1);
end;
{ TQtBrush }
{------------------------------------------------------------------------------
@ -448,7 +454,7 @@ end;
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
constructor TQtDeviceContext.Create(WidgetHandle: HWND);
constructor TQtDeviceContext.Create(WidgetHandle: THandle);
begin
{$ifdef VerboseQt}
WriteLn('TQtDeviceContext.Create ( WidgetHandle: ' + IntToStr(WidgetHandle) + ' )');
@ -522,8 +528,7 @@ var
QtFontMetrics: TQtFontMetrics;
begin
{$ifdef VerboseQt}
WriteLn('TQtDeviceContext.drawText TargetX: ', dbgs(Origin.X + X),
' TargetY: ', dbgs(Origin.Y + Y));
WriteLn('TQtDeviceContext.drawText TargetX: ', (Origin.X + X), ' TargetY: ', (Origin.Y + Y));
{$endif}
QtFontMetrics := TQtFontMetrics.Create(Font.Widget);
@ -531,7 +536,7 @@ begin
QPainter_drawText(Widget, Origin.X + x, Origin.Y + y + QtFontMetrics.height, s);
{$ifdef VerboseQt}
WriteLn(' Font metrics height: ', dbgs(QtFontMetrics.height));
WriteLn(' Font metrics height: ', QtFontMetrics.height);
{$endif}
finally
QtFontMetrics.Free;

View File

@ -64,6 +64,7 @@ type
procedure Repaint;
procedure setWindowTitle(Str: PWideString);
procedure WindowTitle(Str: PWideString);
procedure Hide;
procedure Show;
procedure setEnabled(p1: Boolean);
procedure setVisible(visible: Boolean);
@ -773,6 +774,11 @@ begin
QWidget_WindowTitle(Widget, Str);
end;
procedure TQtWidget.Hide;
begin
QWidget_hide(Widget);
end;
procedure TQtWidget.Show;
begin
QWidget_show(Widget);

View File

@ -423,6 +423,7 @@ function TQtWidgetSet.DrawText(DC: HDC; Str: PChar; Count: Integer;
var Rect: TRect; Flags: Cardinal): Integer;
var
WideStr: WideString;
QtFontMetrics: TQtFontMetrics;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI DrawText] DC: ', dbgs(DC), ' Str: ', string(Str),
@ -434,13 +435,20 @@ begin
if not IsValidDC(DC) then Exit;
WideStr := UTF8Decode(Str);
if (Flags and DT_CALCRECT) = DT_CALCRECT then
begin
Result := 30;
Exit;
QtFontMetrics := TQtFontMetrics.Create(TQtDeviceContext(DC).font.Widget);
try
Result := QtFontMetrics.width(@WideStr);
if Result < 30 then Result := 30;
finally
QtFontMetrics.Free;
end;
WideStr := UTF8Decode(Str);
Exit;
end;
TQtDeviceContext(DC).drawText(Rect.Left, Rect.Top, @WideStr);
@ -1404,6 +1412,9 @@ end;
Returns: Nothing
------------------------------------------------------------------------------}
function TQtWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
var
QtFontMetrics: TQtFontMetrics;
WideStr: WideString;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetTextExtentPoint]');
@ -1413,7 +1424,14 @@ begin
if not IsValidDC(DC) then Exit;
// code here
QtFontMetrics := TQtFontMetrics.Create(TQtDeviceContext(DC).font.Widget);
try
WideStr := Utf8Decode(Str);
Size.cx := QtFontMetrics.width(@WideStr);
Size.cy := QtFontMetrics.height;
finally
QtFontMetrics.Free;
end;
Result := True;
end;

View File

@ -278,7 +278,7 @@ class procedure TQtWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
var
QtDialog: TQtDialog;
begin
QtDialog := TQtDialog.Create;
{ QtDialog := TQtDialog.Create;
try
TQtWidget(ACustomForm.Handle).setParent(QtDialog.Widget);
@ -289,7 +289,13 @@ begin
TQtWidget(ACustomForm.Handle).setParent(nil);
finally
QtDialog.Free;
end
end}
TQtWidget(ACustomForm.Handle).setWindowModality(QtApplicationModal);
TQtWidget(ACustomForm.Handle).Hide;
TQtWidget(ACustomForm.Handle).Show;
end;
{------------------------------------------------------------------------------