Skip to content

Commit

Permalink
Hot-update the font size after changing the view font size. Fix Vecto…
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Feb 3, 2023
1 parent ec187c1 commit 8cfe189
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 90 deletions.
73 changes: 19 additions & 54 deletions ui/breakpointswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ QVariant DebugBreakpointsListModel::data(const QModelIndex& index, int role) con
if (!item)
return QVariant();

if (role != Qt::DisplayRole)
if ((role != Qt::DisplayRole) && (role != Qt::SizeHintRole))
return QVariant();

switch (index.column())
Expand All @@ -118,11 +118,18 @@ QVariant DebugBreakpointsListModel::data(const QModelIndex& index, int role) con
auto fileName = fileInfo.fileName();
text = QString::fromStdString(fmt::format("{} + 0x{:x}", fileName.toStdString(), item->location().offset));
}

if (role == Qt::SizeHintRole)
return QVariant((qulonglong)text.size());

return QVariant(text);
}
case DebugBreakpointsListModel::AddressColumn:
{
QString text = QString::fromStdString(fmt::format("0x{:x}", item->address()));
if (role == Qt::SizeHintRole)
return QVariant((qulonglong)text.size());

return QVariant(text);
}
}
Expand Down Expand Up @@ -212,6 +219,13 @@ void DebugBreakpointsItemDelegate::updateFonts()
}


QSize DebugBreakpointsItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& idx) const
{
auto totalWidth = (idx.data(Qt::SizeHintRole).toInt() + 2) * m_charWidth + 4;
return QSize(totalWidth, m_charHeight + 2);
}


DebugBreakpointsWidget::DebugBreakpointsWidget(ViewFrame* view, BinaryViewRef data, Menu* menu) : m_view(view)
{
m_controller = DebuggerController::GetController(data);
Expand Down Expand Up @@ -283,10 +297,10 @@ void DebugBreakpointsWidget::onDoubleClicked()
}


//void DebugBreakpointsWidget::notifyFontChanged()
//{
// m_delegate->updateFonts();
//}
void DebugBreakpointsWidget::updateFonts()
{
m_delegate->updateFonts();
}


void DebugBreakpointsWidget::contextMenuEvent(QContextMenuEvent* event)
Expand Down Expand Up @@ -395,52 +409,3 @@ void DebugBreakpointsWidget::updateContent()

m_model->updateRows(bps);
}


BreakpointSideBarWidget::BreakpointSideBarWidget(const QString& name, ViewFrame* view, BinaryViewRef data) :
SidebarWidget(name), m_view(view)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setAlignment(Qt::AlignTop);

m_breakpointsWidget = new DebugBreakpointsWidget(m_view, data, m_menu);

layout->addWidget(m_breakpointsWidget);
setLayout(layout);

m_ui = DebuggerUI::GetForViewFrame(view);
connect(m_ui, &DebuggerUI::debuggerEvent, this, &BreakpointSideBarWidget::uiEventHandler);
}


BreakpointSideBarWidget::~BreakpointSideBarWidget() {}


void BreakpointSideBarWidget::uiEventHandler(const DebuggerEvent& event)
{
switch (event.type)
{
case TargetStoppedEventType:
case DetachedEventType:
case QuitDebuggingEventType:
case BackEndDisconnectedEventType:
case RelativeBreakpointAddedEvent:
case AbsoluteBreakpointAddedEvent:
case RelativeBreakpointRemovedEvent:
case AbsoluteBreakpointRemovedEvent:
updateContent();
default:
break;
}
}


void BreakpointSideBarWidget::updateContent()
{
m_breakpointsWidget->updateContent();
}


void BreakpointSideBarWidget::notifyFontChanged() {}
35 changes: 2 additions & 33 deletions ui/breakpointswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class DebugBreakpointsItemDelegate : public QStyledItemDelegate
DebugBreakpointsItemDelegate(QWidget* parent);
void updateFonts();
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& idx) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& idx) const;
};


Expand Down Expand Up @@ -139,6 +140,7 @@ class DebugBreakpointsWidget : public QWidget
~DebugBreakpointsWidget();

void uiEventHandler(const DebuggerEvent& event);
void updateFonts();

private slots:
void jump();
Expand All @@ -152,36 +154,3 @@ public slots:


class DebuggerUI;
class BreakpointSideBarWidget : public SidebarWidget
{
Q_OBJECT;

ViewFrame* m_view;

DebugBreakpointsWidget* m_breakpointsWidget;

DebuggerUI* m_ui;

virtual void notifyFontChanged() override;

private slots:
void uiEventHandler(const DebuggerEvent& event);

public:
BreakpointSideBarWidget(const QString& name, ViewFrame* view, BinaryViewRef data);
~BreakpointSideBarWidget();

void updateContent();
};


// class BreakpointWidgetType : public SidebarWidgetType {
// public:
// BreakpointWidgetType(const QImage& icon, const QString& name) : SidebarWidgetType(icon, name) { }
//
// bool isInReferenceArea() const override { return false; }
//
// SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override {
// return new BreakpointSideBarWidget("Breakpoint", frame, data);
// }
// };
3 changes: 2 additions & 1 deletion ui/debuggerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ DebuggerWidget::~DebuggerWidget() {}

void DebuggerWidget::notifyFontChanged()
{
LogWarn("font changed");
m_registersWidget->updateFonts();
m_breakpointsWidget->updateFonts();
}


Expand Down
22 changes: 22 additions & 0 deletions ui/moduleswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ void DebugModulesWidget::setFilter(const string& filter)
}


void DebugModulesWidget::updateFonts()
{
m_delegate->updateFonts();
}


void DebugModulesWidget::scrollToFirstItem() {}


Expand Down Expand Up @@ -597,6 +603,12 @@ DebugModulesWithFilter::DebugModulesWithFilter(ViewFrame* view, BinaryViewRef da
}


void DebugModulesWithFilter::updateFonts()
{
m_modules->updateFonts();
}


GlobalDebugModulesContainer::GlobalDebugModulesContainer(const QString& title) :
GlobalAreaWidget(title), m_currentFrame(nullptr), m_consoleStack(new QStackedWidget)
{
Expand Down Expand Up @@ -684,6 +696,16 @@ void GlobalDebugModulesContainer::notifyViewChanged(ViewFrame* frame)
}


void GlobalDebugModulesContainer::notifyFontChanged()
{
for (auto it = m_widgetMap.begin(); it != m_widgetMap.end(); it++)
{
if (it.value())
it.value()->updateFonts();
}
}


DebugModulesFilterProxyModel::DebugModulesFilterProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
Expand Down
4 changes: 3 additions & 1 deletion ui/moduleswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class DebugModulesWidget : public QWidget, public FilterTarget

void updateColumnWidths();
void notifyModulesChanged(std::vector<DebugModule> modules);
void updateFonts();

private slots:
void jumpToStart();
Expand All @@ -191,7 +192,7 @@ class DebugModulesWithFilter : public QWidget

public:
DebugModulesWithFilter(ViewFrame* view, BinaryViewRef data);
void updateContent();
void updateFonts();
};


Expand All @@ -213,4 +214,5 @@ class GlobalDebugModulesContainer : public GlobalAreaWidget
GlobalDebugModulesContainer(const QString& title);

void notifyViewChanged(ViewFrame*) override;
void notifyFontChanged() override;
};
13 changes: 13 additions & 0 deletions ui/registerswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ void DebugRegistersWidget::updateContent()
}


void DebugRegistersWidget::updateFonts()
{
m_delegate->updateFonts();
}


void DebugRegistersWidget::setToZero()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
Expand Down Expand Up @@ -725,6 +731,13 @@ void DebugRegistersContainer::updateContent()
m_register->updateContent();
}


void DebugRegistersContainer::updateFonts()
{
m_register->updateFonts();
}


// TODO: Group this with other settings key constants if more pop up.
constexpr auto HideUnusedRegistersKey = "ui/debugger/registers/hideUnused";

Expand Down
2 changes: 2 additions & 0 deletions ui/registerswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class DebugRegistersWidget : public QWidget, public FilterTarget
public:
DebugRegistersWidget(ViewFrame* view, BinaryViewRef data, Menu* menu);
void notifyRegistersChanged(std::vector<DebugRegister> regs);
void updateFonts();

private slots:
void setToZero();
Expand Down Expand Up @@ -212,4 +213,5 @@ class DebugRegistersContainer : public QWidget
public:
DebugRegistersContainer(ViewFrame* view, BinaryViewRef data, Menu* menu);
void updateContent();
void updateFonts();
};
15 changes: 15 additions & 0 deletions ui/threadframes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ void ThreadFramesWidget::makeItSoloThread()
m_debugger->SetActiveThread(soloTid);
}

void ThreadFramesWidget::updateFonts()
{
m_delegate->updateFonts();
}

void ThreadFramesWidget::resumeThread()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
Expand Down Expand Up @@ -834,3 +839,13 @@ void GlobalThreadFramesContainer::notifyViewChanged(ViewFrame* frame)

m_consoleStack->setCurrentWidget(currentConsole);
}


void GlobalThreadFramesContainer::notifyFontChanged()
{
for (auto it = m_consoleMap.begin(); it != m_consoleMap.end(); it++)
{
if (it.value())
it.value()->updateFonts();
}
}
3 changes: 2 additions & 1 deletion ui/threadframes.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public slots:
ThreadFramesWidget(QWidget* parent, ViewFrame* view, BinaryViewRef debugger);
~ThreadFramesWidget();

void notifyFontChanged();
void updateFonts();

private slots:
void onDoubleClicked();
Expand Down Expand Up @@ -207,4 +207,5 @@ class GlobalThreadFramesContainer : public GlobalAreaWidget
void sendText(const QString& msg) const;

void notifyViewChanged(ViewFrame*) override;
void notifyFontChanged() override;
};

0 comments on commit 8cfe189

Please sign in to comment.