mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 14:16:08 +00:00
Decouple QuickFilterView as independent class
This commit is contained in:
parent
326bf70ff2
commit
f694daac88
@ -84,7 +84,8 @@ SOURCES += \
|
|||||||
widgets/GraphView.cpp \
|
widgets/GraphView.cpp \
|
||||||
dialogs/preferences/PreferencesDialog.cpp \
|
dialogs/preferences/PreferencesDialog.cpp \
|
||||||
dialogs/preferences/GeneralOptionsWidget.cpp \
|
dialogs/preferences/GeneralOptionsWidget.cpp \
|
||||||
dialogs/preferences/GraphOptionsWidget.cpp
|
dialogs/preferences/GraphOptionsWidget.cpp \
|
||||||
|
widgets/QuickFilterView.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
cutter.h \
|
cutter.h \
|
||||||
@ -139,7 +140,8 @@ HEADERS += \
|
|||||||
widgets/GraphView.h \
|
widgets/GraphView.h \
|
||||||
dialogs/preferences/PreferencesDialog.h \
|
dialogs/preferences/PreferencesDialog.h \
|
||||||
dialogs/preferences/GeneralOptionsWidget.h \
|
dialogs/preferences/GeneralOptionsWidget.h \
|
||||||
dialogs/preferences/GraphOptionsWidget.h
|
dialogs/preferences/GraphOptionsWidget.h \
|
||||||
|
widgets/QuickFilterView.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialogs/AboutDialog.ui \
|
dialogs/AboutDialog.ui \
|
||||||
@ -171,7 +173,8 @@ FORMS += \
|
|||||||
dialogs/SaveProjectDialog.ui \
|
dialogs/SaveProjectDialog.ui \
|
||||||
dialogs/preferences/PreferencesDialog.ui \
|
dialogs/preferences/PreferencesDialog.ui \
|
||||||
dialogs/preferences/GeneralOptionsWidget.ui \
|
dialogs/preferences/GeneralOptionsWidget.ui \
|
||||||
dialogs/preferences/GraphOptionsWidget.ui
|
dialogs/preferences/GraphOptionsWidget.ui \
|
||||||
|
widgets/QuickFilterView.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
@ -334,12 +334,12 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
|
|||||||
|
|
||||||
// Ctrl-F to show/hide the filter entry
|
// Ctrl-F to show/hide the filter entry
|
||||||
QShortcut *search_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this);
|
QShortcut *search_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this);
|
||||||
connect(search_shortcut, SIGNAL(activated()), this, SLOT(show_filter()));
|
connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
|
||||||
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
|
||||||
// Esc to clear the filter entry
|
// Esc to clear the filter entry
|
||||||
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||||
connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clear_filter()));
|
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
||||||
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
|
||||||
QFontInfo font_info = ui->functionsTreeView->fontInfo();
|
QFontInfo font_info = ui->functionsTreeView->fontInfo();
|
||||||
@ -348,16 +348,21 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
|
|||||||
|
|
||||||
function_model = new FunctionModel(&functions, &import_addresses, false, default_font, highlight_font, this);
|
function_model = new FunctionModel(&functions, &import_addresses, false, default_font, highlight_font, this);
|
||||||
function_proxy_model = new FunctionSortFilterProxyModel(function_model, this);
|
function_proxy_model = new FunctionSortFilterProxyModel(function_model, this);
|
||||||
connect(ui->filterLineEdit, SIGNAL(textChanged(const QString &)), function_proxy_model, SLOT(setFilterWildcard(const QString &)));
|
|
||||||
ui->functionsTreeView->setModel(function_proxy_model);
|
ui->functionsTreeView->setModel(function_proxy_model);
|
||||||
ui->functionsTreeView->sortByColumn(FunctionModel::NameColumn, Qt::AscendingOrder);
|
ui->functionsTreeView->sortByColumn(FunctionModel::NameColumn, Qt::AscendingOrder);
|
||||||
|
|
||||||
nested_function_model = new FunctionModel(&functions, &import_addresses, true, default_font, highlight_font, this);
|
nested_function_model = new FunctionModel(&functions, &import_addresses, true, default_font, highlight_font, this);
|
||||||
nested_function_proxy_model = new FunctionSortFilterProxyModel(nested_function_model, this);
|
nested_function_proxy_model = new FunctionSortFilterProxyModel(nested_function_model, this);
|
||||||
connect(ui->filterLineEdit, SIGNAL(textChanged(const QString &)), nested_function_proxy_model, SLOT(setFilterWildcard(const QString &)));
|
|
||||||
ui->nestedFunctionsTreeView->setModel(nested_function_proxy_model);
|
ui->nestedFunctionsTreeView->setModel(nested_function_proxy_model);
|
||||||
ui->nestedFunctionsTreeView->sortByColumn(0, Qt::AscendingOrder);
|
ui->nestedFunctionsTreeView->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), function_proxy_model, SLOT(setFilterWildcard(const QString &)));
|
||||||
|
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), nested_function_proxy_model, SLOT(setFilterWildcard(const QString &)));
|
||||||
|
connect(ui->quickFilterView, &QuickFilterView::filterClosed, this, [this]()
|
||||||
|
{
|
||||||
|
getCurrentTreeView()->setFocus();
|
||||||
|
});
|
||||||
|
|
||||||
setScrollMode();
|
setScrollMode();
|
||||||
|
|
||||||
// Set Functions context menu
|
// Set Functions context menu
|
||||||
@ -565,32 +570,4 @@ void FunctionsWidget::resizeEvent(QResizeEvent *event)
|
|||||||
void FunctionsWidget::setScrollMode()
|
void FunctionsWidget::setScrollMode()
|
||||||
{
|
{
|
||||||
qhelpers::setVerticalScrollMode(ui->functionsTreeView);
|
qhelpers::setVerticalScrollMode(ui->functionsTreeView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionsWidget::show_filter()
|
|
||||||
{
|
|
||||||
ui->filterLineEdit->setVisible(true);
|
|
||||||
ui->closeFilterButton->setVisible(true);
|
|
||||||
ui->filterLineEdit->setFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FunctionsWidget::clear_filter()
|
|
||||||
{
|
|
||||||
if (ui->filterLineEdit->text() == "")
|
|
||||||
{
|
|
||||||
ui->filterLineEdit->setVisible(false);
|
|
||||||
ui->closeFilterButton->setVisible(false);
|
|
||||||
ui->functionsTreeView->setFocus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->filterLineEdit->setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FunctionsWidget::on_closeFilterButton_clicked()
|
|
||||||
{
|
|
||||||
ui->filterLineEdit->setVisible(false);
|
|
||||||
ui->closeFilterButton->setVisible(false);
|
|
||||||
ui->functionsTreeView->setFocus();
|
|
||||||
}
|
|
@ -100,12 +100,6 @@ private slots:
|
|||||||
void on_actionHorizontal_triggered();
|
void on_actionHorizontal_triggered();
|
||||||
void on_actionVertical_triggered();
|
void on_actionVertical_triggered();
|
||||||
|
|
||||||
void show_filter();
|
|
||||||
|
|
||||||
void clear_filter();
|
|
||||||
|
|
||||||
void on_closeFilterButton_clicked();
|
|
||||||
|
|
||||||
void showTitleContextMenu(const QPoint &pt);
|
void showTitleContextMenu(const QPoint &pt);
|
||||||
|
|
||||||
void refreshTree();
|
void refreshTree();
|
||||||
|
@ -197,71 +197,7 @@ QToolTip {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="QuickFilterView" name="quickFilterView" native="true"/>
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="sizeConstraint">
|
|
||||||
<enum>QLayout::SetNoConstraint</enum>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="filterLineEdit">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Quick Filter</string>
|
|
||||||
</property>
|
|
||||||
<property name="clearButtonEnabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="closeFilterButton">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<weight>75</weight>
|
|
||||||
<italic>false</italic>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QToolButton { /* all types of tool button */
|
|
||||||
border: 2px solid #333;
|
|
||||||
border-left: 2px solid #333;
|
|
||||||
border-right: 2px solid #333;
|
|
||||||
background-color: #333;
|
|
||||||
color: rgb(255, 255, 255)
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:hover {
|
|
||||||
border: 2px solid rgb(128, 128, 128);
|
|
||||||
border-left: 2px solid rgb(128, 128, 128);
|
|
||||||
border-right: 2px solid rgb(128, 128, 128);
|
|
||||||
background-color: rgb(128, 128, 128);
|
|
||||||
color: rgb(255, 255, 255)
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:pressed {
|
|
||||||
border: 2px solid #2180a9;
|
|
||||||
border-left: 2px solid #2180a9;
|
|
||||||
border-right: 2px solid #2180a9;
|
|
||||||
background-color: #2180a9;
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>X</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -305,6 +241,14 @@ QToolButton:pressed {
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QuickFilterView</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>widgets/QuickFilterView.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
44
src/widgets/QuickFilterView.cpp
Normal file
44
src/widgets/QuickFilterView.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
#include "QuickFilterView.h"
|
||||||
|
#include "ui_QuickFilterView.h"
|
||||||
|
|
||||||
|
QuickFilterView::QuickFilterView(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::QuickFilterView())
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->closeFilterButton, &QAbstractButton::clicked, this, &QuickFilterView::closeFilter);
|
||||||
|
|
||||||
|
connect(ui->filterLineEdit, &QLineEdit::textChanged, this, [this](const QString &text)
|
||||||
|
{
|
||||||
|
emit filterTextChanged(text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickFilterView::~QuickFilterView() {}
|
||||||
|
|
||||||
|
|
||||||
|
void QuickFilterView::showFilter()
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
ui->filterLineEdit->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickFilterView::clearFilter()
|
||||||
|
{
|
||||||
|
if (ui->filterLineEdit->text().isEmpty())
|
||||||
|
{
|
||||||
|
closeFilter();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->filterLineEdit->setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickFilterView::closeFilter()
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
emit filterClosed();
|
||||||
|
}
|
35
src/widgets/QuickFilterView.h
Normal file
35
src/widgets/QuickFilterView.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
#ifndef QUICKFILTERVIEW_H
|
||||||
|
#define QUICKFILTERVIEW_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class QuickFilterView;
|
||||||
|
}
|
||||||
|
|
||||||
|
class QuickFilterView : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QuickFilterView(QWidget *parent = nullptr);
|
||||||
|
~QuickFilterView();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void showFilter();
|
||||||
|
void closeFilter();
|
||||||
|
void clearFilter();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void filterTextChanged(const QString &text);
|
||||||
|
void filterClosed();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Ui::QuickFilterView> ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //QUICKFILTERVIEW_H
|
90
src/widgets/QuickFilterView.ui
Normal file
90
src/widgets/QuickFilterView.ui
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QuickFilterView</class>
|
||||||
|
<widget class="QWidget" name="QuickFilterView">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>327</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="filterLineEdit">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Quick Filter</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="closeFilterButton">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<italic>false</italic>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">QToolButton { /* all types of tool button */
|
||||||
|
border: 2px solid #333;
|
||||||
|
border-left: 2px solid #333;
|
||||||
|
border-right: 2px solid #333;
|
||||||
|
background-color: #333;
|
||||||
|
color: rgb(255, 255, 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
QToolButton:hover {
|
||||||
|
border: 2px solid rgb(128, 128, 128);
|
||||||
|
border-left: 2px solid rgb(128, 128, 128);
|
||||||
|
border-right: 2px solid rgb(128, 128, 128);
|
||||||
|
background-color: rgb(128, 128, 128);
|
||||||
|
color: rgb(255, 255, 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
QToolButton:pressed {
|
||||||
|
border: 2px solid #2180a9;
|
||||||
|
border-left: 2px solid #2180a9;
|
||||||
|
border-right: 2px solid #2180a9;
|
||||||
|
background-color: #2180a9;
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>X</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user