Implement font style context menu

This commit is contained in:
G.K.MacGregor
2024-05-26 19:27:48 +01:00
parent e9855ceba3
commit dfff4c5e17
3 changed files with 59 additions and 0 deletions

View File

@@ -1106,6 +1106,17 @@ void X26DockWidget::customMenuRequested(QPoint pos)
connect(static_cast<TripletDisplayAttrsQMenu *>(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<TripletFontStyleQMenu *>(customMenu)->setStyleChecked(i, index.model()->data(index.model()->index(index.row(), 0), Qt::UserRole+i+1).toBool());
connect(static_cast<TripletFontStyleQMenu *>(customMenu)->styleAction(i), &QAction::toggled, [=](const int checked) { updateModelFromCookedWidget(checked, Qt::UserRole+i+1); updateAllCookedTripletWidgets(index); });
}
static_cast<TripletFontStyleQMenu *>(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<TripletFontStyleQMenu *>(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

View File

@@ -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);
}

View File

@@ -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