Skip to content

Commit

Permalink
Set it so live view disables floating dock by default because of bug.…
Browse files Browse the repository at this point in the history
… Added auto hide for files tab
  • Loading branch information
Arthur Glowacki committed Jun 28, 2024
1 parent 300f285 commit 2433a17
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 24 deletions.
53 changes: 53 additions & 0 deletions src/mvc/AnnimateSlideWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*-----------------------------------------------------------------------------
* Copyright (c) 2024, UChicago Argonne, LLC
* See LICENSE file.
*---------------------------------------------------------------------------*/

#include <mvc/AnnimateSlideWidget.h>
#include <QHBoxLayout>
//---------------------------------------------------------------------------

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;
}
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
95 changes: 95 additions & 0 deletions src/mvc/AnnimateSlideWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*-----------------------------------------------------------------------------
* Copyright (c) 2024, UChicago Argonne, LLC
* See LICENSE file.
*---------------------------------------------------------------------------*/

#ifndef AnnimateSlideWidget_H
#define AnnimateSlideWidget_H

//---------------------------------------------------------------------------

//#include <preferences/Preferences.h>
#include <QWidget>
#include <QPropertyAnimation>
#include <QPushButton>

//---------------------------------------------------------------------------

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 */

//---------------------------------------------------------------------------
27 changes: 23 additions & 4 deletions src/mvc/ImageStackControlWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/mvc/ImageStackControlWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "mvc/MDA_Widget.h"
#include "mvc/MapsElementsWidget.h"
#include "mvc/MapsWorkspaceFilesWidget.h"
#include "mvc/AnnimateSlideWidget.h"

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -105,7 +108,8 @@ public slots:
QDockWidget* _files_dock;

QDockWidget* _nav_dock;
//QDialog _raw_file_dialog;

AnnimateSlideWidget* _files_anim_widget;

};

Expand Down
2 changes: 1 addition & 1 deletion src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 17 additions & 15 deletions src/mvc/MapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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);
}

//---------------------------------------------------------------------------
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/mvc/MapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/mvc/MapsWorkspaceFilesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MapsWorkspaceFilesWidget::~MapsWorkspaceFilesWidget()

void MapsWorkspaceFilesWidget::createLayout()
{

std::vector<std::string> bound_types {"Not Initialized", "Fixed", "Limited Low High", "Limited Low", "Limited High", "Fit"};
_lbl_workspace = new QLabel();
_tab_widget = new QTabWidget();
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2433a17

Please sign in to comment.