Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 2a6cf6d9 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

UIParamPath added.

parent 7d6514bd
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#include "UIParamPath.h"
UIParamPath::UIParamPath( const QString& id,
const QString& name,
const QString& description,
const QString& value,
bool dirOnly,
bool mustExist ) :
UIParam(id,name,description),
m_DirOnly( dirOnly ),
m_MustExist( mustExist )
{
QHBoxLayout *l = new QHBoxLayout();
l->setContentsMargins( 0, 0, 0, 0 );
l->setSpacing( 2 );
m_Path = new QComboBox();
m_Path->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_Path->setEditable( true );
m_Path->addItem( value );
connect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
QPushButton *chooseButton = new QPushButton( "Choose" );
connect( chooseButton, SIGNAL(clicked()), this, SLOT(openFileDialog()) );
l->addWidget( m_Path );
l->addWidget( chooseButton );
m_Widget = new QWidget();
m_Widget->setLayout( l );
connect( (QCheckBox*)m_Widget, SIGNAL(stateChanged(int)), this, SLOT(triggerValueChanged(int)) );
}
void UIParamPath::openFileDialog()
{
QString selected;
if( m_DirOnly )
selected = QFileDialog::getExistingDirectory( NULL, "Select directory", m_Path->currentText() );
else if( m_MustExist )
selected = QFileDialog::getOpenFileName( NULL, "Select directory", m_Path->currentText() );
else
selected = QFileDialog::getSaveFileName( NULL, "Select directory", m_Path->currentText() );
if( !selected.isEmpty() )
{
m_Path->clear();
m_Path->addItem( selected );
}
}
void UIParamPath::editPath( const QString& text )
{
QDir pathDir( text );
if( pathDir.exists() )
{
m_LastValidDir = text;
m_LastDirContent = pathDir.entryList( QDir::NoDotAndDotDot | (m_DirOnly? QDir::Dirs : QDir::Files), QDir::SortFlag::Name );
m_TryCompletion = (!m_LastDirContent.isEmpty() && text.at(text.length()-1) == '/');
}
if( m_TryCompletion )
{
disconnect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
QString incompleteEntry = text.right( text.size() - m_LastValidDir.size() );
QStringList filteredContent = m_LastDirContent;
for( int n=0; n<incompleteEntry.length(); ++n )
{
for( auto s=filteredContent.begin(); s!=filteredContent.end(); )
if( (*s)[n].toLower() != incompleteEntry[n].toLower() )
s = filteredContent.erase( s );
else
++ s;
}
for( auto &s : filteredContent )
s = m_LastValidDir + s;
filteredContent.push_front( text );
m_Path->clear();
m_Path->addItems( filteredContent );
connect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
}
}
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifndef __UIPARAMPATH_H__
#define __UIPARAMPATH_H__
#include "UIParam.h"
class UIParamPath : public UIParam
{
Q_OBJECT
QComboBox *m_Path;
QString m_LastValidDir;
QStringList m_LastDirContent;
bool m_TryCompletion = false;
bool m_DirOnly;
bool m_MustExist;
public:
UIParamPath( const QString& id,
const QString& name,
const QString& description,
const QString& value,
bool dirOnly,
bool mustExist );
//inline void SetValue( const QString &value ) { m_Path->setText( value ); }
inline QString Value() const { return m_Path->currentText(); }
inline const QWidget* Widget() const { return m_Widget; }
inline QWidget* Widget() { return m_Widget; }
inline void ConnectModificationSignal();
signals:
void valueChanged( bool );
private slots:
inline void triggerValueChanged( int state ) { emit valueChanged( state == Qt::Checked ); }
void openFileDialog();
void editPath( const QString& text );
};
inline void UIParamPath::ConnectModificationSignal()
{
QObject::connect( Widget(), SIGNAL(stateChanged(int)), this, SLOT(triggerParameterUpdate()) );
}
#endif // __UIPARAMPATH_H__
......@@ -33,6 +33,7 @@
#include "UIParamAnimation.h"
#include "UIParamChildren.h"
#include "UIParamSlider.h"
#include "UIParamPath.h"
......@@ -124,6 +125,7 @@ public:
inline UIParamGradient* GetGradient ( const QString &paramName ) const { return GetParam<UIParamGradient >( paramName ); }
inline UIParamChildren* GetChild ( const QString &paramName ) const { return GetParam<UIParamChildren >( paramName ); }
inline UIParamSlider* GetSlider ( const QString &paramName ) const { return GetParam<UIParamSlider >( paramName ); }
inline UIParamPath* GetPath ( const QString &paramName ) const { return GetParam<UIParamPath >( paramName ); }
inline UIParamAnimation* GetAnimationCtrl () const { return m_AnimationCtrl; }
inline const QList<UIParamAction*>& GetActions() const { return m_Actions; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment