Changeset 63
- Timestamp:
- 04/14/06 14:36:57 (2 years ago)
- Files:
-
- trunk/src/IDocument.cxx (modified) (8 diffs)
- trunk/src/IDocument.h (modified) (2 diffs)
- trunk/src/MainPter.cxx (modified) (7 diffs)
- trunk/src/MainPter.h (modified) (3 diffs)
- trunk/src/PDFDocument.cxx (modified) (1 diff)
- trunk/tests/DumbDocument.cxx (modified) (1 diff)
- trunk/tests/MainPterTest.cxx (modified) (4 diffs)
- trunk/tests/MainPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/IDocument.cxx
r60 r63 654 654 655 655 /// 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 /// 662 void 663 IDocument::setRotation (gint rotation) 664 { 665 m_Rotation = (rotation % 360); 666 } 667 668 /// 656 669 /// @brief Rotates 90 to the left. 657 670 /// … … 661 674 IDocument::rotateLeft () 662 675 { 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); 668 682 } 669 683 … … 676 690 IDocument::rotateRight () 677 691 { 678 m_Rotation = (m_Rotation + 90) % 360;692 setRotation (getRotation () + 90); 679 693 } 680 694 … … 706 720 /// @return The current zoom or scale level. 707 721 /// 708 g float722 gdouble 709 723 IDocument::getZoom (void) 710 724 { 711 725 return m_Scale; 726 } 727 728 /// 729 /// @brief Sets the current zoom. 730 /// 731 /// @param zoom The new zoom level. 732 /// 733 void 734 IDocument::setZoom (gdouble zoom) 735 { 736 m_Scale = zoom; 712 737 } 713 738 … … 725 750 if (canZoomIn ()) 726 751 { 727 m_Scale *= ZOOM_IN_FACTOR;752 setZoom (getZoom () * ZOOM_IN_FACTOR); 728 753 } 729 754 } … … 742 767 if (canZoomOut ()) 743 768 { 744 m_Scale *= ZOOM_OUT_FACTOR;769 setZoom (getZoom () * ZOOM_OUT_FACTOR); 745 770 } 746 771 } … … 766 791 gdouble widthScale = (gdouble)width / pageWidth; 767 792 gdouble heightScale = (gdouble)height / pageHeight; 768 m_Scale = MIN (widthScale, heightScale);793 setZoom (MIN (widthScale, heightScale)); 769 794 } 770 795 … … 784 809 785 810 getPageSize (&pageWidth, &pageHeight); 786 m_Scale = (gdouble)width / pageWidth;787 } 811 setZoom ((gdouble)width / pageWidth); 812 } trunk/src/IDocument.h
r58 r63 208 208 209 209 gint getRotation (void); 210 void setRotation (gint rotation); 210 211 void rotateLeft (void); 211 212 void rotateRight (void); … … 213 214 gboolean canZoomIn (void); 214 215 gboolean canZoomOut (void); 215 gfloat getZoom (void); 216 gdouble getZoom (void); 217 void setZoom (gdouble zoom); 216 218 void zoomIn (void); 217 219 void zoomOut (void); trunk/src/MainPter.cxx
r62 r63 64 64 /// set the window's title and tell the main view to show itself. 65 65 /// 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 /// 72 void 73 MainPter::setInitialState (gboolean canShowPage) 68 74 { 69 75 g_assert ( NULL != m_Document && "The document is NULL."); … … 90 96 view.sensitiveZoomWidth (TRUE); 91 97 view.setTotalPages (m_Document->getNumPages ()); 92 showPage (); 98 99 if ( canShowPage ) 100 { 101 showPage (); 102 } 93 103 } 94 104 else … … 139 149 // Now that the view is set, it's time to set the initial 140 150 // state. 141 setInitialState ( );151 setInitialState (TRUE); 142 152 } 143 153 … … 235 245 IMainView &view = getView (); 236 246 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 /// 257 void 258 MainPter::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 /// 277 void 278 MainPter::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 /// 289 void 290 MainPter::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 /// 301 void 302 MainPter::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 /// 316 void 317 MainPter::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 /// 328 void 329 MainPter::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 /// 340 void 341 MainPter::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 /// 366 void 367 MainPter::openDocument (const gchar *fileName, gboolean canShowPage) 368 { 369 // if fileName is NULL, then the user cancelled the operation. 238 370 // I don't need to do anything in this case. I'm only interested when 239 371 // the user tried to open a file. … … 245 377 // Now that the document has been loaded, just reset the initial 246 378 // state. 247 setInitialState ( );379 setInitialState (canShowPage); 248 380 } 249 381 else … … 272 404 { 273 405 // Phew, finally loaded. Set the initial state. 274 setInitialState ( );406 setInitialState (canShowPage); 275 407 } 276 408 else if ( NULL != password ) … … 293 425 g_free (error); 294 426 } 295 g_free (fileName);296 427 } 297 428 } 298 429 299 ///300 /// @brief The "Rotate Left" was activated.301 ///302 void303 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 void315 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 void327 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 void342 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 void354 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 void366 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 }376 430 377 431 /// trunk/src/MainPter.h
r49 r63 41 41 ~MainPter (void); 42 42 43 void setInitialState ( void);43 void setInitialState (gboolean canShowPage); 44 44 IMainView &getView (void); 45 45 void setView (IMainView *view); … … 51 51 void goToPreviousPageActivated (void); 52 52 void openFileActivated (void); 53 void reloadActivated (void); 53 54 void rotateLeftActivated (void); 54 55 void rotateRightActivated (void); … … 59 60 60 61 protected: 62 void openDocument (const gchar *fileName, gboolean canShowPage); 61 63 void showPage (void); 62 64 trunk/src/PDFDocument.cxx
r61 r63 133 133 setOutline (m_Outline, outline->getItems ()); 134 134 // Set the current rotation angle and zoom level. 135 m_Rotation = 0;136 m_Scale = 1.0f;135 setRotation (0); 136 setZoom (1.0f); 137 137 // Set the output device. 138 138 delete m_OutputDevice; trunk/tests/DumbDocument.cxx
r31 r63 66 66 "%s", IDocument::getErrorMessage (m_OpenError)); 67 67 } 68 m_Rotation = 0;69 m_Scale = 1.0f;68 setRotation (0); 69 setZoom (1.0f); 70 70 return m_Loaded; 71 71 } trunk/tests/MainPterTest.cxx
r62 r63 288 288 } 289 289 290 290 291 /// 291 292 /// @brief Test page navigation. … … 490 491 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 491 492 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 492 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0 f, m_Document->getZoom (), 0.0001f);493 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 493 494 494 495 m_MainPter->zoomInActivated (); 495 496 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 496 497 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 497 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2 f, m_Document->getZoom (), 0.0001f);498 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2, m_Document->getZoom (), 0.0001); 498 499 499 500 m_MainPter->zoomOutActivated (); 500 501 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 501 502 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); 503 504 504 505 CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); … … 523 524 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 524 525 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 525 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2 f, m_Document->getZoom (), 0.0001f);526 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 526 527 // For the width it should be 75/100 = 0.75 527 528 m_MainPter->zoomWidthActivated (); 528 529 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 529 530 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 530 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75 f, m_Document->getZoom (), 0.0001f);531 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 531 532 532 533 // Now rotate and try again. … … 537 538 // Since rotation is now 90 the zoom level should be 75/250 = 0.3 538 539 m_MainPter->zoomFitActivated (); 539 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3 f, m_Document->getZoom (), 0.0001f);540 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 540 541 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 541 542 // For the width it should be 75/250 = 0.3 also. 542 543 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 /// 554 void 555 MainPterTest::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 37 37 CPPUNIT_TEST (pageRotate); 38 38 CPPUNIT_TEST (pageZoom); 39 CPPUNIT_TEST (reloadNormal); 39 40 CPPUNIT_TEST_SUITE_END(); 40 41 … … 54 55 void pageRotate (void); 55 56 void pageZoom (void); 57 void reloadNormal (void); 56 58 57 59 private:
