Commit 14ad4170 authored by Norby, Tom's avatar Norby, Tom
Browse files

Add +/- buttons to NumberPadWidget.

parent cdcb7b57
Pipeline #80004 passed with stages
in 18 minutes and 38 seconds
#include "radixwidgets/numberpadwidget.hh"
#include "radixbug/bug.hh"
#include <QApplication>
#include <QDesktopWidget>
#include <QKeyEvent>
#include <QPoint>
#include <QRect>
#include "radixbug/bug.hh"
#define NEXT_ROW_MARKER 0
namespace radix
{
......@@ -17,21 +16,17 @@ struct KeyboardLayoutEntry
const char *label;
};
const KeyboardLayoutEntry keyboardLayout[] = {{Qt::Key_7, "7"},
{Qt::Key_8, "8"},
{Qt::Key_9, "9"},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_4, "4"},
{Qt::Key_5, "5"},
{Qt::Key_6, "6"},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_1, "1"},
{Qt::Key_2, "2"},
{Qt::Key_3, "3"},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_0, "0"},
{Qt::Key_Period, "."},
{Qt::Key_Backspace, "Backspace"}};
const KeyboardLayoutEntry keyboardLayout[] = {
{Qt::Key_7, "7"}, {Qt::Key_8, "8"},
{Qt::Key_9, "9"}, {NEXT_ROW_MARKER, nullptr},
{Qt::Key_4, "4"}, {Qt::Key_5, "5"},
{Qt::Key_6, "6"}, {NEXT_ROW_MARKER, nullptr},
{Qt::Key_1, "1"}, {Qt::Key_2, "2"},
{Qt::Key_3, "3"}, {NEXT_ROW_MARKER, nullptr},
{Qt::Key_0, "0"}, {Qt::Key_Period, "."},
{Qt::Key_Plus, "+"}, {Qt::Key_Minus, "-"},
{NEXT_ROW_MARKER, nullptr}, {Qt::Key_Backspace, "Backspace"},
{Qt::Key_Delete, "Delete"}};
const int layoutSize = (sizeof(keyboardLayout) / sizeof(KeyboardLayoutEntry));
......@@ -74,12 +69,30 @@ NumberPadWidget::NumberPadWidget(QWidget *parent)
col = 0;
continue;
}
mButton = new QPushButton(this);
mButton->setObjectName("number_pad_button");
mButton->setText(QString::fromLatin1(keyboardLayout[i].label));
mMapper->setMapping(mButton, keyboardLayout[i].key);
connect(mButton, SIGNAL(clicked()), mMapper, SLOT(map()));
mNumLayout->addWidget(mButton, row, col);
QPushButton *button = new QPushButton(this);
int colSpan = 1;
switch (keyboardLayout[i].key)
{
case Qt::Key_Delete:
col = 2;
// [[fallthrough]]; C++17
case Qt::Key_Backspace:
case Qt::Key_3:
case Qt::Key_6:
case Qt::Key_9:
button->setObjectName("number_pad_button_wide");
colSpan = 2;
break;
default:
button->setObjectName("number_pad_button");
break;
}
button->setText(QString::fromLatin1(keyboardLayout[i].label));
mMapper->setMapping(button, keyboardLayout[i].key);
connect(button, SIGNAL(clicked()), mMapper, SLOT(map()));
mNumLayout->addWidget(button, row, col, 1, colSpan);
col++;
}
}
......@@ -98,8 +111,8 @@ void NumberPadWidget::focusInEvent(QFocusEvent *event)
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->move(center.x() - int(mNumberWidget->width() * 0.5),
center.y() - int(mNumberWidget->height() * 0.5));
mNumberWidget->show();
}
......
......@@ -17,7 +17,6 @@ class RADIX_PUBLIC NumberPadWidget : public QLineEdit
QSignalMapper* mMapper;
QWidget* mNumberWidget;
QGridLayout* mNumLayout;
QPushButton* mButton;
public:
NumberPadWidget(QWidget* parent = nullptr);
......
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