Build for /usr/local/qt3
[snark14.git] / tools / Display / openimages.cpp
1 /** @file openimages.cpp
2     @package snark14Display
3     @author Bruno M. Carvalho and Deniz Sarioz
4     licensed under (open-source) QPL v1.0
5     which accompanies this distribution in the file QPL
6 */
7
8 #include "variables.hpp"
9 #include "openimages.hpp"
10 #include "displaywindow.hpp"
11 #include "SnarkDisplay.hpp"
12
13 #include <stdio.h>
14 #include <qapplication.h>
15 #include <qframe.h>
16 #include <qlistbox.h>
17 #include <qpushbutton.h>
18 #include <qlayout.h>
19 #include <qvariant.h>
20 #include <qtooltip.h>
21 #include <qwhatsthis.h>
22 #include <qwidget.h>
23
24 // extern displaywindow **displaywindowset;
25
26 /* 
27  *  Constructs a openimageswindow which is a child of 'parent', with the 
28  *  name 'name' and widget flags set to 'f' 
29  *
30  *  The dialog will by default be modeless, unless you set 'modal' to
31  *  TRUE to construct a modal dialog.
32  */
33 openimageswindow::openimageswindow( displaywindow** displaywindowset_in, QWidget* parent,  const char* name, bool modal, WFlags fl , int x , int y )
34   //    : QDialog( parent, name, modal, fl )
35   : QWidget( parent, name, fl )
36 {
37     QPoint topleft;
38     displaywindowset = displaywindowset_in;
39     if ( !name )
40         setName( "openimageswindow" );
41     resize( 540, 350 );
42     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
43     setMinimumSize( QSize( 540, 350 ) );
44     setMaximumSize( QSize( 540, 350 ) );
45     setCaption( tr( "Open Images" ) );
46
47     Parent=parent;
48
49     topleft.setX(x);
50     topleft.setY(y);
51     this->move(topleft);
52     openbutton = new QPushButton( this, "openbutton" );
53     openbutton->setGeometry( QRect( 10, 15, 140, 40 ) ); 
54     openbutton->setText( tr( "Open" ) );
55
56     QObject::connect(openbutton,SIGNAL(clicked()) ,this, SLOT(openImages()));
57
58     selectbutton = new QPushButton( this, "selectbutton" );
59     selectbutton->setGeometry( QRect( 10, 65, 140, 40 ) ); 
60     selectbutton->setText( tr( "Select All" ) );
61     QObject::connect(selectbutton,SIGNAL(clicked()),this,SLOT(selectAll()));
62     //    QObject::connect(openbutton,SIGNAL(clicked()) ,parent, SLOT(signalAllDifference(bool)));
63
64
65     clearselectbutton = new QPushButton( this, "clearselectbutton" );
66     clearselectbutton->setGeometry( QRect( 10, 115, 140, 40 ) ); 
67     clearselectbutton->setText( tr( "Clear Selected" ) );
68     QObject::connect(clearselectbutton,SIGNAL(clicked()),this,SLOT(clearSelected()));
69
70     imageslistbox = new QListBox( this, "imageslistbox" );
71     imageslistbox->setSelectionMode(QListBox::Multi);
72     QFont f = QFont("courier",10,25,false);
73     f.setFixedPitch(true);
74     imageslistbox->setFont(f);
75     for(int i=0;i<numimages;i++)
76       imageslistbox->insertItem(imagetitles[i]);
77     imageslistbox->setGeometry( QRect( 160, 15, 370, 250 ) ); 
78
79     Line6 = new QFrame( this, "Line6" );
80     Line6->setGeometry( QRect( 0, 280, 540, 16 ) ); 
81     Line6->setFrameStyle( QFrame::HLine | QFrame::Sunken );
82
83     closebutton = new QPushButton( this, "closebutton" );
84     closebutton->setGeometry( QRect( 380, 300, 100, 40 ) ); 
85     closebutton->setText( tr( "Close" ) );
86     //    QObject::connect(closebutton,SIGNAL(clicked()),this,SLOT(reject()));
87     QObject::connect(closebutton,SIGNAL(clicked()),this,SLOT(close()));
88 }
89
90
91 /*  
92  *  Destroys the object and frees any allocated resources
93  */
94 openimageswindow::~openimageswindow()
95 {
96     // no need to delete child widgets, Qt does it all for us
97 }
98
99
100 void openimageswindow::openImages()
101 {
102   //  std::cerr << "++openimageswindow::openImages()" << std::endl;
103   int i,x,y;
104   QPoint topleft;
105   topleft=this->pos();
106   x=topleft.x();
107   y=topleft.y();
108   for(i=0;i<numimages;i++) {
109 //     std::cerr << "in openimages() for loop, i=" << i << std::endl;
110 //     std::cerr << "displaywindowset[i]=" << (displaywindowset[i]) 
111 //            << " active: " << (displaywindowactive[i] ? "yes" : "no")
112 //            << std::endl;
113     // the new way--should only happen in the first pass of the same recfil
114     //    if(!displaywindowset[i]) {
115       //      displaywindowset[i]=new displaywindow(0,"",false,0,dataformat,i,x,y);
116     //    }
117     if((imageslistbox->isSelected(i)) && (!displaywindowactive[i])) {
118       //      std::cerr << "SHOWING for i=" << i << std::endl;
119       // fixed HUGE bug while trying to fix bug #119 (which was a while ago)
120       //   displaywindow* nw=new displaywindow(desk,"",false,0,dataformat,i,x,y);
121       //   nw->show();
122       x+=30;
123       y+=30;
124       if(y>(maxSizey-630)) {
125         y=30;
126       }
127       if(x>(maxSizex-50)) {
128         x = 30;
129       }
130       if(!displaywindowset[i]) {
131         displaywindowset[i]=new displaywindow(0,"",false,0,dataformat,i,x,y);
132       }
133       displaywindowactive[i]=true;
134       displaywindowset[i]->show();
135       displaywindowset[i]->updateZoom(); // trick to get right size scroll pane
136     }
137   }
138   //  std::cerr << "--openimageswindow::openImages()" << std::endl;
139 } // --openimageswindow::openImages()
140
141
142 void openimageswindow::setImagesNames()
143 {
144   int i;
145   
146   imageslistbox->clear();
147   for(i=0;i<numimages;i++) 
148     imageslistbox->insertItem(imagetitles[i]);
149 }
150
151
152 void openimageswindow::selectAll()
153 {
154   imageslistbox->selectAll(true);
155 }
156
157
158 void openimageswindow::clearSelected()
159 {
160   imageslistbox->selectAll(false);
161 }