diff --git a/src/AnalThread.cpp b/src/AnalThread.cpp index 5ec51b81..03dff64d 100644 --- a/src/AnalThread.cpp +++ b/src/AnalThread.cpp @@ -34,7 +34,7 @@ void AnalThread::start(MainWindow *main, int level, QList advanced) void AnalThread::run() { const auto optionsDialog = dynamic_cast(parent()); - const auto& ui = optionsDialog->ui; + const auto &ui = optionsDialog->ui; int va = ui->vaCheckBox->isChecked(); ut64 loadaddr = 0LL; ut64 mapaddr = 0LL; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 90d59161..b0339df3 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -257,9 +257,7 @@ void MainWindow::initUI() dockWidgets.push_back(dashboardDock); // Set up dock widgets default layout - restoreDocks(); - hideAllDocks(); - showDefaultDocks(); + resetToDefaultLayout(); // Restore saved settings this->readSettings(); @@ -339,10 +337,10 @@ void MainWindow::finalizeOpen() core->cmd("fs sections"); updateFrames(); - if(core->getNotes().isEmpty()) + if (core->getNotes().isEmpty()) { core->setNotes(tr("# Binary information\n\n") + core->cmd("i") + - "\n" + core->cmd("ie") + "\n" + core->cmd("iM") + "\n"); + "\n" + core->cmd("ie") + "\n" + core->cmd("iM") + "\n"); } //Get binary beginning/end addresses @@ -374,8 +372,8 @@ bool MainWindow::saveProject(bool quit) bool MainWindow::saveProjectAs(bool quit) { - SaveProjectDialog dialog(quit, this); - int result = dialog.exec(); + SaveProjectDialog dialog(quit, this); + int result = dialog.exec(); return !quit || result != SaveProjectDialog::Rejected; @@ -406,7 +404,7 @@ void MainWindow::closeEvent(QCloseEvent *event) //qDebug() << ret; if (ret == QMessageBox::Save) { - if(saveProject(true)) + if (saveProject(true)) { QSettings settings; settings.setValue("geometry", saveGeometry()); @@ -498,8 +496,9 @@ void MainWindow::updateFrames() for (auto W : dockWidgets) { // Temporary hack - DockWidget* w = dynamic_cast(W); - if (w) { + DockWidget *w = dynamic_cast(W); + if (w) + { w->setup(); } } @@ -511,8 +510,9 @@ void MainWindow::updateFrames() for (auto W : dockWidgets) { // Temporary hack - DockWidget* w = dynamic_cast(W); - if (w) { + DockWidget *w = dynamic_cast(W); + if (w) + { w->refresh(); } } @@ -730,36 +730,39 @@ void MainWindow::on_actionDisasAdd_comment_triggered() void MainWindow::restoreDocks() { - addDockWidget(Qt::RightDockWidgetArea, this->sectionsDock); - addDockWidget(Qt::TopDockWidgetArea, this->dashboardDock); - this->tabifyDockWidget(this->sectionsDock, this->commentsDock); - this->tabifyDockWidget(this->dashboardDock, this->disassemblyDock); - this->tabifyDockWidget(this->dashboardDock, this->graphDock); - this->tabifyDockWidget(this->dashboardDock, this->hexdumpDock); - this->tabifyDockWidget(this->dashboardDock, this->previewDock); - this->tabifyDockWidget(this->dashboardDock, this->sidebarDock); - this->tabifyDockWidget(this->dashboardDock, this->functionsDock); - this->tabifyDockWidget(this->dashboardDock, this->entrypointDock); - this->tabifyDockWidget(this->dashboardDock, this->flagsDock); - this->tabifyDockWidget(this->dashboardDock, this->stringsDock); - this->tabifyDockWidget(this->dashboardDock, this->relocsDock); - this->tabifyDockWidget(this->dashboardDock, this->importsDock); - this->tabifyDockWidget(this->dashboardDock, this->exportsDock); - this->tabifyDockWidget(this->dashboardDock, this->symbolsDock); - this->tabifyDockWidget(this->dashboardDock, this->notepadDock); - this->dashboardDock->raise(); - this->sectionsDock->raise(); -} + // bottom right + addDockWidget(Qt::RightDockWidgetArea, sectionsDock); + + // left + addDockWidget(Qt::TopDockWidgetArea, functionsDock); + + // center + splitDockWidget(functionsDock, dashboardDock, Qt::Horizontal); + + // right (sidebar) + splitDockWidget(dashboardDock, sidebarDock, Qt::Horizontal); -void MainWindow::on_actionDefaut_triggered() -{ - hideAllDocks(); - restoreDocks(); - showDefaultDocks(); - this->dashboardDock->raise(); + // tabs for center (must be applied after splitDockWidget()) + tabifyDockWidget(sectionsDock, commentsDock); + tabifyDockWidget(dashboardDock, disassemblyDock); + tabifyDockWidget(dashboardDock, graphDock); + tabifyDockWidget(dashboardDock, hexdumpDock); + tabifyDockWidget(dashboardDock, previewDock); + tabifyDockWidget(dashboardDock, entrypointDock); + tabifyDockWidget(dashboardDock, flagsDock); + tabifyDockWidget(dashboardDock, stringsDock); + tabifyDockWidget(dashboardDock, relocsDock); + tabifyDockWidget(dashboardDock, importsDock); + tabifyDockWidget(dashboardDock, exportsDock); + tabifyDockWidget(dashboardDock, symbolsDock); + tabifyDockWidget(dashboardDock, notepadDock); + + dashboardDock->raise(); + sectionsDock->raise(); } + void MainWindow::hideAllDocks() { for (auto w : dockWidgets) @@ -771,20 +774,20 @@ void MainWindow::hideAllDocks() void MainWindow::showDefaultDocks() { const QList defaultDocks = { sectionsDock, - entrypointDock, - functionsDock, - previewDock, - commentsDock, - stringsDock, - importsDock, - symbolsDock, - notepadDock, - graphDock, - disassemblyDock, - sidebarDock, - hexdumpDock, - dashboardDock - }; + entrypointDock, + functionsDock, + previewDock, + commentsDock, + stringsDock, + importsDock, + symbolsDock, + notepadDock, + graphDock, + disassemblyDock, + sidebarDock, + hexdumpDock, + dashboardDock + }; for (auto w : dockWidgets) { @@ -795,6 +798,30 @@ void MainWindow::showDefaultDocks() } } +void MainWindow::resetToDefaultLayout() +{ + restoreDocks(); + hideAllDocks(); + showDefaultDocks(); + + dashboardDock->raise(); + + // ugly workaround to set the default widths of functions and sidebar docks + // if anyone finds a way to do this cleaner that also works, feel free to change it! + auto restoreFunctionDock = qhelpers::forceWidth(functionsDock->widget(), 300); + auto restoreSidebarDock = qhelpers::forceWidth(sidebarDock->widget(), 300); + + qApp->processEvents(); + + restoreFunctionDock.restoreWidth(functionsDock->widget()); + restoreSidebarDock.restoreWidth(sidebarDock->widget()); +} + +void MainWindow::on_actionDefaut_triggered() +{ + resetToDefaultLayout(); +} + void MainWindow::on_actionhide_bottomPannel_triggered() { if (ui->centralWidget->isVisible()) @@ -844,7 +871,7 @@ void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSaveAs_triggered() { - saveProjectAs(); + saveProjectAs(); } void MainWindow::on_actionRun_Script_triggered() @@ -958,8 +985,9 @@ void MainWindow::refreshVisibleDockWidgets() if (isDockVisible(W)) { // Temporary hack - DockWidget* w = dynamic_cast(W); - if (w) { + DockWidget *w = dynamic_cast(W); + if (w) + { w->setup(); } } diff --git a/src/MainWindow.h b/src/MainWindow.h index 634920cd..15f88fec 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -57,8 +57,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - void openNewFile(const QString &fn, int anal_level = -1, QList advanced = QList()); - void openProject(const QString &project_name); + void openNewFile(const QString &fn, int anal_level = -1, QList advanced = QList()); + void openProject(const QString &project_name); void initUI(); void finalizeOpen(); @@ -73,7 +73,7 @@ public: * @param quit whether to show destructive button in dialog * @return if quit is true, false if the application should not close */ - bool saveProjectAs(bool quit = false); + bool saveProjectAs(bool quit = false); void start_web_server(); void closeEvent(QCloseEvent *event) override; @@ -147,20 +147,14 @@ private slots: void on_actionDisasAdd_comment_triggered(); - void restoreDocks(); - void on_actionDefaut_triggered(); - void hideAllDocks(); - - void showDefaultDocks(); - void on_actionFunctionsRename_triggered(); void on_actionNew_triggered(); void on_actionSave_triggered(); - void on_actionSaveAs_triggered(); + void on_actionSaveAs_triggered(); void on_actionWhite_Theme_triggered(); @@ -228,6 +222,12 @@ private: void toggleDockWidget(QDockWidget *dock_widget); + void resetToDefaultLayout(); + + void restoreDocks(); + void hideAllDocks(); + void showDefaultDocks(); + public: RVA getCursorAddress() const { return cursorAddress; } QString getFilename() const { return filename; } diff --git a/src/cutter.cpp b/src/cutter.cpp index 1c18fd9f..469a4f79 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -189,7 +189,8 @@ QString CutterCore::cmd(const QString &str) char *res = r_core_cmd_str(this->core_, cmd.constData()); QString o = QString(res ? res : ""); r_mem_free(res); - if (offset != core_->offset) { + if (offset != core_->offset) + { emit seekChanged(core_->offset); } return o; diff --git a/src/cutter.h b/src/cutter.h index 7e36bee7..68c1b895 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -186,7 +186,7 @@ class CutterCore: public QObject public: explicit CutterCore(QObject *parent = 0); ~CutterCore(); - static CutterCore* getInstance(); + static CutterCore *getInstance(); /* Getters */ RVA getOffset() const { return core_->offset; } diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index 34bafbdf..4a4c89f9 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -59,8 +59,8 @@ static QString formatBytecount(const long bytecount) } NewFileDialog::NewFileDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::NewFileDialog) + QDialog(parent), + ui(new Ui::NewFileDialog) { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); @@ -82,7 +82,7 @@ NewFileDialog::NewFileDialog(QWidget *parent) : // Hide "create" button until the dialog works ui->createButton->hide(); - ui->loadProjectButton->setEnabled(ui->projectsListWidget->currentItem() != nullptr); + ui->loadProjectButton->setEnabled(ui->projectsListWidget->currentItem() != nullptr); } NewFileDialog::~NewFileDialog() {} @@ -105,41 +105,41 @@ void NewFileDialog::on_selectFileButton_clicked() void NewFileDialog::on_selectProjectsDirButton_clicked() { - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::DirectoryOnly); + QFileDialog dialog(this); + dialog.setFileMode(QFileDialog::DirectoryOnly); QString currentDir = CutterCore::getInstance()->getConfig("dir.projects"); if(currentDir.startsWith("~")) { currentDir = QDir::homePath() + currentDir.mid(1); } - dialog.setDirectory(currentDir); + dialog.setDirectory(currentDir); dialog.setWindowTitle(tr("Select project path (dir.projects)")); - if(!dialog.exec()) + if(!dialog.exec()) { return; } - QString dir = dialog.selectedFiles().first(); - if (!dir.isEmpty()) - { - CutterCore::getInstance()->setConfig("dir.projects", dir); - fillProjectsList(); - } + QString dir = dialog.selectedFiles().first(); + if (!dir.isEmpty()) + { + CutterCore::getInstance()->setConfig("dir.projects", dir); + fillProjectsList(); + } } void NewFileDialog::on_loadProjectButton_clicked() { - QListWidgetItem *item = ui->projectsListWidget->currentItem(); + QListWidgetItem *item = ui->projectsListWidget->currentItem(); - if (item == nullptr) - { - return; - } + if (item == nullptr) + { + return; + } - loadProject(item->data(Qt::UserRole).toString()); + loadProject(item->data(Qt::UserRole).toString()); } void NewFileDialog::on_recentsListWidget_itemClicked(QListWidgetItem *item) @@ -156,7 +156,7 @@ void NewFileDialog::on_recentsListWidget_itemDoubleClicked(QListWidgetItem *item void NewFileDialog::on_projectsListWidget_itemSelectionChanged() { - ui->loadProjectButton->setEnabled(ui->projectsListWidget->currentItem() != nullptr); + ui->loadProjectButton->setEnabled(ui->projectsListWidget->currentItem() != nullptr); } void NewFileDialog::on_projectsListWidget_itemDoubleClicked(QListWidgetItem *item) @@ -255,12 +255,12 @@ bool NewFileDialog::fillProjectsList() { CutterCore *core = CutterCore::getInstance(); - ui->projectsDirEdit->setText(core->getConfig("dir.projects")); + ui->projectsDirEdit->setText(core->getConfig("dir.projects")); QStringList projects = core->getProjectNames(); projects.sort(Qt::CaseInsensitive); - ui->projectsListWidget->clear(); + ui->projectsListWidget->clear(); int i=0; for(const QString &project : projects) diff --git a/src/dialogs/NewFileDialog.h b/src/dialogs/NewFileDialog.h index 654297ec..f6c12353 100644 --- a/src/dialogs/NewFileDialog.h +++ b/src/dialogs/NewFileDialog.h @@ -12,7 +12,7 @@ namespace Ui class NewFileDialog : public QDialog { - Q_OBJECT +Q_OBJECT public: explicit NewFileDialog(QWidget *parent = 0); @@ -21,18 +21,18 @@ public: private slots: void on_loadFileButton_clicked(); void on_selectFileButton_clicked(); - void on_createButton_clicked(); + void on_createButton_clicked(); - void on_selectProjectsDirButton_clicked(); - void on_loadProjectButton_clicked(); + void on_selectProjectsDirButton_clicked(); + void on_loadProjectButton_clicked(); - void on_cancelButton_clicked(); + void on_cancelButton_clicked(); void on_recentsListWidget_itemClicked(QListWidgetItem *item); void on_recentsListWidget_itemDoubleClicked(QListWidgetItem *item); - void on_projectsListWidget_itemSelectionChanged(); - void on_projectsListWidget_itemDoubleClicked(QListWidgetItem *item); + void on_projectsListWidget_itemSelectionChanged(); + void on_projectsListWidget_itemDoubleClicked(QListWidgetItem *item); void on_actionRemove_item_triggered(); void on_actionClear_all_triggered(); @@ -40,18 +40,18 @@ private slots: private: std::unique_ptr ui; - /*! - * @return true if list is not empty - */ - bool fillRecentFilesList(); + /*! + * @return true if list is not empty + */ + bool fillRecentFilesList(); - /*! - * @return true if list is not empty - */ - bool fillProjectsList(); + /*! + * @return true if list is not empty + */ + bool fillProjectsList(); - void loadFile(const QString &filename); - void loadProject(const QString &project); + void loadFile(const QString &filename); + void loadProject(const QString &project); static const int MaxRecentFiles = 5; }; diff --git a/src/dialogs/SaveProjectDialog.cpp b/src/dialogs/SaveProjectDialog.cpp index 6aba072d..21cb080b 100644 --- a/src/dialogs/SaveProjectDialog.cpp +++ b/src/dialogs/SaveProjectDialog.cpp @@ -6,12 +6,12 @@ #include "ui_SaveProjectDialog.h" SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) : - QDialog(parent), - ui(new Ui::SaveProjectDialog) + QDialog(parent), + ui(new Ui::SaveProjectDialog) { ui->setupUi(this); - CutterCore *core = CutterCore::getInstance(); + CutterCore *core = CutterCore::getInstance(); if (quit) { @@ -26,10 +26,10 @@ SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) : } ui->nameEdit->setText(core->getConfig("prj.name")); - ui->projectsDirEdit->setText(core->getConfig("dir.projects")); - ui->filesCheckBox->setChecked(core->getConfigb("prj.files")); - ui->gitCheckBox->setChecked(core->getConfigb("prj.git")); - ui->zipCheckBox->setChecked(core->getConfigb("prj.zip")); + ui->projectsDirEdit->setText(core->getConfig("dir.projects")); + ui->filesCheckBox->setChecked(core->getConfigb("prj.files")); + ui->gitCheckBox->setChecked(core->getConfigb("prj.git")); + ui->zipCheckBox->setChecked(core->getConfigb("prj.zip")); } SaveProjectDialog::~SaveProjectDialog() @@ -64,19 +64,19 @@ void SaveProjectDialog::on_selectProjectsDirButton_clicked() void SaveProjectDialog::on_buttonBox_clicked(QAbstractButton *button) { - switch(ui->buttonBox->buttonRole(button)) - { - case QDialogButtonBox::DestructiveRole: + switch(ui->buttonBox->buttonRole(button)) + { + case QDialogButtonBox::DestructiveRole: QDialog::done(Destructive); - break; + break; - case QDialogButtonBox::RejectRole: + case QDialogButtonBox::RejectRole: QDialog::done(Rejected); - break; + break; - default: - break; - } + default: + break; + } } void SaveProjectDialog::accept() diff --git a/src/dialogs/SaveProjectDialog.h b/src/dialogs/SaveProjectDialog.h index f4fed151..db2885d9 100644 --- a/src/dialogs/SaveProjectDialog.h +++ b/src/dialogs/SaveProjectDialog.h @@ -16,17 +16,17 @@ class SaveProjectDialog : public QDialog Q_OBJECT public: - enum Result { Saved, Rejected, Destructive }; + enum Result { Saved, Rejected, Destructive }; explicit SaveProjectDialog(bool quit, QWidget *parent = 0); ~SaveProjectDialog(); virtual void accept() override; - virtual void reject() override; + virtual void reject() override; private slots: - void on_buttonBox_clicked(QAbstractButton *button); - void on_selectProjectsDirButton_clicked(); + void on_buttonBox_clicked(QAbstractButton *button); + void on_selectProjectsDirButton_clicked(); private: std::unique_ptr ui; diff --git a/src/main.cpp b/src/main.cpp index 796a2971..b72c02c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,12 +16,13 @@ void set_appimage_symlink() { - char* path = realpath("/proc/self/exe", NULL); - char* i = strrchr(path, '/'); - *(i+1) = '\0'; - char* dest = strcat(path, "../"); + char *path = realpath("/proc/self/exe", NULL); + char *i = strrchr(path, '/'); + *(i + 1) = '\0'; + char *dest = strcat(path, "../"); struct stat buf; - if (lstat(PREFIX, &buf) == 0 && S_ISLNK(buf.st_mode)) { + if (lstat(PREFIX, &buf) == 0 && S_ISLNK(buf.st_mode)) + { remove(PREFIX); } symlink(dest, PREFIX); diff --git a/src/utils/Helpers.cpp b/src/utils/Helpers.cpp index 080ac672..e8f7fa70 100644 --- a/src/utils/Helpers.cpp +++ b/src/utils/Helpers.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include static QAbstractItemView::ScrollMode scrollMode() @@ -87,4 +89,52 @@ namespace qhelpers button->blockSignals(blocked); } + + SizePolicyMinMax forceWidth(QWidget *widget, int width) + { + SizePolicyMinMax r; + r.sizePolicy = widget->sizePolicy(); + r.min = widget->minimumWidth(); + r.max = widget->maximumWidth(); + + QSizePolicy sizePolicy = r.sizePolicy; + sizePolicy.setHorizontalPolicy(QSizePolicy::Fixed); + widget->setSizePolicy(sizePolicy); + widget->setMinimumWidth(width); + widget->setMaximumWidth(width); + + return r; + } + + + SizePolicyMinMax forceHeight(QWidget *widget, int height) + { + SizePolicyMinMax r; + r.sizePolicy = widget->sizePolicy(); + r.min = widget->minimumHeight(); + r.max = widget->maximumHeight(); + + QSizePolicy sizePolicy = r.sizePolicy; + sizePolicy.setVerticalPolicy(QSizePolicy::Fixed); + widget->setSizePolicy(sizePolicy); + widget->setMinimumHeight(height); + widget->setMaximumHeight(height); + + return r; + } + + void SizePolicyMinMax::restoreWidth(QWidget *widget) + { + widget->setSizePolicy(sizePolicy); + widget->setMinimumWidth(min); + widget->setMaximumWidth(max); + } + + void SizePolicyMinMax::restoreHeight(QWidget *widget) + { + widget->setSizePolicy(sizePolicy); + widget->setMinimumHeight(min); + widget->setMaximumHeight(max); + } + } // end namespace diff --git a/src/utils/Helpers.h b/src/utils/Helpers.h index fba10672..b7ffae5a 100644 --- a/src/utils/Helpers.h +++ b/src/utils/Helpers.h @@ -2,6 +2,7 @@ #define QHELPERS_H #include +#include class QPlainTextEdit; class QTextEdit; @@ -10,6 +11,7 @@ class QTreeWidget; class QTreeWidgetItem; class QAbstractItemView; class QAbstractButton; +class QWidget; namespace qhelpers { @@ -24,6 +26,20 @@ namespace qhelpers void setVerticalScrollMode(QAbstractItemView *tw); void setCheckedWithoutSignals(QAbstractButton *button, bool checked); + + + struct SizePolicyMinMax + { + QSizePolicy sizePolicy; + int min; + int max; + + void restoreWidth(QWidget *widget); + void restoreHeight(QWidget *widget); + }; + + SizePolicyMinMax forceWidth(QWidget *widget, int width); + SizePolicyMinMax forceHeight(QWidget *widget, int height); } #endif // HELPERS_H diff --git a/src/widgets/FunctionsWidget.ui b/src/widgets/FunctionsWidget.ui index 83ddddde..39a94ae4 100644 --- a/src/widgets/FunctionsWidget.ui +++ b/src/widgets/FunctionsWidget.ui @@ -6,8 +6,8 @@ 0 0 - 603 - 314 + 289 + 359 @@ -17,6 +17,18 @@ Functions + + + 1 + 0 + + + + + 200 + 0 + + 0 @@ -35,6 +47,12 @@ + + + 0 + 0 + + QTabWidget::pane { /* The tab widget frame */ border-top: 0px; @@ -47,6 +65,12 @@ border-top: 0px; 0 + + + 0 + 0 + + List @@ -68,6 +92,12 @@ border-top: 0px; + + + 0 + 0 + + Qt::CustomContextMenu @@ -120,6 +150,12 @@ QToolTip + + + 0 + 0 + + Tree @@ -141,6 +177,12 @@ QToolTip + + + 0 + 0 + + Qt::CustomContextMenu @@ -196,11 +238,20 @@ QToolTip { 0 + + QLayout::SetNoConstraint + 2 + + + 0 + 0 + + Quick Filter diff --git a/src/widgets/SidebarWidget.ui b/src/widgets/SidebarWidget.ui index 732816ad..277bb275 100644 --- a/src/widgets/SidebarWidget.ui +++ b/src/widgets/SidebarWidget.ui @@ -11,7 +11,7 @@ - + 0 0 @@ -20,6 +20,18 @@ Sidebar + + + 0 + 0 + + + + + 200 + 0 + + 0 @@ -560,7 +572,4 @@ QToolTip { - - -