Skip to content
Permalink
Browse files

UI fixes

  • Loading branch information...
Dax89 committed May 9, 2019
1 parent 044bb7c commit 899628983b74801959a330ef65b4746fe6b7dd42
@@ -135,6 +135,12 @@ bool DisassemblerActions::followUnderCursor()
return true;
}

void DisassemblerActions::setEnabled(bool b)
{
for(QAction* a : m_actions)
a->setEnabled(a);
}

void DisassemblerActions::showCallGraph()
{
const REDasm::Symbol* symbol = m_renderer->symbolUnderCursor();
@@ -20,6 +20,7 @@ class DisassemblerActions : public QObject

public slots:
bool followUnderCursor();
void setEnabled(bool b);
void popup(const QPoint& pos);
void copy();

@@ -27,7 +27,6 @@ int main(int argc, char *argv[])
REDasmSettings::setDefaultFormat(REDasmSettings::IniFormat);
ThemeProvider::applyTheme();
MainWindow w;

w.show();
return a.exec();
}
@@ -14,6 +14,7 @@
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->toolBar->actions()[3]->setVisible(false); // Hide separator
this->tabifyDockWidget(ui->dockFunctions, ui->dockCallTree);

REDasm::ContextSettings ctxsettings;
@@ -58,7 +59,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(ui->action_Open, &QAction::triggered, this, &MainWindow::onOpenClicked);
connect(ui->action_Save, &QAction::triggered, this, &MainWindow::onSaveClicked);
connect(ui->action_Save_As, &QAction::triggered, this, &MainWindow::onSaveAsClicked);
connect(ui->action_Close, &QAction::triggered, this, &MainWindow::onCloseClicked);
connect(ui->action_Close, &QAction::triggered, this, &MainWindow::closeFile);
connect(ui->action_Exit, &QAction::triggered, this, &MainWindow::onExitClicked);
connect(ui->action_Signatures, &QAction::triggered, this, &MainWindow::onSignaturesClicked);
connect(ui->action_Reset_Layout, &QAction::triggered, this, &MainWindow::onResetLayoutClicked);
@@ -88,6 +89,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
return;
}

this->closeFile(); // Deallocate actions and docks
QWidget::closeEvent(e);
}

@@ -191,12 +193,6 @@ void MainWindow::onSaveAsClicked() // TODO: Handle multiple outputs
REDasm::log(REDasm::Database::lastError());
}

void MainWindow::onCloseClicked()
{
this->closeFile();
ui->action_Close->setEnabled(false);
}

void MainWindow::onRecentFileClicked()
{
QAction* sender = qobject_cast<QAction*>(this->sender());
@@ -343,6 +339,13 @@ void MainWindow::checkCommandLine()
}
}

void MainWindow::setStandardActionsEnabled(bool b)
{
ui->action_Save->setEnabled(b);
ui->action_Save_As->setEnabled(b);
ui->action_Signatures->setEnabled(b);
}

void MainWindow::showDisassemblerView(REDasm::Disassembler *disassembler, bool fromdatabase)
{
EVENT_CONNECT(disassembler, busyChanged, this, [&]() {
@@ -397,18 +400,21 @@ void MainWindow::closeFile()
disassembler->stop();
}

QWidget* oldwidget = ui->stackView->currentWidget();
DisassemblerView* oldview = this->currentDisassemblerView();

if(oldwidget != nullptr)
if(oldview != nullptr)
{
ui->stackView->removeWidget(oldwidget);
oldwidget->deleteLater();
oldview->hideActions();
ui->stackView->removeWidget(oldview);
oldview->deleteLater();
}

ui->action_Close->setEnabled(false);
ui->pteOutput->clear();
m_lblstatus->clear();
m_lblprogress->setVisible(false);
m_pbstatus->setVisible(false);
this->setStandardActionsEnabled(false);
this->setViewWidgetsVisible(false);
}

@@ -501,9 +507,7 @@ void MainWindow::checkDisassemblerStatus()
m_pbstatus->setVisible(true);
m_lblprogress->setVisible(disassembler->busy());

ui->action_Save->setEnabled(!disassembler->busy());
ui->action_Save_As->setEnabled(!disassembler->busy());
ui->action_Signatures->setEnabled(!disassembler->busy());
this->setStandardActionsEnabled(!disassembler->busy());
ui->action_Close->setEnabled(true);
}

@@ -33,7 +33,6 @@ class MainWindow : public QMainWindow
void onOpenClicked();
void onSaveClicked();
void onSaveAsClicked();
void onCloseClicked();
void onRecentFileClicked();
void onExitClicked();
void onSignaturesClicked();
@@ -42,6 +41,7 @@ class MainWindow : public QMainWindow
void onAboutClicked();
void changeDisassemblerStatus();
void checkDisassemblerStatus();
void closeFile();

private:
DisassemblerView* currentDisassemblerView() const;
@@ -51,11 +51,11 @@ class MainWindow : public QMainWindow
bool loadDatabase(const QString& filepath);
void load(const QString &filepath);
void checkCommandLine();
void setStandardActionsEnabled(bool b);
void showDisassemblerView(REDasm::Disassembler *disassembler, bool fromdatabase);
void selectLoader(REDasm::LoadRequest &request);
void setViewWidgetsVisible(bool b);
void configureWebEngine();
void closeFile();
bool canClose();

private:
@@ -146,6 +146,11 @@
<addaction name="action_Open"/>
<addaction name="action_Save"/>
<addaction name="action_Signatures"/>
<addaction name="separator"/>
<addaction name="action_Back"/>
<addaction name="action_Forward"/>
<addaction name="action_Goto"/>
<addaction name="action_Graph"/>
</widget>
<widget class="QDockWidget" name="dockOutput">
<property name="sizePolicy">
@@ -216,7 +221,7 @@
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_2"/>
<widget class="ListingMap" name="listingMap"/>
</widget>
<widget class="QDockWidget" name="dockFunctions">
<property name="features">
@@ -467,6 +472,38 @@
<string>&amp;Subscribe to /r/REDasm</string>
</property>
</action>
<action name="action_Back">
<property name="text">
<string>&amp;Back</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="action_Forward">
<property name="text">
<string>&amp;Forward</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="action_Goto">
<property name="text">
<string>&amp;Goto</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="action_Graph">
<property name="text">
<string>&amp;Graph</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
@@ -475,6 +512,12 @@
<extends>QPlainTextEdit</extends>
<header>widgets/outputwidget.h</header>
</customwidget>
<customwidget>
<class>ListingMap</class>
<extends>QWidget</extends>
<header>widgets/listingmap.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
@@ -46,6 +46,10 @@ void CallTreeModel::populate(REDasm::ListingItem* parentitem)
return;

REDasm::ListingItems calls = m_disassembler->getCalls(parentitem->address);

if(calls.empty())
return;

QModelIndex index;

if(parentitem != m_root)
@@ -161,6 +161,12 @@ void DisassemblerView::bindDisassembler(REDasm::DisassemblerAPI *disassembler, b
m_disassembler->disassemble();
}

void DisassemblerView::hideActions()
{
if(m_actions)
m_actions->hideActions();
}

void DisassemblerView::changeDisassemblerStatus()
{
if(m_disassembler->state() == REDasm::Job::ActiveState)
@@ -28,6 +28,7 @@ class DisassemblerView : public QWidget
virtual ~DisassemblerView();
REDasm::DisassemblerAPI *disassembler();
void bindDisassembler(REDasm::DisassemblerAPI *disassembler, bool fromdatabase);
void hideActions();
void toggleFilter();
void showFilter();
void clearFilter();
@@ -74,7 +75,6 @@ class DisassemblerView : public QWidget
QLineEdit* m_lefilter;
ListingFilterModel *m_segmentsmodel, *m_importsmodel, *m_exportsmodel, *m_stringsmodel;
QAction* m_actsetfilter;
QActionGroup* m_viewactions;
};

#endif // DISASSEMBLERVIEW_H
@@ -12,7 +12,7 @@ DisassemblerViewActions::DisassemblerViewActions(QObject *parent) : QObject(pare
break;
}

this->addActions();
this->initActions();
}

void DisassemblerViewActions::setIcon(int actionid, const QIcon &icon)
@@ -40,40 +40,39 @@ void DisassemblerViewActions::setVisible(int actionid, bool b)
m_actions[actionid]->setVisible(b);
}

DisassemblerViewActions::~DisassemblerViewActions() { this->removeActions(); }
void DisassemblerViewActions::addSeparator() { m_separators.push_back(m_toolbar->addSeparator()); }

void DisassemblerViewActions::addActions()
void DisassemblerViewActions::findActions(const std::function<void(QAction*)>& cb)
{
if(!m_toolbar)
return;

this->addSeparator();

m_actions[DisassemblerViewActions::BackAction] = m_toolbar->addAction(THEME_ICON("back"), QString(),
this, &DisassemblerViewActions::backRequested);

m_actions[DisassemblerViewActions::ForwardAction] = m_toolbar->addAction(THEME_ICON("forward"), QString(),
this, &DisassemblerViewActions::forwardRequested);
QList<QAction*> actions = m_toolbar->actions();
auto it = std::find_if(actions.begin(), actions.end(), [](QAction* a) -> bool { return a->isSeparator(); });

m_actions[DisassemblerViewActions::GotoAction] = m_toolbar->addAction(THEME_ICON("goto"), QString(),
this, &DisassemblerViewActions::gotoRequested);
for(; it != actions.end(); it++)
cb(*it);
}

m_actions[DisassemblerViewActions::GraphListingAction] = m_toolbar->addAction(THEME_ICON("graph"), QString(),
this, &DisassemblerViewActions::graphListingRequested);
void DisassemblerViewActions::initActions()
{
this->findActions([&](QAction* a) {
if(a->isSeparator())
m_separators.push_back(a);
else if(a->objectName().endsWith("Back"))
this->showAction(DisassemblerViewActions::BackAction, a, THEME_ICON("back"), &DisassemblerViewActions::backRequested);
else if(a->objectName().endsWith("Forward"))
this->showAction(DisassemblerViewActions::ForwardAction, a, THEME_ICON("forward"), &DisassemblerViewActions::forwardRequested);
else if(a->objectName().endsWith("Goto"))
this->showAction(DisassemblerViewActions::GotoAction, a, THEME_ICON("goto"), &DisassemblerViewActions::forwardRequested);
else if(a->objectName().endsWith("Graph"))
this->showAction(DisassemblerViewActions::GraphListingAction, a, THEME_ICON("graph"), &DisassemblerViewActions::graphListingRequested);
});
}

void DisassemblerViewActions::removeActions()
void DisassemblerViewActions::hideActions()
{
for(auto it = m_actions.begin(); it != m_actions.end(); )
{
m_toolbar->removeAction(it.value());
it = m_actions.erase(it);
}
for(auto it = m_actions.begin(); it != m_actions.end(); it++)
(*it)->setVisible(false);

while(!m_separators.empty())
{
m_toolbar->removeAction(m_separators.front());
m_separators.pop_front();
}
for(auto it = m_separators.begin(); it != m_separators.end(); it++)
(*it)->setVisible(false);
}
@@ -14,15 +14,15 @@ class DisassemblerViewActions : public QObject

public:
explicit DisassemblerViewActions(QObject *parent = nullptr);
virtual ~DisassemblerViewActions();
void setIcon(int actionid, const QIcon& icon);
void setEnabled(int actionid, bool b);
void setVisible(int actionid, bool b);
void hideActions();

private:
void addSeparator();
void addActions();
void removeActions();
template<typename Func> void showAction(int type, QAction* action, const QIcon& icon, const Func& slot);
void findActions(const std::function<void(QAction*)>& cb);
void initActions();

signals:
void backRequested();
@@ -36,4 +36,11 @@ class DisassemblerViewActions : public QObject
QLinkedList<QAction*> m_separators;
};

template<typename Func> void DisassemblerViewActions::showAction(int type, QAction* action, const QIcon& icon, const Func& slot) {
m_actions[type] = action;
action->setIcon(icon);
action->setVisible(true);
connect(action, &QAction::triggered, this, slot);
}

#endif // DISASSEMBLERVIEWACTIONS_H
@@ -15,12 +15,6 @@ DisassemblerViewDocks::DisassemblerViewDocks(QObject *parent) : QObject(parent),
this->createListingMap();
}

DisassemblerViewDocks::~DisassemblerViewDocks()
{
if(m_listingmap)
m_listingmap->deleteLater();
}

void DisassemblerViewDocks::setDisassembler(const REDasm::DisassemblerPtr& disassembler)
{
m_disassembler = disassembler;
@@ -148,6 +142,5 @@ void DisassemblerViewDocks::createListingMap()
return;
}

m_listingmap = new ListingMap();
m_docklistingmap->setWidget(m_listingmap);
m_listingmap = static_cast<ListingMap*>(m_docklistingmap->widget());
}
@@ -18,7 +18,6 @@ class DisassemblerViewDocks : public QObject

public:
explicit DisassemblerViewDocks(QObject *parent = nullptr);
virtual ~DisassemblerViewDocks();
void setDisassembler(const REDasm::DisassemblerPtr &disassembler);

public:
Oops, something went wrong.

0 comments on commit 8996289

Please sign in to comment.
You can’t perform that action at this time.