You've already forked lazarus-ccr
richmemo: + added Qt support for set/get text attributes.
+ added implementation for Qt search() method git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4139 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,13 +1,16 @@
|
|||||||
unit QtRichMemo;
|
unit QtRichMemo;
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
{$mode delphi}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Following class methods are need for the implementation
|
// Following class methods are need for the implementation
|
||||||
// QTextCharFormatH
|
// QTextCharFormatH
|
||||||
// QTextBlockFormatH
|
// QTextBlockFormatH
|
||||||
uses
|
uses
|
||||||
LCLType, Controls, StdCtrls,
|
LCLType, Controls, StdCtrls, Graphics,
|
||||||
qt4, qtwidgets, qtprivate,
|
qt4, qtobjects, qtwidgets, qtprivate,
|
||||||
WSProc,
|
WSProc,
|
||||||
RichMemo, WSRichMemo;
|
RichMemo, WSRichMemo;
|
||||||
|
|
||||||
@ -22,6 +25,12 @@ type
|
|||||||
var AAlign: TIntParaAlignment): Boolean; override;
|
var AAlign: TIntParaAlignment): Boolean; override;
|
||||||
class procedure SetParaAlignment(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
class procedure SetParaAlignment(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
const AAlign: TIntParaAlignment); override;
|
const AAlign: TIntParaAlignment); override;
|
||||||
|
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var Params: TIntFontParams): Boolean; override;
|
||||||
|
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const Params: TIntFontParams); override;
|
||||||
|
|
||||||
|
class function Search(const AWinControl: TWinControl; const ANiddle: string; const SearchOpts: TIntSearchOpt): Integer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -88,6 +97,131 @@ begin
|
|||||||
te.setSelection(ss, sl);
|
te.setSelection(ss, sl);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
const
|
||||||
|
QNormal = 50;
|
||||||
|
QBold = 75;
|
||||||
|
|
||||||
|
class function TQtWSCustomRichMemo.GetTextAttributes(
|
||||||
|
const AWinControl: TWinControl; TextStart: Integer; var Params: TIntFontParams
|
||||||
|
): Boolean;
|
||||||
|
var
|
||||||
|
w : QTextEditH;
|
||||||
|
te : TQtTextEdit;
|
||||||
|
ss, sl : Integer;
|
||||||
|
ws : WideString;
|
||||||
|
clr: TQColor;
|
||||||
|
begin
|
||||||
|
InitFontParams(Params);
|
||||||
|
if not WSCheckHandleAllocated(AWinControl, 'GetTextAttributes') then begin
|
||||||
|
Result:=false;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
te:=TQtTextEdit(AWinControl.Handle);
|
||||||
|
w:=QTextEditH(te.Widget);
|
||||||
|
|
||||||
|
ss:=te.getSelectionStart;
|
||||||
|
sl:=te.getSelectionLength;
|
||||||
|
|
||||||
|
te.setSelection(TextStart, 1);
|
||||||
|
|
||||||
|
//todo!
|
||||||
|
ws:='';
|
||||||
|
QTextEdit_fontFamily(w, @ws);
|
||||||
|
writeln(wS);
|
||||||
|
if ws<>'' then Params.Name:=ws;
|
||||||
|
|
||||||
|
Params.Size:=round(QTextEdit_fontPointSize(w));
|
||||||
|
if QTextEdit_fontWeight(w)>=QBold then Include(Params.Style, fsBold);
|
||||||
|
if QTextEdit_fontItalic(w) then Include(Params.Style, fsItalic);
|
||||||
|
if QTextEdit_fontUnderline(w) then Include(Params.Style, fsUnderline);
|
||||||
|
|
||||||
|
FillChar(clr, sizeof(clr), 0);
|
||||||
|
QTextEdit_textColor(w, @clr);
|
||||||
|
TQColorToColorRef(clr, TColorRef(params.Color));
|
||||||
|
|
||||||
|
FillChar(clr, sizeof(clr), 0);
|
||||||
|
QTextEdit_textBackgroundColor(w, @clr);
|
||||||
|
TQColorToColorRef(clr, TColorRef(params.BkColor));
|
||||||
|
//todo!
|
||||||
|
params.HasBkClr:=false;
|
||||||
|
|
||||||
|
te.setSelection(ss, sl);
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TQtWSCustomRichMemo.SetTextAttributes(
|
||||||
|
const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const Params: TIntFontParams);
|
||||||
|
var
|
||||||
|
w : QTextEditH;
|
||||||
|
te : TQtTextEdit;
|
||||||
|
ss, sl : Integer;
|
||||||
|
ws : WideString;
|
||||||
|
clr: TQColor;
|
||||||
|
const
|
||||||
|
QNormal = 50;
|
||||||
|
QBold = 75;
|
||||||
|
const
|
||||||
|
QIsBold: array [Boolean] of integer = (QNormal, QBold);
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(AWinControl, 'SetTextAttributes') then
|
||||||
|
Exit;
|
||||||
|
te:=TQtTextEdit(AWinControl.Handle);
|
||||||
|
w:=QTextEditH(te.Widget);
|
||||||
|
|
||||||
|
ss:=te.getSelectionStart;
|
||||||
|
sl:=te.getSelectionLength;
|
||||||
|
|
||||||
|
te.setSelection(TextStart, TextLen);
|
||||||
|
|
||||||
|
ws:=UTF8Decode(Params.Name);
|
||||||
|
if ws<>'' then QTextEdit_setFontFamily(w, @ws);
|
||||||
|
if Params.Size>0 then QTextEdit_setFontPointSize(w, Params.Size);
|
||||||
|
QTextEdit_setFontUnderline(w, fsUnderline in Params.Style);
|
||||||
|
QTextEdit_setFontWeight(w, QisBold[fsBold in Params.Style]);
|
||||||
|
QTextEdit_setFontItalic(w, fsItalic in Params.Style);
|
||||||
|
|
||||||
|
ColorRefToTQColor(Params.Color, clr);
|
||||||
|
QTextEdit_setTextColor(w, @clr);
|
||||||
|
|
||||||
|
//todo:
|
||||||
|
{
|
||||||
|
if not Params.HasBkClr then begin
|
||||||
|
ColorRefToTQColor(Params.BkColor, clr);
|
||||||
|
clr.Alpha:=0;
|
||||||
|
end else
|
||||||
|
ColorRefToTQColor(Params.BkColor, clr);
|
||||||
|
QTextEdit_setTextBackgroundColor(w, @clr);
|
||||||
|
}
|
||||||
|
|
||||||
|
te.setSelection(ss, sl);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TQtWSCustomRichMemo.Search(const AWinControl: TWinControl;
|
||||||
|
const ANiddle: string; const SearchOpts: TIntSearchOpt): Integer;
|
||||||
|
var
|
||||||
|
w : QTextEditH;
|
||||||
|
te : TQtTextEdit;
|
||||||
|
ws : Widestring;
|
||||||
|
fl : QTextDocumentFindFlags;
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(AWinControl, 'SetParaAlignment') then
|
||||||
|
Exit;
|
||||||
|
te:=TQtTextEdit(AWinControl.Handle);
|
||||||
|
w:=QTextEditH(te.Widget);
|
||||||
|
|
||||||
|
fl:=0;
|
||||||
|
if soMatchCase in SearchOpts.Options then fl:=fl or QTextDocumentFindCaseSensitively;
|
||||||
|
if soWholeWord in SearchOpts.Options then fl:=fl or QTextDocumentFindWholeWords;
|
||||||
|
if soBackward in SearchOpts.Options then fl:=fl or QTextDocumentFindBackward;
|
||||||
|
|
||||||
|
//todo: range filtering in Serach Opts
|
||||||
|
ws:=UTF8Decode(ANiddle);
|
||||||
|
if QTextEdit_find(w, @ws, fl) then Result:=te.getSelectionStart
|
||||||
|
else Result:=-1;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TQtWSCustomRichMemo.GetParaAlignment(
|
class function TQtWSCustomRichMemo.GetParaAlignment(
|
||||||
const AWinControl: TWinControl; TextStart: Integer;
|
const AWinControl: TWinControl; TextStart: Integer;
|
||||||
var AAlign: TIntParaAlignment): Boolean;
|
var AAlign: TIntParaAlignment): Boolean;
|
||||||
|
Reference in New Issue
Block a user