Show
Ignore:
Timestamp:
04/20/06 13:09:22 (3 years ago)
Author:
jordi
Message:

The MainPter? now resizes the page shown if the zoom to width or zoom to fit, that now are toggle actions, are activated. The view also tells to the presenter when the scroll window has resized, so it can calculate the new page.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/MainPterTest.cxx

    r98 r99  
    559559    m_MainPter->openFileActivated (); 
    560560    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    561     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    562561    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
    563562 
    564563    // OK, now try to zoom width. Since rotation is 0 
    565564    // the zoom level should be 75/100 = 0.75 
    566     m_MainPter->zoomWidthActivated (); 
    567     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    568     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     565    m_MainPter->zoomWidthActivated (TRUE); 
     566    CPPUNIT_ASSERT (m_View->isZoomToWidthActive ()); 
     567    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    569568    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
     569 
     570    // Now change the view size. We do this calling the main presenter's 
     571    // function instead of the view, because the view here don't have anything 
     572    // to do. 
     573    // The new zoom should be 50/100 = 0.5 
     574    m_MainPter->pageViewResized (50, 50); 
     575    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     576    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.5, m_Document->getZoom (), 0.0001); 
     577     
     578    m_MainPter->pageViewResized (75, 50); 
     579    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     580    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
     581 
     582    // If we desactive the zoom to width, no resizing changes the 
     583    // zoom. 
     584    m_MainPter->zoomWidthActivated (FALSE); 
     585    CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); 
     586    m_MainPter->pageViewResized (50, 50); 
     587    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     588    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
     589    m_MainPter->pageViewResized (100, 50); 
     590    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     591    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
     592 
     593    // Now rotate and try again. 
     594    m_MainPter->rotateRightActivated ();  
     595    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     596    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());     
     597    // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
     598    m_MainPter->zoomWidthActivated (TRUE); 
     599    CPPUNIT_ASSERT (m_View->isZoomToWidthActive ()); 
     600    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     601    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     602    // Resizing. 50/250 = 0.2 
     603    m_MainPter->pageViewResized (50, 50); 
     604    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     605    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
     606 
     607    // Changing any of the zoom in or zoom out features should make the  
     608    // zoom to width not being active. 
     609    m_MainPter->zoomInActivated (); 
     610    CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); 
     611    m_MainPter->zoomWidthActivated (TRUE); 
     612    m_MainPter->zoomOutActivated (); 
     613    CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); 
     614} 
     615 
     616/// 
     617/// @brief Tests page's zoom to fit 
     618/// 
     619void 
     620MainPterTest::pageZoomFit () 
     621{ 
     622    m_View->setOpenFileName ("/tmp/test.pdf"); 
     623    m_MainPter->openFileActivated (); 
     624    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     625    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     626 
     627    // OK, now try to zoom to fit. Since rotation is 0 
     628    // the zoom level should be 50/250 = 0.2 
     629    m_MainPter->zoomFitActivated (TRUE); 
     630    CPPUNIT_ASSERT (m_View->isZoomToFitActive ()); 
     631    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     632    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
     633 
     634    // Resizing the view size. 100/250 = 0.4 
     635    m_MainPter->pageViewResized (100, 100); 
     636    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     637    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.4, m_Document->getZoom (), 0.0001); 
     638    m_MainPter->pageViewResized (100, 50); 
     639    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     640    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
     641 
     642    // Desactivating the zoom to fit. 
     643    m_MainPter->zoomFitActivated (FALSE); 
     644    CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); 
     645    m_MainPter->pageViewResized (100, 100); 
     646    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     647    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
     648    m_MainPter->pageViewResized (100, 50); 
     649    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     650    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    570651 
    571652    // Now rotate and try again. 
     
    575656     
    576657    // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
    577     m_MainPter->zoomWidthActivated (); 
     658    m_MainPter->zoomFitActivated (TRUE); 
     659    CPPUNIT_ASSERT (m_View->isZoomToFitActive ()); 
    578660    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    579661    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    580 } 
    581  
    582 /// 
    583 /// @brief Tests page's zoom to fit 
    584 /// 
    585 void 
    586 MainPterTest::pageZoomFit () 
    587 { 
    588     m_View->setOpenFileName ("/tmp/test.pdf"); 
    589     m_MainPter->openFileActivated (); 
    590     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    591     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    592     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
    593  
    594     // OK, now try to zoom to fit. Since rotation is 0 
    595     // the zoom level should be 50/250 = 0.2 
    596     m_MainPter->zoomFitActivated (); 
    597     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    598     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    599     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    600  
    601     // Now rotate and try again. 
    602     m_MainPter->rotateRightActivated ();  
    603     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    604     CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
     662    // 100/250 = 0.4 
     663    m_MainPter->pageViewResized (100, 100); 
     664    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.4, m_Document->getZoom (), 0.0001); 
     665    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    605666     
    606     // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
    607     m_MainPter->zoomFitActivated (); 
    608     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    609     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     667    // Changing any of the zoom in or zoom out features should make the  
     668    // zoom to fit not being active. 
     669    m_MainPter->zoomInActivated (); 
     670    CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); 
     671    m_MainPter->zoomFitActivated (TRUE); 
     672    m_MainPter->zoomOutActivated (); 
     673    CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); 
    610674} 
    611675 
     
    626690    m_MainPter->goToNextPageActivated (); 
    627691    m_MainPter->rotateRightActivated ();  
    628     m_MainPter->zoomWidthActivated (); 
     692    m_MainPter->zoomWidthActivated (TRUE); 
    629693    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
    630694    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     
    662726    m_MainPter->goToNextPageActivated (); 
    663727    m_MainPter->rotateRightActivated ();  
    664     m_MainPter->zoomWidthActivated (); 
     728    m_MainPter->zoomWidthActivated (TRUE); 
    665729    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
    666730    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     
    702766    m_MainPter->goToNextPageActivated (); 
    703767    m_MainPter->rotateRightActivated ();  
    704     m_MainPter->zoomWidthActivated (); 
     768    m_MainPter->zoomWidthActivated (TRUE); 
    705769    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
    706770    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());