Skip to content

Commit

Permalink
ADD: Start on file browser, UI is likely to change radically though. #48
Browse files Browse the repository at this point in the history
  • Loading branch information
spillerrec committed Oct 21, 2014
1 parent daa0176 commit 8d8d954
Show file tree
Hide file tree
Showing 9 changed files with 1,409 additions and 1,183 deletions.
7 changes: 5 additions & 2 deletions overmix.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ unix{

include(overmix.pri)

QMAKE_CXXFLAGS_DEBUG += -pg
QMAKE_LFLAGS_DEBUG += -pg

# Interface
FORMS += src/mainwindow.ui
HEADERS += src/mainwindow.hpp
SOURCES += src/mainwindow.cpp src/main.cpp
HEADERS += src/mainwindow.hpp src/gui/ImagesModel.hpp
SOURCES += src/mainwindow.cpp src/gui/ImagesModel.cpp src/main.cpp

#Viewer
HEADERS += src/viewer/colorManager.h \
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ImageContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

void ImageContainer::addImage( ImageEx&& img, int mask, int group, QString filepath ){
if( groups.size() == 0 )
groups.emplace_back( "", masks );
groups.emplace_back( "Auto group", masks );

ImageItem item{ filepath, std::move(img) };
item.setSharedMask( mask );
Expand Down
4 changes: 2 additions & 2 deletions src/containers/ImageGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@

class ImageItem{
private:
QString filename;
ImageEx img;
Plane mask;
int mask_id{ -1 };

public:
QString filename;
Point<double> offset;
int frame{ -1 };

ImageItem( QString filename, ImageEx&& img )
: filename(filename), img(img) { }
: img(img), filename(filename) { }

const ImageEx& image() const{ return img; }
int maskId() const{ return mask_id; }
Expand Down
91 changes: 91 additions & 0 deletions src/gui/ImagesModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
This file is part of Overmix.
Overmix 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 3 of the License, or
(at your option) any later version.
Overmix 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 Overmix. If not, see <http://www.gnu.org/licenses/>.
*/


#include "ImagesModel.hpp"


QModelIndex ImagesModel::index( int row, int column, const QModelIndex& parent ) const{
//Root/Group level
if( !parent.isValid() )
return createIndex( row, column, 0ull );

//Item level
if( parent.internalId() == 0 ){
auto pos = parent.row();
if( (unsigned)pos < images.groupAmount() )
return createIndex( row, column, pos + 1 );
return QModelIndex();
}

//level is too high!
return QModelIndex();
}

QModelIndex ImagesModel::parent( const QModelIndex& child ) const{
auto id = child.internalId();
if( !child.isValid() ||id == 0 )
return QModelIndex();
return index( id-1, 0 );
}

int ImagesModel::rowCount( const QModelIndex &parent ) const{
if( !parent.isValid() )
return images.groupAmount();

auto pos = parent.row();
if( (unsigned)pos < images.groupAmount() && parent.internalId() == 0 )
return images.getConstGroup( pos ).count();
else
return 0;
}

int ImagesModel::columnCount( const QModelIndex& parent ) const{
return parent.isValid() ? 5 : 5; //TODO:
}

QVariant ImagesModel::data( const QModelIndex& index, int role ) const{
auto id = index.internalId();
if( !index.isValid() || role != Qt::DisplayRole )
return QVariant();

//Root/Group level
if( id == 0 ){
auto row = index.row();
if( (unsigned)row >= images.groupAmount() || index.column() != 0 )
return QVariant(); //Out-of-bounds, invalid
return images.getConstGroup( row ).name;
}

if( id-1 >= images.groupAmount() )
return QVariant();

auto& group = images.getConstGroup( id-1 );
if( (unsigned)index.row() >= group.count() )
return QVariant();
auto& item = group.items[index.row()];

switch( index.column() ){
case 0: return item.filename;
case 1: return item.offset.x;
case 2: return item.offset.y;
case 3: return item.maskId();
case 4: return item.frame;
default: return QVariant();
}
}

44 changes: 44 additions & 0 deletions src/gui/ImagesModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This file is part of Overmix.
Overmix 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 3 of the License, or
(at your option) any later version.
Overmix 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 Overmix. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef IMAGES_MODEL_HPP
#define IMAGES_MODEL_HPP

#include "../containers/ImageContainer.hpp"

#include <QAbstractItemModel>


class ImagesModel : public QAbstractItemModel{
Q_OBJECT

private:
ImageContainer& images;

public:
ImagesModel( ImageContainer& images ) : images(images) { }

//QAbstractItemModel implementation
virtual QModelIndex index( int row, int column, const QModelIndex& parent=QModelIndex() ) const override;
virtual QModelIndex parent(const QModelIndex & index) const override;
virtual int rowCount( const QModelIndex &parent=QModelIndex() ) const override;
virtual int columnCount( const QModelIndex& parent=QModelIndex() ) const override;
virtual QVariant data( const QModelIndex& index, int role=Qt::DisplayRole ) const override;
};

#endif

20 changes: 16 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ main_widget::main_widget( Preprocessor& preprocessor, ImageContainer& images )
, settings( "spillerrec", "overmix" )
#endif
, viewer( settings, (QWidget*)this )
, browser( settings, (QWidget*)this )
, preprocessor( preprocessor )
, images( images )
, img_model( images )
{
ui->setupUi(this);

Expand Down Expand Up @@ -128,9 +130,14 @@ main_widget::main_widget( Preprocessor& preprocessor, ImageContainer& images )
//Refresh info labels
refresh_text();

//Init files model
ui->files_view->setModel( &img_model );

setAcceptDrops( true );
ui->main_layout->addWidget( &viewer );
viewer.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
ui->preview_layout->addWidget( &viewer );
ui->files_layout ->addWidget( &browser );
viewer .setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
browser.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );

save_dir = settings.value( "save_directory", "." ).toString();
if( settings.value( "remember_position", true ).toBool() )
Expand Down Expand Up @@ -198,6 +205,7 @@ void main_widget::process_urls( QList<QUrl> urls ){
QFuture<ImageEx> img_loader = QtConcurrent::run( load, urls[0] );

for( int i=0; i<urls.count(); i++ ){
auto file = urls[i].toLocalFile();
progress.setValue( i );

QTime delay;
Expand All @@ -210,8 +218,11 @@ void main_widget::process_urls( QList<QUrl> urls ){
loading_delay += delay.elapsed();

//De-telecine
if( detelecine.isActive() )
if( detelecine.isActive() ){
img = detelecine.process( img );
file = ""; //The result might be a bit of several files
//TODO: somehow provide info about the detelecine process?
}
if( !img.is_valid() )
continue;

Expand All @@ -231,7 +242,7 @@ void main_widget::process_urls( QList<QUrl> urls ){
preprocessor.scale_y = ui->pre_scale_height->value();

preprocessor.processFile( img );
images.addImage( std::move( img ), alpha_mask ); //TODO: get filename
images.addImage( std::move( img ), alpha_mask, -1, file );

if( progress.wasCanceled() )
break;
Expand All @@ -243,6 +254,7 @@ void main_widget::process_urls( QList<QUrl> urls ){
refresh_text();
update_draw();
update();
ui->files_view->reset();
}


Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "ImageEx.hpp"
#include "viewer/imageViewer.h"

#include "gui/ImagesModel.hpp"

#include "Deteleciner.hpp"
#include "RenderOperations.hpp"

Expand All @@ -45,6 +47,7 @@ class main_widget: public QMainWindow{
QString save_dir;

imageViewer viewer;
imageViewer browser;
Preprocessor& preprocessor;
ImageContainer& images;
QImage temp;
Expand All @@ -55,6 +58,8 @@ class main_widget: public QMainWindow{

int alpha_mask{ -1 };

ImagesModel img_model;

void clear_cache();


Expand Down
Loading

0 comments on commit 8d8d954

Please sign in to comment.