Hex offsets

Hex offsets Git Source Tree

Root/uientry.cpp

1/*
2 Copyright (C) 2017 Grégory Soutadé
3
4 This file is part of Hex offsets.
5
6 Hex offsets is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Hex offsets is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Hex offsets. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "uientry.hpp"
21#include "mainwindow.hpp"
22
23UIEntry::operation UIEntry::getOperation(void)
24{
25 if (this->buttonPlus->isChecked())
26 return UIEntry::operation::OPERATION_PLUS;
27 else
28 return UIEntry::operation::OPERATION_MINUS;
29}
30
31void UIEntry::on_line_textChanged(const QString &arg1)
32{
33 (void) arg1;
34 this->ui->computeResult();
35}
36
37void UIEntry::on_buttonPlus_toggled(bool checked)
38{
39 this->buttonMinus->setChecked(!checked);
40 this->ui->computeResult();
41}
42
43void UIEntry::on_buttonMinus_toggled(bool checked)
44{
45 this->buttonPlus->setChecked(!checked);
46 this->ui->computeResult();
47}
48
49void UIEntry::on_buttonClear_clicked()
50{
51 this->line->clear();
52 this->ui->computeResult();
53}
54
55void UIEntry::on_checkEnable_toggled(bool checked)
56{
57 (void) checked;
58 this->ui->computeResult();
59}
60
61UIEntry::UIEntry(QWidget *parent, MainWindow* ui) : parent(parent), ui(ui)
62{
63 layout = new QHBoxLayout(0);
64
65 layout->setMargin(0);
66 layout->setSpacing(0);
67
68 buttonClear = new QPushButton(QString("Clear"), this);
69 buttonPlus = new QPushButton(QString("+"), this);
70 buttonMinus = new QPushButton(QString("-"), this);
71 checkEnable = new QCheckBox(this);
72 line = new QLineEdit(this);
73
74 line->setAlignment(Qt::AlignRight);
75
76 buttonPlus->setCheckable(true);
77 buttonMinus->setCheckable(true);
78 buttonPlus->setChecked(true);
79
80 checkEnable->setChecked(true);
81
82 buttonClear->setFocusPolicy(Qt::NoFocus);
83 buttonPlus->setFocusPolicy(Qt::NoFocus);
84 buttonMinus->setFocusPolicy(Qt::NoFocus);
85 checkEnable->setFocusPolicy(Qt::NoFocus);
86 line->setFocusPolicy(Qt::StrongFocus);
87 setFocusPolicy(Qt::StrongFocus);
88
89 this->connect(buttonClear, SIGNAL(clicked(void)), this, SLOT(on_buttonClear_clicked(void)));
90 this->connect(buttonPlus, SIGNAL(toggled(bool)), this, SLOT(on_buttonPlus_toggled(bool)));
91 this->connect(buttonMinus, SIGNAL(toggled(bool)), this, SLOT(on_buttonMinus_toggled(bool)));
92 this->connect(checkEnable, SIGNAL(toggled(bool)), this, SLOT(on_checkEnable_toggled(bool)));
93 this->connect(line, SIGNAL(textChanged(QString)), this, SLOT(on_line_textChanged(QString)));
94
95 layout->addWidget(buttonClear);
96 layout->addWidget(buttonPlus);
97 layout->addWidget(buttonMinus);
98 layout->addWidget(checkEnable);
99 layout->addWidget(line);
100
101 setLayout(layout);
102 resize(width(), minimumHeight());
103}
104
105UIEntry::~UIEntry()
106{
107 delete buttonClear;
108 delete buttonPlus;
109 delete buttonMinus;
110 delete checkEnable;
111 delete line;
112
113 delete layout;
114}
115

Archive Download this file

Branches