Changeset 63

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

The presenter now can reload a document. To do so I had to add the setters for IDocument's zoom and rotation (they should've been from the start, but...)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/IDocument.cxx

    r60 r63  
    654654 
    655655/// 
     656/// @brief Sets the current rotation degress. 
     657/// 
     658/// @param rotation The rotation in positive degrees.  
     659///                 If the parameter is greater than 360 degrees, its set 
     660///                 between 0 and 360 as a result of @a rotation % 360. 
     661/// 
     662void 
     663IDocument::setRotation (gint rotation) 
     664{ 
     665    m_Rotation = (rotation % 360); 
     666} 
     667 
     668/// 
    656669/// @brief Rotates 90 to the left. 
    657670/// 
     
    661674IDocument::rotateLeft () 
    662675{ 
    663     m_Rotation = (m_Rotation - 90) % 360; 
    664     if ( m_Rotation < 0 ) 
    665     { 
    666         m_Rotation += 360; 
    667     } 
     676    gint rotation = (getRotation () - 90); 
     677    if ( rotation < 0 ) 
     678    { 
     679        rotation += 360; 
     680    } 
     681    setRotation (rotation); 
    668682} 
    669683 
     
    676690IDocument::rotateRight () 
    677691{ 
    678     m_Rotation = (m_Rotation + 90) % 360
     692    setRotation (getRotation () + 90)
    679693} 
    680694 
     
    706720/// @return The current zoom or scale level. 
    707721/// 
    708 gfloat 
     722gdouble 
    709723IDocument::getZoom (void) 
    710724{ 
    711725    return m_Scale; 
     726} 
     727 
     728/// 
     729/// @brief Sets the current zoom. 
     730/// 
     731/// @param zoom The new zoom level. 
     732/// 
     733void 
     734IDocument::setZoom (gdouble zoom) 
     735{ 
     736    m_Scale = zoom; 
    712737} 
    713738 
     
    725750    if (canZoomIn ()) 
    726751    { 
    727         m_Scale *= ZOOM_IN_FACTOR
     752        setZoom (getZoom () * ZOOM_IN_FACTOR)
    728753    } 
    729754} 
     
    742767    if (canZoomOut ()) 
    743768    { 
    744         m_Scale *= ZOOM_OUT_FACTOR
     769        setZoom (getZoom () * ZOOM_OUT_FACTOR)
    745770    } 
    746771} 
     
    766791    gdouble widthScale = (gdouble)width / pageWidth; 
    767792    gdouble heightScale = (gdouble)height / pageHeight; 
    768     m_Scale = MIN (widthScale, heightScale); 
     793    setZoom (MIN (widthScale, heightScale)); 
    769794} 
    770795 
     
    784809 
    785810    getPageSize (&pageWidth, &pageHeight); 
    786     m_Scale = (gdouble)width / pageWidth
    787 } 
     811    setZoom ((gdouble)width / pageWidth)
     812} 
  • trunk/src/IDocument.h

    r58 r63  
    208208 
    209209            gint getRotation (void); 
     210            void setRotation (gint rotation); 
    210211            void rotateLeft (void); 
    211212            void rotateRight (void); 
     
    213214            gboolean canZoomIn (void); 
    214215            gboolean canZoomOut (void); 
    215             gfloat getZoom (void); 
     216            gdouble getZoom (void); 
     217            void setZoom (gdouble zoom); 
    216218            void zoomIn (void); 
    217219            void zoomOut (void); 
  • trunk/src/MainPter.cxx

    r62 r63  
    6464/// set the window's title and tell the main view to show itself. 
    6565/// 
    66 void 
    67 MainPter::setInitialState () 
     66/// @param canShowPage Set to TRUE if the application should show the page  
     67///                    after setting the initial state or not. This is useful  
     68///                    when reloading the document, because after loading we  
     69///                    want to set the page, rotation and zoom again and then 
     70///                    show the page again. 
     71/// 
     72void 
     73MainPter::setInitialState (gboolean canShowPage) 
    6874{ 
    6975    g_assert ( NULL != m_Document && "The document is NULL."); 
     
    9096        view.sensitiveZoomWidth (TRUE); 
    9197        view.setTotalPages (m_Document->getNumPages ()); 
    92         showPage (); 
     98 
     99        if ( canShowPage ) 
     100        { 
     101            showPage (); 
     102        } 
    93103    } 
    94104    else 
     
    139149    // Now that the view is set, it's time to set the initial  
    140150    // state. 
    141     setInitialState (); 
     151    setInitialState (TRUE); 
    142152} 
    143153 
     
    235245    IMainView &view = getView (); 
    236246    gchar *fileName = view.openFileDialog (); 
    237     // if openFileDialog returns NULL, then the user cancelled the operation. 
     247    openDocument (fileName, TRUE); 
     248    g_free (fileName); 
     249
     250 
     251/// 
     252/// @brief The "Reload" was activated. 
     253/// 
     254/// Reloading is like opening the same file but the current page, rotation 
     255/// and zoom are maintained. 
     256/// 
     257void 
     258MainPter::reloadActivated () 
     259{     
     260    // Save the current document's state. 
     261    gint currentPage = m_Document->getCurrentPageNum (); 
     262    gint currentRotation = m_Document->getRotation (); 
     263    gdouble currentZoom = m_Document->getZoom (); 
     264    // Reopen the document. 
     265    openDocument (m_Document->getFileName (), FALSE); 
     266    // And restore the state 
     267    m_Document->setZoom (currentZoom); 
     268    m_Document->setRotation (currentRotation); 
     269    m_Document->goToPage (currentPage); 
     270    // Draw the document. 
     271    showPage (); 
     272
     273 
     274/// 
     275/// @brief The "Rotate Left" was activated. 
     276/// 
     277void 
     278MainPter::rotateLeftActivated () 
     279
     280    g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
     281 
     282    m_Document->rotateLeft (); 
     283    showPage (); 
     284
     285 
     286/// 
     287/// @brief The "Rotate Right" was activated. 
     288/// 
     289void 
     290MainPter::rotateRightActivated () 
     291
     292    g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
     293 
     294    m_Document->rotateRight (); 
     295    showPage (); 
     296
     297 
     298/// 
     299/// @brief The "Zoom Fit Best" was activated. 
     300/// 
     301void 
     302MainPter::zoomFitActivated (void) 
     303
     304    g_assert ( NULL != m_Document && "Tried to zoom fit a NULL document."); 
     305 
     306    gint width; 
     307    gint height; 
     308    getView ().getPageViewSize (&width, &height); 
     309    m_Document->zoomToFit (width, height); 
     310    showPage (); 
     311
     312 
     313/// 
     314/// @brief The "Zoom In" was activated. 
     315/// 
     316void 
     317MainPter::zoomInActivated (void) 
     318
     319    g_assert ( NULL != m_Document && "Tried to zoom in a NULL document."); 
     320 
     321    m_Document->zoomIn (); 
     322    showPage (); 
     323
     324 
     325/// 
     326/// @brief The "Zoom Out" was activated. 
     327/// 
     328void 
     329MainPter::zoomOutActivated (void) 
     330
     331    g_assert ( NULL != m_Document && "Tried to zoom out a NULL document."); 
     332 
     333    m_Document->zoomOut (); 
     334    showPage (); 
     335
     336 
     337/// 
     338/// @brief The "Zoom Fit Width" was activated. 
     339/// 
     340void 
     341MainPter::zoomWidthActivated (void) 
     342
     343    g_assert ( NULL != m_Document && "Tried to zoom width a NULL document."); 
     344 
     345    gint width; 
     346    gint height; 
     347    getView ().getPageViewSize (&width, &height); 
     348    m_Document->zoomToWidth (width); 
     349    showPage (); 
     350
     351 
     352/// 
     353/// @brief Opens a document. 
     354/// 
     355/// This function is called both by openFileActivated() and reloadActivated 
     356/// to open a document. 
     357/// 
     358/// @param fileName If be the name of the document to open. If it's 
     359///                 NULL then that means the user didn't wanted to 
     360///                 open a file, so this function won't do anything. 
     361/// @param canShowPage Set to TRUE if the application should show the page  
     362///                    after the loading or not. This is useful when reloading 
     363///                    the document, because after loading we want to set the 
     364///                    page, rotation and zoom again and then show the page. 
     365/// 
     366void 
     367MainPter::openDocument (const gchar *fileName, gboolean canShowPage) 
     368
     369    // if fileName is NULL, then the user cancelled the operation. 
    238370    // I don't need to do anything in this case. I'm only interested when 
    239371    // the user tried to open a file. 
     
    245377            // Now that the document has been loaded, just reset the initial 
    246378            // state. 
    247             setInitialState (); 
     379            setInitialState (canShowPage); 
    248380        } 
    249381        else 
     
    272404                { 
    273405                    // Phew, finally loaded. Set the initial state. 
    274                     setInitialState (); 
     406                    setInitialState (canShowPage); 
    275407                } 
    276408                else if ( NULL != password ) 
     
    293425            g_free (error); 
    294426        } 
    295         g_free (fileName); 
    296427    } 
    297428} 
    298429 
    299 /// 
    300 /// @brief The "Rotate Left" was activated. 
    301 /// 
    302 void 
    303 MainPter::rotateLeftActivated () 
    304 { 
    305     g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
    306  
    307     m_Document->rotateLeft (); 
    308     showPage (); 
    309 } 
    310  
    311 /// 
    312 /// @brief The "Rotate Right" was activated. 
    313 /// 
    314 void 
    315 MainPter::rotateRightActivated () 
    316 { 
    317     g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
    318  
    319     m_Document->rotateRight (); 
    320     showPage (); 
    321 } 
    322  
    323 /// 
    324 /// @brief The "Zoom Fit Best" was activated. 
    325 /// 
    326 void 
    327 MainPter::zoomFitActivated (void) 
    328 { 
    329     g_assert ( NULL != m_Document && "Tried to zoom fit a NULL document."); 
    330  
    331     gint width; 
    332     gint height; 
    333     getView ().getPageViewSize (&width, &height); 
    334     m_Document->zoomToFit (width, height); 
    335     showPage (); 
    336 } 
    337  
    338 /// 
    339 /// @brief The "Zoom In" was activated. 
    340 /// 
    341 void 
    342 MainPter::zoomInActivated (void) 
    343 { 
    344     g_assert ( NULL != m_Document && "Tried to zoom in a NULL document."); 
    345  
    346     m_Document->zoomIn (); 
    347     showPage (); 
    348 } 
    349  
    350 /// 
    351 /// @brief The "Zoom Out" was activated. 
    352 /// 
    353 void 
    354 MainPter::zoomOutActivated (void) 
    355 { 
    356     g_assert ( NULL != m_Document && "Tried to zoom out a NULL document."); 
    357  
    358     m_Document->zoomOut (); 
    359     showPage (); 
    360 } 
    361  
    362 /// 
    363 /// @brief The "Zoom Fit Width" was activated. 
    364 /// 
    365 void 
    366 MainPter::zoomWidthActivated (void) 
    367 { 
    368     g_assert ( NULL != m_Document && "Tried to zoom width a NULL document."); 
    369  
    370     gint width; 
    371     gint height; 
    372     getView ().getPageViewSize (&width, &height); 
    373     m_Document->zoomToWidth (width); 
    374     showPage (); 
    375 } 
    376430 
    377431/// 
  • trunk/src/MainPter.h

    r49 r63  
    4141            ~MainPter (void); 
    4242 
    43             void setInitialState (void);             
     43            void setInitialState (gboolean canShowPage);  
    4444            IMainView &getView (void); 
    4545            void setView (IMainView *view); 
     
    5151            void goToPreviousPageActivated (void); 
    5252            void openFileActivated (void); 
     53            void reloadActivated (void); 
    5354            void rotateLeftActivated (void); 
    5455            void rotateRightActivated (void); 
     
    5960 
    6061        protected: 
     62            void openDocument (const gchar *fileName, gboolean canShowPage); 
    6163            void showPage (void); 
    6264 
  • trunk/src/PDFDocument.cxx

    r61 r63  
    133133    setOutline (m_Outline, outline->getItems ()); 
    134134    // Set the current rotation angle and zoom level. 
    135     m_Rotation = 0
    136     m_Scale = 1.0f
     135    setRotation (0)
     136    setZoom (1.0f)
    137137    // Set the output device. 
    138138    delete m_OutputDevice; 
  • trunk/tests/DumbDocument.cxx

    r31 r63  
    6666                     "%s", IDocument::getErrorMessage (m_OpenError)); 
    6767    } 
    68     m_Rotation = 0
    69     m_Scale = 1.0f
     68    setRotation (0)
     69    setZoom (1.0f)
    7070    return m_Loaded; 
    7171} 
  • trunk/tests/MainPterTest.cxx

    r62 r63  
    288288} 
    289289 
     290 
    290291/// 
    291292/// @brief Test page navigation. 
     
    490491    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    491492    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    492     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), 0.0001f); 
     493    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
    493494 
    494495    m_MainPter->zoomInActivated (); 
    495496    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    496497    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    497     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), 0.0001f); 
     498    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2, m_Document->getZoom (), 0.0001); 
    498499 
    499500    m_MainPter->zoomOutActivated (); 
    500501    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    501502    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    502     CPPUNIT_ASSERT_EQUAL (1.0f, m_Document->getZoom ()); 
     503    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
    503504    
    504505    CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 
     
    523524    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    524525    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    525     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2f, m_Document->getZoom (), 0.0001f); 
     526    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    526527    // For the width it should be 75/100 = 0.75 
    527528    m_MainPter->zoomWidthActivated (); 
    528529    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    529530    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    530     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75f, m_Document->getZoom (), 0.0001f); 
     531    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
    531532 
    532533    // Now rotate and try again. 
     
    537538    // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
    538539    m_MainPter->zoomFitActivated (); 
    539     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3f, m_Document->getZoom (), 0.0001f); 
     540    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    540541    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    541542    // For the width it should be 75/250 = 0.3 also. 
    542543    m_MainPter->zoomWidthActivated (); 
    543     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3f, m_Document->getZoom (), 0.0001f); 
    544     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    545 
     544    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     545    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     546
     547 
     548/// 
     549/// @brief Test to reload a normal document. 
     550/// 
     551/// A "normal" document is a non encrypted document. The document 
     552/// should then be viewed at the same page, scale an rotation. 
     553/// 
     554void 
     555MainPterTest::reloadNormal () 
     556
     557    m_View->setOpenFileName ("/tmp/test.pdf"); 
     558    m_MainPter->openFileActivated (); 
     559    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     560 
     561    m_MainPter->goToNextPageActivated (); 
     562    m_MainPter->rotateRightActivated ();  
     563    m_MainPter->zoomWidthActivated (); 
     564    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     565    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     566    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     567    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     568    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     569 
     570    // Reload the document. 
     571    m_MainPter->reloadActivated (); 
     572    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     573    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     574    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     575    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     576    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     577
  • trunk/tests/MainPterTest.h

    r54 r63  
    3737        CPPUNIT_TEST (pageRotate); 
    3838        CPPUNIT_TEST (pageZoom); 
     39        CPPUNIT_TEST (reloadNormal); 
    3940        CPPUNIT_TEST_SUITE_END(); 
    4041 
     
    5455            void pageRotate (void); 
    5556            void pageZoom (void); 
     57            void reloadNormal (void); 
    5658 
    5759        private: