From 2433a173dc5223b172c69526533951ccd10f9775 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 28 Jun 2024 10:52:55 -0500 Subject: [PATCH] Set it so live view disables floating dock by default because of bug. Added auto hide for files tab --- src/mvc/AnnimateSlideWidget.cpp | 53 ++++++++++++++++ src/mvc/AnnimateSlideWidget.h | 95 ++++++++++++++++++++++++++++ src/mvc/ImageStackControlWidget.cpp | 27 ++++++-- src/mvc/ImageStackControlWidget.h | 6 +- src/mvc/LiveMapsElementsWidget.cpp | 2 +- src/mvc/MapsElementsWidget.cpp | 32 +++++----- src/mvc/MapsElementsWidget.h | 4 +- src/mvc/MapsWorkspaceFilesWidget.cpp | 1 + src/mvc/ScanQueueWidget.cpp | 2 +- 9 files changed, 198 insertions(+), 24 deletions(-) create mode 100644 src/mvc/AnnimateSlideWidget.cpp create mode 100644 src/mvc/AnnimateSlideWidget.h diff --git a/src/mvc/AnnimateSlideWidget.cpp b/src/mvc/AnnimateSlideWidget.cpp new file mode 100644 index 0000000..b1cda89 --- /dev/null +++ b/src/mvc/AnnimateSlideWidget.cpp @@ -0,0 +1,53 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2024, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#include +#include +//--------------------------------------------------------------------------- + +AnnimateSlideWidget::AnnimateSlideWidget(QWidget *parent) : QWidget(parent) +{ + _anim_widget = nullptr; + _anim_enabled = true; +} + +//--------------------------------------------------------------------------- + +void AnnimateSlideWidget::setAnimWidget(QWidget* w, QString btn_name) +{ + if(w != nullptr) + { + if(_btn_hover == nullptr) + { + _btn_hover = new QPushButton(btn_name); + } + _anim_widget = w; + } + + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget(_btn_hover); + layout->addWidget(_anim_widget); + + setLayout(layout); +} + +//--------------------------------------------------------------------------- + +void AnnimateSlideWidget::setAnimEnabled(bool val) +{ + if(val) + { + //_btn_hover->setVisible(true); + _anim_enabled = val; + } + else + { + _btn_hover->setVisible(false); + _anim_enabled = val; + } +} + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/mvc/AnnimateSlideWidget.h b/src/mvc/AnnimateSlideWidget.h new file mode 100644 index 0000000..e15929e --- /dev/null +++ b/src/mvc/AnnimateSlideWidget.h @@ -0,0 +1,95 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2024, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#ifndef AnnimateSlideWidget_H +#define AnnimateSlideWidget_H + +//--------------------------------------------------------------------------- + +//#include +#include +#include +#include + +//--------------------------------------------------------------------------- + +class AnnimateSlideWidget : public QWidget +{ + + Q_OBJECT + +public: + + AnnimateSlideWidget(QWidget *parent = nullptr); + + ~AnnimateSlideWidget(){} + + void setAnimWidget(QWidget* w, QString btn_name); + + void setAnimEnabled(bool val); + +protected: + + virtual void enterEvent(QEnterEvent *event) override + { + if(_anim_enabled) + { + // Show the widget and start the animation + if(_anim_widget!=nullptr) + { + _anim_widget->setVisible(true); + _btn_hover->setVisible(false); + } + animateSlideIn(); + } + } + + virtual void leaveEvent(QEvent *event) override + { + if(_anim_enabled) + { + // Hide the widget and start the animation + if(_anim_widget!=nullptr) + { + _anim_widget->setVisible(false); + _btn_hover->setVisible(true); + } + animateSlideOut(); + } + } + +private slots: + void animateSlideIn() + { + // Animate the widget to slide in + QPropertyAnimation *animation = new QPropertyAnimation(this, "visibleWidth"); + animation->setDuration(1000); + animation->setStartValue(0); + animation->setEndValue(width()); + animation->start(); + } + + void animateSlideOut() + { + // Animate the widget to slide out + QPropertyAnimation *animation = new QPropertyAnimation(this, "visibleWidth"); + animation->setDuration(1000); + animation->setStartValue(width()); + animation->setEndValue(0); + animation->start(); + } + +private: + QWidget* _anim_widget; + QPushButton* _btn_hover; + bool _anim_enabled; + +}; + +//--------------------------------------------------------------------------- + +#endif /* TXM_ABSTRACT_WINDOW_CONTROLLER_H */ + +//--------------------------------------------------------------------------- diff --git a/src/mvc/ImageStackControlWidget.cpp b/src/mvc/ImageStackControlWidget.cpp index f4dea9a..f0d5e26 100644 --- a/src/mvc/ImageStackControlWidget.cpp +++ b/src/mvc/ImageStackControlWidget.cpp @@ -104,22 +104,27 @@ void ImageStackControlWidget::createLayout() _files_dock = new QDockWidget("Files", this); _files_dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); _files_dock->setWidget(_mapsFilsWidget); + connect(_files_dock, &QDockWidget::topLevelChanged, this, &ImageStackControlWidget::onDockFloatChanged); - hlayout2->addWidget(_files_dock); + //hlayout2->addWidget(_files_dock); - QWidget *leftWidget = new QWidget(); - leftWidget->setLayout(hlayout2); + _files_anim_widget = new AnnimateSlideWidget(); + //QWidget *leftWidget = new QWidget(); + //leftWidget->setLayout(hlayout2); + _files_anim_widget->setAnimWidget(_files_dock, ">"); QWidget *rightWidget = new QWidget(); rightWidget->setLayout(vlayout); QSplitter* single_data_splitter = new QSplitter(); single_data_splitter->setOrientation(Qt::Horizontal); - single_data_splitter->addWidget(leftWidget); + single_data_splitter->addWidget(_files_anim_widget); single_data_splitter->setStretchFactor(0, 1); single_data_splitter->addWidget(rightWidget); //createToolBar(m_imageViewWidget); //counts_layout->addWidget(m_toolbar); //counts_layout->addWidget(splitter); + single_data_splitter->setCollapsible(0, true); + single_data_splitter->setCollapsible(1, false); _load_progress = new QProgressBar(); @@ -182,6 +187,20 @@ void ImageStackControlWidget::model_IndexChanged(const QString &text) //--------------------------------------------------------------------------- +void ImageStackControlWidget::onDockFloatChanged(bool floating) +{ + if(floating) + { + _files_anim_widget->setAnimEnabled(false); + } + else + { + _files_anim_widget->setAnimEnabled(true); + } +} + +//--------------------------------------------------------------------------- + void ImageStackControlWidget::onPrevFilePressed() { int idx = _image_name_cb->currentIndex(); diff --git a/src/mvc/ImageStackControlWidget.h b/src/mvc/ImageStackControlWidget.h index a704213..4e4373e 100644 --- a/src/mvc/ImageStackControlWidget.h +++ b/src/mvc/ImageStackControlWidget.h @@ -19,6 +19,7 @@ #include "mvc/MDA_Widget.h" #include "mvc/MapsElementsWidget.h" #include "mvc/MapsWorkspaceFilesWidget.h" +#include "mvc/AnnimateSlideWidget.h" //--------------------------------------------------------------------------- @@ -70,6 +71,8 @@ public slots: void onLinkRegionToDataset(QString item_name, QString vlm_file_path, QImage image); void onChangeDatasetName(const QString& name); + + void onDockFloatChanged(bool floating); protected: void closeEvent(QCloseEvent *event); @@ -105,7 +108,8 @@ public slots: QDockWidget* _files_dock; QDockWidget* _nav_dock; - //QDialog _raw_file_dialog; + + AnnimateSlideWidget* _files_anim_widget; }; diff --git a/src/mvc/LiveMapsElementsWidget.cpp b/src/mvc/LiveMapsElementsWidget.cpp index 82b3220..2d5ed64 100644 --- a/src/mvc/LiveMapsElementsWidget.cpp +++ b/src/mvc/LiveMapsElementsWidget.cpp @@ -96,7 +96,7 @@ void LiveMapsElementsWidget::createLayout() // _textEdit = new QTextEdit(this); // _textEdit->resize(1024, 800); // _textEdit->scrollBarWidgets(Qt::AlignRight); - _mapsElementsWidget = new MapsElementsWidget(1,1,true,this); + _mapsElementsWidget = new MapsElementsWidget(1,1,true,false); //_mapsElementsWidget->setTabVisible(1, false); _mapsElementsWidget->setTabVisible(2, false); _mapsElementsWidget->setTabVisible(3, false); diff --git a/src/mvc/MapsElementsWidget.cpp b/src/mvc/MapsElementsWidget.cpp index fb872f9..0fcc87c 100644 --- a/src/mvc/MapsElementsWidget.cpp +++ b/src/mvc/MapsElementsWidget.cpp @@ -30,7 +30,7 @@ using gstar::ImageViewWidget; //--------------------------------------------------------------------------- -MapsElementsWidget::MapsElementsWidget(int rows, int cols, bool create_image_nav, QWidget* parent) +MapsElementsWidget::MapsElementsWidget(int rows, int cols, bool create_image_nav, bool restore_floating, QWidget* parent) : AbstractImageWidget(rows, cols, parent) { @@ -67,7 +67,7 @@ MapsElementsWidget::MapsElementsWidget(int rows, int cols, bool create_image_nav connect(&_img_seg_diag, &ImageSegRoiDialog::onNewROIs, this, &MapsElementsWidget::on_add_new_ROIs); setAttribute(Qt::WA_DeleteOnClose, true); connect(this, SIGNAL(destroyed()), this, SLOT(closeEvent())); - _createLayout(create_image_nav); + _createLayout(create_image_nav, restore_floating); } //--------------------------------------------------------------------------- @@ -88,7 +88,7 @@ MapsElementsWidget::~MapsElementsWidget() //--------------------------------------------------------------------------- -void MapsElementsWidget::_createLayout(bool create_image_nav) +void MapsElementsWidget::_createLayout(bool create_image_nav, bool restore_floating) { QHBoxLayout *tmp_layout; @@ -378,21 +378,23 @@ void MapsElementsWidget::_createLayout(bool create_image_nav) setLayout(layout); - - for (auto& mItr : _dockMap) + if(restore_floating) { - QVariant variant = Preferences::inst()->getValue(mItr.first+"_floating"); - if (variant.isValid()) + for (auto& mItr : _dockMap) { - mItr.second->setFloating(variant.toBool()); - } - variant = Preferences::inst()->getValue(mItr.first + "_geometry"); - if (variant.isValid()) - { - mItr.second->restoreGeometry(variant.toByteArray()); + QVariant variant = Preferences::inst()->getValue(mItr.first+"_floating"); + if (variant.isValid()) + { + mItr.second->setFloating(variant.toBool()); + } + variant = Preferences::inst()->getValue(mItr.first + "_geometry"); + if (variant.isValid()) + { + mItr.second->restoreGeometry(variant.toByteArray()); + } + + connect(mItr.second, &QDockWidget::topLevelChanged, this, &MapsElementsWidget::onDockFloatChanged); } - - connect(mItr.second, &QDockWidget::topLevelChanged, this, &MapsElementsWidget::onDockFloatChanged); } } diff --git a/src/mvc/MapsElementsWidget.h b/src/mvc/MapsElementsWidget.h index b799ad7..801ff8f 100644 --- a/src/mvc/MapsElementsWidget.h +++ b/src/mvc/MapsElementsWidget.h @@ -49,7 +49,7 @@ class MapsElementsWidget /** * Constructor. */ - MapsElementsWidget(int rows = 1, int cols = 1, bool create_image_nav=false, QWidget* parent = nullptr); + MapsElementsWidget(int rows = 1, int cols = 1, bool create_image_nav=false, bool restore_floating=true, QWidget* parent = nullptr); /** * Destructor. @@ -136,7 +136,7 @@ public slots: /** * @brief Create layout */ - void _createLayout(bool create_image_nav); + void _createLayout(bool create_image_nav, bool restore_floating); virtual void createActions(); diff --git a/src/mvc/MapsWorkspaceFilesWidget.cpp b/src/mvc/MapsWorkspaceFilesWidget.cpp index c59d2f4..3db1cb0 100644 --- a/src/mvc/MapsWorkspaceFilesWidget.cpp +++ b/src/mvc/MapsWorkspaceFilesWidget.cpp @@ -45,6 +45,7 @@ MapsWorkspaceFilesWidget::~MapsWorkspaceFilesWidget() void MapsWorkspaceFilesWidget::createLayout() { + std::vector bound_types {"Not Initialized", "Fixed", "Limited Low High", "Limited Low", "Limited High", "Fit"}; _lbl_workspace = new QLabel(); _tab_widget = new QTabWidget(); diff --git a/src/mvc/ScanQueueWidget.cpp b/src/mvc/ScanQueueWidget.cpp index 9640e91..65a1215 100644 --- a/src/mvc/ScanQueueWidget.cpp +++ b/src/mvc/ScanQueueWidget.cpp @@ -50,7 +50,7 @@ void ScanQueueWidget::_createLayout() hlayout->addWidget(_btn_update); layout->addLayout(hlayout); - _mapsElementsWidget = new MapsElementsWidget(1,1,true,this); + _mapsElementsWidget = new MapsElementsWidget(1,1,true); //_mapsElementsWidget->setTabVisible(1, false); _mapsElementsWidget->setTabVisible(2, false); _mapsElementsWidget->setTabVisible(3, false);