Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGtk4GedEditor.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 30/10/2026
2
3/*************************************************************************
4 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TGtk4GedEditor.h"
12
13#include "Gtk4MethodDialog.h"
14#include "TGtk4Canvas.h"
15
16#include "TCanvas.h"
17#include "TROOT.h"
18#include "TColor.h"
19
20#include "TClass.h"
21#include "TBaseClass.h"
22#include "TMethod.h"
23#include "TMethodCall.h"
24
25#include "TAttMarker.h"
26#include "TAttLine.h"
27#include "TAttFill.h"
28#include "TAttText.h"
29
30
31
32#include <memory>
33
34using namespace ROOT::Experimental;
35
36/** \class TGtk4GedEditor
37 \ingroup gtk4canvas
38 \brief TVirtualPadEditor ABI implementation for GTK4
39*/
40
41TGtk4GedEditor::TGtk4GedEditor(TCanvas *c)
42{
43 SetCanvas(c);
44}
45
49
50
52{
53 if (fCanvas == newcan) return;
54
56 fCanvas = newcan;
57
58 if (!newcan) return;
59
60 // SetWindowName(Form("%s_Editor", fCanvas->GetName()));
62 if (!fPad) fPad = fCanvas;
64}
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// Connect this editor to the Selected signal of canvas 'c'.
69
71{
72 c->Connect("Selected(TVirtualPad*,TObject*,Int_t)", "ROOT::Experimental::TGtk4GedEditor", this,
73 "SetModel(TVirtualPad*,TObject*,Int_t)");
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Disconnect this editor from the Selected signal of fCanvas.
78
80{
81 if (fCanvas)
82 Disconnect(fCanvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Activate object editors according to the selected object.
87
89{
90 if (event != kButton1Down)
91 return;
92
93 auto prev = fModel;
94
95 fPad = pad;
96 fModel = obj ? obj : pad;
97
98 if (fModel != prev)
100}
101
103{
104 if (gPad)
105 SetCanvas(gPad->GetCanvas());
106
107 if (fCanvas && fGlobal)
109
110 if (!gROOT->GetListOfCleanups()->FindObject(this))
111 gROOT->GetListOfCleanups()->Add(this);
112
113 fDialog = new Gtk4MethodDialog(300, 300);
114
115 /* reposition dialog
116 auto imp = dynamic_cast<TGtk4Canvas *>(fCanvas->GetCanvasImp());
117 if (imp) {
118 auto widget = imp->GetCanvasWidget();
119 fDialog->resize(200, widget->height());
120 QPoint pos = widget->mapToGlobal(QPoint(0, 0));
121 fDialog->move(pos.x() - fDialog->width(), pos.y());
122 }
123 */
124
125 if (fModel)
127}
128
129
131{
132 auto pad = fPad;
133 if (!pad)
134 pad = fCanvas;
135 if (pad)
136 pad->ModifiedUpdate();
137}
138
140{
141 m_line_color = fDialog->addColorInput("Line col", attline->GetLineColor());
142
143 auto style_list = Gtk::StringList::create({"None", "Style 1", "Style 2", "Style 3", "Style 4", "Style 5", "Style 6", "Style 7", "Style 8", "Style 9"});
144 m_line_style = Gtk::make_managed<Gtk::DropDown>(style_list);
145 m_line_style->set_selected(attline->GetLineStyle());
146
147 fDialog->addLine("Line style", m_line_style);
148
149 auto adjustment = Gtk::Adjustment::create(/* value */ attline->GetLineWidth(), /* lower */ 1, /* upper */ 20,
150 /* step_increment */ 1, /* page_increment */ 5.0);
151
152 m_line_width = Gtk::make_managed<Gtk::SpinButton>(adjustment);
153 m_line_width->set_digits(0); // 0 decimal places -> integer display
154
155 fDialog->addLine("Line width", m_line_width);
156
157 fAttLine = attline;
158}
159
161{
162 m_fill_color = fDialog->addColorInput("Fill col", attfill->GetFillColor());
163
164 fAttFill = attfill;
165}
166
168{
169 m_text_color = fDialog->addColorInput("Text col", atttext->GetTextColor());
170
171 fAttText = atttext;
172}
173
175{
176 m_marker_color = fDialog->addColorInput("Marker col", attmark->GetMarkerColor());
177
178 fAttMarker = attmark;
179}
180
182{
183 TString method_name = TString::Format("Add%s", cl->GetName());
184
185 auto mtd = IsA()->GetMethodAny(method_name.Data());
186
187 if (mtd) {
188 void *obj = fModel->IsA()->DynamicCast(cl, fModel);
189 auto sarg = TString::Format("(%s*)0x%zx", cl->GetName(), (size_t)obj);
190 TMethodCall call(IsA(), method_name, sarg.Data());
191 call.Execute(this);
192 }
193
194 auto lst = cl->GetListOfBases();
195
196 TIter iter(lst);
197 while (auto base = (TBaseClass*) iter())
198 FillGed(base->GetClassPointer());
199}
200
202{
203 if (!fModel || !fDialog)
204 return;
205
206 // first delete all previous elements !!!!
208
209 fAttLine = nullptr;
210 fAttFill = nullptr;
211 fAttText = nullptr;
212 fAttMarker = nullptr;
214 m_line_style = nullptr;
215 m_line_width = nullptr;
216
217 FillGed(fModel->IsA());
218
219 auto okBtn = fDialog->addOkCancelButtons();
220
221 okBtn->signal_clicked().connect(sigc::mem_fun(*this, &TGtk4GedEditor::on_ok_button_clicked));
222
223 fDialog->present();
224}
225
226Int_t TGtk4GedEditor::GetRootColor(Gtk::ColorDialogButton* btn)
227{
228 auto selected_color = btn->get_rgba();
229 return TColor::GetColor(selected_color.get_red(),
230 selected_color.get_green(),
231 selected_color.get_blue(),
232 selected_color.get_alpha());
233}
234
235
237{
238 if (fAttLine) {
240 fAttLine->SetLineStyle(m_line_style->get_selected());
241 fAttLine->SetLineWidth(m_line_width->get_value());
242 }
243
244 if (fAttFill) {
246 }
247
248 if (fAttText) {
250 }
251 if (fAttMarker) {
253 }
254
255 fDialog->close();
256 fDialog = nullptr;
257
258 if (gPad)
259 gPad->ModifiedUpdate();
260
261}
262
263
265{
266 gROOT->GetListOfCleanups()->Remove(this);
267 if (fDialog) {
268 fDialog->close();
269 fDialog = nullptr;
270 }
271}
272
274{
275 if (obj == fModel) {
277 } else if (obj == fPad) {
279 } else if (obj == fCanvas)
280 Hide();
281}
@ kButton1Down
Definition Buttons.h:17
#define c(i)
Definition RSha256.hxx:101
cudaEvent_t event
#define gROOT
Definition TROOT.h:417
#define gPad
Specialized dialog to enter arguments for method exection.
void clearAllElements()
clear all elements inside dialog main box
Gtk::ColorDialogButton * addColorInput(const char *title, int colindx)
add line with color button
void addLine(const char *txt, Gtk::Widget *widget)
Add single dialog line.
Gtk::Button * addOkCancelButtons()
Add Ok and Cancel buttons.
Gtk::ColorDialogButton * m_marker_color
Gtk::ColorDialogButton * m_fill_color
void DisconnectFromCanvas()
Disconnect this editor from the Selected signal of fCanvas.
void ConnectToCanvas(TCanvas *c)
Connect this editor to the Selected signal of canvas 'c'.
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event)
Activate object editors according to the selected object.
void RecursiveRemove(TObject *obj) override
Recursively remove this object from a list.
TClass * IsA() const override
Int_t GetRootColor(Gtk::ColorDialogButton *btn)
Gtk::ColorDialogButton * m_text_color
Gtk::ColorDialogButton * m_line_color
Fill Area Attributes class.
Definition TAttFill.h:21
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
Line Attributes class.
Definition TAttLine.h:21
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
Marker Attributes class.
Definition TAttMarker.h:22
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:34
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Text Attributes class.
Definition TAttText.h:21
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
The Canvas class.
Definition TCanvas.h:23
TObject * GetClickSelected() const
Definition TCanvas.h:147
TVirtualPad * GetClickSelectedPad() const
Definition TCanvas.h:152
TVirtualPad * GetSelectedPad() const override
Definition TCanvas.h:151
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
Definition TClass.cxx:5036
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3699
TMethod * GetMethodAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4495
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1939
Method or function calling interface.
Definition TMethodCall.h:37
void Execute(const char *, const char *, int *=nullptr) override
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:42
virtual TClass * IsA() const
Definition TObject.h:248
void ModifiedUpdate() override
Short cut to call Modified() and Update() in a single call.
Definition TPad.cxx:3391
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:53
Namespace for ROOT features in testing.
Definition TROOT.h:100