mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 10:00:40 +00:00
Remove recent filters button in favour of styling a fake combo box
* The filter icon was confusing since it had a 'refresh' badge instead of 'save/load/recent' type badge, and making the latter readable in a few pixels is not feasible. Having the combo dropdown with saved filters is as intuitive and works in-line.
This commit is contained in:
@@ -504,8 +504,13 @@ QRect RDStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
|
||||
if(sc == QStyle::SC_ComboBoxFrame || sc == QStyle::SC_ComboBoxListBoxPopup)
|
||||
return rect;
|
||||
|
||||
rect.adjust(Constants::ComboMargin, Constants::ComboMargin, -Constants::ComboMargin,
|
||||
-Constants::ComboMargin);
|
||||
const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
|
||||
|
||||
if(combo->subControls & QStyle::SC_ComboBoxFrame)
|
||||
{
|
||||
rect.adjust(Constants::ComboMargin, Constants::ComboMargin, -Constants::ComboMargin,
|
||||
-Constants::ComboMargin);
|
||||
}
|
||||
|
||||
if(sc == QStyle::SC_ComboBoxEditField)
|
||||
return rect.adjusted(0, 0, -Constants::ComboArrowDim, 0);
|
||||
@@ -1138,10 +1143,18 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl
|
||||
}
|
||||
else if(control == QStyle::CC_ComboBox)
|
||||
{
|
||||
drawRoundedRectBorder(opt, p, widget, QPalette::Base, false);
|
||||
const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
|
||||
|
||||
if(combo->subControls & QStyle::SC_ComboBoxFrame)
|
||||
{
|
||||
drawRoundedRectBorder(opt, p, widget, QPalette::Base, false);
|
||||
}
|
||||
|
||||
QRectF rect = proxy()->subControlRect(control, opt, QStyle::SC_ComboBoxArrow, widget);
|
||||
|
||||
if(!(combo->subControls & QStyle::SC_ComboBoxFrame))
|
||||
p->fillRect(rect, opt->palette.brush(QPalette::Base));
|
||||
|
||||
p->save();
|
||||
p->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
||||
@@ -405,6 +405,11 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio
|
||||
|
||||
const QStyleOptionToolButton *toolopt = qstyleoption_cast<const QStyleOptionToolButton *>(opt);
|
||||
|
||||
if((toolopt->features & QStyleOptionToolButton::Arrow) && toolopt->arrowType != Qt::NoArrow)
|
||||
{
|
||||
return QProxyStyle::drawControl(control, opt, p, widget);
|
||||
}
|
||||
|
||||
QRect rect = toolopt->rect;
|
||||
|
||||
// even though our style doesn't shift the button contents, this is the tweaked native style so
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QAbstractItemView>
|
||||
#include <QCompleter>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
#include <QStringListModel>
|
||||
#include "Code/QRDUtils.h"
|
||||
@@ -80,6 +81,28 @@ void RDTextEdit::setSingleLine()
|
||||
});
|
||||
}
|
||||
|
||||
void RDTextEdit::setDropDown()
|
||||
{
|
||||
if(m_Drop)
|
||||
return;
|
||||
|
||||
m_Drop = new RDTextEditDropDownButton(this);
|
||||
m_Drop->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_Drop->setArrowType(Qt::DownArrow);
|
||||
QObject::connect(m_Drop, &QToolButton::clicked, [this]() { emit(dropDownClicked()); });
|
||||
|
||||
QStyleOptionComboBox opt;
|
||||
opt.rect = rect();
|
||||
QRect r = style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, this);
|
||||
|
||||
setViewportMargins(0, 0, r.width(), 0);
|
||||
setMinimumHeight(r.height() + 2);
|
||||
|
||||
m_Drop->setFixedSize(r.size());
|
||||
|
||||
updateDropButtonGeometry();
|
||||
}
|
||||
|
||||
void RDTextEdit::setHoverTrack()
|
||||
{
|
||||
setAttribute(Qt::WA_Hover);
|
||||
@@ -348,6 +371,24 @@ void RDTextEdit::mouseMoveEvent(QMouseEvent *e)
|
||||
QTextEdit::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void RDTextEdit::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
updateDropButtonGeometry();
|
||||
|
||||
QTextEdit::resizeEvent(e);
|
||||
}
|
||||
|
||||
void RDTextEdit::updateDropButtonGeometry()
|
||||
{
|
||||
if(m_Drop)
|
||||
{
|
||||
QRect r = contentsRect();
|
||||
r.setLeft(r.right() - m_Drop->rect().width() + 1);
|
||||
r.setSize(m_Drop->size());
|
||||
m_Drop->setGeometry(r);
|
||||
}
|
||||
}
|
||||
|
||||
bool RDTextEdit::event(QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::HoverEnter)
|
||||
@@ -360,3 +401,34 @@ bool RDTextEdit::event(QEvent *e)
|
||||
}
|
||||
return QTextEdit::event(e);
|
||||
}
|
||||
|
||||
RDTextEditDropDownButton::RDTextEditDropDownButton(QWidget *parent) : QToolButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
RDTextEditDropDownButton::~RDTextEditDropDownButton()
|
||||
{
|
||||
}
|
||||
|
||||
void RDTextEditDropDownButton::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this);
|
||||
|
||||
QStyleOptionToolButton butt;
|
||||
|
||||
initStyleOption(&butt);
|
||||
|
||||
QStyleOptionComboBox opt;
|
||||
|
||||
opt.direction = butt.direction;
|
||||
opt.rect = butt.rect;
|
||||
opt.fontMetrics = butt.fontMetrics;
|
||||
opt.palette = butt.palette;
|
||||
opt.state = butt.state;
|
||||
opt.subControls = QStyle::SC_ComboBoxArrow;
|
||||
opt.activeSubControls = QStyle::SC_ComboBoxArrow;
|
||||
opt.editable = true;
|
||||
opt.frame = false;
|
||||
|
||||
style()->drawComplexControl(QStyle::CC_ComboBox, &opt, &p, this);
|
||||
}
|
||||
|
||||
@@ -23,11 +23,27 @@
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextEdit>
|
||||
#include <QToolButton>
|
||||
|
||||
class QCompleter;
|
||||
class QStringListModel;
|
||||
class QToolButton;
|
||||
|
||||
class RDTextEditDropDownButton : public QToolButton
|
||||
{
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RDTextEditDropDownButton(QWidget *parent = 0);
|
||||
~RDTextEditDropDownButton();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
};
|
||||
|
||||
class RDTextEdit : public QTextEdit
|
||||
{
|
||||
@@ -39,11 +55,14 @@ private:
|
||||
QStringListModel *m_CompletionModel = NULL;
|
||||
QString m_WordCharacters;
|
||||
|
||||
QToolButton *m_Drop = NULL;
|
||||
|
||||
public:
|
||||
explicit RDTextEdit(QWidget *parent = 0);
|
||||
~RDTextEdit();
|
||||
|
||||
void setSingleLine();
|
||||
void setDropDown();
|
||||
void setHoverTrack();
|
||||
void enableCompletion();
|
||||
|
||||
@@ -58,6 +77,7 @@ signals:
|
||||
void leave();
|
||||
void hoverEnter();
|
||||
void hoverLeave();
|
||||
void dropDownClicked();
|
||||
void mouseMoved(QMouseEvent *event);
|
||||
void keyPress(QKeyEvent *e);
|
||||
void completionBegin(QString prefix);
|
||||
@@ -70,6 +90,10 @@ protected:
|
||||
void focusOutEvent(QFocusEvent *e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
void updateDropButtonGeometry();
|
||||
|
||||
bool event(QEvent *e);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
};
|
||||
|
||||
@@ -3337,6 +3337,7 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent)
|
||||
OnCaptureClosed();
|
||||
|
||||
ui->filterExpression->setSingleLine();
|
||||
ui->filterExpression->setDropDown();
|
||||
ui->filterExpression->setHoverTrack();
|
||||
ui->filterExpression->enableCompletion();
|
||||
ui->filterExpression->setAcceptRichText(false);
|
||||
@@ -3367,7 +3368,7 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent)
|
||||
QObject::connect(ui->filterExpression, &RDTextEdit::keyPress, this,
|
||||
&EventBrowser::savedFilter_keyPress);
|
||||
|
||||
QObject::connect(ui->recentFilters, &QToolButton::clicked,
|
||||
QObject::connect(ui->filterExpression, &RDTextEdit::dropDownClicked,
|
||||
[this]() { ShowSavedFilterCompleter(ui->filterExpression); });
|
||||
|
||||
QObject::connect(ui->filterSettings, &QToolButton::clicked, this,
|
||||
@@ -3588,7 +3589,6 @@ void EventBrowser::CreateFilterDialog()
|
||||
RDLabel *listLabel = new RDLabel(this);
|
||||
RDLabel *filterLabel = new RDLabel(this);
|
||||
CollapseGroupBox *settingsGroup = new CollapseGroupBox(this);
|
||||
QToolButton *recentFilters = new QToolButton(this);
|
||||
QToolButton *saveFilter = new QToolButton(this);
|
||||
|
||||
QVBoxLayout *settingsLayout = new QVBoxLayout();
|
||||
@@ -3650,6 +3650,7 @@ void EventBrowser::CreateFilterDialog()
|
||||
m_FilterSettings.Filter->enableCompletion();
|
||||
m_FilterSettings.Filter->setAcceptRichText(false);
|
||||
m_FilterSettings.Filter->setSingleLine();
|
||||
m_FilterSettings.Filter->setDropDown();
|
||||
|
||||
QObject::connect(m_FilterSettings.Filter, &RDTextEdit::keyPress, this,
|
||||
&EventBrowser::filter_forceCompletion_keyPress);
|
||||
@@ -3664,7 +3665,7 @@ void EventBrowser::CreateFilterDialog()
|
||||
QObject::connect(m_FilterSettings.Filter, &RDTextEdit::keyPress, this,
|
||||
&EventBrowser::savedFilter_keyPress);
|
||||
|
||||
QObject::connect(recentFilters, &QToolButton::clicked,
|
||||
QObject::connect(m_FilterSettings.Filter, &RDTextEdit::dropDownClicked,
|
||||
[this]() { ShowSavedFilterCompleter(m_FilterSettings.Filter); });
|
||||
|
||||
QObject::connect(saveFilter, &QToolButton::clicked, [this]() {
|
||||
@@ -3806,9 +3807,6 @@ void EventBrowser::CreateFilterDialog()
|
||||
dialog->deleteLater();
|
||||
});
|
||||
|
||||
recentFilters->setAutoRaise(true);
|
||||
recentFilters->setIcon(Icons::filter_reapply());
|
||||
recentFilters->setToolTip(tr("Load saved filters"));
|
||||
saveFilter->setAutoRaise(true);
|
||||
saveFilter->setIcon(Icons::save());
|
||||
saveFilter->setText(tr("Save"));
|
||||
@@ -3947,7 +3945,6 @@ For searching arbitrary parameters consider using the $param() function.
|
||||
{
|
||||
filterLayout->addWidget(filterLabel);
|
||||
filterLayout->addWidget(m_FilterSettings.Filter);
|
||||
filterLayout->addWidget(recentFilters);
|
||||
filterLayout->addWidget(saveFilter);
|
||||
|
||||
layout->addLayout(filterLayout);
|
||||
|
||||
@@ -350,23 +350,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="recentFilters">
|
||||
<property name="toolTip">
|
||||
<string>Saved filters</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../Resources/resources.qrc">
|
||||
<normaloff>:/filter_reapply.png</normaloff>:/filter_reapply.png</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="filterSettings">
|
||||
<property name="toolTip">
|
||||
|
||||
Reference in New Issue
Block a user