-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImage_Viewer.cc
3096 lines (2864 loc) · 80.7 KB
/
Image_Viewer.cc
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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Image_Viewer
HiROC CVS ID: $Id: Image_Viewer.cc,v 1.137 2014/05/27 17:32:25 guym Exp $
Copyright (C) 2009-2011 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#include "Image_Viewer.hh"
#include "HiView_Config.hh"
#include "Plastic_Image.hh"
#include "Plastic_QImage.hh"
#include "JP2_Image.hh"
#include "Tiled_Image_Display.hh"
#include "HiView_Utilities.hh"
#include "Projection.hh"
#include "Coordinate.hh"
// UA::HiRISE::JP2_Reader.
#include "JP2.hh"
using UA::HiRISE::JP2;
#include "JP2_Reader.hh"
using UA::HiRISE::JP2_Reader;
#include "JP2_Exception.hh"
using UA::HiRISE::JP2_Exception;
#include <QApplication>
#include <QDesktopWidget>
#include <QScrollBar>
#include <QSlider>
#include <QLabel>
#include <QFont>
#include <QFile>
#include <QResizeEvent>
#include <QAction>
#include <QMenu>
#include <QContextMenuEvent>
#include <QErrorMessage>
#include <QCursor>
#include <QBitmap>
#include <QClipboard>
#include <algorithm>
using std::min;
using std::max;
#include <cmath>
#include <sstream>
using std::ostringstream;
#include <stdexcept>
using std::invalid_argument;
#include <iomanip>
using std::endl;
#if defined (DEBUG_SECTION)
#include <QDebug>
/*******************************************************************************
DEBUG_SECTION controls
DEBUG_SECTION report selection options.
Define any of the following options to obtain the desired debug reports:
*/
#define DEBUG_OFF 0
#define DEBUG_ALL -1
#define DEBUG_CONSTRUCTORS (1 << 0)
#define DEBUG_LOAD_IMAGE (1 << 1)
#define DEBUG_LAYOUT (1 << 2)
#define DEBUG_SCALE (1 << 3)
#define DEBUG_SLOTS (1 << 4)
#define DEBUG_SIGNALS (1 << 5)
#define DEBUG_MENUS (1 << 6)
#define DEBUG_SCROLLBARS (1 << 7)
#define DEBUG_EVENTS (1 << 8)
#define DEBUG_MOUSE_EVENTS (1 << 9)
#define DEBUG_KEY_EVENTS (1 << 10)
#define DEBUG_MOVE (1 << 11)
#define DEBUG_SIZE_HINT (1 << 12)
#define DEBUG_MAP_BANDS (1 << 13)
#define DEBUG_MAP_DATA (1 << 14)
#define DEBUG_DEFAULT (DEBUG_ALL & \
~DEBUG_EVENTS & \
~DEBUG_MOUSE_EVENTS & \
~DEBUG_SIGNALS)
#if (DEBUG_SECTION +0) == 0
#undef DEBUG_SECTION
#define DEBUG_SECTION DEBUG_OFF
#endif
#ifndef AS_STRING
/* Provides stringification of #defined names.
Note: The extra double quotes are for MSVC which fails to stringify
__VA_ARGS__ if its value is empty (STRINGIFIED has no argument).
In this case the double quotes coalesce into the intended empty
string constant; otherwise they have no effect on the string generated.
*/
#define STRINGIFIED(...) "" #__VA_ARGS__ ""
#define AS_STRING(...) STRINGIFIED(__VA_ARGS__)
#endif
#ifndef WIN32
#define _DEBUG_OBJECT_ AS_STRING(DEBUG_OBJECT)
#define OBJECT_CONDITIONAL(expression) \
if (QString (_DEBUG_OBJECT_).isEmpty () || \
QString (_DEBUG_OBJECT_) == objectName ()) \
{ \
expression \
}
#else
#define OBJECT_CONDITIONAL(expression) expression
#endif
#include <iostream>
#include <bitset>
#include <limits>
using std::clog;
using std::boolalpha;
using std::hex;
using std::dec;
#endif // DEBUG_SECTION
namespace UA
{
namespace HiRISE
{
/*==============================================================================
Constants
*/
const char* const
Image_Viewer::ID =
"UA::HiRISE::Image_Viewer ($Revision: 1.137 $ $Date: 2014/05/27 17:32:25 $)";
#ifndef DEFAULT_IMAGE_DISPLAY_WIDTH
#define DEFAULT_IMAGE_DISPLAY_WIDTH 512
#endif
#ifndef DEFAULT_IMAGE_DISPLAY_HEIGHT
#define DEFAULT_IMAGE_DISPLAY_HEIGHT 316
#endif
const QSize
Image_Viewer::DEFAULT_IMAGE_DISPLAY_SIZE
(DEFAULT_IMAGE_DISPLAY_WIDTH, DEFAULT_IMAGE_DISPLAY_HEIGHT);
/*==============================================================================
Application configuration parameters
*/
#define Panel_Frame_Style \
HiView_Config::Panel_Frame_Style
#define Panel_Frame_Width \
HiView_Config::Panel_Frame_Width
#define Reticule_Cursor \
HiView_Config::Reticule_Cursor
#define Shift_Cursor \
HiView_Config::Shift_Cursor
#define Scale_Cursor \
HiView_Config::Scale_Cursor
/*==============================================================================
Class data members
*/
#ifndef SCALING_MINOR_INCREMENT
#define SCALING_MINOR_INCREMENT .01
#endif
double
Image_Viewer::Scaling_Minor_Increment = SCALING_MINOR_INCREMENT;
#ifndef SCALING_MAJOR_INCREMENT
#define SCALING_MAJOR_INCREMENT .1
#endif
double
Image_Viewer::Scaling_Major_Increment = SCALING_MAJOR_INCREMENT;
int
Image_Viewer::Horizontal_Scrollbar_Height,
Image_Viewer::Vertical_Scrollbar_Width,
Image_Viewer::Sliding_Scale_Width;
QErrorMessage
*Image_Viewer::Error_Message = NULL;
#ifndef DEFAULT_SCALING_IMMEDIATE
#define DEFAULT_SCALING_IMMEDIATE true;
#endif
bool
Image_Viewer::Default_Scaling_Immediate = DEFAULT_SCALING_IMMEDIATE;
#ifndef DEFAULT_SCROLLBARS_ENABLED
#define DEFAULT_SCROLLBARS_ENABLED true
#endif
/*==============================================================================
Constructors
*/
Image_Viewer::Image_Viewer
(
QWidget* parent
)
: QFrame (parent),
Source_Name (),
Image_Display (NULL),
Horizontal_Scrollbar (NULL),
Vertical_Scrollbar (NULL),
Scrollbars_Enabled (DEFAULT_SCROLLBARS_ENABLED),
Menu_Position (-1, -1),
Control_Mode (NO_CONTROL_MODE),
Mouse_Drag_Image_Position (-1, -1),
Default_Cursor (NULL),
Projector(NULL),
Block_Image_Updates (true)
{
setObjectName ("Image_Viewer");
#if ((DEBUG_SECTION) & (DEBUG_CONSTRUCTORS | DEBUG_LAYOUT))
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer @ " << (void*)this
<< ": " << object_pathname (this) << endl;)
#endif
setFrameStyle (Panel_Frame_Style);
setLineWidth (Panel_Frame_Width);
create_menus ();
// Vertical_Scrollbar - right side.
Vertical_Scrollbar = new QScrollBar (Qt::Vertical, this);
Vertical_Scrollbar->setToolTip (tr ("Vertical scrolling"));
Vertical_Scrollbar_Width = (Vertical_Scrollbar->sizeHint ()).rwidth ();
Vertical_Scrollbar->setMinimum (0);
// Horizontal_Scrollbar - bottom.
Horizontal_Scrollbar = new QScrollBar (Qt::Horizontal, this);
Horizontal_Scrollbar->setToolTip (tr ("Horizontal scrolling"));
Horizontal_Scrollbar_Height = (Horizontal_Scrollbar->sizeHint ()).rheight ();
Horizontal_Scrollbar->setMinimum (0);
// Lower Right Corner (LRC) widget.
LRC_Widget = new QWidget (this);
LRC_Widget->setFixedSize
(Vertical_Scrollbar_Width, Horizontal_Scrollbar_Height);
LRC_Widget->setVisible (false);
// Scrollbars movement connections.
connect (Horizontal_Scrollbar,
SIGNAL (valueChanged (int)),
SLOT (scrollbar_value_changed ()));
connect (Vertical_Scrollbar,
SIGNAL (valueChanged (int)),
SLOT (scrollbar_value_changed ()));
// Sliding_Scale.
Sliding_Scale = new QSlider (Qt::Vertical, this);
Sliding_Scale->setInvertedControls(true);
// this has no effect on mouse drag
Sliding_Scale->setInvertedControls(true);
Sliding_Scale->setToolTip (tr ("Image scaling"));
Sliding_Scale->setTickPosition (QSlider::NoTicks);
Sliding_Scale->setRange
(scale_to_slider (Tiled_Image_Display::min_scale ()),
scale_to_slider (Tiled_Image_Display::max_scale ()));
Sliding_Scale->setSingleStep
(Sliding_Scale->maximum () * Scaling_Minor_Increment);
if (! Sliding_Scale->singleStep ())
Sliding_Scale->setSingleStep (1); // Minimum increment.
Sliding_Scale->setPageStep
(Sliding_Scale->maximum () * Scaling_Major_Increment);
Sliding_Scale->setTracking (default_scaling_immediate ());
Sliding_Scale->setValue (0);
#if ((DEBUG_SECTION) & (DEBUG_CONSTRUCTORS | DEBUG_LAYOUT | DEBUG_SCALE))
//OBJECT_CONDITIONAL (
qDebug() << " Sliding_Scale range: "
<< slider_to_scale (Sliding_Scale->minimum ())
<< '/' << Sliding_Scale->minimum () << " - "
<< slider_to_scale (Sliding_Scale->maximum ())
<< '/' << Sliding_Scale->maximum () << endl
<< " Sliding_Scale increments: "
<< "minor - " << Scaling_Minor_Increment
<< '/' << Sliding_Scale->singleStep ()
<< ", major - " << Scaling_Major_Increment
<< '/' << Sliding_Scale->pageStep () << endl
<< " Sliding_Scale tracking: "
<< Sliding_Scale->hasTracking () << endl
<< " Sliding_Scale position: "
<< Sliding_Scale->sliderPosition ()
<< " [" << Sliding_Scale->value () << "]" << endl;//)
#endif
Sliding_Scale_Width = (Sliding_Scale->sizeHint ()).rwidth ();
/*connect (Sliding_Scale,
SIGNAL (sliderMoved (int)),
SLOT (sliding_scale_value (int)));*/
connect (Sliding_Scale,
SIGNAL (valueChanged (int)),
SLOT (sliding_scale_value_changed (int)));
Sliding_Scale_Value = new QLabel (this);
sliding_scale_value (1.0);
QFont
scale_font (Sliding_Scale_Value->font ());
scale_font.setStyleHint (QFont::SansSerif);
scale_font.setStretch (QFont::Condensed);
scale_font.setPointSize (9);
Sliding_Scale_Value->setFont (scale_font);
Sliding_Scale_Width = qMax (Sliding_Scale_Width,
(Sliding_Scale_Value->sizeHint ()).width ());
Sliding_Scale_Value->setFixedSize
(Sliding_Scale_Width, Horizontal_Scrollbar_Height);
// Enable keyboard events.
setFocusPolicy (Qt::StrongFocus);
// Image_Display
#if ((DEBUG_SECTION) & DEBUG_CONSTRUCTORS)
OBJECT_CONDITIONAL (
clog << " new Tiled_Image_Display ..." << endl;)
#endif
Image_Display = new Tiled_Image_Display (this);
// Default cursor.
Default_Cursor = Reticule_Cursor;
Image_Display->setCursor (*Default_Cursor);
// Instantiate an empty Image_Display.
loaded (true);
// Image load connection.
connect (Image_Display,
SIGNAL (image_loaded (bool)),
SLOT (loaded (bool)));
// Image cursor move connection.
connect (Image_Display,
SIGNAL (image_cursor_moved (const QPoint&, const QPoint&)),
SLOT (cursor_moved (const QPoint&, const QPoint&)));
// Image display move propagation.
connect (Image_Display,
SIGNAL (image_moved (const QPoint&, int)),
SIGNAL (image_moved (const QPoint&, int)));
// Image display resize propagation.
connect (Image_Display,
SIGNAL (displayed_image_region_resized (const QSize&)),
SIGNAL (displayed_image_region_resized (const QSize&)));
connect (Image_Display,
SIGNAL (display_viewport_resized (const QSize&)),
SIGNAL (display_viewport_resized (const QSize&)));
// Image scaling propagation.
connect (Image_Display,
SIGNAL (image_scaled (const QSizeF&, int)),
SIGNAL (image_scaled (const QSizeF&, int)));
// Image display rendering status propagation.
connect (Image_Display,
SIGNAL (rendering_status (int)),
SIGNAL (rendering_status (int)));
// Image display status notice propagation.
connect (Image_Display,
SIGNAL (rendering_status_notice (const QString&)),
SIGNAL (rendering_status_notice (const QString&)));
// Image display status change notice propagation.
connect (Image_Display,
SIGNAL (state_change (int)),
SIGNAL (state_change (int)));
Block_Image_Updates = false;
#if ((DEBUG_SECTION) & DEBUG_CONSTRUCTORS)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer "<< object_pathname (this) << endl;)
#endif
}
Image_Viewer::~Image_Viewer ()
{
#if ((DEBUG_SECTION) & DEBUG_CONSTRUCTORS)
OBJECT_CONDITIONAL (
clog << ">-< ~Image_Viewer: @ " << (void*)this << endl;)
#endif
}
/*==============================================================================
Image
*/
bool
Image_Viewer::image
(
const QString& source_name,
const QSize& display_size
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::image (QString, QSize) "
<< object_pathname (this) << endl
<< " source_name = \"" << source_name << '"' << endl
<< " display_size = " << display_size << endl;)
#endif
bool
loaded;
if (display_size.isEmpty ())
loaded = Image_Display->image (source_name, viewport_size ());
else
loaded = Image_Display->image (source_name, display_size);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::image (QString, QSize) "
<< object_pathname (this) << ": " << boolalpha << loaded << endl;)
#endif
return loaded;
}
bool
Image_Viewer::image
(
const QString& source_name,
const QSizeF& scaling
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::image (QString, QSizeF) "
<< object_pathname (this) << endl
<< " source_name = \"" << source_name << '"' << endl
<< " scaling = " << scaling << endl;)
#endif
bool
loaded;
if (scaling.isEmpty ())
loaded = image (source_name, QSize ());
else
loaded = Image_Display->image (source_name, scaling);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::image (QString, QSizeF) "
<< object_pathname (this) << ": " << boolalpha << loaded << endl;)
#endif
return loaded;
}
bool
Image_Viewer::image
(
const Shared_Image& source_image,
const QSize& display_size
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::image (Shared_Image, QSize) "
<< object_pathname (this) << endl
<< " source_" << *source_image << endl
<< " display_size = " << display_size << endl;)
#endif
bool
loaded;
if (display_size.isEmpty ())
loaded = Image_Display->image (source_image, viewport_size ());
else
loaded = Image_Display->image (source_image, display_size);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::image (Shared_Image, QSize) "
<< object_pathname (this) << ": " << boolalpha << loaded << endl;)
#endif
return loaded;
}
bool
Image_Viewer::image
(
const Shared_Image& source_image,
const QSizeF& scaling
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::image (Shared_Image, QSizeF) "
<< object_pathname (this) << endl
<< " source_" << *source_image << endl
<< " scaling = " << scaling << endl;)
#endif
bool
loaded;
if (scaling.isEmpty ())
loaded = image (source_image, QSize ());
else
loaded = Image_Display->image (source_image, scaling);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::image (Shared_Image, QSizeF) "
<< object_pathname (this) << ": " << boolalpha << loaded << endl;)
#endif
return loaded;
}
bool
Image_Viewer::image
(
const QImage& source_image,
const QSize& display_size
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << ">>> Image_Viewer::image (QImage, QSize) "
<< object_pathname (this) << endl
<< " source_image @ " << (void*)&source_image << endl
<< " display_size = " << display_size << endl));)
#endif
// Copy the source image.
const Plastic_Image
*source;
Plastic_Image
*plastic_image;
if ((source = dynamic_cast<const Plastic_Image*>(&source_image)))
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " cloning the Plastic_Image" << endl;)
#endif
plastic_image = source->clone ();
}
else
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " wrapping the QImage in a Plastic_Image" << endl;)
#endif
plastic_image = new Plastic_QImage (source_image);
}
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " new " << *plastic_image << endl;)
#endif
QSize
fit_to_size (display_size);
if (fit_to_size.isEmpty ())
fit_to_size = viewport_size ();
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " fit_to_size = " << fit_to_size << endl;)
#endif
bool
registered = image (Shared_Image (plastic_image), fit_to_size);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << "<<< Image_Viewer::image "
<< object_pathname (this) << ": " << boolalpha << registered << endl));)
#endif
return registered;
}
bool
Image_Viewer::image
(
const QImage& source_image,
const QSizeF& scaling
)
{
if (scaling.isEmpty ())
return image (source_image, QSize ());
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << ">>> Image_Viewer::image (QImage, QSizeF) "
<< object_pathname (this) << endl
<< " source_image @ " << (void*)&source_image << endl
<< " scaling = " << scaling << endl));)
#endif
// Copy the source image.
const Plastic_Image
*source;
Plastic_Image
*plastic_image;
if ((source = dynamic_cast<const Plastic_Image*>(&source_image)))
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " cloning the Plastic_Image" << endl;)
#endif
plastic_image = source->clone ();
}
else
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " wrapping the QImage in a Plastic_Image" << endl;)
#endif
plastic_image = new Plastic_QImage (source_image);
}
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
clog << " new " << *plastic_image << endl;)
#endif
bool
registered = image (Shared_Image (plastic_image), scaling);
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << "<<< Image_Viewer::image "
<< object_pathname (this) << ": " << boolalpha << registered << endl));)
#endif
return registered;
}
void
Image_Viewer::loaded
(
bool successful
)
{
#if ((DEBUG_SECTION) & DEBUG_LOAD_IMAGE)
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << ">>> Image_Viewer::loaded " << object_pathname (this)
<< ": " << boolalpha << successful << endl));)
#endif
Source_Name = Image_Display->image_name ();
// Reset the image display conditions.
QSize
display_size (size ());
if (! display_size.isValid ())
display_size = sizeHint ();
layout_display (display_size);
update_sliding_scale ();
update_actions ();
if (! Block_Image_Updates)
{
// >>> SIGNAL <<<
#if ((DEBUG_SECTION) & (DEBUG_LOAD_IMAGE | DEBUG_SIGNALS))
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << "^^^ Image_Viewer::loaded: "
"emit image_loaded " << boolalpha << successful << endl));)
#endif
emit image_loaded (successful);
}
#if ((DEBUG_SECTION) & (DEBUG_LOAD_IMAGE | DEBUG_SIGNALS))
else
{
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << " Image_Viewer::loaded: emit image_loaded "
<< boolalpha << successful << " blocked" << endl));)
}
OBJECT_CONDITIONAL (
LOCKED_LOGGING ((
clog << "<<< Image_Viewer::loaded " << object_pathname (this) << endl));)
#endif
}
void
Image_Viewer::cancel_rendering ()
{Image_Display->cancel_rendering ();}
/*==============================================================================
Layout
*/
void
Image_Viewer::layout_display
(
QSize display_size
)
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::layout_display " << object_pathname (this) << endl
<< " display_size = " << display_size << endl;)
#endif
QSize
scaled_image_size (Image_Display->scaled_image_size ());
if (display_size.isEmpty ())
display_size = scaled_image_size;
QSize
widget_size (display_size);
int
frame_margin = frameWidth ();
// Exclude the frame margins from the image display size.
display_size.rwidth () -= (frame_margin << 1);
display_size.rheight () -= (frame_margin << 1);
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " viewport size = " << size () << endl
<< " widget size = " << widget_size << endl
<< " frame width = " << frame_margin << endl
<< " image display size = " << display_size << endl
<< " displayed_image_region = " << displayed_image_region () << endl
<< " scaled_image_size = " << scaled_image_size << endl
<< " scrollbars enabled = " << boolalpha << Scrollbars_Enabled
<< endl;)
#endif
bool
vertical_scrollbar_visible = false,
horizontal_scrollbar_visible = false,
sliding_scale_visible = false;
int
sliding_scale_x = 0,
sliding_scale_height = 0;
if (Scrollbars_Enabled &&
! scaled_image_size.isEmpty ())
{
sliding_scale_visible = true;
display_size.rwidth () -= Sliding_Scale_Width;
sliding_scale_x =
frame_margin + display_size.rwidth ();
sliding_scale_height =
display_size.rheight () - Horizontal_Scrollbar_Height;
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Sliding_Scale visible" << endl
<< " image display width reduced by "
<< Sliding_Scale_Width << endl;)
#endif
if (scaled_image_size.rheight () > display_size.rheight ())
{
vertical_scrollbar_visible = true;
display_size.rwidth () -= Vertical_Scrollbar_Width;
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Vertical_Scrollbar visible" << endl
<< " image display width reduced by "
<< Vertical_Scrollbar_Width << endl;)
#endif
}
if (scaled_image_size.rwidth () > display_size.rwidth ())
{
horizontal_scrollbar_visible = true;
display_size.rheight () -= Horizontal_Scrollbar_Height;
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Horizontal_Scrollbar visible" << endl
<< " image display height reduced by "
<< Horizontal_Scrollbar_Height << endl;)
#endif
if (! vertical_scrollbar_visible &&
scaled_image_size.rheight () > display_size.rheight ())
{
vertical_scrollbar_visible = true;
display_size.rwidth () -= Vertical_Scrollbar_Width;
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Vertical_Scrollbar visible" << endl
<< " image display width reduced by "
<< Vertical_Scrollbar_Width << endl;)
#endif
}
}
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Image_Display geometry, request = "
<< frame_margin << "x, "
<< frame_margin << "y, "
<< display_size.rwidth () << "w, "
<< display_size.rheight () << 'h' << endl;)
#endif
Image_Display->setGeometry
(frame_margin, frame_margin,
display_size.rwidth (), display_size.rheight ());
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Image_Display geometry, actual = "
<< Image_Display->geometry () << endl;)
#endif
Vertical_Scrollbar->setVisible (vertical_scrollbar_visible);
if (vertical_scrollbar_visible)
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Vertical_Scrollbar geometry = "
<< (frame_margin + display_size.rwidth ()) << "x, "
<< frame_margin << "y, "
<< Vertical_Scrollbar_Width << "w, "
<< display_size.rheight () << 'h' << endl;)
#endif
Vertical_Scrollbar->setGeometry
(frame_margin + display_size.rwidth (), frame_margin,
Vertical_Scrollbar_Width, display_size.rheight ());
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " "
<< Vertical_Scrollbar->geometry () << endl;)
#endif
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
else
OBJECT_CONDITIONAL (
clog << " Vertical_Scrollbar not visible" << endl;)
#endif
Horizontal_Scrollbar->setVisible (horizontal_scrollbar_visible);
if (horizontal_scrollbar_visible)
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Horizontal_Scrollbar geometry = "
<< frame_margin << "x, "
<< (frame_margin + display_size.rheight ()) << "y, "
<< display_size.rwidth () << "w, "
<< Horizontal_Scrollbar_Height << 'h' << endl;)
#endif
Horizontal_Scrollbar->setGeometry
(frame_margin, frame_margin + display_size.rheight (),
display_size.rwidth (), Horizontal_Scrollbar_Height);
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " "
<< Horizontal_Scrollbar->geometry () << endl;)
#endif
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
else
OBJECT_CONDITIONAL (
clog << " Horizontal_Scrollbar not visible" << endl;)
#endif
Sliding_Scale->setVisible (sliding_scale_visible);
Sliding_Scale_Value->setVisible (sliding_scale_visible);
if (sliding_scale_visible)
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Sliding_Scale geometry = "
<< sliding_scale_x << "x, "
<< frame_margin << "y, "
<< Sliding_Scale_Width << "w, "
<< sliding_scale_height << 'h' << endl;)
#endif
Sliding_Scale->setGeometry
(sliding_scale_x, frame_margin,
Sliding_Scale_Width, sliding_scale_height);
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " "
<< Sliding_Scale->geometry () << endl;)
#endif
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Sliding_Scale_Value location = "
<< sliding_scale_x << "x, "
<< (frame_margin + sliding_scale_height) << 'y' << endl;)
#endif
Sliding_Scale_Value->move
(sliding_scale_x, frame_margin + sliding_scale_height);
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " "
<< Sliding_Scale_Value->geometry () << endl;)
#endif
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
else
OBJECT_CONDITIONAL (
clog << " Sliding_Scale not visible" << endl;)
#endif
adjust_scrollbars_range ();
if (vertical_scrollbar_visible &&
horizontal_scrollbar_visible)
{
LRC_Widget->move
(frame_margin + display_size.rwidth (),
frame_margin + display_size.rheight ());
LRC_Widget->setVisible (true);
}
else
LRC_Widget->setVisible (false);
if (widget_size != size ())
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " Image_Viewer::layout_display: adjusting ..." << endl;)
#endif
updateGeometry ();
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_EVENTS))
OBJECT_CONDITIONAL (
clog << " displayed_image_region = " << displayed_image_region () << endl
<< "<<< Image_Viewer::layout_display " << object_pathname (this) << endl;)
#endif
}
QSize
Image_Viewer::sizeHint () const
{
#if ((DEBUG_SECTION) & DEBUG_SIZE_HINT)
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::sizeHint" << endl
<< " Image_Display sizeHint = " << Image_Display->sizeHint () << endl;)
#endif
QSize
display_size (Image_Display->sizeHint ());
if (display_size.isEmpty ())
display_size = DEFAULT_IMAGE_DISPLAY_SIZE;
display_size.rwidth () += (frameWidth () << 1);
display_size.rheight () += (frameWidth () << 1);
if (Vertical_Scrollbar &&
Vertical_Scrollbar->isVisible ())
display_size.rwidth () += Vertical_Scrollbar_Width;
if (Sliding_Scale &&
Sliding_Scale->isVisible ())
display_size.rwidth () += Sliding_Scale_Width;
if (Horizontal_Scrollbar &&
Horizontal_Scrollbar->isVisible ())
display_size.rheight () += Horizontal_Scrollbar_Height;
#if ((DEBUG_SECTION) & DEBUG_SIZE_HINT)
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::sizeHint: " << display_size << endl;)
#endif
return display_size;
}
QSize
Image_Viewer::viewport_size () const
{
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_LOAD_IMAGE))
OBJECT_CONDITIONAL (
clog << ">>> Image_Viewer::viewport_size" << endl;)
#endif
QSize
preferred_size (Image_Display->size ());
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_LOAD_IMAGE))
OBJECT_CONDITIONAL (
clog << " Image_Display size = " << preferred_size << endl;)
#endif
if (preferred_size.isEmpty ())
preferred_size = DEFAULT_IMAGE_DISPLAY_SIZE;
else
{
// Use the display size sans scrollbars.
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_LOAD_IMAGE))
OBJECT_CONDITIONAL (
clog << " adjusting for scrollbars" << endl;)
#endif
if (Vertical_Scrollbar &&
Vertical_Scrollbar->isVisible ())
preferred_size.rwidth () += Vertical_Scrollbar_Width;
if (Horizontal_Scrollbar &&
Horizontal_Scrollbar->isVisible ())
preferred_size.rheight () += Horizontal_Scrollbar_Height;
// !!! Hack to ensure that the image will fit without scrollbars.
preferred_size.rwidth () -= 1;
preferred_size.rheight () -= 1;
}
#if ((DEBUG_SECTION) & (DEBUG_LAYOUT | DEBUG_LOAD_IMAGE))
OBJECT_CONDITIONAL (
clog << "<<< Image_Viewer::viewport_size: " << preferred_size << endl;)
#endif
return preferred_size;
}
QSize
Image_Viewer::image_display_size () const
{
#if ((DEBUG_SECTION) & DEBUG_LAYOUT)