qcanvas passage
This commit is contained in:
@@ -17,6 +17,12 @@
|
|||||||
#include <Gtypes.h>
|
#include <Gtypes.h>
|
||||||
#include <TVirtualX.h>
|
#include <TVirtualX.h>
|
||||||
#include <TEnv.h>
|
#include <TEnv.h>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
#include <TClass.h>
|
||||||
|
#include <TMethod.h>
|
||||||
|
#include <TList.h>
|
||||||
|
#include <TInterpreter.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Root {
|
namespace Root {
|
||||||
@@ -116,9 +122,14 @@ void QCanvas::mousePressEvent(QMouseEvent* event) {
|
|||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
m_canvas->HandleInput(kButton1Down, pos.x(), pos.y());
|
m_canvas->HandleInput(kButton1Down, pos.x(), pos.y());
|
||||||
break;
|
break;
|
||||||
case Qt::RightButton:
|
case Qt::RightButton: {
|
||||||
m_canvas->HandleInput(kButton3Down, pos.x(), pos.y());
|
m_canvas->HandleInput(kButton3Down, pos.x(), pos.y());
|
||||||
|
TObject *obj = m_canvas->GetSelected();
|
||||||
|
if (obj) {
|
||||||
|
ShowContextMenu(obj, event->globalPosition().toPoint());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Qt::MiddleButton:
|
case Qt::MiddleButton:
|
||||||
m_canvas->HandleInput(kButton2Down, pos.x(), pos.y());
|
m_canvas->HandleInput(kButton2Down, pos.x(), pos.y());
|
||||||
break;
|
break;
|
||||||
@@ -128,6 +139,51 @@ void QCanvas::mousePressEvent(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QCanvas::ShowContextMenu(TObject* obj, const QPoint& globalPos) {
|
||||||
|
if (!obj) return;
|
||||||
|
|
||||||
|
QMenu menu(this);
|
||||||
|
menu.setTitle(obj->GetName());
|
||||||
|
|
||||||
|
TClass* cl = obj->IsA();
|
||||||
|
if (!cl) return;
|
||||||
|
|
||||||
|
TList* methods = cl->GetListOfMethods();
|
||||||
|
if (!methods) return;
|
||||||
|
|
||||||
|
TIter next(methods);
|
||||||
|
TObject* m_obj;
|
||||||
|
while ((m_obj = next())) {
|
||||||
|
TMethod* method = (TMethod*)m_obj;
|
||||||
|
if (method->IsMenuItem()) {
|
||||||
|
QString label = QString::fromStdString(method->GetName());
|
||||||
|
if (strlen(method->GetTitle()) > 0) {
|
||||||
|
label += " (" + QString::fromStdString(method->GetTitle()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* action = menu.addAction(label);
|
||||||
|
connect(action, &QAction::triggered, [this, obj, method]() {
|
||||||
|
// For now, only support methods without arguments for simplicity
|
||||||
|
// or methods that can be called via TInterpreter
|
||||||
|
if (method->GetNargs() == 0) {
|
||||||
|
obj->Execute((char*)method->GetName(), (char*)"");
|
||||||
|
if (m_canvas) {
|
||||||
|
m_canvas->Modified();
|
||||||
|
m_canvas->Update();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: Handle methods with arguments if needed
|
||||||
|
std::cout << "DEBUG: Method " << method->GetName() << " requires arguments." << std::endl;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!menu.actions().isEmpty()) {
|
||||||
|
menu.exec(globalPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QCanvas::mouseReleaseEvent(QMouseEvent* event) {
|
void QCanvas::mouseReleaseEvent(QMouseEvent* event) {
|
||||||
if (m_canvas) {
|
if (m_canvas) {
|
||||||
auto pos = event->position();
|
auto pos = event->position();
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
#ifdef HAVE_QT
|
#ifdef HAVE_QT
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class TCanvas;
|
|
||||||
class QPaintEvent;
|
|
||||||
class QResizeEvent;
|
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
class QPoint;
|
||||||
|
|
||||||
|
class TObject;
|
||||||
|
class TCanvas;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Root {
|
namespace Root {
|
||||||
@@ -21,6 +22,7 @@ public:
|
|||||||
void SetCanvas(TCanvas* c);
|
void SetCanvas(TCanvas* c);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void ShowContextMenu(TObject* obj, const QPoint& globalPos);
|
||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) override;
|
||||||
void resizeEvent(QResizeEvent* event) override;
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
|||||||
33
src/Root/testing/root_api_test.cpp
Normal file
33
src/Root/testing/root_api_test.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <TClass.h>
|
||||||
|
#include <TMethod.h>
|
||||||
|
#include <TList.h>
|
||||||
|
#include <TH1F.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <TMethodCall.h>
|
||||||
|
#include <TSystem.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
TH1F *h = new TH1F("h", "h", 10, 0, 10);
|
||||||
|
TClass *cl = h->IsA();
|
||||||
|
if (!cl) {
|
||||||
|
std::cout << "No class found" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
TList *methods = cl->GetListOfMethods();
|
||||||
|
if (!methods) {
|
||||||
|
std::cout << "No methods found" << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
TIter next(methods);
|
||||||
|
TObject *obj;
|
||||||
|
int count = 0;
|
||||||
|
while ((obj = next())) {
|
||||||
|
TMethod *method = dynamic_cast<TMethod*>(obj);
|
||||||
|
if (method && method->IsMenuItem()) {
|
||||||
|
std::cout << "Menu item: " << method->GetName() << " (" << method->GetTitle() << ")" << std::endl;
|
||||||
|
count++;
|
||||||
|
if (count > 5) break; // Just show a few
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user