mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 06:22:30 +02:00
trayicon: added tootip and popup menu support for qt from Felipe
git-svn-id: trunk@10623 -
This commit is contained in:
parent
78205ce402
commit
05919925eb
@ -28,7 +28,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Graphics, ExtCtrls, Menus, Controls, Lclintf,
|
Classes, SysUtils, Graphics, ExtCtrls, Menus, Controls, Lclintf,
|
||||||
wscommontrayicon, qt4;
|
wscommontrayicon, qt4, qtobjects, qtwidgets;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -37,14 +37,12 @@ type
|
|||||||
TWidgetTrayIcon = class(TCustomWidgetTrayIcon)
|
TWidgetTrayIcon = class(TCustomWidgetTrayIcon)
|
||||||
private
|
private
|
||||||
IconHandle: QIconH;
|
IconHandle: QIconH;
|
||||||
handle: QSystemTrayIconH;
|
SystemTrayIcon: TQtSystemTrayIcon;
|
||||||
function CreateIcon: QIconH;
|
function CreateIcon: QIconH;
|
||||||
function GetCanvas: TCanvas;
|
function GetCanvas: TCanvas;
|
||||||
protected
|
protected
|
||||||
public
|
public
|
||||||
hIcon, hSmallIcon: Cardinal;
|
hIcon, hSmallIcon: Cardinal;
|
||||||
ShowToolTip: Boolean;
|
|
||||||
ToolTip: string;
|
|
||||||
function Hide: Boolean; override;
|
function Hide: Boolean; override;
|
||||||
function Show: Boolean; override;
|
function Show: Boolean; override;
|
||||||
property Canvas: TCanvas read GetCanvas;
|
property Canvas: TCanvas read GetCanvas;
|
||||||
@ -55,7 +53,7 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses WSTrayIcon, qtobjects, qtwidgets;
|
uses WSTrayIcon;
|
||||||
|
|
||||||
{ TWidgetTrayIcon }
|
{ TWidgetTrayIcon }
|
||||||
|
|
||||||
@ -73,13 +71,13 @@ function TWidgetTrayIcon.CreateIcon: QIconH;
|
|||||||
var
|
var
|
||||||
Pixmap: QPixmapH;
|
Pixmap: QPixmapH;
|
||||||
begin
|
begin
|
||||||
if Self.Icon.Handle <> 0 then
|
{ if Self.Icon.Handle <> 0 then
|
||||||
begin
|
begin
|
||||||
TQtPixmap.fromImage(Pixmap, TQtImage(Self.Icon.Handle).Handle);
|
QPixmap_fromImage(Pixmap, TQtImage(Self.Icon.Handle).Handle);
|
||||||
|
|
||||||
Result := QIcon_create(Pixmap);
|
Result := QIcon_create(Pixmap);
|
||||||
end
|
end
|
||||||
else
|
else }
|
||||||
Result := QIcon_create();
|
Result := QIcon_create();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -114,11 +112,14 @@ begin
|
|||||||
|
|
||||||
if not vVisible then Exit;
|
if not vVisible then Exit;
|
||||||
|
|
||||||
QSystemTrayIcon_hide(Handle);
|
SystemTrayIcon.hide;
|
||||||
QSystemTrayIcon_destroy(Handle);
|
|
||||||
|
SystemTrayIcon.Free;
|
||||||
|
|
||||||
QIcon_destroy(IconHandle);
|
QIcon_destroy(IconHandle);
|
||||||
|
|
||||||
|
vVisible := False;
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -133,6 +134,8 @@ end;
|
|||||||
*
|
*
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
function TWidgetTrayIcon.Show: Boolean;
|
function TWidgetTrayIcon.Show: Boolean;
|
||||||
|
var
|
||||||
|
Text: WideString;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
@ -140,13 +143,18 @@ begin
|
|||||||
|
|
||||||
IconHandle := CreateIcon;
|
IconHandle := CreateIcon;
|
||||||
|
|
||||||
Handle := QSystemTrayIcon_create(IconHandle, nil);
|
SystemTrayIcon := TQtSystemTrayIcon.create(IconHandle);
|
||||||
|
|
||||||
{ if Assigned(PopUpMenu) then
|
Text := UTF8Decode(Hint);
|
||||||
|
SystemTrayIcon.setToolTip(Text);
|
||||||
|
|
||||||
|
if Assigned(PopUpMenu) then
|
||||||
if TQtMenu(PopUpMenu.Handle).Widget <> nil then
|
if TQtMenu(PopUpMenu.Handle).Widget <> nil then
|
||||||
QSystemTrayIcon_setContextMenu(Handle, QMenuH(TQtMenu(PopUpMenu.Handle).Widget));}
|
SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(PopUpMenu.Handle).Widget));
|
||||||
|
|
||||||
QSystemTrayIcon_show(Handle);
|
SystemTrayIcon.show;
|
||||||
|
|
||||||
|
vVisible := True;
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
@ -164,7 +172,10 @@ end;
|
|||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
procedure TWidgetTrayIcon.InternalUpdate;
|
procedure TWidgetTrayIcon.InternalUpdate;
|
||||||
begin
|
begin
|
||||||
|
{ PopUpMenu }
|
||||||
|
if Assigned(PopUpMenu) then
|
||||||
|
if TQtMenu(PopUpMenu.Handle).Widget <> nil then
|
||||||
|
SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(PopUpMenu.Handle).Widget));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*******************************************************************
|
{*******************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user