Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
bffd5f7c
Commit
bffd5f7c
authored
Jul 08, 2018
by
LEFEBVREJP email
Browse files
Merge branch 'widgets' into 'master'
Initial working version of NumberPadWidget. See merge request
!44
parents
f095cc95
3efc6701
Pipeline
#14011
passed with stages
in 7 minutes and 41 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixwidgets/CMakeLists.txt
View file @
bffd5f7c
...
...
@@ -23,6 +23,7 @@ TRIBITS_SUBPACKAGE(widgets)
SET
(
HEADERS
tabwidget.hh
tableview.hh
numberpadwidget.hh
)
#
# Moc the header files
...
...
@@ -50,6 +51,7 @@ ENDIF()
SET
(
SOURCES
tabwidget.cc
tableview.cc
numberpadwidget.cc
)
##---------------------------------------------------------------------------##
...
...
@@ -59,6 +61,7 @@ SET(SOURCES
TRIBITS_ADD_LIBRARY
(
radixwidgets
SOURCES
${
SOURCES
}
${
MOC_FILES
}
${
RESOURCE_RESULT
}
NOINSTALLHEADERS
${
HEADERS
}
)
INSTALL
(
FILES
${
HEADERS
}
...
...
radixwidgets/examples/CMakeLists.txt
View file @
bffd5f7c
...
...
@@ -8,6 +8,9 @@ IF(USE_QT4)
QT4_WRAP_CPP
(
QMOC_FILES2
radixtablewidget.hh
)
QT4_WRAP_CPP
(
QMOC_FILES3
radixnumberpadwidget.hh
)
ELSE
()
QT5_WRAP_CPP
(
QMOC_FILES1
radixtabwidget.hh
...
...
@@ -15,6 +18,9 @@ ELSE()
QT5_WRAP_CPP
(
QMOC_FILES2
radixtablewidget.hh
)
QT5_WRAP_CPP
(
QMOC_FILES3
radixnumberpadwidget.hh
)
ENDIF
()
TRIBITS_ADD_EXECUTABLE
(
radixtabwidget
NOEXEPREFIX
...
...
@@ -26,3 +32,7 @@ TRIBITS_ADD_EXECUTABLE(radixtablewidget
SOURCES radixtablewidget.cc
${
QMOC_FILES2
}
)
TRIBITS_ADD_EXECUTABLE
(
radixnumberpadwidget
NOEXEPREFIX
SOURCES radixnumberpadwidget.cc
${
QMOC_FILES3
}
)
radixwidgets/examples/radixnumberpadwidget.cc
0 → 100644
View file @
bffd5f7c
/*
* @file: radixnumberpadwidget.cc
* @author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
*/
#include "radixnumberpadwidget.hh"
#include <QApplication>
#include <QGridLayout>
#include <QHeaderView>
#include <QLabel>
#include <limits>
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
)
{
setGeometry
(
400
,
250
,
542
,
390
);
QWidget
*
container
=
new
QWidget
(
this
);
QGridLayout
*
layout
=
new
QGridLayout
(
container
);
QLineEdit
*
empty
=
new
QLineEdit
(
"Regular line edit:"
,
this
);
widget
=
new
radix
::
NumberPadWidget
(
this
);
layout
->
addWidget
(
empty
);
layout
->
addWidget
(
widget
);
setCentralWidget
(
container
);
}
MainWindow
::~
MainWindow
()
{}
/******************************************************************************/
/******************************** MAIN PROGRAM ********************************/
/******************************************************************************/
int
main
(
int
argc
,
char
**
argv
)
{
QApplication
app
(
argc
,
argv
);
MainWindow
mainWindow
;
mainWindow
.
show
();
mainWindow
.
raise
();
return
app
.
exec
();
}
radixwidgets/examples/radixnumberpadwidget.hh
0 → 100644
View file @
bffd5f7c
#ifndef RADIX_RADIXWIDGETS_EXAMPLE_RADIXNUMBERPADWIDGET_HH_
#define RADIX_RADIXWIDGETS_EXAMPLE_RADIXNUMBERPADWIDGET_HH_
#include <QMainWindow>
#include "radixwidgets/numberpadwidget.hh"
namespace
Ui
{
class
MainWindow
;
}
class
MainWindow
:
public
QMainWindow
{
Q_OBJECT
private:
radix
::
NumberPadWidget
*
widget
;
public:
explicit
MainWindow
(
QWidget
*
parent
=
0
);
~
MainWindow
();
};
#endif // RADIX_RADIXWIDGETS_EXAMPLE_RADIXNUMBERPADWIDGET_HH_
radixwidgets/numberpadwidget.cc
0 → 100644
View file @
bffd5f7c
#include "radixwidgets/numberpadwidget.hh"
#include "radixbug/bug.hh"
#include <QApplication>
#include <QDesktopWidget>
#include <QGridLayout>
#include <QKeyEvent>
#include <QPoint>
#include <QPushButton>
#include <QRect>
#include <QSignalMapper>
#define NEXT_ROW_MARKER 0
namespace
radix
{
struct
KeyboardLayoutEntry
{
int
key
;
const
char
*
label
;
};
const
KeyboardLayoutEntry
keyboardLayout
[]
=
{{
Qt
::
Key_7
,
"7"
},
{
Qt
::
Key_8
,
"8"
},
{
Qt
::
Key_9
,
"9"
},
{
NEXT_ROW_MARKER
,
0
},
{
Qt
::
Key_4
,
"4"
},
{
Qt
::
Key_5
,
"5"
},
{
Qt
::
Key_6
,
"6"
},
{
NEXT_ROW_MARKER
,
0
},
{
Qt
::
Key_1
,
"1"
},
{
Qt
::
Key_2
,
"2"
},
{
Qt
::
Key_3
,
"3"
},
{
NEXT_ROW_MARKER
,
0
},
{
Qt
::
Key_0
,
"0"
},
{
Qt
::
Key_Period
,
"."
},
{
Qt
::
Key_Backspace
,
"Backspace"
}};
const
int
layoutSize
=
(
sizeof
(
keyboardLayout
)
/
sizeof
(
KeyboardLayoutEntry
));
QString
keyToCharacter
(
int
key
)
{
for
(
int
i
=
0
;
i
<
layoutSize
;
++
i
)
{
if
(
keyboardLayout
[
i
].
key
==
key
)
{
return
QString
::
fromLatin1
(
keyboardLayout
[
i
].
label
);
}
}
return
QString
();
}
NumberPadWidget
::
NumberPadWidget
(
QWidget
*
parent
)
:
QLineEdit
(
parent
)
{
QSignalMapper
*
mapper
=
new
QSignalMapper
(
this
);
connect
(
mapper
,
SIGNAL
(
mapped
(
int
)),
SLOT
(
buttonClicked
(
int
)));
// add widget containing
mNumberWidget
=
new
QWidget
(
this
);
QGridLayout
*
numLayout
=
new
QGridLayout
(
mNumberWidget
);
mNumberWidget
->
hide
();
mNumberWidget
->
setWindowFlags
(
Qt
::
WindowDoesNotAcceptFocus
|
Qt
::
Tool
|
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
);
int
row
=
0
;
int
col
=
0
;
// Create keyboard widget
for
(
int
i
=
0
;
i
<
layoutSize
;
++
i
)
{
if
(
keyboardLayout
[
i
].
key
==
NEXT_ROW_MARKER
)
{
row
++
;
col
=
0
;
continue
;
}
QPushButton
*
button
=
new
QPushButton
(
this
);
button
->
setObjectName
(
"number_pad_button"
);
button
->
setText
(
QString
::
fromLatin1
(
keyboardLayout
[
i
].
label
));
mapper
->
setMapping
(
button
,
keyboardLayout
[
i
].
key
);
connect
(
button
,
SIGNAL
(
clicked
()),
mapper
,
SLOT
(
map
()));
numLayout
->
addWidget
(
button
,
row
,
col
);
col
++
;
}
}
void
NumberPadWidget
::
buttonClicked
(
int
key
)
{
QLineEdit
::
keyPressEvent
(
new
QKeyEvent
(
QEvent
::
KeyPress
,
key
,
Qt
::
NoModifier
,
keyToCharacter
(
key
)));
}
void
NumberPadWidget
::
focusInEvent
(
QFocusEvent
*
event
)
{
QLineEdit
::
focusInEvent
(
event
);
//
// Determine where to place the widget
QRect
desktopRect
=
QApplication
::
desktop
()
->
availableGeometry
(
this
);
QPoint
center
=
desktopRect
.
center
();
mNumberWidget
->
move
(
center
.
x
()
-
mNumberWidget
->
width
()
*
0.5
,
center
.
y
()
-
mNumberWidget
->
height
()
*
0.5
);
mNumberWidget
->
show
();
}
void
NumberPadWidget
::
focusOutEvent
(
QFocusEvent
*
event
)
{
QLineEdit
::
focusOutEvent
(
event
);
mNumberWidget
->
hide
();
}
bool
NumberPadWidget
::
numberPadVisible
()
const
{
return
QWidget
::
isVisible
();
}
}
// namespace radix
radixwidgets/numberpadwidget.hh
0 → 100644
View file @
bffd5f7c
#ifndef RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_
#define RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_
#include <QLineEdit>
#include <QWidget>
namespace
radix
{
class
NumberPadWidget
:
public
QLineEdit
{
Q_OBJECT
QWidget
*
mNumberWidget
;
public:
NumberPadWidget
(
QWidget
*
parent
=
0
);
public
slots
:
void
focusInEvent
(
QFocusEvent
*
)
override
;
void
focusOutEvent
(
QFocusEvent
*
)
override
;
bool
numberPadVisible
()
const
;
private
slots
:
void
buttonClicked
(
int
key
);
};
// class
}
// namespace radix
#endif
/** RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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