Skip to content

Commit

Permalink
Fix #13 (Implement code viewer from tivars_lib_cpp)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Mar 28, 2016
1 parent 54030ec commit 4eb7c63
Show file tree
Hide file tree
Showing 24 changed files with 1,875 additions and 4 deletions.
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Portions of this program use code, directly or modified, from:
* z80e, a z80 emulator developed by KnightOS Group
* Firebird, a TI-Nspire emulator developed by Fabian Vogt
* QHexEdit2, developed by Simsys
* tivars_lib_cpp, developed by Adrien "Adriweb" Bertrand
* Silk iconset, created by Mark James from famfamfam.com

________________________________________________________
Expand Down Expand Up @@ -32,6 +33,20 @@ QHexEdit2 license:
GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1, February 1999
As per https://github.com/Simsys/qhexedit2/blob/f1e342cd342efd0dc71ee6625fd8b28cf44f26b1/src/license.txt


________________________________________________________
tivars_lib_cpp license:

The MIT License (MIT)
Copyright (c) 2015 Adrien Bertrand

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


________________________________________________________
Silk iconset license:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ _(Take a look at [the issues](https://github.com/CE-Programming/CEmu/issues), to

## License
CEmu is licensed under the [GPLv3](LICENSE).
_Acknowledgements_: Some CEmu parts are, directly, modified, or inspired, from [z80e](https://github.com/KnightOS/z80e), [Firebird](https://github.com/nspire-emus/firebird), [QHexEdit2](https://github.com/Simsys/qhexedit2), and the [Silk iconset](http://www.famfamfam.com/lab/icons/silk/). The complete licensing information is available in the [LICENSE](LICENSE) file.
_Acknowledgements_: Some CEmu parts are, directly, modified, or inspired, from [z80e](https://github.com/KnightOS/z80e), [Firebird](https://github.com/nspire-emus/firebird), [QHexEdit2](https://github.com/Simsys/qhexedit2), [tivars_lib_cpp](https://github.com/adriweb/tivars_lib_cpp), and the [Silk iconset](http://www.famfamfam.com/lab/icons/silk/). The complete licensing information is available in the [LICENSE](LICENSE) file.
21 changes: 18 additions & 3 deletions gui/qt/CEmu.pro
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ SOURCES += utils.cpp \
qhexedit/chunks.cpp \
qhexedit/commands.cpp \
qhexedit/qhexedit.cpp \
tivarslib/utils_tivarslib.cpp \
tivarslib/TypeHandlers/TH_0x00.cpp \
tivarslib/TypeHandlers/TH_0x05.cpp \
../../core/asic.c \
../../core/cpu.c \
../../core/keypad.c \
Expand All @@ -96,7 +99,8 @@ SOURCES += utils.cpp \
capture/gif.cpp \
datawidget.cpp \
lcdpopout.cpp \
searchwidget.cpp
searchwidget.cpp \
basiccodeviewerwindow.cpp

linux|macx|ios: SOURCES += ../../core/os/os-linux.c
win32: SOURCES += ../../core/os/os-win32.c win32-console.cpp
Expand All @@ -113,6 +117,15 @@ HEADERS += utils.h \
qhexedit/chunks.h \
qhexedit/commands.h \
qhexedit/qhexedit.h \
tivarslib/autoloader.h \
tivarslib/utils_tivarslib.h \
tivarslib/TypeHandlers/TypeHandlerFuncGetter.h \
tivarslib/TypeHandlers/ITIVarTypeHandler.h \
tivarslib/TypeHandlers/TH_0x00.h \
tivarslib/TypeHandlers/TH_0x03.h \
tivarslib/TypeHandlers/TH_0x04.h \
tivarslib/TypeHandlers/TH_0x05.h \
tivarslib/TypeHandlers/TH_0x06.h \
../../core/asic.h \
../../core/cpu.h \
../../core/defines.h \
Expand Down Expand Up @@ -143,12 +156,14 @@ HEADERS += utils.h \
capture/giflib.h \
datawidget.h \
lcdpopout.h \
searchwidget.h
searchwidget.h \
basiccodeviewerwindow.h

FORMS += mainwindow.ui \
romselection.ui \
lcdpopout.ui \
searchwidget.ui
searchwidget.ui \
basiccodeviewerwindow.ui

RESOURCES += \
resources.qrc
Expand Down
33 changes: 33 additions & 0 deletions gui/qt/basiccodeviewerwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "basiccodeviewerwindow.h"
#include "ui_basiccodeviewerwindow.h"

BasicCodeViewerWindow::BasicCodeViewerWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::BasicCodeViewerWindow)
{
ui->setupUi(this);
setWindowTitle(tr("Variable viewer"));
ui->plainTextEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
}

void BasicCodeViewerWindow::setVariableName(const QString &name)
{
variableName = name;
setWindowTitle(tr("Variable viewer") + " | " + variableName);
}

void BasicCodeViewerWindow::on_pushButton_clicked()
{
showingFormatted = !showingFormatted;
showCode();
}

void BasicCodeViewerWindow::showCode()
{
ui->plainTextEdit->document()->setPlainText(showingFormatted ? formattedCode : originalCode);
}

BasicCodeViewerWindow::~BasicCodeViewerWindow()
{
delete ui;
}
39 changes: 39 additions & 0 deletions gui/qt/basiccodeviewerwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef BASICCODEVIEWERWINDOW_H
#define BASICCODEVIEWERWINDOW_H

#include <QDialog>
#include <QString>
#include "tivarslib/autoloader.h"

namespace Ui {
class BasicCodeViewerWindow;
}

class BasicCodeViewerWindow : public QDialog
{
Q_OBJECT

public:
explicit BasicCodeViewerWindow(QWidget *parent = 0);
void setVariableName(const QString& name);
void setOriginalCode(const QString& code) {
originalCode = code;
formattedCode = QString::fromStdString(tivars::TH_0x05::reindentCodeString(originalCode.toStdString()));
showCode();
}
~BasicCodeViewerWindow();

private slots:
void on_pushButton_clicked();

private:
void showCode();

Ui::BasicCodeViewerWindow *ui;
QString variableName;
QString originalCode;
QString formattedCode;
bool showingFormatted = false;
};

#endif // BASICCODEVIEWERWINDOW_H
65 changes: 65 additions & 0 deletions gui/qt/basiccodeviewerwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BasicCodeViewerWindow</class>
<widget class="QDialog" name="BasicCodeViewerWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>349</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Toggle original/reformatted</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
12 changes: 12 additions & 0 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "qtframebuffer.h"
#include "qtkeypadbridge.h"
#include "searchwidget.h"
#include "basiccodeviewerwindow.h"

#include "utils.h"
#include "capture/gif.h"
Expand Down Expand Up @@ -971,17 +972,28 @@ void MainWindow::refreshVariableList() {
currentRow = ui->emuVarView->rowCount();
ui->emuVarView->setRowCount(currentRow + 1);

QString var_value = QString::fromStdString(calc_var_content_string(var));

QTableWidgetItem *var_name = new QTableWidgetItem(calc_var_name_to_utf8(var.name));
QTableWidgetItem *var_type = new QTableWidgetItem(calc_var_type_names[var.type]);
QTableWidgetItem *var_size = new QTableWidgetItem(QString::number(var.size));
QTableWidgetItem *var_preview = new QTableWidgetItem(var_value);

var_name->setCheckState(Qt::Unchecked);

ui->emuVarView->setItem(currentRow, 0, var_name);
ui->emuVarView->setItem(currentRow, 1, var_type);
ui->emuVarView->setItem(currentRow, 2, var_size);
ui->emuVarView->setItem(currentRow, 3, var_preview);
}
}
connect(ui->emuVarView, &QTableWidget::itemDoubleClicked, this, [&](QTableWidgetItem* item) {
BasicCodeViewerWindow codePopup;
codePopup.setOriginalCode(item->text());
codePopup.setVariableName(ui->emuVarView->item(item->row(), 0)->text());
codePopup.show();
codePopup.exec();
});
}

inReceivingMode = !inReceivingMode;
Expand Down
5 changes: 5 additions & 0 deletions gui/qt/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>Preview</string>
</property>
</column>
</widget>
</item>
</layout>
Expand Down
3 changes: 3 additions & 0 deletions gui/qt/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@
<file>resources/icons/rom.png</file>
<file>resources/icons/wizard.png</file>
</qresource>
<qresource prefix="/other">
<file>tivarslib/TypeHandlers/programs_tokens.csv</file>
</qresource>
</RCC>
41 changes: 41 additions & 0 deletions gui/qt/tivarslib/TypeHandlers/ITIVarTypeHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Part of tivars_lib_cpp
* (C) 2015 Adrien 'Adriweb' Bertrand
* https://github.com/adriweb/tivars_lib_cpp
* License: MIT
*/

#ifndef ITIVARTYPEHANDLER_H
#define ITIVARTYPEHANDLER_H

#include "../utils_tivarslib.h"

namespace tivars
{
class ITIVarTypeHandler
{

public:

// We can't make virtual static methods...

static data_t makeDataFromString(const std::string& str, const options_t options)
{
(void)str;
(void)options;
std::cerr << "This type is not supported / implemented (yet?)" << std::endl;
return data_t();
}

static std::string makeStringFromData(const data_t& data, const options_t options)
{
(void)data;
(void)options;
std::cerr << "This type is not supported / implemented (yet?)" << std::endl;
return "";
}

};
}

#endif
Loading

0 comments on commit 4eb7c63

Please sign in to comment.