Default Layout (#84)

* Basic default layout
* Workaround to set default widths for QDockWidgets
* AStyle
This commit is contained in:
Florian Märkl 2017-11-03 18:22:54 +01:00 committed by xarkes
parent bfed7d43ed
commit 0b5a351d5f
14 changed files with 294 additions and 138 deletions

View File

@ -257,9 +257,7 @@ void MainWindow::initUI()
dockWidgets.push_back(dashboardDock); dockWidgets.push_back(dashboardDock);
// Set up dock widgets default layout // Set up dock widgets default layout
restoreDocks(); resetToDefaultLayout();
hideAllDocks();
showDefaultDocks();
// Restore saved settings // Restore saved settings
this->readSettings(); this->readSettings();
@ -499,7 +497,8 @@ void MainWindow::updateFrames()
{ {
// Temporary hack // Temporary hack
DockWidget *w = dynamic_cast<DockWidget *>(W); DockWidget *w = dynamic_cast<DockWidget *>(W);
if (w) { if (w)
{
w->setup(); w->setup();
} }
} }
@ -512,7 +511,8 @@ void MainWindow::updateFrames()
{ {
// Temporary hack // Temporary hack
DockWidget *w = dynamic_cast<DockWidget *>(W); DockWidget *w = dynamic_cast<DockWidget *>(W);
if (w) { if (w)
{
w->refresh(); w->refresh();
} }
} }
@ -730,36 +730,39 @@ void MainWindow::on_actionDisasAdd_comment_triggered()
void MainWindow::restoreDocks() void MainWindow::restoreDocks()
{ {
addDockWidget(Qt::RightDockWidgetArea, this->sectionsDock); // bottom right
addDockWidget(Qt::TopDockWidgetArea, this->dashboardDock); addDockWidget(Qt::RightDockWidgetArea, sectionsDock);
this->tabifyDockWidget(this->sectionsDock, this->commentsDock);
this->tabifyDockWidget(this->dashboardDock, this->disassemblyDock); // left
this->tabifyDockWidget(this->dashboardDock, this->graphDock); addDockWidget(Qt::TopDockWidgetArea, functionsDock);
this->tabifyDockWidget(this->dashboardDock, this->hexdumpDock);
this->tabifyDockWidget(this->dashboardDock, this->previewDock); // center
this->tabifyDockWidget(this->dashboardDock, this->sidebarDock); splitDockWidget(functionsDock, dashboardDock, Qt::Horizontal);
this->tabifyDockWidget(this->dashboardDock, this->functionsDock);
this->tabifyDockWidget(this->dashboardDock, this->entrypointDock); // right (sidebar)
this->tabifyDockWidget(this->dashboardDock, this->flagsDock); splitDockWidget(dashboardDock, sidebarDock, Qt::Horizontal);
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();
}
void MainWindow::on_actionDefaut_triggered() // tabs for center (must be applied after splitDockWidget())
{ tabifyDockWidget(sectionsDock, commentsDock);
hideAllDocks(); tabifyDockWidget(dashboardDock, disassemblyDock);
restoreDocks(); tabifyDockWidget(dashboardDock, graphDock);
showDefaultDocks(); tabifyDockWidget(dashboardDock, hexdumpDock);
this->dashboardDock->raise(); 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() void MainWindow::hideAllDocks()
{ {
for (auto w : dockWidgets) 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() void MainWindow::on_actionhide_bottomPannel_triggered()
{ {
if (ui->centralWidget->isVisible()) if (ui->centralWidget->isVisible())
@ -959,7 +986,8 @@ void MainWindow::refreshVisibleDockWidgets()
{ {
// Temporary hack // Temporary hack
DockWidget *w = dynamic_cast<DockWidget *>(W); DockWidget *w = dynamic_cast<DockWidget *>(W);
if (w) { if (w)
{
w->setup(); w->setup();
} }
} }

View File

@ -147,14 +147,8 @@ private slots:
void on_actionDisasAdd_comment_triggered(); void on_actionDisasAdd_comment_triggered();
void restoreDocks();
void on_actionDefaut_triggered(); void on_actionDefaut_triggered();
void hideAllDocks();
void showDefaultDocks();
void on_actionFunctionsRename_triggered(); void on_actionFunctionsRename_triggered();
void on_actionNew_triggered(); void on_actionNew_triggered();
@ -228,6 +222,12 @@ private:
void toggleDockWidget(QDockWidget *dock_widget); void toggleDockWidget(QDockWidget *dock_widget);
void resetToDefaultLayout();
void restoreDocks();
void hideAllDocks();
void showDefaultDocks();
public: public:
RVA getCursorAddress() const { return cursorAddress; } RVA getCursorAddress() const { return cursorAddress; }
QString getFilename() const { return filename; } QString getFilename() const { return filename; }

View File

@ -189,7 +189,8 @@ QString CutterCore::cmd(const QString &str)
char *res = r_core_cmd_str(this->core_, cmd.constData()); char *res = r_core_cmd_str(this->core_, cmd.constData());
QString o = QString(res ? res : ""); QString o = QString(res ? res : "");
r_mem_free(res); r_mem_free(res);
if (offset != core_->offset) { if (offset != core_->offset)
{
emit seekChanged(core_->offset); emit seekChanged(core_->offset);
} }
return o; return o;

View File

@ -21,7 +21,8 @@ void set_appimage_symlink()
*(i + 1) = '\0'; *(i + 1) = '\0';
char *dest = strcat(path, "../"); char *dest = strcat(path, "../");
struct stat buf; 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); remove(PREFIX);
} }
symlink(dest, PREFIX); symlink(dest, PREFIX);

View File

@ -8,6 +8,8 @@
#include <QString> #include <QString>
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QAbstractButton> #include <QAbstractButton>
#include <QDockWidget>
#include <QtGui/QtGui>
static QAbstractItemView::ScrollMode scrollMode() static QAbstractItemView::ScrollMode scrollMode()
@ -87,4 +89,52 @@ namespace qhelpers
button->blockSignals(blocked); 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 } // end namespace

View File

@ -2,6 +2,7 @@
#define QHELPERS_H #define QHELPERS_H
#include <QString> #include <QString>
#include <QSizePolicy>
class QPlainTextEdit; class QPlainTextEdit;
class QTextEdit; class QTextEdit;
@ -10,6 +11,7 @@ class QTreeWidget;
class QTreeWidgetItem; class QTreeWidgetItem;
class QAbstractItemView; class QAbstractItemView;
class QAbstractButton; class QAbstractButton;
class QWidget;
namespace qhelpers namespace qhelpers
{ {
@ -24,6 +26,20 @@ namespace qhelpers
void setVerticalScrollMode(QAbstractItemView *tw); void setVerticalScrollMode(QAbstractItemView *tw);
void setCheckedWithoutSignals(QAbstractButton *button, bool checked); 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 #endif // HELPERS_H

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>603</width> <width>289</width>
<height>314</height> <height>359</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -17,6 +17,18 @@
<string notr="true">Functions</string> <string notr="true">Functions</string>
</property> </property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
@ -35,6 +47,12 @@
</property> </property>
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QTabWidget::pane { /* The tab widget frame */ <string notr="true">QTabWidget::pane { /* The tab widget frame */
border-top: 0px; border-top: 0px;
@ -47,6 +65,12 @@ border-top: 0px;
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title"> <attribute name="title">
<string>List</string> <string>List</string>
</attribute> </attribute>
@ -68,6 +92,12 @@ border-top: 0px;
</property> </property>
<item> <item>
<widget class="QTreeView" name="functionsTreeView"> <widget class="QTreeView" name="functionsTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
@ -120,6 +150,12 @@ QToolTip
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="tab_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title"> <attribute name="title">
<string>Tree</string> <string>Tree</string>
</attribute> </attribute>
@ -141,6 +177,12 @@ QToolTip
</property> </property>
<item> <item>
<widget class="QTreeView" name="nestedFunctionsTreeView"> <widget class="QTreeView" name="nestedFunctionsTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
@ -196,11 +238,20 @@ QToolTip {
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="rightMargin"> <property name="rightMargin">
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
<widget class="QLineEdit" name="filterLineEdit"> <widget class="QLineEdit" name="filterLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>Quick Filter</string> <string>Quick Filter</string>
</property> </property>

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -20,6 +20,18 @@
<string notr="true">Sidebar</string> <string notr="true">Sidebar</string>
</property> </property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
@ -560,7 +572,4 @@ QToolTip {
<include location="../resources.qrc"/> <include location="../resources.qrc"/>
</resources> </resources>
<connections/> <connections/>
<buttongroups>
<buttongroup name="buttonGroup_2"/>
</buttongroups>
</ui> </ui>