diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
commit | f508189682b6fba62e08feeb1596f682bad5fff9 (patch) | |
tree | 28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/devices/gui | |
download | piklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip |
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/devices/gui')
-rw-r--r-- | src/devices/gui/Makefile.am | 7 | ||||
-rw-r--r-- | src/devices/gui/device_group_ui.cpp | 9 | ||||
-rw-r--r-- | src/devices/gui/device_group_ui.h | 45 | ||||
-rw-r--r-- | src/devices/gui/hex_view.cpp | 23 | ||||
-rw-r--r-- | src/devices/gui/hex_view.h | 39 | ||||
-rw-r--r-- | src/devices/gui/hex_word_editor.cpp | 42 | ||||
-rw-r--r-- | src/devices/gui/hex_word_editor.h | 64 | ||||
-rw-r--r-- | src/devices/gui/memory_editor.cpp | 369 | ||||
-rw-r--r-- | src/devices/gui/memory_editor.h | 156 | ||||
-rw-r--r-- | src/devices/gui/register_view.cpp | 208 | ||||
-rw-r--r-- | src/devices/gui/register_view.h | 105 |
11 files changed, 1067 insertions, 0 deletions
diff --git a/src/devices/gui/Makefile.am b/src/devices/gui/Makefile.am new file mode 100644 index 0000000..ae92163 --- /dev/null +++ b/src/devices/gui/Makefile.am @@ -0,0 +1,7 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +libdeviceui_la_LDFLAGS = $(all_libraries) +noinst_LTLIBRARIES = libdeviceui.la +libdeviceui_la_SOURCES = hex_word_editor.cpp memory_editor.cpp \ + register_view.cpp hex_view.cpp device_group_ui.cpp diff --git a/src/devices/gui/device_group_ui.cpp b/src/devices/gui/device_group_ui.cpp new file mode 100644 index 0000000..64b5c14 --- /dev/null +++ b/src/devices/gui/device_group_ui.cpp @@ -0,0 +1,9 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "device_group_ui.h" diff --git a/src/devices/gui/device_group_ui.h b/src/devices/gui/device_group_ui.h new file mode 100644 index 0000000..3b2fa91 --- /dev/null +++ b/src/devices/gui/device_group_ui.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef DEVICE_GROUP_UI_H +#define DEVICE_GROUP_UI_H + +#include <qpixmap.h> +class QWidget; +class KPopupMenu; +class KListViewItem; +class KAction; + +#include "devices/base/generic_device.h" +#include "devices/base/device_group.h" +#include "devices/base/register.h" +namespace Register { class View; class ListViewItem; } +class HexEditor; +class ListContainer; + +namespace Device +{ +class Memory; +class HexView; +class MemoryEditor; + +class GroupUI : public ::Group::BaseGui +{ +public: + virtual HexView *createHexView(const HexEditor &editor, QWidget *parent) const = 0; + virtual Register::View *createRegisterView(QWidget *parent) const = 0; + virtual MemoryEditor *createConfigEditor(Device::Memory &memory, QWidget *parent) const = 0; + virtual void fillWatchListContainer(ListContainer *container, QValueVector<Register::TypeData> &ids) const = 0; + virtual Register::ListViewItem *createWatchItem(const Register::TypeData &data, KListViewItem *parent) const = 0; +}; + +inline const Device::GroupUI &groupui(const Device::Data &data) { return static_cast<const Device::GroupUI &>(*data.group().gui()); } + +} // namespace + +#endif diff --git a/src/devices/gui/hex_view.cpp b/src/devices/gui/hex_view.cpp new file mode 100644 index 0000000..6b26b0a --- /dev/null +++ b/src/devices/gui/hex_view.cpp @@ -0,0 +1,23 @@ +/*************************************************************************** + * Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> * + * Copyright (C) 2003 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "hex_view.h" + +Device::HexView::HexView(const HexEditor &editor, QWidget *parent, const char *name) + : MemoryEditorGroup(0, parent, name), _editor(editor) +{} + +void Device::HexView::display(Memory *memory) +{ + _memory = memory; + for (uint i=0; i<_editors.count(); i++) delete _editors[i]; + _editors.clear(); + if ( _memory==0 ) return; + display(); +} diff --git a/src/devices/gui/hex_view.h b/src/devices/gui/hex_view.h new file mode 100644 index 0000000..d73710e --- /dev/null +++ b/src/devices/gui/hex_view.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> * + * Copyright (C) 2003 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef HEX_VIEW_H +#define HEX_VIEW_H + +#include "memory_editor.h" +#include "libgui/hex_editor.h" + +namespace Device +{ + +class HexView : public MemoryEditorGroup +{ +Q_OBJECT +public: + HexView(const HexEditor &editor, QWidget *parent, const char *name); + virtual void display(Memory *memory); + virtual uint nbChecksumChars() const = 0; + virtual BitValue checksum() const = 0; + bool isModified() const { return _editor.isModified(); } + const Memory *originalMemory() const { return _editor.originalMemory(); } + +protected: + virtual void display() = 0; + +private: + const HexEditor &_editor; +}; + +} // namespace + +#endif diff --git a/src/devices/gui/hex_word_editor.cpp b/src/devices/gui/hex_word_editor.cpp new file mode 100644 index 0000000..fd64e13 --- /dev/null +++ b/src/devices/gui/hex_word_editor.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> * + * Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "hex_word_editor.h" + +#include <qframe.h> +#include <qgroupbox.h> +#include <qlabel.h> +#include <qapplication.h> +#include <qtimer.h> + +//----------------------------------------------------------------------------- +Device::HexWordEditor::HexWordEditor(Memory &memory, uint nbChars, QWidget *parent) + : GenericHexWordEditor(nbChars, true, parent), _memory(memory) +{ + setOffset(-1); +} + +void Device::HexWordEditor::setOffset(int offset) +{ + _offset = offset; + set(); +} + +//----------------------------------------------------------------------------- +Device::RegisterHexWordEditor::RegisterHexWordEditor(QWidget *parent, uint nbChars, BitValue mask) + : GenericHexWordEditor(nbChars, true, parent), _mask(mask) +{ + clear(); +} + +void Device::RegisterHexWordEditor::setValue(BitValue word) +{ + _word = word; + set(); +} diff --git a/src/devices/gui/hex_word_editor.h b/src/devices/gui/hex_word_editor.h new file mode 100644 index 0000000..bd9fadb --- /dev/null +++ b/src/devices/gui/hex_word_editor.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org> * + * Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef HEX_WORD_EDITOR_H +#define HEX_WORD_EDITOR_H + +#include "common/gui/hexword_gui.h" +#include "devices/base/generic_memory.h" + +namespace Device +{ +//----------------------------------------------------------------------------- +class HexWordEditor : public GenericHexWordEditor +{ +Q_OBJECT +public: + HexWordEditor(Memory &memory, uint nbChars, QWidget *parent); + void setOffset(int offset); + int offset() const { return _offset; } + +protected: + Device::Memory &_memory; + int _offset; + + virtual bool isValid() const { return _offset!=-1; } + virtual BitValue mask() const = 0; + virtual BitValue normalizeWord(BitValue value) const = 0; + virtual BitValue word() const = 0; + virtual void setWord(BitValue value) = 0; + virtual BitValue blankValue() const { return BitValue(); } +}; + +//----------------------------------------------------------------------------- +class RegisterHexWordEditor : public GenericHexWordEditor +{ +Q_OBJECT +public: + RegisterHexWordEditor(QWidget *parent, uint nbChars, BitValue mask); + void clear() { setValue(BitValue()); } + void setValue(BitValue word); + BitValue value() const { return _word; } + void setColor(QColor color) { setPaletteForegroundColor(color); } + void unsetColor() { unsetPalette(); } + +private: + BitValue _mask, _word; + + virtual bool isValid() const { return true; } + virtual BitValue mask() const { return _mask; } + virtual BitValue normalizeWord(BitValue value) const { return value.maskWith(_mask); } + virtual BitValue word() const { return _word; } + virtual void setWord(BitValue value) { _word = value; } + virtual BitValue blankValue() const { return BitValue(); } +}; + +} // namespace + +#endif diff --git a/src/devices/gui/memory_editor.cpp b/src/devices/gui/memory_editor.cpp new file mode 100644 index 0000000..175f011 --- /dev/null +++ b/src/devices/gui/memory_editor.cpp @@ -0,0 +1,369 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> * + * Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "memory_editor.h" + +#include <qlabel.h> +#include <qscrollbar.h> +#include <qlayout.h> +#include <qgrid.h> +#include <qtimer.h> +#include <qpopupmenu.h> +#include <klocale.h> +#include <kpushbutton.h> +#include <kaction.h> + +#include "common/common/misc.h" +#include "hex_word_editor.h" +#include "device_group_ui.h" +#include "libgui/toplevel.h" +#include "libgui/main_global.h" +#include "hex_view.h" +#include "libgui/gui_prog_manager.h" + +//----------------------------------------------------------------------------- +Device::MemoryEditor::MemoryEditor(Device::Memory *memory, QWidget *parent, const char *name) + : QFrame(parent, name), _memory(memory) +{ + _top = new QVBoxLayout(this, 5, 10); +} + +//----------------------------------------------------------------------------- +Device::MemoryRangeEditor::MemoryRangeEditor(Device::Memory &memory, + uint nbLines, uint nbCols, uint offset, int nb, + QWidget *parent, const char *name) + : MemoryEditor(&memory, parent, name), + _nbLines(nbLines), _nbCols(nbCols), _offset(offset), _nb(nb) +{} + +void Device::MemoryRangeEditor::init() +{ + if ( _nb==-1 ) _nb = nbWords(); + uint totalNbLines = _nb / _nbCols; + if ( (_nb % _nbCols)!=0 ) totalNbLines++; + + QHBoxLayout *hbox = new QHBoxLayout(_top); + + QVBoxLayout *vbox = new QVBoxLayout(hbox); + QFrame *frame = new QFrame(this); + frame->setFrameStyle(QFrame::Panel | QFrame::Raised); + frame->setMargin(5); + vbox->addWidget(frame); + vbox->addStretch(1); + QHBoxLayout *fbox = new QHBoxLayout(frame, 5, 5); + QGrid *grid = new QGrid(3+_nbCols, QGrid::Horizontal, frame, "memory_range_editor_grid"); + fbox->addWidget(grid); + grid->setSpacing(0); + grid->setMargin(3); + QFont f("courier", font().pointSize()); + grid->setFont(f); + for (uint k=0; k<_nbLines; ++k) { + // addresses + QWidget *w = new QWidget(grid); + w->setFixedWidth(10); + _blocks.append(w); + QLabel *label = new QLabel(toHex(0, 2*_memory->device().nbBytesAddress()), grid, "address_label"); + _addresses.append(label); + label = new QLabel(":", grid); + // memory + for (uint i = 0; i<_nbCols; ++i) { + HexWordEditor *h = createHexWordEditor(grid); + _editors.append(h); + connect(h, SIGNAL(modified()), SIGNAL(modified())); + connect(h, SIGNAL(moveNext()), SLOT(moveNext())); + connect(h, SIGNAL(movePrev()), SLOT(movePrev())); + connect(h, SIGNAL(moveFirst()), SLOT(moveFirst())); + connect(h, SIGNAL(moveLast()), SLOT(moveLast())); + connect(h, SIGNAL(moveUp()), SLOT(moveUp())); + connect(h, SIGNAL(moveDown()), SLOT(moveDown())); + connect(h, SIGNAL(moveNextPage()), SLOT(moveNextPage())); + connect(h, SIGNAL(movePrevPage()), SLOT(movePrevPage())); + } + } + + // scrollbar if there are more lines to display than visible + _scrollbar = new QScrollBar(0, QMAX(_nbLines, totalNbLines)-_nbLines, 1, _nbLines, 0, + QScrollBar::Vertical, frame, "memory_range_editor_scrollbar"); + connect(_scrollbar, SIGNAL(valueChanged(int)), SLOT(setIndex(int))) ; + if ( totalNbLines<=_nbLines ) _scrollbar->hide(); + fbox->addWidget(_scrollbar); + fbox->addStretch(1); + + vbox->addStretch(1); + QVBoxLayout *vboxc = new QVBoxLayout(hbox); + vboxc->setSpacing(0); + _comment = new QLabel(this); + _comment->hide(); + vboxc->addWidget(_comment); + _spacer = new QLabel(this); + _spacer->setFixedHeight(10); + _spacer->hide(); + vboxc->addWidget(_spacer); + addLegend(vboxc); + vboxc->addStretch(1); + hbox->addStretch(1); + + setReadOnly(false); + setIndex(0); +} + +void Device::MemoryRangeEditor::setComment(const QString &text) +{ + _comment->setText(text); + _comment->show(); + _spacer->show(); +} + +void Device::MemoryRangeEditor::setReadOnly(bool readOnly) +{ + for (uint i=0; i<_editors.count(); i++) + _editors[i]->setReadOnly(readOnly || isRangeReadOnly()); +} + +void Device::MemoryRangeEditor::updateDisplay() +{ + setIndex(_scrollbar->value()); +} + +void Device::MemoryRangeEditor::setStartWord(int index) +{ + setIndex(index / _nbCols / addressIncrement()); +} + +void Device::MemoryRangeEditor::setEndWord(int index) +{ + uint i = index / _nbCols / addressIncrement(); + i = (i<_nbLines ? 0 : i - _nbLines + 1); + setIndex(i); +} + +void Device::MemoryRangeEditor::setIndex(int index) +{ + _scrollbar->blockSignals(true); + _scrollbar->setValue(index); + _scrollbar->blockSignals(false); + + // memory + for (uint i=0; i<_editors.count(); i++) { + int offset = wordOffset() + i; + _editors[i]->setOffset(offset<int(nbWords()) ? offset : -1); + } + + // adresses + uint inc = addressIncrement(); + Address address = startAddress() + inc * wordOffset(); + for (uint i=0; i<_addresses.count(); i++) { + _addresses[i]->setText(toHex(address, 2*_memory->device().nbBytesAddress())); + updateAddressColor(i, address); + address += inc * _nbCols; + } +} + +void Device::MemoryRangeEditor::moveNext() +{ + QValueList<HexWordEditor *>::iterator it = _editors.find((HexWordEditor *)sender()); + ++it; + if ( it==_editors.end() || (*it)->offset()==-1 ) { + if ( current()==uint(_scrollbar->maxValue()) ) return; // at end + setIndex(current()+1); + _editors[_editors.count()-_nbCols]->setFocus(); + } else (*it)->setFocus(); +} + +void Device::MemoryRangeEditor::movePrev() +{ + QValueList<HexWordEditor *>::iterator it = _editors.find((HexWordEditor *)sender()); + if ( it==_editors.begin() ) { + if ( current()==0 ) return; // at beginning + setIndex(current()-1); + _editors[_nbCols-1]->setFocus(); + } else { + --it; + (*it)->setFocus(); + } +} + +void Device::MemoryRangeEditor::moveFirst() +{ + if ( _editors[0]==0 ) return; + setIndex(0); + _editors[0]->setFocus(); +} + +void Device::MemoryRangeEditor::moveLast() +{ + if ( _editors.count()==0 ) return; + setIndex(_scrollbar->maxValue()); + for (uint i=1; i<=_nbCols; i++) { + if ( _editors[_editors.count()-i]->offset()==-1 ) continue; + _editors[_editors.count()-i]->setFocus(); + break; + } +} + +void Device::MemoryRangeEditor::moveUp() +{ + int i = _editors.findIndex((HexWordEditor *)sender()); + uint line = i / _nbCols; + if ( line==0 ) { + if ( current()==0 ) return; // on first line + setIndex(current()-1); + _editors[i]->setFocus(); + } else _editors[i-_nbCols]->setFocus(); +} + +void Device::MemoryRangeEditor::moveDown() +{ + int i = _editors.findIndex((HexWordEditor *)sender()); + uint line = i / _nbCols; + if ( line+1==_nbLines ) { + if ( current()==uint(_scrollbar->maxValue()) ) return; // on last line + setIndex(current()+1); + if ( _editors[i]->offset()==-1 ) _editors[i-_nbCols]->setFocus(); + else _editors[i]->setFocus(); + } else _editors[i+_nbCols]->setFocus(); +} + +void Device::MemoryRangeEditor::moveNextPage() +{ + int i = _editors.findIndex((HexWordEditor *)sender()); + if ( _nbLines>(uint(_scrollbar->maxValue()) - current()) ) i = (_nbLines-1) * _nbCols + (i % _nbCols); + else setIndex(current()+_nbLines); + if ( _editors[i]->offset()==-1 ) _editors[i-_nbCols]->setFocus(); + else _editors[i]->setFocus(); +} + +void Device::MemoryRangeEditor::movePrevPage() +{ + int i = _editors.findIndex((HexWordEditor *)sender()); + if ( current()<_nbLines ) i = (i % _nbCols); + else setIndex(current()-_nbLines); + _editors[i]->setFocus(); +} + +//----------------------------------------------------------------------------- +Device::MemoryEditorGroup::MemoryEditorGroup(Device::Memory *memory, QWidget *parent, const char *name) + : MemoryEditor(memory, parent, name) +{} + +void Device::MemoryEditorGroup::addEditor(MemoryEditor *editor) +{ + connect(editor, SIGNAL(modified()), SIGNAL(modified())); + _editors.append(editor); +} + +void Device::MemoryEditorGroup::setReadOnly(bool readOnly) +{ + for (uint i=0; i<_editors.count(); i++) + _editors[i]->setReadOnly(readOnly); +} + +void Device::MemoryEditorGroup::updateDisplay() +{ + for (uint i=0; i<_editors.count(); i++) + _editors[i]->updateDisplay(); +} + +//----------------------------------------------------------------------------- +const Device::ActionData Device::ACTION_DATA[Nb_Actions] = { + { I18N_NOOP("&Clear"), "fileclose", NeedWrite }, + { I18N_NOOP("&Zero"), 0, NeedWrite }, + { I18N_NOOP("For checksum check"), 0, NeedWrite }, + { I18N_NOOP("Re&load"), "reload", SeparatorAfter | NeedModified }, + { I18N_NOOP("&Program"), "piklab_burnchip", NeedProgrammer }, + { I18N_NOOP("&Verify"), "piklab_verifychip", NeedProgrammer }, + { I18N_NOOP("&Read"), "piklab_readchip", NeedProgrammer | NeedWrite }, + { I18N_NOOP("&Erase"), "piklab_erasechip", NeedProgrammer }, + { I18N_NOOP("&Blank Check"), "piklab_blankcheck", NeedProgrammer } +}; + +Device::MemoryTypeEditor::MemoryTypeEditor(const HexView *hexview, Device::Memory &memory, + QWidget *parent, const char *name) + : MemoryEditorGroup(&memory, parent, name), + _title(0), _comment(0), _hexview(hexview) +{ + for (uint i=0; i<Nb_Actions; i++) _actions[i] = 0; +} + +void Device::MemoryTypeEditor::init(bool first) +{ + if ( !first ) _top->addWidget(new SeparatorWidget(this)); + QHBoxLayout *hbox = new QHBoxLayout(_top); + + _title = new PopupButton(this); + for (uint i=0; i<Nb_Actions; i++) { + if ( hasAction(Action(i)) ) { + _actions[i] = new KAction(i18n(ACTION_DATA[i].label), ACTION_DATA[i].icon, 0, + this, SLOT(doAction()), Main::toplevel().actionCollection()); + addAction(_actions[i]); + } + if ( ACTION_DATA[i].properties & SeparatorAfter ) _title->appendSeparator(); + } + _title->appendSeparator(); + hbox->addWidget(_title); + + _comment = new QLabel(this); + hbox->addWidget(_comment); + hbox->addStretch(1); + + connect(&Main::toplevel(), SIGNAL(stateChanged()), SLOT(stateChanged())); +} + +void Device::MemoryTypeEditor::addAction(KAction *action) +{ + _title->appendAction(action); +} + +void Device::MemoryTypeEditor::doAction() +{ + for (uint i=0; i<Nb_Actions; i++) { + if ( sender()==_actions[i] ) { + doAction(Action(i)); + break; + } + } +} + +void Device::MemoryTypeEditor::doAction(Action action) +{ + if ( (ACTION_DATA[action].properties & NeedProgrammer) + && !Programmer::manager->initProgramming(false) ) return; + bool ok = internalDoAction(action); + if ( ACTION_DATA[action].properties & NeedProgrammer ) + Programmer::manager->endProgramming(); + if (ok) { + updateDisplay(); + modified(); + } +} + +void Device::MemoryTypeEditor::stateChanged() +{ + bool idle = ( Main::state()==Main::Idle ); + for (uint i=0; i<Nb_Actions; i++) { + if ( _actions[i]==0 ) continue; + bool on = true; + if ( (ACTION_DATA[i].properties & NeedProgrammer) && !idle ) on = false; + if ( (ACTION_DATA[i].properties & NeedWrite) && _readOnly ) on = false; + if ( (ACTION_DATA[i].properties & NeedModified) && (_hexview==0 || !_hexview->isModified()) ) on = false; + _actions[i]->setEnabled(on); + } +} + +void Device::MemoryTypeEditor::setReadOnly(bool readOnly) +{ + _readOnly = readOnly; + MemoryEditorGroup::setReadOnly(readOnly); + stateChanged(); +} + +const Device::Memory *Device::MemoryTypeEditor::originalMemory() const +{ + return (_hexview ? _hexview->originalMemory() : 0); +} diff --git a/src/devices/gui/memory_editor.h b/src/devices/gui/memory_editor.h new file mode 100644 index 0000000..9836261 --- /dev/null +++ b/src/devices/gui/memory_editor.h @@ -0,0 +1,156 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef MEMORY_EDITOR_H +#define MEMORY_EDITOR_H + +#include <qframe.h> +#include <qscrollbar.h> +#include <qlabel.h> +#include "common/common/qflags.h" +#include "common/common/bitvalue.h" +class QVBoxLayout; +class QHBoxLayout; +class QHBox; +class KAction; +class PopupButton; + +namespace Device +{ +class HexView; +class HexWordEditor; +class Memory; + +enum Action { Clear = 0, Zero, ChecksumCheck, Reload, + Program, Verify, Read, Erase, BlankCheck, Nb_Actions }; +enum ActionProperty { NoProperty = 0, SeparatorAfter = 1, NeedProgrammer = 2, + NeedWrite = 4, NeedModified = 8 }; +Q_DECLARE_FLAGS(ActionProperties, ActionProperty) +Q_DECLARE_OPERATORS_FOR_FLAGS(ActionProperties) +struct ActionData { + const char *label, *icon; + ActionProperties properties; +}; +extern const ActionData ACTION_DATA[Nb_Actions]; + +//---------------------------------------------------------------------------- +class MemoryEditor : public QFrame +{ +Q_OBJECT +public: + MemoryEditor(Device::Memory *memory, QWidget *parent, const char *name); + virtual void setReadOnly(bool readOnly) = 0; + +public slots: + virtual void updateDisplay() = 0; + +signals: + void modified(); + +protected: + Device::Memory *_memory; + QVBoxLayout *_top; +}; + +//---------------------------------------------------------------------------- +class MemoryRangeEditor : public MemoryEditor +{ +Q_OBJECT +public: + MemoryRangeEditor(Device::Memory &memory, uint nbLines, uint nbCols, + uint offset, int nb, QWidget *parent, const char *name); + virtual void init(); + virtual void setReadOnly(bool readOnly); + void setComment(const QString &text); + +public slots: + virtual void updateDisplay(); + void moveNext(); + void movePrev(); + void moveFirst(); + void moveLast(); + void moveUp(); + void moveDown(); + void moveNextPage(); + void movePrevPage(); + +protected slots: + void setStartWord(int index); + void setEndWord(int index); + void setIndex(int index); + +protected: + uint _nbLines, _nbCols, _offset; + int _nb; + QValueList<QLabel *> _addresses; + QValueList<QWidget *> _blocks; + QValueList<HexWordEditor *> _editors; + QScrollBar *_scrollbar; + QLabel *_comment; + QWidget *_spacer; + + uint wordOffset() const { return _offset + current() * _nbCols; } + uint current() const { return _scrollbar->value(); } + virtual uint nbWords() const = 0; + virtual uint addressIncrement() const = 0; + virtual Address startAddress() const = 0; + virtual HexWordEditor *createHexWordEditor(QWidget *parent) = 0; + virtual bool isRangeReadOnly() const = 0; + virtual void updateAddressColor(uint i, Address address) { Q_UNUSED(i); Q_UNUSED(address); } + virtual void addLegend(QVBoxLayout *vbox) { Q_UNUSED(vbox); } +}; + +//---------------------------------------------------------------------------- +class MemoryEditorGroup : public MemoryEditor +{ +Q_OBJECT +public: + MemoryEditorGroup(Device::Memory *memory, QWidget *parent, const char *name); + void addEditor(MemoryEditor *editor); + virtual void setReadOnly(bool readOnly); + +public slots: + virtual void updateDisplay(); + +protected: + bool _modified; + QValueList<MemoryEditor *> _editors; +}; + +//---------------------------------------------------------------------------- +class MemoryTypeEditor : public MemoryEditorGroup +{ +Q_OBJECT +public: + MemoryTypeEditor(const HexView *hexview, Device::Memory &memory, QWidget *parent, const char *name); + virtual void init(bool first); + virtual void setReadOnly(bool readOnly); + +protected slots: + void doAction(); + void stateChanged(); + +protected: + PopupButton *_title; + QLabel *_comment; + const HexView *_hexview; + virtual bool internalDoAction(Action action) = 0; // return true if memory modified + virtual bool hasAction(Action) const { return true; } + void addAction(KAction *action); + const Device::Memory *originalMemory() const; + +private: + bool _readOnly; + KAction *_actions[Nb_Actions]; + + void doAction(Action action); +}; + +} // namespace + +#endif diff --git a/src/devices/gui/register_view.cpp b/src/devices/gui/register_view.cpp new file mode 100644 index 0000000..70dedc9 --- /dev/null +++ b/src/devices/gui/register_view.cpp @@ -0,0 +1,208 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "register_view.h" + +#include "libgui/main_global.h" +#include "libgui/gui_debug_manager.h" + +//---------------------------------------------------------------------------- +Register::PortBitListViewItem::PortBitListViewItem(uint index, uint bit, KListViewItem *parent) + : KListViewItem(parent), _index(index), _bit(bit) +{ + const Device::RegistersData *rdata = Main::deviceData()->registersData(); + setText(1, rdata->portBitName(_index, _bit)); + setSelectable(false); +} + +void Register::PortBitListViewItem::updateView() +{ + const QMap<uint, Device::PortBitData> &pdata = Register::list().portData(_index); + QString text; + if ( pdata.isEmpty() ) text = "--"; + else { +/* + switch (pdata[_bit].state) { + case Device::High: text = " 1"; break; + case Device::Low: text = " 0"; break; + case Device::WeakPullUp: text = "w1"; break; + case Device::WeakPullDown: text = "w0"; break; + case Device::HighImpedance: text = "HZ"; break; + case Device::Unknown: text = " "; break; + } +*/ + if ( pdata[_bit].drivingState==Device::IoUnknown ) text = " "; + else text += (pdata[_bit].drivingState==Device::IoHigh ? "1" : "0"); + text += (pdata[_bit].driving ? " > " : " < "); + if ( pdata[_bit].drivenState==Device::IoUnknown ) text += " "; + else text += (pdata[_bit].drivenState==Device::IoHigh ? "1" : "0"); + } + setText(2, text); + repaint(); +} + +void Register::PortBitListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align) +{ + QColorGroup ncg = cg; + const QMap<uint, Device::PortBitData> &data = Register::list().portData(_index); + const QMap<uint, Device::PortBitData> &odata = Register::list().oldPortData(_index); + bool changed = ( !data.isEmpty() && data[_bit]!=odata[_bit] ); + if ( column==2 && changed ) ncg.setColor(QColorGroup::Text, red); + KListViewItem::paintCell(p, ncg, column, width, align); +} + +QString Register::PortBitListViewItem::tooltip(int col) const +{ + if ( col!=2 ) return QString::null; + const QMap<uint, Device::PortBitData> &pdata = Register::list().portData(_index); + if ( pdata.isEmpty() ) return QString::null; + QString s = text(1) + ": "; + if (pdata[_bit].driving) { + if ( pdata[_bit].drivingState!=Device::IoUnknown ) s += i18n("unknown state"); + else s += (pdata[_bit].drivingState==Device::IoHigh ? i18n("driving high") : i18n("driving low")); + s += i18n(" (output)"); + } else { + if ( pdata[_bit].drivenState==Device::IoUnknown ) s += i18n("unknown state"); + else s += (pdata[_bit].drivenState==Device::IoHigh ? i18n("driven high") : i18n("driven low")); + s += i18n(" (input)"); + } + return s; +} + +//----------------------------------------------------------------------------- +Register::ListViewItem::ListViewItem(const TypeData &data, KListViewItem *parent) + : EditListViewItem(parent), _data(data), _base(NumberBase::Hex) +{ + setSelectable(false); + const Device::RegistersData *rdata = Main::deviceData()->registersData(); + if ( data.type()==Regular && rdata ) { + int i = rdata->portIndex(data.address()); + if ( i!=-1 ) { + for (int k=Device::MAX_NB_PORT_BITS-1; k>=0; k--) { + if ( !rdata->hasPortBit(i, k) ) continue; + PortBitListViewItem *item = new PortBitListViewItem(i, k, this); + _items.append(item); + } + } + } +} + +QString Register::ListViewItem::text() const +{ + BitValue value = Register::list().value(_data); + uint nbChars = convertNbChars(_data.nbChars(), NumberBase::Hex, _base); + return (value.isInitialized() ? toLabel(_base, value, nbChars) : "--"); +} + +int Register::ListViewItem::compare(QListViewItem *item, int, bool) const +{ + const TypeData &data = static_cast<ListViewItem *>(item)->data(); + int i1 = list().watched().findIndex(data); + Q_ASSERT( i1!=-1 ); + int i2 = list().watched().findIndex(_data); + Q_ASSERT( i2!=-1 ); + return ( i1-i2 ); +} + +void Register::ListViewItem::updateView() +{ + if ( _data.type()!=Special ) setText(0, toHexLabel(_data.address(), nbCharsAddress()) + ":"); + setText(1, label()); + setText(2, text()); + repaint(); + for (uint i=0; i<_items.count(); i++) _items[i]->updateView(); +} + +void Register::ListViewItem::setBase(NumberBase base) +{ + _base = base; + updateView(); +} + +void Register::ListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align) +{ + QColorGroup ncg = cg; + BitValue value = Register::list().value(_data); + BitValue oldValue = Register::list().oldValue(_data); + if ( column==2 && value!=oldValue ) ncg.setColor(QColorGroup::Text, red); + EditListViewItem::paintCell(p, ncg, column, width, align); +} + +QString Register::ListViewItem::tooltip(int col) const +{ + if ( col!=2 ) return QString::null; + BitValue value = Register::list().value(_data); + if ( !value.isInitialized() ) return QString::null; + BitValue v = value; + QString s; + for (uint i=0; i<_data.nbChars(); i++) { + char c = v.nybble(i); + if ( isprint(c) ) s = c + s; + else s = "." + s; + } + return QString("%1 - %2 - \"%3\"").arg(toHexLabel(value, _data.nbChars())) + .arg(toLabel(NumberBase::Bin, value, 4*_data.nbChars())).arg(s); +} + +QWidget *Register::ListViewItem::editWidgetFactory(int col) const +{ + if ( col!=2 || Main::programmerState()!=Programmer::Halted ) return 0; + return new NumberLineEdit(text(), 0); +} + +void Register::ListViewItem::editDone(int col, const QWidget *edit) +{ + if ( col!=2 ) return; + bool ok; + ulong value = static_cast<const NumberLineEdit *>(edit)->value(&ok); + if (ok) Debugger::manager->writeRegister(_data, value); +} + +//---------------------------------------------------------------------------- +Register::LineEdit::LineEdit(QWidget *parent, const char *name) + : NumberLineEdit(parent, name), _base(NumberBase::Nb_Types) +{ + connect(this, SIGNAL(lostFocus()), SLOT(updateText())); + connect(this, SIGNAL(returnPressed()), SLOT(returnPressedSlot())); +} + +void Register::LineEdit::updateText() +{ + setText(_value.isInitialized() ? toLabel(_base, _value, _nbChars) : "--"); + uint w = 2*frameWidth() + maxLabelWidth(_base, _nbChars, font()); + setFixedWidth(w+5); + setFixedHeight(minimumSizeHint().height()); +} + +void Register::LineEdit::setValue(NumberBase base, BitValue value, uint nbChars) +{ + _base = base; + _value = value; + _nbChars = nbChars; + updateText(); +} + +void Register::LineEdit::returnPressedSlot() +{ + bool ok; + uint v = fromAnyLabel(text(), &ok); + if (ok) _value = v; + updateText(); + emit modified(); +} + +void Register::LineEdit::keyPressEvent(QKeyEvent *e) +{ + if ( e->key()==Key_Escape ) clearFocus(); + else NumberLineEdit::keyPressEvent(e); +} + +//---------------------------------------------------------------------------- +Register::View::View(QWidget *parent, const char *name) + : QFrame(parent, name), GenericView(list()) +{} diff --git a/src/devices/gui/register_view.h b/src/devices/gui/register_view.h new file mode 100644 index 0000000..7ef8a54 --- /dev/null +++ b/src/devices/gui/register_view.h @@ -0,0 +1,105 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef REGISTER_VIEW_H +#define REGISTER_VIEW_H + +#include <qframe.h> + +#include "devices/base/register.h" +#include "common/gui/number_gui.h" +#include "common/gui/list_view.h" + +namespace Register +{ +enum { PortBitRtti = 1000, RegisterRtti = 1001 }; + +//----------------------------------------------------------------------------- +class PortBitListViewItem : public KListViewItem +{ +public: + PortBitListViewItem(uint address, uint bit, KListViewItem *parent); + virtual int rtti() const { return PortBitRtti; } + void updateView(); + QString tooltip(int column) const; + +private: + uint _index, _bit; + + virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align); +}; + +//----------------------------------------------------------------------------- +class ListViewItem : public EditListViewItem +{ +public: + ListViewItem(const TypeData &data, KListViewItem *item); + virtual int rtti() const { return RegisterRtti; } + virtual void updateView(); + const TypeData &data() const { return _data; } + QString tooltip(int column) const; + NumberBase base() const { return _base; } + void setBase(NumberBase base); + virtual QString label() const = 0; + virtual int compare(QListViewItem *item, int, bool) const; + +protected: + TypeData _data; + QValueList<PortBitListViewItem *> _items; + NumberBase _base; + + virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align); + virtual QWidget *editWidgetFactory(int col) const; + virtual bool alwaysAcceptEdit(int) const { return false; } + virtual void editDone(int col, const QWidget *editWidget); + virtual uint nbCharsAddress() const = 0; + virtual QString text() const; + virtual void activate() {} +}; + +//----------------------------------------------------------------------------- +class LineEdit : public NumberLineEdit +{ +Q_OBJECT +public: + LineEdit(QWidget *parent, const char *name = 0); + void setValue(NumberBase base, BitValue value, uint nbChars); + BitValue value() const { return _value; } + +signals: + void modified(); + +protected: + virtual void keyPressEvent(QKeyEvent *e); + +private slots: + void updateText(); + void returnPressedSlot(); + +private: + NumberBase _base; + BitValue _value; + uint _nbChars; +}; + +//----------------------------------------------------------------------------- +class View : public QFrame, public GenericView +{ +Q_OBJECT +public: + View(QWidget *parent, const char *name); + +signals: + void readSignal(uint address); + void writeSignal(uint address, uint value); + void setWatchedSignal(uint address, bool watched); +}; + +} // namespace + +#endif |