Qt5: let qt5 use lcTransparentWindow.

git-svn-id: trunk@54145 -
This commit is contained in:
zeljko 2017-02-13 08:48:57 +00:00
parent 33e6b24cc6
commit 80e4403f0b
2 changed files with 93 additions and 49 deletions

View File

@ -1208,6 +1208,7 @@ begin
{when issue #20475 is fixed, then set this to LCL_CAPABILITY_YES}
lcReceivesLMClearCutCopyPasteReliably: Result := LCL_CAPABILITY_NO;
lcRadialGradientBrush: Result := LCL_CAPABILITY_YES;
lcTransparentWindow: Result := LCL_CAPABILITY_YES;
else
Result := inherited GetLCLCapability(ACapability);
end;

View File

@ -3529,12 +3529,84 @@ var
MousePos: TQtPoint;
MButton: QTMouseButton;
Modifiers: QtKeyboardModifiers;
SaveWidget, AWidgetAt: QWidgetH;
SaveWidget: QWidgetH;
LazButton: Byte;
LazPos: TPoint;
AMouseEvent, ANewEvent: QMouseEventH;
APos, AGlobalPos: TQtPoint;
APosF, AGlobalPosF: TQtPointF;
function isTransparentForMouse: boolean;
begin
Result := testAttribute(QtWA_TransparentForMouseEvents) and
(Self is TQtMainWindow) and not TQtMainWindow(Self).IsMdiChild;
end;
function HandleTransparentForMouse: boolean;
var
AWidgetAt: QWidgetH;
AMouseEvent, ANewEvent: QMouseEventH;
AWnd: HWND;
AContextEvent: QContextMenuEventH;
AMousePos, APos: TQtPoint;
AEventOk: boolean;
begin
Result := False;
{issue #30232}
if isTransparentForMouse then
begin
Result := True;
AMouseEvent := QMouseEventH(Event);
QMouseEvent_globalPos(AMouseEvent, @AMousePos);
AWidgetAt := QApplication_widgetAt(@AMousePos);
{TODO: check what happens if pure form is transparent for mouse events.}
if AWidgetAt = nil then
AWidgetAt := QApplication_activeModalWidget;
if AWidgetAt = nil then
AWidgetAt := QApplication_activeWindow;
QMouseEvent_pos(AMouseEvent, @APos);
if AWidgetAt <> nil then
QWidget_mapFromGlobal(AWidgetAt, @APos, @AMousePos);
ANewEvent := QMouseEvent_create(QEvent_type(Event), @APos,
@AMousePos, QMouseEvent_button(AMouseEvent),
QMouseEvent_buttons(AMouseEvent), QInputEvent_modifiers(QInputEventH(Event)));
QEvent_accept(Event);
AEventOk := QCoreApplication_sendEvent(AWidgetAt, ANewEvent);
QEvent_destroy(ANewEvent);
if AEventOk and Assigned(AWidgetAt) then
begin
AWnd := HwndFromWidgetH(AWidgetAt);
if (AWnd <> 0) and (TQtWidget(AWnd) is TQtAbstractScrollArea) then
AWidgetAt := TQtAbstractScrollArea(AWnd).viewportWidget;
if (QWidget_focusPolicy(AWidgetAt) > QtNoFocus) and QWidget_isVisible(AWidgetAt) and
QWidget_isEnabled(AWidgetAt) then
QWidget_setFocus(AWidgetAt, QtMouseFocusReason);
if (AWnd <> 0) and Assigned(TQtWidget(AWnd).LCLObject) then
begin
if (QEvent_type(Event) <> QEventMouseButtonRelease) and
(QMouseEvent_button(QMouseEventH(Event)) = QtRightButton) then
begin
AContextEvent := QContextMenuEvent_create(QContextMenuEventMouse, @APos, @AMousePos,
QInputEvent_modifiers(QInputEventH(Event)));
QCoreApplication_sendEvent(AWidgetAt, AContextEvent);
QEvent_destroy(AContextEvent);
end;
if ((Sender <> nil) and not QWidget_isVisible(QWidgetH(Sender))) or (Sender = nil) then
begin
ANewEvent := QMouseEvent_create(QEventMouseButtonRelease, @APos,
@AMousePos, QMouseEvent_button(AMouseEvent),
QMouseEvent_buttons(AMouseEvent), QInputEvent_modifiers(QInputEventH(Event)));
QEvent_accept(Event);
QCoreApplication_sendEvent(AWidgetAt, ANewEvent);
QEvent_destroy(ANewEvent);
end;
end;
end;
exit;
end;
end;
begin
{$ifdef VerboseQt}
WriteLn('TQtWidget.SlotMouse');
@ -3549,47 +3621,6 @@ begin
(not (csDesigning in LCLObject.ComponentState) and not getEnabled) then
Exit;
{issue #30232}
if testAttribute(QtWA_TransparentForMouseEvents) and
(Self is TQtMainWindow) and not TQtMainWindow(Self).IsMdiChild then
begin
AMouseEvent := QMouseEventH(Event);
QMouseEvent_globalPos(AMouseEvent, @MousePos);
AWidgetAt := QApplication_widgetAt(@MousePos);
if AWidgetAt = nil then
AWidgetAt := QApplication_activeModalWidget;
if AWidgetAt = nil then
AWidgetAt := QApplication_activeWindow;
QMouseEvent_pos(AMouseEvent, @APos);
QMouseEvent_globalPos(AMouseEvent, @AGlobalPos);
if AWidgetAt <> nil then
QWidget_mapFromGlobal(AWidgetAt, @APos, @AGlobalPos);
APosF.x := APos.x;
APosF.y := APos.y;
AGlobalPosF.x := AGlobalPos.x;
AGlobalPosF.y := AGlobalPos.y;
ANewEvent := QMouseEvent_create(QEvent_type(Event), @APosF,
@AGlobalPosF, QMouseEvent_button(AMouseEvent),
QMouseEvent_buttons(AMouseEvent), QInputEvent_modifiers(QInputEventH(Event)));
QEvent_accept(Event);
Result := True;
{TODO: check what happens if pure form is transparent for mouse events.}
QCoreApplication_sendEvent(AWidgetAt, ANewEvent);
QEvent_destroy(ANewEvent);
{if our transparent widget is hidden during mouse down, send mouse up to current
widget}
if not QWidget_isVisible(QWidgetH(Sender)) and (QEvent_type(Event)=QEventMouseButtonPress) then
begin
ANewEvent := QMouseEvent_create(QEventMouseButtonRelease, @APosF,
@AGlobalPosF, QMouseEvent_button(AMouseEvent),
QMouseEvent_buttons(AMouseEvent), QInputEvent_modifiers(QInputEventH(Event)));
QCoreApplication_sendEvent(AWidgetAt, ANewEvent);
QEvent_destroy(ANewEvent);
end;
exit;
end;
// idea of multi click implementation is taken from gtk
FillChar(Msg{%H-}, SizeOf(Msg), #0);
@ -3658,8 +3689,14 @@ begin
// Check if our objects exists since LCL can destroy object during
// mouse events...
if CanSendLCLMessage and (Sender <> nil) then
SetNoMousePropagation(QWidgetH(Sender), True)
else
begin
if isTransparentForMouse then
begin
HandleTransparentForMouse;
SetNoMousePropagation(QWidgetH(Sender), False);
end else
SetNoMousePropagation(QWidgetH(Sender), True);
end else
exit(True);
end;
QEventMouseButtonRelease:
@ -3683,8 +3720,14 @@ begin
// Check if our objects exists since LCL can destroy object during
// mouse events...
if CanSendLCLMessage and (Sender <> nil) then
SetNoMousePropagation(QWidgetH(Sender), True)
else
begin
if isTransparentForMouse then
begin
HandleTransparentForMouse;
SetNoMousePropagation(QWidgetH(Sender), False);
end else
SetNoMousePropagation(QWidgetH(Sender), True);
end else
exit(True);
{ Clicking on buttons operates differently, because QEventMouseButtonRelease