GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
color-picker.cc
Go to the documentation of this file.
1 /*
2 
3 This class provides a simple color picker based on tQColorButton
4 by Harald Jedele, 23.03.01, GPL version 2 or any later version.
5 
6 Copyright (C) FZI Forschungszentrum Informatik Karlsruhe
7 Copyright (C) 2013-2018 Torsten
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
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 Octave is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License 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 <https://www.gnu.org/licenses/>.
23 
24 */
25 
26 // Author: Torsten <ttl@justmail.de>
27 
28 #if defined (HAVE_CONFIG_H)
29 # include "config.h"
30 #endif
31 
32 #include "color-picker.h"
33 
34 namespace octave
35 {
36  // Constructor with initial color as parameter
37  color_picker::color_picker (QColor old_color, QWidget *p)
38  : QPushButton (p)
39  {
40  m_color = old_color;
41  setFlat (true);
42  setFocusPolicy (Qt::NoFocus); // no focus, would changes the color
43  update_button ();
44  connect (this, SIGNAL (clicked (void)), SLOT (select_color (void)));
45  }
46 
47  // Slot for button clicked: select a new color using QColorDialog
49  {
50  QColor new_color = QColorDialog::getColor (m_color);
51 
52  if (new_color.isValid () && new_color != m_color)
53  {
54  m_color = new_color;
55  update_button ();
56  }
57  }
58 
59  // Draw the button with the actual color (using a stylesheet)
61  {
62  // Is this the right place to look for a "foreground" color that would
63  // provide a reasonable border for the color swatches?
64  QWidget *p = parentWidget ();
65 
66  QString bordercolor
67  = (p ? p->palette ().text ().color ().name () : QString ("#000000"));
68 
69  setStyleSheet (QString ("background-color: %1; border: 1px solid %2;")
70  .arg (m_color.name ())
71  .arg (bordercolor));
72 
73  repaint ();
74  }
75 }
virtual void update_button(void)
Definition: color-picker.cc:60
octave_value arg
Definition: pr-output.cc:3244
p
Definition: lu.cc:138
void select_color(void)
Definition: color-picker.cc:48
color_picker(QColor color=QColor(0, 0, 0), QWidget *parent=nullptr)
Definition: color-picker.cc:37