⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqofficecolorpanel.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{******************************************************************************}
{* WARNING:  JEDI VCL To CLX Converter generated unit.                        *}
{*           Manual modifications will be lost on next release.               *}
{******************************************************************************}

{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvOfficeColorPanel.PAS, released on 2004-02-26.

The Initial Developer of the Original Code is dejoy [dejoy att ynl dott gov dott cn]
Portions created by Peter Th鰎nqvist are Copyright (C) 2004 Peter Th鰎nqvist.
All Rights Reserved.

Contributor(s):

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Description:
  Color panel for the @link(TJvOfficeColorButton) component

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQOfficeColorPanel.pas,v 1.26 2004/09/11 21:07:03 asnepvangers Exp $

unit JvQOfficeColorPanel;

{$I jvcl.inc}

interface

uses
  SysUtils, Classes,
  QWindows, QMessages, QGraphics, QControls, QForms, QButtons, QExtCtrls, QDialogs, 
  Qt, 
  JvQComponent, JvQSpeedButton;

const
  MaxColorButtonNumber = 40;

  Tag_AutoCaption = 0;
  Tag_OtherCaption = 1;
  Tag_AutoHint = 2;
  Tag_OtherHint = 3;

  MinButtonHeight = 22;
  MinButtonWidth = 23;
  MinColorSize = 18;
  MinColorSpace = 0;
  MinColorSpaceTop = 4;
  MinColorSpaceBottom = 4;
  MinTopMargin = 2;
  MinBottomMargin = 4;
  MinHorizontalMargin = 7;

  Tag_ButtonHeight = 0;
  Tag_ButtonWidth = 1;
  Tag_ColorSize = 2;
  Tag_ColorSpace = 3;
  Tag_ColorSpaceTop = 4;
  Tag_ColorSpaceBottom = 5;
  Tag_TopMargin = 6;
  Tag_BottomMargin = 7;
  Tag_HorizontalMargin = 8;

  LineColorButtonCount = 8;

  SubColorButtonColors: array [0..MaxColorButtonNumber - 1] of TColor =
   ($000000, $003399, $003333, $003300, $663300, $800000, $993333, $333333,
    $000080, $0066FF, $008080, $008000, $808000, $FF0000, $996666, $808080,
    $0000FF, $0099FF, $00CC99, $669933, $CCCC33, $FF6633, $800080, $999999,
    $FF00FF, $00CCFF, $00FFFF, $00FF00, $FFFF00, $FFCC00, $663399, $C0C0C0,
    $CC99FF, $99CCFF, $99FFFF, $CCFFCC, $FFFFCC, $FFCC99, $FF99CC, $FFFFFF);

type
  TJvClickColorButtonType =
    (cbctColorsButton, cbctAutoButton, cbctOtherButton, cbctNone);
  TJvPropertiesChangedEvent = procedure(Sender: TObject; PropName: string) of object;

  TJvColorSpeedButton = class(TJvSpeedButton)
  private
    FButtonColor: TColor;
    procedure SetButtonColor(const Value: TColor);
  public
    constructor Create(AOwner: TComponent); override;
    property ButtonColor: TColor read FButtonColor write SetButtonColor;
  end;

  TJvSubColorButton = class(TJvColorSpeedButton)
  private
    procedure SetEdgeWidth(const Value: Integer);
  protected
    FEdgeWidth: Integer;
    procedure Paint; override;
    function GetEdgeWidth: Integer; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    property Canvas;
    property EdgeWidth: Integer read GetEdgeWidth write SetEdgeWidth;
  end;

  // (ahuser) TJvColorDialog is not registered as component
  TJvOfficeColorDialog = class(TColorDialog)
  published
    property OnShow;
    property OnClose;
  end;

  TJvOfficeColorPanelProperties = class(TPersistent)
  private
    FShowAutoButton: Boolean;
    FShowOtherButton: Boolean;
    FTopMargin: Integer;
    FColorSpaceBottom: Integer;
    FHorizontalMargin: Integer;
    FColorSpace: Integer;
    FColorSpaceTop: Integer;
    FButtonHeight: Integer;
    FColorSize: Integer;
    FBottomMargin: Integer;

    FAutoCaption: string;
    FOtherCaption: string;
    FAutoHint: string;
    FOtherHint: string;

    FOnPropertiesChanged: TJvPropertiesChangedEvent;
    FAutoColor: TColor;
    FShowColorHint: Boolean;
    FRightClickSelect: Boolean;
    FSelectIfPopup: Boolean;
    procedure SetShowAutoButton(const Value: Boolean);
    procedure SetShowOtherButton(const Value: Boolean);
    procedure SetMeasure(const Index, Value: Integer);
    function GetStringValue(const Index: Integer): string;
    procedure SetStringValue(const Index: Integer; const Value: string);
    procedure SetAutoColor(const Value: TColor);
    procedure SetShowColorHint(const Value: Boolean);
    procedure SetRightClickSelect(const Value: Boolean);
    procedure SetSelectIfPopup(const Value: Boolean);
  protected
    procedure Changed(PropName: string); virtual;
    procedure CreateDefaultText; virtual;
  public
    constructor Create; virtual;
    procedure Assign(Source: TPersistent); override;
    property AutoColor: TColor read FAutoColor write SetAutoColor default clDefault;
    property OnPropertiesChanged: TJvPropertiesChangedEvent read FOnPropertiesChanged write FOnPropertiesChanged;
  published
    property ShowAutoButton: Boolean read FShowAutoButton write SetShowAutoButton default True;
    property ShowOtherButton: Boolean read FShowOtherButton write SetShowOtherButton default True;
    property ShowColorHint: Boolean read FShowColorHint write SetShowColorHint default True;

    property TopMargin: Integer index Tag_TopMargin read FTopMargin write SetMeasure
      default MinTopMargin;
    property BottomMargin: Integer index Tag_BottomMargin read FBottomMargin write SetMeasure
      default MinBottomMargin;
    property HorizontalMargin: Integer index Tag_HorizontalMargin read FHorizontalMargin write SetMeasure
      default MinHorizontalMargin;
    property ColorSpace: Integer index Tag_ColorSpace read FColorSpace write SetMeasure
       default MinColorSpace;
    property ColorSpaceTop: Integer index Tag_ColorSpaceTop read FColorSpaceTop write SetMeasure
      default MinColorSpaceTop;
    property ColorSpaceBottom: Integer index Tag_ColorSpaceBottom read FColorSpaceBottom write SetMeasure
      default MinColorSpaceBottom;
    property ColorSize: Integer index Tag_ColorSize read FColorSize write SetMeasure
      default MinColorSize;
    property ButtonHeight: Integer index Tag_ButtonHeight read FButtonHeight write SetMeasure
      default MinButtonHeight;
    property AutoCaption: string index Tag_AutoCaption read GetStringValue write SetStringValue;
    property OtherCaption: string index Tag_OtherCaption read GetStringValue write SetStringValue;
    property AutoHint: string index Tag_AutoHint read GetStringValue write SetStringValue;
    property OtherHint: string index Tag_OtherHint read GetStringValue write SetStringValue;

    property RightClickSelect: Boolean read FRightClickSelect write SetRightClickSelect default False;
    property SelectIfPopup: Boolean read FSelectIfPopup write SetSelectIfPopup default False;
  end;

  TJvCustomOfficeColorPanel = class(TJvCustomPanel)
  private
    FColorButtons: array [0..MaxColorButtonNumber - 1] of TJvSubColorButton;
    FAutoButton: TJvSubColorButton;
    FOtherButton: TJvColorSpeedButton;
    FProperties: TJvOfficeColorPanelProperties;
    FOwner: TControl;
    FColorDialog: TJvOfficeColorDialog;
    FSelectedColor: TColor;
    FWordStyle: Boolean;
    FFlat: Boolean;
    FInited: Boolean;
    FOnColorChange: TNotifyEvent;
    FOnColorButtonClick: TNotifyEvent;
    FClickColorButton: TJvClickColorButtonType; 
    procedure ColorButtonClick(Sender: TObject);
    procedure RedirectToColorButtonClick(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    procedure SetFlat(const Value: Boolean);
    procedure SetSelectedColor(const Value: TColor);
    function GetCustomColors: TStrings;
    procedure SetCustomColors(const Value: TStrings);
    function GetProperties: TJvOfficeColorPanelProperties;
    procedure SetProperties(const Value: TJvOfficeColorPanelProperties);
  protected  
    procedure InitWidget; override; 
    procedure Resize; override;
    procedure Paint; override;
    procedure ShowHintChanged; override;
    procedure PropertiesChanged(Sender: TObject; PropName: string); virtual;
    procedure SetWordStyle(const Value: Boolean);
    procedure MakeColorButtons;
    procedure AdjustColorButtons;
    procedure SetEnabled( const  Value: Boolean); override;

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure SetButton(Button: TControl);
    property ColorDialog: TJvOfficeColorDialog read FColorDialog write FColorDialog;
    property SelectedColor: TColor read FSelectedColor write SetSelectedColor default clBlack;

    property ClickColorButton: TJvClickColorButtonType read FClickColorButton;
    property Color: TColor read FSelectedColor write SetSelectedColor default clBlack;
    property Flat: Boolean read FFlat write SetFlat default True;
    property CustomColors: TStrings read GetCustomColors write SetCustomColors;
    property Properties: TJvOfficeColorPanelProperties read GetProperties write SetProperties; 
    property OnColorChange: TNotifyEvent read FOnColorChange write FOnColorChange;
    property OnColorButtonClick: TNotifyEvent read FOnColorButtonClick write FOnColorButtonClick;
  end;

  TJvOfficeColorPanel = class(TJvCustomOfficeColorPanel)
  published
    property Flat;
    property Color;
    property CustomColors; 

    property Align;
    property Anchors;
    property Constraints;
    property DragMode;
    property Enabled;
    property Font;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnConstrainedResize;
    property OnContextPopup;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnStartDrag;

    property Properties;
    property OnColorChange;
    property OnColorButtonClick;
    property OnClick;
  end;

implementation

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  JvQJCLUtils, JvQResources;

const
  cAutoCaption = 'AutoCaption';
  cAutoColor = 'AutoColor';
  cAutoHint = 'AutoHint';
  cOtherCaption = 'OtherCaption';
  cOtherHint = 'OtherHint';
  cShowAutoButton = 'ShowAutoButton';
  cShowColorHint = 'ShowColorHint';
  cShowOtherButton = 'ShowOtherButton';

//=== { TJvOfficeColorPanelProperties } ======================================

constructor TJvOfficeColorPanelProperties.Create;
begin
  inherited Create;
  FShowAutoButton := True;
  FShowOtherButton := True;
  FShowColorHint := True;
  FAutoColor := clDefault;

  FHorizontalMargin := MinHorizontalMargin;
  FTopMargin := MinTopMargin;
  FColorSpace := MinColorSize;
  FColorSpaceTop := MinColorSpaceTop;
  FColorSize := MinColorSize;
  FButtonHeight := MinButtonHeight;
  FColorSpaceBottom := MinColorSpaceBottom;
  FBottomMargin := MinBottomMargin;

  FRightClickSelect := False;
  FSelectIfPopup := False;

  CreateDefaultText;
end;

procedure TJvOfficeColorPanelProperties.Assign(Source: TPersistent);
begin
  if Source is TJvOfficeColorPanelProperties then
    with TJvOfficeColorPanelProperties(Source) do
    begin
      Self.FShowAutoButton := ShowAutoButton;
      Self.FShowOtherButton := ShowOtherButton;
      Self.FShowColorHint := ShowColorHint;
      Self.FTopMargin := TopMargin;
      Self.FColorSpaceBottom := ColorSpaceBottom;
      Self.FHorizontalMargin := HorizontalMargin;
      Self.FColorSpace := ColorSpace;
      Self.FColorSpaceTop := ColorSpaceTop;
      Self.FButtonHeight := ButtonHeight;
      Self.FColorSize := ColorSize;
      Self.FBottomMargin := BottomMargin;

      Self.FAutoCaption := AutoCaption;
      Self.FOtherCaption := OtherCaption;
      Self.FAutoHint := AutoHint;
      Self.FOtherHint := OtherHint;
      Self.FAutoColor := AutoColor;

      Self.FRightClickSelect :=  RightClickSelect;
      Self.FSelectIfPopup := SelectIfPopup;
    end
  else
    inherited Assign(Source);
end;

procedure TJvOfficeColorPanelProperties.Changed(PropName: string);
begin
  if Assigned(FOnPropertiesChanged) then
    FOnPropertiesChanged(Self, PropName);
end;

procedure TJvOfficeColorPanelProperties.CreateDefaultText;
begin
  FAutoCaption := RsAutoCaption;
  FOtherCaption := RsOtherColorCaption;
end;

function TJvOfficeColorPanelProperties.GetStringValue(const Index: Integer): string;
begin
  case Index of
    Tag_AutoCaption:
      Result := FAutoCaption;
    Tag_OtherCaption:
      Result := FOtherCaption;
    Tag_AutoHint:
      Result := FAutoHint;
    Tag_OtherHint:
      Result := FOtherHint;
  end;
end;

procedure TJvOfficeColorPanelProperties.SetAutoColor(const Value: TColor);
begin
  if FAutoColor<>Value then
  begin
    FAutoColor := Value;
    Changed(cAutoColor);
  end;
end;

procedure TJvOfficeColorPanelProperties.SetMeasure(const Index, Value: Integer);
var
  MeasureItem: PInteger;
  MeasureConst: Integer;
  LName: string;
begin
  case Index of
    Tag_TopMargin:
      begin
        MeasureItem := @FTopMargin;
        MeasureConst := MinTopMargin;
        LName := 'TopMargin';
      end;
    Tag_BottomMargin:
      begin
        MeasureItem := @FBottomMargin;
        MeasureConst := MinBottomMargin;
        LName := 'BottomMargin';
      end;
    Tag_HorizontalMargin:
      begin
        MeasureItem := @FHorizontalMargin;
        MeasureConst := MinHorizontalMargin;
        LName := 'HorizontalMargin';
      end;
    Tag_ColorSpace:
      begin
        MeasureItem := @FColorSpace;
        MeasureConst := MinColorSpace;
        LName := 'ColorSpace';
      end;
    Tag_ColorSpaceTop:
      begin
        MeasureItem := @FColorSpaceTop;
        MeasureConst := MinColorSpaceTop;
        LName := 'ColorSpaceTop';
      end;
    Tag_ColorSpaceBottom:
      begin
        MeasureItem := @FColorSpaceBottom;
        MeasureConst := MinColorSpaceBottom;
        LName := 'ColorSpaceBottom';
      end;
    Tag_ColorSize:
      begin
        MeasureItem := @FColorSize;
        MeasureConst := MinColorSize;
        LName := 'ColorSize';
      end;
    Tag_ButtonHeight:
      begin
        MeasureItem := @FButtonHeight;
        MeasureConst := MinButtonHeight;
        LName := 'ButtonHeight';
      end;
  else
    Exit;
  end;
  if MeasureItem^ = Value then
    Exit;

  MeasureItem^ := Value;
  if MeasureItem^ < MeasureConst then
    MeasureItem^ := MeasureConst;
  Changed(LName);
end;

procedure TJvOfficeColorPanelProperties.SetShowAutoButton(const Value: Boolean);
begin
  if FShowAutoButton <> Value then
  begin
    FShowAutoButton := Value;
    Changed(cShowAutoButton);
  end;
end;

procedure TJvOfficeColorPanelProperties.SetShowColorHint(const Value: Boolean);
begin
  if FShowColorHint <> Value then
  begin
    FShowColorHint := Value;
    Changed(cShowColorHint);
  end;
end;

procedure TJvOfficeColorPanelProperties.SetShowOtherButton(const Value: Boolean);
begin
  if FShowOtherButton <> Value then
  begin
    FShowOtherButton := Value;
    Changed(cShowOtherButton);
  end;
end;

procedure TJvOfficeColorPanelProperties.SetStringValue(const Index: Integer;
  const Value: string);
begin
  case Index of
    Tag_AutoCaption:
      if FAutoCaption <> Value then
      begin
        FAutoCaption := Value;
        Changed(cAutoCaption);
      end;
    Tag_OtherCaption:
      if FOtherCaption <> Value then
      begin
        FOtherCaption := Value;
        Changed(cOtherCaption);
      end;
    Tag_AutoHint:
      if FAutoHint <> Value then
      begin
        FAutoHint := Value;
        Changed(cAutoHint);
      end;
    Tag_OtherHint:
      if FAutoHint <> Value then
      begin
        FOtherHint := Value;
        Changed(cOtherHint);
      end;
  end;
end;

procedure TJvOfficeColorPanelProperties.SetRightClickSelect(
  const Value: Boolean);
begin
  FRightClickSelect := Value;
  Changed('RightClickSelect');
end;

procedure TJvOfficeColorPanelProperties.SetSelectIfPopup(
  const Value: Boolean);
begin
  FSelectIfPopup := Value;
  Changed('SelectIfPopup');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -