1
0
Fork 0

Moved disassembly popup to AbstractTableView and added its support in StdTable

This commit is contained in:
torusrxxx 2018-10-13 16:36:05 +08:00
parent 6705ce1af3
commit 707cd444ae
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
7 changed files with 91 additions and 94 deletions

View File

@ -999,3 +999,26 @@ void AbstractStdTable::reloadData()
} }
AbstractTableView::reloadData(); AbstractTableView::reloadData();
} }
duint AbstractStdTable::getDisassemblyPopupAddress(int mousex, int mousey)
{
int c = getColumnIndexFromX(mousex);
int r = getTableOffset() + getIndexOffsetFromY(transY(mousey));
if(r < getRowCount())
{
QString cell = getCellContent(r, c);
duint addr;
bool ok = false;
#ifdef _WIN64
addr = cell.toULongLong(&ok, 16);
#else //x86
addr = cell.toULong(&ok, 16);
#endif //_WIN64
if(!ok)
return 0;
else
return addr;
}
else
return 0;
}

View File

@ -44,6 +44,7 @@ public:
virtual QString getCellContent(int r, int c) = 0; virtual QString getCellContent(int r, int c) = 0;
virtual bool isValidIndex(int r, int c) = 0; virtual bool isValidIndex(int r, int c) = 0;
virtual void sortRows(int column, bool ascending) = 0; virtual void sortRows(int column, bool ascending) = 0;
duint getDisassemblyPopupAddress(int mousex, int mousey) override;
//context menu helpers //context menu helpers
void setupCopyMenu(QMenu* copyMenu); void setupCopyMenu(QMenu* copyMenu);

View File

@ -4,6 +4,7 @@
#include "ColumnReorderDialog.h" #include "ColumnReorderDialog.h"
#include "CachedFontMetrics.h" #include "CachedFontMetrics.h"
#include "Bridge.h" #include "Bridge.h"
#include "DisassemblyPopup.h"
#include <windows.h> #include <windows.h>
int AbstractTableView::mMouseWheelScrollDelta = 0; int AbstractTableView::mMouseWheelScrollDelta = 0;
@ -28,7 +29,8 @@ void AbstractTableScrollBar::leaveEvent(QEvent* event)
AbstractTableView::AbstractTableView(QWidget* parent) AbstractTableView::AbstractTableView(QWidget* parent)
: QAbstractScrollArea(parent), : QAbstractScrollArea(parent),
mFontMetrics(nullptr) mFontMetrics(nullptr),
mDisassemblyPopup(nullptr)
{ {
// Class variable initialization // Class variable initialization
mTableOffset = 0; mTableOffset = 0;
@ -369,16 +371,21 @@ void AbstractTableView::mouseMoveEvent(QMouseEvent* event)
mColResizeData.splitHandle = true; mColResizeData.splitHandle = true;
mGuiState = AbstractTableView::ReadyToResize; mGuiState = AbstractTableView::ReadyToResize;
} }
if((wHandle == false) && (wHasCursor == true)) else if((wHandle == false) && (wHasCursor == true))
{ {
unsetCursor(); unsetCursor();
mColResizeData.splitHandle = false; mColResizeData.splitHandle = false;
mGuiState = AbstractTableView::NoState; mGuiState = AbstractTableView::NoState;
} }
else if(wHandle == false && wHasCursor == false)
{
if(event->y() > getHeaderHeight())
ShowDisassemblyPopup(getDisassemblyPopupAddress(event->x(), event->y()), event->x(), event->y());
}
} }
else else
{ {
QWidget::mouseMoveEvent(event); QAbstractScrollArea::mouseMoveEvent(event);
} }
} }
break; break;
@ -596,6 +603,7 @@ void AbstractTableView::wheelEvent(QWheelEvent* event)
else // -1 : one screen at a time else // -1 : one screen at a time
verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd); verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd);
} }
QAbstractScrollArea::wheelEvent(event);
} }
@ -614,7 +622,13 @@ void AbstractTableView::resizeEvent(QResizeEvent* event)
emit viewableRowsChanged(getViewableRowsCount()); emit viewableRowsChanged(getViewableRowsCount());
mShouldReload = true; mShouldReload = true;
} }
QWidget::resizeEvent(event); QAbstractScrollArea::resizeEvent(event);
}
void AbstractTableView::leaveEvent(QEvent* event)
{
ShowDisassemblyPopup(0, 0, 0);
QAbstractScrollArea::leaveEvent(event);
} }
/************************************************************************************ /************************************************************************************
@ -1256,3 +1270,39 @@ void AbstractTableView::prepareData()
dsint wRemainingRowsCount = getRowCount() - mTableOffset; dsint wRemainingRowsCount = getRowCount() - mTableOffset;
mNbrOfLineToPrint = (dsint)wRemainingRowsCount > (dsint)wViewableRowsCount ? (int)wViewableRowsCount : (int)wRemainingRowsCount; mNbrOfLineToPrint = (dsint)wRemainingRowsCount > (dsint)wViewableRowsCount ? (int)wViewableRowsCount : (int)wRemainingRowsCount;
} }
/************************************************************************************
DisassemblyPopup
************************************************************************************/
duint AbstractTableView::getDisassemblyPopupAddress(int mousex, int mousey)
{
return 0; //Default is no disassembly popup
}
void AbstractTableView::ShowDisassemblyPopup(duint addr, int x, int y)
{
if(!addr)
{
if(mDisassemblyPopup)
mDisassemblyPopup->hide();
return;
}
if(!mDisassemblyPopup)
mDisassemblyPopup = new DisassemblyPopup(this);
if(mDisassemblyPopup->getAddress() == addr)
return;
if(DbgFunctions()->MemIsCodePage(addr, false))
{
mDisassemblyPopup->move(mapToGlobal(QPoint(x + 20, y + fontMetrics().height() * 2)));
mDisassemblyPopup->setAddress(addr);
mDisassemblyPopup->show();
}
else
mDisassemblyPopup->hide();
}
void AbstractTableView::hideEvent(QHideEvent* event)
{
ShowDisassemblyPopup(0, 0, 0);
QAbstractScrollArea::hideEvent(event);
}

View File

@ -15,6 +15,7 @@
#include "ActionHelpers.h" #include "ActionHelpers.h"
class CachedFontMetrics; class CachedFontMetrics;
class DisassemblyPopup;
//Hacky class that fixes a really annoying cursor problem //Hacky class that fixes a really annoying cursor problem
class AbstractTableScrollBar : public QScrollBar class AbstractTableScrollBar : public QScrollBar
@ -64,6 +65,8 @@ public:
void wheelEvent(QWheelEvent* event) override; void wheelEvent(QWheelEvent* event) override;
void resizeEvent(QResizeEvent* event) override; void resizeEvent(QResizeEvent* event) override;
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
void leaveEvent(QEvent* event) override;
void hideEvent(QHideEvent* event) override;
// ScrollBar Management // ScrollBar Management
virtual dsint sliderMovedHook(int type, dsint value, dsint delta); virtual dsint sliderMovedHook(int type, dsint value, dsint delta);
@ -120,6 +123,8 @@ public:
// Update/Reload/Refresh/Repaint // Update/Reload/Refresh/Repaint
virtual void prepareData(); virtual void prepareData();
virtual duint getDisassemblyPopupAddress(int mousex, int mousey);
signals: signals:
void enterPressedSignal(); void enterPressedSignal();
void headerButtonPressed(int col); void headerButtonPressed(int col);
@ -218,6 +223,10 @@ protected:
// Font metrics // Font metrics
CachedFontMetrics* mFontMetrics; CachedFontMetrics* mFontMetrics;
void invalidateCachedFont(); void invalidateCachedFont();
// Disassembly Popup
DisassemblyPopup* mDisassemblyPopup;
void ShowDisassemblyPopup(duint addr, int x, int y);
}; };
#endif // ABSTRACTTABLEVIEW_H #endif // ABSTRACTTABLEVIEW_H

View File

@ -1,19 +1,12 @@
#include "StdSearchListView.h" #include "StdSearchListView.h"
#include "StdTable.h" #include "StdTable.h"
//#include "CachedFontMetrics.h"
#include "DisassemblyPopup.h"
void StdTableMouseMove::mouseMoveEvent(QMouseEvent* event)
{
emit mouseMoveSignal(event);
}
class StdTableSearchList : public AbstractSearchList class StdTableSearchList : public AbstractSearchList
{ {
public: public:
friend class StdSearchListView; friend class StdSearchListView;
StdTableSearchList() : mList(new StdTableMouseMove()), mSearchList(new StdTableMouseMove()) { } StdTableSearchList() : mList(new StdTable()), mSearchList(new StdTable()) { }
~StdTableSearchList() {delete mList; delete mSearchList; } ~StdTableSearchList() {delete mList; delete mSearchList; }
void lock() override { } void lock() override { }
@ -42,17 +35,14 @@ public:
} }
private: private:
StdTableMouseMove* mList; StdTable* mList;
StdTableMouseMove* mSearchList; StdTable* mSearchList;
}; };
StdSearchListView::StdSearchListView(QWidget* parent, bool enableRegex, bool enableLock) StdSearchListView::StdSearchListView(QWidget* parent, bool enableRegex, bool enableLock)
: SearchListView(parent, mSearchListData = new StdTableSearchList(), enableRegex, enableLock) : SearchListView(parent, mSearchListData = new StdTableSearchList(), enableRegex, enableLock)
{ {
setAddressColumn(0); setAddressColumn(0);
mDisassemblyPopup = nullptr;
connect(mSearchListData->mList, SIGNAL(mouseMoveSignal(QMouseEvent*)), this, SLOT(mouseMoveSlot(QMouseEvent*)));
connect(mSearchListData->mSearchList, SIGNAL(mouseMoveSignal(QMouseEvent*)), this, SLOT(mouseMoveSlot(QMouseEvent*)));
} }
StdSearchListView::~StdSearchListView() StdSearchListView::~StdSearchListView()
@ -134,60 +124,3 @@ StdTable* StdSearchListView::stdSearchList()
{ {
return mSearchListData->mSearchList; return mSearchListData->mSearchList;
} }
void StdSearchListView::mouseMoveSlot(QMouseEvent* event)
{
StdTable* that;
that = qobject_cast<StdTable*>(sender());
if(that)
{
int column = that->getColumnIndexFromX(event->x());
int row = that->getIndexOffsetFromY(that->transY(event->y()));
duint addr = 0;
if(row < that->getRowCount())
{
bool ok = false;
QString addrStr = that->getCellContent(row, column);
GuiAddStatusBarMessage((addrStr + "\n").toUtf8().constData());
#ifdef _WIN64
addr = addrStr.toULongLong(&ok, 16);
#else //x86
addr = addrStr.toULong(&ok, 16);
#endif //_WIN64
if(ok && DbgFunctions()->MemIsCodePage(addr, false))
ShowDisassemblyPopup(addr, event->x(), event->y());
else //not a code section, clear addr to reset default behaviour
addr = 0;
}
ShowDisassemblyPopup(addr, event->x(), event->y());
}
else
ShowDisassemblyPopup(0, 0, 0);
}
void StdSearchListView::leaveEvent(QEvent* event)
{
ShowDisassemblyPopup(0, 0, 0);
}
void StdSearchListView::ShowDisassemblyPopup(duint addr, int x, int y)
{
if(!addr)
{
if(mDisassemblyPopup)
mDisassemblyPopup->hide();
return;
}
if(!mDisassemblyPopup)
mDisassemblyPopup = new DisassemblyPopup(this);
if(mDisassemblyPopup->getAddress() == addr)
return;
if(DbgFunctions()->MemIsCodePage(addr, false))
{
mDisassemblyPopup->move(mapToGlobal(QPoint(x + 20, y + stdList()->fontMetrics().height() * 2)));
mDisassemblyPopup->setAddress(addr);
mDisassemblyPopup->show();
}
else
mDisassemblyPopup->hide();
}

View File

@ -3,7 +3,6 @@
#include "SearchListView.h" #include "SearchListView.h"
#include "StdTable.h" #include "StdTable.h"
class DisassemblyPopup;
class StdTableSearchList; class StdTableSearchList;
@ -27,32 +26,14 @@ public slots:
void setCellContent(int r, int c, QString s); void setCellContent(int r, int c, QString s);
void reloadData(); void reloadData();
void setSearchStartCol(int col); void setSearchStartCol(int col);
void mouseMoveSlot(QMouseEvent* event);
private: private:
StdTableSearchList* mSearchListData; StdTableSearchList* mSearchListData;
DisassemblyPopup* mDisassemblyPopup;
void leaveEvent(QEvent* event);
protected: protected:
friend class SymbolView; friend class SymbolView;
friend class Bridge; friend class Bridge;
StdTable* stdList(); StdTable* stdList();
StdTable* stdSearchList(); StdTable* stdSearchList();
void ShowDisassemblyPopup(duint addr, int x, int y);
};
//Hacked class to recieve mouse move event. This class must be placed in a header file, otherwise Qt won't create its internal functions.
class StdTableMouseMove : public StdTable
{
Q_OBJECT
public:
explicit StdTableMouseMove(QWidget* parent = 0) : StdTable(parent) { }
void mouseMoveEvent(QMouseEvent* event);
//int fontHeight() const {return mFontMetrics->height();}
signals:
void mouseMoveSignal(QMouseEvent* event);
}; };
#endif // STDSEARCHLISTVIEW_H #endif // STDSEARCHLISTVIEW_H

View File

@ -1,7 +1,7 @@
#ifndef SNOWMANVIEW_H #ifndef SNOWMANVIEW_H
#define SNOWMANVIEW_H #define SNOWMANVIEW_H
#include <QWidget> class QWidget;
struct SnowmanRange struct SnowmanRange
{ {