Patch from zeljko. Font, Text Color & Color can be changed for all TWinControl descendants on Qt.

git-svn-id: trunk@11402 -
This commit is contained in:
sekelsenmat 2007-06-29 15:31:49 +00:00
parent bdecf2b5b9
commit 43c999f092
2 changed files with 133 additions and 46 deletions

View File

@ -83,6 +83,7 @@ type
procedure SlotContextMenu; cdecl;
public
procedure SetColor(const Value: PQColor); virtual;
procedure SetTextColor(const Value: PQColor); virtual;
procedure SetCursor(const ACursor: QCursorH); virtual;
procedure Update;
procedure Repaint;
@ -105,6 +106,20 @@ type
property PaintData: TPaintData read FPaintData write FPaintData;
end;
{ TQtFrame }
TQtFrame = class(TQtWidget)
private
protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public
destructor Destroy; override;
procedure setFrameStyle(p1: Integer);
procedure setFrameShape(p1: QFrameShape);
procedure setFrameShadow(p1: QFrameShadow);
procedure setTextColor(const Value: PQColor); override;
end;
{ TQtAbstractButton }
TQtAbstractButton = class(TQtWidget)
@ -160,7 +175,7 @@ type
{ TQtStaticText }
TQtStaticText = class(TQtWidget)
TQtStaticText = class(TQtFrame)
private
protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
@ -221,20 +236,6 @@ type
BoxLayout: QGridLayoutH;
end;
{ TQtFrame }
TQtFrame = class(TQtWidget)
private
protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public
destructor Destroy; override;
procedure setFrameStyle(p1: Integer);
procedure setFrameShape(p1: QFrameShape);
procedure setFrameShadow(p1: QFrameShadow);
end;
{ TQtAbstractSlider , inherited by TQtScrollBar, TQtTrackBar }
TQtAbstractSlider = class(TQtWidget)
@ -418,6 +419,7 @@ type
procedure setCornerWidget(AWidget: TQtWidget);
procedure setHorizontalScrollBar(AScrollBar: TQtScrollBar);
procedure setScrollStyle(AScrollStyle: TScrollStyle);
procedure setTextColor(const Value: PQColor); override;
procedure setVerticalScrollBar(AScrollBar: TQtScrollBar);
procedure setViewPort(AWidget: TQtWidget);
end;
@ -1269,12 +1271,33 @@ procedure TQtWidget.SetColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette:=QPalette_create(QWidget_palette(Widget));
// Set the palette for all color groups (active, inactive, disabled)
QPalette_setColor(Palette,QPaletteWindow,Value);
// Set the Palette
QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette);
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteWindow, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
{------------------------------------------------------------------------------
Function: TQtWidget.SetTextColor
Params: QColorH
Returns: Nothing
Changes the text color of a widget
------------------------------------------------------------------------------}
procedure TQtWidget.SetTextColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteText, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
procedure TQtWidget.SetCursor(const ACursor: QCursorH);
@ -1767,12 +1790,13 @@ procedure TQtAbstractButton.SetColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette:=QPalette_create(QWidget_palette(Widget));
// Set the palette for all color groups (active, inactive, disabled)
QPalette_setColor(Palette,QPaletteButton,Value);
// Set the Palette
QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette);
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteButton, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
{------------------------------------------------------------------------------
@ -2181,6 +2205,7 @@ begin
Parent := TQtWidget(LCLObject.Parent.Handle).GetContainerWidget;
Result := QLabel_create(Parent);
QWidget_setAutoFillBackground(Result, True);
end;
{------------------------------------------------------------------------------
@ -2488,7 +2513,6 @@ begin
inherited Destroy;
end;
{ TQtFrame }
function TQtFrame.CreateWidget(const AParams: TCreateParams): QWidgetH;
@ -2501,6 +2525,7 @@ begin
{$endif}
Parent := TQtWidget(LCLObject.Parent.Handle).GetContainerWidget;
Result := QFrame_create(Parent);
QWidget_setAutoFillBackground(Result, True);
end;
{------------------------------------------------------------------------------
@ -2550,6 +2575,24 @@ begin
QFrame_setFrameShadow(QFrameH(Widget), p1);
end;
{------------------------------------------------------------------------------
Function: TQtFrame.setTextColor
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
procedure TQtFrame.setTextColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteForeground, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
function TQtAbstractSlider.CreateWidget(const AParams: TCreateParams
): QWidgetH;
var
@ -2993,12 +3036,13 @@ procedure TQtLineEdit.SetColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette:=QPalette_create(QWidget_palette(Widget));
// Set the palette for all color groups (active, inactive, disabled)
QPalette_setColor(Palette,QPaletteBase,Value);
// Set the Palette
QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette);
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteBase, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
{------------------------------------------------------------------------------
@ -3071,12 +3115,13 @@ procedure TQtTextEdit.SetColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette:=QPalette_create(QWidget_palette(Widget));
// Set the palette for all color groups (active, inactive, disabled)
QPalette_setColor(Palette,QPaletteBase,Value);
// Set the Palette
QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette);
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteBase, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
procedure TQtTextEdit.SetAlignment(const AAlignment: TAlignment);
@ -4257,10 +4302,13 @@ procedure TQtAbstractScrollArea.setColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette:=QPalette_create(QWidget_palette(Widget));
QPalette_setColor(Palette,QPaletteBase,Value);
QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette);
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteBase, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
{------------------------------------------------------------------------------
@ -4280,6 +4328,24 @@ begin
QAbstractScrollArea_setCornerWidget(QAbstractScrollAreaH(Widget), NiL);
end;
{------------------------------------------------------------------------------
Function: TQtAbstractScrollArea.setTextColor
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
procedure TQtAbstractScrollArea.setTextColor(const Value: PQColor);
var
Palette: QPaletteH;
begin
Palette := QPalette_create(QWidget_palette(Widget));
try
QPalette_setColor(Palette, QPaletteText, Value);
QWidget_setPalette(Widget, Palette);
finally
QPalette_destroy(Palette);
end;
end;
{------------------------------------------------------------------------------
Function: TQtAbstractScrollArea.setHorizontalScrollbar
Params: None

View File

@ -33,7 +33,7 @@ uses
{$else}
qt4,
{$endif}
qtwidgets,
qtwidgets, qtobjects,
// LCL
SysUtils, Controls, LCLType, LCLProc, Forms, Graphics,
// Widgetset
@ -75,6 +75,7 @@ type
class procedure ShowHide(const AWinControl: TWinControl); override; //TODO: rename to SetVisible(control, visible)
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetCursor(const AWinControl: TWinControl; const ACursor: HCursor); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
// class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
// class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
@ -85,7 +86,6 @@ type
class procedure SetChildZPosition(const AWinControl, AChild: TWinControl;
const AOldPos, ANewPos: Integer;
const AChildren: TFPList); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure ConstraintsChange(const AWinControl: TWinControl); override;}
end;
@ -400,6 +400,27 @@ begin
TQtWidget(AWinControl.Handle).SetCursor(QCursorH(ACursor));
end;
{------------------------------------------------------------------------------
Method: TQtWSWinControl.SetFont
Params: AWinControl - the calling object, AFont - object font
Returns: Nothing
Sets the font of the widget.
------------------------------------------------------------------------------}
class procedure TQtWSWinControl.SetFont(const AWinControl: TWinControl; const AFont: TFont);
var
QColor: TQColor;
Color: TColor;
begin
QWidget_setFont(TQtWidget(AWinControl.Handle).Widget, TQtFont(AFont.Handle).Widget);
if AFont.Color = CLR_INVALID then exit;
Color := ColorToRGB(AFont.Color);
QColor_setRgb(@QColor,Red(Color),Green(Color),Blue(Color));
TQtWidget(AWinControl.Handle).SetTextColor(@QColor);
end;
initialization
////////////////////////////////////////////////////