Initial commit
This commit is contained in:
commit
7befc37f3f
233
Makefile
Normal file
233
Makefile
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
#############################################################################
|
||||||
|
# Makefile for building: offsets
|
||||||
|
# Generated by qmake (2.01a) (Qt 4.8.7) on: mar. avr. 18 21:10:34 2017
|
||||||
|
# Project: offsets.pro
|
||||||
|
# Template: app
|
||||||
|
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++-64 CONFIG+=debug -o Makefile offsets.pro
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
####### Compiler, tools and options
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CXX = g++
|
||||||
|
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
|
||||||
|
CFLAGS = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
||||||
|
CXXFLAGS = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
|
||||||
|
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I.
|
||||||
|
LINK = g++
|
||||||
|
LFLAGS = -m64
|
||||||
|
LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
|
||||||
|
AR = ar cqs
|
||||||
|
RANLIB =
|
||||||
|
QMAKE = /usr/bin/qmake-qt4
|
||||||
|
TAR = tar -cf
|
||||||
|
COMPRESS = gzip -9f
|
||||||
|
COPY = cp -f
|
||||||
|
SED = sed
|
||||||
|
COPY_FILE = $(COPY)
|
||||||
|
COPY_DIR = $(COPY) -r
|
||||||
|
STRIP = strip
|
||||||
|
INSTALL_FILE = install -m 644 -p
|
||||||
|
INSTALL_DIR = $(COPY_DIR)
|
||||||
|
INSTALL_PROGRAM = install -m 755 -p
|
||||||
|
DEL_FILE = rm -f
|
||||||
|
SYMLINK = ln -f -s
|
||||||
|
DEL_DIR = rmdir
|
||||||
|
MOVE = mv -f
|
||||||
|
CHK_DIR_EXISTS= test -d
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
|
||||||
|
####### Output directory
|
||||||
|
|
||||||
|
OBJECTS_DIR = ./
|
||||||
|
|
||||||
|
####### Files
|
||||||
|
|
||||||
|
SOURCES = main.cpp \
|
||||||
|
mainwindow.cpp moc_mainwindow.cpp
|
||||||
|
OBJECTS = main.o \
|
||||||
|
mainwindow.o \
|
||||||
|
moc_mainwindow.o
|
||||||
|
DIST = /usr/share/qt4/mkspecs/common/unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/linux.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-base.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/qconfig.pri \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_functions.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_config.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/default_pre.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/debug.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/default_post.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/shared.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/moc.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/resources.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/uic.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/yacc.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/lex.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
|
||||||
|
offsets.pro
|
||||||
|
QMAKE_TARGET = offsets
|
||||||
|
DESTDIR =
|
||||||
|
TARGET = offsets
|
||||||
|
|
||||||
|
first: all
|
||||||
|
####### Implicit rules
|
||||||
|
|
||||||
|
.SUFFIXES: .o .c .cpp .cc .cxx .C
|
||||||
|
|
||||||
|
.cpp.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
||||||
|
|
||||||
|
.cc.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
||||||
|
|
||||||
|
.C.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
|
||||||
|
|
||||||
|
####### Build rules
|
||||||
|
|
||||||
|
all: Makefile $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): ui_mainwindow.h $(OBJECTS)
|
||||||
|
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
|
||||||
|
{ test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9][^0-9]*\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true
|
||||||
|
|
||||||
|
Makefile: offsets.pro /usr/share/qt4/mkspecs/linux-g++-64/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/linux.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-base.conf \
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-unix.conf \
|
||||||
|
/usr/share/qt4/mkspecs/qconfig.pri \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_functions.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_config.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/default_pre.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/debug.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/default_post.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/shared.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/warn_on.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/qt.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/thread.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/moc.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/resources.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/uic.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/yacc.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/lex.prf \
|
||||||
|
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
|
||||||
|
/usr/lib/x86_64-linux-gnu/libQtGui.prl \
|
||||||
|
/usr/lib/x86_64-linux-gnu/libQtCore.prl
|
||||||
|
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++-64 CONFIG+=debug -o Makefile offsets.pro
|
||||||
|
/usr/share/qt4/mkspecs/common/unix.conf:
|
||||||
|
/usr/share/qt4/mkspecs/common/linux.conf:
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base.conf:
|
||||||
|
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf:
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-base.conf:
|
||||||
|
/usr/share/qt4/mkspecs/common/g++-unix.conf:
|
||||||
|
/usr/share/qt4/mkspecs/qconfig.pri:
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_functions.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/qt_config.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/default_pre.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/debug.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/default_post.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/shared.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/warn_on.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/qt.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/unix/thread.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/moc.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/resources.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/uic.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/yacc.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/lex.prf:
|
||||||
|
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
|
||||||
|
/usr/lib/x86_64-linux-gnu/libQtGui.prl:
|
||||||
|
/usr/lib/x86_64-linux-gnu/libQtCore.prl:
|
||||||
|
qmake: FORCE
|
||||||
|
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++-64 CONFIG+=debug -o Makefile offsets.pro
|
||||||
|
|
||||||
|
dist:
|
||||||
|
@$(CHK_DIR_EXISTS) .tmp/offsets1.0.0 || $(MKDIR) .tmp/offsets1.0.0
|
||||||
|
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/offsets1.0.0/ && $(COPY_FILE) --parents mainwindow.hpp .tmp/offsets1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp .tmp/offsets1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/offsets1.0.0/ && (cd `dirname .tmp/offsets1.0.0` && $(TAR) offsets1.0.0.tar offsets1.0.0 && $(COMPRESS) offsets1.0.0.tar) && $(MOVE) `dirname .tmp/offsets1.0.0`/offsets1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/offsets1.0.0
|
||||||
|
|
||||||
|
|
||||||
|
clean:compiler_clean
|
||||||
|
-$(DEL_FILE) $(OBJECTS)
|
||||||
|
-$(DEL_FILE) *~ core *.core
|
||||||
|
|
||||||
|
|
||||||
|
####### Sub-libraries
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
-$(DEL_FILE) $(TARGET)
|
||||||
|
-$(DEL_FILE) Makefile
|
||||||
|
|
||||||
|
|
||||||
|
check: first
|
||||||
|
|
||||||
|
mocclean: compiler_moc_header_clean compiler_moc_source_clean
|
||||||
|
|
||||||
|
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
||||||
|
|
||||||
|
compiler_moc_header_make_all: moc_mainwindow.cpp
|
||||||
|
compiler_moc_header_clean:
|
||||||
|
-$(DEL_FILE) moc_mainwindow.cpp
|
||||||
|
moc_mainwindow.cpp: mainwindow.hpp
|
||||||
|
/usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) mainwindow.hpp -o moc_mainwindow.cpp
|
||||||
|
|
||||||
|
compiler_rcc_make_all:
|
||||||
|
compiler_rcc_clean:
|
||||||
|
compiler_image_collection_make_all: qmake_image_collection.cpp
|
||||||
|
compiler_image_collection_clean:
|
||||||
|
-$(DEL_FILE) qmake_image_collection.cpp
|
||||||
|
compiler_moc_source_make_all:
|
||||||
|
compiler_moc_source_clean:
|
||||||
|
compiler_uic_make_all: ui_mainwindow.h
|
||||||
|
compiler_uic_clean:
|
||||||
|
-$(DEL_FILE) ui_mainwindow.h
|
||||||
|
ui_mainwindow.h: mainwindow.ui
|
||||||
|
/usr/lib/x86_64-linux-gnu/qt4/bin/uic mainwindow.ui -o ui_mainwindow.h
|
||||||
|
|
||||||
|
compiler_yacc_decl_make_all:
|
||||||
|
compiler_yacc_decl_clean:
|
||||||
|
compiler_yacc_impl_make_all:
|
||||||
|
compiler_yacc_impl_clean:
|
||||||
|
compiler_lex_make_all:
|
||||||
|
compiler_lex_clean:
|
||||||
|
compiler_clean: compiler_moc_header_clean compiler_uic_clean
|
||||||
|
|
||||||
|
####### Compile
|
||||||
|
|
||||||
|
main.o: main.cpp mainwindow.hpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
||||||
|
|
||||||
|
mainwindow.o: mainwindow.cpp mainwindow.hpp \
|
||||||
|
ui_mainwindow.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
|
||||||
|
|
||||||
|
moc_mainwindow.o: moc_mainwindow.cpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp
|
||||||
|
|
||||||
|
####### Install
|
||||||
|
|
||||||
|
install: FORCE
|
||||||
|
|
||||||
|
uninstall: FORCE
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
|
7
README
Normal file
7
README
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
hex offsets : Hexadecimal offset calculator
|
||||||
|
|
||||||
|
Copyright (C) 2017 Grégory Soutadé
|
||||||
|
|
||||||
|
Licence : GPL v3
|
||||||
|
|
||||||
|
See http://indefero.soutade.fr/p/offsets/ for further information
|
20
main.cpp
Normal file
20
main.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int entriesNumber = UIEntry::MIN_ENTRIES_NUMBER, temp;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
temp = QString(argv[1]).toInt(&ok);
|
||||||
|
if (ok)
|
||||||
|
entriesNumber = temp;
|
||||||
|
}
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
MainWindow w(0, entriesNumber);
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
226
mainwindow.cpp
Normal file
226
mainwindow.cpp
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 Grégory Soutadé
|
||||||
|
|
||||||
|
This file is part of Hex offsets.
|
||||||
|
|
||||||
|
Hex offsets is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Hex offsets is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Hex offsets. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
#include "uientry.hpp"
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget *parent, int entriesNumber) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
ui(new Ui::MainWindow),
|
||||||
|
editConversion(false),
|
||||||
|
entriesNumber(entriesNumber)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
UIEntry* entry;
|
||||||
|
|
||||||
|
errorFont.setBold(true);
|
||||||
|
redPalette.setColor(QPalette::Text, Qt::red);
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
QWidget* curWidget = this->ui->lineBase;
|
||||||
|
for(i=0; i<UIEntry::MIN_ENTRIES_NUMBER; i++)
|
||||||
|
{
|
||||||
|
entry = new UIEntry(0, this);
|
||||||
|
ui->verticalLayout->insertWidget(1+i, entry);
|
||||||
|
setTabOrder(curWidget, entry->getLine());
|
||||||
|
entries.push_back(entry);
|
||||||
|
curWidget = entry->getLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ui->spinUIEntries->setValue(entriesNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidNumberException
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addValue(QLineEdit* line, UIEntry* entry, long* result, int base)
|
||||||
|
{
|
||||||
|
long temp;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (line->text().length() == 0) return;
|
||||||
|
|
||||||
|
temp = line->text().toLong(&ok, base);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
line->setPalette(redPalette);
|
||||||
|
line->setFont(errorFont);
|
||||||
|
throw(InvalidNumberException());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line->setPalette(blackPalette);
|
||||||
|
line->setFont(normalFont);
|
||||||
|
|
||||||
|
if (entry && !entry->enabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!entry || entry->getOperation() == UIEntry::OPERATION_PLUS)
|
||||||
|
*result += temp;
|
||||||
|
else
|
||||||
|
*result -= temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setTextValue(QLineEdit* line, long value, int base)
|
||||||
|
{
|
||||||
|
QString qres;
|
||||||
|
|
||||||
|
if (base == 10 || value >= 0)
|
||||||
|
qres.setNum(value, base);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qres = "-" + qres.setNum(-value, 16);
|
||||||
|
}
|
||||||
|
line->setText(qres);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::computeResult(void)
|
||||||
|
{
|
||||||
|
long result = 0;
|
||||||
|
QString qres;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this->addValue(this->ui->lineBase, 0, &result);
|
||||||
|
for (auto entry : entries)
|
||||||
|
{
|
||||||
|
addValue(entry->getLine(), entry, &result);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTextValue(ui->lineResult, result);
|
||||||
|
}
|
||||||
|
catch(InvalidNumberException e)
|
||||||
|
{
|
||||||
|
this->ui->lineResult->setText(QString("NaN"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_lineBase_textChanged(const QString &arg1)
|
||||||
|
{
|
||||||
|
(void) arg1;
|
||||||
|
computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_buttonCopyClipboard_clicked()
|
||||||
|
{
|
||||||
|
QApplication::clipboard()->setText(this->ui->lineResult->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_lineDec_textChanged(const QString &arg1)
|
||||||
|
{
|
||||||
|
long result = 0;
|
||||||
|
(void) arg1;
|
||||||
|
|
||||||
|
if (editConversion) return;
|
||||||
|
|
||||||
|
editConversion = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addValue(ui->lineDec, 0, &result, 10);
|
||||||
|
setTextValue(ui->lineHex, result);
|
||||||
|
}
|
||||||
|
catch (InvalidNumberException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
editConversion = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_lineHex_textChanged(const QString &arg1)
|
||||||
|
{
|
||||||
|
long result = 0;
|
||||||
|
|
||||||
|
(void) arg1;
|
||||||
|
|
||||||
|
if (editConversion) return;
|
||||||
|
|
||||||
|
editConversion = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addValue(ui->lineHex, 0, &result);
|
||||||
|
setTextValue(ui->lineDec, result, 10);
|
||||||
|
}
|
||||||
|
catch (InvalidNumberException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
editConversion = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_buttonClearBase_clicked()
|
||||||
|
{
|
||||||
|
this->ui->lineBase->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_buttonClearAll_clicked()
|
||||||
|
{
|
||||||
|
this->ui->lineBase->clear();
|
||||||
|
for (auto entry : entries)
|
||||||
|
{
|
||||||
|
entry->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_spinUIEntries_valueChanged(int newValue)
|
||||||
|
{
|
||||||
|
int i, start;
|
||||||
|
UIEntry* entry = entries[entries.size()-1];
|
||||||
|
QWidget* curWidget = entry->getLine();
|
||||||
|
|
||||||
|
start = entries.size();
|
||||||
|
if (newValue == start)
|
||||||
|
return;
|
||||||
|
else if (newValue > start)
|
||||||
|
{
|
||||||
|
for(i=start; i<newValue; i++)
|
||||||
|
{
|
||||||
|
entry = new UIEntry((QWidget*)ui->verticalLayout, this);
|
||||||
|
ui->verticalLayout->insertWidget(1+i, entry);
|
||||||
|
entries.push_back(entry);
|
||||||
|
setTabOrder(curWidget, entry->getLine());
|
||||||
|
curWidget = entry->getLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (start-- > newValue)
|
||||||
|
{
|
||||||
|
entry = entries.back();
|
||||||
|
ui->verticalLayout->removeWidget(entry);
|
||||||
|
|
||||||
|
delete entry;
|
||||||
|
entries.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resize(width(), minimumHeight());
|
||||||
|
computeResult();
|
||||||
|
}
|
71
mainwindow.hpp
Normal file
71
mainwindow.hpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 Grégory Soutadé
|
||||||
|
|
||||||
|
This file is part of Hex offsets.
|
||||||
|
|
||||||
|
Hex offsets is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Hex offsets is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Hex offsets. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_HPP
|
||||||
|
#define MAINWINDOW_HPP
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <uientry.hpp>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MainWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MainWindow(QWidget *parent = 0, int entriesNumber = 4);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_lineBase_textChanged(const QString &arg1);
|
||||||
|
|
||||||
|
void on_buttonCopyClipboard_clicked();
|
||||||
|
|
||||||
|
void on_lineDec_textChanged(const QString &arg1);
|
||||||
|
|
||||||
|
void on_lineHex_textChanged(const QString &arg1);
|
||||||
|
|
||||||
|
void on_buttonClearBase_clicked();
|
||||||
|
|
||||||
|
void on_buttonClearAll_clicked();
|
||||||
|
|
||||||
|
void on_spinUIEntries_valueChanged(int arg1);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWindow *ui;
|
||||||
|
QFont normalFont, errorFont;
|
||||||
|
QPalette blackPalette, redPalette;
|
||||||
|
void addValue(QLineEdit* line, UIEntry* entry, long* result, int base=16);
|
||||||
|
void setTextValue(QLineEdit* line, long value, int base=16);
|
||||||
|
bool editConversion;
|
||||||
|
std::vector<UIEntry*> entries;
|
||||||
|
int entriesNumber;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void computeResult(void);
|
||||||
|
void getValue(QLineEdit* line, long* result, int base);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINWINDOW_HPP
|
174
mainwindow.ui
Normal file
174
mainwindow.ui
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>394</width>
|
||||||
|
<height>299</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Hex Offsets</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetNoConstraint</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonClearBase">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Base</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineBase">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Result</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineResult">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinUIEntries">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>20</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonClearAll">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear All</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonCopyClipboard">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy to clipboard</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Dec</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineDec">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Hex</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineHex">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
23
offsets.pro
Normal file
23
offsets.pro
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2017-04-13T09:57:50
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
TARGET = offsets
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += main.cpp\
|
||||||
|
mainwindow.cpp \
|
||||||
|
uientry.cpp
|
||||||
|
|
||||||
|
HEADERS += mainwindow.hpp \
|
||||||
|
uientry.hpp
|
||||||
|
|
||||||
|
FORMS += mainwindow.ui
|
115
uientry.cpp
Normal file
115
uientry.cpp
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 Grégory Soutadé
|
||||||
|
|
||||||
|
This file is part of Hex offsets.
|
||||||
|
|
||||||
|
Hex offsets is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Hex offsets is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Hex offsets. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "uientry.hpp"
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
|
UIEntry::operation UIEntry::getOperation(void)
|
||||||
|
{
|
||||||
|
if (this->buttonPlus->isChecked())
|
||||||
|
return UIEntry::operation::OPERATION_PLUS;
|
||||||
|
else
|
||||||
|
return UIEntry::operation::OPERATION_MINUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIEntry::on_line_textChanged(const QString &arg1)
|
||||||
|
{
|
||||||
|
(void) arg1;
|
||||||
|
this->ui->computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIEntry::on_buttonPlus_toggled(bool checked)
|
||||||
|
{
|
||||||
|
this->buttonMinus->setChecked(!checked);
|
||||||
|
this->ui->computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIEntry::on_buttonMinus_toggled(bool checked)
|
||||||
|
{
|
||||||
|
this->buttonPlus->setChecked(!checked);
|
||||||
|
this->ui->computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIEntry::on_buttonClear_clicked()
|
||||||
|
{
|
||||||
|
this->line->clear();
|
||||||
|
this->ui->computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIEntry::on_checkEnable_toggled(bool checked)
|
||||||
|
{
|
||||||
|
(void) checked;
|
||||||
|
this->ui->computeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEntry::UIEntry(QWidget *parent, MainWindow* ui) : parent(parent), ui(ui)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(0);
|
||||||
|
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
|
||||||
|
buttonClear = new QPushButton(QString("Clear"), this);
|
||||||
|
buttonPlus = new QPushButton(QString("+"), this);
|
||||||
|
buttonMinus = new QPushButton(QString("-"), this);
|
||||||
|
checkEnable = new QCheckBox(this);
|
||||||
|
line = new QLineEdit(this);
|
||||||
|
|
||||||
|
line->setAlignment(Qt::AlignRight);
|
||||||
|
|
||||||
|
buttonPlus->setCheckable(true);
|
||||||
|
buttonMinus->setCheckable(true);
|
||||||
|
buttonPlus->setChecked(true);
|
||||||
|
|
||||||
|
checkEnable->setChecked(true);
|
||||||
|
|
||||||
|
buttonClear->setFocusPolicy(Qt::NoFocus);
|
||||||
|
buttonPlus->setFocusPolicy(Qt::NoFocus);
|
||||||
|
buttonMinus->setFocusPolicy(Qt::NoFocus);
|
||||||
|
checkEnable->setFocusPolicy(Qt::NoFocus);
|
||||||
|
line->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
|
this->connect(buttonClear, SIGNAL(clicked(void)), this, SLOT(on_buttonClear_clicked(void)));
|
||||||
|
this->connect(buttonPlus, SIGNAL(toggled(bool)), this, SLOT(on_buttonPlus_toggled(bool)));
|
||||||
|
this->connect(buttonMinus, SIGNAL(toggled(bool)), this, SLOT(on_buttonMinus_toggled(bool)));
|
||||||
|
this->connect(checkEnable, SIGNAL(toggled(bool)), this, SLOT(on_checkEnable_toggled(bool)));
|
||||||
|
this->connect(line, SIGNAL(textChanged(QString)), this, SLOT(on_line_textChanged(QString)));
|
||||||
|
|
||||||
|
layout->addWidget(buttonClear);
|
||||||
|
layout->addWidget(buttonPlus);
|
||||||
|
layout->addWidget(buttonMinus);
|
||||||
|
layout->addWidget(checkEnable);
|
||||||
|
layout->addWidget(line);
|
||||||
|
|
||||||
|
setLayout(layout);
|
||||||
|
resize(width(), minimumHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEntry::~UIEntry()
|
||||||
|
{
|
||||||
|
delete buttonClear;
|
||||||
|
delete buttonPlus;
|
||||||
|
delete buttonMinus;
|
||||||
|
delete checkEnable;
|
||||||
|
delete line;
|
||||||
|
|
||||||
|
delete layout;
|
||||||
|
}
|
||||||
|
|
74
uientry.hpp
Normal file
74
uientry.hpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2017 Grégory Soutadé
|
||||||
|
|
||||||
|
This file is part of Hex offsets.
|
||||||
|
|
||||||
|
Hex offsets is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Hex offsets is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Hex offsets. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UIENTRY_HPP
|
||||||
|
#define UIENTRY_HPP
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class UIEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
|
class UIEntry : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_line_textChanged(const QString &arg1);
|
||||||
|
void on_buttonPlus_toggled(bool checked);
|
||||||
|
void on_buttonMinus_toggled(bool checked);
|
||||||
|
void on_buttonClear_clicked();
|
||||||
|
void on_checkEnable_toggled(bool checked);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UIEntry(QWidget *parent = 0, MainWindow* ui = 0);
|
||||||
|
~UIEntry();
|
||||||
|
|
||||||
|
enum operation {OPERATION_PLUS, OPERATION_MINUS};
|
||||||
|
|
||||||
|
static const int MIN_ENTRIES_NUMBER = 4;
|
||||||
|
|
||||||
|
QHBoxLayout* getLayout(void) {return layout;}
|
||||||
|
QLineEdit* getLine(void) {return line;}
|
||||||
|
void clear(void) {line->clear();}
|
||||||
|
|
||||||
|
UIEntry::operation getOperation(void);
|
||||||
|
bool enabled(void) {return checkEnable->isChecked();}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget *parent;
|
||||||
|
MainWindow *ui;
|
||||||
|
|
||||||
|
QHBoxLayout* layout;
|
||||||
|
QPushButton* buttonClear;
|
||||||
|
QPushButton* buttonPlus;
|
||||||
|
QPushButton* buttonMinus;
|
||||||
|
QCheckBox* checkEnable;
|
||||||
|
QLineEdit* line;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user