From d2bdaad7bf5cf4c2c2c90bcd6560195b7d91fcb4 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 4 Sep 2022 22:11:52 +0000 Subject: [PATCH] tvplanit: Fix painting glitches for TVpTaskList. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8443 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tvplanit/examples/fulldemo/demomain.lfm | 47 ++--- .../tvplanit/source/vpmonthviewpainter.pas | 27 --- components/tvplanit/source/vptasklist.pas | 107 ++++++------ .../tvplanit/source/vptasklistpainter.pas | 163 ++++++++---------- .../tvplanit/source/vpweekviewpainter.pas | 79 ++++----- 5 files changed, 191 insertions(+), 232 deletions(-) diff --git a/components/tvplanit/examples/fulldemo/demomain.lfm b/components/tvplanit/examples/fulldemo/demomain.lfm index 121fccab3..f395809c1 100644 --- a/components/tvplanit/examples/fulldemo/demomain.lfm +++ b/components/tvplanit/examples/fulldemo/demomain.lfm @@ -1,24 +1,25 @@ object MainForm: TMainForm - Left = 227 + Left = 362 Height = 596 - Top = 134 + Top = 135 Width = 959 Caption = 'Turbo Power VisualPlanIt Demo' - ClientHeight = 596 + ClientHeight = 576 ClientWidth = 959 Menu = MainMenu1 OnCloseQuery = FormCloseQuery OnCreate = FormCreate OnDestroy = FormDestroy + LCLVersion = '2.3.0.0' object Panel1: TPanel Left = 125 - Height = 596 + Height = 576 Top = 0 Width = 834 Align = alClient AutoSize = True BevelOuter = bvNone - ClientHeight = 596 + ClientHeight = 576 ClientWidth = 834 TabOrder = 2 object HeaderPanel: TPanel @@ -55,7 +56,7 @@ object MainForm: TMainForm end object Notebook: TNotebook Left = 0 - Height = 548 + Height = 528 Top = 48 Width = 834 PageIndex = 0 @@ -65,18 +66,18 @@ object MainForm: TMainForm object Events: TPage object LeftPanel: TPanel Left = 0 - Height = 548 + Height = 528 Top = 0 Width = 357 Align = alLeft BevelOuter = bvNone - ClientHeight = 548 + ClientHeight = 528 ClientWidth = 357 TabOrder = 0 object VpMonthView1: TVpMonthView Left = 0 Height = 197 - Top = 351 + Top = 331 Width = 357 ShowHint = True PopupMenu = VpMonthView1.default @@ -102,14 +103,14 @@ object MainForm: TMainForm Cursor = crVSplit Left = 0 Height = 5 - Top = 346 + Top = 326 Width = 357 Align = alBottom ResizeAnchor = akBottom end object VpDayView1: TVpDayView Left = 0 - Height = 312 + Height = 292 Top = 34 Width = 357 ShowHint = True @@ -277,13 +278,13 @@ object MainForm: TMainForm end object Splitter3: TSplitter Left = 357 - Height = 548 + Height = 528 Top = 0 Width = 5 end object VpWeekView1: TVpWeekView Left = 362 - Height = 548 + Height = 528 Top = 0 Width = 472 ShowHint = True @@ -362,24 +363,10 @@ object MainForm: TMainForm Width = 834 PopupMenu = VpTaskList1.default ControlLink = VpControlLink1 - ParentFont = False Align = alClient TabOrder = 1 - DisplayOptions.CheckBGColor = clWindow - DisplayOptions.CheckColor = cl3DDkShadow - DisplayOptions.CheckStyle = csCheck - DisplayOptions.DueDateFormat = 'dd.MM.yyyy' - DisplayOptions.ShowCompletedTasks = False - DisplayOptions.ShowAll = False - DisplayOptions.ShowDueDate = True - DisplayOptions.OverdueColor = clRed - DisplayOptions.NormalColor = clBlack - DisplayOptions.CompletedColor = clGray - LineColor = clGray - MaxVisibleTasks = 250 - TaskHeadAttributes.Color = clSilver - TaskHeadAttributes.Font.Style = [fsItalic] DrawingStyle = dsFlat + TaskHeadAttributes.Font.Style = [fsItalic] end end object Contacts: TPage @@ -730,7 +717,7 @@ object MainForm: TMainForm end object VpNavBar1: TVpNavBar Left = 0 - Height = 596 + Height = 576 Top = 0 Width = 120 ActiveFolder = 0 @@ -831,7 +818,7 @@ object MainForm: TMainForm end object Splitter1: TSplitter Left = 120 - Height = 596 + Height = 576 Top = 0 Width = 5 end diff --git a/components/tvplanit/source/vpmonthviewpainter.pas b/components/tvplanit/source/vpmonthviewpainter.pas index 44a78cab0..af769a77c 100644 --- a/components/tvplanit/source/vpmonthviewpainter.pas +++ b/components/tvplanit/source/vpmonthviewpainter.pas @@ -95,33 +95,6 @@ begin dsFlat: DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow); ds3D: DrawBevelRect(RenderCanvas, R, BevelShadow, BevelHighlight); end; - (* - if FMonthView.DrawingStyle = dsFlat then begin - { draw a simple rectangular border } - DrawBevelRect( - RenderCanvas, - TPSRotateRectangle(Angle, RenderIn, R), - BevelShadow, - BevelShadow - ); - end else - if FMonthView.DrawingStyle = ds3d then begin - { draw a 3d bevel } - DrawBevelRect( - RenderCanvas, - TPSRotateRectangle(Angle, RenderIn, R), - BevelShadow, - BevelHighlight - ); - InflateRect(R, -1, -1); - DrawBevelRect( - RenderCanvas, - TPSRotateRectangle(Angle, RenderIn, R), - BevelDarkShadow, - BevelFace - ); - end; - *) end; procedure TVpMonthViewPainter.DrawDayCell(ADate: TDate; ACol, ARow: Integer; diff --git a/components/tvplanit/source/vptasklist.pas b/components/tvplanit/source/vptasklist.pas index ef9b622ea..590a56b23 100644 --- a/components/tvplanit/source/vptasklist.pas +++ b/components/tvplanit/source/vptasklist.pas @@ -67,6 +67,7 @@ type FOverdueColor: TColor; FNormalColor: TColor; FCompletedColor: TColor; + function IsStoredDueDateFormat: Boolean; procedure SetCheckColor(Value: TColor); procedure SetCheckBGColor(Value: TColor); procedure SetCheckStyle(Value: TVpCheckStyle); @@ -81,16 +82,16 @@ type constructor Create(Owner: TVpTaskList); destructor Destroy; override; published - property CheckBGColor: TColor read FCheckBGColor write SetCheckBGColor; - property CheckColor: TColor read FCheckColor write SetCheckColor; - property CheckStyle: TVpCheckStyle read FCheckStyle write SetCheckStyle; - property DueDateFormat: string read FDueDateFormat write SetDueDateFormat; - property ShowCompletedTasks: Boolean read FShowCompleted write SetShowCompleted; - property ShowAll: Boolean read FShowAll write SetShowAll; - property ShowDueDate: Boolean read FShowDueDate write SetShowDueDate; - property OverdueColor: TColor read FOverdueColor write SetOverdueColor; - property NormalColor: TColor read FNormalColor write SetNormalColor; - property CompletedColor: TColor read FCompletedColor write SetCompletedColor; + property CheckBGColor: TColor read FCheckBGColor write SetCheckBGColor default clWindow; + property CheckColor: TColor read FCheckColor write SetCheckColor default cl3DDkShadow; + property CheckStyle: TVpCheckStyle read FCheckStyle write SetCheckStyle default csCheck; + property DueDateFormat: string read FDueDateFormat write SetDueDateFormat stored IsStoredDueDateFormat; + property ShowCompletedTasks: Boolean read FShowCompleted write SetShowCompleted default false; + property ShowAll: Boolean read FShowAll write SetShowAll default false; + property ShowDueDate: Boolean read FShowDueDate write SetShowDueDate default true; + property OverdueColor: TColor read FOverdueColor write SetOverdueColor default clRed; + property NormalColor: TColor read FNormalColor write SetNormalColor default clWindowText; + property CompletedColor: TColor read FCompletedColor write SetCompletedColor default clGray; end; { InPlace Editor } @@ -104,12 +105,16 @@ type end; TVpTaskHeadAttr = class(TVpPersistent) - protected{private} + private FTaskList: TVpTaskList; FFont: TVpFont; FColor: TColor; + FGlyphDist: Integer; procedure SetColor(Value: TColor); procedure SetFont(Value: TVpFont); + procedure SetGlyphDist(Value: Integer); + protected + public constructor Create(AOwner: TVpTaskList); destructor Destroy; override; @@ -117,8 +122,9 @@ type { The Invalidate method is used as a bridge between FFont & FTaskList. } property TaskList: TVpTaskList read FTaskList; published - property Color: TColor read FColor write SetColor; + property Color: TColor read FColor write SetColor default clBtnFace; property Font: TVpFont read FFont write SetFont; + property GlyphDistance: Integer read FGlyphDist write SetGlyphDist default 10; end; { Task List } @@ -264,14 +270,14 @@ type property AllowInplaceEditing: Boolean read FAllowInplaceEdit write FAllowInplaceEdit default true; - property DisplayOptions: TVpTaskDisplayOptions read FDisplayOptions write FDisplayOptions; - property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR; - property MaxVisibleTasks: Word read FMaxVisibleTasks write SetMaxVisibleTasks; - property TaskHeadAttributes: TVpTaskHeadAttr read FTaskHeadAttr write FTaskHeadAttr; - property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d; property Color: TColor read FColor write SetColor default DEFAULT_COLOR; + property DisplayOptions: TVpTaskDisplayOptions read FDisplayOptions write FDisplayOptions; + property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle default ds3d; + property LineColor: TColor read FLineColor write SetLineColor default DEFAULT_LINECOLOR; + property MaxVisibleTasks: Word read FMaxVisibleTasks write SetMaxVisibleTasks default 250; property ShowIcon: Boolean read FShowIcon write SetShowIcon default True; property ShowResourceName: Boolean read FShowResourceName write SetShowResourceName default true; + property TaskHeadAttributes: TVpTaskHeadAttr read FTaskHeadAttr write FTaskHeadAttr; property TextMargin: Integer read FTextMargin write SetTextMargin default TEXT_MARGIN; { events } property BeforeEdit: TVpBeforeEditTask read FBeforeEdit write FBeforeEdit; @@ -286,8 +292,8 @@ uses VpDlg, VpTaskEditDlg, VpTasklistPainter; (*****************************************************************************) - { TVpTaskDisplayOptions } +(*****************************************************************************) constructor TVpTaskDisplayOptions.Create(Owner: TVpTaskList); begin inherited Create; @@ -299,15 +305,18 @@ begin FCheckStyle := csCheck; FOverdueColor := clRed; FCompletedColor := clGray; - FNormalColor := clBlack; + FNormalColor := clWindowText; end; -{=====} destructor TVpTaskDisplayOptions.Destroy; begin inherited; end; -{=====} + +function TVpTaskDisplayOptions.IsStoredDueDateFormat: Boolean; +begin + Result := FDueDateFormat <> DefaultFormatSettings.ShortDateFormat; +end; procedure TVpTaskDisplayOptions.SetOverdueColor(Value : TColor); begin @@ -316,7 +325,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetNormalColor(Value: TColor); begin @@ -325,7 +333,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetCompletedColor(Value: TColor); begin @@ -334,7 +341,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetCheckColor(Value: TColor); begin @@ -343,7 +349,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetCheckBGColor(Value: TColor); begin @@ -352,7 +357,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetCheckStyle(Value: TVpCheckStyle); begin @@ -361,7 +365,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetDueDateFormat(Value: string); begin @@ -370,7 +373,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetShowCompleted(Value : Boolean); begin @@ -379,7 +381,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetShowDueDate(Value: Boolean); begin @@ -388,7 +389,6 @@ begin FTaskList.Invalidate; end; end; -{=====} procedure TVpTaskDisplayOptions.SetShowAll(Value: Boolean); begin @@ -397,53 +397,61 @@ begin FTaskList.Invalidate; end; end; -{=====} -{ TVpTaskHeadAttr } + +(******************************************************************************) +{ TVpTaskHeadAttr } +(******************************************************************************) constructor TVpTaskHeadAttr.Create(AOwner: TVpTaskList); begin inherited Create; FTaskList := AOwner; FFont := TVpFont.Create(self); FFont.Assign(FTaskList.Font); - FColor := clSilver; + FColor := clBtnFace; + FGlyphDist := 10; end; -{=====} destructor TVpTaskHeadAttr.Destroy; begin FFont.Free; end; -{=====} procedure TVpTaskHeadAttr.Invalidate; begin if Assigned(FTaskList) then FTaskList.Invalidate; end; -{=====} procedure TVpTaskHeadAttr.SetColor(Value: TColor); begin if Value <> FColor then begin FColor := Value; - TaskList.Invalidate; + Invalidate; end; end; -{=====} procedure TVpTaskHeadAttr.SetFont(Value: TVpFont); begin if Value <> FFont then begin FFont.Assign(Value); - TaskList.Invalidate; + Invalidate; + end; +end; + +procedure TVpTaskHeadAttr.SetGlyphDist(Value: Integer); +begin + if Value <> FGlyphDist then + begin + FGlyphDist := Value; + Invalidate; end; end; -{=====} -{ TVpCGInPlaceEdit } - +(******************************************************************************) +{ TVpCGInPlaceEdit } +(******************************************************************************) constructor TVpTLInPlaceEdit.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -508,13 +516,15 @@ begin end; end; -(*****************************************************************************) -{ TVpTaskList } +(******************************************************************************) +{ TVpTaskList } +(******************************************************************************) constructor TVpTaskList.Create(AOwner: TComponent); begin inherited; ControlStyle := [csCaptureMouse, csOpaque, csDoubleClicks]; + { Create internal classes and stuff } tlClickTimer := TTimer.Create(self); FTaskHeadAttr := TVpTaskHeadAttr.Create(Self); @@ -673,7 +683,7 @@ end; procedure TVpTaskList.Paint; begin - { paint simply calls RenderToCanvas and passes in the screen canvas. } + // Paint simply calls RenderToCanvas and passes in the screen canvas. RenderToCanvas( Canvas, { Screen Canvas} Rect(0, 0, Width, Height), { Clipping Rectangle } @@ -766,7 +776,6 @@ begin Result := -1 else Result := FActiveTask.Owner.IndexOf(FActiveTask); -// result := FActiveTask.ItemIndex; end; procedure TVpTaskList.SetLineColor(Value: TColor); @@ -802,7 +811,7 @@ procedure TVpTaskList.WMSize(var Msg: TLMSize); {$ENDIF} begin inherited; - { force a repaint on resize } + // Force a repaint on resize Invalidate; end; @@ -962,7 +971,7 @@ begin Exit; if not CheckCreateResource then Exit; - { Allow the user to fill in all the new information } + // Allow the user to fill in all the new information. Repaint; tlSpawnTaskEditDialog(True); end; @@ -1376,6 +1385,8 @@ begin if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then begin FTextMargin := round(FTextMargin * AXProportion); + with FTaskHeadAttr do + FGlyphDist := round(FGlyphDist * AXProportion); end; end; {$IFEND} diff --git a/components/tvplanit/source/vptasklistpainter.pas b/components/tvplanit/source/vptasklistpainter.pas index 3035981fc..95abf5055 100644 --- a/components/tvplanit/source/vptasklistpainter.pas +++ b/components/tvplanit/source/vptasklistpainter.pas @@ -54,7 +54,7 @@ type implementation uses - Forms, + Math, Forms, VpData, VpMisc, VpCanvasUtils, VpSR; type @@ -212,31 +212,21 @@ procedure TVpTaskListPainter.DrawBorders; var R: TRect; begin - R := Rect(RenderIn.Left, RenderIn.Top, RenderIn.Right - 1, RenderIn.Bottom - 1); + R := TPSRotateRectangle(Angle, RenderIn, Rect(RealLeft, RealTop, RealRight - 1, RealBottom - 1)); case FTasklist.DrawingStyle of - dsFlat: - begin - DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow); - { wp: above line replaces the following code, no bevel in flat mode - DrawBevelRect(RenderCanvas, R, BevelShadow, BevelHighlight); - InflateRect(R, -1, -1); - DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelShadow); } - end; - ds3d: - begin - DrawBevelRect(RenderCanvas, R, BevelShadow, BevelHighlight); - InflateRect(R, -1, -1); - DrawBevelRect(RenderCanvas, R, BevelDarkShadow, BevelFace); - end; + dsNoBorder: ; + dsFlat: DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow); + ds3d: DrawBevelRect(RenderCanvas, R, BevelShadow, BevelHighlight); end; end; procedure TVpTaskListPainter.DrawHeader; var - GlyphRect: TRect; - HeadStr: string; + glyphRect: TRect; + textRect: TRect; + headStr: string; delta: Integer; - w, h: Integer; + w, h, hText: Integer; bmp: TBitmap; begin RenderCanvas.Brush.Color := TaskHeadAttrColor; @@ -244,32 +234,30 @@ begin {$IF VP_LCL_SCALING = 0} RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); {$ENDIF} + hText := RenderCanvas.TextHeight('Tg'); - if FTaskList.DrawingStyle = dsFlat then delta := 1 else delta := 2; + delta := IfThen(FTaskList.DrawingStyle = ds3D, 1, 0); HeadRect.Left := RealLeft + delta; HeadRect.Left := RealLeft + delta; HeadRect.Top := RealTop + delta; - HeadRect.Right := RealRight - delta; - HeadRect.Bottom := RealTop + RenderCanvas.TextHeight('YyGg0') + FTasklist.TextMargin * 2; + HeadRect.Right := RealRight - delta - 1; + HeadRect.Bottom := RealTop + hText + FTasklist.TextMargin * 2 - 1; TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); { draw the header cell borders } - case FTaskList.DrawingStyle of - dsFlat: - begin { draw an outer and inner bevel } - { wp: no bevel in flat style! - HeadRect.Left := HeadRect.Left - 1; - HeadRect.Top := HeadRect.Top - 1; - DrawBevelRect(RenderCanvas, TPSRotateRectangle(Angle, RenderIn, HeadRect), BevelShadow, BevelShadow); - } - end; - ds3d: - begin { draw a 3d bevel } - HeadRect.Right := HeadRect.Right - 1; - DrawBevelRect(RenderCanvas, TPSRotateRectangle(Angle, RenderIn, HeadRect), BevelHighlight, BevelDarkShadow); - end; + if FTaskList.DrawingStyle = ds3d then + begin { draw a 3d bevel } + HeadRect.Right := HeadRect.Right; + DrawBevelRect(RenderCanvas, TPSRotateRectangle(Angle, RenderIn, HeadRect), BevelHighlight, BevelDarkShadow); + end else + begin + RenderCanvas.Pen.Color := BevelShadow; + TPSMoveTo(RenderCanvas, Angle, RenderIn, HeadRect.Left, HeadRect.Bottom); + TPSLineTo(RenderCanvas, Angle, RenderIn, HeadRect.Right, HeadRect.Bottom); end; + textRect := HeadRect; + { Draw the glyph } if FTaskList.ShowIcon then begin bmp := TBitmap.Create; @@ -283,39 +271,36 @@ begin begin w := Round(bmp.Width * Scale); h := Round(bmp.Height * Scale); - GlyphRect.TopLeft := Point( + glyphRect.TopLeft := Point( HeadRect.Left + FTasklist.TextMargin, - (Headrect.Top + HeadRect.Bottom - h) div 2 + (HeadRect.Top + HeadRect.Bottom - h) div 2 ); - GlyphRect.BottomRight := Point(GlyphRect.Left + w, GlyphRect.Top + h); + glyphRect.BottomRight := Point(glyphRect.Left + w, glyphRect.Top + h); {$IFDEF FPC} RotateBitmap(Bmp, Angle); {$ENDIF} - TPSStretchDraw(RenderCanvas, Angle, RenderIn, GlyphRect, Bmp); - HeadRect.Left := HeadRect.Left + w + FTasklist.TextMargin; + TPSStretchDraw(RenderCanvas, Angle, RenderIn, glyphRect, Bmp); + textRect.Left := glyphRect.Right + FTasklist.TaskHeadAttributes.GlyphDistance; end; finally bmp.Free; end; - end; + end else + textRect.Left := HeadRect.Left + FTaskList.TextMargin; { draw the text } with FTaskList do begin if ShowResourceName and (DataStore <> nil) and (DataStore.Resource <> nil) then - HeadStr := RSTaskTitleResource + DataStore.Resource.Description + headStr := RSTaskTitleResource + DataStore.Resource.Description else - HeadStr := RSTaskTitleNoResource; - RenderCanvas.Font.Assign(TaskHeadAttributes.Font); - {$IF VP_LCL_SCALING = 0} - RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); - {$ENDIF} + headStr := RSTaskTitleNoResource; TPSTextOut( RenderCanvas, Angle, RenderIn, - HeadRect.Left + TextMargin, - HeadRect.Top + TextMargin, - HeadStr + textRect.Left, + (textRect.Top + textRect.Bottom - hText) div 2, + headStr ); end; end; @@ -329,27 +314,29 @@ begin LinePos := HeadRect.Bottom + RowHeight; while LinePos < RealBottom do begin TPSMoveTo(RenderCanvas, Angle, RenderIn, RealLeft, LinePos); - TPSLineTo(RenderCanvas, Angle, RenderIn, RealRight - 2, LinePos); + TPSLineTo(RenderCanvas, Angle, RenderIn, RealRight - 1, LinePos); Inc(LinePos, RowHeight); end; end; procedure TVpTaskListPainter.DrawTasks; var + xLeft, xRight: Integer; I: Integer; - Task: TVpTask; + task: TVpTask; LineRect: TRect; CheckRect: TRect; DisplayStr: string; begin + xLeft := RealLeft + 2; + xRight := xLeft + RealWidth - 3; with TVpTaskListOpener(FTaskList) do begin if (DataStore = nil) or (DataStore.Resource = nil) or (DataStore.Resource.Tasks.Count = 0) then begin if Focused then begin - LineRect.TopLeft := Point(RealLeft + 2, HeadRect.Bottom); - LineRect.BottomRight := Point(LineRect.Left + RealWidth - 4, LineRect.Top + RowHeight); + LineRect := Rect(xLeft, HeadRect.Bottom, xRight, HeadRect.Bottom + RowHeight); RenderCanvas.Brush.Color := BackgroundSelHighlight; RenderCanvas.FillRect(LineRect); RenderCanvas.Brush.Color := RealColor; @@ -357,29 +344,27 @@ begin Exit; end; - LineRect.TopLeft := Point(RealLeft + 2, HeadRect.Bottom); - LineRect.BottomRight := Point(LineRect.Left + RealWidth - 4, LineRect.Top + RowHeight); - + LineRect := Rect(xLeft, HeadRect.Bottom, xRight, HeadRect.Bottom + RowHeight); tlVisibleItems := 0; RenderCanvas.Brush.Color := RealColor; tlAllTaskList.Clear; - { Make sure the tasks are properly sorted } + // Make sure the tasks are properly sorted DataStore.Resource.Tasks.Sort; for I := 0 to pred(DataStore.Resource.Tasks.Count) do begin if DisplayOptions.ShowAll then - { Get all tasks regardless of their status and due date } + // Get all tasks regardless of their status and due date tlAllTaskList.Add(DataStore.Resource.Tasks.GetTask(I)) else begin - { get all tasks which are incomplete, or were just completed today.} - Task := DataStore.Resource.Tasks.GetTask(I); - if not Task.Complete then - tlAllTaskList.Add(Task) + // Get all tasks which are incomplete, or were just completed today. + task := DataStore.Resource.Tasks.GetTask(I); + if not task.Complete then + tlAllTaskList.Add(task) else if FDisplayOptions.ShowCompletedTasks and SameDate(Task.CompletedOn, now) then - tlAllTaskList.Add(Task); + tlAllTaskList.Add(task); end; end; @@ -388,11 +373,11 @@ begin RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); {$ENDIF} for I := StartLine to pred(tlAllTaskList.Count) do begin - Task := tlAllTaskList[I]; + task := tlAllTaskList[I]; if (LineRect.Top + Trunc(RowHeight * 0.5) <= RealBottom) then begin - { if this is the selected task and we are not in edit mode, } - { then set background selection } - if (Task = FActiveTask) and + // If this is the selected task and we are not in edit mode, + // then set background selection. + if (task = FActiveTask) and ((tlInPlaceEditor = nil) or not tlInplaceEditor.Visible) and (not DisplayOnly) and Focused then begin @@ -401,48 +386,48 @@ begin RenderCanvas.Brush.Color := RealColor; end; - { draw the checkbox } - CheckRect := DrawCheck(LineRect, Task.Complete); + // Draw the checkbox + CheckRect := DrawCheck(LineRect, task.Complete); - if Task.Complete then begin - { complete task } + if task.Complete then begin + // Complete task RenderCanvas.Font.Style := RenderCanvas.Font.Style + [fsStrikeout]; RenderCanvas.Font.Color := RealCompleteColor; end else begin - { incomplete task } + // Incomplete task RenderCanvas.Font.Style := RenderCanvas.Font.Style - [fsStrikeout]; - if (Trunc(Task.DueDate) < Trunc(Now)) and (Trunc(Task.DueDate) <> 0) then - { overdue task } + if (Trunc(task.DueDate) < Trunc(Now)) and (Trunc(task.DueDate) <> 0) then + // Overdue task RenderCanvas.Font.Color := RealOverdueColor else RenderCanvas.Font.Color := RealNormalColor; end; - if Task.Priority = ord(tpHigh) then + if task.Priority = ord(tpHigh) then RenderCanvas.Font.Style := RenderCanvas.Font.Style + [fsBold] else RenderCanvas.Font.Style := RenderCanvas.Font.style - [fsBold]; - { if this is the selected task, set highlight text color } - if (Task = FActiveTask) and + // If this is the selected task, set highlight text color } + if (task = FActiveTask) and ((tlInPlaceEditor = nil) or not tlInplaceEditor.Visible) and (not DisplayOnly) and Focused then RenderCanvas.Font.Color := ForegroundSelHighlight; - { build display string } + // Build display string. DisplayStr := ''; - if (FDisplayOptions.ShowDueDate) and (Trunc(Task.DueDate) <> 0) then - DisplayStr := FormatDateTime(FDisplayOptions.DueDateFormat, Task.DueDate) + ' - '; - DisplayStr := DisplayStr + Task.Description; + if (FDisplayOptions.ShowDueDate) and (Trunc(task.DueDate) <> 0) then + DisplayStr := FormatDateTime(FDisplayOptions.DueDateFormat, task.DueDate) + ' - '; + DisplayStr := DisplayStr + task.Description; - { Adjust display string - If the string is too long for the available } - { space, Chop the end off and replace it with an ellipses. } + // Adjust display string - If the string is too long for the available + // space, chop the end off and replace it with an ellipses. DisplayStr := GetDisplayString(RenderCanvas, DisplayStr, 3, WidthOf(LineRect) - CheckRect.Right - TextMargin); - { paint the text } + // Paint the text TPSTextOut(RenderCanvas, Angle, RenderIn, CheckRect.Right + TextMargin * 2, LineRect.Top + TextMargin, DisplayStr); - { store the tasks drawing details } - tlVisibleTaskArray[tlVisibleItems].Task := Task; + // Store the tasks drawing details + tlVisibleTaskArray[tlVisibleItems].Task := task; tlVisibleTaskArray[tlVisibleItems].LineRect := Rect( CheckRect.Right + TextMargin, LineRect.Top, @@ -485,6 +470,7 @@ end; procedure TVpTaskListPainter.InitColors; begin if DisplayOnly then begin + // Colors for printing RealColor := clWhite; BackgroundSelHighlight := clBlack; ForegroundSelHighlight := clWhite; @@ -501,6 +487,7 @@ begin RealNormalColor := clBlack; TaskHeadAttrColor := clSilver; end else begin + // Colors for screen display RealColor := FTaskList.Color; BackgroundSelHighlight := clHighlight; ForegroundSelHighlight := clHighlightText; diff --git a/components/tvplanit/source/vpweekviewpainter.pas b/components/tvplanit/source/vpweekviewpainter.pas index 396a6687b..8b6b0090f 100644 --- a/components/tvplanit/source/vpweekviewpainter.pas +++ b/components/tvplanit/source/vpweekviewpainter.pas @@ -589,12 +589,13 @@ var headTextRect: TRect; headStr: string = ''; headStrLen: Integer; + maxStrLen: Integer; weekNo: Integer; startStr, endStr: String; txtStart: Integer; - txtMargin: Integer; + margin: Integer; begin - txtMargin := FWeekView.TextMargin; + margin := FWeekView.HeaderMargin; RenderCanvas.Brush.Color := RealHeadAttrColor; RenderCanvas.Font.Assign(TFont(FWeekView.HeadAttributes.Font)); @@ -622,48 +623,17 @@ begin end; end; - // Build header caption - weekNo := GetWeekOfYear(StartDate); - startStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate); - endStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate+6); - headStr := Format('%s %d (%s - %s)', [RSCalendarWeek, weekNo, startStr, endStr]); - - { draw the text } - if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= WidthOf(RenderIn)) then - headTextRect.TopLeft := Point(RealLeft + txtMargin * 2, HeadRect.Top) - else - if DisplayOnly then - headTextRect.TopLeft := Point( - RealLeft + (RealRight - RealLeft - RenderCanvas.TextWidth(headStr)) div 2, - headRect.Top - ) - else - headTextRect.TopLeft := Point( - RealLeft + Trunc(TVpWeekViewOpener(FWeekView).wvHeaderHeight * 0.8) * 2 + txtMargin * 2, - headRect.Top - ); - headTextRect.BottomRight := headRect.BottomRight; - dec(headTextRect.Right, txtMargin); - - // Fix header string - headStrLen := RenderCanvas.TextWidth(headStr); - if headStrLen > headTextRect.Right - headTextRect.Left - txtMargin then - begin - headStr := GetDisplayString(RenderCanvas, headStr, 0, - headTextRect.Right - headTextRect.Left - txtMargin); - end; - // Position the spinner buttons with FWeekView do begin PrevMonthBtn.Width := PrevMonthBtn.Height; - PrevMonthBtn.Left := TextMargin; + PrevMonthBtn.Left := margin; PrevMonthBtn.Top := (headRect.Top + headRect.Bottom - PrevMonthBtn.Height) div 2; - + PrevWeekBtn.Height := PrevMonthBtn.Height; PrevWeekBtn.Width := PrevMonthBtn.Height; PrevWeekBtn.Left := PrevMonthBtn.Left + PrevMonthBtn.Width; PrevWeekBtn.Top := PrevMonthBtn.Top; - + NextWeekBtn.Height := PrevMonthBtn.Height; NextWeekBtn.Width := PrevMonthBtn.Height; NextWeekBtn.Left := PrevWeekBtn.Left + PrevWeekBtn.Width; @@ -673,13 +643,44 @@ begin NextMonthBtn.Width := PrevMonthBtn.Height; NextMonthBtn.Left := NextWeekBtn.Left + NextWeekBtn.Width; NextMonthBtn.Top := PrevMonthBtn.Top; - - txtStart := NextMonthBtn.Left + NextMonthBtn.Width + txtMargin; + + txtStart := NextMonthBtn.Left + NextMonthBtn.Width + margin; end; + // Build header caption + weekNo := GetWeekOfYear(StartDate); + startStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate); + endStr := FormatDateTime(FWeekView.DateLabelFormat, StartDate+6); + headStr := Format('%s %d (%s - %s)', [RSCalendarWeek, weekNo, startStr, endStr]); + + // Draw the text + { + if DisplayOnly and (RenderCanvas.TextWidth(headStr) >= WidthOf(RenderIn)) then + headTextRect.TopLeft := Point(RealLeft + margin, HeadRect.Top) + else + if DisplayOnly then + headTextRect.TopLeft := Point( + RealLeft + (RealRight - RealLeft - RenderCanvas.TextWidth(headStr)) div 2, + headRect.Top + ) + else + headTextRect.TopLeft := Point( + RealLeft + Trunc(TVpWeekViewOpener(FWeekView).wvHeaderHeight * 0.8) * 2 + margin, + headRect.Top + ); + headTextRect.BottomRight := headRect.BottomRight; + dec(headTextRect.Right, margin); + } + + // Fix length of header string + headStrLen := RenderCanvas.TextWidth(headStr); + maxStrLen := headRect.Right - margin - txtStart; + if headStrLen > maxStrLen then + headStr := GetDisplayString(RenderCanvas, headStr, 0, maxStrlen); + TPSTextOut(RenderCanvas, Angle, RenderIn, txtStart, - (headTextRect.Top + headTextRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2, + (headRect.Top + headRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2, headStr ); end;