Recent

Author Topic: Accessing QT5 clipboard dataChanged event  (Read 995 times)

alanphys

  • New Member
  • *
  • Posts: 46
Accessing QT5 clipboard dataChanged event
« on: April 24, 2020, 10:09:13 am »
Hi

I am helping port an application to Lazarus. The application responds to changes in the clipboard and if the data is appropriately formatted graphs it. The functionality for windows has been implemented using examples from the wiki and posted elsewhere on the forum but I would like to implement it for QT5 as well.

The QT5 documentation for QClipboard shows the dataChanged event. If I look at QT5Pas.pas the dataChanged event seems to be defined:

Code: Pascal  [Select][+][-]
  1. type
  2.   QClipboard_changed_Event = procedure (mode: QClipboardMode) of object cdecl;
  3.   QClipboard_selectionChanged_Event = procedure () of object cdecl;
  4.   QClipboard_findBufferChanged_Event = procedure () of object cdecl;
  5.   QClipboard_dataChanged_Event = procedure () of object cdecl;
  6.  

But it doesn't seem to be included in the lcl (clipbrd.inc). Ideally what I want to do is something along the lines of:

Code: Pascal  [Select][+][-]
  1. unit clpbrdunit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Clipbrd;
  9.  
  10. type
  11.  
  12.    { TClpbrdForm }
  13.  
  14.    TClpbrdForm = class(TForm)
  15.       Memo: TMemo;
  16.       procedure FormCreate(Sender: TObject);
  17.       procedure ClipboardChanged;
  18.    private
  19.  
  20.    public
  21.  
  22.    end;
  23.  
  24. var
  25.    ClpbrdForm: TClpbrdForm;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TClpbrdForm }
  32.  
  33. procedure TClpbrdForm.FormCreate(Sender: TObject);
  34. begin
  35. Memo.PasteFromClipboard;
  36. Clipbrd.dataChanged := @ClipboardChanged;
  37. end;
  38.  
  39. procedure TClpbrdForm.ClipboardChanged;
  40. begin
  41. Memo.PasteFromClipboard;
  42. end;
  43.  
  44. end.
  45.  

If anyone has done this in QT5 or has some pointers I'd be grateful.

Regards
Alanphys
Fedora 32 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1149
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Accessing QT5 clipboard dataChanged event
« Reply #1 on: April 24, 2020, 01:44:49 pm »
You should never include widgetset specific code into LCL (eg clipbrd unit).
If you want to implement dataChanged() then it should be implemented in
lcl/interfaces/qt5/qtobjects.pas inside TQtClipboard class.
EDIT: Maybe LCL needs implementation WM_CLIPBOARDUPDATE or similar and TClipboard.OnDataChanged event to get it work on (almost) all widgetsets.
« Last Edit: April 24, 2020, 01:50:48 pm by zeljko »

alanphys

  • New Member
  • *
  • Posts: 46
Re: Accessing QT5 clipboard dataChanged event
« Reply #2 on: April 28, 2020, 09:13:04 am »
Thanks zeljko

If I look at qtobjects.pas it already appears to be implemented:

Code: Pascal  [Select][+][-]
  1. procedure TQtClipboard.signalDataChanged; cdecl;
  2. begin
  3.   {$IFDEF VERBOSE_QT_CLIPBOARD}
  4.   writeln('signalDataChanged()');
  5.   {$ENDIF}
  6.   FClipChanged := IsClipboardChanged;
  7. end;
  8.  

But if I look at /usr/lib64/lazarus/lcl/clipbrd.pp I don't see the equivalent function there. If I understand you and the Lazaurs documentation correctly I need to implement a general function here and specific functions in each of the other widget sets, or can I do for just the one widget set?

Regards
Alanphys
Fedora 32 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1149
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Accessing QT5 clipboard dataChanged event
« Reply #3 on: April 28, 2020, 09:16:38 am »
Thanks zeljko

If I look at qtobjects.pas it already appears to be implemented:

Code: Pascal  [Select][+][-]
  1. procedure TQtClipboard.signalDataChanged; cdecl;
  2. begin
  3.   {$IFDEF VERBOSE_QT_CLIPBOARD}
  4.   writeln('signalDataChanged()');
  5.   {$ENDIF}
  6.   FClipChanged := IsClipboardChanged;
  7. end;
  8.  

But if I look at /usr/lib64/lazarus/lcl/clipbrd.pp I don't see the equivalent function there. If I understand you and the Lazaurs documentation correctly I need to implement a general function here and specific functions in each of the other widget sets, or can I do for just the one widget set?

That's because LCL does not have implementation for such event. I've implemented that signal just for future use and stop event from Qt (see my comments about it):

    if QEvent_type(Event) = QEventClipboard then
    begin
      Result := FClipChanged;
      // Clipboard is changed, but we have no ability at moment to pass that info
      // to LCL since LCL has no support for that event
      // so we are using signalDataChanged() to pass changes to Clipbrd.Clipboard
      if FClipChanged then
        FClipChanged := False;
      QEvent_accept(Event);
    end;



 

TinyPortal © 2005-2018