- QT bindings updated to 1.43
- QT ThemeServices is working now. Can paint Buttons (w/wo Flat), CheckBox, RadioButton, Header

git-svn-id: trunk@11523 -
This commit is contained in:
paul 2007-07-16 09:26:28 +00:00
parent dcbce23a9c
commit 72d601e943
5 changed files with 9779 additions and 9445 deletions

File diff suppressed because it is too large Load Diff

View File

@ -163,8 +163,8 @@ end;
function TQtWidgetSet.CreateThemeServices: TThemeServices; function TQtWidgetSet.CreateThemeServices: TThemeServices;
begin begin
// TODO: uncomment if you want to test TQtThemeServices // TODO: uncomment if you want to test TQtThemeServices
// Result := TQtThemeServices.Create; Result := TQtThemeServices.Create;
Result := inherited CreateThemeServices; //Result := inherited CreateThemeServices;
end; end;
function TQtWidgetSet.LCLPlatform: TLCLPlatform; function TQtWidgetSet.LCLPlatform: TLCLPlatform;

View File

@ -1336,13 +1336,18 @@ var
Mode: QtBGMode; Mode: QtBGMode;
begin begin
result := 0; result := 0;
if Widget<>nil then if Widget <> nil then
begin begin
Mode := QPainter_BackgroundMode(Widget); Mode := QPainter_BackgroundMode(Widget);
if Mode=QtOpaqueMode then result := OPAQUE if Mode = QtOpaqueMode then
else result := TRANSPARENT; result := OPAQUE
if BkMode=OPAQUE then Mode := QtOpaqueMode else
else Mode := QtTransparentMode; result := TRANSPARENT;
if BkMode = OPAQUE then
Mode := QtOpaqueMode
else
Mode := QtTransparentMode;
QPainter_SetBackgroundMode(Widget, Mode); QPainter_SetBackgroundMode(Widget, Mode);
end; end;
end; end;

View File

@ -2,16 +2,6 @@ unit QtThemes;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{
This theme services class is not ready. It waiting for some bindings. Without
them it is not useful.
Waiting for:
QStyleOption_setState
QStyleOption_setRect
... and other QStyleOption setters and getters
}
interface interface
uses uses
@ -55,7 +45,6 @@ type
function ThemedControlsEnabled: Boolean; override; function ThemedControlsEnabled: Boolean; override;
procedure InternalDrawParentBackground(Window: HWND; Target: HDC; Bounds: PRect); override; procedure InternalDrawParentBackground(Window: HWND; Target: HDC; Bounds: PRect); override;
function CreateQRect(R: TRect): QRectH;
function GetControlState(Details: TThemedElementDetails): QStyleState; function GetControlState(Details: TThemedElementDetails): QStyleState;
function GetDrawElement(Details: TThemedElementDetails): TQtDrawElement; function GetDrawElement(Details: TThemedElementDetails): TQtDrawElement;
property Style: QStyleH read GetStyle; property Style: QStyleH read GetStyle;
@ -63,7 +52,7 @@ type
procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect); override; procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect); override;
procedure DrawEdge(DC: HDC; Details: TThemedElementDetails; const R: TRect; Edge, Flags: Cardinal; AContentRect: PRect); override; procedure DrawEdge(DC: HDC; Details: TThemedElementDetails; const R: TRect; Edge, Flags: Cardinal; AContentRect: PRect); override;
procedure DrawIcon(DC: HDC; Details: TThemedElementDetails; const R: TRect; himl: HIMAGELIST; Index: Integer); override; procedure DrawIcon(DC: HDC; Details: TThemedElementDetails; const R: TRect; himl: HIMAGELIST; Index: Integer); override;
procedure DrawText(DC: HDC; Details: TThemedElementDetails; const S: WideString; R: TRect; Flags, Flags2: Cardinal); override; procedure DrawText(ACanvas: TPersistent; Details: TThemedElementDetails; const S: WideString; R: TRect; Flags, Flags2: Cardinal); override;
function ContentRect(DC: HDC; Details: TThemedElementDetails; BoundingRect: TRect): TRect; override; function ContentRect(DC: HDC; Details: TThemedElementDetails; BoundingRect: TRect): TRect; override;
function HasTransparentParts(Details: TThemedElementDetails): Boolean; override; function HasTransparentParts(Details: TThemedElementDetails): Boolean; override;
@ -100,6 +89,7 @@ function TQtThemeServices.ContentRect(DC: HDC;
Details: TThemedElementDetails; BoundingRect: TRect): TRect; Details: TThemedElementDetails; BoundingRect: TRect): TRect;
begin begin
Result := BoundingRect; Result := BoundingRect;
InflateRect(Result, -1, -1);
end; end;
procedure TQtThemeServices.DrawEdge(DC: HDC; procedure TQtThemeServices.DrawEdge(DC: HDC;
@ -114,52 +104,60 @@ procedure TQtThemeServices.DrawElement(DC: HDC;
var var
Context: TQtDeviceContext absolute DC; Context: TQtDeviceContext absolute DC;
opt: QStyleOptionH; opt: QStyleOptionH;
ARect: QRectH; ARect: TRect;
Element: TQtDrawElement; Element: TQtDrawElement;
//QVariant: QVariantH;
Features: QStyleOptionButtonButtonFeatures; Features: QStyleOptionButtonButtonFeatures;
begin begin
{$IFDEF USE_QT_4_3}
if (Context <> nil) then if (Context <> nil) then
begin begin
ARect := CreateQRect(R); ARect := R;
Element := GetDrawElement(Details); Element := GetDrawElement(Details);
if (Element.DrawVariant = qdvControl) and (Element.ControlElement = QStyleCE_PushButton) then case Element.DrawVariant of
begin qdvControl:
opt := QStyleOptionButton_create(); begin
Features := 0; if (Element.ControlElement in [QStyleCE_PushButton, QStyleCE_RadioButton, QStyleCE_CheckBox]) then
if Details.Element = teToolBar then begin
Features := Features or QStyleOptionButtonFlat opt := QStyleOptionButton_create();
else Features := QStyleOptionButtonNone;
Features := Features or QStyleOptionButtonNone; if Details.Element = teToolBar then
Features := Features or QStyleOptionButtonFlat;
QStyleOptionButton_setFeatures(QStyleOptionButtonH(opt), Features);
end
else
opt := QStyleOptionComplex_create(LongInt(QStyleOptionVersion), LongInt(QStyleOptionSO_Default));
{ // TODO: wait for bindings QStyleOption_setState(opt, GetControlState(Details));
QStyleOption_setRect(opt, @ARect);
QStyleOptionButton_setButtonFeatures(opt, Features); QStyle_drawControl(Style, Element.ControlElement, opt, Context.Widget);
QStyleOption_setState(opt, GetControlState(Details)); QStyleOption_Destroy(opt);
QStyleOption_setRect(opt, ARect); end;
qdvComplexControl:
} begin
QStyle_drawControl(Style, Element.ControlElement, opt, Context.Widget); if Element.ComplexElement = QStyleCC_ToolButton then
QStyleOption_Destroy(opt); opt := QStyleOptionToolButton_create()
end else
else opt := QStyleOptionComplex_create(LongInt(QStyleOptionVersion), LongInt(QStyleOptionSO_Default));
if (Element.DrawVariant = qdvComplexControl) then
begin
if Element.ComplexElement = QStyleCC_ToolButton then
opt := QStyleOptionToolButton_create()
else
opt := QStyleOptionComplex_create(LongInt(QStyleOptionVersion), LongInt(QStyleOptionSO_Default));
{ // TODO: wait for bindings
QStyleOption_setState(opt, GetControlState(Details)); QStyleOption_setState(opt, GetControlState(Details));
QStyleOption_setRect(opt, ARect); QStyleOption_setRect(opt, @ARect);
} QStyle_drawComplexControl(Style, Element.ComplexElement, QStyleOptionComplexH(opt), Context.Widget);
QStyle_drawComplexControl(Style, Element.ComplexElement, QStyleOptionComplexH(opt), Context.Widget); QStyleOption_Destroy(opt);
QStyleOption_Destroy(opt); end;
qdvPrimitive:
begin
opt := QStyleOption_create(Integer(QStyleOptionVersion), Integer(QStyleOptionSO_Default));
QStyleOption_setState(opt, GetControlState(Details));
QStyleOption_setRect(opt, @ARect);
QStyle_drawPrimitive(Style, Element.PrimitiveElement, opt, Context.Widget);
QStyleOption_Destroy(opt);
end;
end; end;
QRect_destroy(ARect);
end; end;
{$ELSE}
inherited;
{$ENDIF}
end; end;
procedure TQtThemeServices.DrawIcon(DC: HDC; procedure TQtThemeServices.DrawIcon(DC: HDC;
@ -169,6 +167,19 @@ begin
end; end;
procedure TQtThemeServices.DrawText(ACanvas: TPersistent;
Details: TThemedElementDetails; const S: WideString; R: TRect; Flags,
Flags2: Cardinal);
begin
with TCanvas(ACanvas) do
begin
WidgetSet.SetBkMode(Handle, TRANSPARENT);
WidgetSet.DrawText(Handle, PChar(String(S)), Length(S), R, Flags);
if Brush.Style = bsSolid then;
WidgetSet.SetBkMode(Handle, OPAQUE);
end;
end;
function TQtThemeServices.HasTransparentParts(Details: TThemedElementDetails): Boolean; function TQtThemeServices.HasTransparentParts(Details: TThemedElementDetails): Boolean;
begin begin
Result := True; Result := True;
@ -180,18 +191,6 @@ begin
// ? // ?
end; end;
function TQtThemeServices.CreateQRect(R: TRect): QRectH;
begin
Result := QRect_create();
with R do
begin
QRect_setLeft(Result, Left);
QRect_setRight(Result, Right);
QRect_setTop(Result, Top);
QRect_setBottom(Result, Bottom);
end;
end;
function TQtThemeServices.GetControlState(Details: TThemedElementDetails): QStyleState; function TQtThemeServices.GetControlState(Details: TThemedElementDetails): QStyleState;
begin begin
{ {
@ -222,6 +221,18 @@ begin
QStyleState_ReadOnly QStyleState_ReadOnly
} }
Result := QStyleState_None; Result := QStyleState_None;
if not IsDisabled(Details) then
Result := Result or QStyleState_Enabled;
if IsHot(Details) then
Result := Result or QStyleState_MouseOver;
if IsPushed(Details) then
Result := Result or QStyleState_Sunken;
if IsChecked(Details) then
Result := Result or QStyleState_On;
end; end;
function TQtThemeServices.GetDrawElement(Details: TThemedElementDetails): TQtDrawElement; function TQtThemeServices.GetDrawElement(Details: TThemedElementDetails): TQtDrawElement;
@ -250,22 +261,42 @@ begin
Result.ComplexElement := QStyleCC_GroupBox; Result.ComplexElement := QStyleCC_GroupBox;
end; end;
end; end;
teHeader:
begin
case Details.Part of
HP_HEADERITEM:
begin
Result.DrawVariant := qdvControl;
Result.ControlElement := QStyleCE_HeaderSection;
end;
HP_HEADERITEMLEFT,
HP_HEADERITEMRIGHT:
begin
Result.DrawVariant := qdvControl;
{$IFDEF USE_QT_4_3}
Result.ControlElement := QStyleCE_HeaderEmptyArea;
{$ELSE}
Result.ControlElement := QStyleCE_HeaderSection;
{$ENDIF}
end;
HP_HEADERSORTARROW:
begin
Result.DrawVariant := qdvPrimitive;
Result.PrimitiveElement := QStylePE_IndicatorHeaderArrow;
end;
end;
end;
teToolBar: teToolBar:
begin begin
if Details.Part = TP_BUTTON then if Details.Part = TP_BUTTON then
begin begin
Result.DrawVariant := qdvComplexControl; Result.DrawVariant := qdvPrimitive;
Result.ComplexElement := QStyleCC_ToolButton; Result.PrimitiveElement := QStylePE_PanelButtonTool;
end; end;
end; end;
end; end;
end; end;
procedure TQtThemeServices.DrawText(DC: HDC; Details: TThemedElementDetails;
const S: WideString; R: TRect; Flags, Flags2: Cardinal);
begin
//
end;
end. end.

View File

@ -419,6 +419,7 @@ type
function IsDisabled(Details: TThemedElementDetails): Boolean; function IsDisabled(Details: TThemedElementDetails): Boolean;
function IsPushed(Details: TThemedElementDetails): Boolean; function IsPushed(Details: TThemedElementDetails): Boolean;
function IsHot(Details: TThemedElementDetails): Boolean; function IsHot(Details: TThemedElementDetails): Boolean;
function IsChecked(Details: TThemedElementDetails): Boolean;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
@ -1798,18 +1799,8 @@ begin
if Details.Element = teButton then if Details.Element = teButton then
begin begin
case Details.Part of case Details.Part of
BP_RADIOBUTTON: BP_RADIOBUTTON: ADrawFlags := DFCS_BUTTONRADIO;
begin BP_CHECKBOX: ADrawFlags := DFCS_BUTTONCHECK;
ADrawFlags := DFCS_BUTTONRADIO;
if Details.State >= RBS_CHECKEDNORMAL then
ADrawFlags := ADrawFlags or DFCS_CHECKED;
end;
BP_CHECKBOX:
begin
ADrawFlags := DFCS_BUTTONCHECK;
if Details.State >= CBS_CHECKEDNORMAL then
ADrawFlags := ADrawFlags or DFCS_CHECKED;
end;
end; end;
end; end;
@ -1820,6 +1811,9 @@ begin
if IsHot(Details) then if IsHot(Details) then
ADrawFlags := ADrawFlags or DFCS_HOT; ADrawFlags := ADrawFlags or DFCS_HOT;
if IsChecked(Details) then
ADrawFlags := ADrawFlags or DFCS_CHECKED;
WidgetSet.DrawFrameControl(DC, ARect, DFC_BUTTON, ADrawFlags); WidgetSet.DrawFrameControl(DC, ARect, DFC_BUTTON, ADrawFlags);
end; end;
teHeader: teHeader:
@ -1907,6 +1901,13 @@ begin
Result := Details.State in [2, 6]; Result := Details.State in [2, 6];
end; end;
function TThemeServices.IsChecked(Details: TThemedElementDetails): Boolean;
begin
Result := False;
if (Details.Element in [teButton]) then
Result := Details.State > 4;
end;
function TThemeServices.InitThemes: Boolean; function TThemeServices.InitThemes: Boolean;
begin begin
Result := False; Result := False;