Skip to content

Commit

Permalink
Merge pull request #151 from cristian64/bouquet_of_gui_fixes
Browse files Browse the repository at this point in the history
Bouquet of GUI fixes and improvements.
  • Loading branch information
dreamsyntax authored May 25, 2024
2 parents d934003 + 8b6b31a commit 0060c79
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 28 deletions.
5 changes: 1 addition & 4 deletions Source/GUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void MainWindow::makeLayouts()
void MainWindow::makeMemViewer()
{
m_viewer = new MemViewerWidget(nullptr);
m_viewer->setWindowIcon(windowIcon());
connect(m_viewer, &MemViewerWidget::mustUnhook, this, &MainWindow::onUnhook);
connect(m_viewer, &MemViewerWidget::addWatchRequested, m_watcher, &MemWatchWidget::addWatchEntry);
connect(m_watcher, &MemWatchWidget::goToAddressInViewer, this,
Expand Down Expand Up @@ -282,7 +283,6 @@ void MainWindow::updateDolphinHookingStatus()
tr("Hooked successfully to Dolphin, current start address: ") +
QString::number(DolphinComm::DolphinAccessor::getEmuRAMAddressStart(), 16).toUpper());
m_scanner->setEnabled(true);
m_watcher->setEnabled(true);
m_copier->setEnabled(true);
m_actMemoryViewer->setEnabled(true);
m_actCopyMemory->setEnabled(true);
Expand All @@ -294,7 +294,6 @@ void MainWindow::updateDolphinHookingStatus()
{
m_lblDolphinStatus->setText(tr("Cannot hook to Dolphin, the process is not running"));
m_scanner->setDisabled(true);
m_watcher->setDisabled(true);
m_copier->setDisabled(true);
m_actMemoryViewer->setDisabled(true);
m_actCopyMemory->setDisabled(true);
Expand All @@ -307,7 +306,6 @@ void MainWindow::updateDolphinHookingStatus()
m_lblDolphinStatus->setText(
tr("Cannot hook to Dolphin, the process is running, but no emulation has been started"));
m_scanner->setDisabled(true);
m_watcher->setDisabled(true);
m_copier->setDisabled(true);
m_actMemoryViewer->setDisabled(true);
m_actCopyMemory->setDisabled(true);
Expand All @@ -319,7 +317,6 @@ void MainWindow::updateDolphinHookingStatus()
{
m_lblDolphinStatus->setText(tr("Unhooked, press \"Hook\" to hook to Dolphin again"));
m_scanner->setDisabled(true);
m_watcher->setDisabled(true);
m_copier->setDisabled(true);
m_actMemoryViewer->setDisabled(true);
m_actCopyMemory->setDisabled(true);
Expand Down
21 changes: 18 additions & 3 deletions Source/GUI/MemScanner/MemScanWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MemScanWidget.h"

#include <QFontDatabase>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QMessageBox>
Expand Down Expand Up @@ -35,9 +36,17 @@ void MemScanWidget::initialiseWidgets()
m_tblResulstList->setSelectionMode(QAbstractItemView::ExtendedSelection);

m_tblResulstList->horizontalHeader()->setStretchLastSection(true);
m_tblResulstList->horizontalHeader()->resizeSection(ResultsListModel::RESULT_COL_ADDRESS, 125);
m_tblResulstList->horizontalHeader()->resizeSection(ResultsListModel::RESULT_COL_SCANNED, 150);

const int charWidth{m_tblResulstList->fontMetrics().averageCharWidth()};
m_tblResulstList->horizontalHeader()->setMinimumSectionSize(charWidth);
m_tblResulstList->horizontalHeader()->resizeSection(ResultsListModel::RESULT_COL_SCANNED,
charWidth * 15);

m_tblResulstList->horizontalHeader()->setSectionResizeMode(ResultsListModel::RESULT_COL_ADDRESS,
QHeaderView::ResizeToContents);

m_tblResulstList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_tblResulstList->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_tblResulstList->setSelectionBehavior(QAbstractItemView::SelectRows);
m_tblResulstList->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_tblResulstList->setMinimumWidth(385);
Expand Down Expand Up @@ -90,6 +99,12 @@ void MemScanWidget::initialiseWidgets()
m_txbSearchRange2->setPlaceholderText("Search End (Optional)");
m_txbSearchRange2->setToolTip("Search Range End (Optional)");

const QFont fixedFont{QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)};
m_txbSearchTerm1->setFont(fixedFont);
m_txbSearchTerm2->setFont(fixedFont);
m_txbSearchRange1->setFont(fixedFont);
m_txbSearchRange2->setFont(fixedFont);

m_searchTerm2Widget = new QWidget();

m_searchTerm2Widget->hide();
Expand Down Expand Up @@ -118,7 +133,7 @@ void MemScanWidget::initialiseWidgets()
m_btnGroupScanBase->addButton(m_rdbBaseBinary, 3);
m_rdbBaseDecimal->setChecked(true);

m_groupScanBase = new QGroupBox(tr("Base to use"));
m_groupScanBase = new QGroupBox({});

m_chkSignedScan = new QCheckBox(tr("Signed value scan"));
m_chkSignedScan->setChecked(false);
Expand Down
8 changes: 8 additions & 0 deletions Source/GUI/MemScanner/ResultsListModel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ResultsListModel.h"

#include <QFontDatabase>

ResultsListModel::ResultsListModel(QObject* parent, MemScanner* scanner)
: QAbstractTableModel(parent), m_scanner(scanner)
{
Expand Down Expand Up @@ -28,6 +30,12 @@ QVariant ResultsListModel::data(const QModelIndex& index, int role) const
if (!index.isValid())
return {};

if (role == Qt::FontRole)
{
static const QFont s_fixedFont{QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)};
return s_fixedFont;
}

if (role == Qt::DisplayRole)
{
switch (index.column())
Expand Down
5 changes: 5 additions & 0 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DlgAddWatchEntry.h"

#include <QDialogButtonBox>
#include <QFontDatabase>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QMessageBox>
Expand Down Expand Up @@ -44,6 +45,10 @@ void DlgAddWatchEntry::initialiseWidgets()
m_txbAddress->setMaxLength(10);
connect(m_txbAddress, &QLineEdit::textEdited, this, &DlgAddWatchEntry::onAddressChanged);

const QFont fixedFont{QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)};
m_txbAddress->setFont(fixedFont);
m_lblValuePreview->setFont(fixedFont);

m_offsetsLayout = new QGridLayout;

m_offsets = QVector<QLineEdit*>();
Expand Down
70 changes: 70 additions & 0 deletions Source/GUI/MemWatcher/MemWatchDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "MemWatchDelegate.h"

#include <QApplication>
#include <QFontDatabase>
#include <QLineEdit>
#include <QPainter>

#include "../../MemoryWatch/MemWatchTreeNode.h"
#include "../GUICommon.h"
Expand All @@ -14,7 +17,10 @@ QWidget* MemWatchDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
MemWatchTreeNode* const node{MemWatchModel::getTreeNodeFromIndex(index)};
QLineEdit* editor = new QLineEdit(parent);
if (index.column() == MemWatchModel::WATCH_COL_VALUE && !node->isGroup())
{
editor->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont));
node->setValueEditing(true);
}
GUICommon::g_valueEditing = true;
return editor;
}
Expand All @@ -35,3 +41,67 @@ void MemWatchDelegate::destroyEditor(QWidget* editor, const QModelIndex& index)
GUICommon::g_valueEditing = false;
editor->deleteLater();
}

void MemWatchDelegate::paint(QPainter* const painter, const QStyleOptionViewItem& option_,
const QModelIndex& index) const
{
QStyleOptionViewItem option = option_;
initStyleOption(&option, index);

const int column{index.column()};
if (column == MemWatchModel::WATCH_COL_LOCK)
{
MemWatchTreeNode* const node{MemWatchModel::getTreeNodeFromIndex(index)};
MemWatchEntry* const entry{node->getEntry()};
if (entry)
{
QStyleOptionButton checkboxstyle;
QRect checkbox_rect =
QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkboxstyle);
checkboxstyle.rect = option.rect;
checkboxstyle.rect.setLeft(option.rect.x() + option.rect.width() / 2 -
checkbox_rect.width() / 2);

const bool checked{entry->isLocked()};
checkboxstyle.state = checked ? QStyle::State_On : QStyle::State_Off;
const bool enabled{static_cast<bool>(option.state & QStyle::State_Enabled)};
if (enabled)
{
checkboxstyle.state |= QStyle::State_Enabled;
}
checkboxstyle.palette = option.palette;

QStyledItemDelegate::paint(painter, option, index);
QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxstyle, painter);
return;
}
}

QStyledItemDelegate::paint(painter, option, index);
}

bool MemWatchDelegate::editorEvent(QEvent* const event, QAbstractItemModel* const model,
const QStyleOptionViewItem& option, const QModelIndex& index)
{
const QEvent::Type eventType{event->type()};

const int column{index.column()};
if (column == MemWatchModel::WATCH_COL_LOCK)
{
if (eventType == QEvent::MouseButtonDblClick)
return true; // Consume event

if (eventType == QEvent::MouseButtonRelease)
{
MemWatchTreeNode* const node{MemWatchModel::getTreeNodeFromIndex(index)};
MemWatchEntry* const entry{node->getEntry()};
if (entry)
{
entry->setLock(!entry->isLocked());
return true;
}
}
}

return QStyledItemDelegate::editorEvent(event, model, option, index);
}
4 changes: 4 additions & 0 deletions Source/GUI/MemWatcher/MemWatchDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ class MemWatchDelegate : public QStyledItemDelegate
void setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index) const override;
void destroyEditor(QWidget* editor, const QModelIndex& index) const override;
void paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const override;
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
const QModelIndex& index) override;
};
40 changes: 26 additions & 14 deletions Source/GUI/MemWatcher/MemWatchModel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "MemWatchModel.h"

#include <QDataStream>
#include <QFontDatabase>
#include <QIcon>
#include <QMimeData>

Expand All @@ -11,6 +12,7 @@

#include "../../CheatEngineParser/CheatEngineParser.h"
#include "../../Common/CommonUtils.h"
#include "../../DolphinProcess/DolphinAccessor.h"
#include "../GUICommon.h"

namespace
Expand Down Expand Up @@ -279,10 +281,22 @@ QVariant MemWatchModel::data(const QModelIndex& index, int role) const
if (!index.isValid())
return {};

const int column{index.column()};

MemWatchTreeNode* item = static_cast<MemWatchTreeNode*>(index.internalPointer());

if (!item->isGroup())
{
if (role == Qt::FontRole)
{
if (column == WATCH_COL_ADDRESS || column == WATCH_COL_VALUE)
{
static const QFont s_fixedFont{
QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)};
return s_fixedFont;
}
}

if (role == Qt::EditRole && index.column() == WATCH_COL_TYPE)
return {static_cast<int>(item->getEntry()->getType())};

Expand Down Expand Up @@ -313,12 +327,6 @@ QVariant MemWatchModel::data(const QModelIndex& index, int role) const
break;
}
}
else if (role == Qt::CheckStateRole && index.column() == WATCH_COL_LOCK)
{
if (entry->isLocked())
return Qt::Checked;
return Qt::Unchecked;
}
}
else
{
Expand Down Expand Up @@ -382,12 +390,6 @@ bool MemWatchModel::editData(const QModelIndex& index, const QVariant& value, co
}
}
}
else if (role == Qt::CheckStateRole && index.column() == WATCH_COL_LOCK)
{
value == Qt::Checked ? entry->setLock(true) : entry->setLock(false);
emit dataChanged(index, index);
return true;
}
else
{
return false;
Expand Down Expand Up @@ -421,10 +423,20 @@ Qt::ItemFlags MemWatchModel::flags(const QModelIndex& index) const
}

if (index.column() == WATCH_COL_LOCK)
return flags |= Qt::ItemIsUserCheckable;
return flags;

if (index.column() != WATCH_COL_ADDRESS && index.column() != WATCH_COL_TYPE)
if (index.column() == WATCH_COL_LABEL)
{
flags |= Qt::ItemIsEditable;
}
else if (index.column() == WATCH_COL_VALUE)
{
const bool hooked{DolphinComm::DolphinAccessor::getStatus() ==
DolphinComm::DolphinAccessor::DolphinStatus::hooked};
const Qt::ItemFlag itemIsEditable{hooked ? Qt::ItemIsEditable : Qt::NoItemFlags};
flags |= itemIsEditable;
}

return flags;
}

Expand Down
19 changes: 14 additions & 5 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void MemWatchWidget::initialiseWidgets()
m_watchView->setAcceptDrops(true);
m_watchView->setDragDropMode(QAbstractItemView::InternalMove);
m_watchView->setDropIndicatorShown(true);
m_watchView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_watchView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_watchView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_watchView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_watchView->setContextMenuPolicy(Qt::CustomContextMenu);
Expand All @@ -66,10 +68,16 @@ void MemWatchWidget::initialiseWidgets()
m_watchView->setItemDelegate(m_watchDelegate);
m_watchView->setModel(m_watchModel);

m_watchView->header()->resizeSection(MemWatchModel::WATCH_COL_LOCK, 50);
m_watchView->header()->resizeSection(MemWatchModel::WATCH_COL_LABEL, 225);
m_watchView->header()->resizeSection(MemWatchModel::WATCH_COL_TYPE, 130);
m_watchView->header()->resizeSection(MemWatchModel::WATCH_COL_ADDRESS, 120);
const int charWidth{m_watchView->fontMetrics().averageCharWidth()};
m_watchView->header()->setMinimumSectionSize(charWidth);
m_watchView->header()->resizeSection(MemWatchModel::WATCH_COL_LABEL, charWidth * 35);

m_watchView->header()->setSectionResizeMode(MemWatchModel::WATCH_COL_TYPE,
QHeaderView::ResizeToContents);
m_watchView->header()->setSectionResizeMode(MemWatchModel::WATCH_COL_ADDRESS,
QHeaderView::ResizeToContents);
m_watchView->header()->setSectionResizeMode(MemWatchModel::WATCH_COL_LOCK,
QHeaderView::ResizeToContents);

QShortcut* deleteWatchShortcut = new QShortcut(QKeySequence::Delete, m_watchView);
connect(deleteWatchShortcut, &QShortcut::activated, this, &MemWatchWidget::onDeleteSelection);
Expand Down Expand Up @@ -624,7 +632,8 @@ void MemWatchWidget::onRowsInserted(const QModelIndex& parent, const int first,
{
const QModelIndex firstIndex{m_watchModel->index(first, 0, parent)};
const QModelIndex lastIndex{m_watchModel->index(last, 0, parent)};
const QItemSelection selection{firstIndex, lastIndex};
const QItemSelection selection{firstIndex,
lastIndex.siblingAtColumn(MemWatchModel::WATCH_COL_NUM - 1)};

QItemSelectionModel* const selectionModel{m_watchView->selectionModel()};
selectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
Expand Down
4 changes: 2 additions & 2 deletions Source/GUI/Settings/SConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <cassert>
#include <iostream>

#include <qcoreapplication.h>
#include <QDir>
#include <qfile.h>
#include <QFileInfo>
#include <qcoreapplication.h>
#include <qfile.h>

namespace
{
Expand Down

0 comments on commit 0060c79

Please sign in to comment.