6c76825e3f2b98b99c748a089f5912c37fa6cc98
[mussa.git] / qui / motif_editor / MotifDetail.cpp
1 #include <QColorDialog>
2 #include <QHBoxLayout>
3 #include <QRegExp>
4
5 #include "qui/motif_editor/MotifDetail.hpp"
6
7 #include <iostream>
8 using namespace std;
9
10 static const QRegExp iupacAlphabet("[ACTGUWRKYSMBHDVN]*", Qt::CaseInsensitive);
11 static const QRegExpValidator iupacValidator(iupacAlphabet, 0);
12
13 MotifDetail::MotifDetail(QWidget *parent)
14   : QWidget(parent),
15     motif_color(1.0, 1.0, 1.0)
16 {
17   setupWidget();
18 }
19
20 MotifDetail::MotifDetail(const MotifDetail &md)
21   : QWidget((QWidget *)md.parent()),
22     motif_color(md.motif_color),
23     motifText(md.motifText.displayText()),
24     motifName(md.motifName.displayText())
25 {
26 }
27
28 MotifDetail::MotifDetail(std::string& m, Color& c, std::string& name, QWidget *parent)
29   : QWidget(parent),
30     motif_color(c),
31     motifText(m.c_str()),
32     motifName(name.c_str())
33 {
34   setupWidget();
35 }
36
37 void MotifDetail::setupWidget()
38 {
39   QHBoxLayout *layout = new QHBoxLayout;
40
41   colorButton.setFlat(true);
42     
43   colorButton.setPalette(QPalette(qcolor()));
44   colorButton.setAutoFillBackground(true);
45   connect(&colorButton, SIGNAL(clicked()), this, SLOT(promptColor()));
46   layout->addWidget(&colorButton);
47   motifText.setValidator(&iupacValidator);
48   layout->addWidget(&motifText);
49   layout->addWidget(&motifName);
50   
51   setLayout(layout);
52 }
53
54 void MotifDetail::setMotif(const string &m)
55 {
56   motifText.setText(m.c_str());
57 }
58
59 string MotifDetail::motif() const
60 {
61   return motifText.text().toStdString();
62 }
63
64 void MotifDetail::setName(const std::string& name)
65 {
66   motifName.setText(name.c_str());
67 }
68
69 std::string MotifDetail::name() const
70 {
71   return motifName.text().toStdString();
72 }
73
74 void MotifDetail::setColor(const Color &c)
75 {
76   motif_color = c;
77   colorButton.setPalette(QPalette(qcolor()));
78 }
79
80 Color MotifDetail::color() const
81 {
82   return motif_color;
83 }
84
85 QColor MotifDetail::qcolor() const
86 {
87   QColor qc;
88   qc.setRedF(motif_color.r());
89   qc.setGreenF(motif_color.g());
90   qc.setBlueF(motif_color.b());
91   return qc;
92 }
93
94 void MotifDetail::promptColor()
95 {
96   QColor new_qcolor = QColorDialog::getColor(qcolor(), this);
97   Color new_color(new_qcolor.redF(), new_qcolor.greenF(), new_qcolor.blueF());
98   setColor(new_color);
99 }