GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
color-picker.cc
Go to the documentation of this file.
1 //
2 // This class provides a simple color picker based on tQColorButton
3 // by Harald Jedele, 23.03.01, GPL version 2 or any later version.
4 //
5 // Copyright (C) FZI Forschungszentrum Informatik Karlsruhe
6 // Copyright (C) 2013-2015 Torsten
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software; you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3 of the License, or (at your
13 // option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but WITHOUT
16 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 // for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <http://www.gnu.org/licenses/>.
23 //
24 
25 // Author: Torsten <[email protected]>
26 
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 
31 #include "color-picker.h"
32 
33 // constuctor with initial color as parameter
34 color_picker::color_picker (QColor old_color, QWidget* p) : QPushButton (p)
35 {
36  _color = old_color;
37  setFlat (true);
38  setFocusPolicy (Qt::NoFocus); // no focus, would changes the color
39  update_button ();
40  connect (this, SIGNAL (clicked ()), SLOT (select_color ()));
41 }
42 
43 // slot for bitton clicked: selct a new color using QColorDialog
44 void
46 {
47  QColor new_color = QColorDialog::getColor (_color);
48  if (new_color.isValid () && new_color != _color)
49  {
50  _color = new_color;
51  update_button ();
52  }
53 }
54 
55 // draw the button with the actual color (using a stylesheet)
57 {
58  // Is this the right place to look for a "foreground" color that would
59  // provide a reasonable border for the color swatches?
60  QWidget *p = parentWidget ();
61 
62  QString bordercolor
63  = p ? p->palette ().text ().color ().name () : QString ("#000000");
64 
65  QString css = QString ("background-color: %1; border: 1px solid %2;")
66  .arg (_color.name ())
67  .arg (bordercolor);
68 
69  setStyleSheet (css);
70  repaint ();
71 }
double arg(double x)
Definition: lo-mappers.h:37
void select_color()
Definition: color-picker.cc:45
virtual void update_button()
Definition: color-picker.cc:56
QColor _color
Definition: color-picker.h:46
color_picker(QColor color=QColor(0, 0, 0), QWidget *parent=0)
Definition: color-picker.cc:34