@ -40,22 +40,24 @@
# include "base/utils/fs.h"
# include "base/utils/fs.h"
# include "base/utils/misc.h"
# include "base/utils/misc.h"
# include "previewlistdelegate.h"
# include "previewlistdelegate.h"
# include "ui_previewselectdialog.h"
# include "utils.h"
# include "utils.h"
# define SETTINGS_KEY(name) "PreviewSelectDialog / " name
# define SETTINGS_KEY(name) "PreviewSelectDialog / " name
PreviewSelectDialog : : PreviewSelectDialog ( QWidget * parent , BitTorrent : : TorrentHandle * const torrent )
PreviewSelectDialog : : PreviewSelectDialog ( QWidget * parent , BitTorrent : : TorrentHandle * const torrent )
: QDialog ( parent )
: QDialog ( parent )
, m_ui ( new Ui : : PreviewSelectDialog )
, m_torrent ( torrent )
, m_torrent ( torrent )
, m_storeDialogSize ( SETTINGS_KEY ( " Dimension " ) )
, m_storeDialogSize ( SETTINGS_KEY ( " Dimension " ) )
, m_storeTreeHeaderState ( SETTINGS_KEY ( " HeaderState " ) )
, m_storeTreeHeaderState ( SETTINGS_KEY ( " HeaderState " ) )
{
{
setupUi ( this ) ;
m_ui - > setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
buttonBox - > button ( QDialogButtonBox : : Ok ) - > setText ( tr ( " Preview " ) ) ;
m_ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setText ( tr ( " Preview " ) ) ;
connect ( buttonBox , & QDialogButtonBox : : accepted , this , & PreviewSelectDialog : : previewButtonClicked ) ;
connect ( m_ui - > buttonBox , & QDialogButtonBox : : accepted , this , & PreviewSelectDialog : : previewButtonClicked ) ;
connect ( buttonBox , & QDialogButtonBox : : rejected , this , & QDialog : : reject ) ;
connect ( m_ui - > buttonBox , & QDialogButtonBox : : rejected , this , & QDialog : : reject ) ;
Preferences * const pref = Preferences : : instance ( ) ;
Preferences * const pref = Preferences : : instance ( ) ;
// Preview list
// Preview list
@ -67,15 +69,15 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
// This hack fixes reordering of first column with Qt5.
// This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused ;
QTableView unused ;
unused . setVerticalHeader ( previewList - > header ( ) ) ;
unused . setVerticalHeader ( m_ui - > previewList - > header ( ) ) ;
previewList - > header ( ) - > setParent ( previewList ) ;
m_ui - > previewList - > header ( ) - > setParent ( m_ui - > previewList ) ;
unused . setVerticalHeader ( new QHeaderView ( Qt : : Horizontal ) ) ;
unused . setVerticalHeader ( new QHeaderView ( Qt : : Horizontal ) ) ;
previewList - > setModel ( m_previewListModel ) ;
m_ui - > previewList - > setModel ( m_previewListModel ) ;
previewList - > hideColumn ( FILE_INDEX ) ;
m_ui - > previewList - > hideColumn ( FILE_INDEX ) ;
m_listDelegate = new PreviewListDelegate ( this ) ;
m_listDelegate = new PreviewListDelegate ( this ) ;
previewList - > setItemDelegate ( m_listDelegate ) ;
m_ui - > previewList - > setItemDelegate ( m_listDelegate ) ;
previewList - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
m_ui - > previewList - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
// Fill list in
// Fill list in
QVector < qreal > fp = torrent - > filesProgress ( ) ;
QVector < qreal > fp = torrent - > filesProgress ( ) ;
int nbFiles = torrent - > filesCount ( ) ;
int nbFiles = torrent - > filesCount ( ) ;
@ -96,8 +98,8 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
connect ( this , SIGNAL ( readyToPreviewFile ( QString ) ) , parent , SLOT ( previewFile ( QString ) ) ) ;
connect ( this , SIGNAL ( readyToPreviewFile ( QString ) ) , parent , SLOT ( previewFile ( QString ) ) ) ;
m_previewListModel - > sort ( NAME ) ;
m_previewListModel - > sort ( NAME ) ;
previewList - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
m_ui - > previewList - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
previewList - > selectionModel ( ) - > select ( m_previewListModel - > index ( 0 , NAME ) , QItemSelectionModel : : Select | QItemSelectionModel : : Rows ) ;
m_ui - > previewList - > selectionModel ( ) - > select ( m_previewListModel - > index ( 0 , NAME ) , QItemSelectionModel : : Select | QItemSelectionModel : : Rows ) ;
// Restore dialog state
// Restore dialog state
loadWindowState ( ) ;
loadWindowState ( ) ;
@ -119,11 +121,12 @@ PreviewSelectDialog::~PreviewSelectDialog()
delete m_previewListModel ;
delete m_previewListModel ;
delete m_listDelegate ;
delete m_listDelegate ;
delete m_ui ;
}
}
void PreviewSelectDialog : : previewButtonClicked ( )
void PreviewSelectDialog : : previewButtonClicked ( )
{
{
QModelIndexList selectedIndexes = previewList - > selectionModel ( ) - > selectedRows ( FILE_INDEX ) ;
QModelIndexList selectedIndexes = m_ui - > previewList - > selectionModel ( ) - > selectedRows ( FILE_INDEX ) ;
if ( selectedIndexes . isEmpty ( ) ) return ;
if ( selectedIndexes . isEmpty ( ) ) return ;
// Flush data
// Flush data
@ -146,7 +149,7 @@ void PreviewSelectDialog::saveWindowState()
// Persist dialog size
// Persist dialog size
m_storeDialogSize = size ( ) ;
m_storeDialogSize = size ( ) ;
// Persist TreeView Header state
// Persist TreeView Header state
m_storeTreeHeaderState = previewList - > header ( ) - > saveState ( ) ;
m_storeTreeHeaderState = m_ui - > previewList - > header ( ) - > saveState ( ) ;
}
}
void PreviewSelectDialog : : loadWindowState ( )
void PreviewSelectDialog : : loadWindowState ( )
@ -156,7 +159,7 @@ void PreviewSelectDialog::loadWindowState()
// Restore TreeView Header state
// Restore TreeView Header state
if ( ! m_storeTreeHeaderState . value ( ) . isEmpty ( ) ) {
if ( ! m_storeTreeHeaderState . value ( ) . isEmpty ( ) ) {
m_headerStateInitialized = previewList - > header ( ) - > restoreState ( m_storeTreeHeaderState ) ;
m_headerStateInitialized = m_ui - > previewList - > header ( ) - > restoreState ( m_storeTreeHeaderState ) ;
}
}
}
}
@ -167,8 +170,8 @@ void PreviewSelectDialog::showEvent(QShowEvent *event)
// Default size, have to be called after show(), because width is needed
// Default size, have to be called after show(), because width is needed
// Set Name column width to 60% of TreeView
// Set Name column width to 60% of TreeView
if ( ! m_headerStateInitialized ) {
if ( ! m_headerStateInitialized ) {
int nameSize = ( previewList - > size ( ) . width ( ) * 0.6 ) ;
int nameSize = ( m_ui - > previewList - > size ( ) . width ( ) * 0.6 ) ;
previewList - > header ( ) - > resizeSection ( 0 , nameSize ) ;
m_ui - > previewList - > header ( ) - > resizeSection ( 0 , nameSize ) ;
m_headerStateInitialized = true ;
m_headerStateInitialized = true ;
}
}
}
}