Fixed #129. Refactorized the sections dock

This commit is contained in:
Hugo Teso 2017-04-12 12:16:43 +02:00
parent a1a663ca4b
commit 3d85370ff9
9 changed files with 171 additions and 104 deletions

View File

@ -61,7 +61,8 @@ SOURCES += \
widgets/omnibar.cpp \
widgets/dashboard.cpp \
dialogs/xrefsdialog.cpp \
hexhighlighter.cpp
hexhighlighter.cpp \
widgets/sectionsdock.cpp
HEADERS += \
mainwindow.h \
@ -97,7 +98,8 @@ HEADERS += \
widgets/dashboard.h \
dialogs/xrefsdialog.h \
widgets/banned.h \
hexhighlighter.h
hexhighlighter.h \
widgets/sectionsdock.h
FORMS += \
mainwindow.ui \
@ -119,7 +121,8 @@ FORMS += \
dialogs/commentsdialog.ui \
widgets/sidebar.ui \
widgets/dashboard.ui \
dialogs/xrefsdialog.ui
dialogs/xrefsdialog.ui \
widgets/sectionsdock.ui
RESOURCES += \
resources.qrc

View File

@ -139,16 +139,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) :
// this->add_debug_output( QString::number(this->dockList.length()) );
// Add Sections dock panel
this->sectionsWidget = new SectionsWidget(this);
this->sectionsDock = new QDockWidget("Sections");
this->sectionsDock->setObjectName("sectionsDock");
this->sectionsDock->setAllowedAreas(Qt::AllDockWidgetAreas);
this->sectionsDock->setWidget(this->sectionsWidget);
this->sectionsWidget->setContentsMargins(0, 0, 0, 5);
this->sectionsDock->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
this->sectionsDock->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this->sectionsDock, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showSectionsContextMenu(const QPoint &)));
this->sectionsDock = new SectionsDock(this);
// Add functions DockWidget
this->functionsDock = new FunctionsWidget(this);
@ -579,7 +570,7 @@ void MainWindow::updateFrames()
// TODO: FIXME: Remove the check for first_time;
if (first_time)
{
sectionsWidget->tree->clear();
this->sectionsDock->sectionsWidget->tree->clear();
int row = 0;
for (auto i : core->getList("bin", "sections"))
{
@ -594,7 +585,7 @@ void MainWindow::updateFrames()
QString addr_end = "0x0" + core->itoa(core->math(a[1] + "+" + a[2]));
QString size = QString::number(core->math(a[2]));
QString name = a[4];
this->sectionsWidget->fillSections(row, name, size, addr, addr_end);
this->sectionsDock->sectionsWidget->fillSections(row, name, size, addr, addr_end);
// Used to select a color for the sections graph
if (row == 10)
@ -609,7 +600,7 @@ void MainWindow::updateFrames()
}
}
//adjustColumns(sectionsWidget->tree);
sectionsWidget->adjustColumns();
this->sectionsDock->sectionsWidget->adjustColumns();
first_time = false;
@ -1159,40 +1150,6 @@ void MainWindow::on_actionDashboard_triggered()
}
}
void MainWindow::showSectionsContextMenu(const QPoint &pt)
{
// Set functions popup menu
QMenu *menu = new QMenu(this->sectionsDock);
menu->clear();
menu->addAction(ui->actionSectionsHorizontal);
menu->addAction(ui->actionSectionsVertical);
if (this->sectionsWidget->orientation() == 1)
{
ui->actionSectionsHorizontal->setChecked(true);
ui->actionSectionsVertical->setChecked(false);
}
else
{
ui->actionSectionsVertical->setChecked(true);
ui->actionSectionsHorizontal->setChecked(false);
}
this->sectionsDock->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(this->sectionsDock->mapToGlobal(pt));
delete menu;
}
void MainWindow::on_actionSectionsHorizontal_triggered()
{
this->sectionsWidget->setOrientation(Qt::Horizontal);
}
void MainWindow::on_actionSectionsVertical_triggered()
{
this->sectionsWidget->setOrientation(Qt::Vertical);
}
void MainWindow::on_actionForward_triggered()
{
this->core->cmd("s+");

View File

@ -22,6 +22,7 @@
#include "widgets/importswidget.h"
#include "widgets/symbolswidget.h"
#include "widgets/stringswidget.h"
#include "widgets/sectionsdock.h"
#include "widgets/relocswidget.h"
#include "widgets/flagswidget.h"
#include "widgets/codegraphic.h"
@ -51,7 +52,6 @@ public:
QDockWidget *calcDock;
Omnibar *omnibar;
MemoryWidget *memoryDock;
QDockWidget *sectionsDock;
Notepad *notepadDock;
SideBar *sideBar;
@ -121,10 +121,6 @@ public slots:
void on_actionRun_Script_triggered();
void on_actionSectionsHorizontal_triggered();
void on_actionSectionsVertical_triggered();
void toggleResponsive(bool maybe);
void on_backButton_clicked();
@ -183,8 +179,6 @@ private slots:
void on_actionShow_Hide_mainsidebar_triggered();
void showSectionsContextMenu(const QPoint &pt);
void on_actionForward_triggered();
void on_actionTabs_on_Top_triggered();
@ -210,7 +204,6 @@ private:
Highlighter *highlighter_5;
AsciiHighlighter *hex_highlighter;
GraphicsBar *graphicsBar;
SectionsWidget *sectionsWidget;
FunctionsWidget *functionsDock;
ImportsWidget *importsDock;
SymbolsWidget *symbolsDock;
@ -222,6 +215,7 @@ private:
QLineEdit *gotoEntry;
SdbDock *sdbDock;
QAction *sidebar_action;
SectionsDock *sectionsDock;
WebServerThread webserverThread;
};

View File

@ -676,7 +676,7 @@ background: rgb(64, 64, 64);</string>
<string>Sections</string>
</property>
<property name="toolTip">
<string>Show/HIde Sections panel</string>
<string>Show/Hide Sections panel</string>
</property>
</action>
<action name="actionFunctions">
@ -1057,28 +1057,6 @@ background: rgb(64, 64, 64);</string>
<string>Show/HIde Dashboard panel</string>
</property>
</action>
<action name="actionSectionsVertical">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Vertical</string>
</property>
<property name="toolTip">
<string>Vertical view</string>
</property>
</action>
<action name="actionSectionsHorizontal">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Horizontal</string>
</property>
<property name="toolTip">
<string>Horizontal</string>
</property>
</action>
<action name="actionReset_settings">
<property name="text">
<string>Reset settings</string>

View File

@ -0,0 +1,79 @@
#include "sectionsdock.h"
#include "ui_sectionsdock.h"
#include "mainwindow.h"
#include "widgets/sectionswidget.h"
SectionsDock::SectionsDock(MainWindow *main, QWidget *parent) :
QDockWidget(parent),
ui(new Ui::SectionsDock)
{
ui->setupUi(this);
// Radare core found in:
this->main = main;
this->sectionsWidget = new SectionsWidget(this->main);
this->setWidget(this->sectionsWidget);
this->sectionsWidget->setContentsMargins(0, 0, 0, 5);
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showSectionsContextMenu(const QPoint &)));
}
SectionsDock::~SectionsDock()
{
delete ui;
}
void SectionsDock::showSectionsContextMenu(const QPoint &pt)
{
// Set functions popup menu
QMenu *menu = new QMenu(this);
menu->clear();
menu->addAction(ui->actionHorizontal);
menu->addAction(ui->actionVertical);
if (this->sectionsWidget->orientation() == 1)
{
ui->actionHorizontal->setChecked(true);
ui->actionVertical->setChecked(false);
}
else
{
ui->actionVertical->setChecked(true);
ui->actionHorizontal->setChecked(false);
}
this->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(this->mapToGlobal(pt));
delete menu;
}
void SectionsDock::resizeEvent(QResizeEvent *event)
{
if(main->responsive && isVisible())
{
if (event->size().width() >= event->size().height())
{
// Set horizontal view (list)
this->on_actionHorizontal_triggered();
}
else
{
// Set vertical view (Tree)
this->on_actionVertical_triggered();
}
}
QWidget::resizeEvent(event);
}
void SectionsDock::on_actionVertical_triggered()
{
this->sectionsWidget->setOrientation(Qt::Vertical);
}
void SectionsDock::on_actionHorizontal_triggered()
{
this->sectionsWidget->setOrientation(Qt::Horizontal);
}

View File

@ -0,0 +1,41 @@
#ifndef SECTIONSDOCK_H
#define SECTIONSDOCK_H
#include <QDockWidget>
#include "widgets/sectionswidget.h"
class MainWindow;
namespace Ui
{
class SectionsDock;
}
class SectionsDock : public QDockWidget
{
Q_OBJECT
public:
explicit SectionsDock(MainWindow *main, QWidget *parent = 0);
~SectionsDock();
SectionsWidget *sectionsWidget;
protected:
void resizeEvent(QResizeEvent *event) override;
private slots:
void showSectionsContextMenu(const QPoint &pt);
void on_actionVertical_triggered();
void on_actionHorizontal_triggered();
private:
Ui::SectionsDock *ui;
MainWindow *main;
};
#endif // SECTIONSDOCK_H

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SectionsDock</class>
<widget class="QDockWidget" name="SectionsDock">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Sections</string>
</property>
<widget class="QWidget" name="dockWidgetContents"/>
<action name="actionVertical">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Vertical</string>
</property>
</action>
<action name="actionHorizontal">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Horizontal</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -33,7 +33,7 @@ void SectionsWidget::setupViews()
{
// Table view
this->tree = new QTreeWidget;
this->tree->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
this->tree->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//this->tree->setFont(QFont("Lucida Grande UI", 12));
//this->tree->setFont(QFont("Courier New", 11));
this->tree->setIndentation(10);
@ -50,7 +50,7 @@ void SectionsWidget::setupViews()
pieChart = new PieView;
pieChart->setFrameShape(QFrame::NoFrame);
pieChart->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
pieChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->addWidget(this->tree);
this->addWidget(pieChart);
this->setStretchFactor(0, 4);
@ -97,21 +97,3 @@ void SectionsWidget::adjustColumns()
this->tree->resizeColumnToContents(i);
}
}
void SectionsWidget::resizeEvent(QResizeEvent *event)
{
if(main->responsive && isVisible())
{
if (event->size().width() >= event->size().height())
{
// Set horizontal view (list)
main->on_actionSectionsHorizontal_triggered();
}
else
{
// Set vertical view (Tree)
main->on_actionSectionsVertical_triggered();
}
}
QWidget::resizeEvent(event);
}

View File

@ -30,9 +30,6 @@ public:
void adjustColumns();
QTreeWidget *tree;
protected:
void resizeEvent(QResizeEvent *event) override;
private:
//void setupModel();
void setupViews();