1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Qwt User's Guide: qwt_plot_layout.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>qwt_plot_layout.cpp</h1><pre class="fragment"><div>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span>
00002 <span class="comment"> * Qwt Widget Library</span>
00003 <span class="comment"> * Copyright (C) 1997 Josef Wilgen</span>
00004 <span class="comment"> * Copyright (C) 2002 Uwe Rathmann</span>
00005 <span class="comment"> *</span>
00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span>
00008 <span class="comment"> *****************************************************************************/</span>
00009
00010 <span class="comment">// vim: expandtab</span>
00011
00012 <span class="preprocessor">#include <qlabel.h></span>
00013 <span class="preprocessor">#include "qwt_rect.h"</span>
00014 <span class="preprocessor">#include "qwt_text.h"</span>
00015 <span class="preprocessor">#include "qwt_plot_canvas.h"</span>
00016 <span class="preprocessor">#include "qwt_scale.h"</span>
00017 <span class="preprocessor">#include "qwt_legend.h"</span>
00018 <span class="preprocessor">#include "qwt_plot_layout.h"</span>
00019
00020 <span class="keyword">class </span>QwtPlotLayoutData
00021 {
00022 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="class_qwt_plot_layout.html">QwtPlotLayout</a>;
00023
00024 <span class="keyword">protected</span>:
00025 QwtPlotLayoutData();
00026 ~QwtPlotLayoutData();
00027
00028 <span class="keywordtype">void</span> init(<span class="keyword">const</span> <a class="code" href="class_qwt_plot.html">QwtPlot</a> *, <span class="keyword">const</span> QRect &rect);
00029
00030 <span class="keyword">struct </span>t_legendData
00031 {
00032 <span class="keywordtype">int</span> frameWidth;
00033 <span class="keywordtype">int</span> vScrollBarWidth;
00034 <span class="keywordtype">int</span> hScrollBarHeight;
00035 QSize hint;
00036 } legend;
00037
00038 <span class="keyword">struct </span>t_titleData
00039 {
00040 <span class="keyword">const</span> <a class="code" href="class_qwt_text.html">QwtText</a> *text;
00041 <span class="keywordtype">int</span> frameWidth;
00042 } title;
00043
00044 <span class="keyword">struct </span>t_scaleData
00045 {
00046 <span class="keywordtype">bool</span> isEnabled;
00047 <span class="keyword">const</span> <a class="code" href="class_qwt_scale.html">QwtScale</a> *scale;
00048 QFont scaleFont;
00049 <span class="keywordtype">int</span> start;
00050 <span class="keywordtype">int</span> end;
00051 <span class="keywordtype">int</span> baseLineOffset;
00052 <span class="keywordtype">int</span> tickOffset;
00053 <span class="keywordtype">int</span> dimWithoutTitle;
00054 } scale[QwtPlot::axisCnt];
00055
00056 <span class="keyword">struct </span>t_canvasData
00057 {
00058 <span class="keywordtype">int</span> frameWidth;
00059 } canvas;
00060 };
00061
<a name="l00066"></a><a class="code" href="class_qwt_plot_layout.html#a0">00066</a> <a class="code" href="class_qwt_plot_layout.html#a0">QwtPlotLayout::QwtPlotLayout</a>():
00067 d_margin(0),
00068 d_spacing(5),
00069 d_alignCanvasToScales(FALSE)
00070 {
00071 <a class="code" href="class_qwt_plot_layout.html#a10">setLegendPosition</a>(QwtPlot::Bottom);
00072 <a class="code" href="class_qwt_plot_layout.html#a4">setCanvasMargin</a>(4);
00073 d_layoutData = <span class="keyword">new</span> QwtPlotLayoutData;
00074
00075 <a class="code" href="class_qwt_plot_layout.html#a19">invalidate</a>();
00076 }
00077
<a name="l00079"></a><a class="code" href="class_qwt_plot_layout.html#a1">00079</a> <a class="code" href="class_qwt_plot_layout.html#a1">QwtPlotLayout::~QwtPlotLayout</a>()
00080 {
00081 <span class="keyword">delete</span> d_layoutData;
00082 }
00083
<a name="l00093"></a><a class="code" href="class_qwt_plot_layout.html#a2">00093</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a2">QwtPlotLayout::setMargin</a>(<span class="keywordtype">int</span> margin)
00094 {
00095 <span class="keywordflow">if</span> ( margin < 0 )
00096 margin = 0;
00097 d_margin = margin;
00098 }
00099
<a name="l00106"></a><a class="code" href="class_qwt_plot_layout.html#a3">00106</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_plot_layout.html#a3">QwtPlotLayout::margin</a>()<span class="keyword"> const</span>
00107 <span class="keyword"></span>{
00108 <span class="keywordflow">return</span> d_margin;
00109 }
00110
<a name="l00124"></a><a class="code" href="class_qwt_plot_layout.html#a4">00124</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a4">QwtPlotLayout::setCanvasMargin</a>(<span class="keywordtype">int</span> margin, <span class="keywordtype">int</span> axis)
00125 {
00126 <span class="keywordflow">if</span> ( margin < -1 )
00127 margin = -1;
00128
00129 <span class="keywordflow">if</span> ( axis == -1 )
00130 {
00131 <span class="keywordflow">for</span> (axis = 0; axis < QwtPlot::axisCnt; axis++)
00132 d_canvasMargin[axis] = margin;
00133 }
00134 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( axis >= 0 || axis < QwtPlot::axisCnt )
00135 d_canvasMargin[axis] = margin;
00136 }
00137
<a name="l00143"></a><a class="code" href="class_qwt_plot_layout.html#a5">00143</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_plot_layout.html#a5">QwtPlotLayout::canvasMargin</a>(<span class="keywordtype">int</span> axis)<span class="keyword"> const</span>
00144 <span class="keyword"></span>{
00145 <span class="keywordflow">if</span> ( axis < 0 || axis >= QwtPlot::axisCnt )
00146 <span class="keywordflow">return</span> 0;
00147
00148 <span class="keywordflow">return</span> d_canvasMargin[axis];
00149 }
00150
00151
<a name="l00165"></a><a class="code" href="class_qwt_plot_layout.html#a6">00165</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a6">QwtPlotLayout::setAlignCanvasToScales</a>(<span class="keywordtype">bool</span> alignCanvasToScales)
00166 {
00167 d_alignCanvasToScales = alignCanvasToScales;
00168 }
00169
<a name="l00180"></a><a class="code" href="class_qwt_plot_layout.html#a7">00180</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_plot_layout.html#a7">QwtPlotLayout::alignCanvasToScales</a>()<span class="keyword"> const</span>
00181 <span class="keyword"></span>{
00182 <span class="keywordflow">return</span> d_alignCanvasToScales;
00183 }
00184
<a name="l00193"></a><a class="code" href="class_qwt_plot_layout.html#a8">00193</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a8">QwtPlotLayout::setSpacing</a>(<span class="keywordtype">int</span> spacing)
00194 {
00195 d_spacing = QMAX(0, spacing);
00196 }
00197
<a name="l00202"></a><a class="code" href="class_qwt_plot_layout.html#a9">00202</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_plot_layout.html#a9">QwtPlotLayout::spacing</a>()<span class="keyword"> const</span>
00203 <span class="keyword"></span>{
00204 <span class="keywordflow">return</span> d_spacing;
00205 }
00206
<a name="l00221"></a><a class="code" href="class_qwt_plot_layout.html#a10">00221</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a10">QwtPlotLayout::setLegendPosition</a>(QwtPlot::Position pos, <span class="keywordtype">double</span> ratio)
00222 {
00223 <span class="keywordflow">if</span> ( ratio > 1.0 )
00224 ratio = 1.0;
00225
00226 <span class="keywordflow">switch</span>(pos)
00227 {
00228 <span class="keywordflow">case</span> QwtPlot::Top:
00229 <span class="keywordflow">case</span> QwtPlot::Bottom:
00230 <span class="keywordflow">if</span> ( ratio <= 0.0 )
00231 ratio = 0.33;
00232 d_legendRatio = ratio;
00233 d_legendPos = pos;
00234 <span class="keywordflow">break</span>;
00235 <span class="keywordflow">case</span> QwtPlot::Left:
00236 <span class="keywordflow">case</span> QwtPlot::Right:
00237 <span class="keywordflow">if</span> ( ratio <= 0.0 )
00238 ratio = 0.5;
00239 d_legendRatio = ratio;
00240 d_legendPos = pos;
00241 <span class="keywordflow">break</span>;
00242 <span class="keywordflow">default</span>:
00243 <span class="keywordflow">break</span>;
00244 }
00245 }
00246
<a name="l00255"></a><a class="code" href="class_qwt_plot_layout.html#a11">00255</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a10">QwtPlotLayout::setLegendPosition</a>(QwtPlot::Position pos)
00256 {
00257 <a class="code" href="class_qwt_plot_layout.html#a10">setLegendPosition</a>(pos, 0.0);
00258 }
00259
<a name="l00266"></a><a class="code" href="class_qwt_plot_layout.html#a12">00266</a> QwtPlot::Position <a class="code" href="class_qwt_plot_layout.html#a12">QwtPlotLayout::legendPosition</a>()<span class="keyword"> const</span>
00267 <span class="keyword"></span>{
00268 <span class="keywordflow">return</span> d_legendPos;
00269 }
00270
00271 <span class="preprocessor">#ifndef QWT_NO_COMPAT</span>
00272 <span class="preprocessor"></span>
<a name="l00288"></a><a class="code" href="class_qwt_plot_layout.html#a15">00288</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a15">QwtPlotLayout::setLegendPos</a>(<span class="keywordtype">int</span> pos, <span class="keywordtype">double</span> ratio)
00289 {
00290 <a class="code" href="class_qwt_plot_layout.html#a10">setLegendPosition</a>(QwtPlot::Position(pos), ratio);
00291 }
00292
<a name="l00300"></a><a class="code" href="class_qwt_plot_layout.html#a16">00300</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_plot_layout.html#a16">QwtPlotLayout::legendPos</a>()<span class="keyword"> const</span>
00301 <span class="keyword"></span>{
00302 <span class="keywordflow">return</span> d_legendPos;
00303 }
00304
00305 <span class="preprocessor">#endif // !QWT_NO_COMPAT</span>
00306 <span class="preprocessor"></span>
<a name="l00318"></a><a class="code" href="class_qwt_plot_layout.html#a13">00318</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a13">QwtPlotLayout::setLegendRatio</a>(<span class="keywordtype">double</span> ratio)
00319 {
00320 <a class="code" href="class_qwt_plot_layout.html#a10">setLegendPosition</a>(<a class="code" href="class_qwt_plot_layout.html#a12">legendPosition</a>(), ratio);
00321 }
00322
<a name="l00328"></a><a class="code" href="class_qwt_plot_layout.html#a14">00328</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_plot_layout.html#a14">QwtPlotLayout::legendRatio</a>()<span class="keyword"> const</span>
00329 <span class="keyword"></span>{
00330 <span class="keywordflow">return</span> d_legendRatio;
00331 }
00332
<a name="l00338"></a><a class="code" href="class_qwt_plot_layout.html#a20">00338</a> <span class="keyword">const</span> QRect &<a class="code" href="class_qwt_plot_layout.html#a20">QwtPlotLayout::titleRect</a>()<span class="keyword"> const</span>
00339 <span class="keyword"></span>{
00340 <span class="keywordflow">return</span> d_titleRect;
00341 }
00342
<a name="l00348"></a><a class="code" href="class_qwt_plot_layout.html#a21">00348</a> <span class="keyword">const</span> QRect &<a class="code" href="class_qwt_plot_layout.html#a21">QwtPlotLayout::legendRect</a>()<span class="keyword"> const</span>
00349 <span class="keyword"></span>{
00350 <span class="keywordflow">return</span> d_legendRect;
00351 }
00352
<a name="l00359"></a><a class="code" href="class_qwt_plot_layout.html#a22">00359</a> <span class="keyword">const</span> QRect &<a class="code" href="class_qwt_plot_layout.html#a22">QwtPlotLayout::scaleRect</a>(<span class="keywordtype">int</span> axis)<span class="keyword"> const</span>
00360 <span class="keyword"></span>{
00361 <span class="keywordflow">if</span> ( axis < 0 || axis >= QwtPlot::axisCnt )
00362 {
00363 <span class="keyword">static</span> QRect dummyRect;
00364 <span class="keywordflow">return</span> dummyRect;
00365 }
00366 <span class="keywordflow">return</span> d_scaleRect[axis];
00367 }
00368
<a name="l00374"></a><a class="code" href="class_qwt_plot_layout.html#a23">00374</a> <span class="keyword">const</span> QRect &<a class="code" href="class_qwt_plot_layout.html#a23">QwtPlotLayout::canvasRect</a>()<span class="keyword"> const</span>
00375 <span class="keyword"></span>{
00376 <span class="keywordflow">return</span> d_canvasRect;
00377 }
00378
<a name="l00383"></a><a class="code" href="class_qwt_plot_layout.html#a19">00383</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a19">QwtPlotLayout::invalidate</a>()
00384 {
00385 d_titleRect = d_legendRect = d_canvasRect = QRect();
00386 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> axis = 0; axis < QwtPlot::axisCnt; axis++ )
00387 d_scaleRect[axis] = QRect();
00388 }
00389
<a name="l00395"></a><a class="code" href="class_qwt_plot_layout.html#a17">00395</a> QSize <a class="code" href="class_qwt_plot_layout.html#a17">QwtPlotLayout::minimumSizeHint</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_plot.html">QwtPlot</a> *plot)<span class="keyword"> const</span>
00396 <span class="keyword"></span>{
00397 <span class="keyword">class </span>ScaleData
00398 {
00399 <span class="keyword">public</span>:
00400 ScaleData()
00401 {
00402 w = h = minLeft = minRight = tickOffset = 0;
00403 }
00404
00405 <span class="keywordtype">int</span> w;
00406 <span class="keywordtype">int</span> h;
00407 <span class="keywordtype">int</span> minLeft;
00408 <span class="keywordtype">int</span> minRight;
00409 <span class="keywordtype">int</span> tickOffset;
00410 } scaleData[QwtPlot::axisCnt];
00411
00412 <span class="keywordtype">int</span> canvasBorder[QwtPlot::axisCnt];
00413
00414 <span class="keywordtype">int</span> axis;
00415 <span class="keywordflow">for</span> ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
00416 {
00417 <span class="keyword">const</span> <a class="code" href="class_qwt_scale.html">QwtScale</a> *scl = plot-><a class="code" href="class_qwt_plot.html#a109">axis</a>(axis);
00418 <span class="keywordflow">if</span> ( scl )
00419 {
00420 ScaleData &sd = scaleData[axis];
00421
00422 <span class="keyword">const</span> QSize hint = scl-><a class="code" href="class_qwt_scale.html#a27">minimumSizeHint</a>();
00423 sd.w = hint.width();
00424 sd.h = hint.height();
00425 scl-><a class="code" href="class_qwt_scale.html#a14">minBorderDist</a>(sd.minLeft, sd.minRight);
00426 sd.tickOffset = scl-><a class="code" href="class_qwt_scale.html#a16">baseLineDist</a>() +
00427 scl-><a class="code" href="class_qwt_scale.html#a21">scaleDraw</a>()-><a class="code" href="class_qwt_scale_draw.html#a28">majTickLength</a>();
00428 }
00429
00430 canvasBorder[axis] = plot-><a class="code" href="class_qwt_plot.html#a31">canvas</a>()->frameWidth() +
00431 d_canvasMargin[axis] + 1;
00432
00433 }
00434
00435
00436 <span class="keywordflow">for</span> ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
00437 {
00438 ScaleData &sd = scaleData[axis];
00439 <span class="keywordflow">if</span> ( sd.w && (axis == QwtPlot::xBottom || axis == QwtPlot::xTop) )
00440 {
00441 <span class="keywordflow">if</span> ( (sd.minLeft > canvasBorder[QwtPlot::yLeft])
00442 && scaleData[QwtPlot::yLeft].w )
00443 {
00444 <span class="keywordtype">int</span> shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft];
00445 <span class="keywordflow">if</span> ( shiftLeft > scaleData[QwtPlot::yLeft].w )
00446 shiftLeft = scaleData[QwtPlot::yLeft].w;
00447
00448 sd.w -= shiftLeft;
00449 }
00450 <span class="keywordflow">if</span> ( (sd.minRight > canvasBorder[QwtPlot::yRight])
00451 && scaleData[QwtPlot::yRight].w )
00452 {
00453 <span class="keywordtype">int</span> shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight];
00454 <span class="keywordflow">if</span> ( shiftRight > scaleData[QwtPlot::yRight].w )
00455 shiftRight = scaleData[QwtPlot::yRight].w;
00456
00457 sd.w -= shiftRight;
00458 }
00459 }
00460
00461 <span class="keywordflow">if</span> ( sd.h && (axis == QwtPlot::yLeft || axis == QwtPlot::yRight) )
00462 {
00463 <span class="keywordflow">if</span> ( (sd.minLeft > canvasBorder[QwtPlot::xBottom]) &&
00464 scaleData[QwtPlot::xBottom].h )
00465 {
00466 <span class="keywordtype">int</span> shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom];
00467 <span class="keywordflow">if</span> ( shiftBottom > scaleData[QwtPlot::xBottom].tickOffset )
00468 shiftBottom = scaleData[QwtPlot::xBottom].tickOffset;
00469
00470 sd.h -= shiftBottom;
00471 }
00472 <span class="keywordflow">if</span> ( (sd.minLeft > canvasBorder[QwtPlot::xTop]) &&
00473 scaleData[QwtPlot::xTop].h )
00474 {
00475 <span class="keywordtype">int</span> shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop];
00476 <span class="keywordflow">if</span> ( shiftTop > scaleData[QwtPlot::xTop].tickOffset )
00477 shiftTop = scaleData[QwtPlot::xTop].tickOffset;
00478
00479 sd.h -= shiftTop;
00480 }
00481 }
00482 }
00483
00484 <span class="keyword">const</span> <a class="code" href="class_qwt_plot_canvas.html">QwtPlotCanvas</a> *canvas = plot-><a class="code" href="class_qwt_plot.html#a31">canvas</a>();
00485
00486 <span class="keywordtype">int</span> w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w
00487 + QMAX(scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w)
00488 + 2 * (canvas->frameWidth() + 1);
00489 <span class="keywordtype">int</span> h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h
00490 + QMAX(scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h)
00491 + 2 * (canvas->frameWidth() + 1);
00492
00493 <span class="keyword">const</span> QLabel *title = plot-><a class="code" href="class_qwt_plot.html#a29">titleLabel</a>();
00494 <span class="keywordflow">if</span> (title && !title->text().isEmpty())
00495 {
00496 <span class="comment">// If only QwtPlot::yLeft or QwtPlot::yRight is showing, </span>
00497 <span class="comment">// we center on the plot canvas.</span>
00498 <span class="keyword">const</span> <span class="keywordtype">bool</span> centerOnCanvas = plot-><a class="code" href="class_qwt_plot.html#a109">axis</a>(QwtPlot::yLeft) == 0
00499 || plot-><a class="code" href="class_qwt_plot.html#a109">axis</a>(QwtPlot::yRight) == 0;
00500
00501 <span class="keywordtype">int</span> titleW = w;
00502 <span class="keywordflow">if</span> ( centerOnCanvas )
00503 {
00504 titleW -= scaleData[QwtPlot::yLeft].w
00505 + scaleData[QwtPlot::yRight].w;
00506 }
00507
00508 <span class="keywordtype">int</span> titleH = title->heightForWidth(titleW);
00509 <span class="keywordflow">if</span> ( titleH > titleW ) <span class="comment">// Compensate for a long title</span>
00510 {
00511 w = titleW = titleH;
00512 <span class="keywordflow">if</span> ( centerOnCanvas )
00513 {
00514 w += scaleData[QwtPlot::yLeft].w
00515 + scaleData[QwtPlot::yRight].w;
00516 }
00517
00518 titleH = title->heightForWidth(titleW);
00519 }
00520 h += titleH + d_spacing;
00521 }
00522
00523 <span class="comment">// Compute the legend contribution</span>
00524
00525 <span class="keyword">const</span> <a class="code" href="class_qwt_legend.html">QwtLegend</a> *legend = plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>();
00526 <span class="keywordflow">if</span> ( legend && !legend-><a class="code" href="class_qwt_legend.html#a15">isEmpty</a>() )
00527 {
00528 <span class="keywordflow">if</span> ( d_legendPos == QwtPlot::Left || d_legendPos == QwtPlot::Right )
00529 {
00530 <span class="keywordtype">int</span> legendW = legend-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>().width();
00531 <span class="keywordtype">int</span> legendH = legend-><a class="code" href="class_qwt_legend.html#a19">heightForWidth</a>(legendW);
00532
00533 <span class="keywordflow">if</span> ( legend->frameWidth() > 0 )
00534 w += d_spacing;
00535
00536 <span class="keywordflow">if</span> ( legendH > h )
00537 legendW += legend->verticalScrollBar()-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>().height();
00538
00539 <span class="keywordflow">if</span> ( d_legendRatio < 1.0 )
00540 legendW = QMIN(legendW, <span class="keywordtype">int</span>(w / (1.0 - d_legendRatio)));
00541
00542 w += legendW;
00543 }
00544 <span class="keywordflow">else</span> <span class="comment">// QwtPlot::Top, QwtPlot::Bottom</span>
00545 {
00546 <span class="keywordtype">int</span> legendW = QMIN(legend-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>().width(), w);
00547 <span class="keywordtype">int</span> legendH = legend-><a class="code" href="class_qwt_legend.html#a19">heightForWidth</a>(legendW);
00548
00549 <span class="keywordflow">if</span> ( legend->frameWidth() > 0 )
00550 h += d_spacing;
00551
00552 <span class="keywordflow">if</span> ( d_legendRatio < 1.0 )
00553 legendH = QMIN(legendH, <span class="keywordtype">int</span>(h / (1.0 - d_legendRatio)));
00554
00555 h += legendH;
00556 }
00557 }
00558
00559 w += 2 * d_margin;
00560 h += 2 * d_margin;
00561
00562 <span class="keywordflow">return</span> QSize( w, h );
00563 }
00564
<a name="l00572"></a><a class="code" href="class_qwt_plot_layout.html#b0">00572</a> QRect <a class="code" href="class_qwt_plot_layout.html#b0">QwtPlotLayout::layoutLegend</a>(<span class="keywordtype">int</span> options,
00573 <span class="keyword">const</span> QRect &rect)<span class="keyword"> const</span>
00574 <span class="keyword"></span>{
00575 <span class="keyword">const</span> QSize hint(d_layoutData->legend.hint);
00576
00577 <span class="keywordtype">int</span> dim;
00578 <span class="keywordflow">if</span> ( d_legendPos == QwtPlot::Left || d_legendPos == QwtPlot::Right )
00579 {
00580 <span class="comment">// We don't allow vertical legends to take more than</span>
00581 <span class="comment">// half of the available space.</span>
00582
00583 dim = QMIN(hint.width(), int(rect.width() * d_legendRatio));
00584
00585 <span class="keywordflow">if</span> ( !(options & IgnoreScrollbars) )
00586 {
00587 <span class="keywordflow">if</span> ( hint.height() > rect.height() )
00588 {
00589 <span class="comment">// The legend will need additional</span>
00590 <span class="comment">// space for the vertical scrollbar. </span>
00591
00592 dim += d_layoutData->legend.vScrollBarWidth;
00593 }
00594 }
00595 }
00596 <span class="keywordflow">else</span>
00597 {
00598 dim = QMIN(hint.height(), int(rect.height() * d_legendRatio));
00599 dim = QMAX(dim, d_layoutData->legend.hScrollBarHeight);
00600 }
00601
00602 QRect <a class="code" href="class_qwt_plot_layout.html#a21">legendRect</a> = rect;
00603 <span class="keywordflow">switch</span>(d_legendPos)
00604 {
00605 <span class="keywordflow">case</span> QwtPlot::Left:
00606 legendRect.setWidth(dim);
00607 <span class="keywordflow">break</span>;
00608 <span class="keywordflow">case</span> QwtPlot::Right:
00609 legendRect.setX(rect.right() - dim + 1);
00610 legendRect.setWidth(dim);
00611 <span class="keywordflow">break</span>;
00612 <span class="keywordflow">case</span> QwtPlot::Top:
00613 legendRect.setHeight(dim);
00614 <span class="keywordflow">break</span>;
00615 <span class="keywordflow">case</span> QwtPlot::Bottom:
00616 legendRect.setY(rect.bottom() - dim + 1);
00617 legendRect.setHeight(dim);
00618 <span class="keywordflow">break</span>;
00619 }
00620
00621 <span class="keywordflow">return</span> legendRect;
00622 }
00623
<a name="l00630"></a><a class="code" href="class_qwt_plot_layout.html#b1">00630</a> QRect <a class="code" href="class_qwt_plot_layout.html#b1">QwtPlotLayout::alignLegend</a>(<span class="keyword">const</span> QRect &canvasRect,
00631 <span class="keyword">const</span> QRect &legendRect)<span class="keyword"> const</span>
00632 <span class="keyword"></span>{
00633 QRect alignedRect = legendRect;
00634
00635 <span class="keywordflow">if</span> ( d_legendPos == QwtPlot::Bottom || d_legendPos == QwtPlot::Top )
00636 {
00637 <span class="keywordflow">if</span> ( d_layoutData->legend.hint.width() < canvasRect.width() )
00638 {
00639 alignedRect.setX(canvasRect.x());
00640 alignedRect.setWidth(canvasRect.width());
00641 }
00642 }
00643 <span class="keywordflow">else</span>
00644 {
00645 <span class="keywordflow">if</span> ( d_layoutData->legend.hint.height() < canvasRect.height() )
00646 {
00647 alignedRect.setY(canvasRect.y());
00648 alignedRect.setHeight(canvasRect.height());
00649 }
00650 }
00651
00652 <span class="keywordflow">return</span> alignedRect;
00653 }
00654
<a name="l00664"></a><a class="code" href="class_qwt_plot_layout.html#b2">00664</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#b2">QwtPlotLayout::expandLineBreaks</a>(<span class="keywordtype">int</span> options, <span class="keyword">const</span> QRect &rect,
00665 <span class="keywordtype">int</span> &dimTitle, <span class="keywordtype">int</span> dimAxis[QwtPlot::axisCnt])<span class="keyword"> const</span>
00666 <span class="keyword"></span>{
00667 dimTitle = 0;
00668 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < QwtPlot::axisCnt; i++ )
00669 dimAxis[i] = 0;
00670
00671 <span class="keywordtype">bool</span> done = FALSE;
00672 <span class="keywordflow">while</span> (!done)
00673 {
00674 done = TRUE;
00675
00676 <span class="comment">// the size for the 4 axis depend on each other. Expanding</span>
00677 <span class="comment">// the height of a horizontal axis will shrink the height</span>
00678 <span class="comment">// for the vertical axis, shrinking the height of a vertical</span>
00679 <span class="comment">// axis will result in a line break what will expand the</span>
00680 <span class="comment">// width and results in shrinking the width of a horizontal</span>
00681 <span class="comment">// axis what might result in a line break of a horizontal</span>
00682 <span class="comment">// axis ... . So we loop as long until no size changes.</span>
00683
00684 <span class="keywordflow">if</span> ( d_layoutData->title.text)
00685 {
00686 <span class="keywordtype">int</span> w = rect.width();
00687
00688 <span class="keywordflow">if</span> ( d_layoutData->scale[QwtPlot::yLeft].isEnabled
00689 != d_layoutData->scale[QwtPlot::yRight].isEnabled )
00690 {
00691 <span class="comment">// center to the canvas</span>
00692 w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight];
00693 }
00694
00695 <span class="keywordtype">int</span> d = d_layoutData->title.text->heightForWidth(w);
00696 <span class="keywordflow">if</span> ( !(options & IgnoreFrames) )
00697 d += 2 * d_layoutData->title.frameWidth;
00698
00699 <span class="keywordflow">if</span> ( d > dimTitle )
00700 {
00701 dimTitle = d;
00702 done = FALSE;
00703 }
00704 }
00705
00706 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> axis = 0; axis < QwtPlot::axisCnt; axis++ )
00707 {
00708 <span class="keywordtype">int</span> backboneOffset = d_canvasMargin[axis];
00709 <span class="keywordflow">if</span> ( !(options & IgnoreFrames) )
00710 backboneOffset += d_layoutData->canvas.frameWidth;
00711
00712 <span class="keyword">const</span> <span class="keyword">struct </span>QwtPlotLayoutData::t_scaleData &scaleData =
00713 d_layoutData->scale[axis];
00714
00715 <span class="keywordflow">if</span> (scaleData.isEnabled)
00716 {
00717 <span class="keywordtype">int</span> length;
00718 <span class="keywordflow">if</span> ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
00719 {
00720 length = rect.width() - dimAxis[QwtPlot::yLeft]
00721 - dimAxis[QwtPlot::yRight];
00722 length += QMIN(dimAxis[QwtPlot::yLeft],
00723 scaleData.start - backboneOffset);
00724 length += QMIN(dimAxis[QwtPlot::yRight],
00725 scaleData.end - backboneOffset);
00726 }
00727 <span class="keywordflow">else</span> <span class="comment">// QwtPlot::yLeft, QwtPlot::yRight</span>
00728 {
00729 length = rect.height() - dimAxis[QwtPlot::xTop]
00730 - dimAxis[QwtPlot::xBottom];
00731
00732 <span class="keywordflow">if</span> ( dimAxis[QwtPlot::xBottom] > 0 )
00733 {
00734 length += QMIN(
00735 d_layoutData->scale[QwtPlot::xBottom].tickOffset,
00736 scaleData.start - backboneOffset);
00737 }
00738 <span class="keywordflow">if</span> ( dimAxis[QwtPlot::xTop] > 0 )
00739 {
00740 length += QMIN(
00741 d_layoutData->scale[QwtPlot::xTop].tickOffset,
00742 scaleData.end - backboneOffset);
00743 }
00744
00745 <span class="keywordflow">if</span> ( dimTitle > 0 )
00746 length -= dimTitle + d_spacing;
00747 }
00748
00749 <span class="keywordtype">int</span> d = scaleData.dimWithoutTitle;
00750 <span class="keywordflow">if</span> ( !scaleData.scale->title().isEmpty() )
00751 {
00752 d += scaleData.scale->titleHeightForWidth(length);
00753 }
00754
00755 <span class="keywordflow">if</span> ( options & AlignScales )
00756 d -= scaleData.baseLineOffset;
00757
00758 <span class="keywordflow">if</span> ( d > dimAxis[axis] )
00759 {
00760 dimAxis[axis] = d;
00761 done = FALSE;
00762 }
00763 }
00764 }
00765 }
00766 }
00767
<a name="l00773"></a><a class="code" href="class_qwt_plot_layout.html#b3">00773</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#b3">QwtPlotLayout::alignScales</a>(<span class="keywordtype">int</span> options,
00774 QRect &canvasRect, QRect scaleRect[QwtPlot::axisCnt])<span class="keyword"> const</span>
00775 <span class="keyword"></span>{
00776 <span class="keywordtype">int</span> axis;
00777
00778 <span class="keywordtype">int</span> backboneOffset[QwtPlot::axisCnt];
00779 <span class="keywordflow">for</span> (axis = 0; axis < QwtPlot::axisCnt; axis++ )
00780 {
00781 backboneOffset[axis] = 0;
00782 <span class="keywordflow">if</span> ( !d_alignCanvasToScales )
00783 backboneOffset[axis] += d_canvasMargin[axis];
00784 <span class="keywordflow">if</span> ( !(options & IgnoreFrames) )
00785 backboneOffset[axis] += d_layoutData->canvas.frameWidth;
00786 }
00787
00788 <span class="keywordflow">for</span> (axis = 0; axis < QwtPlot::axisCnt; axis++ )
00789 {
00790 <span class="keywordflow">if</span> ( !<a class="code" href="class_qwt_plot_layout.html#a22">scaleRect</a>[axis].isValid() )
00791 <span class="keywordflow">continue</span>;
00792
00793 <span class="keyword">const</span> <span class="keywordtype">int</span> startDist = d_layoutData->scale[axis].start;
00794 <span class="keyword">const</span> <span class="keywordtype">int</span> endDist = d_layoutData->scale[axis].end;
00795
00796 QRect &axisRect = <a class="code" href="class_qwt_plot_layout.html#a22">scaleRect</a>[axis];
00797
00798 <span class="keywordflow">if</span> ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
00799 {
00800 <span class="keyword">const</span> <span class="keywordtype">int</span> leftOffset = backboneOffset[QwtPlot::yLeft] - startDist;
00801
00802 <span class="keywordflow">if</span> ( scaleRect[QwtPlot::yLeft].isValid() )
00803 {
00804 <span class="keywordtype">int</span> minLeft = scaleRect[QwtPlot::yLeft].left();
00805 <span class="keywordtype">int</span> left = axisRect.left() + leftOffset;
00806 axisRect.setLeft(QMAX(left, minLeft));
00807 }
00808 <span class="keywordflow">else</span>
00809 {
00810 <span class="keywordflow">if</span> ( d_alignCanvasToScales )
00811 {
00812 canvasRect.setLeft(QMAX(canvasRect.left(),
00813 axisRect.left() - leftOffset));
00814 }
00815 <span class="keywordflow">else</span>
00816 {
00817 <span class="keywordflow">if</span> ( leftOffset > 0 )
00818 axisRect.setLeft(axisRect.left() + leftOffset);
00819 }
00820 }
00821
00822 <span class="keyword">const</span> <span class="keywordtype">int</span> rightOffset = backboneOffset[QwtPlot::yRight] - endDist;
00823
00824 <span class="keywordflow">if</span> ( scaleRect[QwtPlot::yRight].isValid() )
00825 {
00826 <span class="keywordtype">int</span> maxRight = scaleRect[QwtPlot::yRight].right();
00827 <span class="keywordtype">int</span> right = axisRect.right() - rightOffset;
00828 axisRect.setRight(QMIN(right, maxRight));
00829 }
00830 <span class="keywordflow">else</span>
00831 {
00832 <span class="keywordflow">if</span> ( d_alignCanvasToScales )
00833 {
00834 canvasRect.setRight( QMIN(canvasRect.right(),
00835 axisRect.right() + rightOffset) );
00836 }
00837 <span class="keywordflow">else</span>
00838 {
00839 <span class="keywordflow">if</span> ( rightOffset > 0 )
00840 axisRect.setRight(axisRect.right() - rightOffset);
00841 }
00842 }
00843 }
00844 <span class="keywordflow">else</span> <span class="comment">// QwtPlot::yLeft, QwtPlot::yRight</span>
00845 {
00846 <span class="keyword">const</span> <span class="keywordtype">int</span> bottomOffset =
00847 backboneOffset[QwtPlot::xBottom] - startDist;
00848
00849 <span class="keywordflow">if</span> ( scaleRect[QwtPlot::xBottom].isValid() )
00850 {
00851 <span class="keywordtype">int</span> maxBottom = scaleRect[QwtPlot::xBottom].top() +
00852 d_layoutData->scale[QwtPlot::xBottom].tickOffset;
00853
00854 <span class="keywordtype">int</span> bottom = axisRect.bottom() - bottomOffset;
00855 axisRect.setBottom(QMIN(bottom, maxBottom));
00856 }
00857 <span class="keywordflow">else</span>
00858 {
00859 <span class="keywordflow">if</span> ( d_alignCanvasToScales )
00860 {
00861 canvasRect.setBottom(QMIN(canvasRect.bottom(),
00862 axisRect.bottom() + bottomOffset));
00863 }
00864 <span class="keywordflow">else</span>
00865 {
00866 <span class="keywordflow">if</span> ( bottomOffset > 0 )
00867 axisRect.setBottom(axisRect.bottom() - bottomOffset);
00868 }
00869 }
00870
00871 <span class="keyword">const</span> <span class="keywordtype">int</span> topOffset = backboneOffset[QwtPlot::xTop] - endDist;
00872
00873 <span class="keywordflow">if</span> ( scaleRect[QwtPlot::xTop].isValid() )
00874 {
00875 <span class="keywordtype">int</span> minTop = scaleRect[QwtPlot::xTop].bottom() -
00876 d_layoutData->scale[QwtPlot::xTop].tickOffset;
00877
00878 <span class="keywordtype">int</span> top = axisRect.top() + topOffset;
00879 axisRect.setTop(QMAX(top, minTop));
00880 }
00881 <span class="keywordflow">else</span>
00882 {
00883 <span class="keywordflow">if</span> ( d_alignCanvasToScales )
00884 {
00885 canvasRect.setTop(QMAX(canvasRect.top(),
00886 axisRect.top() + - topOffset));
00887 }
00888 <span class="keywordflow">else</span>
00889 {
00890 <span class="keywordflow">if</span> ( topOffset > 0 )
00891 axisRect.setTop(axisRect.top() + topOffset);
00892 }
00893 }
00894 }
00895 }
00896 }
00897
<a name="l00910"></a><a class="code" href="class_qwt_plot_layout.html#a18">00910</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_layout.html#a18">QwtPlotLayout::activate</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_plot.html">QwtPlot</a> *plot,
00911 <span class="keyword">const</span> QRect &plotRect, <span class="keywordtype">int</span> options)
00912 {
00913 <a class="code" href="class_qwt_plot_layout.html#a19">invalidate</a>();
00914
00915 QRect rect(plotRect); <span class="comment">// undistributed rest of the plot rect</span>
00916
00917 <span class="keywordflow">if</span> ( !(options & IgnoreMargin) )
00918 {
00919 <span class="comment">// subtract the margin</span>
00920
00921 rect.setRect(
00922 rect.x() + d_margin,
00923 rect.y() + d_margin,
00924 rect.width() - 2 * d_margin,
00925 rect.height() - 2 * d_margin
00926 );
00927 }
00928
00929 <span class="comment">// We extract all layout relevant data from the widgets,</span>
00930 <span class="comment">// filter them through pfilter and save them to d_layoutData.</span>
00931
00932 d_layoutData->init(plot, rect);
00933
00934 <span class="keywordflow">if</span> (!(options & IgnoreLegend)
00935 && plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>() && !plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()-><a class="code" href="class_qwt_legend.html#a15">isEmpty</a>() )
00936 {
00937 d_legendRect = <a class="code" href="class_qwt_plot_layout.html#b0">layoutLegend</a>(options, rect);
00938
00939 <span class="comment">// subtract d_legendRect from rect</span>
00940
00941 <span class="keyword">const</span> QRegion region(rect);
00942 rect = region.subtract(d_legendRect).boundingRect();
00943
00944 <span class="keywordflow">if</span> ( d_layoutData->legend.frameWidth &&
00945 !(options & IgnoreFrames ) )
00946 {
00947 <span class="comment">// In case of a frame we have to insert a spacing.</span>
00948 <span class="comment">// Otherwise the leading of the font separates</span>
00949 <span class="comment">// legend and scale/canvas</span>
00950
00951 <span class="keywordflow">switch</span>(d_legendPos)
00952 {
00953 <span class="keywordflow">case</span> QwtPlot::Left:
00954 rect.setLeft(rect.left() + d_spacing);
00955 <span class="keywordflow">break</span>;
00956 <span class="keywordflow">case</span> QwtPlot::Right:
00957 rect.setRight(rect.right() - d_spacing);
00958 <span class="keywordflow">break</span>;
00959 <span class="keywordflow">case</span> QwtPlot::Top:
00960 rect.setTop(rect.top() + d_spacing);
00961 <span class="keywordflow">break</span>;
00962 <span class="keywordflow">case</span> QwtPlot::Bottom:
00963 rect.setBottom(rect.bottom() - d_spacing);
00964 <span class="keywordflow">break</span>;
00965 }
00966 }
00967 }
00968
00969 <span class="comment">/*</span>
00970 <span class="comment"> +---+-----------+---+</span>
00971 <span class="comment"> | Title |</span>
00972 <span class="comment"> +---+-----------+---+</span>
00973 <span class="comment"> | | Axis | |</span>
00974 <span class="comment"> +---+-----------+---+</span>
00975 <span class="comment"> | A | | A |</span>
00976 <span class="comment"> | x | Canvas | x |</span>
00977 <span class="comment"> | i | | i |</span>
00978 <span class="comment"> | s | | s |</span>
00979 <span class="comment"> +---+-----------+---+</span>
00980 <span class="comment"> | | Axis | |</span>
00981 <span class="comment"> +---+-----------+---+</span>
00982 <span class="comment"> */</span>
00983
00984
00985 <span class="comment">// axes and title include text labels. The height of each</span>
00986 <span class="comment">// label depends on its line breaks, that depend on the width</span>
00987 <span class="comment">// for the label. A line break in a horizontal text will reduce</span>
00988 <span class="comment">// the available width for vertical texts and vice versa. </span>
00989 <span class="comment">// expandLineBreaks finds the height/width for title and axes</span>
00990 <span class="comment">// including all line breaks.</span>
00991
00992 <span class="keywordtype">int</span> dimTitle, dimAxes[QwtPlot::axisCnt];
00993 <a class="code" href="class_qwt_plot_layout.html#b2">expandLineBreaks</a>(options, rect, dimTitle, dimAxes);
00994
00995 <span class="keywordflow">if</span> (dimTitle > 0 )
00996 {
00997 d_titleRect = QRect(rect.x(), rect.y(),
00998 rect.width(), dimTitle);
00999
01000 <span class="keywordflow">if</span> ( d_layoutData->scale[QwtPlot::yLeft].isEnabled !=
01001 d_layoutData->scale[QwtPlot::yRight].isEnabled )
01002 {
01003 <span class="comment">// if only one of the y axes is missing we align</span>
01004 <span class="comment">// the title centered to the canvas</span>
01005
01006 d_titleRect.setX(rect.x() + dimAxes[QwtPlot::yLeft]);
01007 d_titleRect.setWidth(rect.width()
01008 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight]);
01009 }
01010
01011 <span class="comment">// subtract title </span>
01012 rect.setTop(rect.top() + dimTitle + d_spacing);
01013 }
01014
01015 d_canvasRect.setRect(
01016 rect.x() + dimAxes[QwtPlot::yLeft],
01017 rect.y() + dimAxes[QwtPlot::xTop],
01018 rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft],
01019 rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop]);
01020
01021 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> axis = 0; axis < QwtPlot::axisCnt; axis++ )
01022 {
01023 <span class="comment">// set the rects for the axes</span>
01024
01025 <span class="keywordflow">if</span> ( dimAxes[axis] )
01026 {
01027 <span class="keywordtype">int</span> dim = dimAxes[axis];
01028 QRect &<a class="code" href="class_qwt_plot_layout.html#a22">scaleRect</a> = d_scaleRect[axis];
01029
01030 scaleRect = d_canvasRect;
01031 <span class="keywordflow">switch</span>(axis)
01032 {
01033 <span class="keywordflow">case</span> QwtPlot::yLeft:
01034 scaleRect.setX(d_canvasRect.left() - dim);
01035 scaleRect.setWidth(dim);
01036 <span class="keywordflow">break</span>;
01037 <span class="keywordflow">case</span> QwtPlot::yRight:
01038 scaleRect.setX(d_canvasRect.right() + 1);
01039 scaleRect.setWidth(dim);
01040 <span class="keywordflow">break</span>;
01041 <span class="keywordflow">case</span> QwtPlot::xBottom:
01042 scaleRect.setY(d_canvasRect.bottom() + 1);
01043 scaleRect.setHeight(dim);
01044 <span class="keywordflow">break</span>;
01045 <span class="keywordflow">case</span> QwtPlot::xTop:
01046 scaleRect.setY(d_canvasRect.top() - dim);
01047 scaleRect.setHeight(dim);
01048 <span class="keywordflow">break</span>;
01049 }
01050 scaleRect = scaleRect.normalize();
01051 }
01052 }
01053
01054 <span class="comment">// +---+-----------+---+</span>
01055 <span class="comment">// | <- Axis -> |</span>
01056 <span class="comment">// +-^-+-----------+-^-+</span>
01057 <span class="comment">// | | | | | |</span>
01058 <span class="comment">// | | | |</span>
01059 <span class="comment">// | A | | A |</span>
01060 <span class="comment">// | x | Canvas | x |</span>
01061 <span class="comment">// | i | | i |</span>
01062 <span class="comment">// | s | | s |</span>
01063 <span class="comment">// | | | |</span>
01064 <span class="comment">// | | | | | |</span>
01065 <span class="comment">// +-V-+-----------+-V-+</span>
01066 <span class="comment">// | <- Axis -> |</span>
01067 <span class="comment">// +---+-----------+---+</span>
01068
01069 <span class="comment">// The ticks of the axes - not the labels above - should</span>
01070 <span class="comment">// be aligned to the canvas. So we try to use the empty</span>
01071 <span class="comment">// corners to extend the axes, so that the label texts</span>
01072 <span class="comment">// left/right of the min/max ticks are moved into them.</span>
01073
01074 <a class="code" href="class_qwt_plot_layout.html#b3">alignScales</a>(options, d_canvasRect, d_scaleRect);
01075
01076 <span class="keywordflow">if</span> (!d_legendRect.isEmpty() )
01077 {
01078 <span class="comment">// We prefer to align the legend to the canvas - not to</span>
01079 <span class="comment">// the complete plot - if possible.</span>
01080
01081 d_legendRect = <a class="code" href="class_qwt_plot_layout.html#b1">alignLegend</a>(d_canvasRect, d_legendRect);
01082 }
01083 }
01084
01085 QwtPlotLayoutData::QwtPlotLayoutData()
01086 {
01087 title.text = NULL;
01088 }
01089
01090 QwtPlotLayoutData::~QwtPlotLayoutData()
01091 {
01092 <span class="keyword">delete</span> title.text;
01093 }
01094
01095 <span class="comment">/*</span>
01096 <span class="comment"> Extract all layout relevant data from the plot components</span>
01097 <span class="comment">*/</span>
01098
01099 <span class="keywordtype">void</span> QwtPlotLayoutData::init(<span class="keyword">const</span> <a class="code" href="class_qwt_plot.html">QwtPlot</a> *plot, <span class="keyword">const</span> QRect &rect)
01100 {
01101 <span class="comment">// legend</span>
01102
01103 legend.frameWidth = plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()->frameWidth();
01104 legend.vScrollBarWidth =
01105 plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()->verticalScrollBar()-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>().width();
01106 legend.hScrollBarHeight =
01107 plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()->horizontalScrollBar()-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>().height();
01108
01109 <span class="keyword">const</span> QSize hint = plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()-><a class="code" href="class_qwt_legend.html#a18">sizeHint</a>();
01110
01111 <span class="keywordtype">int</span> w = QMIN(hint.width(), rect.width());
01112 <span class="keywordtype">int</span> h = plot-><a class="code" href="class_qwt_plot.html#a170">legend</a>()-><a class="code" href="class_qwt_legend.html#a19">heightForWidth</a>(w);
01113 <span class="keywordflow">if</span> ( h == 0 )
01114 h = hint.height();
01115
01116 <span class="keywordflow">if</span> ( h > rect.height() )
01117 w += legend.vScrollBarWidth;
01118
01119 legend.hint = QSize(w, h);
01120
01121 <span class="comment">// title </span>
01122
01123 title.frameWidth = 0;
01124 <span class="keyword">delete</span> title.text;
01125 title.text = NULL;
01126
01127 <span class="keywordflow">if</span> (plot-><a class="code" href="class_qwt_plot.html#a29">titleLabel</a>() && !plot-><a class="code" href="class_qwt_plot.html#a29">titleLabel</a>()->text().isEmpty())
01128 {
01129 <span class="keyword">const</span> QLabel *label = plot-><a class="code" href="class_qwt_plot.html#a29">titleLabel</a>();
01130 title.text = <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(label->text(), label->textFormat(),
01131 label->alignment(), label->font());
01132 title.frameWidth = plot-><a class="code" href="class_qwt_plot.html#a29">titleLabel</a>()->frameWidth();
01133 }
01134
01135 <span class="comment">// scales </span>
01136
01137 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> axis = 0; axis < QwtPlot::axisCnt; axis++ )
01138 {
01139 <span class="keyword">const</span> <a class="code" href="class_qwt_scale.html">QwtScale</a> *sd = plot-><a class="code" href="class_qwt_plot.html#a109">axis</a>(axis);
01140 <span class="keywordflow">if</span> ( sd )
01141 {
01142 scale[axis].isEnabled = TRUE;
01143
01144 scale[axis].scale = sd;
01145
01146 scale[axis].scaleFont = sd->font();
01147
01148 scale[axis].start = sd-><a class="code" href="class_qwt_scale.html#a12">startBorderDist</a>();
01149 scale[axis].end = sd-><a class="code" href="class_qwt_scale.html#a13">endBorderDist</a>();
01150
01151 scale[axis].baseLineOffset = sd-><a class="code" href="class_qwt_scale.html#a16">baseLineDist</a>();
01152 scale[axis].tickOffset = sd-><a class="code" href="class_qwt_scale.html#a16">baseLineDist</a>() +
01153 (<span class="keywordtype">int</span>)sd-><a class="code" href="class_qwt_scale.html#a21">scaleDraw</a>()-><a class="code" href="class_qwt_scale_draw.html#a28">majTickLength</a>();
01154
01155 scale[axis].dimWithoutTitle = sd-><a class="code" href="class_qwt_scale.html#a30">dimForLength</a>(
01156 QCOORD_MAX, scale[axis].scaleFont);
01157
01158 <span class="keywordflow">if</span> ( !sd-><a class="code" href="class_qwt_scale.html#a4">title</a>().isEmpty() )
01159 {
01160 scale[axis].dimWithoutTitle -=
01161 sd-><a class="code" href="class_qwt_scale.html#a29">titleHeightForWidth</a>(QCOORD_MAX);
01162 }
01163 }
01164 <span class="keywordflow">else</span>
01165 {
01166 scale[axis].isEnabled = FALSE;
01167 scale[axis].start = 0;
01168 scale[axis].end = 0;
01169 scale[axis].baseLineOffset = 0;
01170 scale[axis].tickOffset = 0;
01171 scale[axis].dimWithoutTitle = 0;
01172 }
01173 }
01174
01175 <span class="comment">// canvas </span>
01176
01177 canvas.frameWidth = plot-><a class="code" href="class_qwt_plot.html#a31">canvas</a>()->frameWidth();
01178 }
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>
|