COPASI API  4.16.103
CQEffectDescriptionEdit.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include <QtGui/QColorDialog>
7 
10 
11 #if QT_VERSION < 0x040800
12 #include <QtGui/QPainter>
13 #endif
14 
15 CQEffectDescriptionEdit::CQEffectDescriptionEdit(QWidget* parent, Qt::WindowFlags f):
16  QWidget(parent, f),
17  mpCurrent(NULL)
18 {
19  setupUi(this);
20 }
21 
23 {
24 }
25 
26 void setColor(QLabel *widget, const QColor& color)
27 {
28  QPalette palette(color);
29  palette.setColor(QPalette::Base, color);
30  palette.setColor(QPalette::Background, color);
31  palette.setColor(QPalette::Window, color);
32  palette.setColor(QPalette::Foreground, color);
33  widget->setPalette(palette);
34  QImage image(widget->rect().size(), QImage::Format_ARGB32);
35 
36 #if QT_VERSION >= 0x040800
37  image.fill(color);
38 #else
39  QPainter painter(&image);
40  painter.fillRect(widget->rect(), color);
41 #endif
42 
43  QPixmap pix = QPixmap::fromImage(image);
44  widget->setPixmap(pix);
45 }
46 
47 void CQEffectDescriptionEdit::initFrom(const CQEffectDescription* other, bool multiple)
48 {
49  setColor(txtColorEnd, other->getEndColor());
50  setColor(txtColorStart, other->getStartColor());
51 
52  if (multiple)
53  txtObjectName->setText("");
54  else
55  txtObjectName->setText(other->getCN().c_str());
56 
57  txtScaleStart->setText(QString::number(other->getScaleStart()));
58  txtScaleEnd->setText(QString::number(other->getScaleEnd()));
59 
60  switch (other->getMode())
61  {
63  radColorize->setChecked(true);
64  break;
65 
67  radShadow->setChecked(true);
68  break;
69 
70  default:
72  radScale->setChecked(true);
73  break;
74  }
75 }
76 
77 void CQEffectDescriptionEdit::saveTo(CQEffectDescription* other, bool /* multiple*/)
78 {
79  other->setStartColor(txtColorStart->palette().color(QPalette::Background));
80  other->setEndColor(txtColorEnd->palette().color(QPalette::Background));
81  other->setScaleStart(txtScaleStart->text().toDouble());
82  other->setScaleEnd(txtScaleEnd->text().toDouble());
83 
84  if (radColorize->isChecked())
86  else if (radShadow->isChecked())
88  else
90 }
91 
93 {
94  CQEffectDescription *result = new CQEffectDescription(txtObjectName->text().toStdString());
95 
96  result->setStartColor(txtColorStart->palette().color(QPalette::Background));
97  result->setEndColor(txtColorEnd->palette().color(QPalette::Background));
98  result->setScaleStart(txtScaleStart->text().toDouble());
99  result->setScaleEnd(txtScaleEnd->text().toDouble());
100 
101  if (radColorize->isChecked())
103  else if (radShadow->isChecked())
105  else
107 
108  return result;
109 }
110 
112 {
113 }
114 
116 {
117 }
118 
120 {
121 }
122 
124 {
125 }
126 
128 {
129  setColor(txtColorEnd, QColorDialog::getColor(txtColorEnd->palette().color(QPalette::Background), this));
130 }
131 
133 {
134  setColor(txtColorStart, QColorDialog::getColor(txtColorStart->palette().color(QPalette::Background), this));
135 }
void saveTo(CQEffectDescription *other, bool multiple=false)
const QColor & getEndColor() const
void setScaleStart(qreal scale)
const std::string & getCN() const
void initFrom(const CQEffectDescription *other, bool multiple=false)
void setColor(QLabel *widget, const QColor &color)
CQEffectDescription * toDescription() const
CQEffectDescriptionEdit(QWidget *parent=0, Qt::WindowFlags f=0)
void setStartColor(const QColor &color)
QColor getColor(const CLColorDefinition *cd)
const QColor & getStartColor() const
qreal getScaleStart() const
void setScaleEnd(qreal scale)
void setEndColor(const QColor &color)