Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
1fb2cac6
Commit
1fb2cac6
authored
Nov 14, 2019
by
Norby, Tom
Browse files
Allow +/- to toggle rather than insert.
parent
14ad4170
Pipeline
#80009
passed with stages
in 25 minutes and 58 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixwidgets/numberpadwidget.cc
View file @
1fb2cac6
...
...
@@ -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
);
...
...
radixwidgets/numberpadwidget.hh
View file @
1fb2cac6
...
...
@@ -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_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment