fix build for Qt 5.15
This commit is contained in:
parent
c3af2de74e
commit
74c5178ce4
|
@ -7,12 +7,21 @@
|
||||||
|
|
||||||
#include "QskEvent.h"
|
#include "QskEvent.h"
|
||||||
#include "QskFunctions.h"
|
#include "QskFunctions.h"
|
||||||
|
#include "QskInternalMacros.h"
|
||||||
#include "QskLinearBox.h"
|
#include "QskLinearBox.h"
|
||||||
#include "QskListView.h"
|
#include "QskListView.h"
|
||||||
#include "QskScrollArea.h"
|
#include "QskScrollArea.h"
|
||||||
#include "QskPushButton.h"
|
#include "QskPushButton.h"
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
#include <QDateTime>
|
||||||
|
#else
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QSK_QT_PRIVATE_BEGIN
|
||||||
|
#include <private/qquickwindow_p.h>
|
||||||
|
QSK_QT_PRIVATE_END
|
||||||
|
|
||||||
// copied from QskListView.cpp:
|
// copied from QskListView.cpp:
|
||||||
static inline int qskRowAt( const QskListView* listView, const QPointF& pos )
|
static inline int qskRowAt( const QskListView* listView, const QPointF& pos )
|
||||||
|
@ -48,18 +57,132 @@ static QMouseEvent* qskClonedMouseEvent( const QMouseEvent* event )
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
class Model : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Model( QObject* parent )
|
||||||
|
: QObject( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString rootPath() const
|
||||||
|
{
|
||||||
|
return m_dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRootPath( const QString& path )
|
||||||
|
{
|
||||||
|
m_dir.setPath( path );
|
||||||
|
m_list = m_dir.entryInfoList();
|
||||||
|
Q_EMIT directoryLoaded( m_dir.path() );
|
||||||
|
Q_EMIT rootPathChanged( m_dir.path() );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir::Filters filter() const
|
||||||
|
{
|
||||||
|
return m_dir.filter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFilter( QDir::Filters filter )
|
||||||
|
{
|
||||||
|
m_dir.setFilter( filter );
|
||||||
|
}
|
||||||
|
|
||||||
|
int rows() const
|
||||||
|
{
|
||||||
|
return m_dir.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int columns() const
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant entry( int row, int col )
|
||||||
|
{
|
||||||
|
Q_ASSERT( row < m_list.count() );
|
||||||
|
|
||||||
|
const auto fi = m_list.at( row );
|
||||||
|
|
||||||
|
switch( col )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return fi.fileName();
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if( fi.isDir() )
|
||||||
|
return "Directory";
|
||||||
|
else if( fi.isExecutable() )
|
||||||
|
return "Executable";
|
||||||
|
else
|
||||||
|
return "File";
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fi.fileTime( QFileDevice::FileAccessTime ).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void directoryLoaded( const QString& path );
|
||||||
|
void rootPathChanged( const QString& path );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDir m_dir;
|
||||||
|
QFileInfoList m_list;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
class Model : public QFileSystemModel
|
||||||
|
{
|
||||||
|
using Inherited = QFileSystemModel;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Model( QObject* parent )
|
||||||
|
: QFileSystemModel( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int rows() const
|
||||||
|
{
|
||||||
|
const auto i = index( rootPath() );
|
||||||
|
return Inherited::rowCount( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
int columns() const
|
||||||
|
{
|
||||||
|
const auto i = index( rootPath() );
|
||||||
|
return Inherited::columnCount( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant entry( int row, int col ) const
|
||||||
|
{
|
||||||
|
const auto rootIndex = index( rootPath() );
|
||||||
|
|
||||||
|
const auto i = index( row, col, rootIndex );
|
||||||
|
const auto v = data( i );
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class FileSystemView : public QskListView
|
class FileSystemView : public QskListView
|
||||||
{
|
{
|
||||||
using Inherited = QskListView;
|
using Inherited = QskListView;
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileSystemView( const QString& directory, QDir::Filters filters, QQuickItem* parent = nullptr )
|
FileSystemView( const QString& directory, QDir::Filters filters, QQuickItem* parent = nullptr )
|
||||||
: QskListView( parent )
|
: QskListView( parent )
|
||||||
, m_model( new QFileSystemModel( this ) )
|
, m_model( new Model( this ) )
|
||||||
{
|
{
|
||||||
const auto defaultWidth = 50;
|
const auto defaultWidth = 50;
|
||||||
|
|
||||||
connect( m_model, &QFileSystemModel::directoryLoaded, this, [this]()
|
connect( m_model, &Model::directoryLoaded, this, [this, defaultWidth]()
|
||||||
{
|
{
|
||||||
m_columnWidths.fill( defaultWidth );
|
m_columnWidths.fill( defaultWidth );
|
||||||
updateScrollableSize();
|
updateScrollableSize();
|
||||||
|
@ -67,23 +190,24 @@ namespace
|
||||||
setSelectedRow( -1 );
|
setSelectedRow( -1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect( m_model, &Model::rootPathChanged,
|
||||||
|
this, &FileSystemView::rootPathChanged );
|
||||||
|
|
||||||
|
m_columnWidths.fill( defaultWidth, m_model->columns() );
|
||||||
|
|
||||||
m_model->setFilter( filters );
|
m_model->setFilter( filters );
|
||||||
m_model->setRootPath( {} ); // invalidate to make sure to get an update
|
m_model->setRootPath( {} ); // invalidate to make sure to get an update
|
||||||
m_model->setRootPath( directory );
|
m_model->setRootPath( directory );
|
||||||
|
|
||||||
m_columnWidths.fill( defaultWidth, m_model->columnCount() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int rowCount() const override
|
virtual int rowCount() const override
|
||||||
{
|
{
|
||||||
const auto index = m_model->index( m_model->rootPath() );
|
return m_model->rows();
|
||||||
return m_model->rowCount( index );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int columnCount() const override
|
virtual int columnCount() const override
|
||||||
{
|
{
|
||||||
const auto index = m_model->index( m_model->rootPath() );
|
return m_model->columns();
|
||||||
return m_model->columnCount( index );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual qreal columnWidth( int col ) const override
|
virtual qreal columnWidth( int col ) const override
|
||||||
|
@ -111,10 +235,7 @@ namespace
|
||||||
|
|
||||||
virtual QVariant valueAt( int row, int col ) const override
|
virtual QVariant valueAt( int row, int col ) const override
|
||||||
{
|
{
|
||||||
const auto rootIndex = m_model->index( m_model->rootPath() );
|
const auto v = m_model->entry( row, col );
|
||||||
|
|
||||||
const auto index = m_model->index( row, col, rootIndex );
|
|
||||||
const auto v = m_model->data( index );
|
|
||||||
|
|
||||||
const auto w = qskHorizontalAdvance( effectiveFont( Text ), v.toString() );
|
const auto w = qskHorizontalAdvance( effectiveFont( Text ), v.toString() );
|
||||||
|
|
||||||
|
@ -126,13 +247,25 @@ namespace
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileSystemModel* model()
|
QString rootPath() const
|
||||||
{
|
{
|
||||||
return m_model;
|
return m_model->rootPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
void setRootPath( const QString& rootPath )
|
||||||
|
{
|
||||||
|
m_model->setRootPath( rootPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir::Filters filter() const
|
||||||
|
{
|
||||||
|
return m_model->filter();
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void rootPathChanged( const QString& rootPath );
|
||||||
|
|
||||||
|
protected:
|
||||||
void mousePressEvent( QMouseEvent* event ) override
|
void mousePressEvent( QMouseEvent* event ) override
|
||||||
{
|
{
|
||||||
if( m_doubleClickEvent && m_doubleClickEvent->timestamp() == event->timestamp() )
|
if( m_doubleClickEvent && m_doubleClickEvent->timestamp() == event->timestamp() )
|
||||||
|
@ -164,7 +297,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFileSystemModel* const m_model;
|
Model* const m_model;
|
||||||
mutable QVector< int > m_columnWidths;
|
mutable QVector< int > m_columnWidths;
|
||||||
QMouseEvent* m_doubleClickEvent = nullptr;
|
QMouseEvent* m_doubleClickEvent = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -211,7 +344,7 @@ QString QskFileSelectionWindow< W >::selectedPath() const
|
||||||
if( m_data->fileView->selectedRow() != -1 )
|
if( m_data->fileView->selectedRow() != -1 )
|
||||||
{
|
{
|
||||||
const auto path = m_data->fileView->valueAt( m_data->fileView->selectedRow(), 0 ).toString();
|
const auto path = m_data->fileView->valueAt( m_data->fileView->selectedRow(), 0 ).toString();
|
||||||
QFileInfo fi( m_data->fileView->model()->rootPath(), path );
|
QFileInfo fi( m_data->fileView->rootPath(), path );
|
||||||
return fi.absoluteFilePath();
|
return fi.absoluteFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +408,7 @@ void QskFileSelectionWindow< W >::updateHeader( const QString& path )
|
||||||
|
|
||||||
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
||||||
{
|
{
|
||||||
m_data->fileView->model()->setRootPath( fi.filePath() );
|
m_data->fileView->setRootPath( fi.filePath() );
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,12 +436,12 @@ void QskFileSelectionWindow< W >::setupFileSystemView( const QString& directory,
|
||||||
{
|
{
|
||||||
m_data->fileView = new FileSystemView( directory, filters, parentItem );
|
m_data->fileView = new FileSystemView( directory, filters, parentItem );
|
||||||
|
|
||||||
QObject::connect( m_data->fileView->model(), &QFileSystemModel::rootPathChanged,
|
QObject::connect( m_data->fileView, &FileSystemView::rootPathChanged,
|
||||||
this, &QskFileSelectionWindow< W >::updateHeader );
|
this, &QskFileSelectionWindow< W >::updateHeader );
|
||||||
|
|
||||||
QObject::connect( m_data->fileView, &QskListView::selectedRowChanged, this, [this]()
|
QObject::connect( m_data->fileView, &QskListView::selectedRowChanged, this, [this]()
|
||||||
{
|
{
|
||||||
if( m_data->fileView->model()->filter() & QDir::Files )
|
if( m_data->fileView->filter() & QDir::Files )
|
||||||
{
|
{
|
||||||
QFileInfo fi( selectedPath() );
|
QFileInfo fi( selectedPath() );
|
||||||
W::defaultButton()->setEnabled( !fi.isDir() );
|
W::defaultButton()->setEnabled( !fi.isDir() );
|
||||||
|
@ -318,3 +451,5 @@ void QskFileSelectionWindow< W >::setupFileSystemView( const QString& directory,
|
||||||
|
|
||||||
template class QskFileSelectionWindow< QskDialogWindow >;
|
template class QskFileSelectionWindow< QskDialogWindow >;
|
||||||
template class QskFileSelectionWindow< QskDialogSubWindow >;
|
template class QskFileSelectionWindow< QskDialogSubWindow >;
|
||||||
|
|
||||||
|
#include "QskFileSelectionWindow.moc"
|
||||||
|
|
|
@ -13,6 +13,44 @@
|
||||||
|
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
QStringList families()
|
||||||
|
{
|
||||||
|
QFontDatabase db;
|
||||||
|
return db.families();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList styles( const QString& family )
|
||||||
|
{
|
||||||
|
QFontDatabase db;
|
||||||
|
return db.styles( family );
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< int > pointSizes( const QString& family )
|
||||||
|
{
|
||||||
|
QFontDatabase db;
|
||||||
|
return db.pointSizes( family );
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
QStringList families()
|
||||||
|
{
|
||||||
|
return QFontDatabase::families();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList styles( const QString& family )
|
||||||
|
{
|
||||||
|
return QFontDatabase::styles( family );
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< int > pointSizes( const QString& family )
|
||||||
|
{
|
||||||
|
return QFontDatabase::pointSizes( family );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
template< typename W >
|
template< typename W >
|
||||||
class QskFontSelectionWindow< W >::PrivateData
|
class QskFontSelectionWindow< W >::PrivateData
|
||||||
{
|
{
|
||||||
|
@ -103,20 +141,18 @@ void QskFontSelectionWindow< W >::setupControls( QQuickItem* parentItem )
|
||||||
template< typename W >
|
template< typename W >
|
||||||
void QskFontSelectionWindow< W >::connectSignals()
|
void QskFontSelectionWindow< W >::connectSignals()
|
||||||
{
|
{
|
||||||
const auto families = QFontDatabase::families();
|
m_data->familyView->setEntries( families() );
|
||||||
m_data->familyView->setEntries( families );
|
|
||||||
|
|
||||||
QObject::connect( m_data->familyView, &QskSimpleListBox::selectedEntryChanged,
|
QObject::connect( m_data->familyView, &QskSimpleListBox::selectedEntryChanged,
|
||||||
this, [this]( const QString& family )
|
this, [this]( const QString& family )
|
||||||
{
|
{
|
||||||
const auto styles = QFontDatabase::styles( family );
|
m_data->styleView->setEntries( styles( family ) );
|
||||||
m_data->styleView->setEntries( styles );
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QObject::connect( m_data->familyView, &QskSimpleListBox::selectedEntryChanged,
|
QObject::connect( m_data->familyView, &QskSimpleListBox::selectedEntryChanged,
|
||||||
this, [this]( const QString& family )
|
this, [this]( const QString& family )
|
||||||
{
|
{
|
||||||
const auto sizes = QFontDatabase::pointSizes( family );
|
const auto sizes = pointSizes( family );
|
||||||
QStringList sizesString;
|
QStringList sizesString;
|
||||||
sizesString.reserve( sizes.count() );
|
sizesString.reserve( sizes.count() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue