From 08eaab1b3ec4be5fd3f4890d1424ffd2476ddc10 Mon Sep 17 00:00:00 2001 From: torusrxxx Date: Sun, 9 Aug 2020 20:16:27 +0800 Subject: [PATCH] Add app icon to attach dialog --- .../Src/BasicView/StdIconSearchListView.cpp | 23 ++++++ src/gui/Src/BasicView/StdIconSearchListView.h | 25 ++++++ src/gui/Src/BasicView/StdIconTable.cpp | 80 +++++++++++++++++++ src/gui/Src/BasicView/StdIconTable.h | 27 +++++++ src/gui/Src/BasicView/StdTableSearchList.cpp | 5 ++ src/gui/Src/Gui/AttachDialog.cpp | 6 +- src/gui/Src/Gui/AttachDialog.h | 4 +- src/gui/x64dbg.pro | 4 + 8 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 src/gui/Src/BasicView/StdIconSearchListView.cpp create mode 100644 src/gui/Src/BasicView/StdIconSearchListView.h create mode 100644 src/gui/Src/BasicView/StdIconTable.cpp create mode 100644 src/gui/Src/BasicView/StdIconTable.h diff --git a/src/gui/Src/BasicView/StdIconSearchListView.cpp b/src/gui/Src/BasicView/StdIconSearchListView.cpp new file mode 100644 index 00000000..472a9820 --- /dev/null +++ b/src/gui/Src/BasicView/StdIconSearchListView.cpp @@ -0,0 +1,23 @@ +#include "StdIconSearchListView.h" + +StdIconSearchListView::StdIconSearchListView(QWidget* parent, bool enableRegex, bool enableLock) + : StdIconSearchListView(parent, enableRegex, enableLock, new StdTableSearchList(new StdIconTable(), new StdIconTable())) +{ +} + +StdIconSearchListView::StdIconSearchListView(QWidget* parent, bool enableRegex, bool enableLock, StdTableSearchList* tableSearchList) + : StdSearchListView(parent, enableRegex, enableLock, tableSearchList) +{ +} + +void StdIconSearchListView::setIconColumn(int c) +{ + qobject_cast(stdList())->setIconColumn(c); + qobject_cast(stdSearchList())->setIconColumn(c); +} + +void StdIconSearchListView::setRowIcon(int r, const QIcon & icon) +{ + clearFilter(); + qobject_cast(stdList())->setRowIcon(r, icon); +} diff --git a/src/gui/Src/BasicView/StdIconSearchListView.h b/src/gui/Src/BasicView/StdIconSearchListView.h new file mode 100644 index 00000000..a091a928 --- /dev/null +++ b/src/gui/Src/BasicView/StdIconSearchListView.h @@ -0,0 +1,25 @@ +#ifndef STDICONSEARCHLISTVIEW_H +#define STDICONSEARCHLISTVIEW_H + +#include "StdSearchListView.h" +#include "StdIconTable.h" + +class StdIconSearchListView : public StdSearchListView +{ + Q_OBJECT +public: + StdIconSearchListView(QWidget* parent, bool enableRegex, bool enableLock); + StdIconSearchListView(QWidget* parent, bool enableRegex, bool enableLock, StdTableSearchList* tableSearchList); + +public slots: + void setIconColumn(int c); + void setRowIcon(int r, const QIcon & icon); + +private: + StdTableSearchList* mSearchListData; + +protected: + friend class SymbolView; + friend class Bridge; +}; +#endif // STDICONSEARCHLISTVIEW_H diff --git a/src/gui/Src/BasicView/StdIconTable.cpp b/src/gui/Src/BasicView/StdIconTable.cpp new file mode 100644 index 00000000..c8b820c0 --- /dev/null +++ b/src/gui/Src/BasicView/StdIconTable.cpp @@ -0,0 +1,80 @@ +#include "StdIconTable.h" + +/************************************************************************************ + Data Management +************************************************************************************/ + +void StdIconTable::setRowIcon(int r, const QIcon & icon) +{ + mIcon.at(r) = icon; +} + +QIcon StdIconTable::getRowIcon(int r) const +{ + return mIcon.at(r); +} + +void StdIconTable::setIconColumn(int c) +{ + mIconColumn = c; +} + +int StdIconTable::getIconColumn() const +{ + return mIconColumn; +} + +void StdIconTable::setRowCount(dsint count) +{ + int wRowToAddOrRemove = count - int(mIcon.size()); + for(int i = 0; i < qAbs(wRowToAddOrRemove); i++) + { + if(wRowToAddOrRemove > 0) + mIcon.push_back(QIcon()); + else + mIcon.pop_back(); + } + StdTable::setRowCount(count); +} + +void StdIconTable::sortRows(int column, bool ascending) +{ + auto sortFn = mColumnSortFunctions.at(column); + std::vector index; + index.resize(mData.size()); + size_t i; + for(i = 0; i < mData.size(); i++) + { + index[i] = i; + } + std::stable_sort(index.begin(), index.end(), [column, ascending, this, &sortFn](const size_t & a, const size_t & b) + { + auto less = sortFn(mData.at(a).at(column).text, mData.at(b).at(column).text); + return ascending ? less : !less; + }); + auto copy1 = mData; + auto copy2 = mIcon; + for(i = 0; i < mData.size(); i++) + { + mData[i] = std::move(copy1[index[i]]); + mIcon[i] = std::move(copy2[index[i]]); + } +} + +QString StdIconTable::paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) +{ + if(col == mIconColumn) + { + mIcon.at(rowBase + rowOffset).paint(painter, x, y, h, h); + QString wStr = StdTable::paintContent(painter, rowBase, rowOffset, col, x + h, y, w, h); + + if(wStr.length()) + { + painter->setPen(getCellColor(rowBase + rowOffset, col)); + painter->drawText(QRect(x + 4 + h, y, w - 4 - h, h), Qt::AlignVCenter | Qt::AlignLeft, wStr); + } + return QString(); + } + else + return StdTable::paintContent(painter, rowBase, rowOffset, col, x, y, w, h); +} diff --git a/src/gui/Src/BasicView/StdIconTable.h b/src/gui/Src/BasicView/StdIconTable.h new file mode 100644 index 00000000..baa7908a --- /dev/null +++ b/src/gui/Src/BasicView/StdIconTable.h @@ -0,0 +1,27 @@ +#ifndef STDICONTABLE_H +#define STDICONTABLE_H + +#include "StdTable.h" + +class StdIconTable : public StdTable +{ + Q_OBJECT +public: + explicit StdIconTable(QWidget* parent = 0) : StdTable(parent), mIconColumn(0) {}; + + // Data Management + void setRowIcon(int r, const QIcon & icon); + QIcon getRowIcon(int r) const; + void setIconColumn(int c); + int getIconColumn() const; + void setRowCount(dsint count) override; + void sortRows(int column, bool ascending) override; + + QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) override; + +protected: + std::vector mIcon; //listof(row) where row = (listof(col) where col = CellData) + int mIconColumn; +}; + +#endif // STDICONTABLE_H diff --git a/src/gui/Src/BasicView/StdTableSearchList.cpp b/src/gui/Src/BasicView/StdTableSearchList.cpp index 16e9404b..1e7062ae 100644 --- a/src/gui/Src/BasicView/StdTableSearchList.cpp +++ b/src/gui/Src/BasicView/StdTableSearchList.cpp @@ -1,7 +1,10 @@ #include "StdTableSearchList.h" +#include "StdIconTable.h" void StdTableSearchList::filter(const QString & filter, FilterType type, int startColumn) { + StdIconTable* mSearchIconList = qobject_cast(mSearchList); + StdIconTable* mIconList = qobject_cast(mList); mSearchList->setRowCount(0); int rows = mList->getRowCount(); int columns = mList->getColumnCount(); @@ -15,6 +18,8 @@ void StdTableSearchList::filter(const QString & filter, FilterType type, int sta mSearchList->setCellContent(j, k, mList->getCellContent(i, k)); mSearchList->setCellUserdata(j, k, mList->getCellUserdata(i, k)); } + if(mSearchIconList && mIconList) + mSearchIconList->setRowIcon(j, mIconList->getRowIcon(i)); j++; } } diff --git a/src/gui/Src/Gui/AttachDialog.cpp b/src/gui/Src/Gui/AttachDialog.cpp index 73af594d..265c0adf 100644 --- a/src/gui/Src/Gui/AttachDialog.cpp +++ b/src/gui/Src/Gui/AttachDialog.cpp @@ -1,6 +1,6 @@ #include "AttachDialog.h" #include "ui_AttachDialog.h" -#include "StdSearchListView.h" +#include "StdIconSearchListView.h" #include "StdTable.h" #include #include @@ -27,7 +27,7 @@ AttachDialog::AttachDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Attach connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(refresh())); // Create search view (regex disabled) - mSearchListView = new StdSearchListView(this, false, false); + mSearchListView = new StdIconSearchListView(this, false, false); mSearchListView->mSearchStartCol = 0; ui->verticalLayout->insertWidget(0, mSearchListView); @@ -38,6 +38,7 @@ AttachDialog::AttachDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Attach mSearchListView->addColumnAt(300, tr("Title"), true); mSearchListView->addColumnAt(500, tr("Path"), true); mSearchListView->addColumnAt(800, tr("Command Line Arguments"), true); + mSearchListView->setIconColumn(1); // Name mSearchListView->setDrawDebugOnly(false); connect(mSearchListView, SIGNAL(enterPressedSignal()), this, SLOT(on_btnAttach_clicked())); @@ -74,6 +75,7 @@ void AttachDialog::refresh() mSearchListView->setCellContent(i, ColTitle, QString(entries[i].szExeMainWindowTitle)); mSearchListView->setCellContent(i, ColPath, QString(entries[i].szExeFile)); mSearchListView->setCellContent(i, ColCommandLine, QString(entries[i].szExeArgs)); + mSearchListView->setRowIcon(i, getFileIcon(QString(entries[i].szExeFile))); } mSearchListView->reloadData(); mSearchListView->refreshSearchList(); diff --git a/src/gui/Src/Gui/AttachDialog.h b/src/gui/Src/Gui/AttachDialog.h index e37bdbf3..25b52435 100644 --- a/src/gui/Src/Gui/AttachDialog.h +++ b/src/gui/Src/Gui/AttachDialog.h @@ -3,7 +3,7 @@ #include -class StdSearchListView; +class StdIconSearchListView; class QMenu; class QAction; @@ -28,7 +28,7 @@ private slots: private: Ui::AttachDialog* ui; - StdSearchListView* mSearchListView; + StdIconSearchListView* mSearchListView; QAction* mAttachAction; QAction* mRefreshAction; diff --git a/src/gui/x64dbg.pro b/src/gui/x64dbg.pro index 689b1603..ff1ee59b 100644 --- a/src/gui/x64dbg.pro +++ b/src/gui/x64dbg.pro @@ -74,6 +74,8 @@ RESOURCES += \ resource.qrc SOURCES += \ + Src/BasicView/StdIconSearchListView.cpp \ + Src/BasicView/StdIconTable.cpp \ Src/Gui/CPURegistersView.cpp \ Src/Gui/SystemBreakpointScriptDialog.cpp \ Src/Imports.cpp \ @@ -193,6 +195,8 @@ SOURCES += \ HEADERS += \ + Src/BasicView/StdIconSearchListView.h \ + Src/BasicView/StdIconTable.h \ Src/Gui/CPURegistersView.h \ Src/Gui/SystemBreakpointScriptDialog.h \ Src/Tracer/TraceRegisters.h \