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

📄 gantttimeunit.pas

📁 Gantt source file example to use in delphi 7
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      showRect.Left := DragGanttItemRect.Left;
      showRect.Right := DragGanttItemRect.Right + DeltaX;
      invalidate;
   end;

end;



procedure TGanttTimeChart.WMRButtonDown(var Message: TWMRButtonDown);
begin
   inherited;
  { If a selection has been made, and a right click procedure has been set,
    execute it }
end;



{ Method to set variable and property values and create objects }



procedure TGanttTimeChart.AutoInitialize;
begin
   FGanttTimeType := ttMonth;
end; { of AutoInitialize }

{ Method to free any objects created by AutoInitialize }

procedure TGanttTimeChart.AutoDestroy;
begin
   ClearProjects;
     { No objects from AutoInitialize to free }
end; { of AutoDestroy }





{ Override OnClick handler from TCustomControl }

procedure TGanttTimeChart.Click;
begin
     { Code to execute before activating click
       behavior of component's parent class }

     { Activate click behavior of parent }
   inherited Click;

     { Code to execute after click behavior
       of parent }

end;



{ Override OnKeyPress handler from TCustomControl }

procedure TGanttTimeChart.KeyPress(var Key: Char);
const
   TabKey = Char(VK_TAB);
   EnterKey = Char(VK_RETURN);
begin
     { Key contains the character produced by the keypress.
       It can be tested or assigned a new value before the
       call to the inherited KeyPress method.  Setting Key
       to #0 before call to the inherited KeyPress method
       terminates any further processing of the character. }

     { Activate KeyPress behavior of parent }
   inherited KeyPress(Key);

     { Code to execute after KeyPress behavior of parent }

end;


constructor TGanttTimeChart.Create(AOwner: TComponent);
begin
     { Call the Create method of the parent class }
   inherited Create(AOwner);
   ControlStyle := ControlStyle + [csOpaque];
     { AutoInitialize sets the initial values of variables and      }
     { properties; also, it creates objects for properties of       }
     { standard Delphi object types (e.g., TFont, TTimer,           }
     { TPicture) and for any variables marked as objects.           }
     { AutoInitialize method is generated by Component Create.      }
   AutoInitialize;

     { Code to perform other tasks when the component is created }

end;

destructor TGanttTimeChart.Destroy;
begin
     { AutoDestroy, which is generated by Component Create, frees any   }
     { objects created by AutoInitialize.                               }
   AutoDestroy;

     { Here, free any other dynamic objects that the component methods  }
     { created but have not yet freed.  Also perform any other clean-up }
     { operations needed before the component is destroyed.             }

     { Last, free the component by calling the Destroy method of the    }
     { parent class.                                                    }
   inherited Destroy;
end;


procedure TGanttTimeChart.Loaded;
begin
   inherited Loaded;

     { Perform any component setup that depends on the property
       values having been set }
end;











procedure TGanttTimeChart.PaintOneMovingGanttItem(StartY: Integer; GanttItem: TGanttItem);
var
   ChartStart: Integer;
   HalfDay, HalfHeight: Integer;
   TempFont: Tfont;
   GanttTimetoPaint, Percent: Integer;
   PrintText: Boolean;
   ResizedDays: integer;
   lastganttitem: TGanttItem;
begin
   TempFont := Tfont.Create;
   try
      FOffScreenCanvas.Brush.Assign(GanttItem.ItemBrush);
      TempFont.Assign(FOffScreenCanvas.Font);
      FOffScreenCanvas.Font.Assign(GanttItem.FItemFont);
      HalfDay := Round(FDaysWidth / 2);
      HalfHeight := Round(FProjectHeight / 2);
      GanttTimetoPaint := 1;


      if (GanttItem.StartDate < FGridStartDate) then
      begin
         ChartStart := FBoxWidth;
         GanttTimetoPaint := GetTimeLeft(GanttItem.FStartDate, GanttItem.EndDate, FGridStartDate, FGanttTimeType); //new time based function
        // GanttTimetoPaint := GetDaysLeft(GanttItem.FStartDate, FGridStartDate, GanttItem.Days);
      end
      else
      begin
         ChartStart := (GetTimeFromStart(GanttItem.FStartDate, FGridStartDate, FGanttTimeType) * FDaysWidth) + FBoxWidth;
       //  ChartStart := (GetDaysFromStart(GanttItem.StartDate, FGridStartDate, FStartMonth) * FDaysWidth) + FBoxWidth;
      end;


      GanttTimetoPaint := GetTimeLeft(GanttItem.FStartDate, GanttItem.EndDate, FGridStartDate, FGanttTimeType);
      if GanttTimetoPaint < 1 then GanttTimetoPaint := 1;

      if ChartStart < FBoxWidth then ChartStart := FBoxWidth
      else PrintText := True;

      if FResizing then
         ResizedDays := round(DeltaX / FDaysWidth)
      else ResizedDays := 0;

      if (FDragging = True) then
      begin
         GanttItem.FItemDrawRect.Left := ChartStart + DeltaX;
         GanttItem.FItemDrawRect.Top := (StartY - FProjectHeight + 2) + Deltay;

         if GanttTimetoPaint < 1 then GanttItem.FItemDrawRect.Right := GanttItem.FItemDrawRect.Left
         else GanttItem.FItemDrawRect.Right := ((FDaysWidth * GanttTimetoPaint) + ChartStart) + DeltaX;
         GanttItem.FItemDrawRect.Bottom := Starty + Deltay - 2;
      end
      else
      begin
         GanttItem.FItemDrawRect.Left := ChartStart;
         GanttItem.FItemDrawRect.Top := (StartY - FProjectHeight + 2);
         if GanttTimetoPaint < 1 then GanttItem.FItemDrawRect.Right := GanttItem.FItemDrawRect.Left
         else GanttItem.FItemDrawRect.Right := ((FDaysWidth * GanttTimetoPaint) + ChartStart) + DeltaX;
         GanttItem.FItemDrawRect.Bottom := Starty - 2;
      end;


      GanttItem.FItemPosition.X := GanttItem.FItemDrawRect.Left;
      GanttItem.FItemPosition.Y := GanttItem.FItemDrawRect.Top;

      if GanttItem.FitemType = dsBlock then
      begin
         FOffScreenCanvas.Rectangle(GanttItem.FItemDrawRect);
         Percent := Round(((GanttItem.FItemDrawRect.Right - GanttItem.FItemDrawRect.Left) / 100) * GanttItem.PercentCompleted);
         FOffScreenCanvas.Brush.Color := clNavy;
         FOffScreenCanvas.Rectangle(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Top + 4,
            GanttItem.FItemDrawRect.Left + Percent, GanttItem.FItemDrawRect.Bottom - 4);
         FOffScreenCanvas.Brush.Assign(GanttItem.ItemBrush);
      end;

      if GanttItem.FitemType = dsBall then
         FOffScreenCanvas.RoundRect(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Top, GanttItem.FItemDrawRect.Right, GanttItem.FItemDrawRect.Bottom, FProjectHeight, FProjectHeight);

      if GanttItem.FitemType = dsRing then
         FOffScreenCanvas.Ellipse(GanttItem.FItemDrawRect);

      if GanttItem.FitemType = dsArrow then
         paintArrowStyle(GanttItem.FItemDrawRect, FOffScreenCanvas);

      if GanttItem.FitemType = dsFinish then
      begin
         FOffScreenCanvas.Polygon([Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom + 1),
            Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom - FProjectHeight),
               Point(GanttItem.FItemDrawRect.Left + FDaysWidth, GanttItem.FItemDrawRect.Bottom - HalfHeight),
               Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom + 1)]);
      end;

      if GanttItem.FitemType = dsBenchMark then
      begin
         FOffScreenCanvas.Polygon([Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom - 1),
            Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom - HalfHeight),
               Point(GanttItem.FItemDrawRect.Left + HalfDay, GanttItem.FItemDrawRect.Bottom - FProjectHeight),
               Point(GanttItem.FItemDrawRect.Left + FDaysWidth, GanttItem.FItemDrawRect.Bottom - HalfHeight),
               Point(GanttItem.FItemDrawRect.Left + FDaysWidth, GanttItem.FItemDrawRect.Bottom - 1),
               Point(GanttItem.FItemDrawRect.Left, GanttItem.FItemDrawRect.Bottom - 1)]);
         FOffScreenCanvas.MoveTo(GanttItem.FItemDrawRect.Left + HalfDay, GanttItem.FItemDrawRect.Bottom - FProjectHeight);
         FOffScreenCanvas.LineTo(GanttItem.FItemDrawRect.Left + HalfDay, 40);
         PrintText := False;
      end;

      if GanttItem.FitemType = dsEnd then
      begin
         FOffScreenCanvas.Rectangle(GanttItem.FItemDrawRect.Left, 40, GanttItem.FItemDrawRect.Left + FDaysWidth, GanttItem.FItemDrawRect.Bottom);
         PrintText := False;
      end;

      if GanttItem.FitemType = dsDiaGroup then
         paintDiamondStyle(GanttItem.FItemDrawRect, FOffScreenCanvas);

      if GanttItem.FitemType = dsPointGroup then
         PaintPointStyle(GanttItem.FItemDrawRect, FOffScreenCanvas);

      if GanttItem.FitemType = dsShardGroup then
         PaintShardStyle(GanttItem.FItemDrawRect, FOffScreenCanvas);


      FOffScreenCanvas.Brush.Style := bsClear;

      if (PrintText <> False) then
      begin
         if (FShowItemLength = True) then
         begin
        //JK change
            if GanttItem.FNumberOfDays + ResizedDays = 0 then ResizedDays := 1 - GanttItem.FNumberOfDays; //show minimum 1 Day
            FOffScreenCanvas.TextOut(GanttItem.FItemDrawRect.Right + 3, (GanttItem.FItemDrawRect.Bottom - (HalfHeight + 5)), GanttItem.ItemName + ' : ' + inttostr(GanttItem.FNumberOfDays + ResizedDays) + ' Days')
         end
         else
            FOffScreenCanvas.TextOut(GanttItem.FItemDrawRect.Right + 3, (GanttItem.FItemDrawRect.Bottom - (HalfHeight + 5)), GanttItem.ItemName);
      end; //printtext
      FOffScreenCanvas.Font.Assign(TempFont);
   finally
      TempFont.free;
   end;
end;






procedure TGanttTimeChart.PaintOneGanttItem(StartY: Integer; GanttItem: TGanttItem);
var
   ChartStart: Integer;
   HalfDay, HalfHeight: Integer;
   TempFont: Tfont;
   GanttTimetoPaint, Percent: Integer;
   ShadowRect, ShadowBitmapRect: TRect;
   ShadowBitmap: TBitmap;
   PrintText: Boolean;

begin
   TempFont := Tfont.Create;
   try
      FOffScreenCanvas.Brush.Assign(GanttItem.ItemBrush);
      TempFont.Assign(FOffScreenCanvas.Font);
      FOffScreenCanvas.Font.Assign(GanttItem.FItemFont);
      HalfDay := Round(FDaysWidth / 2);
      HalfHeight := Round(FProjectHeight / 2);
      GanttTimetoPaint := 1;


      if (GanttItem.StartDate < FGridStartDate) then
      begin
         ChartStart := FBoxWidth;
         GanttTimetoPaint := GetTimeLeft(GanttItem.FStartDate, GanttItem.EndDate, FGridStartDate, FGanttTimeType); //new time based function
        // GanttTimetoPaint := GetDaysLeft(GanttItem.FStartDate, FGridStartDate, GanttItem.Days);
      end
      else
      begin
         ChartStart := (GetTimeFromStart(GanttItem.FStartDate, FGridStartDate, FGanttTimeType) * FDaysWidth) + FBoxWidth;
       //  ChartStart := (GetDaysFromStart(GanttItem.StartDate, FGridStartDate, FStartMonth) * FDaysWidth) + FBoxWidth;
      end;

      if (ChartStart < FBoxWidth) then ChartStart := FBoxWidth
      else
         PrintText := True;


       //GetTimeLeft
      //GetTimeFromStart

      GanttItem.FItemDrawRect.Left := ChartStart;
      GanttItem.FItemDrawRect.Top := StartY - FProjectHeight + 2;
      if GanttTimetoPaint < 1 then GanttItem.FItemDrawRect.Right := GanttItem.FItemDrawRect.Left
      else GanttItem.FItemDrawRect.Right := (FDaysWidth * GanttTimetoPaint) + ChartStart;
      GanttItem.FItemDrawRect.Bottom := Starty - 2;
      GanttItem.FItemPosition.X := GanttItem.FItemDrawRect.Left;
      GanttItem.FItemPosition.Y := GanttItem.FItemDrawRect.Top;

      if GanttTimetoPaint > 0 then // Paint Item
      begin
         if FShadows = True then // create dynamic soft shadows
         begin
            ShadowRect := CalculateShadowoffsett(GanttItem.FItemDrawRect);
            ShadowBitmap := TBitmap.create;
            ShadowBitmap.PixelFormat := pf24Bit;
            ShadowBitmap.Width := (ShadowRect.Right - ShadowRect.Left) + 2;
            ShadowBitmap.Height := (ShadowRect.Bottom - ShadowRect.Top) + 2;
            ShadowBitmap.Canvas.Brush.Color := clWhite;
            ShadowBitmap.Canvas.Brush.Style := bsSolid;
            ShadowBitmap.Canvas.Pen.Color := clWhite;
            ShadowBitmapRect := Rect(0, 0, ShadowBitmap.Width - 2, ShadowBitmap.Height - 2);
            ShadowBitmap.Canvas.Rectangle(ShadowBitmapRect);

            ShadowBitmap.Canvas.Brush.Color := FShadowColor;
            ShadowBitmap.Canvas.Pen.Color := FShadowColor;

            if GanttItem.FitemType = dsBlock then
               ShadowBitmap.Canvas.Rectangle(ShadowBitmapRect);

            if GanttItem.FitemType = dsBall then
               ShadowBitmap.Canvas.RoundRect(ShadowBitmapRect.Left, ShadowBitmapRect.Top, ShadowBitmapRect.Right, ShadowBitmapRect.Bottom, FProjectHeight, FProjectHeight);

            if GanttItem.FitemType = dsRing then
               ShadowBitmap.Canvas.Ellipse(ShadowBitmapRect);

            if GanttItem.FitemType = dsArrow then

⌨️ 快捷键说明

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