Tool for inserting changelog into rst documents (i.e. manual)
[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   enabledButton.setCheckState(Qt::Checked);
42   layout->addWidget(&enabledButton);
43   colorButton.setFlat(true);
44   colorButton.setPalette(QPalette(qcolor()));
45   colorButton.setAutoFillBackground(true);
46   connect(&colorButton, SIGNAL(clicked()), this, SLOT(promptColor()));
47   layout->addWidget(&colorButton);
48   motifText.setValidator(&iupacValidator);
49   layout->addWidget(&motifText);
50   layout->addWidget(&motifName);
51   
52   setLayout(layout);
53 }
54
55 void MotifDetail::setMotif(const string &m)
56 {
57   motifText.setText(m.c_str());
58 }
59
60 string MotifDetail::motif() const
61 {
62   return motifText.text().toStdString();
63 }
64
65 void MotifDetail::setName(const std::string& name)
66 {
67   motifName.setText(name.c_str());
68 }
69
70 std::string MotifDetail::name() const
71 {
72   return motifName.text().toStdString();
73 }
74
75 void MotifDetail::setColor(const Color &c)
76 {
77   motif_color = c;
78   colorButton.setPalette(QPalette(qcolor()));
79 }
80
81 Color MotifDetail::color() const
82 {
83   return motif_color;
84 }
85
86 QColor MotifDetail::qcolor() const
87 {
88   QColor qc;
89   qc.setRedF(motif_color.r());
90   qc.setGreenF(motif_color.g());
91   qc.setBlueF(motif_color.b());
92   return qc;
93 }
94
95 void MotifDetail::promptColor()
96 {
97   QColor new_qcolor = QColorDialog::getColor(qcolor(), this);
98   Color new_color(new_qcolor.redF(), new_qcolor.greenF(), new_qcolor.blueF());
99   setColor(new_color);
100 }
101
102 bool MotifDetail::enabled() const
103 {
104   return (enabledButton.checkState() == Qt::Checked);
105 }