mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-15 23:40:34 +01:00
Patch from zeljko to the Qt widgetset. Fixed AV with TFontDialog, added SetFont, implemented TColorDialog, other small fixes, implemented ReadOnly on TSpinBox.
git-svn-id: trunk@11397 -
This commit is contained in:
parent
52ce9136d3
commit
77b45f8368
@ -35,7 +35,7 @@ uses
|
||||
{$endif}
|
||||
qtobjects, qtwidgets,
|
||||
// RTL + LCL
|
||||
SysUtils, Classes, LCLType, Dialogs, Controls, Forms,
|
||||
SysUtils, Classes, LCLType, Dialogs, Controls, Forms, Graphics,
|
||||
// Widgetset
|
||||
WSDialogs, WSLCLClasses;
|
||||
|
||||
@ -301,8 +301,35 @@ end;
|
||||
Returns: Nothing
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TQtWSColorDialog.ShowModal(const ACommonDialog: TCommonDialog);
|
||||
var
|
||||
AColor: TQColor;
|
||||
ARefColor: TColor;
|
||||
Parent: QWidgetH;
|
||||
ARgb: QRgb;
|
||||
ReturnBool: Boolean;
|
||||
AQtColor: QColorH;
|
||||
begin
|
||||
|
||||
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;
|
||||
|
||||
ARefColor:= ColorToRgb(TColorDialog(ACommonDialog).Color);
|
||||
|
||||
ARgb := QColorDialog_getRgba(QRgb(ARefColor), @ReturnBool, Parent);
|
||||
|
||||
AQtColor := QColor_create(ARgb);
|
||||
try
|
||||
QColor_toRgb(AQtColor, @AColor);
|
||||
TQColorToColorRef(AColor, TColorDialog(ACommonDialog).Color);
|
||||
finally
|
||||
QColor_destroy(AQtColor);
|
||||
end;
|
||||
|
||||
if ReturnBool then ACommonDialog.UserChoice := mrOk
|
||||
else ACommonDialog.UserChoice := mrCancel;
|
||||
end;
|
||||
|
||||
{ TQtWSFontDialog }
|
||||
@ -317,14 +344,15 @@ 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
|
||||
Parent := TQtWidget(TWinControl(ACommonDialog.Owner).Handle).Widget
|
||||
else if Assigned(Application.MainForm) then
|
||||
Parent := TQtWidget(Application.MainForm.Handle).Widget
|
||||
Parent := TQtWidget(Application.MainForm.Handle).Widget
|
||||
else Parent := nil;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -332,7 +360,36 @@ begin
|
||||
------------------------------------------------------------------------------}
|
||||
CurrentFont := TQtFont(TFontDialog(ACommonDialog).Font.Handle).Widget;
|
||||
|
||||
QFontDialog_getFont(ReturnFont, @ReturnBool, CurrentFont, Parent);
|
||||
ReturnFont := QFont_create;
|
||||
try
|
||||
QFontDialog_getFont(ReturnFont, @ReturnBool, CurrentFont, Parent);
|
||||
|
||||
QFont_family(ReturnFont, @Str);
|
||||
TFontDialog(ACommonDialog).Font.Name := UTF8Encode(Str);
|
||||
|
||||
TFontDialog(ACommonDialog).Font.Height := QFont_pointSize(ReturnFont);
|
||||
TFontDialog(ACommonDialog).Font.Style := [];
|
||||
|
||||
if QFont_bold(ReturnFont) then
|
||||
TFontDialog(ACommonDialog).Font.Style := TFontDialog(ACommonDialog).Font.Style + [fsBold];
|
||||
|
||||
if QFont_italic(ReturnFont) then
|
||||
TFontDialog(ACommonDialog).Font.Style := TFontDialog(ACommonDialog).Font.Style + [fsItalic];
|
||||
|
||||
if QFont_strikeOut(ReturnFont) then
|
||||
TFontDialog(ACommonDialog).Font.Style := TFontDialog(ACommonDialog).Font.Style + [fsStrikeOut];
|
||||
|
||||
if QFont_underline(ReturnFont) then
|
||||
TFontDialog(ACommonDialog).Font.Style := TFontDialog(ACommonDialog).Font.Style + [fsUnderline];
|
||||
|
||||
if QFont_fixedPitch(ReturnFont) then
|
||||
TFontDialog(ACommonDialog).Font.Pitch := fpFixed
|
||||
else
|
||||
TFontDialog(ACommonDialog).Font.Pitch := fpDefault;
|
||||
|
||||
finally
|
||||
QFont_destroy(ReturnFont);
|
||||
end;
|
||||
|
||||
if ReturnBool then ACommonDialog.UserChoice := mrOk
|
||||
else ACommonDialog.UserChoice := mrCancel;
|
||||
|
||||
@ -35,7 +35,7 @@ uses
|
||||
{$endif}
|
||||
qtwidgets, qtobjects,
|
||||
// LCL
|
||||
SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls, LCLType,
|
||||
SysUtils, Classes, Controls, Graphics, Forms, StdCtrls, ExtCtrls, LCLType,
|
||||
// Widgetset
|
||||
WSExtCtrls, WSLCLClasses;
|
||||
|
||||
@ -380,6 +380,7 @@ begin
|
||||
TEventFilterMethod(Method) := QtTabWidget.EventFilter;
|
||||
|
||||
QObject_hook_hook_events(Hook, Method);
|
||||
|
||||
QTabWidget_currentChanged_Event(Method) := QtTabWidget.SignalCurrentChanged;
|
||||
QTabWidget_hook_hook_currentChanged(QTabWidget_hook_create(QtTabWidget.Widget), Method);
|
||||
|
||||
@ -488,10 +489,10 @@ end;
|
||||
class procedure TQtWSCustomRadioGroup.DestroyHandle(const AWinControl: TWinControl);
|
||||
begin
|
||||
if Assigned(TQtGroupBox(AWinControl.Handle).ButtonGroup) then
|
||||
TQtGroupBox(AWinControl.Handle).ButtonGroup.Free;
|
||||
TQtGroupBox(AWinControl.Handle).ButtonGroup.Free;
|
||||
|
||||
if TQtGroupBox(AWinControl.Handle).BoxLayout <> NiL then
|
||||
QGridLayout_destroy(TQtGroupBox(AWinControl.Handle).BoxLayout);
|
||||
QGridLayout_destroy(TQtGroupBox(AWinControl.Handle).BoxLayout);
|
||||
|
||||
TQtGroupBox(AWinControl.Handle).Free;
|
||||
|
||||
@ -500,9 +501,37 @@ end;
|
||||
|
||||
|
||||
class procedure TQtWSCustomRadioGroup.ShowHide(const AWinControl: TWinControl);
|
||||
var
|
||||
i: Integer;
|
||||
ATextWidth: Integer;
|
||||
ATextHeight: Integer;
|
||||
FM: QFontMetricsH;
|
||||
Str: WideString;
|
||||
begin
|
||||
inherited ShowHide(AWinControl);
|
||||
{without this we have invisible radio buttons}
|
||||
{only this guarantee that our items are visible anytime ....}
|
||||
for i := 0 to TRadioGroup(AWinControl).ComponentCount - 1 do
|
||||
begin
|
||||
if TRadioButton(AWinControl.Components[i]).Height = 0 then
|
||||
begin
|
||||
FM := QFontMetrics_create(QWidget_font(TQtRadioButton(TRadioButton(AWinControl.Components[i]).Handle).Widget));
|
||||
try
|
||||
Str := UTF8Encode(TRadioButton(AWinControl.Components[i]).Caption);
|
||||
ATextWidth := QFontMetrics_width(FM, @Str, Length(Str));
|
||||
ATextHeight := QFontMetrics_height(FM);
|
||||
finally
|
||||
QFontMetrics_destroy(FM);
|
||||
end;
|
||||
|
||||
{ now, textwidth + default width of checkbox, default height
|
||||
qt doesn't align well control with text size < 100}
|
||||
if ATextWidth < 100 then
|
||||
ATextWidth := 100;
|
||||
|
||||
TRadioButton(AWinControl.Components[i]).SetBounds(0, 0, ATextWidth + ATextHeight + 1, ATextHeight);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TQtWSCustomCheckGroup }
|
||||
@ -565,10 +594,10 @@ end;
|
||||
class procedure TQtWSCustomCheckGroup.DestroyHandle(const AWinControl: TWinControl);
|
||||
begin
|
||||
if Assigned(TQtGroupBox(AWinControl.Handle).ButtonGroup) then
|
||||
TQtGroupBox(AWinControl.Handle).ButtonGroup.Free;
|
||||
TQtGroupBox(AWinControl.Handle).ButtonGroup.Free;
|
||||
|
||||
if TQtGroupBox(AWinControl.Handle).BoxLayout <> NiL then
|
||||
QGridLayout_destroy(TQtGroupBox(AWinControl.Handle).BoxLayout);
|
||||
QGridLayout_destroy(TQtGroupBox(AWinControl.Handle).BoxLayout);
|
||||
|
||||
TQtGroupBox(AWinControl.Handle).Free;
|
||||
|
||||
@ -577,9 +606,38 @@ end;
|
||||
|
||||
|
||||
class procedure TQtWSCustomCheckGroup.ShowHide(const AWinControl: TWinControl);
|
||||
var
|
||||
i: Integer;
|
||||
ATextWidth: Integer;
|
||||
ATextHeight: Integer;
|
||||
FM: QFontMetricsH;
|
||||
Str: WideString;
|
||||
begin
|
||||
inherited ShowHide(AWinControl);
|
||||
{without this checkboxes are invisible}
|
||||
inherited ShowHide(AWinControl);
|
||||
|
||||
{only this guarantee that our items are visible anytime ....}
|
||||
for i := 0 to TCheckGroup(AWinControl).ComponentCount - 1 do
|
||||
begin
|
||||
if TCheckBox(AWinControl.Components[i]).Height = 0 then
|
||||
begin
|
||||
FM := QFontMetrics_create(QWidget_font(TQtCheckBox(TCheckBox(AWinControl.Components[i]).Handle).Widget));
|
||||
try
|
||||
Str := UTF8Encode(TCheckBox(AWinControl.Components[i]).Caption);
|
||||
ATextWidth := QFontMetrics_width(FM, @Str, Length(Str));
|
||||
ATextHeight := QFontMetrics_height(FM);
|
||||
finally
|
||||
QFontMetrics_destroy(FM);
|
||||
end;
|
||||
|
||||
{ now, textwidth + default width of checkbox, default height
|
||||
qt doesn't align well control with text size < 100}
|
||||
if ATextWidth < 100 then
|
||||
ATextWidth := 100;
|
||||
|
||||
TCheckBox(AWinControl.Components[i]).SetBounds(0, 0, ATextWidth + ATextHeight + 1, ATextHeight);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
@ -35,7 +35,7 @@ uses
|
||||
{$endif}
|
||||
qtwidgets,
|
||||
// LCL
|
||||
Spin, SysUtils, Controls, Classes, LCLType, LCLProc, LCLIntf, Forms,
|
||||
Spin, SysUtils, Controls, Classes, LCLType, LCLProc, LCLIntf, Forms, StdCtrls,
|
||||
// Widgetset
|
||||
WSSpin, WSLCLClasses;
|
||||
|
||||
@ -54,6 +54,7 @@ type
|
||||
class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
|
||||
class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
|
||||
|
||||
(*
|
||||
class function GetSelStart(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): integer; virtual;
|
||||
@ -198,6 +199,12 @@ begin
|
||||
// perhaps QSpinBox_setSuffix() goes here one day (if we get LCL support)
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomFloatSpinEdit.SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean);
|
||||
begin
|
||||
QAbstractSpinBox_setReadOnly(QAbstractSpinBoxH(TQtAbstractSpinBox(ACustomEdit.Handle).Widget), NewReadOnly);
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
Loading…
Reference in New Issue
Block a user