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

📄 gantttimeunit.pas

📁 Gantt source file example to use in delphi 7
💻 PAS
📖 第 1 页 / 共 5 页
字号:
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 TGanttProjectTimeChart.Loaded;
begin
   inherited Loaded;

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











procedure TGanttProjectTimeChart.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 TGanttProjectTimeChart.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
               paintArrowStyle(ShadowBitmapRect, ShadowBitmap.Canvas);

            if GanttItem.FitemType = dsFinish then
            begin
               ShadowBitmap.Canvas.Polygon([Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom + 1),
                  Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom - FProjectHeight),
                     Point(ShadowBitmapRect.Left + FDaysWidth, ShadowBitmapRect.Bottom - HalfHeight),
                     Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom + 1)]);
            end;
            if GanttItem.FitemType = dsBenchMark then
            begin
               ShadowBitmap.Canvas.Polygon([Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom - 1),
                  Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom - HalfHeight),
                     Point(ShadowBitmapRect.Left + HalfDay, ShadowBitmapRect.Bottom - FProjectHeight),
                     Point(ShadowBitmapRect.Left + FDaysWidth, ShadowBitmapRect.Bottom - HalfHeight),
                     Point(ShadowBitmapRect.Left + FDaysWidth, ShadowBitmapRect.Bottom - 1),
                     Point(ShadowBitmapRect.Left, ShadowBitmapRect.Bottom - 1)]);
            end;

            if GanttItem.FitemType = dsDiaGroup then
               paintDiamondStyle(ShadowBitmapRect, ShadowBitmap.Canvas);

            if GanttItem.FitemType = dsPointGroup then
               PaintPointStyle(ShadowBitmapRect, ShadowBitmap.Canvas);

            if GanttItem.FitemType = dsShardGroup then
               PaintShardStyle(ShadowBitmapRect, ShadowBitmap.Canvas);


            GBlur(ShadowBitmap, 1.5);
            BitBlt(FOffScreenCanvas.Handle, ShadowRect.Left, ShadowRect.Top,
               ShadowRect.Right + 3, ShadowRect.Bottom + 3, ShadowBitmap.Canvas.Handle, 0, 0, SRCAND);
            ShadowBitmap.Free;
         end; // shadows


         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(ChartStart, Starty + 1),
               Point(ChartStart, Starty - FProjectHeight),
                  Point(ChartStart + FDaysWidth, Starty - HalfHeight),
                  Point(ChartStart, Starty + 1)]);
         end;

         if GanttItem.FitemType = dsBenchMark then
         begin
            FOffScreenCanvas.Polygon([Point(ChartStart, Starty - 1),
               Point(ChartStart, Starty - HalfHeight),
                  Point(ChartStart + HalfDay, Starty - FProjectHeight),
                  Point(ChartStart + FDaysWidth, Starty - HalfHeight),
                  Point(ChartStart + FDaysWidth, Starty - 1),
                  Point(ChartStart, Starty - 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);

      end; // Paint Item

    

⌨️ 快捷键说明

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