Improves behavior of click event on buttons and implements TabOrder and TabStop on the Qt widgetset.

git-svn-id: trunk@10199 -
This commit is contained in:
sekelsenmat 2006-11-14 19:14:35 +00:00
parent cdfcfafb10
commit 4b16f5c25c
5 changed files with 123 additions and 16 deletions

View File

@ -31,7 +31,7 @@ uses
// Free Pascal // Free Pascal
Classes, SysUtils, Types, Classes, SysUtils, Types,
// LCL // LCL
LMessages, Forms, Controls, LCLType, LCLProc, ComCtrls, ExtCtrls, StdCtrls, Menus; LMessages, Buttons, Forms, Controls, LCLType, LCLProc, ComCtrls, ExtCtrls, StdCtrls, Menus;
type type
{ TQtWidget } { TQtWidget }
@ -75,6 +75,7 @@ type
function windowFlags: QtWindowFlags; function windowFlags: QtWindowFlags;
procedure setWidth(p1: Integer); procedure setWidth(p1: Integer);
procedure setHeight(p1: Integer); procedure setHeight(p1: Integer);
procedure setTabOrder(p1, p2: TQtWidget);
end; end;
{ TQtAbstractButton } { TQtAbstractButton }
@ -112,6 +113,7 @@ type
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override;
destructor Destroy; override; destructor Destroy; override;
procedure setTabOrders;
public public
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
procedure SlotWindowStateChange; cdecl; procedure SlotWindowStateChange; cdecl;
@ -370,6 +372,15 @@ type
implementation implementation
{ Helper functions }
function SortListByTabOrder(Item1: Pointer; Item2: Pointer): Integer;
begin
if TWinControl(Item1).TabOrder = TWinControl(Item2).TabOrder then Result := 0
else if TWinControl(Item1).TabOrder < TWinControl(Item2).TabOrder then Result := -1
else if TWinControl(Item1).TabOrder > TWinControl(Item2).TabOrder then Result := 1;
end;
{ TQtWidget } { TQtWidget }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -443,7 +454,7 @@ begin
// WriteLn(Integer(QEvent_type(Event))); // WriteLn(Integer(QEvent_type(Event)));
{.$endif} {.$endif}
QEvent_ignore(Event); QEvent_accept(Event);
case QEvent_type(Event) of case QEvent_type(Event) of
QEventShow: SlotShow(True); QEventShow: SlotShow(True);
@ -461,6 +472,8 @@ begin
QEventResize: SlotResize; QEventResize: SlotResize;
QEventPaint: SlotPaint(Event); QEventPaint: SlotPaint(Event);
QEventContextMenu: SlotContextMenu; QEventContextMenu: SlotContextMenu;
else
QEvent_ignore(Event);
end; end;
{ GtkWidgetSet.SetCallback(LM_WINDOWPOSCHANGED, AGTKObject, AComponent); { GtkWidgetSet.SetCallback(LM_WINDOWPOSCHANGED, AGTKObject, AComponent);
@ -640,13 +653,19 @@ begin
QEventMouseButtonPress: Msg.Msg := LM_PRESSED; QEventMouseButtonPress: Msg.Msg := LM_PRESSED;
QEventMouseButtonRelease: QEventMouseButtonRelease:
begin begin
Msg.Msg := LM_CLICKED; { Clicking on buttons operates differently, because QEventMouseButtonRelease
is sent if you click a control, drag the mouse out of it and release, but
buttons should not be clicked on this case. }
if not (LCLObject is TCustomButton) then
begin
Msg.Msg := LM_CLICKED;
try try
LCLObject.WindowProc(TLMessage(Msg)); LCLObject.WindowProc(TLMessage(Msg));
except except
Application.HandleException(nil); Application.HandleException(nil);
end; end;
end;
Msg.Msg := LM_RELEASED; Msg.Msg := LM_RELEASED;
end; end;
@ -879,6 +898,11 @@ begin
QWidget_setGeometry(Widget, @R); QWidget_setGeometry(Widget, @R);
end; end;
procedure TQtWidget.setTabOrder(p1, p2: TQtWidget);
begin
QWidget_setTabOrder(p1.Widget, p2.Widget);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtWidget.QtKeyToLCLKey Function: TQtWidget.QtKeyToLCLKey
Params: None Params: None
@ -1336,9 +1360,6 @@ begin
// Main menu bar // Main menu bar
MenuBar := TQtMenuBar.Create(Widget); MenuBar := TQtMenuBar.Create(Widget);
{ // Accepts keyboard and mouse events
QWidget_setFocusPolicy(Widget, QtStrongFocus);}
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -1357,6 +1378,59 @@ begin
inherited Destroy; inherited Destroy;
end; end;
{------------------------------------------------------------------------------
Function: TQtMainWindow.setTabOrders
Params: None
Returns: Nothing
Sets the tab order of all controls on a form.
------------------------------------------------------------------------------}
procedure TQtMainWindow.setTabOrders;
var
i: Integer;
Form: TForm;
List: TList;
begin
List := TList.Create;
Form := TForm(LCLObject);
{ Creates a list with childs of the form that are available to receive Tab focus }
for i := 0 to Form.ComponentCount - 1 do
begin
if Form.Components[i] is TWinControl then
if TWinControl(Form.Components[i]).TabStop then
List.Add(Form.Components[i]);
end;
List.Sort(SortListByTabOrder);
for i := 0 to List.Count - 2 do
begin
setTabOrder(TQtWidget(TWinControl(List.Items[i]).Handle),
TQtWidget(TWinControl(List.Items[i + 1]).Handle));
{$ifdef VerboseQt}
WriteLn('Setting Tab Order first: ', TWinControl(List.Items[i]).Name, ' second: ',
TWinControl(List.Items[i + 1]).Name);
{$endif}
end;
{ The last element points to the first }
if List.Count > 0 then
begin
setTabOrder(TQtWidget(TWinControl(List.Items[List.Count - 1]).Handle),
TQtWidget(TWinControl(List.Items[0]).Handle));
{$ifdef VerboseQt}
WriteLn('Setting Tab Order first: ', TWinControl(List.Items[List.Count - 1]).Name, ' second: ',
TWinControl(List.Items[0]).Name);
{$endif}
end;
List.Free;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtMainWindow.EventFilter Function: TQtMainWindow.EventFilter
Params: None Params: None

View File

@ -1535,7 +1535,10 @@ begin
TQtDeviceContext(DC).font.family(@FontFamily); TQtDeviceContext(DC).font.family(@FontFamily);
{ Defaults to a TrueType font } { Defaults to a TrueType font.
Note that the meaning of the FIXED_PITCH constant is the opposite of
the name implies, according to MSDN docs. Just a small inconsistency
on Windows API that we have to mimic. }
if TQtDeviceContext(DC).font.fixedPitch then if TQtDeviceContext(DC).font.fixedPitch then
TM.tmPitchAndFamily := TRUETYPE_FONTTYPE TM.tmPitchAndFamily := TRUETYPE_FONTTYPE
else TM.tmPitchAndFamily := FIXED_PITCH or TRUETYPE_FONTTYPE; else TM.tmPitchAndFamily := FIXED_PITCH or TRUETYPE_FONTTYPE;

View File

@ -107,6 +107,16 @@ begin
QObject_hook_hook_events(Hook, Method); QObject_hook_hook_events(Hook, Method);
// OnClick Event
QAbstractButton_clicked2_Event(Method) := QtPushButton.SlotClicked;
QAbstractButton_hook_hook_clicked2(QAbstractButton_hook_create(QtPushButton.Widget), Method);
// Focus
QWidget_setFocusPolicy(QtPushButton.Widget, QtStrongFocus);
// Returns the Handle // Returns the Handle
Result := THandle(QtPushButton); Result := THandle(QtPushButton);
@ -182,6 +192,16 @@ begin
QObject_hook_hook_events(Hook, Method); QObject_hook_hook_events(Hook, Method);
// OnClick Event
QAbstractButton_clicked2_Event(Method) := QtPushButton.SlotClicked;
QAbstractButton_hook_hook_clicked2(QAbstractButton_hook_create(QtPushButton.Widget), Method);
// Focus
QWidget_setFocusPolicy(QtPushButton.Widget, QtStrongFocus);
// Returns the Handle // Returns the Handle
Result := THandle(QtPushButton); Result := THandle(QtPushButton);

View File

@ -213,24 +213,32 @@ end;
Returns: Nothing Returns: Nothing
Shows or hides a wi/dget. Shows or hides a widget.
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class procedure TQtWSWinControl.ShowHide(const AWinControl: TWinControl); class procedure TQtWSWinControl.ShowHide(const AWinControl: TWinControl);
begin begin
{$ifdef VerboseQt}
WriteLn('Trace:> [TQtWSWinControl.ShowHide]');
{$endif}
if AWinControl = nil then exit; if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit; if not AWinControl.HandleAllocated then exit;
{ if the widget is a form, this is a place to set the Tab order }
if (AWinControl is TForm) and AWinControl.HandleObjectShouldBeVisible then
TQtMainWindow(AWinControl.Handle).SetTabOrders;
if AWinControl.HandleObjectShouldBeVisible then if AWinControl.HandleObjectShouldBeVisible then
QWidget_setVisible(TQtWidget(AWinControl.Handle).Widget, True) QWidget_setVisible(TQtWidget(AWinControl.Handle).Widget, True)
else QWidget_setVisible(TQtWidget(AWinControl.Handle).Widget, False); else QWidget_setVisible(TQtWidget(AWinControl.Handle).Widget, False);
{$ifdef VerboseQt} {$ifdef VerboseQt}
Write('TQtWSWinControl.ShowHide '); Write('Trace:< [TQtWSWinControl.ShowHide] ');
if AWinControl is TForm then Write('Is TForm, '); if AWinControl is TForm then Write('Is TForm, ');
if AWinControl.Visible then WriteLn('Visible: True') if AWinControl.HandleObjectShouldBeVisible then WriteLn('Visible: True')
else WriteLn('Visible: False'); else WriteLn('Visible: False');
{$endif} {$endif}
end; end;

View File

@ -886,7 +886,7 @@ var
begin begin
QtCheckBox := TQtCheckBox.Create(AWinControl, AParams); QtCheckBox := TQtCheckBox.Create(AWinControl, AParams);
// SetSlots(QtStaticText); // Focus
QWidget_setFocusPolicy(QtCheckBox.Widget, QtStrongFocus); QWidget_setFocusPolicy(QtCheckBox.Widget, QtStrongFocus);
@ -1004,6 +1004,8 @@ begin
QObject_hook_hook_events(Hook, Method);} QObject_hook_hook_events(Hook, Method);}
// Focus
QWidget_setFocusPolicy(QtRadioButton.Widget, QtStrongFocus); QWidget_setFocusPolicy(QtRadioButton.Widget, QtStrongFocus);
// Returns the Handle // Returns the Handle