Mercurial > octave
annotate libgui/src/color-picker.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
1 /* |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
2 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
3 This class provides a simple color picker based on tQColorButton |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
4 by Harald Jedele, 23.03.01, GPL version 2 or any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
5 |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
6 Copyright (C) 2013-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27893
diff
changeset
|
7 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27893
diff
changeset
|
8 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27893
diff
changeset
|
9 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27893
diff
changeset
|
10 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27893
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
12 This file is part of Octave. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
13 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24514
diff
changeset
|
14 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
15 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24514
diff
changeset
|
16 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
17 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
18 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
19 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
20 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
22 GNU General Public License for more details. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
23 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
24 You should have received a copy of the GNU General Public License |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
25 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24514
diff
changeset
|
26 <https://www.gnu.org/licenses/>. |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
27 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
28 */ |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
29 |
16768 | 30 // Author: Torsten <ttl@justmail.de> |
31 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
32 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21203
diff
changeset
|
33 # include "config.h" |
17921
2a4acd6548c6
include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
34 #endif |
2a4acd6548c6
include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
35 |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
36 #include "color-picker.h" |
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
37 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
38 namespace octave |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
39 { |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
40 // Constructor with initial color as parameter |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
41 color_picker::color_picker (QColor old_color, QWidget *p) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
42 : QPushButton (p) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
43 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
44 m_color = old_color; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
45 setFlat (true); |
27893
465ac679e976
Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
46 setFocusPolicy (Qt::NoFocus); // no focus, would change the color |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
47 update_button (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
48 connect (this, SIGNAL (clicked (void)), SLOT (select_color (void))); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
49 } |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
50 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
51 // Slot for button clicked: select a new color using QColorDialog |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
52 void color_picker::select_color (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
53 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
54 QColor new_color = QColorDialog::getColor (m_color); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
55 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
56 if (new_color.isValid () && new_color != m_color) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
57 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
58 m_color = new_color; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
59 update_button (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
60 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
61 } |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
62 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
63 // Draw the button with the actual color (using a stylesheet) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
64 void color_picker::update_button (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
65 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
66 // Is this the right place to look for a "foreground" color that would |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
67 // provide a reasonable border for the color swatches? |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
68 QWidget *p = parentWidget (); |
16621
2df11dd7a589
draw border around color picker swatches
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
69 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
70 QString bordercolor |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
71 = (p ? p->palette ().text ().color ().name () : QString ("#000000")); |
16621
2df11dd7a589
draw border around color picker swatches
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
72 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
73 setStyleSheet (QString ("background-color: %1; border: 1px solid %2;") |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
74 .arg (m_color.name ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
75 .arg (bordercolor)); |
16621
2df11dd7a589
draw border around color picker swatches
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
76 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
77 repaint (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
78 } |
16402
7fa90eb41240
gui: individually configurable styles of the editor lexers
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
79 } |