Update SequenceDescription to have signal/slots
[mussa.git] / qui / seqbrowser / SequenceDescription.cpp
1 #include <QVBoxLayout>
2
3 #include "qui/seqbrowser/SequenceDescription.hpp"
4
5 using namespace std;
6
7 SequenceDescription::SequenceDescription(QWidget *parent)
8   : QFrame(parent), 
9     pos(-1) // set pos to an invalid value so the setPos function will call
10             // setText
11 {
12   createWidget();
13 }
14
15 SequenceDescription::SequenceDescription(string name, int length, 
16                                          QWidget *parent)
17   : QFrame(parent),
18     pos(-1) // set pos to an invalid value so the setPos function will call
19             // setText
20 {
21   setName(name);
22   setLength(length);
23   createWidget();
24 }
25
26 void SequenceDescription::createWidget()
27 {
28   setFrameStyle(QFrame::Panel | QFrame::Sunken);
29   setLineWidth(1);
30   QLayout *layout = new QVBoxLayout;
31   layout->addWidget(&name_label);
32   layout->addWidget(&length_label);
33   layout->addWidget(&position_label);
34   setLayout(layout);
35 }
36
37 void SequenceDescription::setName(std::string name)
38 {
39   if (name != name_label.text().toStdString()) {
40     name_label.setText(name.c_str());
41     emit nameChanged(name);
42   }
43 }
44
45 void SequenceDescription::setLength(int length_)
46 {
47   QString s;
48   float short_length = length_;
49   if (length_ != length) {
50     if (short_length > 1000000) {
51       short_length /= 1000000;
52       s.setNum(short_length, 'f', 2);
53       s += "mb";
54     } if (short_length > 1000) {
55       short_length /= 1000;
56       s.setNum(short_length, 'f', 2);
57       s += "kb";
58     } else {
59       s.setNum(short_length);
60       s += "b";
61     }
62     length_label.setText(s);
63     length = length_;
64     emit lengthChanged(length);
65   }
66 }
67
68 void SequenceDescription::setPosition(int pos_) 
69
70   QString s; 
71   if (pos != pos_) {
72     pos = pos_;
73     position_label.setText(s.setNum(pos_));
74     emit positionChanged(pos);
75   }
76 }