Changeset 98
- Timestamp:
- 04/20/06 11:13:01 (2 years ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
src/Config.cxx (modified) (5 diffs)
-
src/Config.h (modified) (2 diffs)
-
tests/ConfigTest.cxx (modified) (2 diffs)
-
tests/ConfigTest.h (modified) (2 diffs)
-
tests/MainPterTest.cxx (modified) (4 diffs)
-
tests/MainPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Config.cxx
r96 r98 28 28 static gint DEFAULT_WINDOW_X = 0; 29 29 static gint DEFAULT_WINDOW_Y = 0; 30 static gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 31 static gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 30 32 31 33 // Static member attributes. … … 105 107 106 108 /// 107 /// @brief Gets a n integerconfiguration option.109 /// @brief Gets a boolean configuration option. 108 110 /// 109 111 /// @param group Configuration group where the key belongs. … … 114 116 /// doesn't exists. 115 117 /// 116 g int117 Config::get Integer (const gchar *group, const gchar *key, gintdefaultValue)118 { 119 g intvalue = defaultValue;118 gboolean 119 Config::getBoolean (const gchar *group, const gchar *key, gboolean defaultValue) 120 { 121 gboolean value = defaultValue; 120 122 121 123 if ( g_key_file_has_key (m_Values, group, key, NULL) ) 122 124 { 123 125 GError *error = NULL; 124 gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 126 gboolean savedValue = 127 g_key_file_get_boolean (m_Values, group, key, &error); 125 128 if ( NULL == error ) 126 129 { … … 139 142 140 143 /// 144 /// @brief Gets an integer configuration option. 145 /// 146 /// @param group Configuration group where the key belongs. 147 /// @param key The key name to retrieve its value. 148 /// @param defaultValue The default value to return if @a key doesn't exists. 149 /// 150 /// @return The value of the @a key in @a group or @a defaultValue if @a key 151 /// doesn't exists. 152 /// 153 gint 154 Config::getInteger (const gchar *group, const gchar *key, gint defaultValue) 155 { 156 gint value = defaultValue; 157 158 if ( g_key_file_has_key (m_Values, group, key, NULL) ) 159 { 160 GError *error = NULL; 161 gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 162 if ( NULL == error ) 163 { 164 value = savedValue; 165 } 166 else 167 { 168 g_warning ("Error reading key '%s' from group '%s': %s\n", 169 key, group, error->message); 170 g_error_free (error); 171 } 172 } 173 174 return value; 175 } 176 177 /// 141 178 /// @brief Gets an string configuration option. 142 179 /// … … 299 336 g_key_file_set_integer (m_Values, "main window", "x", x); 300 337 g_key_file_set_integer (m_Values, "main window", "y", y); 338 } 339 340 /// 341 /// @brief Sets the zoom to fit option. 342 /// 343 /// @param activate Set to TRUE to activate the zoom to fit option. FALSE 344 /// otherwise. 345 /// 346 void 347 Config::setZoomToFit (gboolean activate) 348 { 349 g_key_file_set_boolean (m_Values, "main window", "zoomToFit", activate); 350 g_key_file_set_boolean (m_Values, "main window", "zoomToWidth", 351 !activate && zoomToWidth ()); 352 } 353 354 /// 355 /// @brief Sets the zoom to with option. 356 /// 357 /// @param activate Set to TRUE to activate the zoom to width option. FALSE 358 /// otherwise. 359 /// 360 void 361 Config::setZoomToWidth (gboolean activate) 362 { 363 g_key_file_set_boolean (m_Values, "main window", "zoomToFit", 364 !activate && zoomToFit ()); 365 g_key_file_set_boolean (m_Values, "main window", "zoomToWidth", activate); 366 } 367 368 /// 369 /// @brief Gets the zoom to fit option. 370 /// 371 /// @return TRUE if the zoom to fit option is activated. FALSE otherwise. 372 /// 373 gboolean 374 Config::zoomToFit () 375 { 376 return getBoolean ("main window", "zoomToFit", DEFAULT_ZOOM_TO_FIT); 377 } 378 379 /// 380 /// @brief Gets the zoom to width option. 381 /// 382 /// @return TRUE if the zoom to width option is activated. FALSE otherwise. 383 /// 384 gboolean 385 Config::zoomToWidth () 386 { 387 return getBoolean ("main window", "zoomToWidth", DEFAULT_ZOOM_TO_WIDTH); 301 388 } 302 389 -
trunk/src/Config.h
r96 r98 44 44 gint getWindowX (void); 45 45 gint getWindowY (void); 46 gboolean zoomToFit (void); 47 gboolean zoomToWidth (void); 46 48 void save(void); 47 49 void setOpenFileFolder (const gchar *folder); 48 50 void setWindowSize (gint width, gint height); 49 51 void setWindowPos (gint x, gint y); 52 void setZoomToFit (gboolean active); 53 void setZoomToWidth (gboolean active); 50 54 51 55 protected: … … 58 62 static gboolean m_LoadFile; 59 63 64 gboolean getBoolean (const gchar *group, const char *key, 65 gboolean defaultValue); 60 66 gint getInteger (const gchar *group, const char *key, 61 67 gint defaultValue); -
trunk/tests/ConfigTest.cxx
r96 r98 58 58 CPPUNIT_ASSERT_EQUAL (650, config.getWindowHeight ()); 59 59 CPPUNIT_ASSERT_EQUAL ((gchar *)NULL, config.getOpenFileFolder ()); 60 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 61 CPPUNIT_ASSERT ( !config.zoomToFit () ); 60 62 } 61 63 … … 90 92 g_free (openFolder); 91 93 } 94 95 /// 96 /// @brief Check setting the zoom values. 97 /// 98 /// Especially check that zoomToWidth() and zoomToFit() can't be 99 /// set both to true. 100 /// 101 void 102 ConfigTest::zoomValues () 103 { 104 Config &config = Config::getConfig (); 105 106 config.setZoomToFit (TRUE); 107 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 108 CPPUNIT_ASSERT ( config.zoomToFit () ); 109 config.setZoomToFit (FALSE); 110 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 111 CPPUNIT_ASSERT ( !config.zoomToFit () ); 112 config.setZoomToWidth (TRUE); 113 CPPUNIT_ASSERT ( config.zoomToWidth () ); 114 CPPUNIT_ASSERT ( !config.zoomToFit () ); 115 config.setZoomToWidth (FALSE); 116 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 117 CPPUNIT_ASSERT ( !config.zoomToFit () ); 118 config.setZoomToFit (TRUE); 119 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 120 CPPUNIT_ASSERT ( config.zoomToFit () ); 121 config.setZoomToWidth (TRUE); 122 CPPUNIT_ASSERT ( config.zoomToWidth () ); 123 CPPUNIT_ASSERT ( !config.zoomToFit () ); 124 config.setZoomToFit (TRUE); 125 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 126 CPPUNIT_ASSERT ( config.zoomToFit () ); 127 config.setZoomToFit (FALSE); 128 CPPUNIT_ASSERT ( !config.zoomToWidth () ); 129 CPPUNIT_ASSERT ( !config.zoomToFit () ); 130 } -
trunk/tests/ConfigTest.h
r96 r98 29 29 CPPUNIT_TEST (windowValues); 30 30 CPPUNIT_TEST (currentFolder); 31 CPPUNIT_TEST (zoomValues); 31 32 CPPUNIT_TEST_SUITE_END (); 32 33 … … 38 39 void windowValues (void); 39 40 void currentFolder (void); 41 void zoomValues (void); 40 42 }; 41 43 } -
trunk/tests/MainPterTest.cxx
r97 r98 513 513 /// ZoomIn insensitives the ZoomIn button. The same for the ZoomOut. 514 514 /// 515 /// Then will test Zoom Fit and Zoom Width with two different rotations. 516 /// 517 void 518 MainPterTest::pageZoom () 515 /// 516 void 517 MainPterTest::pageZoomInAndOut () 519 518 { 520 519 m_View->setOpenFileName ("/tmp/test.pdf"); … … 549 548 CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 550 549 CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 550 } 551 552 /// 553 /// @brief Tests page's zoom to width 554 /// 555 void 556 MainPterTest::pageZoomWidth () 557 { 558 m_View->setOpenFileName ("/tmp/test.pdf"); 559 m_MainPter->openFileActivated (); 560 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 561 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 562 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 551 563 552 564 // OK, now try to zoom width. Since rotation is 0 565 // 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 ()); 569 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 570 571 // Now rotate and try again. 572 m_MainPter->rotateRightActivated (); 573 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 574 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 575 576 // Since rotation is now 90 the zoom level should be 75/250 = 0.3 577 m_MainPter->zoomWidthActivated (); 578 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 579 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 553 595 // the zoom level should be 50/250 = 0.2 554 596 m_MainPter->zoomFitActivated (); … … 556 598 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 557 599 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 558 // For the width it should be 75/100 = 0.75559 m_MainPter->zoomWidthActivated ();560 CPPUNIT_ASSERT (m_View->hasImagePageView ());561 CPPUNIT_ASSERT (!m_View->hasImagePageView ());562 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001);563 600 564 601 // Now rotate and try again. … … 571 608 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 572 609 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 573 // For the width it should be 75/250 = 0.3 also. 574 m_MainPter->zoomWidthActivated (); 575 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 576 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 577 } 610 } 611 578 612 579 613 /// -
trunk/tests/MainPterTest.h
r97 r98 37 37 CPPUNIT_TEST (pageNavigationEntry); 38 38 CPPUNIT_TEST (pageRotate); 39 CPPUNIT_TEST (pageZoom); 39 CPPUNIT_TEST (pageZoomInAndOut); 40 CPPUNIT_TEST (pageZoomWidth); 41 CPPUNIT_TEST (pageZoomFit); 40 42 CPPUNIT_TEST (reloadNormal); 41 43 CPPUNIT_TEST (reloadEncrypted); … … 59 61 void pageNavigationEntry (void); 60 62 void pageRotate (void); 61 void pageZoom (void); 63 void pageZoomInAndOut (void); 64 void pageZoomWidth (void); 65 void pageZoomFit (void); 62 66 void reloadNormal (void); 63 67 void reloadEncrypted (void);
