Commit 1fb2cac6 authored by Norby, Tom's avatar Norby, Tom
Browse files

Allow +/- to toggle rather than insert.

parent 14ad4170
Pipeline #80009 passed with stages
in 25 minutes and 58 seconds
......@@ -42,9 +42,10 @@ QString keyToCharacter(int key)
return QString();
}
NumberPadWidget::NumberPadWidget(QWidget *parent)
NumberPadWidget::NumberPadWidget(QWidget *parent, bool toggle)
: QLineEdit(parent)
{
mToggle = toggle;
mMapper = new QSignalMapper(this);
connect(mMapper, SIGNAL(mapped(int)), SLOT(buttonClicked(int)));
......@@ -90,8 +91,17 @@ NumberPadWidget::NumberPadWidget(QWidget *parent)
}
button->setText(QString::fromLatin1(keyboardLayout[i].label));
mMapper->setMapping(button, keyboardLayout[i].key);
connect(button, SIGNAL(clicked()), mMapper, SLOT(map()));
if (mToggle && keyboardLayout[i].key == Qt::Key_Plus)
connect(button, SIGNAL(clicked()), this, SLOT(makePositive()));
else if (mToggle && keyboardLayout[i].key == Qt::Key_Minus)
connect(button, SIGNAL(clicked()), this, SLOT(makeNegative()));
else
{
mMapper->setMapping(button, keyboardLayout[i].key);
connect(button, SIGNAL(clicked()), mMapper, SLOT(map()));
}
mNumLayout->addWidget(button, row, col, 1, colSpan);
col++;
}
......@@ -103,6 +113,24 @@ void NumberPadWidget::buttonClicked(int key)
QLineEdit::keyPressEvent(&event);
}
void NumberPadWidget::makePositive()
{
QString sval = text().trimmed();
if (sval.startsWith("-"))
{
setText(sval.mid(1));
}
}
void NumberPadWidget::makeNegative()
{
QString sval = text().trimmed();
if (!sval.startsWith("-"))
{
setText(sval.prepend("-"));
}
}
void NumberPadWidget::focusInEvent(QFocusEvent *event)
{
QLineEdit::focusInEvent(event);
......
......@@ -17,9 +17,10 @@ class RADIX_PUBLIC NumberPadWidget : public QLineEdit
QSignalMapper* mMapper;
QWidget* mNumberWidget;
QGridLayout* mNumLayout;
bool mToggle;
public:
NumberPadWidget(QWidget* parent = nullptr);
NumberPadWidget(QWidget* parent = nullptr, bool toggle = false);
public slots:
void focusInEvent(QFocusEvent*) override;
......@@ -28,6 +29,8 @@ class RADIX_PUBLIC NumberPadWidget : public QLineEdit
private slots:
void buttonClicked(int key);
void makePositive();
void makeNegative();
}; // class
} // namespace radix
#endif /** RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment