| 25 | namespace QtPDF { |
| 26 | |
| 27 | PDFRuler::PDFRuler(PDFDocumentView *parent) |
| 28 | : QWidget(parent) |
| 29 | { |
| 30 | connect(parent, &PDFDocumentView::updated, this, static_cast<void (PDFRuler::*)()>(&PDFRuler::update)); |
| 31 | |
| 32 | auto createUnitAction = [&](const Physical::Length::Unit u) { |
| 33 | QAction * action = new QAction(QString::fromUtf8(Physical::Length::unitSymbol(u)), this); |
| 34 | action->setData(u); |
| 35 | action->setCheckable(true); |
| 36 | action->setChecked(u == unit()); |
| 37 | connect(action, &QAction::triggered, this, [this, u]() { setUnit(u); }); |
| 38 | m_contextMenu.addAction(action); |
| 39 | m_contextMenuActionGroup->addAction(action); |
| 40 | return action; |
| 41 | }; |
| 42 | m_unitActions.append(createUnitAction(Physical::Length::Centimeters)); |
| 43 | m_unitActions.append(createUnitAction(Physical::Length::Inches)); |
| 44 | m_unitActions.append(createUnitAction(Physical::Length::Bigpoints)); |
| 45 | |
| 46 | setCursor(Qt::OpenHandCursor); |
| 47 | } |
| 48 | |
| 49 | void PDFRuler::setUnit(const Physical::Length::Unit & newUnit) |
| 50 | { |