Fix the new analysis dialog so it starts at a good size on os x
[mussa.git] / qui / mussa_setup_dialog / SequenceSetupWidget.cpp
1 #include <QHBoxLayout>
2 #include <QVBoxLayout>
3 #include <QLineEdit>
4 #include <QLabel>
5 #include <QFileDialog>
6 #include <QPushButton>
7
8 #include "qui/mussa_setup_dialog/SequenceSetupWidget.hpp"
9 #include "qui/mussa_setup_dialog/SequenceSetupFrame.hpp"
10
11 #include <cassert>
12
13 SequenceSetupWidget::SequenceSetupWidget(SequenceSetupFrame *setupFrame_,
14                                          QWidget *parent) :
15   QWidget(parent),
16   sequenceNameEdit(0),
17   sequenceLineEdit(0), 
18   annotLineEdit(0),
19   fastaIndexLineEdit(0),
20   seqStartLineEdit(0),
21   seqStopLineEdit(0),
22   setupFrame(setupFrame_)
23 {
24   // we really need the setupFrame, so lets declare that requirement
25   assert(setupFrame != 0);
26
27   // Name line
28   sequenceNameEdit = new QLineEdit();
29   sequenceNameEdit->setWhatsThis(tr("Name of input sequence"));
30   QLabel *sequenceNameLabel = new QLabel(tr("Sequence name:"));
31   sequenceNameLabel->setBuddy(sequenceNameEdit);
32   sequenceNameLabel->setWhatsThis(tr("Name of input sequence"));
33
34   // Sequence file location line
35   sequenceLineEdit = new QLineEdit();
36   sequenceLineEdit->setWhatsThis(tr("File path to input sequence"));
37   //const IsFileValidator *fileValidator = new IsFileValidator(this);
38   //sequenceLineEdit->setValidator(fileValidator);
39   QLabel *sequenceLabel = new QLabel("Sequence Filename:");
40   sequenceLabel->setBuddy(sequenceLineEdit);
41   sequenceLabel->setWhatsThis(tr("File path to input sequence"));
42   
43   QPushButton *sequenceButton = new QPushButton(tr("Browse..."));
44   sequenceButton->setWhatsThis(tr("Browse for input sequence"));
45   connect(sequenceButton, SIGNAL(clicked()), 
46           this, SLOT(promptForFastaFile()));
47
48   // Annotation row
49   annotLineEdit = new QLineEdit();
50   annotLineEdit->setWhatsThis(tr("Annotation file path for above input sequence"));
51   //const IsFileValidator *fileValidator2 = new IsFileValidator(this);
52   //annotLineEdit->setValidator(fileValidator2);
53   QLabel *annotLabel = new QLabel(tr("Annotation Filename:"));
54   annotLabel->setBuddy(annotLineEdit);
55   annotLabel->setWhatsThis(tr("Annotation file path for above input sequence"));
56
57   QPushButton *annotButton = new QPushButton(tr("Browse..."));
58   annotButton->setWhatsThis(tr("Browse for annotation file for above input sequence"));
59   connect(annotButton, SIGNAL(clicked()),
60           this, SLOT(promptForAnnotFile()));
61
62   // Index row
63   fastaIndexLineEdit = new QLineEdit();
64   fastaIndexLineEdit->setWhatsThis(tr("When a FASTA file contains more then one FASTA record, provide a 1 based index (first record is index 1) to select which one to use."));
65   //fastaIndexLineEdit->setMaximumWidth(100);
66
67   QLabel *fastaIndexLabel = new QLabel(tr("Fasta Index:"));
68   fastaIndexLabel->setBuddy(fastaIndexLineEdit);
69   fastaIndexLabel->setWhatsThis(tr("When a FASTA file contains more then one FASTA record, provide a 1 based index (first record is index 1) to select which one to use."));
70
71   seqStartLineEdit = new QLineEdit();
72   seqStartLineEdit->setWhatsThis(tr("Start base pair in input sequence (0 based: 1st base pair is 0)"));
73   //seqStartLineEdit->setMinimumWidth(60);
74   //seqStartLineEdit->setMaximumWidth(80);
75
76   QLabel *seqStartLabel = new QLabel(tr("Sequence Start:"));
77   seqStartLabel->setWhatsThis(tr("Start base pair in input sequence (0 based: 1st base pair is 0)"));
78   seqStartLabel->setBuddy(seqStartLineEdit);
79   
80   seqStopLineEdit = new QLineEdit();
81   seqStopLineEdit->setWhatsThis(tr("Stop base pair in input sequence (0 based: 1st base pair is 0) 0 means all of remaining sequence."));
82   //seqStopLineEdit->setMinimumWidth(40);
83   //seqStopLineEdit->setMaximumWidth(60);
84
85   QLabel *seqStopLabel = new QLabel(tr("Sequence Stop:"));
86   seqStopLabel->setWhatsThis(tr("Stop base pair in input sequence (0 based: 1st base pair is 0) 0 means all of remaining sequence."));
87   seqStopLabel->setBuddy(seqStopLineEdit);
88
89   // Layout
90   QVBoxLayout *mainLayout = new QVBoxLayout;
91   QHBoxLayout *sequenceNameLayout = new QHBoxLayout;
92   QHBoxLayout *sequenceRowLayout = new QHBoxLayout;
93   QHBoxLayout *annotRowLayout = new QHBoxLayout;
94   QHBoxLayout *indexRowLayout = new QHBoxLayout;
95
96   sequenceNameLayout->addWidget(sequenceNameLabel);
97   sequenceNameLayout->addWidget(sequenceNameEdit);
98
99   sequenceRowLayout->addWidget(sequenceLabel);
100   sequenceRowLayout->addWidget(sequenceLineEdit);
101   sequenceRowLayout->addWidget(sequenceButton);
102
103   annotRowLayout->addWidget(annotLabel);
104   annotRowLayout->addWidget(annotLineEdit);
105   annotRowLayout->addWidget(annotButton);
106
107   indexRowLayout->addWidget(fastaIndexLabel);
108   indexRowLayout->addWidget(fastaIndexLineEdit);
109   indexRowLayout->addWidget(seqStartLabel);
110   indexRowLayout->addWidget(seqStartLineEdit);
111   indexRowLayout->addWidget(seqStopLabel);
112   indexRowLayout->addWidget(seqStopLineEdit);
113
114   mainLayout->addLayout(sequenceNameLayout);
115   mainLayout->addLayout(sequenceRowLayout);
116   mainLayout->addLayout(annotRowLayout);
117   mainLayout->addLayout(indexRowLayout);
118   setLayout(mainLayout);
119 }
120
121 //SequenceSetupWidget::SequenceSetupWidget(const SequenceSetupWidget& ssw) :
122 //  sequenceLineEdit(ssw.sequenceLineEdit), 
123 //  annotLineEdit(ssw.annotLineEdit),
124 //  fastaIndexLineEdit(ssw.fastaIndexLineEdit),
125 //  seqStartLineEdit(ssw.seqStartLineEdit),
126 //  seqStopLineEdit(ssw.seqStopLineEdit)
127 //{
128 //}
129
130 int SequenceSetupWidget::getFastaIndex() const
131 {
132   if (fastaIndexLineEdit->text().size() == 0)
133     return 1;
134   else
135     return fastaIndexLineEdit->text().toInt(); 
136 }
137
138 void SequenceSetupWidget::promptForFastaFile()
139 {
140   QString default_dir = setupFrame->get_default_dir().absolutePath();
141   QString fastaFilePath = QFileDialog::getOpenFileName(this,
142                                                "Choose a fasta file",
143                                                default_dir,
144                                                "Fasta (*.fa *.fasta *.fsa *.txt)");
145   if (fastaFilePath.isEmpty())
146     return;
147
148   sequenceLineEdit->setText(fastaFilePath);
149   setupFrame->set_default_dir(QDir(fastaFilePath));
150   return;
151 }
152
153 void SequenceSetupWidget::promptForAnnotFile()
154 {
155   QString default_dir = setupFrame->get_default_dir().absolutePath();
156   QString annotFilePath = QFileDialog::getOpenFileName(this,
157                                                "Choose a annotation file",
158                                                default_dir,
159                                                "Annot (*.txt *.annot)");
160   if (annotFilePath.isEmpty())
161     return;
162
163   annotLineEdit->setText(annotFilePath);
164   setupFrame->set_default_dir(QDir(annotFilePath));
165   return;
166 }