All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TextGridSettingsOutside.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file TextGridSettingsOutside.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
30 #include "ui_TextGridSettings.h"
31 #include "../../core/pattern/mvc/OutsideObserver.h"
32 #include "../../core/pattern/mvc/OutsideController.h"
33 #include "../../core/pattern/singleton/Context.h"
34 #include "../../outside/TextGridSettingsController.h"
35 #include "../../core/enum/Enums.h"
36 #include "../../core/property/TextGridSettingsConfigProperties.h"
37 
38 // STL
39 #include <string>
40 #include <sstream>
41 
42 // Qt
43 #include <QCheckBox>
44 #include <QColorDialog>
45 
47  QDialog(0),
48  OutsideObserver(controller, o),
49  m_ui(new Ui::TextGridSettings)
50 {
51  m_ui->setupUi(this);
52 
54 
55  init();
56 }
57 
59 {
60  if(m_propertiesNames)
61  {
62  delete m_propertiesNames;
63  m_propertiesNames = 0;
64  }
65 }
66 
68 {
69  m_ui->lneEdtBorderWidth->setValidator(new QDoubleValidator(this));
70  m_ui->lneEdtColumnsNumber->setValidator(new QDoubleValidator(this));
71 
72  m_ui->lneEdtColumnsWidth->setValidator(new QDoubleValidator(this));
73  m_ui->lneEdtRowsNumber->setValidator(new QDoubleValidator(this));
74 
75  m_ui->lneEdtTablePadding->setValidator(new QDoubleValidator(this));
76  m_ui->lneEdtTableSpacing->setValidator(new QDoubleValidator(this));
77 
78  m_ui->lneEdtTableWidth->setValidator(new QDoubleValidator(this));
79 
80  m_ui->frmBorderColor->setAutoFillBackground(true);
81  m_ui->frmBorderColor->installEventFilter(this);
82 
83  m_ui->frmHeaderHorizontalColor->setAutoFillBackground(true);
84  m_ui->frmHeaderHorizontalColor->installEventFilter(this);
85 
86  m_ui->frmHeaderVerticalColor->setAutoFillBackground(true);
87  m_ui->frmHeaderVerticalColor->installEventFilter(this);
88 
89  m_ui->frmRowsEven->setAutoFillBackground(true);
90  m_ui->frmRowsEven->installEventFilter(this);
91 
92  m_ui->frmRowsOdd->setAutoFillBackground(true);
93  m_ui->frmRowsOdd->installEventFilter(this);
94 
95  m_ui->frmTableColor->setAutoFillBackground(true);
96  m_ui->frmTableColor->installEventFilter(this);
97 }
98 
100 {
101  setVisible(context.isShow());
102  if(context.isShow() == true)
103  show();
104  else
105  hide();
106 }
107 
108 void te::layout::TextGridSettingsOutside::setPosition( const double& x, const double& y )
109 {
110  move(x,y);
111  refresh();
112 }
113 
115 {
116  QPointF posF = pos();
117  qreal valuex = posF.x();
118  qreal valuey = posF.y();
119 
120  te::gm::Coord2D coordinate;
121  coordinate.x = valuex;
122  coordinate.y = valuey;
123 
124  return coordinate;
125 }
126 
128 {
129  initCombo(m_ui->cmbColumnsWidthConstraints, m_propertiesNames->getColumnWidthConstraints());
130 
131  initCombo(m_ui->cmbTableWidthConstraints, m_propertiesNames->getWidthConstraints());
132 
133  initCombo(m_ui->cmbHeaderAlign, m_propertiesNames->getHeaderAlignment());
134 
135  initCombo(m_ui->cmbBorderStyle, m_propertiesNames->getBorderStyle());
136 
137  initCombo(m_ui->cmbCellAlign, m_propertiesNames->getCellAlignment());
138 
139  initDouble(m_ui->lneEdtBorderWidth, m_propertiesNames->getBorderWidth());
140 
141  initInt(m_ui->lneEdtColumnsNumber, m_propertiesNames->getColumnNumber());
142 
143  initDouble(m_ui->lneEdtColumnsWidth, m_propertiesNames->getColumnWidth());
144 
145  initInt(m_ui->lneEdtRowsNumber, m_propertiesNames->getRowNumber());
146 
147  initDouble(m_ui->lneEdtTablePadding, m_propertiesNames->getPadding());
148 
149  initDouble(m_ui->lneEdtTableSpacing, m_propertiesNames->getSpacing());
150 
151  initDouble(m_ui->lneEdtTableWidth, m_propertiesNames->getWidth());
152 
153  initColor(m_ui->frmBorderColor, m_propertiesNames->getBorderGridColor());
154 
155  initColor(m_ui->frmHeaderHorizontalColor, m_propertiesNames->getHeaderHorizontalColor());
156 
157  initColor(m_ui->frmHeaderVerticalColor, m_propertiesNames->getHeaderVerticalColor());
158 
159  initColor(m_ui->frmRowsEven, m_propertiesNames->getEvenRow());
160 
161  initColor(m_ui->frmRowsOdd, m_propertiesNames->getOddRow());
162 
163  initColor(m_ui->frmTableColor, m_propertiesNames->getTableColor());
164 }
165 
167 {
168  te::color::RGBAColor rgbaColor;
169 
170  QPalette ptt(widget->palette());
171  QBrush brush = ptt.brush(widget->backgroundRole());
172 
173  QColor bColor = brush.color();
174  rgbaColor.setColor(bColor.red(), bColor.green(), bColor.blue());
175 
176  QColor color = QColorDialog::getColor(brush.color(),this, "Color" );
177 
178  if(!color.isValid())
179  return rgbaColor;
180 
181  QPalette paltt(widget->palette());
182  paltt.setColor(widget->backgroundRole(), color);
183  widget->setPalette(paltt);
184  widget->setAutoFillBackground(true);
185 
186  rgbaColor.setColor(color.red(), color.green(), color.blue());
187 
188  return rgbaColor;
189 }
190 
192 {
193  QObjectList list = children();
194 
195  QList<QObject*>::Iterator it;
196  for(it = list.begin() ; it != list.end() ; ++it)
197  {
198  QObject* obj = (*it);
199  QWidget* w = dynamic_cast<QWidget*>(obj);
200  if(w)
201  {
202  if(w->isVisible())
203  {
204  w->setEnabled(false);
205  }
206  }
207  }
208 }
209 
211 {
212  QObjectList list = children();
213 
214  QList<QObject*>::Iterator it;
215  for(it = list.begin() ; it != list.end() ; ++it)
216  {
217  QObject* obj = (*it);
218  QWidget* w = dynamic_cast<QWidget*>(obj);
219  if(w)
220  {
221  if(!w->isVisible())
222  {
223  w->setEnabled(true);
224  }
225  }
226  }
227 }
228 
230 {
231  emit updateProperty();
232 
233  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
234  if(controller)
235  {
236  controller->clearUpdate();
237  }
238 }
239 
241 {
242  reject();
243 }
244 
246 {
247  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
248  if(controller)
249  {
251  Variant variant;
252  variant.setValue(text.toStdString(), dataType->getDataTypeString());
253  controller->addUpdateProperty(m_propertiesNames->getColumnWidthConstraints(), variant);
254  }
255 }
256 
258 {
259  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
260  if(controller)
261  {
263  Variant variant;
264  variant.setValue(text.toStdString(), dataType->getDataTypeString());
265  controller->addUpdateProperty(m_propertiesNames->getWidthConstraints(), variant);
266  }
267 }
268 
270 {
271  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
272  if(controller)
273  {
275  Variant variant;
276  variant.setValue(text.toStdString(), dataType->getDataTypeString());
277  controller->addUpdateProperty(m_propertiesNames->getHeaderAlignment(), variant);
278  }
279 }
280 
282 {
283  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
284  if(controller)
285  {
287  Variant variant;
288  variant.setValue(text.toStdString(), dataType->getDataTypeString());
289  controller->addUpdateProperty(m_propertiesNames->getBorderStyle(), variant);
290  }
291 }
292 
294 {
295  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
296  if(controller)
297  {
299  Variant variant;
300  variant.setValue(text.toStdString(), dataType->getDataTypeString());
301  controller->addUpdateProperty(m_propertiesNames->getCellAlignment(), variant);
302  }
303 }
304 
306 {
307  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
308  if(controller)
309  {
311  Variant variant;
312  variant.setValue(m_ui->lneEdtBorderWidth->text().toDouble(), dataType->getDataTypeDouble());
313  controller->addUpdateProperty(m_propertiesNames->getBorderWidth(), variant);
314  }
315 }
316 
318 {
319  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
320  if(controller)
321  {
323  Variant variant;
324  variant.setValue(m_ui->lneEdtColumnsNumber->text().toInt(), dataType->getDataTypeInt());
325  controller->addUpdateProperty(m_propertiesNames->getColumnNumber(), variant);
326  }
327 }
328 
330 {
331  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
332  if(controller)
333  {
335  Variant variant;
336  variant.setValue(m_ui->lneEdtColumnsWidth->text().toDouble(), dataType->getDataTypeDouble());
337  controller->addUpdateProperty(m_propertiesNames->getColumnWidth(), variant);
338  }
339 }
340 
342 {
343  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
344  if(controller)
345  {
347  Variant variant;
348  variant.setValue(m_ui->lneEdtRowsNumber->text().toInt(), dataType->getDataTypeInt());
349  controller->addUpdateProperty(m_propertiesNames->getRowNumber(), variant);
350  }
351 }
352 
354 {
355  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
356  if(controller)
357  {
359  Variant variant;
360  variant.setValue(m_ui->lneEdtTablePadding->text().toDouble(), dataType->getDataTypeDouble());
361  controller->addUpdateProperty(m_propertiesNames->getPadding(), variant);
362  }
363 }
364 
366 {
367  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
368  if(controller)
369  {
371  Variant variant;
372  variant.setValue(m_ui->lneEdtTableSpacing->text().toDouble(), dataType->getDataTypeDouble());
373  controller->addUpdateProperty(m_propertiesNames->getSpacing(), variant);
374  }
375 }
376 
378 {
379  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
380  if(controller)
381  {
383  Variant variant;
384  variant.setValue(m_ui->lneEdtTableWidth->text().toDouble(), dataType->getDataTypeDouble());
385  controller->addUpdateProperty(m_propertiesNames->getWidth(), variant);
386  }
387 }
388 
389 void te::layout::TextGridSettingsOutside::initString( QWidget* widget, std::string nameComponent )
390 {
391  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
392  if(!controller)
393  return;
394 
395  Property prop = controller->getProperty(nameComponent);
396 
397  QLineEdit* edit = dynamic_cast<QLineEdit*>(widget);
398  if(edit)
399  {
400  edit->setText(prop.getValue().toString().c_str());
401  return;
402  }
403 }
404 
405 void te::layout::TextGridSettingsOutside::initInt( QWidget* widget, std::string nameComponent )
406 {
407  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
408  if(!controller)
409  return;
410 
411  std::ostringstream convert;
412  Property prop = controller->getProperty(nameComponent);
413  convert << prop.getValue().toInt();
414 
415  QLineEdit* edit = dynamic_cast<QLineEdit*>(widget);
416  if(edit)
417  {
418  edit->setText(convert.str().c_str());
419  }
420 }
421 
422 void te::layout::TextGridSettingsOutside::initDouble( QWidget* widget, std::string nameComponent )
423 {
424  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
425  if(!controller)
426  return;
427 
428  std::ostringstream convert;
429  convert.precision(15);
430  Property prop = controller->getProperty(nameComponent);
431  double number = prop.getValue().toDouble();
432  convert << number;
433 
434  QLineEdit* edit = dynamic_cast<QLineEdit*>(widget);
435  if(edit)
436  {
437  edit->setText(convert.str().c_str());
438  }
439 }
440 
441 void te::layout::TextGridSettingsOutside::initBool( QWidget* widget, std::string nameComponent )
442 {
443  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
444  if(!controller)
445  return;
446 
447  Property prop = controller->getProperty(nameComponent);
448 
449  QCheckBox* chk = dynamic_cast<QCheckBox*>(widget);
450 
451  if(chk)
452  {
453  chk->setChecked(prop.getValue().toBool());
454  }
455 }
456 
457 void te::layout::TextGridSettingsOutside::initColor( QWidget* widget, std::string nameComponent )
458 {
459  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
460  if(!controller)
461  return;
462 
463  Property prop = controller->getProperty(nameComponent);
464 
465  te::color::RGBAColor color = prop.getValue().toColor();
466  QColor qcolor(color.getRed(), color.getGreen(), color.getBlue());
467 
468  if(!qcolor.isValid())
469  return;
470 
471  if(!widget)
472  return;
473 
474  QPalette paltt(widget->palette());
475  paltt.setColor(widget->backgroundRole(), qcolor);
476  widget->setPalette(paltt);
477  widget->setAutoFillBackground(true);
478 }
479 
480 void te::layout::TextGridSettingsOutside::initCombo( QWidget* widget, std::string nameComponent )
481 {
482  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
483  if(!controller)
484  return;
485 
486  Property prop = controller->getProperty(nameComponent);
487 
488  QComboBox* combo = dynamic_cast<QComboBox*>(widget);
489 
490  if(!combo)
491  return;
492 
494 
495  int index = -1;
496  QVariant variant;
497 
498  if(prop.getType() == dataType->getDataTypeBool())
499  {
500  variant.setValue(prop.getValue().toBool());
501  }
502  else if(prop.getType() == dataType->getDataTypeDouble())
503  {
504  variant.setValue(prop.getValue().toDouble());
505  }
506  else if(prop.getType() == dataType->getDataTypeInt())
507  {
508  variant.setValue(prop.getValue().toInt());
509  }
510  else if(prop.getType() == dataType->getDataTypeString())
511  {
512  variant.setValue(QString(prop.getValue().toString().c_str()));
513  }
514 
515  index = combo->findData(variant);
516  if ( index != -1 )
517  {
518  combo->setCurrentIndex(index);
519  }
520 }
521 
522 bool te::layout::TextGridSettingsOutside::eventFilter( QObject * watched, QEvent * event )
523 {
524  if(event->type() != QEvent::MouseButtonPress)
525  return QWidget::eventFilter(watched, event);
526 
527  QWidget* wgt = 0;
528  std::string name;
529 
530  if(watched == m_ui->frmBorderColor)
531  {
532  wgt = m_ui->frmBorderColor;
533  name = m_propertiesNames->getBorderGridColor();
534  }
535  else if(watched == m_ui->frmHeaderHorizontalColor)
536  {
537  wgt = m_ui->frmHeaderHorizontalColor;
538  name = m_propertiesNames->getHeaderHorizontalColor();
539  }
540  else if(watched == m_ui->frmHeaderVerticalColor)
541  {
542  wgt = m_ui->frmHeaderVerticalColor;
543  name = m_propertiesNames->getHeaderVerticalColor();
544  }
545  else if(watched == m_ui->frmRowsEven)
546  {
547  wgt = m_ui->frmRowsEven;
548  name = m_propertiesNames->getEvenRow();
549  }
550  else if(watched == m_ui->frmRowsOdd)
551  {
552  wgt = m_ui->frmRowsOdd;
553  name = m_propertiesNames->getOddRow();
554  }
555  else if(watched == m_ui->frmTableColor)
556  {
557  wgt = m_ui->frmTableColor;
558  name = m_propertiesNames->getTableColor();
559  }
560 
561  if(wgt)
562  {
563  te::color::RGBAColor color = configColor(wgt);
564 
565  TextGridSettingsController* controller = dynamic_cast<TextGridSettingsController*>(m_controller);
566  if(controller)
567  {
569  Variant variant;
570  variant.setValue(color, dataType->getDataTypeColor());
571  controller->addUpdateProperty(name, variant);
572  }
573  }
574 
575  return QWidget::eventFilter(watched, event);
576 }
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
virtual void initColor(QWidget *widget, std::string nameComponent)
Variant getValue()
Returns stored value.
Definition: Property.cpp:72
double y
y-coordinate.
Definition: Coord2D.h:114
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
Definition: RGBAColor.h:329
TextGridSettingsConfigProperties * m_propertiesNames
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
virtual EnumType * getDataTypeBool() const
Returns value that represents type bool belonging to enumeration.
double x
x-coordinate.
Definition: Coord2D.h:113
virtual Property getProperty(std::string name)
virtual EnumType * getDataTypeDouble() const
Returns value that represents type double belonging to enumeration.
virtual void addUpdateProperty(std::string name, Variant variant)
virtual EnumType * getDataTypeInt() const
Returns value that represents type integer belonging to enumeration.
Abstract class to represent an observer. "View" part of MVC widget. All classes representing the grap...
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
std::auto_ptr< Ui::TextGridSettings > m_ui
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
virtual bool eventFilter(QObject *watched, QEvent *event)
virtual void updateObserver(ContextItem context)
Reimplemented from Observer.
virtual void initString(QWidget *widget, std::string nameComponent)
static Enums & getInstance()
It returns a reference to the singleton instance.
virtual void on_cmbColumnsWidthConstraints_currentIndexChanged(const QString &text)
TextGridSettingsOutside(OutsideController *controller, Observable *o)
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
virtual void on_cmbTableWidthConstraints_currentIndexChanged(const QString &text)
virtual void on_cmbHeaderAlign_currentIndexChanged(const QString &text)
Class acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
Definition: Variant.h:80
virtual EnumType * getDataTypeColor() const
Returns value that represents type te::color::RGBAColor** (color) belonging to enumeration.
double toDouble()
Returns the value of double type. (The setValue method received a double)
Definition: Variant.cpp:316
virtual void initCombo(QWidget *widget, std::string nameComponent)
virtual void initBool(QWidget *widget, std::string nameComponent)
virtual te::color::RGBAColor configColor(QWidget *widget)
virtual void on_cmbCellAlign_currentIndexChanged(const QString &text)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
std::string toString()
Returns the value of string type. (The setValue method received a string)
Definition: Variant.cpp:311
std::string convert(const path &v)
URI path to string.
Definition: path.cpp:219
virtual void initInt(QWidget *widget, std::string nameComponent)
virtual te::gm::Coord2D getPosition()
Method that returns the position llx, lly Reimplement this function in a ItemObserver subclass to pro...
te::color::RGBAColor toColor()
Returns the value of te::color::RGBAColor type. (The setValue method received a te::color::RGBAColor)...
Definition: Variant.cpp:341
Abstract class to represent a controller. "Controller" part of MVC widget. All classes representing t...
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
virtual void on_cmbBorderStyle_currentIndexChanged(const QString &text)
EnumType * getType()
Returns the type of this property.
Definition: Property.cpp:67
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.
Definition: Property.h:47
int toInt()
Returns the value of int type. (The setValue method received a int)
Definition: Variant.cpp:321
virtual void setPosition(const double &x, const double &y)
Change coordinate llx,lly of the MVC widget. Reimplement this function in a ItemController subclass t...
virtual void initDouble(QWidget *widget, std::string nameComponent)
bool toBool()
Returns the value of boolean type. (The setValue method received a boolean)
Definition: Variant.cpp:336
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Variant.h:288