Fixes component colors bug on Qt widgetset.

git-svn-id: trunk@10282 -
This commit is contained in:
sekelsenmat 2006-12-03 19:10:33 +00:00
parent 73b5502f8c
commit 47e5345d72
4 changed files with 177 additions and 17 deletions

View File

@ -59,7 +59,7 @@ type
procedure SlotResize; cdecl; procedure SlotResize; cdecl;
procedure SlotContextMenu; cdecl; procedure SlotContextMenu; cdecl;
public public
procedure SetColor(const Value: PQColor); procedure SetColor(const Value: PQColor); virtual;
procedure Update; procedure Update;
procedure Repaint; procedure Repaint;
procedure setWindowTitle(Str: PWideString); procedure setWindowTitle(Str: PWideString);
@ -83,6 +83,7 @@ type
TQtAbstractButton = class(TQtWidget) TQtAbstractButton = class(TQtWidget)
private private
public public
procedure SetColor(const Value: PQColor); override;
procedure SetText(text: PWideString); procedure SetText(text: PWideString);
procedure Text(retval: PWideString); procedure Text(retval: PWideString);
function isChecked: Boolean; function isChecked: Boolean;
@ -185,7 +186,7 @@ type
procedure setFrameShadow(p1: QFrameShadow); procedure setFrameShadow(p1: QFrameShadow);
end; end;
{ TQtAbstractSlider , inherited by TQtScrollBar, TQtTrackBar} { TQtAbstractSlider , inherited by TQtScrollBar, TQtTrackBar }
TQtAbstractSlider = class(TQtWidget) TQtAbstractSlider = class(TQtWidget)
private private
@ -209,14 +210,16 @@ type
procedure setValue(p1: Integer); virtual; procedure setValue(p1: Integer); virtual;
end; end;
{ TQtScrollBar } { TQtScrollBar }
TQtScrollBar = class(TQtAbstractSlider) TQtScrollBar = class(TQtAbstractSlider)
private private
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override;
end; end;
{ TQtTrackBar } { TQtTrackBar }
TQtTrackBar = class(TQtAbstractSlider) TQtTrackBar = class(TQtAbstractSlider)
private private
public public
@ -232,6 +235,7 @@ type
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override;
destructor Destroy; override; destructor Destroy; override;
procedure SetColor(const Value: PQColor); override;
end; end;
{ TQtTextEdit } { TQtTextEdit }
@ -241,6 +245,7 @@ type
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override;
destructor Destroy; override; destructor Destroy; override;
procedure SetColor(const Value: PQColor); override;
end; end;
{ TQtTabWidget } { TQtTabWidget }
@ -261,6 +266,7 @@ type
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); override;
destructor Destroy; override; destructor Destroy; override;
procedure SetColor(const Value: PQColor); override;
function currentIndex: Integer; function currentIndex: Integer;
procedure setCurrentIndex(index: Integer); procedure setCurrentIndex(index: Integer);
public public
@ -785,7 +791,7 @@ end;
Params: QColorH Params: QColorH
Returns: Nothing Returns: Nothing
Schedules a paint event for processing when Qt returns to the main event loop Changes the color of a widget
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TQtWidget.SetColor(const Value: PQColor); procedure TQtWidget.SetColor(const Value: PQColor);
var var
@ -794,8 +800,6 @@ begin
Palette:=QPalette_create(QWidget_palette(Widget)); Palette:=QPalette_create(QWidget_palette(Widget));
// Set the palette for all color groups (active, inactive, disabled) // Set the palette for all color groups (active, inactive, disabled)
QPalette_setColor(Palette,QPaletteWindow,Value); QPalette_setColor(Palette,QPaletteWindow,Value);
QPalette_setColor(Palette,QPaletteButton,Value);
QPalette_setColor(Palette,QPaletteBase,Value);
// Set the Palette // Set the Palette
QWidget_setPalette(Widget,Palette); QWidget_setPalette(Widget,Palette);
QPalette_destroy(Palette); QPalette_destroy(Palette);
@ -1218,6 +1222,25 @@ end;
{ TQtAbstractButton } { TQtAbstractButton }
{------------------------------------------------------------------------------
Function: TQtAbstractButton.SetColor
Params: QColorH
Returns: Nothing
Changes the color of a widget
------------------------------------------------------------------------------}
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);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtAbstractButton.SetText Function: TQtAbstractButton.SetText
Params: None Params: None
@ -2131,7 +2154,7 @@ end;
{ TQtLineEdit } { TQtLineEdit }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtLineEdit.Destroy Function: TQtLineEdit.Create
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -2173,6 +2196,25 @@ begin
inherited Destroy; inherited Destroy;
end; end;
{------------------------------------------------------------------------------
Function: TQtLineEdit.SetColor
Params: QColorH
Returns: Nothing
Changes the color of a widget
------------------------------------------------------------------------------}
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);
end;
{ TQtTextEdit } { TQtTextEdit }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -2225,6 +2267,25 @@ begin
inherited Destroy; inherited Destroy;
end; end;
{------------------------------------------------------------------------------
Function: TQtTextEdit.SetColor
Params: QColorH
Returns: Nothing
Changes the color of a widget
------------------------------------------------------------------------------}
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);
end;
{ TQtTabWidget } { TQtTabWidget }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -2341,6 +2402,11 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TQtComboBox.SetColor(const Value: PQColor);
begin
inherited SetColor(Value);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtComboBox.currentIndex Function: TQtComboBox.currentIndex
Params: None Params: None

View File

@ -1098,7 +1098,7 @@ begin
COLOR_ACTIVECAPTION : Result:=GetColor(QPaletteActive, QPaletteBase); COLOR_ACTIVECAPTION : Result:=GetColor(QPaletteActive, QPaletteBase);
COLOR_INACTIVECAPTION : Result:=GetColor(QPaletteInActive, QPaletteBase); COLOR_INACTIVECAPTION : Result:=GetColor(QPaletteInActive, QPaletteBase);
COLOR_MENU : Result:=GetColor(QPaletteActive, QPaletteWindow); COLOR_MENU : Result:=GetColor(QPaletteActive, QPaletteWindow);
COLOR_WINDOW : Result:=GetColor(QPaletteActive, QPaletteWindow); COLOR_WINDOW : Result:=GetColor(QPaletteInActive, QPaletteBase);
COLOR_WINDOWFRAME : Result:=GetColor(QPaletteActive, QPaletteWindow); COLOR_WINDOWFRAME : Result:=GetColor(QPaletteActive, QPaletteWindow);
COLOR_MENUTEXT : Result:=GetColor(QPaletteActive, QPaletteWindowText); COLOR_MENUTEXT : Result:=GetColor(QPaletteActive, QPaletteWindowText);
COLOR_WINDOWTEXT : Result:=GetColor(QPaletteActive, QPaletteWindowText); COLOR_WINDOWTEXT : Result:=GetColor(QPaletteActive, QPaletteWindowText);

View File

@ -30,7 +30,7 @@ uses
// Libs // Libs
qt4, qtwidgets, qt4, qtwidgets,
// LCL // LCL
SysUtils, Controls, LCLType, Forms, InterfaceBase, Buttons, LMessages, SysUtils, Controls, LCLType, Forms, InterfaceBase, Buttons, LMessages, Graphics,
// Widgetset // Widgetset
WSButtons, WSLCLClasses; WSButtons, WSLCLClasses;
@ -50,6 +50,7 @@ type
class procedure SetText(const AWinControl: TWinControl; const AText: String); override; class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
// class procedure GetPreferredSize(const AWinControl: TWinControl; // class procedure GetPreferredSize(const AWinControl: TWinControl;
// var PreferredWidth, PreferredHeight: integer); override; // var PreferredWidth, PreferredHeight: integer); override;
class procedure SetColor(const AWinControl: TWinControl); override;
end; end;
{ TQtWSBitBtn } { TQtWSBitBtn }
@ -66,6 +67,7 @@ type
class procedure SetText(const AWinControl: TWinControl; const AText: String); override; class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
// class procedure GetPreferredSize(const AWinControl: TWinControl; // class procedure GetPreferredSize(const AWinControl: TWinControl;
// var PreferredWidth, PreferredHeight: integer); override; // var PreferredWidth, PreferredHeight: integer); override;
class procedure SetColor(const AWinControl: TWinControl); override;
end; end;
{ TQtWSSpeedButton } { TQtWSSpeedButton }
@ -166,6 +168,35 @@ begin
TQtAbstractButton(AWinControl.Handle).SetText(@Str); TQtAbstractButton(AWinControl.Handle).SetText(@Str);
end; end;
{------------------------------------------------------------------------------
Method: TQtWSButton.SetColor
Params: AWinControl - the calling object
Returns: Nothing
Sets the color of the widget.
------------------------------------------------------------------------------}
class procedure TQtWSButton.SetColor(const AWinControl: TWinControl);
var
QColor: TQColor;
Color: TColor;
begin
if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit;
if AWinControl.Color = CLR_INVALID then exit;
// Get the color numeric value (system colors are mapped to numeric colors depending on the widget style)
Color:=ColorToRGB(AWinControl.Color);
// Fill QColor
QColor_setRgb(@QColor,Red(Color),Green(Color),Blue(Color));
// Set color of the widget to QColor
TQtAbstractButton(AWinControl.Handle).SetColor(@QColor);
end;
{ TQtWSBitBtn } { TQtWSBitBtn }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -252,6 +283,35 @@ begin
TQtAbstractButton(AWinControl.Handle).SetText(@Str); TQtAbstractButton(AWinControl.Handle).SetText(@Str);
end; end;
{------------------------------------------------------------------------------
Method: TQtWSBitBtn.SetColor
Params: AWinControl - the calling object
Returns: Nothing
Sets the color of the widget.
------------------------------------------------------------------------------}
class procedure TQtWSBitBtn.SetColor(const AWinControl: TWinControl);
var
QColor: TQColor;
Color: TColor;
begin
if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit;
if AWinControl.Color = CLR_INVALID then exit;
// Get the color numeric value (system colors are mapped to numeric colors depending on the widget style)
Color:=ColorToRGB(AWinControl.Color);
// Fill QColor
QColor_setRgb(@QColor,Red(Color),Green(Color),Blue(Color));
// Set color of the widget to QColor
TQtAbstractButton(AWinControl.Handle).SetColor(@QColor);
end;
initialization initialization
//////////////////////////////////////////////////// ////////////////////////////////////////////////////

View File

@ -30,9 +30,9 @@ uses
// Bindings // Bindings
qt4, qtprivate, qtwidgets, qt4, qtprivate, qtwidgets,
// LCL // LCL
Classes, StdCtrls, Controls, Graphics, Forms, SysUtils, InterfaceBase, Classes, StdCtrls, Controls, Graphics, Forms, SysUtils, InterfaceBase, LCLType, LCLIntf,
// Widgetset // Widgetset
WSStdCtrls, WSLCLClasses, LCLType; WSStdCtrls, WSLCLClasses;
type type
@ -161,6 +161,7 @@ type
class procedure GetPreferredSize(const AWinControl: TWinControl; class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer); override;} var PreferredWidth, PreferredHeight: integer); override;}
class procedure SetColor(const AWinControl: TWinControl); override;
end; end;
{ TQtWSCustomMemo } { TQtWSCustomMemo }
@ -681,6 +682,8 @@ class function TQtWSCustomEdit.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; const AParams: TCreateParams): HWND;
var var
QtLineEdit: TQtLineEdit; QtLineEdit: TQtLineEdit;
QColor: TQColor;
Color: TColor;
begin begin
QtLineEdit := TQtLineEdit.Create(AWinControl, AParams); QtLineEdit := TQtLineEdit.Create(AWinControl, AParams);
@ -727,6 +730,35 @@ begin
QLineEdit_setText(QLineEditH(TQtWidget(AWinControl.Handle).Widget), @AString); QLineEdit_setText(QLineEditH(TQtWidget(AWinControl.Handle).Widget), @AString);
end; end;
{------------------------------------------------------------------------------
Method: TQtWSCustomEdit.SetColor
Params: AWinControl - the calling object
Returns: Nothing
Sets the color of the widget.
------------------------------------------------------------------------------}
class procedure TQtWSCustomEdit.SetColor(const AWinControl: TWinControl);
var
QColor: TQColor;
Color: TColor;
begin
if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit;
if AWinControl.Color = CLR_INVALID then exit;
// Get the color numeric value (system colors are mapped to numeric colors depending on the widget style)
Color:=ColorToRGB(AWinControl.Color);
// Fill QColor
QColor_setRgb(@QColor,Red(Color),Green(Color),Blue(Color));
// Set color of the widget to QColor
TQtLineEdit(AWinControl.Handle).SetColor(@QColor);
end;
{ TQtWSStaticText } { TQtWSStaticText }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -803,7 +835,7 @@ end;
{ TQtWSCustomCheckBox } { TQtWSCustomCheckBox }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomEdit.RetrieveState Method: TQtWSCustomCheckBox.RetrieveState
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -818,7 +850,7 @@ begin
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomEdit.SetShortCut Method: TQtWSCustomCheckBox.SetShortCut
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -829,7 +861,7 @@ begin
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomEdit.SetState Method: TQtWSCustomCheckBox.SetState
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -844,7 +876,7 @@ begin
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomEdit.GetText Method: TQtWSCustomCheckBox.GetText
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -860,7 +892,7 @@ begin
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomEdit.SetText Method: TQtWSCustomCheckBox.SetText
Params: None Params: None
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -1085,6 +1117,8 @@ var
QtComboBox: TQtComboBox; QtComboBox: TQtComboBox;
Method: TMethod; Method: TMethod;
Hook : QObject_hookH; Hook : QObject_hookH;
QColor: TQColor;
Color: TColor;
begin begin
QtComboBox := TQtComboBox.Create(AWinControl, AParams); QtComboBox := TQtComboBox.Create(AWinControl, AParams);