Ejemplo n.º 1
0
Keyboard::Keyboard(const QVector<QString> &values, int columns, QWidget *parent)
        : QWidget(parent)
{
    QGridLayout *gridLayout = new QGridLayout;
    gridLayout->setSpacing(0);
    gridLayout->setMargin(0);
    gridLayout->setContentsMargins(0,0,0,0);
    this->setLayout(gridLayout);

    int rows = qCeil(qreal(values.size()) / qreal(columns));
    int column = 0, row = 0;
    for (const QString & value : values)
    {
        QPushButton *button = new QPushButton(value);
        button->setObjectName(value);
        if (value == "") {
            button->setEnabled(false);
        }
        connect(button, SIGNAL(pressed()), this, SLOT(pressedButton()));
        gridLayout->addWidget(button,row,column);

        column = (column + 1) % columns;
        if (column == 0) {
            row = (row + 1) % rows;
        }
    }
}
Ejemplo n.º 2
0
int readButton(){
    int buttonIsRead;
    buttonIsRead = pressedButton();
    if(buttonIsRead == 1)
        return 1;
    else
        return 0;
}
Ejemplo n.º 3
0
Keyboard::Keyboard(int base, int columns, QWidget *parent)
{
    QGridLayout *gridLayout = new QGridLayout;
    gridLayout->setSpacing(0);
    gridLayout->setMargin(0);
    gridLayout->setContentsMargins(0,0,0,0);
    this->setLayout(gridLayout);

    int elementsCount = base + 1;
    while (elementsCount % columns != 0)
        elementsCount++;
    int rows = qCeil(qreal(elementsCount) / qreal(columns));
    int column = 0, row = 0;
    for (int v = 0; v < elementsCount; ++v) {
        char c;
        if (v < 9) {
            c = '0' + v;
        }
        else {
            c = 'A' + v - 10;
        }
        if (base != 2) {
            c++; // do not start with '0'
        }

        QString value;
        if ((base == 2 && v + 1 > base) || (base != 2 && v + 1 >= base)) {
            if (column + 1 == columns) {
                value = QString("delete");
            }
            else if (((column + 1) / 2) == columns / 2) {
                value = "0";
            }
            else {
                value = "";
            }
        }
        else {
            value = QString(c);
        }

        QPushButton *button = new QPushButton(value);
        button->setObjectName(value);
        if (value == "") {
            button->setEnabled(false);
        }
        connect(button, SIGNAL(pressed()), this, SLOT(pressedButton()));
        gridLayout->addWidget(button,row,column);

        column = (column + 1) % columns;
        if (column == 0) {
            row = (row + 1);
        }
    }

}
Ejemplo n.º 4
0
void Keyboard::pressedButton() {
    QString senderObjectName = sender()->objectName();

    if (senderObjectName == "delete") {
        senderObjectName = "";
    }
    else if (senderObjectName == "") {
        return;
    }

    emit pressedButton(senderObjectName);
}
Ejemplo n.º 5
0
void LeftHandMenu::buttonPressed(EPage page) {
    mSingleColorButton->shouldHightlght(false);
    mMultiColorButton->shouldHightlght(false);
    mMoodButton->shouldHightlght(false);
    mSettingsButton->shouldHightlght(false);
    if (page == EPage::colorPage) {
        mSingleColorButton->shouldHightlght(true);
    }  else if (page == EPage::palettePage) {
        mMultiColorButton->shouldHightlght(true);
    }  else if (page == EPage::moodPage) {
        mMoodButton->shouldHightlght(true);
    }  else if (page == EPage::settingsPage) {
        mSettingsButton->shouldHightlght(true);
    }  else {
        qDebug() << "Do not recognize key " << pageToString(page);
    }
    emit pressedButton(page);
}
Ejemplo n.º 6
0
//State Diagram LED3
int LED3_SM(State state){
	static uint32_t timer = 0;
	int button = pressedButton();
	static uint32_t previousTime = 0;
	if(timer != 5){
		if(button == GPIO_PIN_SET)
			timer = 0;
	}else if(timer == 5){
		if(button == GPIO_PIN_SET)
			return 0;
	}
	switch(state){
		case INITIAL:
			initRearLED1();
			state = STATEA;
		break;
		case STATEA:
			if(timer != 4){
				if(getCurrentTime()-previousTime >  two_hundred_millisec){
					turnOnLED(PORTB,LED1);
					previousTime = getCurrentTime();
					state = STATEB;
					timer ++ ;
				}
			}
		break;
		case STATEB:
			if(timer==5){
				turnOffLED(PORTB,LED1);
			}else{
			if(getCurrentTime()-previousTime >  two_hundred_millisec){
				turnOffLED(PORTB,LED1);
				previousTime = getCurrentTime();
				state = FINAL;
			}
			}
		break;
		case FINAL:
			state = INITIAL;
		break;
		}
		return state;
}
Ejemplo n.º 7
0
MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
{
    _currentKeyboard = 0;

    _mainLayout = new QVBoxLayout;
    _mainLayout->setSpacing(0);
    _mainLayout->setMargin(0);
    _mainLayout->setContentsMargins(10,10,10,0);

    QWidget *centralWidget = new QWidget;
    centralWidget->setLayout(_mainLayout);
    this->setCentralWidget(centralWidget);

    // create labels
    Label * label = new Label(2);
    label->setObjectName("2");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    _mainLayout->addWidget(label);

    // second row: UInt16 Hex
    QWidget *row = new QWidget;
    QLayout *rowLayout = new QHBoxLayout;
    rowLayout->setSpacing(0);
    rowLayout->setMargin(0);
    row->setLayout(rowLayout);
    _mainLayout->addWidget(row);

    label = new Label(10);
    label->setObjectName("10");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    label = new Label(16);
    label->setObjectName("16");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    // third row: Octal Char
    row = new QWidget;
    rowLayout = new QHBoxLayout;
    rowLayout->setSpacing(0);
    rowLayout->setMargin(0);
    row->setLayout(rowLayout);
    _mainLayout->addWidget(row);

    label = new Label(8);
    label->setObjectName("8");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    label = new CharLabel();
    _labels["Char"] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    // keyboard box widget
    _keyboardBoxWidget = new QWidget;
    QLayout * keyboardBoxLayout = new QGridLayout;
    keyboardBoxLayout->setSpacing(0);
    keyboardBoxLayout->setMargin(0);
    keyboardBoxLayout->setContentsMargins(0,0,0,0);
    _keyboardBoxWidget->setLayout(keyboardBoxLayout);
    _keyboardBoxWidget->setFixedHeight(200);
    _mainLayout->addWidget(_keyboardBoxWidget);

    // keyboards
    Keyboard *keyboard = new Keyboard(16, 3);
    keyboard->setObjectName("16");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(8, 3);
    keyboard->setObjectName("8");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(10, 3);
    keyboard->setObjectName("10");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(2, 2);
    keyboard->setObjectName("2");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    setKeyboard(tr("10"));
    updateLabels();
}