1{ $Id: qtwsextctrls.pp 58122 2018-06-04 12:17:30Z zeljko $} 2{ 3 ***************************************************************************** 4 * QtWSExtCtrls.pp * 5 * --------------- * 6 * * 7 * * 8 ***************************************************************************** 9 10 ***************************************************************************** 11 This file is part of the Lazarus Component Library (LCL) 12 13 See the file COPYING.modifiedLGPL.txt, included in this distribution, 14 for details about the license. 15 ***************************************************************************** 16} 17unit QtWSExtCtrls; 18 19{$mode objfpc}{$H+} 20 21interface 22 23{$I qtdefines.inc} 24 25uses 26 // Bindings 27 qt4, 28 qtwidgets, qtobjects, qtproc, QtWSControls, 29 // LCL 30 SysUtils, Classes, Controls, Graphics, Forms, ExtCtrls, LCLType, LazUTF8, 31 // Widgetset 32 WSExtCtrls, WSLCLClasses; 33 34type 35 { TQtWSPage } 36 37 TQtWSPage = class(TWSPage) 38 published 39 end; 40 41 { TQtWSNotebook } 42 43 TQtWSNotebook = class(TWSNotebook) 44 published 45 end; 46 47 { TQtWSShape } 48 49 TQtWSShape = class(TWSShape) 50 published 51 end; 52 53 { TQtWSCustomSplitter } 54 55 TQtWSCustomSplitter = class(TWSCustomSplitter) 56 published 57 end; 58 59 { TQtWSSplitter } 60 61 TQtWSSplitter = class(TWSSplitter) 62 published 63 end; 64 65 { TQtWSPaintBox } 66 67 TQtWSPaintBox = class(TWSPaintBox) 68 published 69 end; 70 71 { TQtWSCustomImage } 72 73 TQtWSCustomImage = class(TWSCustomImage) 74 published 75 end; 76 77 { TQtWSImage } 78 79 TQtWSImage = class(TWSImage) 80 published 81 end; 82 83 { TQtWSBevel } 84 85 TQtWSBevel = class(TWSBevel) 86 published 87 end; 88 89 { TQtWSCustomRadioGroup } 90 91 TQtWSCustomRadioGroup = class(TWSCustomRadioGroup) 92 published 93 class function CreateHandle(const AWinControl: TWinControl; 94 const AParams: TCreateParams): TLCLIntfHandle; override; 95 end; 96 97 { TQtWSRadioGroup } 98 99 TQtWSRadioGroup = class(TWSRadioGroup) 100 published 101 end; 102 103 { TQtWSCustomCheckGroup } 104 105 TQtWSCustomCheckGroup = class(TWSCustomCheckGroup) 106 published 107 class function CreateHandle(const AWinControl: TWinControl; 108 const AParams: TCreateParams): TLCLIntfHandle; override; 109 end; 110 111 { TQtWSCheckGroup } 112 113 TQtWSCheckGroup = class(TWSCheckGroup) 114 published 115 end; 116 117 { TQtWSCustomLabeledEdit } 118 119 TQtWSCustomLabeledEdit = class(TWSCustomLabeledEdit) 120 published 121 end; 122 123 { TQtWSLabeledEdit } 124 125 TQtWSLabeledEdit = class(TWSLabeledEdit) 126 published 127 end; 128 129 { TQtWSCustomPanel } 130 131 TQtWSCustomPanel = class(TWSCustomPanel) 132 published 133 class function CreateHandle(const AWinControl: TWinControl; 134 const AParams: TCreateParams): TLCLIntfHandle; override; 135 class function GetDefaultColor(const AControl: TControl; const ADefaultColorType: TDefaultColorType): TColor; override; 136 end; 137 138 { TQtWSPanel } 139 140 TQtWSPanel = class(TWSPanel) 141 published 142 end; 143 144 { TQtWSCustomTrayIcon } 145 146 TQtWSCustomTrayIcon = class(TWSCustomTrayIcon) 147 published 148 class function Hide(const ATrayIcon: TCustomTrayIcon): Boolean; override; 149 class function Show(const ATrayIcon: TCustomTrayIcon): Boolean; override; 150 class procedure InternalUpdate(const ATrayIcon: TCustomTrayIcon); override; 151 class function ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean; override; 152 class function GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; override; 153 class function GetCanvas(const ATrayIcon: TCustomTrayIcon): TCanvas; override; 154 end; 155 156implementation 157uses qtsystemtrayicon; 158 159{ TQtWSCustomPanel } 160 161{------------------------------------------------------------------------------ 162 Method: TQtWSCustomPanel.CreateHandle 163 Params: None 164 Returns: Nothing 165 166 Allocates memory and resources for the control and shows it 167 ------------------------------------------------------------------------------} 168class function TQtWSCustomPanel.CreateHandle(const AWinControl: TWinControl; 169 const AParams: TCreateParams): TLCLIntfHandle; 170var 171 QtFrame: TQtFrame; 172begin 173 QtFrame := TQtFrame.Create(AWinControl, AParams); 174 QtFrame.AttachEvents; 175 176 // Set's initial properties 177 QtFrame.setFrameShape(TBorderStyleToQtFrameShapeMap[TCustomPanel(AWinControl).BorderStyle]); 178 179 // Return the Handle 180 Result := TLCLIntfHandle(QtFrame); 181end; 182 183class function TQtWSCustomPanel.GetDefaultColor(const AControl: TControl; 184 const ADefaultColorType: TDefaultColorType): TColor; 185const 186 DefColors: array[TDefaultColorType] of TColor = ( 187 { dctBrush } clBackground, 188 { dctFont } clBtnText 189 ); 190begin 191 Result := DefColors[ADefaultColorType]; 192end; 193 194{ TQtWSCustomRadioGroup } 195 196{------------------------------------------------------------------------------ 197 Method: TQtWSCustomRadioGroup.CreateHandle 198 Params: None 199 Returns: Nothing 200 201 Allocates memory and resources for the control and shows it 202 ------------------------------------------------------------------------------} 203 204class function TQtWSCustomRadioGroup.CreateHandle(const AWinControl: TWinControl; 205 const AParams: TCreateParams): TLCLIntfHandle; 206var 207 QtGroupBox: TQtGroupBox; 208 Str: WideString; 209begin 210 QtGroupBox := TQtGroupBox.Create(AWinControl, AParams); 211 QtGroupBox.GroupBoxType := tgbtRadioGroup; 212 213 Str := AWinControl{%H-}.Caption; 214 QGroupBox_setTitle(QGroupBoxH(QtGroupBox.Widget), @Str); 215 216 QtGroupBox.AttachEvents; 217 218 Result := TLCLIntfHandle(QtGroupBox); 219end; 220 221{ TQtWSCustomCheckGroup } 222 223{------------------------------------------------------------------------------ 224 Method: TQtWSCustomCheckGroup.CreateHandle 225 Params: None 226 Returns: Nothing 227 228 Allocates memory and resources for the control and shows it 229 ------------------------------------------------------------------------------} 230class function TQtWSCustomCheckGroup.CreateHandle(const AWinControl: TWinControl; 231 const AParams: TCreateParams): TLCLIntfHandle; 232var 233 QtGroupBox: TQtGroupBox; 234 Str: WideString; 235begin 236 QtGroupBox := TQtGroupBox.Create(AWinControl, AParams); 237 QtGroupBox.GroupBoxType := tgbtCheckGroup; 238 239 Str := AWinControl{%H-}.Caption; 240 QGroupBox_setTitle(QGroupBoxH(QtGroupBox.Widget), @Str); 241 242 QtGroupBox.AttachEvents; 243 244 Result := TLCLIntfHandle(QtGroupBox); 245end; 246 247{ TQtWSCustomTrayIcon } 248 249class function TQtWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean; 250var 251 SystemTrayIcon: TQtSystemTrayIcon; 252begin 253 Result := False; 254 255 SystemTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle); 256 257 SystemTrayIcon.Hide; 258 259 SystemTrayIcon.Free; 260 261 ATrayIcon.Handle := 0; 262 263 Result := True; 264end; 265 266class function TQtWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean; 267var 268 Text: WideString; 269 SystemTrayIcon: TQtSystemTrayIcon; 270 IconH: QIconH; 271begin 272 Result := False; 273 274 if ATrayIcon.Icon.Handle = 0 then 275 IconH := nil 276 else 277 IconH := TQtIcon(ATrayIcon.Icon.Handle).Handle; 278 279 SystemTrayIcon := TQtSystemTrayIcon.Create(IconH); 280 SystemTrayIcon.FTrayIcon := ATrayIcon; 281 282 ATrayIcon.Handle := HWND(SystemTrayIcon); 283 284 Text := ATrayIcon{%H-}.Hint; 285 SystemTrayIcon.setToolTip(Text); 286 287 if Assigned(ATrayIcon.PopUpMenu) then 288 if TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget <> nil then 289 SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget)); 290 291 SystemTrayIcon.show; 292 293 Result := True; 294end; 295 296{******************************************************************* 297* TQtWSCustomTrayIcon.InternalUpdate () 298* 299* DESCRIPTION: Makes modifications to the Icon while running 300* i.e. without hiding it and showing again 301*******************************************************************} 302class procedure TQtWSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon); 303var 304 SystemTrayIcon: TQtSystemTrayIcon; 305 AIcon: QIconH; 306 AHint: WideString; 307begin 308 if (ATrayIcon.Handle = 0) then Exit; 309 310 SystemTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle); 311 if Assigned(ATrayIcon.Icon) then 312 begin 313 // animate 314 if ATrayIcon.Animate and Assigned(ATrayIcon.Icons) then 315 SystemTrayIcon.setIcon(TQtImage(ATrayIcon.Icon.BitmapHandle).AsIcon) 316 else 317 // normal 318 if (ATrayIcon.Icon.Handle <> 0) then 319 SystemTrayIcon.setIcon(TQtIcon(ATrayIcon.Icon.Handle).Handle) 320 else 321 begin 322 AIcon := QIcon_create(); 323 SystemTrayIcon.setIcon(AIcon); 324 QIcon_destroy(AIcon); 325 end; 326 end else 327 begin 328 AIcon := QIcon_create; 329 SystemTrayIcon.setIcon(AIcon); 330 QIcon_destroy(AIcon); 331 end; 332 333 { PopUpMenu } 334 if Assigned(ATrayIcon.PopUpMenu) then 335 if TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget <> nil then 336 SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget)); 337 338 AHint := ATrayIcon{%H-}.Hint; 339 SystemTrayIcon.setToolTip(AHint); 340 341 SystemTrayIcon.UpdateSystemTrayWidget; 342end; 343 344class function TQtWSCustomTrayIcon.ShowBalloonHint( 345 const ATrayIcon: TCustomTrayIcon): Boolean; 346var 347 QtTrayIcon: TQtSystemTrayIcon; 348begin 349 Result := False; 350 if (ATrayIcon.Handle = 0) then Exit; 351 QtTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle); 352 353 QtTrayIcon.showBaloonHint(ATrayIcon.BalloonTitle, ATrayIcon.BalloonHint, 354 QSystemTrayIconMessageIcon(Ord(ATrayIcon.BalloonFlags)), 355 ATrayIcon.BalloonTimeout); 356 357 Result := True; 358end; 359 360class function TQtWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; 361begin 362 Result := Point(0, 0); 363 if (ATrayIcon.Handle = 0) then 364 exit; 365 Result := TQtSystemTrayIcon(ATrayIcon.Handle).GetPosition; 366end; 367 368class function TQtWSCustomTrayIcon.GetCanvas(const ATrayIcon: TCustomTrayIcon 369 ): TCanvas; 370begin 371 Result := nil; 372 if (ATrayIcon.Handle <> 0) then 373 Result := TQtSystemTrayIcon(ATrayIcon.Handle).Canvas; 374end; 375 376end. 377