ColorPlugin.cc 23.7 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
42

43
#include "ColorPlugin.hh"
Matthias Möller's avatar
Matthias Möller committed
44
45
46
47
48
49

#if QT_VERSION >= 0x050000 
  #include <QtWidgets>
#else
  #include <QtGui>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
50
51

#include <iostream>
Jan Möbius's avatar
Jan Möbius committed
52
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
53
54
55
56

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

57
58
59
60
61
62
63
64
65
66
67
68

//-----------------------------------------------------------------------------

/** \brief Constructor
 *
 */
ColorPlugin::ColorPlugin() : optionsWidget_(0)
{

  //set default values for colors

  backgroundColorDefault_      = ACG::GLState::default_clear_color;
Jan Möbius's avatar
Jan Möbius committed
69
70
  backgroundColorPaper_        = OpenMesh::Vec4f(1.00f, 1.00f, 1.00f, 1.0f);
  backgroundColorPresentation_ = OpenMesh::Vec4f(0.0f, 0.188f, 0.062f, 1.0f);
71
  baseColorDefault_      = ACG::GLState::default_base_color;
Jan Möbius's avatar
Jan Möbius committed
72
73
  baseColorPaper_        = OpenMesh::Vec4f(0.00f, 0.00f, 0.00f, 1.0f);
  baseColorPresentation_ = OpenMesh::Vec4f(0.88f, 0.88f,  0.188f, 1.0f);
74
  materialColorDefault_      = ACG::GLState::default_diffuse_color;
Jan Möbius's avatar
Jan Möbius committed
75
76
  materialColorPaper_        = OpenMesh::Vec4f(0.12f, 0.76f, 0.62f, 1.0f);
  materialColorPresentation_ = OpenMesh::Vec4f(0.941f, 0.439f, 0.31f, 1.0f);
77
78
79
80
81
82
83
84
85
86
87
88
89

  lineWidthDefault_      = 1.0;
  lineWidthPaper_        = 2.0;
  lineWidthPresentation_ = 1.0;

}


//-----------------------------------------------------------------------------

/** \brief initialize the toolbar and menubar
 *
 */
Jan Möbius's avatar
 
Jan Möbius committed
90
91
void ColorPlugin::pluginsInitialized()
{
Jan Möbius's avatar
Jan Möbius committed
92
93
94
  // =============================================================================
  // Add a Menu for color selection
  // =============================================================================
Jan Möbius's avatar
Jan Möbius committed
95
  QMenu *colorMenu = new QMenu(tr("&Color schemes"));
Jan Möbius's avatar
Jan Möbius committed
96
97

  colorMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"format-stroke-color.png"));
Jan Möbius's avatar
   
Jan Möbius committed
98
  emit addMenubarAction(colorMenu->menuAction(), VIEWMENU );
Jan Möbius's avatar
Jan Möbius committed
99

Jan Möbius's avatar
Jan Möbius committed
100
101
102
  // =============================================================================
  // Add Menu entries
  // =============================================================================
103
  WhatsThisGenerator whatsThis("Color");
Jan Möbius's avatar
Jan Möbius committed
104

Jan Möbius's avatar
Jan Möbius committed
105
  QAction* AC_set_Default_color = new QAction(tr("&Default colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
106
  AC_set_Default_color->setStatusTip(tr("Set Default Colors"));
107
  AC_set_Default_color->setWhatsThis(tr("Set colors to default colors. ")+whatsThis.generateLink());
Jan Möbius's avatar
Jan Möbius committed
108
  AC_set_Default_color->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-default.png"));
Jan Möbius's avatar
 
Jan Möbius committed
109
110
  connect(AC_set_Default_color, SIGNAL(triggered()), this, SLOT(setDefaultColor()));
  colorMenu->addAction(AC_set_Default_color);
Jan Möbius's avatar
Jan Möbius committed
111

112
113
  QAction* AC_set_Presentation_color = new QAction(tr("&Presentation colors"), this);
  AC_set_Presentation_color->setStatusTip(tr("Set Presentation Colors"));
114
  AC_set_Presentation_color->setWhatsThis(tr("Set colors to presentation colors. ")+whatsThis.generateLink());
Jan Möbius's avatar
Jan Möbius committed
115
  AC_set_Presentation_color->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-powerpoint.png"));
116
117
  connect(AC_set_Presentation_color, SIGNAL(triggered()), this, SLOT(setPresentationColor()));
  colorMenu->addAction(AC_set_Presentation_color);
Jan Möbius's avatar
Jan Möbius committed
118

Jan Möbius's avatar
Jan Möbius committed
119
  QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
120
  AC_set_Paper_color->setStatusTip(tr("Set Paper Colors"));
121
  AC_set_Paper_color->setWhatsThis(tr("Set colors to colors for papers. ")+whatsThis.generateLink());
Jan Möbius's avatar
Jan Möbius committed
122
  AC_set_Paper_color->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-paper.png"));
Jan Möbius's avatar
 
Jan Möbius committed
123
124
  connect(AC_set_Paper_color, SIGNAL(triggered()), this, SLOT(setPaperColor()));
  colorMenu->addAction(AC_set_Paper_color);
Jan Möbius's avatar
Jan Möbius committed
125

Jan Möbius's avatar
Jan Möbius committed
126
  // =============================================================================
Jan Möbius's avatar
Jan Möbius committed
127
  // Create Tool bar with same contents
Jan Möbius's avatar
Jan Möbius committed
128
129
  // =============================================================================

Jan Möbius's avatar
Jan Möbius committed
130
  QToolBar* toolbar = new QToolBar(tr("Color Toolbar"));
Jan Möbius's avatar
 
Jan Möbius committed
131
  toolbar->addAction(AC_set_Default_color);
132
  toolbar->addAction(AC_set_Presentation_color);
Jan Möbius's avatar
 
Jan Möbius committed
133
134
  toolbar->addAction(AC_set_Paper_color);
  emit addToolbar( toolbar );
Jan Möbius's avatar
Jan Möbius committed
135

Jan Möbius's avatar
 
Jan Möbius committed
136
137
}

138
139
140
141
142
143

//-----------------------------------------------------------------------------

/** \brief set the defaultColor preset
 *
 */
Jan Möbius's avatar
 
Jan Möbius committed
144
void ColorPlugin::setDefaultColor() {
Jan Möbius's avatar
Jan Möbius committed
145

Jan Möbius's avatar
Jan Möbius committed
146
147
148
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
149
  emit scriptInfo( "setDefaultColor()" );
Jan Möbius's avatar
Jan Möbius committed
150
  emit showStatusMessage( tr("Set to default Colors"), 4000 );
Jan Möbius's avatar
Jan Möbius committed
151

Jan Möbius's avatar
Jan Möbius committed
152
153
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
154
  // =============================================================================
155
  OpenMesh::Vec4f ambient_color,
Jan Möbius's avatar
Jan Möbius committed
156
                  diffuse_color,
157
                  specular_color;
Jan Möbius's avatar
Jan Möbius committed
158

159
160
161
  ambient_color  = 0.2f * materialColorDefault_;
  diffuse_color  = 0.6f * materialColorDefault_;
  specular_color = 0.8f * materialColorDefault_;
162
163
164
  ambient_color[3] = 1.0f;
  diffuse_color[3] = 1.0f;
  specular_color[3] = 1.0f;
Jan Möbius's avatar
Jan Möbius committed
165

Jan Möbius's avatar
Jan Möbius committed
166
  // Set background color
167
  PluginFunctions::setBackColor( backgroundColorDefault_ );
Jan Möbius's avatar
 
Jan Möbius committed
168

Jan Möbius's avatar
Jan Möbius committed
169
170
  // =============================================================================
  // Apply to all objects
Jan Möbius's avatar
Jan Möbius committed
171
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
172
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
173
    MaterialNode* mat = o_it->materialNode();
174
    mat->set_base_color( baseColorDefault_ );
Jan Möbius's avatar
 
Jan Möbius committed
175
176
177
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
178
    mat->set_line_width( lineWidthDefault_ );
Jan Möbius's avatar
 
Jan Möbius committed
179
  }
Jan Möbius's avatar
Jan Möbius committed
180

Jan Möbius's avatar
   
Jan Möbius committed
181
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
182
183
}

184
185
186
187
188
189
190

//-----------------------------------------------------------------------------

/** \brief Set the presentation color preset
 *
 */
void ColorPlugin::setPresentationColor() {
Jan Möbius's avatar
Jan Möbius committed
191

Jan Möbius's avatar
Jan Möbius committed
192
193
194
  // =============================================================================
  // Give user feedback
  // =============================================================================
195
  emit scriptInfo( "setPresentationColor()" );
Jan Möbius's avatar
Jan Möbius committed
196
  emit showStatusMessage( tr("Set to Presentation Colors"), 4000 );
Jan Möbius's avatar
Jan Möbius committed
197

Jan Möbius's avatar
Jan Möbius committed
198
199
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
200
  // =============================================================================
201
  OpenMesh::Vec4f ambient_color,
Jan Möbius's avatar
Jan Möbius committed
202
                  diffuse_color,
203
204
205
206
207
                  specular_color;

  ambient_color  = 0.2f * materialColorPresentation_;
  diffuse_color  = 0.6f * materialColorPresentation_;
  specular_color = 0.8f * materialColorPresentation_;
208
209
210
  ambient_color[3] = 1.0f;
  diffuse_color[3] = 1.0f;
  specular_color[3] = 1.0f;
Jan Möbius's avatar
Jan Möbius committed
211

Jan Möbius's avatar
Jan Möbius committed
212
  // Set background color
213
  PluginFunctions::setBackColor( backgroundColorPresentation_ );
Jan Möbius's avatar
 
Jan Möbius committed
214

Jan Möbius's avatar
Jan Möbius committed
215
216
217
  // =============================================================================
  // Apply to all objects
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
218
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
Jan Möbius committed
219
    MaterialNode* mat = o_it->materialNode();
220
    mat->set_base_color( baseColorPresentation_ );
Jan Möbius's avatar
Jan Möbius committed
221
222
223
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
224
    mat->set_line_width( lineWidthPresentation_ );
Jan Möbius's avatar
Jan Möbius committed
225
  }
Jan Möbius's avatar
Jan Möbius committed
226

Jan Möbius's avatar
   
Jan Möbius committed
227
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
228
229
}

230
231
232
233
234
235

//-----------------------------------------------------------------------------

/** \brief set the paperColor Preset
 *
 */
Jan Möbius's avatar
 
Jan Möbius committed
236
void ColorPlugin::setPaperColor() {
Jan Möbius's avatar
Jan Möbius committed
237

Jan Möbius's avatar
Jan Möbius committed
238
239
240
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
241
  emit scriptInfo( "setPaperColor()" );
Jan Möbius's avatar
Jan Möbius committed
242
  emit showStatusMessage( tr("Set to Paper Colors"), 4000 );
Jan Möbius's avatar
Jan Möbius committed
243

Jan Möbius's avatar
Jan Möbius committed
244
245
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
246
  // =============================================================================
247
  OpenMesh::Vec4f ambient_color,
Jan Möbius's avatar
Jan Möbius committed
248
                  diffuse_color,
249
250
251
252
253
                  specular_color;

  ambient_color  = 0.2f * materialColorPaper_;
  diffuse_color  = 0.5f * materialColorPaper_;
  specular_color = 0.8f * materialColorPaper_;
254
255
256
  ambient_color[3] = 1.0f;
  diffuse_color[3] = 1.0f;
  specular_color[3] = 1.0f;
Jan Möbius's avatar
Jan Möbius committed
257

Jan Möbius's avatar
Jan Möbius committed
258
  // Set background color
259
  PluginFunctions::setBackColor( backgroundColorPaper_ );
Jan Möbius's avatar
Jan Möbius committed
260

Jan Möbius's avatar
Jan Möbius committed
261
262
263
  // =============================================================================
  // Apply to all objects
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
264
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
Jan Möbius committed
265
    MaterialNode* mat = o_it->materialNode();
266
    mat->set_base_color( baseColorPaper_ );
Jan Möbius's avatar
Jan Möbius committed
267
268
269
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
270
    mat->set_line_width( lineWidthPaper_ );
Jan Möbius's avatar
Jan Möbius committed
271
  }
Jan Möbius's avatar
Jan Möbius committed
272

Jan Möbius's avatar
   
Jan Möbius committed
273
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
274
275
}

276

Jan Möbius's avatar
 
Jan Möbius committed
277
278
//-----------------------------------------------------------------------------

279
280
281
282
/** \brief Set the backgroundColor
 *
 * @param _color a color
 */
Jan Möbius's avatar
 
Jan Möbius committed
283
void ColorPlugin::setBackgroundColor( Vector _color ) {
Jan Möbius's avatar
Jan Möbius committed
284
  emit scriptInfo( "setBackgroundColor()" );
Jan Möbius's avatar
Jan Möbius committed
285
  emit showStatusMessage( tr("Set background color"), 4000 );
Jan Möbius's avatar
Jan Möbius committed
286

Jan Möbius's avatar
 
Jan Möbius committed
287
288
289
290
291
  ACG::Vec4f color;
  color[0] = _color[0];
  color[1] = _color[1];
  color[2] = _color[2];
  color[3] = 1.0;
Jan Möbius's avatar
Jan Möbius committed
292

Jan Möbius's avatar
 
Jan Möbius committed
293
294
295
  PluginFunctions::setBackColor(color);
}

296
297
//-----------------------------------------------------------------------------

298
299
300
301
302
/** Sets the emissive color of an object
 *
 * @param _objectId  Id of an Object
 * @param _color     Color to be set
 */
303
304
305
306
307
308
309
310
311
312
313
void ColorPlugin::setObjectEmissiveColor(int _objectId , Vector4 _color) {

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    return;
  }

  OpenMesh::Vec4f tmp = OpenMesh::Vec4f(_color);
  object->materialNode()->set_base_color(tmp);

}
Jan Möbius's avatar
 
Jan Möbius committed
314

315
316
//-----------------------------------------------------------------------------

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/** Sets the ambient color of an object
 *
 * @param _objectId  Id of an Object
 * @param _color     Color to be set
 */
void ColorPlugin::setObjectAmbientColor(int _objectId , Vector4 _color) {
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    return;
  }

  OpenMesh::Vec4f tmp = OpenMesh::Vec4f(_color);
  object->materialNode()->set_ambient_color(tmp);
}

//-----------------------------------------------------------------------------

/** Sets the diffuse color of an object
 *
 * @param _objectId  Id of an Object
 * @param _color     Color to be set
 */
void ColorPlugin::setObjectDiffuseColor(int _objectId , Vector4 _color) {
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    return;
  }

  OpenMesh::Vec4f tmp = OpenMesh::Vec4f(_color);
  object->materialNode()->set_diffuse_color(tmp);
}

//-----------------------------------------------------------------------------

/** Sets the specular color of an object
 *
 * @param _objectId  Id of an Object
 * @param _color     Color to be set
 */
void ColorPlugin::setObjectSpecularColor(int _objectId , Vector4 _color) {
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    return;
  }

  OpenMesh::Vec4f tmp = OpenMesh::Vec4f(_color);
  object->materialNode()->set_specular_color(tmp);
}

//-----------------------------------------------------------------------------

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/** \brief Generate an icon with given color
 *
 * @param _color a color vector
 * @return an icon
 */
QIcon ColorPlugin::generateIcon(OpenMesh::Vec4f _color){

  QColor color;
  color.setRgbF(_color[0], _color[1], _color[2], _color[3] );

  QPixmap pic(32,32);
  pic.fill( color );

  return QIcon( pic );
}


//-----------------------------------------------------------------------------

/** \brief Generate an icon with given color
 *
 * @param _color a color
 * @return the icon
 */
QIcon ColorPlugin::generateIcon(QRgb _color){

  QColor color(_color);

  QPixmap pic(32,32);
  pic.fill( color );

  return QIcon( pic );
}


//-----------------------------------------------------------------------------

/** \brief Get the color of an icon
 *
 * @param _icon an icon
 * @return its color
 */
QRgb ColorPlugin::getIconColor(QIcon _icon){

  QRgb rgb = _icon.pixmap(32,32).toImage().pixel(0,0);

  return rgb;
}


//-----------------------------------------------------------------------------

/** \brief convert an icons color to a Vec4f
 *
 * @param _icon an icon
 * @param _color reference to a color vector
 */
void ColorPlugin::setNewColor(QIcon _icon, OpenMesh::Vec4f& _color){

  QColor color( getIconColor(_icon) );

  _color[0] = color.redF();
  _color[1] = color.greenF();
  _color[2] = color.blueF();
  _color[3] = color.alphaF();
}

//-----------------------------------------------------------------------------

/** \brief show a colorDialog and store the chosen value in the icon of the sender()
 *
 */
void ColorPlugin::getColorDialog(){

  QPushButton* button = dynamic_cast< QPushButton* > ( sender() );

  if (button != 0){

    bool ok;

    QRgb newColor = QColorDialog::getRgba ( getIconColor( button->icon() ) , &ok );

    if (ok)
      button->setIcon( generateIcon(newColor) );

  }
}


//-----------------------------------------------------------------------------

/** \brief generate an optionsWidget to change color presets
 *
 * @param _widget reference to the generated widget
 * @return return true if the widget was successfully generated
 */
bool ColorPlugin::initializeOptionsWidget(QWidget*& _widget){

  if (optionsWidget_ == 0){

    optionsWidget_ = new ColorOptions();

    //connect the signals
    connect(optionsWidget_->backgroundDefault,      SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->backgroundPaper,        SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->backgroundPresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );

    connect(optionsWidget_->baseDefault,      SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->basePaper,        SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->basePresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );

    connect(optionsWidget_->materialDefault,      SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->materialPaper,        SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
    connect(optionsWidget_->materialPresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
  }

  //put values into the optionsWidget
  optionsWidget_->backgroundDefault->setIcon( generateIcon( backgroundColorDefault_ ) );
  optionsWidget_->backgroundPaper->setIcon( generateIcon( backgroundColorPaper_ ) );
  optionsWidget_->backgroundPresentation->setIcon( generateIcon( backgroundColorPresentation_ ) );

  optionsWidget_->baseDefault->setIcon( generateIcon( baseColorDefault_ ) );
  optionsWidget_->basePaper->setIcon( generateIcon( baseColorPaper_ ) );
  optionsWidget_->basePresentation->setIcon( generateIcon( baseColorPresentation_ ) );

  optionsWidget_->materialDefault->setIcon( generateIcon( materialColorDefault_ ) );
  optionsWidget_->materialPaper->setIcon( generateIcon( materialColorPaper_ ) );
  optionsWidget_->materialPresentation->setIcon( generateIcon( materialColorPresentation_ ) );

  optionsWidget_->lineDefault->setValue( lineWidthDefault_ );
  optionsWidget_->linePaper->setValue( lineWidthPaper_ );
  optionsWidget_->linePresentation->setValue( lineWidthPresentation_ );

  _widget = optionsWidget_;

  return true;
}


//-----------------------------------------------------------------------------

/** \brief Store the changed color presets when the apply Button was hit
 *
 */
void ColorPlugin::applyOptions(){

  setNewColor(optionsWidget_->backgroundDefault->icon(),      backgroundColorDefault_);
  setNewColor(optionsWidget_->backgroundPaper->icon(),        backgroundColorPaper_);
  setNewColor(optionsWidget_->backgroundPresentation->icon(), backgroundColorPresentation_);

  setNewColor(optionsWidget_->baseDefault->icon(),      baseColorDefault_);
  setNewColor(optionsWidget_->basePaper->icon(),        baseColorPaper_);
  setNewColor(optionsWidget_->basePresentation->icon(), baseColorPresentation_);

  setNewColor(optionsWidget_->materialDefault->icon(),      materialColorDefault_);
  setNewColor(optionsWidget_->materialPaper->icon(),        materialColorPaper_);
  setNewColor(optionsWidget_->materialPresentation->icon(), materialColorPresentation_);

  lineWidthDefault_      = optionsWidget_->lineDefault->value();
  lineWidthPaper_        = optionsWidget_->linePaper->value();
  lineWidthPresentation_ = optionsWidget_->linePresentation->value();
}


//-----------------------------------------------------------------------------

/** \brief convert between uint and Vec4f
 *
 * @param _color given color
 * @param _vector color vector to convert to
 */
void ColorPlugin::convertColor(uint _color, OpenMesh::Vec4f& _vector){

  QColor color;
  color.setRgba( _color );

  _vector[0] = color.redF();
  _vector[1] = color.greenF();
  _vector[2] = color.blueF();
  _vector[3] = color.alphaF();
}


//-----------------------------------------------------------------------------

/** \brief convert between uint and Vec4f
 *
 * @param _vector reference to a color vector
 * @return same color as uint
 */
uint ColorPlugin::convertColor(OpenMesh::Vec4f& _vector){

  QColor color;
  color.setRgbF(_vector[0], _vector[1], _vector[2], _vector[3] );

  return (uint) color.rgba();
}


//-----------------------------------------------------------------------------

/** \brief read color preset from ini file
 *
 * @param _ini file to read from
 */
void ColorPlugin::loadIniFileOptions(INIFile& _ini){

  if ( _ini.section_exists("ColorPlugin") ){

    uint color = 0;

    if ( _ini.get_entry( color, "ColorPlugin" , "backgroundColorDefault") )
      convertColor( color, backgroundColorDefault_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "backgroundColorPaper") )
      convertColor( color, backgroundColorPaper_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "backgroundColorPresentation") )
      convertColor( color, backgroundColorPresentation_ );

    if ( _ini.get_entry( color, "ColorPlugin" , "baseColorDefault") )
      convertColor( color, baseColorDefault_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "baseColorPaper") )
      convertColor( color, baseColorPaper_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "baseColorPresentation") )
      convertColor( color, baseColorPresentation_ );

    if ( _ini.get_entry( color, "ColorPlugin" , "materialColorDefault") )
      convertColor( color, materialColorDefault_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "materialColorPaper") )
      convertColor( color, materialColorPaper_ );
    if ( _ini.get_entry( color, "ColorPlugin" , "materialColorPresentation") )
      convertColor( color, materialColorPresentation_ );

    double width;

    if ( _ini.get_entry( width, "ColorPlugin" , "lineWidthDefault") )
      lineWidthDefault_ = width;
    if ( _ini.get_entry( width, "ColorPlugin" , "lineWidthPaper") )
      lineWidthPaper_ = width;
    if ( _ini.get_entry( width, "ColorPlugin" , "lineWidthPresentation") )
      lineWidthPresentation_ = width;

  }
}


//-----------------------------------------------------------------------------

/** \brief Store current color preset to an ini file
 *
 * @param _ini file to store color presets in
 */
void ColorPlugin::saveIniFileOptions(INIFile& _ini){
std::cerr << "save to ini file\n";
621

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

  _ini.add_entry("ColorPlugin","backgroundColorDefault",      convertColor( backgroundColorDefault_ )  );
  _ini.add_entry("ColorPlugin","backgroundColorPaper",        convertColor( backgroundColorPaper_ )  );
  _ini.add_entry("ColorPlugin","backgroundColorPresentation", convertColor( backgroundColorPresentation_ )  );

  _ini.add_entry("ColorPlugin","baseColorDefault",      convertColor( baseColorDefault_ )  );
  _ini.add_entry("ColorPlugin","baseColorPaper",        convertColor( baseColorPaper_ )  );
  _ini.add_entry("ColorPlugin","baseColorPresentation", convertColor( baseColorPresentation_ )  );

  _ini.add_entry("ColorPlugin","materialColorDefault",      convertColor( materialColorDefault_ )  );
  _ini.add_entry("ColorPlugin","materialColorPaper",        convertColor( materialColorPaper_ )  );
  _ini.add_entry("ColorPlugin","materialColorPresentation", convertColor( materialColorPresentation_ )  );

  _ini.add_entry("ColorPlugin","lineWidthDefault",      lineWidthDefault_ );
  _ini.add_entry("ColorPlugin","lineWidthPaper",        lineWidthPaper_   );
  _ini.add_entry("ColorPlugin","lineWidthPresentation", lineWidthPresentation_ );
}

Matthias Möller's avatar
Matthias Möller committed
640
#if QT_VERSION < 0x050000
Jan Möbius's avatar
 
Jan Möbius committed
641
Q_EXPORT_PLUGIN2( colorplugin , ColorPlugin );
Matthias Möller's avatar
Matthias Möller committed
642
643
#endif

Jan Möbius's avatar
 
Jan Möbius committed
644