annotate libgui/graphics/ToggleButtonControl.cc @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 1a12d4369beb
children 028205a91a07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26225
diff changeset
3 Copyright (C) 2011-2019 Michael Goffioul
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
5 This file is part of Octave.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
8 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: 23795
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
10 (at your option) any later version.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
15 GNU General Public License for more details.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
18 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: 23795
diff changeset
19 <https://www.gnu.org/licenses/>.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
24 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <QPushButton>
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "ToggleButtonControl.h"
21824
6780a8657be3 Implement uibuttongroup (bug #47513)
Andrew Thornton <art27@cantab.net>
parents: 21724
diff changeset
30 #include "ButtonGroup.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "Container.h"
18505
fb96b7f55242 rename file to avoid clash on case-insenstive filesystems (bug #41658)
John W. Eaton <jwe@octave.org>
parents: 18501
diff changeset
32 #include "QtHandlesUtils.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 namespace QtHandles
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
37 ToggleButtonControl*
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
38 ToggleButtonControl::create (const graphics_object& go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
39 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
40 Object *parent = Object::parentObject (go);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
42 if (parent)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
43 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
44 Container *container = parent->innerContainer ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
46 if (container)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
47 return new ToggleButtonControl (go, new QPushButton (container));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
48 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23449
diff changeset
50 return nullptr;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
51 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 ToggleButtonControl::ToggleButtonControl (const graphics_object& go,
25788
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
54 QPushButton *btn)
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 : ButtonControl (go, btn)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
56 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
57 Object *parent = Object::parentObject (go);
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
58 ButtonGroup *btnGroup = dynamic_cast<ButtonGroup *>(parent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
59 if (btnGroup)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
60 btnGroup->addButton (btn);
21824
6780a8657be3 Implement uibuttongroup (bug #47513)
Andrew Thornton <art27@cantab.net>
parents: 21724
diff changeset
61
25788
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
62 uicontrol::properties& up = properties<uicontrol> ();
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
63
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
64 btn->setCheckable (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
65 btn->setAutoFillBackground (true);
25788
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
66 octave_value cdat = up.get_cdata ();
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
67 QImage img = Utils::makeImageFromCData (cdat,
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
68 cdat.rows (), cdat.columns ());
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
69 btn->setIcon (QIcon (QPixmap::fromImage (img)));
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
70 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
72 ToggleButtonControl::~ToggleButtonControl (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22411
diff changeset
73 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
25788
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
75 void
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
76 ToggleButtonControl::update (int pId)
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
77 {
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
78 uicontrol::properties& up = properties<uicontrol> ();
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
79 QPushButton *btn = qWidget<QPushButton> ();
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
80
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
81 switch (pId)
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
82 {
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
83 case uicontrol::properties::ID_CDATA:
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
84 {
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
85 octave_value cdat = up.get_cdata ();
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
86 QImage img = Utils::makeImageFromCData (cdat,
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
87 cdat.rows (),
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
88 cdat.columns ());
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
89 btn->setIcon (QIcon (QPixmap::fromImage (img)));
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
90 }
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
91 break;
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
92
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
93 default:
26225
1a12d4369beb Fix "Value" property for uicontrol togglebuttons (bug #55211).
Rik <rik@octave.org>
parents: 25788
diff changeset
94 ButtonControl::update (pId);
25788
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
95 break;
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
96 }
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
97 }
88e87c69c8b8 Implement "cdata" property for pushbuttons (bug #44332).
Rik <rik@octave.org>
parents: 25054
diff changeset
98
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 };