Changeset 31

Show
Ignore:
Timestamp:
04/11/06 14:53:06 (2 years ago)
Author:
jordi
Message:

The presenter is now able to control the Zoom: In, Out, toFit and toWidth.
The ZoomIn? and ZoomOut? controls also get sensitived depending if we can zoom in/out or not.

This puts an end to the presenter. I still need to check why compiling MainPterTest?.cxx takes this insane amount of time.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r29 r31  
    4848            virtual void setGoToPageText (const gchar *text) = 0; 
    4949            virtual const gchar *getGoToPageText (void) = 0; 
     50            virtual void getPageViewSize (gint *width, gint *height) = 0; 
    5051            virtual void setTitle (const gchar *title) = 0; 
    5152 
  • trunk/src/MainPter.cxx

    r30 r31  
    306306 
    307307/// 
     308/// @brief The "Zoom Fit Best" was activated. 
     309/// 
     310void 
     311MainPter::zoomFitActivated (void) 
     312{ 
     313    g_assert ( NULL != m_Document && "Tried to zoom fit a NULL document."); 
     314 
     315    gint width; 
     316    gint height; 
     317    getView ().getPageViewSize (&width, &height); 
     318    m_Document->zoomToFit (width, height); 
     319    showPage (); 
     320} 
     321 
     322/// 
     323/// @brief The "Zoom In" was activated. 
     324/// 
     325void 
     326MainPter::zoomInActivated (void) 
     327{ 
     328    g_assert ( NULL != m_Document && "Tried to zoom in a NULL document."); 
     329 
     330    m_Document->zoomIn (); 
     331    showPage (); 
     332} 
     333 
     334/// 
     335/// @brief The "Zoom Out" was activated. 
     336/// 
     337void 
     338MainPter::zoomOutActivated (void) 
     339{ 
     340    g_assert ( NULL != m_Document && "Tried to zoom out a NULL document."); 
     341 
     342    m_Document->zoomOut (); 
     343    showPage (); 
     344} 
     345 
     346/// 
     347/// @brief The "Zoom Fit Width" was activated. 
     348/// 
     349void 
     350MainPter::zoomWidthActivated (void) 
     351{ 
     352    g_assert ( NULL != m_Document && "Tried to zoom width a NULL document."); 
     353 
     354    gint width; 
     355    gint height; 
     356    getView ().getPageViewSize (&width, &height); 
     357    m_Document->zoomToWidth (width); 
     358    showPage (); 
     359} 
     360 
     361/// 
    308362/// @brief Shows the current page. 
    309363/// 
     
    332386    view.sensitiveGoToLastPage (m_Document->getNumPages() > currentPage); 
    333387    view.sensitiveGoToNextPage (m_Document->getNumPages() > currentPage); 
     388    // And the zoom sentitivity. 
     389    view.sensitiveZoomIn (m_Document->canZoomIn ()); 
     390    view.sensitiveZoomOut (m_Document->canZoomOut ()); 
    334391     
    335392    DocumentPage *page = m_Document->renderPage (); 
  • trunk/src/MainPter.h

    r30 r31  
    4040            void rotateLeftActivated (void); 
    4141            void rotateRightActivated (void); 
     42            void zoomFitActivated (void); 
     43            void zoomInActivated (void); 
     44            void zoomOutActivated (void); 
     45            void zoomWidthActivated (void); 
    4246 
    4347        protected: 
  • trunk/tests/DumbDocument.cxx

    r30 r31  
    7474DumbDocument::getPageSize (gdouble *width, gdouble *height) 
    7575{ 
    76     *width = 100; 
    77     *height = 250; 
     76    if ( 0 == getRotation () || 270 == getRotation () ) 
     77    { 
     78        *width = 100; 
     79        *height = 250; 
     80    } 
     81    else 
     82    { 
     83        *width = 250; 
     84        *height = 100; 
     85    } 
    7886} 
    7987 
  • trunk/tests/DumbMainView.cxx

    r29 r31  
    145145 
    146146void 
     147DumbMainView::getPageViewSize (gint *width, gint *height) 
     148{ 
     149    *width = 75; 
     150    *height = 50; 
     151} 
     152 
     153void 
    147154DumbMainView::setTitle (const gchar *title) 
    148155{ 
  • trunk/tests/DumbMainView.h

    r29 r31  
    4040            void sensitiveZoomWidth (gboolean sensitive); 
    4141            const gchar *getGoToPageText (void); 
     42            void getPageViewSize (gint *width, gint *height); 
    4243            void setTotalPages (gint pages); 
    4344            void setGoToPageText (const char *text); 
  • trunk/tests/MainPterTest.cxx

    r30 r31  
    425425    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    426426    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    427     CPPUNIT_ASSERT_EQUAL (m_Document->getRotation (), 0); 
     427    CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 
    428428 
    429429    m_MainPter->rotateRightActivated ();  
    430430    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    431431    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    432     CPPUNIT_ASSERT_EQUAL (m_Document->getRotation (), 90); 
     432    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
    433433 
    434434    m_MainPter->rotateLeftActivated ();  
    435435    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    436436    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    437     CPPUNIT_ASSERT_EQUAL (m_Document->getRotation (), 0); 
    438 } 
     437    CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 
     438} 
     439 
     440/// 
     441/// @brief Tests page's zoom. 
     442/// 
     443/// The DumbDocument has a fixed size of 100x250 pixels and the DumbMainView 
     444/// has a fixed pageView of 75x50. We will make sure that getting to the max 
     445/// ZoomIn unsensitives the ZoomIn button. The same for the ZoomOut. 
     446/// 
     447/// Then will test Zoom Fit and Zoom Width with two different rotations. 
     448/// 
     449void 
     450MainPterTest::pageZoom () 
     451{ 
     452    m_View->setOpenFileName ("/tmp/test.pdf"); 
     453    m_MainPter->openFileActivated (); 
     454    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     455    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     456    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), 0.0001f); 
     457 
     458    m_MainPter->zoomInActivated (); 
     459    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     460    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     461    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), 0.0001f); 
     462 
     463    m_MainPter->zoomOutActivated (); 
     464    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     465    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     466    CPPUNIT_ASSERT_EQUAL (1.0f, m_Document->getZoom ()); 
     467    
     468    CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 
     469    CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); 
     470    // Make sure we go to the last zoom level. 
     471    for (int count = 0 ; count < 20 ; count++) 
     472    { 
     473        m_MainPter->zoomInActivated (); 
     474    } 
     475    CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); 
     476    CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); 
     477    for (int count = 0 ; count < 40 ; count ++) 
     478    { 
     479        m_MainPter->zoomOutActivated (); 
     480    } 
     481    CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 
     482    CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 
     483 
     484    // OK, now try to zoom width. Since rotation is 0 
     485    // the zoom level should be 50/250 = 0.2 
     486    m_MainPter->zoomFitActivated (); 
     487    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     488    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     489    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2f, m_Document->getZoom (), 0.0001f); 
     490    // For the width it should be 75/100 = 0.75 
     491    m_MainPter->zoomWidthActivated (); 
     492    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     493    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     494    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75f, m_Document->getZoom (), 0.0001f); 
     495 
     496    // Now rotate and try again. 
     497    m_MainPter->rotateRightActivated ();  
     498    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     499    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     500    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
     501     
     502    // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
     503    m_MainPter->zoomFitActivated (); 
     504    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3f, m_Document->getZoom (), 0.0001f); 
     505    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     506    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     507    // For the width it should be 75/250 = 0.3 also. 
     508    m_MainPter->zoomWidthActivated (); 
     509    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3f, m_Document->getZoom (), 0.0001f); 
     510    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     511    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     512} 
  • trunk/tests/MainPterTest.h

    r30 r31  
    3535        CPPUNIT_TEST (pageNavigation); 
    3636        CPPUNIT_TEST (pageRotate); 
     37        CPPUNIT_TEST (pageZoom); 
    3738        CPPUNIT_TEST_SUITE_END(); 
    3839 
     
    5051            void pageNavigation (void); 
    5152            void pageRotate (void); 
     53            void pageZoom (void); 
    5254 
    5355        private: