ui/qt/toolbar.cpp

changeset 575
50da9696a865
parent 574
19de5292f08f
child 576
dd38b170f9a8
--- a/ui/qt/toolbar.cpp	Fri Apr 18 14:56:12 2025 +0200
+++ b/ui/qt/toolbar.cpp	Fri Apr 18 17:22:28 2025 +0200
@@ -86,12 +86,45 @@
 
 void ui_toolbar_add_item(UiObject *obj, QToolBar *toolbar, UiToolbarItem *item) {
     QAction *action = new QAction();
-    action->setText(item->args.label);
+    if(item->args.label) {
+        action->setText(item->args.label);
+    }
+    if(item->args.icon) {
+        action->setIcon(QIcon::fromTheme(item->args.icon));
+    }
     toolbar->addAction(action);
+    
+    UiEventWrapper *event = new UiEventWrapper(obj, item->args.onclick, item->args.onclickdata);
+    action->connect(action, SIGNAL(clicked()), event, SLOT(slot()));
+    action->connect(action, SIGNAL(destroyed()), event, SLOT(destroy()));
+}
+
+static void toolbar_togglebutton_event(UiEvent *event, UiEventWrapper *wrapper) {
+    QAction *action = (QAction*)wrapper->customdata1;
+    event->intval = action->isChecked();
+    if(wrapper->var) {
+        event->eventdata = wrapper->var->value;
+    }
 }
 
 void ui_toolbar_add_toggleitem(UiObject *obj, QToolBar *toolbar, UiToolbarToggleItem *item) {
+    QAction *action = new QAction();
+    action->setCheckable(true);
+    if(item->args.label) {
+        action->setText(item->args.label);
+    }
+    if(item->args.icon) {
+        action->setIcon(QIcon::fromTheme(item->args.icon));
+    }
+    toolbar->addAction(action);
     
+    UiVar* var = uic_widget_var(obj->ctx, obj->ctx, nullptr, item->args.varname, UI_VAR_INTEGER);
+    UiEventWrapper *event = new UiEventWrapper(obj, item->args.onchange, item->args.onchangedata);
+    event->var = var;
+    event->customdata1 = action;
+    event->prepare_event = toolbar_togglebutton_event;
+    action->connect(action, SIGNAL(clicked()), event, SLOT(slot()));
+    action->connect(action, SIGNAL(destroyed()), event, SLOT(destroy()));
 }
 
 void ui_toolbar_add_menu(UiObject *obj, QToolBar *toolbar, UiToolbarMenuItem *item) {

mercurial