Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Part of the MVS Application for TechView
21 #include "mvsvideocontrol.h"
23 CMVSAppView* CMVSAppView::NewL(const TRect& aRect, CMVSVideoPlayAgent& aVideoPlayAgent)
25 CMVSAppView * self = new(ELeave) CMVSAppView;
26 CleanupStack::PushL(self);
27 self->ConstructL(aRect, aVideoPlayAgent);
33 CMVSAppView::CMVSAppView()
38 CMVSAppView::~CMVSAppView()
41 delete iMainWindowControl;
42 delete iStatusWindowFNameControl;
43 delete iStatusWindowStateControl;
44 delete iStatusWindowTimeControl;
45 delete iInfoWindowControl;
52 void CMVSAppView::ConstructL(const TRect& aRect, CMVSVideoPlayAgent& aVideoPlayAgent)
54 //we need a window in which to place controls, so take ownership of one
57 //Set the extent of the control.
59 TRect fullRectWindow = Rect();
60 //vertical point co-ordinate
61 TInt statusPaneHeight = 4*(fullRectWindow.iTl.iY + fullRectWindow.iBr.iY)/5;
62 TInt halfLength = (fullRectWindow.iTl.iX + fullRectWindow.iBr.iX)/2;
63 TInt threeQuarterLength= 3*(fullRectWindow.iTl.iX + fullRectWindow.iBr.iX)/4;
65 //set the dimensions of our main window
66 TRect mainWindow(Rect());
67 mainWindow.iTl.iX = halfLength-115;
68 mainWindow.iBr.iY = statusPaneHeight;
70 iMainWindowControl = CMVSVideoControl::NewL(aVideoPlayAgent, 0, Window());
71 iMainWindowControl->SetExtent(mainWindow.iTl, mainWindow.Size());
73 //set the dimensions of our status window
74 TRect statusWindowFName = fullRectWindow;
75 statusWindowFName.iTl.iY = statusPaneHeight;
76 statusWindowFName.iBr.iX = halfLength;
78 //now construct our status window filename control
79 iStatusWindowFNameControl = CMVSFileControl::NewL(*this, statusWindowFName,
81 //set the dimensions of our state window
82 TRect statusWindowState = fullRectWindow;
83 statusWindowState.iTl.iX = halfLength;
84 statusWindowState.iTl.iY = statusPaneHeight;
85 statusWindowState.iBr.iX = threeQuarterLength;
87 //now construct our status window state control
88 iStatusWindowStateControl = CMVSStateControl::NewL(*this, statusWindowState,
91 //set the dimensions of our timer window
92 TRect statusWindowTime = fullRectWindow;
93 statusWindowTime.iTl.iX = threeQuarterLength;
94 statusWindowTime.iTl.iY = statusPaneHeight;
96 //now construct our status window timer control
97 iStatusWindowTimeControl = CMVSTimeControl::NewL(*this, statusWindowTime,
99 TRect infoWindow = fullRectWindow;
101 infoWindow.iBr.iX= halfLength-115;
102 infoWindow.iBr.iY =statusPaneHeight-15;
103 iInfoWindowControl = CMVSInfoControl::NewL(*this,infoWindow,KNullDesC);
104 iInfoWindowControl->SetParent(this);
105 //now activate the control.
107 // construct and draw the progress bar
108 iProgress = new (ELeave) CEikProgressInfo();
110 TResourceReader reader;
111 iEikonEnv->CreateResourceReaderLC(reader, R_CLIP_PROGRESSINFO);
112 iProgress->ConstructFromResourceL(reader);
113 iProgress->SetContainerWindowL(*this);
114 iProgress->SetExtent(TPoint(fullRectWindow.iTl.iX+ (fullRectWindow.iBr.iX/20),statusPaneHeight-10),TSize((fullRectWindow.iBr.iX - fullRectWindow.iTl.iX - (fullRectWindow.iBr.iX/10) ),10));
115 iProgress->SetAndDraw(0);
116 CleanupStack::PopAndDestroy();
121 void CMVSAppView::SetClipLength(TInt& aClipLen)
123 iClipLength = aClipLen;
127 //CountComponentControls()
129 // Implemented by a view with more than one control so that a call to
130 // DrawNow successfully draws all four component controls.
132 TInt CMVSAppView::CountComponentControls() const
134 return 6; //we have six controls
138 // To handle the Pointer events on the Progress Bar
140 void CMVSAppView::HandlePointerEventL(const TPointerEvent &aPointerEvent)
143 TRect rect = iProgress->Rect();
144 if( (aPointerEvent.iPosition.iX>=rect.iTl.iX && aPointerEvent.iPosition.iX<=rect.iBr.iX) &&
145 (aPointerEvent.iPosition.iY>=rect.iTl.iY && aPointerEvent.iPosition.iY<=rect.iBr.iY) )
147 TInt pos = aPointerEvent.iPosition.iX - rect.iTl.iX;
148 switch(aPointerEvent.iType)
150 case TPointerEvent::EButton1Down:
152 case TPointerEvent::EDrag:
154 iProgress->SetAndDraw(pos);
157 case TPointerEvent::EButton1Up:
159 TInt progToDraw = pos* (static_cast<double>(200)/(rect.iBr.iX -rect.iTl.iX));
160 iProgress->SetAndDraw(progToDraw+1);
161 clipPos = (progToDraw+1) *(static_cast<double>(iClipLength)/200);
162 TTimeIntervalMicroSeconds clipTime(clipPos);
163 static_cast<CMVSAppUi*>(CEikonEnv::Static()->EikAppUi())->SetPosition(clipTime);
171 CCoeControl::HandlePointerEventL(aPointerEvent);
177 // Updates the Audion play progress
179 void CMVSAppView::UpdatePlayProgress(TTimeIntervalMicroSeconds& aPos)
181 TInt curPos = I64INT(aPos.Int64());
182 TInt percent = curPos*(static_cast<double>(100)/iClipLength);
183 TInt progressPos = percent*2;
184 iProgress->SetAndDraw(progressPos+1);
188 // Reset the Progress to ) and redraw
190 void CMVSAppView::ResetProgressBar()
192 iProgress->SetAndDraw(0);
195 //ComponentControl(...)
197 // Returns the control by index. The counting sequence goes left to right, top
200 CCoeControl* CMVSAppView::ComponentControl(TInt aIndex) const
204 case 0: return iMainWindowControl;
205 case 1: return iStatusWindowFNameControl;
206 case 2: return iStatusWindowStateControl;
207 case 3: return iStatusWindowTimeControl;
208 case 4: return iInfoWindowControl;
209 case 5: return iProgress;
218 // class CMVSFileControl
225 //NewL(...) *** This method can LEAVE ***
227 // Factory contructor, initialises a control based on the rectangle provided.
229 CMVSFileControl* CMVSFileControl::NewL(const CCoeControl& aContainer,
233 CMVSFileControl* self=new(ELeave) CMVSFileControl;
234 CleanupStack::PushL(self);
235 self->ConstructL(aContainer, aRect, aText);
242 //ContructL(...) *** This method can LEAVE ***
245 void CMVSFileControl::ConstructL(const CCoeControl& aContainer,
246 const TRect& aRect, const TDesC& aText)
248 SetContainerWindowL(aContainer);
252 //Activate the control
260 // Constructor, does nothing. Private to prevent it being called.
262 CMVSFileControl::CMVSFileControl()
272 CMVSFileControl::~CMVSFileControl()
278 //Draw the FileName Display Window
279 void CMVSFileControl::Draw(const TRect& /*aRect*/) const
281 //Establish a Graphics Context
282 CWindowGc& gc=SystemGc();
284 //Establish a drawing rectangle
287 //Move in 2 pixels each side to give a white border
291 gc.SetPenStyle(CGraphicsContext::ENullPen);
292 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
293 gc.SetBrushColor(KRgbDarkGray);
295 //Draw a blank rectangle
298 //Fill in the border-regions
299 DrawUtils::DrawBetweenRects(gc, Rect(), rect);
301 //Change the pen colour to black
302 gc.SetPenStyle(CGraphicsContext::ESolidPen);
303 gc.SetPenColor(KRgbWhite);
305 //Set the fill colour to 'no fill'
306 gc.SetBrushStyle(CGraphicsContext::ENullBrush);
308 //Draw a rectangle (transparent with a black border)
312 const CFont* appFont = iEikonEnv->AnnotationFont();
313 DrawOtherWindows(gc,rect,appFont);
320 //DrawOtherWindows(...)
322 // Draw the text in a central position in the window.
324 void CMVSFileControl::DrawOtherWindows(CGraphicsContext& aGc,
325 const TRect& aDeviceRect,
326 const CFont* aFont) const
328 //Set up the pen and brush colours
329 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
330 aGc.SetBrushColor(KRgbGray);
332 aGc.SetPenStyle(CGraphicsContext::ESolidPen);
333 aGc.SetPenColor(KRgbWhite);
338 //Set the baseline to be half the height of the rectangle + half
339 //the height of the font
340 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2;
343 //__ASSERT_ALWAYS(iText != NULL, User::Panic(KNullPtr, KNAPanicNullPointer));
344 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter);
350 void CMVSFileControl::SetTextL(const TDesC& aText)
352 HBufC* text=aText.AllocL();
360 // Returns the window defined by this object.
361 TRect& CMVSFileControl::Window()
370 // class CMVSStateControl
377 //NewL(...) *** This method can LEAVE ***
379 // Factory contructor, initialises a control based on the rectangle provided.
381 CMVSStateControl* CMVSStateControl::NewL(const CCoeControl& aContainer,
385 CMVSStateControl* self=new(ELeave) CMVSStateControl;
386 CleanupStack::PushL(self);
387 self->ConstructL(aContainer, aRect, aText);
395 //ContructL(...) *** This method can LEAVE ***
398 void CMVSStateControl::ConstructL(const CCoeControl& aContainer,
399 const TRect& aRect, const TDesC& aText)
401 SetContainerWindowL(aContainer);
406 //Activate the control
415 // Constructor, does nothing. Private to prevent it being called.
417 CMVSStateControl::CMVSStateControl()
427 CMVSStateControl::~CMVSStateControl()
435 //For Displaying the state
436 void CMVSStateControl::Draw(const TRect& /*aRect*/) const
438 //Establish a Graphics Context
439 CWindowGc& gc=SystemGc();
441 //Establish a drawing rectangle
444 //Move in 2 pixels each side to give a white border
448 gc.SetPenStyle(CGraphicsContext::ENullPen);
449 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
450 gc.SetBrushColor(KRgbDarkGray);
452 //Draw a blank rectangle
455 //Fill in the border-regions
456 DrawUtils::DrawBetweenRects(gc, Rect(), rect);
458 //Change the pen colour to black
459 gc.SetPenStyle(CGraphicsContext::ESolidPen);
460 gc.SetPenColor(KRgbWhite);
462 //Set the fill colour to 'no fill'
463 gc.SetBrushStyle(CGraphicsContext::ENullBrush);
465 //Draw a rectangle (transparent with a black border)
469 const CFont* appFont = iEikonEnv->AnnotationFont();
470 DrawOtherWindows(gc,rect,appFont);
478 //DrawOtherWindows(...)
480 // Draw the text in a central position in the window.
482 void CMVSStateControl::DrawOtherWindows(CGraphicsContext& aGc,
483 const TRect& aDeviceRect,
484 const CFont* aFont) const
486 //Set up the pen and brush colours
487 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
488 aGc.SetBrushColor(KRgbGray);
490 aGc.SetPenStyle(CGraphicsContext::ESolidPen);
491 aGc.SetPenColor(KRgbWhite);
496 //Set the baseline to be half the height of the rectangle + half
497 //the height of the font
498 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2;
501 //__ASSERT_ALWAYS(iText != NULL, User::Panic(KNullPtr, KNAPanicNullPointer));
502 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter);
508 void CMVSStateControl::SetTextL(const TDesC& aText)
510 HBufC* text=aText.AllocL();
519 // Returns the window defined by this object.
520 TRect& CMVSStateControl::Window()
529 // class CMVSTimeControl
536 //NewL(...) *** This method can LEAVE ***
538 // Factory contructor, initialises a control based on the rectangle provided.
540 CMVSTimeControl* CMVSTimeControl::NewL(const CCoeControl& aContainer,
544 CMVSTimeControl* self=new(ELeave) CMVSTimeControl;
545 CleanupStack::PushL(self);
546 self->ConstructL(aContainer, aRect, aText);
554 //ContructL(...) *** This method can LEAVE ***
557 void CMVSTimeControl::ConstructL(const CCoeControl& aContainer,
558 const TRect& aRect, const TDesC& aText)
560 SetContainerWindowL(aContainer);
565 //Activate the control
574 // Constructor, does nothing. Private to prevent it being called.
576 CMVSTimeControl::CMVSTimeControl()
586 CMVSTimeControl::~CMVSTimeControl()
599 void CMVSTimeControl::Draw(const TRect& /*aRect*/) const
601 //Establish a Graphics Context
602 CWindowGc& gc=SystemGc();
604 //Establish a drawing rectangle
607 //Move in 2 pixels each side to give a white border
611 gc.SetPenStyle(CGraphicsContext::ENullPen);
612 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
613 gc.SetBrushColor(KRgbDarkGray);
615 //Draw a blank rectangle
618 //Fill in the border-regions
619 DrawUtils::DrawBetweenRects(gc, Rect(), rect);
621 //Change the pen colour to black
622 gc.SetPenStyle(CGraphicsContext::ESolidPen);
623 gc.SetPenColor(KRgbWhite);
625 //Set the fill colour to 'no fill'
626 gc.SetBrushStyle(CGraphicsContext::ENullBrush);
628 //Draw a rectangle (transparent with a black border)
632 const CFont* appFont = iEikonEnv->AnnotationFont();
633 DrawOtherWindows(gc,rect,appFont);
641 //DrawOtherWindows(...)
643 // Draw the text in a central position in the window.
645 void CMVSTimeControl::DrawOtherWindows(CGraphicsContext& aGc,
646 const TRect& aDeviceRect,
647 const CFont* aFont) const
649 //Set up the pen and brush colours
650 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
651 aGc.SetBrushColor(KRgbGray);
653 aGc.SetPenStyle(CGraphicsContext::ESolidPen);
654 aGc.SetPenColor(KRgbWhite);
662 TInt rWidth = aDeviceRect.iBr.iX - aDeviceRect.iTl.iX;
663 TInt rHeight = aDeviceRect.iBr.iY - aDeviceRect.iTl.iY;
665 TRect rect1(aDeviceRect.iTl,TSize(rWidth, rHeight/2));
666 TRect rect2(TPoint(aDeviceRect.iTl.iX, aDeviceRect.iTl.iY + rHeight/2),TSize(rWidth, rHeight/2));
668 TInt baseline = rect1.Height();
670 aGc.DrawText(*iText, rect1, baseline - 2, CGraphicsContext::ECenter);
672 aGc.DrawText(*iText2, rect2, baseline - 3 , CGraphicsContext::ECenter);
676 //Set the baseline to be half the height of the rectangle + half
677 //the height of the font
678 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2;
681 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter);
688 void CMVSTimeControl::SetTextL(const TDesC& aText)
690 HBufC* text=aText.AllocL();
696 void CMVSTimeControl::SetText2L(const TDesC& aText)
698 HBufC* text=aText.AllocL();
704 void CMVSTimeControl::ResetText2L()
712 // Returns the window defined by this object.
713 TRect& CMVSTimeControl::Window()
721 // class CMVSInfoControl
728 //NewL(...) *** This method can LEAVE ***
730 // Factory contructor, initialises a control based on the rectangle provided.
732 CMVSInfoControl* CMVSInfoControl::NewL(const CCoeControl& aContainer,
736 CMVSInfoControl* self=new(ELeave) CMVSInfoControl;
737 CleanupStack::PushL(self);
738 self->ConstructL(aContainer, aRect, aText);
746 //ContructL(...) *** This method can LEAVE ***
749 void CMVSInfoControl::ConstructL(const CCoeControl& aContainer,
750 const TRect& aRect, const TDesC& aText)
752 SetContainerWindowL(aContainer);
756 //Activate the control
765 // Constructor, does nothing. Private to prevent it being called.
767 CMVSInfoControl::CMVSInfoControl()
777 CMVSInfoControl::~CMVSInfoControl()
787 void CMVSInfoControl::Draw(const TRect& /*aRect*/) const
789 //Establish a Graphics Context
790 CWindowGc& gc=SystemGc();
792 //Establish a drawing rectangle
795 //Move in 2 pixels each side to give a white border
799 gc.SetPenStyle(CGraphicsContext::ENullPen);
800 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
801 gc.SetBrushColor(KRgbDarkGray);
803 //Draw a blank rectangle
806 //To cover Progress Bar area
807 TRect ProgRect = rect;
808 TInt statusPaneHeight = 4*(Parent()->Rect().iTl.iY + Parent()->Rect().iBr.iY)/5;
809 ProgRect.iBr.iY = statusPaneHeight;
811 gc.DrawRect(ProgRect);
813 //Fill in the border-regions
814 DrawUtils::DrawBetweenRects(gc, Rect(), rect);
816 //Change the pen colour to black
817 gc.SetPenStyle(CGraphicsContext::ESolidPen);
818 gc.SetPenColor(KRgbWhite);
820 //Set the fill colour to 'no fill'
821 gc.SetBrushStyle(CGraphicsContext::ENullBrush);
823 //Draw a rectangle (transparent with a black border)
827 const CFont* appFont = iEikonEnv->AnnotationFont();
828 DrawMainWindow(gc,rect,appFont);
834 void CMVSInfoControl::DrawMainWindow(CGraphicsContext& aGc,
835 const TRect& /*aDeviceRect*/,
836 const CFont* aFont) const
838 //Set up a brush and pen
839 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
840 aGc.SetBrushColor(KRgbDarkGray);
842 aGc.SetPenStyle(CGraphicsContext::ESolidPen);
843 aGc.SetPenColor(KRgbWhite);
848 //The 'step' by which we move down to get to a fresh line in
850 TInt distToNextBaseline = (aFont->AscentInPixels()/2)*3;
852 //The main window text
853 TPtrC mainWindowText;
854 mainWindowText.Set(iText->Des());
856 //The escape sequence
857 _LIT(KDollarDollar, "$$");
860 TInt x = 10; //The left hand side of the rectangle
861 TInt y = 10; //The top of the rectangle.
863 //Whilst we can find a '$$' in the string
864 while(mainWindowText.Find(KDollarDollar) != KErrNotFound)
867 TInt pos = mainWindowText.Find(KDollarDollar);
868 TPtrC text(mainWindowText.Mid(0,pos));
870 //define the rectangle for this text
871 TInt height = aFont->HeightInPixels();
872 TInt width = aFont->TextWidthInPixels( text );
873 rect.SetRect( x, y, x + width, y + height );
876 aGc.DrawText(text, rect, height - aFont->DescentInPixels(),
877 CGraphicsContext::ELeft);
879 //delete text upto and including '$$'
880 text.Set(mainWindowText.Right(mainWindowText.Length() - (pos+2)));
881 mainWindowText.Set(text);
883 //adjust the baseline offset
884 y+=distToNextBaseline;
892 void CMVSInfoControl::SetTextL(const TDesC& aText)
894 HBufC* text=aText.AllocL();
903 // Returns the window defined by this object.
904 TRect& CMVSInfoControl::Window()