Fixed text file permissions
[snark14.git] / tools / Display / selectimages.cpp
1 /** @file selectimages.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 "selectimages.hpp"
9 #include "variables.hpp"
10
11 #include <malloc.h>
12 #include <qfont.h>
13 #include <qframe.h>
14 #include <q3listbox.h>
15 #include <qpushbutton.h>
16 #include <qlayout.h>
17 #include <qvariant.h>
18 #include <qtooltip.h>
19 #include <qwhatsthis.h>
20 #include <qmessagebox.h>
21
22 /* 
23  *  Constructs a selectimageswindow which is a child of 'parent', with the 
24  *  name 'name' and widget flags set to 'f' 
25  *
26  *  The dialog will by default be modeless, unless you set 'modal' to
27  *  TRUE to construct a modal dialog.
28  */
29 selectimageswindow::selectimageswindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
30     : QDialog( parent, name, modal, fl )
31 {
32     int i;
33
34     if ( !name )
35         setName( "selectimageswindow" );
36     resize( 540, 350 ); 
37     setMinimumSize( QSize( 540, 350 ) );
38     setMaximumSize( QSize( 540, 350 ) );
39     setCaption( tr( "Select Images" ) );
40
41     okbutton = new QPushButton( this, "okbutton" );
42     okbutton->setGeometry( QRect( 10, 15, 140, 40 ) ); 
43     okbutton->setText( tr( "Ok" ) );
44     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(accept()));
45
46     selectbutton = new QPushButton( this, "selectbutton" );
47     selectbutton->setGeometry( QRect( 10, 65, 140, 40 ) ); 
48     selectbutton->setText( tr( "Select All" ) );
49     QObject::connect(selectbutton,SIGNAL(clicked()),this,SLOT(selectAll()));
50
51     clearselectbutton = new QPushButton( this, "clearselectbutton" );
52     clearselectbutton->setGeometry( QRect( 10, 115, 140, 40 ) ); 
53     clearselectbutton->setText( tr( "Clear Selected" ) );
54     QObject::connect(clearselectbutton,SIGNAL(clicked()),this,SLOT(clearSelected()));
55
56     imageslistbox = new QListBox( this, "imageslistbox" );
57     imageslistbox->setSelectionMode(QListBox::Multi);
58     QFont f = QFont("courier",10,25,false);
59     f.setFixedPitch(true);
60     imageslistbox->setFont(f);
61     for(i=0;i<numimages;i++)
62       imageslistbox->insertItem(imagetitles[i]);
63     imageslistbox->setGeometry( QRect( 160, 15, 370, 250 ) ); 
64
65     Line6 = new QFrame( this, "Line6" );
66     Line6->setGeometry( QRect( 0, 280, 540, 16 ) ); 
67     Line6->setFrameStyle( QFrame::HLine | QFrame::Sunken );
68
69     cancelbutton = new QPushButton( this, "cancelbutton" );
70     cancelbutton->setGeometry( QRect( 300, 300, 100, 40 ) ); 
71     cancelbutton->setText( tr( "Cancel" ) );
72     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
73 }
74
75 /*  
76  *  Destroys the object and frees any allocated resources
77  */
78 selectimageswindow::~selectimageswindow()
79 {
80     // no need to delete child widgets, Qt does it all for us
81 }
82
83 int* selectimageswindow::getSelectedImages()
84 {
85   int i,j,nsi=0,*siarray;
86
87   for(i=0;i<numimages;i++) 
88     if(imageslistbox->isSelected(i))
89        nsi++;
90
91   siarray = (int*) malloc((unsigned) (nsi+1)*sizeof(int));
92   if(!siarray) {
93     QMessageBox::information(this,"SnarkDisplay","Error!\n"
94                              "Allocation failure in getSelectedImages()\n");
95   }
96   else {
97     siarray[0]=nsi;
98     j=1;
99     for(i=0;i<numimages;i++) 
100       if(imageslistbox->isSelected(i)) {
101         siarray[j]=i;
102         j++;
103       }
104   }
105   return siarray;
106 }
107
108 void selectimageswindow::selectAll()
109 {
110   imageslistbox->selectAll(true);
111 }
112
113 void selectimageswindow::clearSelected()
114 {
115   imageslistbox->selectAll(false);
116 }