Ver Fonte

New update to test/test_bcnumerickeyboard

lainz há 9 anos atrás
pai
commit
abe2cb190a
2 ficheiros alterados com 58 adições e 21 exclusões
  1. 23 3
      test/test_bcnumerickeyboard/umain.lfm
  2. 35 18
      test/test_bcnumerickeyboard/umain.pas

+ 23 - 3
test/test_bcnumerickeyboard/umain.lfm

@@ -2,17 +2,17 @@ object Form1: TForm1
   Left = 442
   Height = 240
   Top = 143
-  Width = 320
+  Width = 516
   Caption = 'BC Numeric Keyboard'
   ClientHeight = 240
-  ClientWidth = 320
+  ClientWidth = 516
   OnCreate = FormCreate
   LCLVersion = '1.7'
   object BCPanel1: TBCPanel
     Left = 0
     Height = 240
     Top = 0
-    Width = 320
+    Width = 516
     Align = alClient
     Background.Color = clBtnFace
     Background.ColorOpacity = 255
@@ -410,6 +410,26 @@ object Form1: TForm1
       TextApplyGlobalOpacity = False
       MemoryUsage = bmuHigh
     end
+    object FloatSpinEdit1: TFloatSpinEdit
+      Left = 152
+      Height = 28
+      Top = 8
+      Width = 76
+      Increment = 1
+      MaxValue = 100000
+      MinValue = 0
+      OnClick = Button1Click
+      TabOrder = 0
+      Value = 0
+    end
+    object Edit1: TEdit
+      Left = 232
+      Height = 28
+      Top = 8
+      Width = 80
+      OnClick = Button1Click
+      TabOrder = 1
+    end
   end
   object BCNumericKeyboard1: TBCNumericKeyboard
     OnUserChange = BCNumericKeyboard1Change

+ 35 - 18
test/test_bcnumerickeyboard/umain.pas

@@ -6,7 +6,7 @@ interface
 
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  BCNumericKeyboard, BCButton, BCTypes, BCPanel, BGRABitmapTypes;
+  Spin, BCNumericKeyboard, BCButton, BCTypes, BCPanel, BGRABitmapTypes;
 
 type
 
@@ -17,12 +17,14 @@ type
     BCPanel1: TBCPanel;
     Button1: TBCButton;
     Button2: TBCButton;
+    Edit1: TEdit;
+    FloatSpinEdit1: TFloatSpinEdit;
     procedure BCNumericKeyboard1Change(Sender: TObject);
     procedure Button1Click(Sender: TObject);
     procedure FormClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);
   private
-    ButtonSender: TBCButton;
+    NumericSender: TControl;
   public
 
   end;
@@ -36,6 +38,7 @@ implementation
 
 { TForm1 }
 
+{ Button style }
 procedure BCButtonWindows8(AButton: TBCButton; cl1, cl2: TColor);
 begin
   AButton.Rounding.RoundX := 1;
@@ -75,39 +78,53 @@ end;
 
 procedure TForm1.Button1Click(Sender: TObject);
 begin
-  if (ButtonSender <> nil) and (ButtonSender.Name = TBCButton(Sender).Name) and
+  if (NumericSender <> nil) and (NumericSender.Name = TControl(Sender).Name) and
     (BCNumericKeyboard1.Visible) then
   begin
     BCNumericKeyboard1.Hide();
-    // Remove unnecessary comma
-    if Pos(DefaultFormatSettings.DecimalSeparator, ButtonSender.Caption) =
-      Length(ButtonSender.Caption) then
-      ButtonSender.Caption := LeftStr(ButtonSender.Caption,
-        Length(ButtonSender.Caption) - 1);
+    // Remove unnecessary comma for button caption
+    if Sender is TBCButton then
+      if Pos(DefaultFormatSettings.DecimalSeparator, NumericSender.Caption) =
+        Length(NumericSender.Caption) then
+        NumericSender.Caption :=
+          LeftStr(NumericSender.Caption, Length(NumericSender.Caption) - 1);
   end
   else
   begin
-    ButtonSender := Sender as TBCButton;
+    NumericSender := Sender as TControl;
     BCNumericKeyboard1.Value := '';
-    BCNumericKeyboard1.Panel.Left := ButtonSender.Left;
-    BCNumericKeyboard1.Panel.Top := ButtonSender.Top + ButtonSender.Height;
+    BCNumericKeyboard1.Panel.Left := NumericSender.Left;
+    BCNumericKeyboard1.Panel.Top := NumericSender.Top + NumericSender.Height;
     BCNumericKeyboard1.Show();
   end;
 end;
 
 procedure TForm1.FormClick(Sender: TObject);
 begin
-  Button1Click(ButtonSender);
+  Button1Click(NumericSender);
 end;
 
 procedure TForm1.BCNumericKeyboard1Change(Sender: TObject);
+var
+  d: double;
 begin
-  if BCNumericKeyboard1.Value <> '' then
-    ButtonSender.Caption := DefaultFormatSettings.CurrencyString +
-      ' ' + BCNumericKeyboard1.Value
-  else
-    ButtonSender.Caption := DefaultFormatSettings.CurrencyString +
-      ' 0' + DefaultFormatSettings.DecimalSeparator + '00';
+  // For buttons
+  if NumericSender is TBCButton or NumericSender is TEdit then
+  begin
+    if BCNumericKeyboard1.Value <> '' then
+      NumericSender.Caption :=
+        DefaultFormatSettings.CurrencyString + ' ' + BCNumericKeyboard1.Value
+    else
+      NumericSender.Caption :=
+        DefaultFormatSettings.CurrencyString + ' 0' +
+        DefaultFormatSettings.DecimalSeparator + '00';
+  end;
+  // For spin edit
+  if NumericSender is TFloatSpinEdit then
+  begin
+    TryStrToFloat(BCNumericKeyboard1.Value, d);
+    TFloatSpinEdit(NumericSender).Value := d;
+  end;
 end;
 
 procedure TForm1.FormCreate(Sender: TObject);