breadcrumbs
This commit is contained in:
parent
2d70a6ae42
commit
0894d6457d
|
@ -14,8 +14,8 @@
|
||||||
#include "QskSelectionSubWindow.h"
|
#include "QskSelectionSubWindow.h"
|
||||||
#include "QskSelectionWindow.h"
|
#include "QskSelectionWindow.h"
|
||||||
|
|
||||||
|
#include "QskPushButton.h"
|
||||||
#include "QskSimpleListBox.h"
|
#include "QskSimpleListBox.h"
|
||||||
#include "QskTextLabel.h"
|
|
||||||
|
|
||||||
#include "QskFocusIndicator.h"
|
#include "QskFocusIndicator.h"
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileSelection
|
class FileSelection // ### looks like we don't need this class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileSelection( QObject* parent, const QString& directory )
|
FileSelection( QObject* parent, const QString& directory )
|
||||||
|
@ -167,7 +167,7 @@ namespace
|
||||||
{
|
{
|
||||||
Q_UNUSED( parent )
|
Q_UNUSED( parent )
|
||||||
|
|
||||||
m_dir.setFilter( QDir::Files | QDir::NoDotAndDotDot );
|
m_dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString selectedFile() const
|
QString selectedFile() const
|
||||||
|
@ -180,6 +180,11 @@ namespace
|
||||||
return m_dir;
|
return m_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCurrentDir( const QString& path )
|
||||||
|
{
|
||||||
|
m_dir.setPath( path );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDir m_dir;
|
QDir m_dir;
|
||||||
};
|
};
|
||||||
|
@ -195,8 +200,10 @@ namespace
|
||||||
: WindowOrSubWindow< W, FileSelection, QString >( parent, title, actions, defaultAction, directory )
|
: WindowOrSubWindow< W, FileSelection, QString >( parent, title, actions, defaultAction, directory )
|
||||||
{
|
{
|
||||||
auto* outerBox = new QskLinearBox( Qt::Vertical );
|
auto* outerBox = new QskLinearBox( Qt::Vertical );
|
||||||
|
outerBox->setMargins( 20 );
|
||||||
|
outerBox->setSpacing( 20 );
|
||||||
#if 1
|
#if 1
|
||||||
outerBox->setPreferredSize( 500, 500 );
|
outerBox->setFixedSize( 500, 500 );
|
||||||
#endif
|
#endif
|
||||||
setupHeader( outerBox );
|
setupHeader( outerBox );
|
||||||
setupListBox( outerBox );
|
setupListBox( outerBox );
|
||||||
|
@ -207,30 +214,94 @@ namespace
|
||||||
private:
|
private:
|
||||||
void setupHeader( QQuickItem* parentItem )
|
void setupHeader( QQuickItem* parentItem )
|
||||||
{
|
{
|
||||||
m_header = new QskTextLabel( parentItem );
|
m_headerBox = new QskLinearBox( Qt::Horizontal, parentItem );
|
||||||
const auto path = FileSelection::currentDir().absolutePath();
|
m_headerBox->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
||||||
updateHeader( path );
|
}
|
||||||
|
|
||||||
|
static QStringList splitPath( const QString& path )
|
||||||
|
{
|
||||||
|
const auto cleanPath = QDir::cleanPath( path );
|
||||||
|
|
||||||
|
QDir dir( cleanPath );
|
||||||
|
|
||||||
|
QStringList result;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if( dir != QDir::root() )
|
||||||
|
{
|
||||||
|
result.prepend( dir.absolutePath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while( dir.cdUp() );
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateHeader( const QString& path )
|
void updateHeader( const QString& path )
|
||||||
{
|
{
|
||||||
// m_header->setText( s );
|
const auto dirPaths = splitPath( path );
|
||||||
|
|
||||||
|
for( int i = 0; i < dirPaths.count(); ++i )
|
||||||
|
{
|
||||||
|
QskPushButton* b;
|
||||||
|
|
||||||
|
if( m_breadcrumbsButtons.count() <= i )
|
||||||
|
{
|
||||||
|
b = new QskPushButton( m_headerBox );
|
||||||
|
b->setStrutSizeHint( QskPushButton::Panel, { -1, -1 } );
|
||||||
|
m_breadcrumbsButtons.append( b );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
b = m_breadcrumbsButtons.at( i );
|
||||||
|
b->disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo fi( dirPaths.at( i ) );
|
||||||
|
b->setText( fi.baseName() );
|
||||||
|
|
||||||
|
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
||||||
|
{
|
||||||
|
FileSelection::setCurrentDir( fi.filePath() );
|
||||||
|
loadContents( fi.filePath() );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = dirPaths.count(); i < m_breadcrumbsButtons.count(); i++ )
|
||||||
|
{
|
||||||
|
m_breadcrumbsButtons.at( i )->deleteLater();
|
||||||
|
m_breadcrumbsButtons.removeAt( i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupListBox( QQuickItem* parentItem )
|
void setupListBox( QQuickItem* parentItem )
|
||||||
{
|
{
|
||||||
m_listBox = new QskSimpleListBox( parentItem );
|
m_listBox = new QskSimpleListBox( parentItem );
|
||||||
loadContents();
|
|
||||||
|
QObject::connect( m_listBox, &QskSimpleListBox::selectedEntryChanged,
|
||||||
|
this, [this]( const QString& path )
|
||||||
|
{
|
||||||
|
QDir dir = FileSelection::currentDir();
|
||||||
|
dir.cd( path );
|
||||||
|
loadContents( dir.absolutePath() );
|
||||||
|
});
|
||||||
|
|
||||||
|
loadContents( FileSelection::currentDir().absolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadContents()
|
void loadContents( const QString& path )
|
||||||
{
|
{
|
||||||
m_listBox->removeBulk( 0 );
|
m_listBox->removeBulk( 0 );
|
||||||
|
FileSelection::setCurrentDir( path );
|
||||||
m_listBox->setEntries( FileSelection::currentDir().entryList() );
|
m_listBox->setEntries( FileSelection::currentDir().entryList() );
|
||||||
|
|
||||||
|
updateHeader( FileSelection::currentDir().path() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskSimpleListBox* m_listBox;
|
QskSimpleListBox* m_listBox;
|
||||||
QskTextLabel* m_header;
|
QskLinearBox* m_headerBox;
|
||||||
|
QVector< QskPushButton* > m_breadcrumbsButtons;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue