mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-20 12:19:31 +02:00
Qt:
- rework FileDialogs - now they understand more options and handle events (disadvantage - FileDialogs are no more native) - fix ColorDialog (was wrong selected color) - introduce TQtStringList which encapsulates QStringListH - fix compilation of qt 4.2 git-svn-id: trunk@12083 -
This commit is contained in:
parent
ec721b475a
commit
feb1dfe899
@ -70,6 +70,7 @@ type
|
||||
FTitle : string;
|
||||
FUserChoice: integer;
|
||||
FHelpContext: THelpContext;
|
||||
FCanCloseCalled: Boolean;
|
||||
procedure SetHandle(const AValue: THandle);
|
||||
procedure SetHeight(const AValue: integer);
|
||||
procedure SetWidth(const AValue: integer);
|
||||
@ -83,6 +84,7 @@ type
|
||||
property UserChoice: integer read FUserChoice write FUserChoice;
|
||||
procedure Close; virtual;
|
||||
procedure DoShow; virtual;
|
||||
procedure DoCanClose(var CanClose: Boolean); virtual;
|
||||
procedure DoClose; virtual;
|
||||
function HandleAllocated: boolean;
|
||||
published
|
||||
|
@ -49,6 +49,13 @@ begin
|
||||
if Assigned(FOnShow) then FOnShow(Self);
|
||||
end;
|
||||
|
||||
procedure TCommonDialog.DoCanClose(var CanClose: Boolean);
|
||||
begin
|
||||
FCanCloseCalled := True;
|
||||
if Assigned(FOnCanClose) then
|
||||
OnCanClose(Self, CanClose);
|
||||
end;
|
||||
|
||||
procedure TCommonDialog.DoClose;
|
||||
begin
|
||||
if Assigned(FOnClose) then FOnClose(Self);
|
||||
@ -79,20 +86,27 @@ end;
|
||||
function TCommonDialog.DoExecute : boolean;
|
||||
var CanClose: boolean;
|
||||
begin
|
||||
if Assigned(FOnShow) then FOnShow(Self);
|
||||
FCanCloseCalled := False;
|
||||
if Assigned(FOnShow) then
|
||||
FOnShow(Self);
|
||||
TWSCommonDialogClass(WidgetSetClass).ShowModal(Self);
|
||||
repeat
|
||||
if (FUserChoice <> mrNone) and (Handle<>0)
|
||||
and (OnCanClose<>nil) then begin
|
||||
CanClose:=true;
|
||||
OnCanClose(Self,CanClose);
|
||||
if not CanClose then FUserChoice:=mrNone;
|
||||
end;
|
||||
if FUserChoice <> mrNone then
|
||||
break;
|
||||
{ win32 widgetset dialogs use their own message loop,
|
||||
so only FUserChoice may have been set already }
|
||||
Application.HandleMessage;
|
||||
until false;
|
||||
// can close was called from widgetset loop
|
||||
if not FCanCloseCalled then
|
||||
begin
|
||||
repeat
|
||||
if (FUserChoice <> mrNone) and (Handle<>0) then
|
||||
begin
|
||||
CanClose := True;
|
||||
DoCanClose(CanClose);
|
||||
if not CanClose then
|
||||
FUserChoice:=mrNone;
|
||||
end;
|
||||
if FUserChoice <> mrNone then
|
||||
break;
|
||||
{ win32 widgetset dialogs use their own message loop,
|
||||
so only FUserChoice may have been set already }
|
||||
Application.HandleMessage;
|
||||
until false;
|
||||
end;
|
||||
Result := (FUserChoice = mrOk);
|
||||
end;
|
||||
|
@ -398,6 +398,26 @@ type
|
||||
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
|
||||
end;
|
||||
|
||||
{ TQtStringList }
|
||||
|
||||
TQtStringList = class(TStrings)
|
||||
private
|
||||
FHandle: QStringListH;
|
||||
FOwnHandle: Boolean;
|
||||
protected
|
||||
function Get(Index: Integer): string; override;
|
||||
function GetCount: Integer; override;
|
||||
public
|
||||
constructor Create;
|
||||
constructor Create(Source: QStringListH);
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure Clear; override;
|
||||
procedure Delete(Index: Integer); override;
|
||||
procedure Insert(Index: Integer; const S: string); override;
|
||||
property Handle: QStringListH read FHandle;
|
||||
end;
|
||||
|
||||
procedure TQColorToColorRef(const AColor: TQColor; out AColorRef: TColorRef);
|
||||
procedure ColorRefToTQColor(const AColorRef: TColorRef; var AColor:TQColor);
|
||||
procedure DebugRegion(const msg: string; Rgn: QRegionH);
|
||||
@ -2374,6 +2394,58 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TQtStringList }
|
||||
|
||||
function TQtStringList.Get(Index: Integer): string;
|
||||
var
|
||||
W: Widestring;
|
||||
begin
|
||||
QStringList_at(FHandle, @W, Index);
|
||||
Result := Utf8Encode(W);
|
||||
end;
|
||||
|
||||
function TQtStringList.GetCount: Integer;
|
||||
begin
|
||||
Result := QStringList_size(FHandle);
|
||||
end;
|
||||
|
||||
constructor TQtStringList.Create;
|
||||
begin
|
||||
FHandle := QStringList_create();
|
||||
FOwnHandle := True;
|
||||
end;
|
||||
|
||||
constructor TQtStringList.Create(Source: QStringListH);
|
||||
begin
|
||||
FHandle := Source;
|
||||
FOwnHandle := False;
|
||||
end;
|
||||
|
||||
destructor TQtStringList.Destroy;
|
||||
begin
|
||||
if FOwnHandle then
|
||||
QStringList_destroy(FHandle);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TQtStringList.Clear;
|
||||
begin
|
||||
QStringList_clear(FHandle);
|
||||
end;
|
||||
|
||||
procedure TQtStringList.Delete(Index: Integer);
|
||||
begin
|
||||
QStringList_removeAt(FHandle, Index);
|
||||
end;
|
||||
|
||||
procedure TQtStringList.Insert(Index: Integer; const S: string);
|
||||
var
|
||||
W: WideString;
|
||||
begin
|
||||
W := GetUtf8String(S);
|
||||
QStringList_insert(FHandle, Index, @W);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ uses
|
||||
Classes, SysUtils, Types,
|
||||
// LCL
|
||||
LCLType, LCLProc, LCLIntf, LMessages, Buttons, Forms, Controls, ComCtrls, CommCtrl,
|
||||
ExtCtrls, StdCtrls, Menus;
|
||||
ExtCtrls, StdCtrls, Menus, Dialogs;
|
||||
|
||||
type
|
||||
// forward declarations
|
||||
@ -83,7 +83,6 @@ type
|
||||
function QtButtonsToLCLButtons(AButtons: QTMouseButton): PtrInt;
|
||||
function QtKeyModifiersToKeyState(AModifiers: QtKeyboardModifiers): PtrInt;
|
||||
function QtKeyToLCLKey(AKey: Integer; AText: WideString): Word;
|
||||
function DeliverMessage(var Msg): LRESULT;
|
||||
procedure SetProps(const AnIndex: String; const AValue: pointer);
|
||||
procedure SetWidget(const AValue: QWidgetH);
|
||||
function ShiftStateToQtModifiers(Shift: TShiftState): QtModifier;
|
||||
@ -95,6 +94,7 @@ type
|
||||
|
||||
function CreateWidget(const Params: TCreateParams):QWidgetH; virtual;
|
||||
procedure SetGeometry; virtual; overload;
|
||||
function DeliverMessage(var Msg): LRESULT; virtual;
|
||||
public
|
||||
AVariant: QVariantH;
|
||||
LCLObject: TWinControl;
|
||||
@ -111,7 +111,7 @@ type
|
||||
public
|
||||
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
|
||||
procedure SlotShow(vShow: Boolean); cdecl;
|
||||
procedure SlotClose; cdecl;
|
||||
function SlotClose: Boolean; cdecl; virtual;
|
||||
procedure SlotDestroy; cdecl;
|
||||
procedure SlotFocus(FocusIn: Boolean); cdecl;
|
||||
procedure SlotHover(Sender: QObjectH; Event: QEventH); cdecl;
|
||||
@ -872,10 +872,47 @@ type
|
||||
{ TQtDialog }
|
||||
|
||||
TQtDialog = class(TQtWidget)
|
||||
private
|
||||
protected
|
||||
FDialog: TCommonDialog;
|
||||
function CreateWidget(parent: QWidgetH; f: QtWindowFlags):QWidgetH; virtual; overload;
|
||||
public
|
||||
constructor Create(ADialog: TCommonDialog; parent: QWidgetH = nil; f: QtWindowFlags = 0); overload;
|
||||
procedure AttachEvents; override;
|
||||
procedure DetachEvents; override;
|
||||
function DeliverMessage(var Msg): LRESULT; override;
|
||||
function SlotClose: Boolean; cdecl; override;
|
||||
public
|
||||
constructor Create(parent: QWidgetH = nil; f: QtWindowFlags = 0); overload;
|
||||
function exec: Integer;
|
||||
procedure setSizeGripEnabled(const AEnabled: Boolean);
|
||||
end;
|
||||
|
||||
{ TQtFileDialog }
|
||||
|
||||
TQtFileDialog = class(TQtDialog)
|
||||
private
|
||||
FCurrentChangedHook: QFileDialog_hookH;
|
||||
FDirecotyEnteredHook: QFileDialog_hookH;
|
||||
FFilterSelectedHook: QFileDialog_hookH;
|
||||
protected
|
||||
function CreateWidget(parent: QWidgetH; f: QtWindowFlags):QWidgetH; override;
|
||||
public
|
||||
procedure AttachEvents; override;
|
||||
procedure DetachEvents; override;
|
||||
procedure CurrentChangedEvent(path: PWideString); cdecl;
|
||||
procedure FilterSelectedEvent(filter: PWideString); cdecl;
|
||||
procedure DirectoryEnteredEvent(directory: PWideString); cdecl;
|
||||
public
|
||||
procedure getFilters(const retval: QStringListH);
|
||||
function selectFile: WideString;
|
||||
procedure selectedFiles(retval: QStringListH);
|
||||
procedure setAcceptMode(const AMode: QFileDialogAcceptMode);
|
||||
procedure setConfirmOverwrite(const AValue: Boolean);
|
||||
procedure setDirectory(const ADirectory: WideString);
|
||||
procedure setFileMode(const AMode: QFileDialogFileMode);
|
||||
procedure setFilter(const AFilter: WideString);
|
||||
procedure setLabelText(const ALabel: QFileDialogDialogLabel; const AText: WideString);
|
||||
procedure setReadOnly(const AReadOnly: Boolean);
|
||||
procedure setViewMode(const AMode: QFileDialogViewMode);
|
||||
end;
|
||||
|
||||
{ TQtCalendar }
|
||||
@ -1256,9 +1293,9 @@ begin
|
||||
QEventShow: SlotShow(True);
|
||||
QEventHide: SlotShow(False);
|
||||
QEventClose:
|
||||
if not SlotClose then
|
||||
begin
|
||||
QEvent_ignore(Event);
|
||||
SlotClose;
|
||||
Result := True;
|
||||
end;
|
||||
QEventDestroy: SlotDestroy;
|
||||
@ -1339,13 +1376,20 @@ end;
|
||||
Note: LCL uses LM_CLOSEQUERY to set the form visibility and if we don<EFBFBD>t send this
|
||||
message, you won<EFBFBD>t be able to show a form twice.
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TQtWidget.SlotClose; cdecl;
|
||||
function TQtWidget.SlotClose: Boolean; cdecl;
|
||||
var
|
||||
Msg : TLMessage;
|
||||
begin
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('TQtWidget.SlotClose');
|
||||
{$endif}
|
||||
FillChar(Msg, SizeOf(Msg), 0);
|
||||
|
||||
LCLSendCloseQueryMsg(LCLObject);
|
||||
Msg.Msg := LM_CLOSEQUERY;
|
||||
|
||||
DeliverMessage(Msg);
|
||||
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -6008,9 +6052,45 @@ end;
|
||||
|
||||
{ TQtDialog }
|
||||
|
||||
constructor TQtDialog.Create(parent: QWidgetH; f: QtWindowFlags);
|
||||
function TQtDialog.CreateWidget(parent: QWidgetH; f: QtWindowFlags): QWidgetH;
|
||||
begin
|
||||
Widget := QDialog_create(parent, f);
|
||||
Result := QDialog_create(parent, f);
|
||||
end;
|
||||
|
||||
constructor TQtDialog.Create(ADialog: TCommonDialog; parent: QWidgetH; f: QtWindowFlags);
|
||||
begin
|
||||
FDialog := ADialog;
|
||||
Widget := CreateWidget(parent, f);
|
||||
end;
|
||||
|
||||
procedure TQtDialog.AttachEvents;
|
||||
begin
|
||||
inherited AttachEvents;
|
||||
end;
|
||||
|
||||
procedure TQtDialog.DetachEvents;
|
||||
begin
|
||||
inherited DetachEvents;
|
||||
end;
|
||||
|
||||
function TQtDialog.DeliverMessage(var Msg): LRESULT;
|
||||
begin
|
||||
try
|
||||
if FDialog.HandleAllocated then
|
||||
begin
|
||||
FDialog.Dispatch(TLMessage(Msg));
|
||||
Result := TLMessage(Msg).Result;
|
||||
end else
|
||||
Result := 0;
|
||||
except
|
||||
Application.HandleException(nil);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TQtDialog.SlotClose: Boolean; cdecl;
|
||||
begin
|
||||
Result := True;
|
||||
FDialog.DoCanClose(Result);
|
||||
end;
|
||||
|
||||
function TQtDialog.exec: Integer;
|
||||
@ -6018,6 +6098,11 @@ begin
|
||||
Result := QDialog_exec(QDialogH(Widget));
|
||||
end;
|
||||
|
||||
procedure TQtDialog.setSizeGripEnabled(const AEnabled: Boolean);
|
||||
begin
|
||||
QDialog_setSizeGripEnabled(QDialogH(Widget), AEnabled);
|
||||
end;
|
||||
|
||||
{ TQtAbstractScrollArea }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -6603,4 +6688,130 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TQtFileDialog }
|
||||
|
||||
function TQtFileDialog.CreateWidget(parent: QWidgetH; f: QtWindowFlags): QWidgetH;
|
||||
begin
|
||||
Result := QFileDialog_create(parent, f);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.AttachEvents;
|
||||
var
|
||||
Method: TMethod;
|
||||
begin
|
||||
inherited AttachEvents;
|
||||
|
||||
FCurrentChangedHook := QFileDialog_hook_create(Widget);
|
||||
FDirecotyEnteredHook := QFileDialog_hook_create(Widget);
|
||||
FFilterSelectedHook := QFileDialog_hook_create(Widget);
|
||||
|
||||
{$IFDEF USE_QT_4_3}
|
||||
QFileDialog_filterSelected_Event(Method) := FilterSelectedEvent;
|
||||
QFileDialog_hook_hook_filterSelected(FFilterSelectedHook, Method);
|
||||
{$ENDIF}
|
||||
|
||||
QFileDialog_currentChanged_Event(Method) := CurrentChangedEvent;
|
||||
QFileDialog_hook_hook_currentChanged(FCurrentChangedHook, Method);
|
||||
|
||||
{$IFDEF USE_QT_4_3}
|
||||
QFileDialog_directoryEntered_Event(Method) := DirectoryEnteredEvent;
|
||||
QFileDialog_hook_hook_directoryEntered(FDirecotyEnteredHook, Method);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.DetachEvents;
|
||||
begin
|
||||
QFileDialog_hook_destroy(FCurrentChangedHook);
|
||||
QFileDialog_hook_destroy(FFilterSelectedHook);
|
||||
QFileDialog_hook_destroy(FDirecotyEnteredHook);
|
||||
|
||||
inherited DetachEvents;
|
||||
end;
|
||||
|
||||
function TQtFileDialog.selectFile: WideString;
|
||||
begin
|
||||
QFileDialog_selectFile(QFileDialogH(Widget), @Result);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.selectedFiles(retval: QStringListH);
|
||||
begin
|
||||
QFileDialog_selectedFiles(QFileDialogH(Widget), retval);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setAcceptMode(const AMode: QFileDialogAcceptMode);
|
||||
begin
|
||||
QFileDialog_setAcceptMode(QFileDialogH(Widget), AMode)
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setConfirmOverwrite(const AValue: Boolean);
|
||||
begin
|
||||
QFileDialog_setConfirmOverwrite(QFileDialogH(Widget), AValue);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setDirectory(const ADirectory: WideString);
|
||||
begin
|
||||
QFileDialog_setDirectory(QFileDialogH(Widget), @ADirectory);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setFileMode(const AMode: QFileDialogFileMode);
|
||||
begin
|
||||
QFileDialog_setFileMode(QFileDialogH(Widget), AMode);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setFilter(const AFilter: WideString);
|
||||
begin
|
||||
QFileDialog_setFilter(QFileDialogH(Widget), @AFilter);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setLabelText(const ALabel: QFileDialogDialogLabel; const AText: WideString);
|
||||
begin
|
||||
QFileDialog_setLabelText(QFileDialogH(Widget), ALabel, @AText);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setReadOnly(const AReadOnly: Boolean);
|
||||
begin
|
||||
QFileDialog_setReadOnly(QFileDialogH(Widget), AReadOnly);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.setViewMode(const AMode: QFileDialogViewMode);
|
||||
begin
|
||||
QFileDialog_setViewMode(QFileDialogH(Widget), AMode);
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.FilterSelectedEvent(filter: PWideString); cdecl;
|
||||
var
|
||||
List: TQtStringList;
|
||||
index: Integer;
|
||||
begin
|
||||
if filter <> nil then
|
||||
begin
|
||||
List := TQtStringList.Create;
|
||||
getFilters(List.Handle);
|
||||
index := List.IndexOf(Utf8Encode(filter^));
|
||||
if index <> -1 then
|
||||
TFileDialog(FDialog).IntfFileTypeChanged(index + 1);
|
||||
List.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.CurrentChangedEvent(path: PWideString); cdecl;
|
||||
begin
|
||||
if FDialog is TOpenDialog then
|
||||
begin
|
||||
TOpenDialog(FDialog).FileName := Utf8Encode(path^);
|
||||
TOpenDialog(FDialog).DoSelectionChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.DirectoryEnteredEvent(directory: PWideString); cdecl;
|
||||
begin
|
||||
if FDialog is TOpenDialog then
|
||||
TOpenDialog(FDialog).DoFolderChange;
|
||||
end;
|
||||
|
||||
procedure TQtFileDialog.getFilters(const retval: QStringListH);
|
||||
begin
|
||||
QFileDialog_filters(QFileDialogH(Widget), retval);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -922,8 +922,7 @@ var
|
||||
ColorDark, ColorLight: TColor;
|
||||
ClientRect: TRect;
|
||||
QtDC: TQtDeviceContext;
|
||||
Pen: QPenH;
|
||||
|
||||
|
||||
procedure InternalDrawEdge(Outer: Boolean; const R: TRect);
|
||||
var
|
||||
X1, Y1, X2, Y2: Integer;
|
||||
|
@ -46,9 +46,11 @@ type
|
||||
TQtWSCommonDialog = class(TWSCommonDialog)
|
||||
private
|
||||
protected
|
||||
class function GetDialogParent(const ACommonDialog: TCommonDialog): QWidgetH;
|
||||
public
|
||||
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
|
||||
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
|
||||
class procedure DestroyHandle(const ACommonDialog: TCommonDialog); override;
|
||||
class procedure ShowModal(const ACommonDialog: TCommonDialog); override;
|
||||
end;
|
||||
|
||||
{ TQtWSFileDialog }
|
||||
@ -56,7 +58,10 @@ type
|
||||
TQtWSFileDialog = class(TWSFileDialog)
|
||||
private
|
||||
protected
|
||||
class function GetQtFilterString(const AFileDialog: TFileDialog): WideString;
|
||||
class procedure UpdateProperties(const AFileDialog: TFileDialog; QtFileDialog: TQtFileDialog);
|
||||
public
|
||||
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
|
||||
class procedure ShowModal(const ACommonDialog: TCommonDialog); override;
|
||||
end;
|
||||
|
||||
@ -90,6 +95,7 @@ type
|
||||
private
|
||||
protected
|
||||
public
|
||||
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
|
||||
class procedure ShowModal(const ACommonDialog: TCommonDialog); override;
|
||||
end;
|
||||
|
||||
@ -107,14 +113,33 @@ type
|
||||
private
|
||||
protected
|
||||
public
|
||||
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
|
||||
class procedure ShowModal(const ACommonDialog: TCommonDialog); override;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
QtDialogCodeToModalResultMap: array[QDialogDialogCode] of TModalResult =
|
||||
(
|
||||
{QDialogRejected} mrCancel,
|
||||
{QDialogAccepted} mrOk
|
||||
);
|
||||
|
||||
{ TQtWSCommonDialog }
|
||||
|
||||
class function TQtWSCommonDialog.GetDialogParent(const ACommonDialog: TCommonDialog): QWidgetH;
|
||||
begin
|
||||
if ACommonDialog.Owner is TWinControl then
|
||||
Result := TQtWidget(TWinControl(ACommonDialog.Owner).Handle).Widget
|
||||
else
|
||||
if Assigned(Application.MainForm) then
|
||||
Result := TQtWidget(Application.MainForm.Handle).Widget
|
||||
else
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: TQtWSCommonDialog.CreateHandle
|
||||
Params: None
|
||||
@ -124,7 +149,8 @@ implementation
|
||||
------------------------------------------------------------------------------}
|
||||
class function TQtWSCommonDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
Result := THandle(TQtDialog.Create(ACommonDialog, GetDialogParent(ACommonDialog)));
|
||||
TQtDialog(Result).AttachEvents;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -136,49 +162,22 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSCommonDialog.DestroyHandle(const ACommonDialog: TCommonDialog);
|
||||
begin
|
||||
TQtDialog(ACommonDialog.Handle).Release;
|
||||
end;
|
||||
|
||||
class procedure TQtWSCommonDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
begin
|
||||
TQtDialog(ACommonDialog.Handle).exec;
|
||||
end;
|
||||
|
||||
{ TQtWSFileDialog }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: TQtWSFileDialog.ShowModal
|
||||
Params: None
|
||||
Returns: Nothing
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSFileDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
class function TQtWSFileDialog.GetQtFilterString(const AFileDialog: TFileDialog): WideString;
|
||||
var
|
||||
Caption, Dir, Filter, selectedFilter, ReturnText: WideString;
|
||||
TmpFilter, strExtensions: string;
|
||||
FileDialog: TFileDialog;
|
||||
options: QFileDialogOptions;
|
||||
Parent: QWidgetH;
|
||||
ReturnList: QStringListH;
|
||||
ParserState, Position, i: Integer;
|
||||
begin
|
||||
{------------------------------------------------------------------------------
|
||||
Initialization of variables
|
||||
------------------------------------------------------------------------------}
|
||||
ReturnText := '';
|
||||
TmpFilter := '';
|
||||
selectedFilter := '';
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Initialization of the dialog fields
|
||||
------------------------------------------------------------------------------}
|
||||
if ACommonDialog.Owner is TWinControl then
|
||||
Parent := TQtWidget(TWinControl(ACommonDialog.Owner).Handle).Widget
|
||||
else if Assigned(Application.MainForm) then
|
||||
Parent := TQtWidget(Application.MainForm.Handle).Widget
|
||||
else Parent := nil;
|
||||
|
||||
Caption := GetUtf8String(ACommonDialog.Title);
|
||||
|
||||
FileDialog := TFileDialog(ACommonDialog);
|
||||
|
||||
Dir := GetUtf8String(FileDialog.InitialDir);
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
{------------------------------------------------------------------------------
|
||||
This is a parser that converts LCL filter strings to Qt filter strings
|
||||
|
||||
The parses states are:
|
||||
@ -208,105 +207,141 @@ begin
|
||||
|
||||
ParserState := 0;
|
||||
Position := 1;
|
||||
TmpFilter := '';
|
||||
|
||||
for i := 1 to Length(FileDialog.Filter) do
|
||||
for i := 1 to Length(AFileDialog.Filter) do
|
||||
begin
|
||||
if Copy(FileDialog.Filter, i, 1) = '|' then
|
||||
if Copy(AFileDialog.Filter, i, 1) = '|' then
|
||||
begin
|
||||
ParserState := ParserState + 1;
|
||||
|
||||
if ParserState = 1 then
|
||||
TmpFilter := TmpFilter + Copy(FileDialog.Filter, Position, i - Position)
|
||||
else if ParserState = 2 then
|
||||
TmpFilter := TmpFilter + Copy(AFileDialog.Filter, Position, i - Position)
|
||||
else
|
||||
if ParserState = 2 then
|
||||
begin
|
||||
strExtensions := '(' + Copy(FileDialog.Filter, Position, i - Position) + ')';
|
||||
strExtensions := '(' + Copy(AFileDialog.Filter, Position, i - Position) + ')';
|
||||
|
||||
if Pos(strExtensions, TmpFilter) = 0 then TmpFilter := TmpFilter + ' ' + strExtensions;
|
||||
if Pos(strExtensions, TmpFilter) = 0 then
|
||||
TmpFilter := TmpFilter + ' ' + strExtensions;
|
||||
|
||||
TmpFilter := TmpFilter + ';;';
|
||||
|
||||
ParserState := 0;
|
||||
end;
|
||||
|
||||
if i <> Length(FileDialog.Filter) then Position := i + 1;
|
||||
if i <> Length(AFileDialog.Filter) then
|
||||
Position := i + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
strExtensions := '(' + Copy(FileDialog.Filter, Position, i + 1 - Position) + ')';
|
||||
strExtensions := '(' + Copy(AFileDialog.Filter, Position, i + 1 - Position) + ')';
|
||||
|
||||
if Pos(strExtensions, TmpFilter) = 0 then TmpFilter := TmpFilter + ' ' + strExtensions;
|
||||
if Pos(strExtensions, TmpFilter) = 0 then
|
||||
TmpFilter := TmpFilter + ' ' + strExtensions;
|
||||
Result := GetUtf8String(TmpFilter);
|
||||
end;
|
||||
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('[TQtWSCommonDialog.ShowModal] Parsed Filter: ', TmpFilter);
|
||||
{$endif}
|
||||
class procedure TQtWSFileDialog.UpdateProperties(
|
||||
const AFileDialog: TFileDialog; QtFileDialog: TQtFileDialog);
|
||||
var
|
||||
ATitle: WideString;
|
||||
begin
|
||||
ATitle := GetUtf8String(AFileDialog.Title);
|
||||
QtFileDialog.setWindowTitle(@ATitle);
|
||||
QtFileDialog.setDirectory(GetUtf8String(AFileDialog.InitialDir));
|
||||
QtFileDialog.setFilter(GetQtFilterString(AFileDialog));
|
||||
QtFileDialog.setConfirmOverwrite(ofOverwritePrompt in TOpenDialog(AFileDialog).Options);
|
||||
QtFileDialog.setReadOnly(ofReadOnly in TOpenDialog(AFileDialog).Options);
|
||||
QtFileDialog.setSizeGripEnabled(ofEnableSizing in TOpenDialog(AFileDialog).Options);
|
||||
|
||||
Filter := GetUtf8String(TmpFilter);
|
||||
if ofViewDetail in TOpenDialog(AFileDialog).Options then
|
||||
QtFileDialog.setViewMode(QFileDialogDetail)
|
||||
else
|
||||
QtFileDialog.setViewMode(QFileDialogList);
|
||||
|
||||
if ofFileMustExist in TOpenDialog(AFileDialog).Options then
|
||||
begin
|
||||
if ofAllowMultiSelect in TOpenDialog(AFileDialog).Options then
|
||||
QtFileDialog.setFileMode(QFileDialogExistingFiles)
|
||||
else
|
||||
QtFileDialog.setFileMode(QFileDialogExistingFile)
|
||||
end
|
||||
else
|
||||
QtFileDialog.setFileMode(QFileDialogAnyFile);
|
||||
QtFileDialog.setLabelText(QFileDialogFileName, GetUtf8String(AFileDialog.FileName));
|
||||
end;
|
||||
|
||||
class function TQtWSFileDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
|
||||
var
|
||||
FileDialog: TQtFileDialog;
|
||||
begin
|
||||
FileDialog := TQtFileDialog.Create(ACommonDialog, TQtWSCommonDialog.GetDialogParent(ACommonDialog));
|
||||
FileDialog.AttachEvents;
|
||||
|
||||
Result := THandle(FileDialog);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: TQtWSFileDialog.ShowModal
|
||||
Params: None
|
||||
Returns: Nothing
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSFileDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
var
|
||||
selectedFilter, ReturnText: WideString;
|
||||
FileDialog: TFileDialog;
|
||||
ReturnList: QStringListH;
|
||||
i: integer;
|
||||
QtFileDialog: TQtFileDialog;
|
||||
begin
|
||||
{------------------------------------------------------------------------------
|
||||
Qt doesn´t have most of the dialog options available on LCL
|
||||
Initialization of variables
|
||||
------------------------------------------------------------------------------}
|
||||
ReturnText := '';
|
||||
selectedFilter := '';
|
||||
|
||||
options := 0;
|
||||
FileDialog := TFileDialog(ACommonDialog);
|
||||
QtFileDialog := TQtFileDialog(FileDialog.Handle);
|
||||
|
||||
UpdateProperties(FileDialog, QtFileDialog);
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Code to call the dialog
|
||||
------------------------------------------------------------------------------}
|
||||
if ACommonDialog is TSaveDialog then
|
||||
begin
|
||||
if ofOverwritePrompt in TSaveDialog(ACommonDialog).Options then
|
||||
options := options or QFileDialogDontConfirmOverwrite;
|
||||
if FileDialog is TSaveDialog then
|
||||
QtFileDialog.setAcceptMode(QFileDialogAcceptSave)
|
||||
else
|
||||
if FileDialog is TOpenDialog then
|
||||
QtFileDialog.setAcceptMode(QFileDialogAcceptOpen)
|
||||
else
|
||||
if ACommonDialog is TSelectDirectoryDialog then
|
||||
QtFileDialog.setFileMode(QFileDialogDirectoryOnly);
|
||||
|
||||
Dir := Dir + ExtractFileName(FileDialog.FileName);
|
||||
|
||||
QFileDialog_getSaveFileName(@ReturnText, Parent, @Caption, @Dir, @Filter, @selectedFilter, options);
|
||||
|
||||
if ReturnText = '' then ACommonDialog.UserChoice := mrCancel
|
||||
else ACommonDialog.UserChoice := mrOK;
|
||||
|
||||
FileDialog.FileName := UTF8Encode(ReturnText);
|
||||
end
|
||||
else if ACommonDialog is TOpenDialog then
|
||||
begin
|
||||
if ofAllowMultiSelect in TOpenDialog(ACommonDialog).Options then
|
||||
FileDialog.UserChoice := QtDialogCodeToModalResultMap[QDialogDialogCode(QtFileDialog.exec)];
|
||||
ReturnList := QStringList_create;
|
||||
try
|
||||
QtFileDialog.selectedFiles(ReturnList);
|
||||
for i := 0 to QStringList_size(ReturnList) - 1 do
|
||||
begin
|
||||
ReturnList := QStringList_create;
|
||||
try
|
||||
|
||||
QFileDialog_getOpenFileNames(ReturnList, Parent, @Caption, @Dir, @Filter, @selectedFilter, options);
|
||||
|
||||
for i := 0 to QStringList_size(ReturnList) - 1 do
|
||||
begin
|
||||
QStringList_at(ReturnList, @ReturnText, i);
|
||||
FileDialog.Files.Add(UTF8Encode(ReturnText));
|
||||
end;
|
||||
|
||||
ReturnText := FileDialog.Files.Text;
|
||||
|
||||
finally
|
||||
QStringList_destroy(ReturnList);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
QFileDialog_getOpenFileName(@ReturnText, Parent, @Caption, @Dir, @Filter, @selectedFilter, options);
|
||||
|
||||
FileDialog.FileName := UTF8Encode(ReturnText);
|
||||
QStringList_at(ReturnList, @ReturnText, i);
|
||||
FileDialog.Files.Add(UTF8Encode(ReturnText));
|
||||
if i = 0 then
|
||||
FileDialog.FileName := UTF8Encode(ReturnText);
|
||||
end;
|
||||
|
||||
if ReturnText = '' then ACommonDialog.UserChoice := mrCancel
|
||||
else ACommonDialog.UserChoice := mrOK;
|
||||
end
|
||||
else if ACommonDialog is TSelectDirectoryDialog then
|
||||
begin
|
||||
QFileDialog_getExistingDirectory(@ReturnText, Parent, @Caption, @Dir);
|
||||
|
||||
if ReturnText = '' then ACommonDialog.UserChoice := mrCancel
|
||||
else ACommonDialog.UserChoice := mrOK;
|
||||
ReturnText := FileDialog.Files.Text;
|
||||
finally
|
||||
QStringList_destroy(ReturnList);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TQtWSColorDialog }
|
||||
|
||||
class function TQtWSColorDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: TQtWSColorDialog.ShowModal
|
||||
Params: None
|
||||
@ -314,39 +349,46 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSColorDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
var
|
||||
AColor: TQColor;
|
||||
ARefColor: TColor;
|
||||
Parent: QWidgetH;
|
||||
AColor: TColor;
|
||||
AQColor: TQColor;
|
||||
AQtColor: QColorH;
|
||||
ARgb: QRgb;
|
||||
ReturnBool: Boolean;
|
||||
AQtColor: QColorH;
|
||||
begin
|
||||
AColor := ColorToRgb(TColorDialog(ACommonDialog).Color);
|
||||
AQColor.Alpha := $FFFF;
|
||||
AQColor.ColorSpec := 1;
|
||||
AQColor.Pad := 0;
|
||||
ColorRefToTQColor(AColor, AQColor);
|
||||
AQtColor := QColor_create(PQColor(@AQColor));
|
||||
ARgb := QColor_rgba(AQtColor);
|
||||
|
||||
if ACommonDialog.Owner is TWinControl then
|
||||
Parent := TQtWidget(TWinControl(ACommonDialog.Owner).Handle).Widget
|
||||
else if Assigned(Application.MainForm) then
|
||||
Parent := TQtWidget(Application.MainForm.Handle).Widget
|
||||
else Parent := nil;
|
||||
ARgb := QColorDialog_getRgba(ARgb, @ReturnBool,
|
||||
TQtWSCommonDialog.GetDialogParent(ACommonDialog));
|
||||
|
||||
ARefColor:= ColorToRgb(TColorDialog(ACommonDialog).Color);
|
||||
|
||||
ARgb := QColorDialog_getRgba(QRgb(ARefColor), @ReturnBool, Parent);
|
||||
|
||||
AQtColor := QColor_create(ARgb);
|
||||
QColor_fromRgba(PQColor(AQtColor), ARgb);
|
||||
try
|
||||
QColor_toRgb(AQtColor, @AColor);
|
||||
TQColorToColorRef(AColor, ARefColor);
|
||||
TColorDialog(ACommonDialog).Color := ARefColor;
|
||||
QColor_toRgb(AQtColor, @AQColor);
|
||||
TQColorToColorRef(AQColor, AColor);
|
||||
TColorDialog(ACommonDialog).Color := AColor;
|
||||
finally
|
||||
QColor_destroy(AQtColor);
|
||||
end;
|
||||
|
||||
if ReturnBool then ACommonDialog.UserChoice := mrOk
|
||||
else ACommonDialog.UserChoice := mrCancel;
|
||||
if ReturnBool then
|
||||
ACommonDialog.UserChoice := mrOk
|
||||
else
|
||||
ACommonDialog.UserChoice := mrCancel;
|
||||
end;
|
||||
|
||||
{ TQtWSFontDialog }
|
||||
|
||||
class function TQtWSFontDialog.CreateHandle(const ACommonDialog: TCommonDialog
|
||||
): THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: TQtWSFontDialog.ShowModal
|
||||
Params: None
|
||||
@ -354,20 +396,10 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSFontDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
var
|
||||
Parent: QWidgetH;
|
||||
ReturnFont, CurrentFont: QFontH;
|
||||
ReturnBool: Boolean;
|
||||
Str: WideString;
|
||||
begin
|
||||
{------------------------------------------------------------------------------
|
||||
Initialization of options
|
||||
------------------------------------------------------------------------------}
|
||||
if ACommonDialog.Owner is TWinControl then
|
||||
Parent := TQtWidget(TWinControl(ACommonDialog.Owner).Handle).Widget
|
||||
else if Assigned(Application.MainForm) then
|
||||
Parent := TQtWidget(Application.MainForm.Handle).Widget
|
||||
else Parent := nil;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Code to call the dialog
|
||||
------------------------------------------------------------------------------}
|
||||
@ -375,7 +407,8 @@ begin
|
||||
|
||||
ReturnFont := QFont_create;
|
||||
try
|
||||
QFontDialog_getFont(ReturnFont, @ReturnBool, CurrentFont, Parent);
|
||||
QFontDialog_getFont(ReturnFont, @ReturnBool, CurrentFont,
|
||||
TQtWSCommonDialog.GetDialogParent(ACommonDialog));
|
||||
|
||||
QFont_family(ReturnFont, @Str);
|
||||
TFontDialog(ACommonDialog).Font.Name := UTF8Encode(Str);
|
||||
@ -404,8 +437,10 @@ begin
|
||||
QFont_destroy(ReturnFont);
|
||||
end;
|
||||
|
||||
if ReturnBool then ACommonDialog.UserChoice := mrOk
|
||||
else ACommonDialog.UserChoice := mrCancel;
|
||||
if ReturnBool then
|
||||
ACommonDialog.UserChoice := mrOk
|
||||
else
|
||||
ACommonDialog.UserChoice := mrCancel;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -389,7 +389,7 @@ begin
|
||||
{$else}
|
||||
w := QWidget_childAt(TabWidget.TabBar, @APoint);
|
||||
if w <> nil then
|
||||
Result := TabWidget.indexOf(w);
|
||||
Result := TabWidget.indexOf(w)
|
||||
else
|
||||
Result := -1;
|
||||
{$endif}
|
||||
|
Loading…
Reference in New Issue
Block a user