-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft for Issue1123 - Expandable Transfer Function #3698
base: main
Are you sure you want to change the base?
Changes from all commits
9129412
0c8140d
0331407
43c98ed
f5755c5
18f454a
23b975e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "PTFEditor.h" | ||
#include <vapor/RenderParams.h> | ||
#include <vapor/GUIStateParams.h> | ||
#include "TFColorWidget.h" | ||
#include "TFOpacityWidget.h" | ||
#include "TFHistogramWidget.h" | ||
|
@@ -28,22 +29,24 @@ template class PTFMapWidget<TFIsoValueWidget>; | |
|
||
PTFEditor::PTFEditor() : PTFEditor(RenderParams::_variableNameTag) {} | ||
|
||
PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, const std::string &label) : PWidget(tag, _section = new VSection(label.empty() ? tag : label)) | ||
PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, const std::string &label, bool expandable) : PWidget(tag, _section = new VSection(label.empty() ? tag : label)), _expandable(expandable) | ||
{ | ||
_maps = new TFMapGroupWidget; | ||
_histogram = new TFHistogramMap(tag); | ||
_opacityMap = new TFOpacityMap(tag); | ||
_colorMap = new TFColorMap(tag); | ||
_isoMap = new TFIsoValueMap(tag); | ||
_range = new TFMappingRangeSelector(tag); | ||
_elements = elements; | ||
_label = label; | ||
|
||
_maps->Add({_opacityMap, _histogram}); | ||
_maps->Add(_isoMap); | ||
_maps->Add(_colorMap); | ||
|
||
_section->layout()->addWidget(_maps); | ||
_section->layout()->addWidget(_maps, 1); | ||
_section->layout()->addWidget(_mapsInfo = _maps->CreateInfoGroup()); | ||
_section->layout()->addWidget(_range); | ||
_section->layout()->addWidget(_range, 0); | ||
connect(_range, SIGNAL(ValueChangedIntermediate(float, float)), _histogram, SLOT(update())); | ||
|
||
int start = 0; | ||
|
@@ -63,6 +66,11 @@ PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, c | |
_histogram->PopulateSettingsMenu(menu); | ||
for (int i = start; i < menu->actions().size(); i++) _histogramActions.push_back(menu->actions()[i]); | ||
|
||
if (_expandable) { | ||
_section->setExpandedSection(); | ||
connect(_section, &VSection::expandButtonClicked, this, &PTFEditor::showExpandedPTFEditor); | ||
} | ||
|
||
_section->setMenu(menu); | ||
|
||
_histogram->hide(); | ||
|
@@ -134,4 +142,57 @@ void PTFEditor::updateGUI() const | |
for (auto a : _histogramActions) a->setEnabled(_histogram->IsShown()); | ||
} | ||
|
||
void PTFEditor::Update(VAPoR::ParamsBase *params, VAPoR::ParamsMgr *paramsMgr, VAPoR::DataMgr *dataMgr) { | ||
PWidget::Update(params, paramsMgr, dataMgr); | ||
if (_expandable==true) { | ||
std::string name, inst; | ||
getExpandedPTFEditorInfo(name, inst); | ||
|
||
if (_expandedPTFEditor!=nullptr) { | ||
_expandedPTFEditor->setWindowTitle(QString::fromStdString(name)); | ||
_expandedPTFEditor->Update(params, paramsMgr, dataMgr); | ||
} | ||
} | ||
} | ||
|
||
void PTFEditor::getExpandedPTFEditorInfo(std::string &name, std::string& type) { | ||
ParamsMgr* pm = getParamsMgr(); | ||
GUIStateParams* p = dynamic_cast<GUIStateParams *>(pm->GetParams(GUIStateParams::GetClassType())); | ||
type = p->GetActiveRendererInst(); | ||
p->GetActiveRenderer(p->GetActiveVizName(), type, name); | ||
if (dynamic_cast<PColormapTFEditor*>(this)) { | ||
name+="_Colormap"; | ||
type+="_Colormap"; | ||
} | ||
} | ||
|
||
void PTFEditor::showExpandedPTFEditor() { | ||
if (_expandedPTFEditor==nullptr) { | ||
_expandedPTFEditor = new PTFEditor(_tag, _elements, _label, false); | ||
connect(_expandedPTFEditor, SIGNAL(closed()), this, SLOT(closeExpandedPTFEditor())); | ||
|
||
if (_showColormapBasedOnParam==true) _expandedPTFEditor->ShowColormapBasedOnParam(_showColormapBasedOnParamTag, _showColormapBasedOnParamValue); | ||
if (_showOpacityBasedOnParam==true) _expandedPTFEditor->ShowOpacityBasedOnParam(_showOpacityBasedOnParamTag, _showOpacityBasedOnParamValue); | ||
|
||
_expandedPTFEditor->setAttribute(Qt::WA_ShowWithoutActivating); | ||
_expandedPTFEditor->setAttribute(Qt::WA_DeleteOnClose); | ||
} | ||
_expandedPTFEditor->raise(); | ||
|
||
// It was originally thought to store the open expanded PTFEditors in GUIStateParams. | ||
// This lead to problems and the team agreed that it's not important to restore them if | ||
// they were expanded in a session, so we manually call Update here. | ||
Update(getParams(), getParamsMgr(), getDataMgr()); | ||
} | ||
|
||
void PTFEditor::closeExpandedPTFEditor() { | ||
_expandedPTFEditor->close(); | ||
_expandedPTFEditor=nullptr; | ||
} | ||
|
||
void PTFEditor::closeEvent(QCloseEvent* event) { | ||
emit closed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to specifically capture the expanded PTFEditor's closeEvent so the containing PTFEditor can then set the expanded to nullptr. If we don't, then the checks for _expandedPTFEditor==nullptr will fail, particularly in PTFEditor::showExpandedPTFEditor(). |
||
close(); | ||
} | ||
|
||
PColormapTFEditor::PColormapTFEditor() : PTFEditor(RenderParams::_colorMapVariableNameTag, {PTFEditor::Histogram, PTFEditor::Colormap}, "Colormap Transfer Function") {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ class PWidget : public UWidget { | |
VAPoR::ParamsBase *_params = nullptr; | ||
VAPoR::ParamsMgr * _paramsMgr = nullptr; | ||
VAPoR::DataMgr * _dataMgr = nullptr; | ||
const std::string _tag; | ||
|
||
bool _showBasedOnParam = false; | ||
std::string _showBasedOnParamTag = ""; | ||
|
@@ -55,6 +54,8 @@ class PWidget : public UWidget { | |
void setToolTip(const QString &) = delete; | ||
|
||
protected: | ||
const std::string _tag; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should remain private. |
||
|
||
virtual void updateGUI() const = 0; | ||
virtual bool requireParamsMgr() const { return false; } | ||
virtual bool requireDataMgr() const { return false; } | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#include "TFMapWidget.h" | ||
#include "TFColorWidget.h" | ||
#include "TFIsoValueWidget.h" | ||
#include <QPainter> | ||
#include <QResizeEvent> | ||
#include <QMenu> | ||
|
@@ -199,6 +201,11 @@ TFMapWidget::TFMapWidget(TFMap *map) | |
AddMap(map); | ||
setContextMenuPolicy(Qt::CustomContextMenu); | ||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(_showContextMenu(const QPoint &))); | ||
|
||
// Is there a better way or place to set the sizePolicy of this object? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could do it in the subclass constructor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subclass isn't a QWidget though. It needs to be done in the TFMapWidget, not the TFMap :\ |
||
if (dynamic_cast<TFColorMap*>(map)) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); | ||
else if (dynamic_cast<TFIsoValueMap*>(map)) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); | ||
else setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | ||
} | ||
|
||
TFMapWidget::~TFMapWidget() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,16 @@ void VSection::setMenu(QMenu *menu) | |
menuButton->setMenu(menu); | ||
} | ||
|
||
void VSection::setExpandedSection() | ||
{ | ||
ExpandSectionButton *expandSectionButton = (ExpandSectionButton *)QTabWidget::cornerWidget(); | ||
if (!expandSectionButton) { | ||
expandSectionButton = new ExpandSectionButton; | ||
QTabWidget::setCornerWidget(expandSectionButton, Qt::TopLeftCorner); | ||
} | ||
connect(expandSectionButton, &QToolButton::clicked, this, [this](){ emit this->expandButtonClicked(); }); | ||
} | ||
|
||
QWidget *VSection::_tab() const { return QTabWidget::widget(0); } | ||
|
||
QString VSection::_createStylesheet() const | ||
|
@@ -39,6 +49,13 @@ QString VSection::_createStylesheet() const | |
right: 3px; | ||
} | ||
)"; | ||
stylesheet += | ||
R"( | ||
QTabWidget::left-corner { | ||
top: 24px; | ||
left: 3px; | ||
} | ||
)"; | ||
#else | ||
stylesheet += | ||
R"( | ||
|
@@ -47,6 +64,13 @@ QString VSection::_createStylesheet() const | |
right: 5px; | ||
} | ||
)"; | ||
stylesheet += | ||
R"( | ||
QTabWidget::left-corner { | ||
top: -3px; | ||
right: 5px; | ||
} | ||
)"; | ||
#endif | ||
|
||
return QString::fromStdString(stylesheet); | ||
|
@@ -75,3 +99,28 @@ void VSection::SettingsMenuButton::paintEvent(QPaintEvent *event) | |
option.features = QStyleOptionToolButton::None; | ||
p.drawComplexControl(QStyle::CC_ToolButton, option); | ||
} | ||
|
||
VSection::ExpandSectionButton::ExpandSectionButton() | ||
{ | ||
setIcon(QIcon(QString::fromStdString(Wasp::GetSharePath("images/expandSection.png")))); | ||
setIconSize(QSize(18, 18)); | ||
setCursor(QCursor(Qt::PointingHandCursor)); | ||
setPopupMode(QToolButton::InstantPopup); | ||
|
||
setStyleSheet("border: none;" | ||
"background-color: none;" | ||
"padding: 0px;"); | ||
} | ||
|
||
void VSection::ExpandSectionButton::paintEvent(QPaintEvent *event) | ||
{ | ||
// This function is overridden to prevent Qt from drawing its own dropdown arrow | ||
QStylePainter p(this); | ||
|
||
QStyleOptionToolButton option; | ||
initStyleOption(&option); | ||
option.subControls = QStyle::SC_ToolButton; | ||
option.features = QStyleOptionToolButton::None; | ||
p.drawComplexControl(QStyle::CC_ToolButton, option); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,13 @@ class VSection : public QTabWidget { | |
Q_OBJECT | ||
|
||
class SettingsMenuButton; | ||
class ExpandSectionButton; | ||
|
||
public: | ||
VSection(const std::string &title); | ||
QVBoxLayout *layout() const; | ||
void setMenu(QMenu *menu); | ||
void setExpandedSection(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method is called |
||
|
||
void setLayout(QLayout *layout) = delete; | ||
int addTab(QWidget *page, const QString &label) = delete; | ||
|
@@ -34,6 +36,9 @@ class VSection : public QTabWidget { | |
private: | ||
QWidget *_tab() const; | ||
QString _createStylesheet() const; | ||
|
||
signals: | ||
void expandButtonClicked(); | ||
}; | ||
|
||
#include "AbstractWidgetGroup.h" | ||
|
@@ -61,3 +66,13 @@ class VSection::SettingsMenuButton : public QToolButton { | |
protected: | ||
void paintEvent(QPaintEvent *event); | ||
}; | ||
|
||
class VSection::ExpandSectionButton: public QToolButton { | ||
Q_OBJECT | ||
|
||
public: | ||
ExpandSectionButton(); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label parameter should be held by the VSection rather than in the subclass. Also, it is optional which is not being handled.