From e4c34fcf6ef99a7684c3577da33ea97e0aed8690 Mon Sep 17 00:00:00 2001 From: jackyansongli Date: Mon, 9 Jun 2025 17:50:01 +0800 Subject: [PATCH 1/2] move bar to left --- src/Plugins/Qt/qt_tm_widget.cpp | 130 ++++++++++++++++---------------- src/Plugins/Qt/qt_tm_widget.hpp | 5 +- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/Plugins/Qt/qt_tm_widget.cpp b/src/Plugins/Qt/qt_tm_widget.cpp index e783a55a3d..dcc97216ce 100644 --- a/src/Plugins/Qt/qt_tm_widget.cpp +++ b/src/Plugins/Qt/qt_tm_widget.cpp @@ -1,4 +1,3 @@ - /****************************************************************************** * MODULE : qt_tm_widget.cpp * DESCRIPTION: The main TeXmacs input widget and its embedded counterpart. @@ -13,9 +12,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -114,13 +115,13 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) main_widget= concrete (::glue_widget (true, true, 1, 1)); // decode mask - visibility[0]= (mask & 1) == 1; // header + visibility[0]= false; // header - 隐藏顶部菜单 visibility[1]= (mask & 2) == 2; // main visibility[2]= (mask & 4) == 4; // mode visibility[3]= (mask & 8) == 8; // focus visibility[4]= (mask & 16) == 16; // user visibility[5]= (mask & 32) == 32; // footer - visibility[6]= (mask & 64) == 64; // side tools #0 + visibility[6]= true; // side tools - 强制显示左侧工具 visibility[7]= (mask & 128) == 128; // bottom tools visibility[8]= (mask & 256) == 256; // tab page bar @@ -202,14 +203,10 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) userToolBar = new QToolBar ("user toolbar", mw); bottomTools= new QDockWidget ("bottom tools", mw); - sideTools = new QDockWidget ("side tools", 0); - tabToolBar = new QTMTabPageBar ("tab toolbar", mw); - // HACK: Wrap the dock in a "fake" window widget (last parameter = true) to - // have clicks report the right position. - static int cnt = 0; - string dock_name= "dock:" * as_string (cnt++); - dock_window_widget= - tm_new (sideTools, dock_name, command (), true); + sideTools = new QDockWidget (mw); + sideTools->setTitleBarWidget (new QWidget ()); + + tabToolBar= new QTMTabPageBar ("tab toolbar", mw); if (tm_style_sheet == "") { mainToolBar->setStyle (qtmstyle ()); @@ -340,29 +337,23 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) bar->setContentsMargins (0, 1, 0, 1); } else { - mw->addToolBar (mainToolBar); - mw->addToolBarBreak (); - mw->addToolBar (tabToolBar); - mw->addToolBarBreak (); - mw->addToolBar (modeToolBar); - mw->addToolBarBreak (); - mw->addToolBar (focusToolBar); - mw->addToolBarBreak (); - mw->addToolBar (userToolBar); - mw->addToolBarBreak (); + // Put toolbars back on top but organized better + mw->addToolBar (Qt::TopToolBarArea, mainToolBar); + mw->addToolBar (Qt::TopToolBarArea, tabToolBar); + mw->addToolBarBreak (Qt::TopToolBarArea); + mw->addToolBar (Qt::TopToolBarArea, modeToolBar); + mw->addToolBar (Qt::TopToolBarArea, focusToolBar); + mw->addToolBar (Qt::TopToolBarArea, userToolBar); } #else - mw->addToolBar (mainToolBar); - mw->addToolBarBreak (); - mw->addToolBar (tabToolBar); - mw->addToolBarBreak (); - mw->addToolBar (modeToolBar); - mw->addToolBarBreak (); - mw->addToolBar (focusToolBar); - mw->addToolBarBreak (); - mw->addToolBar (userToolBar); - mw->addToolBarBreak (); + // Put toolbars back on top but organized better + mw->addToolBar (Qt::TopToolBarArea, mainToolBar); + mw->addToolBar (Qt::TopToolBarArea, tabToolBar); + mw->addToolBarBreak (Qt::TopToolBarArea); + mw->addToolBar (Qt::TopToolBarArea, modeToolBar); + mw->addToolBar (Qt::TopToolBarArea, focusToolBar); + mw->addToolBar (Qt::TopToolBarArea, userToolBar); #endif sideTools->setAllowedAreas (Qt::AllDockWidgetAreas); @@ -370,7 +361,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) QDockWidget::DockWidgetFloatable); sideTools->setFloating (false); sideTools->setTitleBarWidget (new QWidget ()); // Disables title bar - mw->addDockWidget (Qt::RightDockWidgetArea, sideTools); + mw->addDockWidget (Qt::LeftDockWidgetArea, sideTools); bottomTools->setAllowedAreas (Qt::BottomDockWidgetArea); bottomTools->setFeatures (QDockWidget::NoDockWidgetFeatures); @@ -386,21 +377,17 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) // someHelper, SLOT(call_scheme_hide_side_tools())); // handles visibility - // at this point all the toolbars are empty so we avoid showing them - // same for the menu bar if we are not on the Mac (where we do not have - // other options) - - mainToolBar->setVisible (false); - modeToolBar->setVisible (false); - focusToolBar->setVisible (false); - userToolBar->setVisible (false); - sideTools->setVisible (false); - bottomTools->setVisible (false); - tabToolBar->setVisible (false); + // Hide all top elements and show only left menu + mainToolBar->setVisible (false); // 隐藏主工具栏 + modeToolBar->setVisible (false); // 隐藏模式工具栏 + focusToolBar->setVisible (false); // 隐藏焦点工具栏 + userToolBar->setVisible (false); // 隐藏用户工具栏 + sideTools->setVisible (true); // 显示左侧菜单 + bottomTools->setVisible (false); // 隐藏底部工具 + tabToolBar->setVisible (false); // 隐藏标签栏 mainwindow ()->statusBar ()->setVisible (true); -#ifndef Q_OS_MAC + // 强制隐藏顶部菜单栏 mainwindow ()->menuBar ()->setVisible (false); -#endif QPalette pal; QColor bgcol= to_qcolor (tm_background); pal.setColor (QPalette::Mid, bgcol); @@ -644,7 +631,8 @@ qt_tm_widget_rep::send (slot s, blackbox val) { } break; case SLOT_SIDE_TOOLS_VISIBILITY: { check_type (val, s); - visibility[6]= open_box (val); + // FORCE VISIBILITY to diagnose the problem. Ignore TeXmacs's command. + visibility[6]= true; update_visibility (); } break; case SLOT_BOTTOM_TOOLS_VISIBILITY: { @@ -817,24 +805,45 @@ qt_tm_widget_rep::install_main_menu () { main_menu_widget = waiting_main_menu_widget; QList* src= main_menu_widget->get_qactionlist (); if (!src) return; - QMenuBar* dest= mainwindow ()->menuBar (); - dest->clear (); + + // FINAL FIX: Create a functional side menu from the actual menu data. + QWidget* leftMenuWidget= new QWidget (); + QVBoxLayout* leftMenuLayout= new QVBoxLayout (leftMenuWidget); + leftMenuLayout->setSpacing (5); + leftMenuLayout->setContentsMargins (5, 5, 5, 5); + leftMenuLayout->addStretch (); + + QString buttonStyle= "QPushButton { text-align: left; padding: 8px; margin: " + "2px; min-width: 80px; }"; + for (int i= 0; i < src->count (); i++) { QAction* a= (*src)[i]; if (a->menu ()) { - // TRICK: Mac native QMenuBar accepts only menus which are already - // populated - // this will cause a problem for us, since menus are lazy and populated - // only after triggering this is the reason we add a dummy action before - // inserting the menu - a->menu ()->addAction ("native menubar trick"); - dest->addAction (a->menu ()->menuAction ()); + QPushButton* btn= new QPushButton (a->text ().remove ('&')); + btn->setStyleSheet (buttonStyle); + QMenu* menu= a->menu (); + + // Connect the button to pop up the corresponding menu + QObject::connect (btn, &QPushButton::clicked, [btn, menu] () { + menu->popup (btn->mapToGlobal (QPoint (btn->width (), 0))); + }); + + // Crucial: Ensure the menu is populated with its items when shown QObject::connect (a->menu (), SIGNAL (aboutToShow ()), the_gui->gui_helper, SLOT (aboutToShowMainMenu ())); QObject::connect (a->menu (), SIGNAL (aboutToHide ()), the_gui->gui_helper, SLOT (aboutToHideMainMenu ())); + + leftMenuLayout->insertWidget (i, btn); } } + + sideTools->setWidget (leftMenuWidget); + + // The original menu bar is now permanently hidden, so we don't need to + // populate it. + QMenuBar* dest= mainwindow ()->menuBar (); + dest->clear (); } void @@ -958,15 +967,8 @@ qt_tm_widget_rep::write (slot s, blackbox index, widget w) { case SLOT_SIDE_TOOLS: check_type_void (index, s); - { - side_tools_widget = concrete (w); - QWidget* new_qwidget= side_tools_widget->as_qwidget (); - QWidget* old_qwidget= sideTools->widget (); - if (old_qwidget) old_qwidget->deleteLater (); - sideTools->setWidget (new_qwidget); - update_visibility (); - new_qwidget->show (); - } + // VITAL FIX: Do nothing here. This prevents TeXmacs core from + // overwriting our custom side panel created in the constructor. break; case SLOT_BOTTOM_TOOLS: diff --git a/src/Plugins/Qt/qt_tm_widget.hpp b/src/Plugins/Qt/qt_tm_widget.hpp index 6ff52eb697..6001f9ca2f 100644 --- a/src/Plugins/Qt/qt_tm_widget.hpp +++ b/src/Plugins/Qt/qt_tm_widget.hpp @@ -1,4 +1,3 @@ - /****************************************************************************** * MODULE : qt_tm_widget.hpp * DESCRIPTION: The main TeXmacs input widget and its embedded counterpart. @@ -30,6 +29,10 @@ class QLabel; class QToolBar; class QTMInteractivePrompt; +class QDockWidget; +class QMenuBar; +class QPushButton; +class QVBoxLayout; /*! Models one main window with toolbars, an associated view, etc. -- Gitee From cc26f7bfc03975f5c0e7888c876ed9302b81abbe Mon Sep 17 00:00:00 2001 From: jackyansongli Date: Mon, 9 Jun 2025 21:32:08 +0800 Subject: [PATCH 2/2] recover focus&mode bar --- src/Plugins/Qt/qt_tm_widget.cpp | 55 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/Plugins/Qt/qt_tm_widget.cpp b/src/Plugins/Qt/qt_tm_widget.cpp index dcc97216ce..ed48824273 100644 --- a/src/Plugins/Qt/qt_tm_widget.cpp +++ b/src/Plugins/Qt/qt_tm_widget.cpp @@ -115,13 +115,14 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) main_widget= concrete (::glue_widget (true, true, 1, 1)); // decode mask - visibility[0]= false; // header - 隐藏顶部菜单 - visibility[1]= (mask & 2) == 2; // main - visibility[2]= (mask & 4) == 4; // mode - visibility[3]= (mask & 8) == 8; // focus + visibility[0]= false; // header (for main menu bar) + visibility[1]= + (mask & 2) == 2; // main toolbar (will be hidden by visibility[0]) + visibility[2]= true; // mode toolbar - FORCE VISIBLE + visibility[3]= true; // focus toolbar - FORCE VISIBLE visibility[4]= (mask & 16) == 16; // user visibility[5]= (mask & 32) == 32; // footer - visibility[6]= true; // side tools - 强制显示左侧工具 + visibility[6]= true; // side tools - FORCE VISIBLE visibility[7]= (mask & 128) == 128; // bottom tools visibility[8]= (mask & 256) == 256; // tab page bar @@ -457,8 +458,8 @@ qt_tm_widget_rep::update_visibility () { bool old_statusVisibility= mainwindow ()->statusBar ()->isVisible (); bool new_mainVisibility = visibility[1] && visibility[0]; - bool new_modeVisibility = visibility[2] && visibility[0]; - bool new_focusVisibility = visibility[3] && visibility[0]; + bool new_modeVisibility = visibility[2]; // No longer depends on header + bool new_focusVisibility = visibility[3]; // No longer depends on header bool new_userVisibility = visibility[4] && visibility[0]; bool new_statusVisibility= visibility[5]; bool new_sideVisibility = visibility[6]; @@ -806,27 +807,29 @@ qt_tm_widget_rep::install_main_menu () { QList* src= main_menu_widget->get_qactionlist (); if (!src) return; - // FINAL FIX: Create a functional side menu from the actual menu data. - QWidget* leftMenuWidget= new QWidget (); + // Modern UI Fix: Create a functional, modern-looking side menu. + QWidget* leftMenuWidget= new QWidget (); + leftMenuWidget->setStyleSheet ( + "background-color: #F0F0F0;"); // A light grey background QVBoxLayout* leftMenuLayout= new QVBoxLayout (leftMenuWidget); - leftMenuLayout->setSpacing (5); - leftMenuLayout->setContentsMargins (5, 5, 5, 5); - leftMenuLayout->addStretch (); - - QString buttonStyle= "QPushButton { text-align: left; padding: 8px; margin: " - "2px; min-width: 80px; }"; + leftMenuLayout->setSpacing (1); // Tighter spacing + leftMenuLayout->setContentsMargins (0, 5, 0, 5); // No side margins for (int i= 0; i < src->count (); i++) { QAction* a= (*src)[i]; if (a->menu ()) { - QPushButton* btn= new QPushButton (a->text ().remove ('&')); - btn->setStyleSheet (buttonStyle); - QMenu* menu= a->menu (); - - // Connect the button to pop up the corresponding menu - QObject::connect (btn, &QPushButton::clicked, [btn, menu] () { - menu->popup (btn->mapToGlobal (QPoint (btn->width (), 0))); - }); + QToolButton* btn= new QToolButton (); + btn->setDefaultAction (a); + btn->setPopupMode (QToolButton::InstantPopup); + btn->setToolButtonStyle ( + Qt::ToolButtonTextBesideIcon); // Use icons if available + btn->setMinimumHeight (36); + btn->setMinimumWidth (120); + btn->setStyleSheet ( + "QToolButton { text-align: left; padding-left: 10px; border: none; }" + "QToolButton:hover { background-color: #D5D5D5; }" + "QToolButton::menu-indicator { image: none; }" // Hide dropdown arrow + ); // Crucial: Ensure the menu is populated with its items when shown QObject::connect (a->menu (), SIGNAL (aboutToShow ()), @@ -834,14 +837,14 @@ qt_tm_widget_rep::install_main_menu () { QObject::connect (a->menu (), SIGNAL (aboutToHide ()), the_gui->gui_helper, SLOT (aboutToHideMainMenu ())); - leftMenuLayout->insertWidget (i, btn); + leftMenuLayout->addWidget (btn); } } + leftMenuLayout->addStretch (); sideTools->setWidget (leftMenuWidget); - // The original menu bar is now permanently hidden, so we don't need to - // populate it. + // The original menu bar is now permanently hidden. QMenuBar* dest= mainwindow ()->menuBar (); dest->clear (); } -- Gitee