From dfff4c5e1774f2cc958177c2e991f3e4bc66516c Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Sun, 26 May 2024 19:27:48 +0100 Subject: [PATCH] Implement font style context menu --- x26dockwidget.cpp | 11 +++++++++++ x26menus.cpp | 32 ++++++++++++++++++++++++++++++++ x26menus.h | 16 ++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/x26dockwidget.cpp b/x26dockwidget.cpp index a271f6b..d80ffb7 100644 --- a/x26dockwidget.cpp +++ b/x26dockwidget.cpp @@ -1106,6 +1106,17 @@ void X26DockWidget::customMenuRequested(QPoint pos) connect(static_cast(customMenu)->otherAttrAction(i), &QAction::toggled, [=](const int checked) { updateModelFromCookedWidget(checked, Qt::UserRole+i+2); updateAllCookedTripletWidgets(index); }); } break; + case 0x2e: // Font style + customMenu = new TripletFontStyleQMenu(this); + + for (int i=0; i<3; i++) { + static_cast(customMenu)->setStyleChecked(i, index.model()->data(index.model()->index(index.row(), 0), Qt::UserRole+i+1).toBool()); + connect(static_cast(customMenu)->styleAction(i), &QAction::toggled, [=](const int checked) { updateModelFromCookedWidget(checked, Qt::UserRole+i+1); updateAllCookedTripletWidgets(index); }); + } + static_cast(customMenu)->setRowsChecked(index.model()->data(index.model()->index(index.row(), 0), Qt::UserRole+4).toInt()); + for (int i=0; i<8; i++) + connect(static_cast(customMenu)->rowsAction(i), &QAction::triggered, [=]() { updateModelFromCookedWidget(i, Qt::UserRole+4); updateAllCookedTripletWidgets(index); }); + break; case 0x21: // G1 mosaic character case 0x22: // G3 mosaic character at level 1.5 case 0x2b: // G3 mosaic character at level >=2.5 diff --git a/x26menus.cpp b/x26menus.cpp index b88d335..1c7f08d 100644 --- a/x26menus.cpp +++ b/x26menus.cpp @@ -215,3 +215,35 @@ void TripletDisplayAttrsQMenu::setOtherAttrChecked(int n, bool b) { m_actions[n+4]->setChecked(b); } + + +TripletFontStyleQMenu::TripletFontStyleQMenu(QWidget *parent): QMenu(parent) +{ + m_actions[0] = this->addAction(tr("Proportional")); + m_actions[1] = this->addAction(tr("Bold")); + m_actions[2] = this->addAction(tr("Italic")); + m_styleActionGroup = new QActionGroup(this); + m_styleActionGroup->setExclusive(false); + for (int i=0; i<3; i++) { + m_actions[i]->setCheckable(true); + m_styleActionGroup->addAction(m_actions[i]); + } + + QMenu *rowsMenu = this->addMenu(tr("Next rows")); + m_rowsActionGroup = new QActionGroup(this); + for (int i=3; i<11; i++) { + m_actions[i] = rowsMenu->addAction(QString("%1").arg(i-3)); + m_actions[i]->setCheckable(true); + m_rowsActionGroup->addAction(m_actions[i]); + } +} + +void TripletFontStyleQMenu::setStyleChecked(int n, bool b) +{ + m_actions[n]->setChecked(b); +} + +void TripletFontStyleQMenu::setRowsChecked(int n) +{ + m_actions[n+3]->setChecked(true); +} diff --git a/x26menus.h b/x26menus.h index bece6fd..6a1221b 100644 --- a/x26menus.h +++ b/x26menus.h @@ -188,4 +188,20 @@ private: QActionGroup *m_sizeActionGroup, *m_otherActionGroup; }; +class TripletFontStyleQMenu : public QMenu +{ + Q_OBJECT + +public: + TripletFontStyleQMenu(QWidget *parent = nullptr); + QAction *styleAction(int n) const { return m_actions[n]; }; + QAction *rowsAction(int n) const { return m_actions[n+3]; }; + void setStyleChecked(int n, bool b); + void setRowsChecked(int n); + +private: + QAction *m_actions[11]; + QActionGroup *m_styleActionGroup, *m_rowsActionGroup; +}; + #endif