Commit 93616b44 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

settings: Add a widget to represent a selectable list of folders

parent 3acf036a
......@@ -213,6 +213,7 @@ vlmc_SOURCES += \
src/Gui/settings/PreferenceWidget.cpp \
src/Gui/settings/SettingsDialog.cpp \
src/Gui/settings/StringWidget.cpp \
src/Gui/settings/FolderListWidget.cpp \
src/Gui/timeline/Timeline.cpp \
src/Gui/timeline/ThumbnailImageProvider.cpp \
src/Gui/widgets/ExtendedLabel.cpp \
......@@ -284,6 +285,7 @@ vlmc_SOURCES += \
src/Gui/settings/LanguageWidget.h \
src/Gui/settings/Panel.h \
src/Gui/settings/PreferenceWidget.h \
src/Gui/settings/FolderListWidget.h \
src/Gui/import/ImportController.h \
src/Gui/import/TagWidget.h \
src/Gui/effectsengine/EffectStack.h \
......@@ -350,6 +352,7 @@ nodist_vlmc_SOURCES += \
src/Gui/settings/PathWidget.moc.cpp \
src/Gui/settings/IntWidget.moc.cpp \
src/Gui/settings/StringWidget.moc.cpp \
src/Gui/settings/FolderListWidget.moc.cpp \
src/Gui/effectsengine/EffectsListView.moc.cpp \
$(NULL)
......@@ -363,6 +366,7 @@ vlmc_UI = \
src/Gui/ui/TagWidget.ui \
src/Gui/ui/MediaCellView.ui \
src/Gui/ui/MediaLibraryView.ui \
src/Gui/ui/FolderListWidget.ui \
src/Gui/ui/StackViewNavController.ui \
src/Gui/ui/ClipMetadataDisplayer.ui \
src/Gui/ui/PreviewWidget.ui \
......
/*****************************************************************************
* FolderListWidget.cpp
*****************************************************************************
* Copyright (C) 2008-2016 the VLMC team
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "FolderListWidget.h"
#include <QHeaderView>
#include <QTreeView>
#include <QFileSystemModel>
#include "ui/FolderListWidget.h"
FolderList::FolderList( QWidget* parent )
: QWidget( parent )
, m_ui( new Ui::FolderListWidget )
{
m_ui->setupUi( this );
m_fsModel = new QFileSystemModel( this );
m_fsModel->setRootPath( QDir::rootPath() );
m_fsModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
m_ui->fsView->setModel( m_fsModel );
m_ui->fsView->header()->setStretchLastSection( false );
m_ui->fsView->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
m_ui->fsView->setColumnHidden( 1, true );
m_ui->fsView->setColumnHidden( 2, true );
m_ui->fsView->setColumnHidden( 3, true );
connect( m_ui->addButton, &QPushButton::clicked, this, &FolderList::addFolder );
connect( m_ui->removeButton, &QPushButton::clicked, this, &FolderList::removeFolder );
}
void
FolderList::addFolder()
{
auto idx = m_ui->fsView->currentIndex();
const auto path = m_fsModel->filePath( idx );
if ( path.isEmpty() == true )
return;
auto items = m_ui->selectedFolders->findItems( path, Qt::MatchExactly );
if ( items.size() > 0 )
return;
m_ui->selectedFolders->addItem( path );
emit foldersChanged();
}
void
FolderList::removeFolder()
{
auto idx = m_ui->selectedFolders->currentIndex();
auto item = m_ui->selectedFolders->takeItem( idx.row() );
if ( item == nullptr )
return;
emit foldersChanged();
delete item;
}
QStringList
FolderList::folders()
{
QStringList res;
for ( auto i = 0; i < m_ui->selectedFolders->count(); ++i )
res.append( m_ui->selectedFolders->item( i )->text() );
return res;
}
void
FolderList::setFolders(QStringList folders)
{
m_ui->selectedFolders->clear();
for ( const auto& s : folders )
m_ui->selectedFolders->addItem( s );
}
FolderListWidget::FolderListWidget( SettingValue* s, QWidget* parent )
: ISettingsCategoryWidget( parent, s )
, m_widget( new FolderList( this ) )
{
}
bool
FolderListWidget::save()
{
m_setting->set( m_widget->property( "folders" ) );
return true;
}
void
FolderListWidget::changed( const QVariant& value )
{
m_widget->setProperty( "folders", value );
}
/*****************************************************************************
* FolderListWidget.cpp
*****************************************************************************
* Copyright (C) 2008-2016 the VLMC team
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef FOLDERLISTWIDGET_H
#define FOLDERLISTWIDGET_H
#include "ISettingsCategoryWidget.h"
namespace Ui
{
class FolderListWidget;
}
class QTreeView;
class QItemSelectionModel;
class QFileSystemModel;
class FolderList : public QWidget
{
Q_OBJECT
public:
FolderList( QWidget* parent = nullptr );
Q_PROPERTY(QStringList folders READ folders WRITE setFolders USER true)
signals:
void foldersChanged();
private:
void addFolder();
void removeFolder();
QStringList folders();
void setFolders(QStringList folders);
private:
QFileSystemModel* m_fsModel;
Ui::FolderListWidget* m_ui;
};
class FolderListWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
FolderListWidget( SettingValue* s, QWidget* parent = nullptr );
bool save() override;
private slots:
virtual void changed( const QVariant& ) override;
private:
FolderList* m_widget;
};
#endif // FOLDERLISTWIDGET_H
......@@ -30,6 +30,7 @@
#include "PreferenceWidget.h"
#include "BoolWidget.h"
#include "FolderListWidget.h"
#include "DoubleWidget.h"
#include "IntWidget.h"
#include "KeyboardShortcut.h"
......@@ -92,6 +93,12 @@ PreferenceWidget::widgetFactory( SettingValue *s )
return new BoolWidget( s, this );
case SettingValue::Path:
return new PathWidget( s, this );
case SettingValue::List:
{
if ( s->flags().testFlag( SettingValue::Folders ))
return new FolderListWidget( s, this );
return nullptr;
}
default:
return nullptr;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FolderListWidget</class>
<widget class="QWidget" name="FolderListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>650</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="5">
<widget class="QTreeView" name="fsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>400</height>
</size>
</property>
</widget>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="5">
<widget class="QListWidget" name="selectedFolders">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="addButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.qrc">
<normaloff>:/images/down</normaloff>:/images/down</iconset>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="removeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.qrc">
<normaloff>:/images/up</normaloff>:/images/up</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../../resources.qrc"/>
</resources>
<connections/>
</ui>
......@@ -52,7 +52,7 @@ class SettingValue : public QObject
Map,
Hash,
Color,
Position
Position,
};
enum Flag
{
......@@ -64,6 +64,7 @@ class SettingValue : public QObject
EightMultiple = 1 << 3, ///< Forces the value to be a multiple of 8
NotEmpty = 1 << 4, ///< Forces the value not to be empty (likely to be used only with Strings)
Runtime = 1 << 5, ///< Defines a variable that is not meant to be saved
Folders = 1 << 6, ///< Specifies that a setting should only contain folders.
};
Q_DECLARE_FLAGS( Flags, Flag )
/**
......
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