void DlgSettingsDigitizeCurve::createControls (QGridLayout *layout, int &row) { LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsDigitizeCurve::createControls"; m_boxCursor = new QGroupBox ("Cursor"); layout->addWidget (m_boxCursor, row++, 1, 1, 2); // Layout inside cursor group box QGridLayout *layoutCursor = new QGridLayout; m_boxCursor->setLayout (layoutCursor); int rowCursor = 0; QLabel *labelCursorType = new QLabel("Type:"); layoutCursor->addWidget (labelCursorType, rowCursor, 0); m_btnStandard = new QRadioButton ("Standard cross"); m_btnStandard->setWhatsThis (tr ("Selects the standard cross cursor")); layoutCursor->addWidget (m_btnStandard, rowCursor++, 1); connect (m_btnStandard, SIGNAL (toggled (bool)), this, SLOT (slotCursorStandard(bool))); m_btnCustom = new QRadioButton ("Custom cross"); m_btnCustom->setWhatsThis (tr ("Selects a custom cursor based on the settings selected below")); layoutCursor->addWidget (m_btnCustom, rowCursor++, 1); connect (m_btnCustom, SIGNAL (toggled (bool)), this, SLOT (slotCursorCustom(bool))); QLabel *labelSize = new QLabel("Size (pixels):"); layoutCursor->addWidget (labelSize, rowCursor, 0); m_cmbSize = new QComboBox; m_cmbSize->addItem (QString::number (CursorSizeToPixels (CURSOR_SIZE_16)), QVariant (CURSOR_SIZE_16)); m_cmbSize->addItem (QString::number (CursorSizeToPixels (CURSOR_SIZE_32)), QVariant (CURSOR_SIZE_32)); m_cmbSize->addItem (QString::number (CursorSizeToPixels (CURSOR_SIZE_48)), QVariant (CURSOR_SIZE_48)); m_cmbSize->addItem (QString::number (CursorSizeToPixels (CURSOR_SIZE_64)), QVariant (CURSOR_SIZE_64)); ENGAUGE_ASSERT (m_cmbSize->count() == NUM_CURSOR_SIZES); m_cmbSize->setWhatsThis (tr ("Horizontal and vertical size of the cursor in pixels")); layoutCursor->addWidget (m_cmbSize, rowCursor++, 1); connect (m_cmbSize, SIGNAL (currentIndexChanged (const QString &)), this, SLOT (slotCursorSize (const QString &))); QLabel *labelInnerRadius = new QLabel("Inner radius (pixels):"); layoutCursor->addWidget (labelInnerRadius, rowCursor, 0); m_spinInnerRadius = new QSpinBox; m_spinInnerRadius->setRange (INNER_RADIUS_MIN, INNER_RADIUS_MAX); m_spinInnerRadius->setWhatsThis (tr ("Radius of circle at the center of the cursor that will remain empty")); layoutCursor->addWidget (m_spinInnerRadius, rowCursor++, 1); connect (m_spinInnerRadius, SIGNAL (valueChanged(const QString &)), this, SLOT (slotCursorInnerRadius (const QString &))); QLabel *labelLineWidth = new QLabel("Line width (pixels):"); layoutCursor->addWidget (labelLineWidth, rowCursor, 0); m_spinLineWidth = new QSpinBox; m_spinLineWidth->setRange (LINE_WIDTH_MIN, LINE_WIDTH_MAX); m_spinLineWidth->setWhatsThis (tr ("Width of each arm of the cross of the cursor")); layoutCursor->addWidget (m_spinLineWidth, rowCursor++, 1); connect (m_spinLineWidth, SIGNAL (valueChanged(const QString &)), this, SLOT (slotCursorLineWidth (const QString &))); }
QCursor CursorFactory::generate (const DocumentModelDigitizeCurve &modelDigitizeCurve) const { // To prevent hideous drawing errors when the line is thicker, we // leave a padding region around the outside equal in size to the line width int innerRadius = modelDigitizeCurve.cursorInnerRadius(); int size = CursorSizeToPixels (modelDigitizeCurve.cursorSize()); int halfSize = size / 2; int lineWidth = modelDigitizeCurve.cursorLineWidth(); int halfLineWidth = lineWidth / 2; if (modelDigitizeCurve.cursorStandardCross()) { // Standard cursor return QCursor (Qt::CrossCursor); } else { // Custom cursor const int BACKGROUND_COLOR = Qt::white, FOREGROUND_COLOR = Qt::black; // Cursor is created with pic image (which has nontrivial pen) masked by picMask image // (which has single color pen) QPixmap picMask (size, size); QPainter picMaskPaint (&picMask); picMask.fill (QColor (BACKGROUND_COLOR)); QPen pen (QBrush (FOREGROUND_COLOR), modelDigitizeCurve.cursorLineWidth()); picMaskPaint.setPen (pen); picMaskPaint.drawLine (QPointF (halfSize, halfSize - innerRadius - halfLineWidth), QPointF (halfSize, lineWidth)); // Up picMaskPaint.drawLine (QPointF (halfSize - innerRadius - halfLineWidth, halfSize), QPointF (lineWidth, halfSize)); // Left picMaskPaint.drawLine (QPointF (halfSize, halfSize + innerRadius + halfLineWidth), QPointF (halfSize, size - 1 - lineWidth)); // Down picMaskPaint.drawLine (QPointF (halfSize + innerRadius + halfLineWidth, halfSize), QPointF (size - 1 - lineWidth, halfSize)); // Right QPixmap pic (size, size); pic.fill (QColor (FOREGROUND_COLOR)); return QCursor (pic.createMaskFromColor(QColor (BACKGROUND_COLOR)), picMask.createMaskFromColor(QColor (BACKGROUND_COLOR))); } }
void DlgSettingsDigitizeCurve::updateControls() { // Cursor has to fit into current extent bool isGoodState = 2 * (m_modelDigitizeCurveAfter->cursorInnerRadius() + LINE_LENGTH_MIN) <= CursorSizeToPixels (m_modelDigitizeCurveAfter->cursorSize()); enableOk (isGoodState); m_spinInnerRadius->setEnabled (m_btnCustom->isChecked()); m_cmbSize->setEnabled (m_btnCustom->isChecked()); m_spinLineWidth->setEnabled (m_btnCustom->isChecked()); }