diff --git a/YACReaderLibrary/db/comic.cpp b/YACReaderLibrary/db/comic.cpp index 1841f1ee..e130f1ff 100644 --- a/YACReaderLibrary/db/comic.cpp +++ b/YACReaderLibrary/db/comic.cpp @@ -4,38 +4,27 @@ #include #include +//----------------------------------------------------------------------------- +//COMIC------------------------------------------------------------------------ +//----------------------------------------------------------------------------- Comic::Comic() { } -Comic::Comic(qulonglong cparentId, qulonglong ccomicInfoId, QString cname, QString cpath, QString chash) - :comicInfoId(ccomicInfoId),hash(chash) +Comic::Comic(qulonglong cparentId, QString cname, QString cpath, QString chash, QSqlDatabase & database) { parentId = cparentId; name = cname; path = cpath; -} -qulonglong Comic::insert(QSqlDatabase & db) -{ - //TODO comprobar si ya hay comic info con ese hash - QSqlQuery comicInfoInsert(db); - comicInfoInsert.prepare("INSERT INTO comic_info (hash) " - "VALUES (:hash)"); - comicInfoInsert.bindValue(":hash", hash); - comicInfoInsert.exec(); - qulonglong comicInfoId =comicInfoInsert.lastInsertId().toLongLong(); - - QSqlQuery query(db); - query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " - "VALUES (:parentId,:comicInfoId,:name, :path)"); - query.bindValue(":parentId", parentId); - query.bindValue(":comicInfoId", comicInfoId); - query.bindValue(":name", name); - query.bindValue(":path", path); - query.exec(); - return query.lastInsertId().toLongLong(); + if(!info.load(chash,database)) + { + info.hash = chash; + _hasCover = false; + } + else + _hasCover = true; } QList Comic::getComicsFromParent(qulonglong parentId, QSqlDatabase & db) @@ -59,7 +48,7 @@ QList Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas currentItem->id = record.value(0).toLongLong(); currentItem->parentId = record.value(1).toLongLong(); currentItem->name = record.value(2).toString(); - currentItem->hash = record.value(3).toString(); + currentItem->info.load(record.value(3).toString(),db); int lessThan = 0; if(list.isEmpty()) list.append(currentItem); @@ -87,6 +76,44 @@ QList Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas return list; } +bool Comic::load(qulonglong id, QSqlDatabase & db) +{ + return true; +} + +qulonglong Comic::insert(QSqlDatabase & db) +{ + //TODO comprobar si ya hay comic info con ese hash + + if(!info.existOnDb) + { + QSqlQuery comicInfoInsert(db); + comicInfoInsert.prepare("INSERT INTO comic_info (hash) " + "VALUES (:hash)"); + comicInfoInsert.bindValue(":hash", info.hash); + comicInfoInsert.exec(); + info.id =comicInfoInsert.lastInsertId().toLongLong(); + _hasCover = false; + } + else + _hasCover = true; //TODO check on disk... + + QSqlQuery query(db); + query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " + "VALUES (:parentId,:comicInfoId,:name, :path)"); + query.bindValue(":parentId", parentId); + query.bindValue(":comicInfoId", info.id); + query.bindValue(":name", name); + query.bindValue(":path", path); + query.exec(); + return query.lastInsertId().toLongLong(); +} + +void Comic::update(QSqlDatabase & db) +{ + +} + void Comic::removeFromDB(QSqlDatabase & db) { QSqlQuery query(db); @@ -98,4 +125,50 @@ void Comic::removeFromDB(QSqlDatabase & db) bool Comic::isDir() { return false; -} \ No newline at end of file +} + +//----------------------------------------------------------------------------- +//COMIC_INFO------------------------------------------------------------------- +//----------------------------------------------------------------------------- +ComicInfo::ComicInfo() + :existOnDb(false) +{ + +} + +bool ComicInfo::load(QString hash, QSqlDatabase & db) +{ + QSqlQuery findComicInfo(db); + findComicInfo.prepare("SELECT * FROM comic_info WHERE hash = :hash"); + findComicInfo.bindValue(":hash", hash); + findComicInfo.exec(); + + + if(findComicInfo.next()) + { + QSqlRecord record = findComicInfo.record(); + + this->hash = hash; + this->id = record.value(0).toLongLong(); + this->name = record.value(2).toString(); + this->read = record.value(3).toBool(); + existOnDb = true; + return true; + } + + existOnDb = false; + return false; +} + +qulonglong ComicInfo::insert(QSqlDatabase & db) +{ + return 0; +} +void ComicInfo::removeFromDB(QSqlDatabase & db) +{ + +} +void ComicInfo::update(QSqlDatabase & db) +{ + +} diff --git a/YACReaderLibrary/db/comic.h b/YACReaderLibrary/db/comic.h index 338f05e3..41096a30 100644 --- a/YACReaderLibrary/db/comic.h +++ b/YACReaderLibrary/db/comic.h @@ -5,19 +5,43 @@ #include #include -class Comic : public LibraryItem +class ComicInfo { public: - qulonglong comicInfoId; - QString hash; + ComicInfo(); - Comic(); - Comic(qulonglong cparentId, qulonglong ccomicInfoId, QString cname, QString cpath, QString chash); - //Comic(QString fn, QString fp):name(fn),path(fp),knownParent(false), knownId(false){}; + bool load(QString hash, QSqlDatabase & db); qulonglong insert(QSqlDatabase & db); + void removeFromDB(QSqlDatabase & db); + void update(QSqlDatabase & db); + + qulonglong id; + bool read; + QString hash; + QString name; + + bool existOnDb; +}; + +class Comic : public LibraryItem +{ +private: + bool _hasCover; +public: + Comic(); + Comic(qulonglong cparentId, QString cname, QString cpath, QString chash, QSqlDatabase & database); + //Comic(QString fn, QString fp):name(fn),path(fp),knownParent(false), knownId(false){}; + static QList getComicsFromParent(qulonglong parentId, QSqlDatabase & db); bool isDir(); + + bool load(qulonglong id, QSqlDatabase & db); + qulonglong insert(QSqlDatabase & db); void removeFromDB(QSqlDatabase & db); + void update(QSqlDatabase & db); + bool hasCover() {return _hasCover;}; + + ComicInfo info; }; diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index 7f3c1986..a84c67d8 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -25,8 +25,15 @@ QSqlDatabase DataBaseManagement::createDatabase(QString name, QString path) qDebug() << db.lastError(); else { qDebug() << db.tables(); - db.close(); } + QSqlQuery pragma("PRAGMA foreign_keys = ON",db); + DataBaseManagement::createTables(db); + + QSqlQuery query("INSERT INTO folder (parentId, name, path) " + "VALUES (1,'root', '/')",db); + + //db.close(); + return db; } @@ -37,9 +44,32 @@ QSqlDatabase DataBaseManagement::loadDatabase(QString path) db.setDatabaseName(path+"/library.ydb"); if (!db.open()) { //se devuelve una base de datos vacía e inválida + return QSqlDatabase(); } - + QSqlQuery pragma("PRAGMA foreign_keys = ON",db); //devuelve la base de datos return db; +} + +bool DataBaseManagement::createTables(QSqlDatabase & database) +{ + bool success = true; + + //FOLDER (representa una carpeta en disco) + QSqlQuery queryFolder(database); + queryFolder.prepare("CREATE TABLE folder (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE)"); + success = success && queryFolder.exec(); + + //COMIC INFO (representa la información de un cómic, cada cómic tendrá un idéntificador único formado por un hash sha1'de los primeros 512kb' + su tamaño en bytes) + QSqlQuery queryComicInfo(database); + queryComicInfo.prepare("CREATE TABLE comic_info (id INTEGER PRIMARY KEY, hash TEXT NOT NULL, name TEXT, read BOOLEAN)"); + success = success && queryComicInfo.exec(); + + //COMIC (representa un cómic en disco, contiene el nombre de fichero) + QSqlQuery queryComic(database); + queryComic.prepare("CREATE TABLE comic (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, comicInfoId INTEGER NOT NULL, fileName TEXT NOT NULL, path TEXT, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE, FOREIGN KEY(comicInfoId) REFERENCES comic_info(id))"); + success = success && queryComic.exec(); + + return success; } \ No newline at end of file diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index 9f91fc19..46b354f4 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -15,8 +15,11 @@ private: public: DataBaseManagement(); TreeModel * newTreeModel(QString path); + //crea una base de datos y todas sus tablas static QSqlDatabase createDatabase(QString name, QString path); + //carga una base de datos desde la ruta path static QSqlDatabase loadDatabase(QString path); + static bool createTables(QSqlDatabase & database); }; #endif \ No newline at end of file diff --git a/YACReaderLibrary/db/folder.cpp b/YACReaderLibrary/db/folder.cpp index f411e6c5..045ebed5 100644 --- a/YACReaderLibrary/db/folder.cpp +++ b/YACReaderLibrary/db/folder.cpp @@ -21,7 +21,7 @@ QList Folder::getFoldersFromParent(qulonglong parentId, QSqlDatab QList list; QSqlQuery selectQuery(db); //TODO check - selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId"); + selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId and id <> 1"); selectQuery.bindValue(":parentId", parentId); selectQuery.exec(); diff --git a/YACReaderLibrary/db/tableitem.cpp b/YACReaderLibrary/db/tableitem.cpp index 0557980a..c1a4e21f 100644 --- a/YACReaderLibrary/db/tableitem.cpp +++ b/YACReaderLibrary/db/tableitem.cpp @@ -5,6 +5,7 @@ //! [0] TableItem::TableItem(const QList &data) + { itemData = data; } diff --git a/YACReaderLibrary/db/tableitem.h b/YACReaderLibrary/db/tableitem.h index ebad058a..29cb8f26 100644 --- a/YACReaderLibrary/db/tableitem.h +++ b/YACReaderLibrary/db/tableitem.h @@ -3,6 +3,7 @@ #include #include +#include "comic.h" //! [0] class TableItem @@ -14,6 +15,7 @@ public: QVariant data(int column) const; int row() const; unsigned long long int id; //TODO sustituir por una clase adecuada + Comic comic; private: QList itemData; diff --git a/YACReaderLibrary/db/treeitem.h b/YACReaderLibrary/db/treeitem.h index 9b38fd0f..5223e3b7 100644 --- a/YACReaderLibrary/db/treeitem.h +++ b/YACReaderLibrary/db/treeitem.h @@ -43,6 +43,7 @@ #include #include +#include //! [0] class TreeItem @@ -63,9 +64,8 @@ public: TreeItem *parentItem; unsigned long long int id; QList comicNames; - int originalRow; //usado en los TreeItem filtrados //TODO crear clase específica..... - int originalColumn; //usado en los TreeItem filtrados //TODO crear clase específica..... - int column; + QModelIndex index; + QModelIndex originalIndex; private: QList childItems; QList itemData; diff --git a/YACReaderLibrary/db/treemodel.cpp b/YACReaderLibrary/db/treemodel.cpp index 0054ab46..c62bb48d 100644 --- a/YACReaderLibrary/db/treemodel.cpp +++ b/YACReaderLibrary/db/treemodel.cpp @@ -52,6 +52,8 @@ #include "treemodel.h" #include "data_base_management.h" +#define ROOT 1 + TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent),rootItem(0),rootBeforeFilter(0),filterEnabled(false),includeComics(false) { @@ -67,7 +69,7 @@ TreeModel::TreeModel( QSqlQuery &sqlquery, QObject *parent) QList rootData; rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem) rootItem = new TreeItem(rootData); - rootItem->id = 0; + rootItem->id = ROOT; setupModelData(sqlquery, rootItem); } //! [0] @@ -145,8 +147,8 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) TreeItem *childItem = parentItem->child(row); if (childItem) { - childItem->column = column; - return createIndex(row, column, childItem); + childItem->index = createIndex(row, column, childItem); + return childItem->index; } else return QModelIndex(); @@ -165,7 +167,8 @@ QModelIndex TreeModel::parent(const QModelIndex &index) const if (parentItem == rootItem) return QModelIndex(); - return createIndex(parentItem->row(), 0, parentItem); + parentItem->index = createIndex(parentItem->row(), 0, parentItem); + return parentItem->index; } //! [7] @@ -188,21 +191,23 @@ int TreeModel::rowCount(const QModelIndex &parent) const void TreeModel::setupModelData(QString path) { emit(beforeReset()); - if(rootItem == 0) + if(rootItem != 0) delete rootItem; //TODO comprobar que se libera bien la memoria - + filterEnabled = false; + rootItem = 0; + rootBeforeFilter = 0; //inicializar el nodo raíz QList rootData; rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem) rootItem = new TreeItem(rootData); - rootItem->id = 0; + rootItem->id = ROOT; //cargar la base de datos if(_database.isOpen()) _database.close(); _database = DataBaseManagement::loadDatabase(path); //crear la consulta - QSqlQuery selectQuery("select * from folder order by parentId,name",_database); + QSqlQuery selectQuery("select * from folder where id <> 1 order by parentId,name",_database); setupModelData(selectQuery,rootItem); _database.close(); @@ -215,7 +220,7 @@ void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent) { //64 bits para la primary key, es decir la misma precisión que soporta sqlit 2^64 //el diccionario permitirá encontrar cualquier nodo del árbol rápidamente, de forma que añadir un hijo a un padre sea O(1) - + items.clear(); //se añade el nodo 0 items.insert(parent->id,parent); @@ -243,20 +248,30 @@ void TreeModel::setupFilteredModelData() if(rootBeforeFilter == 0) rootBeforeFilter = rootItem; + else + delete rootItem;//los resultados de la búsqueda anterior deben ser borrados QList rootData; - rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem) + rootData << "root"; //id 1, padre 1, title "root" (el id, y el id del padre van a ir en la clase TreeItem) rootItem = new TreeItem(rootData); - rootItem->id = 0; + rootItem->id = ROOT; //cargar la base de datos if(_database.isValid()) _database.open(); //crear la consulta QSqlQuery selectQuery(_database); //TODO check - selectQuery.prepare("select * from folder where upper(name) like upper(:filter) order by parentId,name "); - selectQuery.bindValue(":filter", "%%"+filter+"%%"); - selectQuery.exec(); + if(!includeComics) + { + selectQuery.prepare("select * from folder where id <> 1 and upper(name) like upper(:filter) order by parentId,name "); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + } + else + { + selectQuery.prepare("select distinct f.id, f.parentId, f.name, f.path from folder f inner join comic c on (f.id = c.parentId) where f.id <> 1 and upper(c.fileName) like upper(:filter) order by f.parentId,f.name"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + } + selectQuery.exec(); setupFilteredModelData(selectQuery,rootItem); _database.close(); emit(reset()); @@ -286,8 +301,7 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent) filteredItems.insert(item->id,item); //es necesario conocer las coordenadas de origen para poder realizar scroll automático en la vista - item->originalRow = items.value(item->id)->row(); - item->originalColumn = items.value(item->id)->column; + item->originalIndex = items.value(item->id)->index; //si el padre ya existe en el modelo, el item se añade como hijo if(filteredItems.contains(parentId)) @@ -298,7 +312,7 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent) bool parentPreviousInserted = false; //mientras no se alcance el nodo raíz se procesan todos los padres (de abajo a arriba) - while(parentId !=0 ) + while(parentId != ROOT ) { //el padre no estaba en el modelo filtrado, así que se rescata del modelo original TreeItem * parentItem = items.value(parentId); @@ -306,6 +320,8 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent) TreeItem * newparentItem = new TreeItem(parentItem->getData()); //padre que se añadirá a la estructura de directorios filtrados newparentItem->id = parentId; + newparentItem->originalIndex = parentItem->index; + //si el modelo contiene al padre, se añade el item actual como hijo if(filteredItems.contains(parentId)) { @@ -325,12 +341,10 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent) parentId = parentItem->parentItem->id; } - //si el nodo hijo de 0, no había sido previamente insertado como hijo, se añade como tal + //si el nodo es hijo de 1 y no había sido previamente insertado como hijo, se añade como tal if(!parentPreviousInserted) - filteredItems.value(0)->appendChild(item); + filteredItems.value(ROOT)->appendChild(item); } - - } } @@ -360,7 +374,13 @@ void TreeModel::resetFilter() filter = ""; includeComics = false; //TODO hay que liberar la memoria reservada para el filtrado + //items.clear(); + filteredItems.clear(); + TreeItem * root = rootItem; rootItem = rootBeforeFilter; //TODO si no se aplica el filtro previamente, esto invalidaría en modelo + //if(root !=0) + // delete root; + rootBeforeFilter = 0; filterEnabled = false; emit(reset()); diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index e384bb8f..3a7313cb 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -32,5 +32,6 @@ ../images/importCover.png ../images/editComic.png ../images/selectAll.png + ../images/hideComicFlow.png diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index fbff32d7..25069e41 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "data_base_management.h" //QMutex mutex; @@ -38,27 +39,7 @@ void LibraryCreator::updateLibrary(const QString &source, const QString &target) _mode = UPDATER; } -bool LibraryCreator::createTables() -{ - bool success = true; - //FOLDER (representa una carpeta en disco) - QSqlQuery queryFolder(_database); - queryFolder.prepare("CREATE TABLE folder (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE)"); - success = success && queryFolder.exec(); - - //COMIC INFO (representa la información de un cómic, cada cómic tendrá un idéntificador único formado por un hash sha1'de los primeros 512kb' + su tamaño en bytes) - QSqlQuery queryComicInfo(_database); - queryComicInfo.prepare("CREATE TABLE comic_info (id INTEGER PRIMARY KEY, hash TEXT NOT NULL, name TEXT)"); - success = success && queryComicInfo.exec(); - - //COMIC (representa un cómic en disco, contiene el nombre de fichero) - QSqlQuery queryComic(_database); - queryComic.prepare("CREATE TABLE comic (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, comicInfoId INTEGER NOT NULL, fileName TEXT NOT NULL, path TEXT, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE, FOREIGN KEY(comicInfoId) REFERENCES comic_info(id))"); - success = success && queryComic.exec(); - - return success; -} // void LibraryCreator::run() { @@ -66,17 +47,20 @@ void LibraryCreator::run() if(_mode == CREATOR) { + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + //se crean los directorios .yacreaderlibrary y .yacreaderlibrary/covers QDir dir; dir.mkpath(_target+"/covers"); - _database = QSqlDatabase::addDatabase("QSQLITE"); - _database.setDatabaseName(_target+"/library.ydb"); - if(!_database.open()) + + //se crea la base de datos .yacreaderlibrary/library.ydb + _database = DataBaseManagement::createDatabase("library",_target);// + /*if(!_database.open()) return; //TODO avisar del problema + + QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);*/ _database.transaction(); - _currentPathFolders.clear(); - _currentPathFolders.append(Folder(0,0,"root","/")); - if(!createTables()) - return; + //se crea la librería create(QDir(_source)); _database.commit(); _database.close(); @@ -84,11 +68,12 @@ void LibraryCreator::run() else { _currentPathFolders.clear(); - _currentPathFolders.append(Folder(0,0,"root","/")); - _database = QSqlDatabase::addDatabase("QSQLITE"); - _database.setDatabaseName(_target+"/library.ydb"); - if(!_database.open()) - return; //TODO avisar del problema + _currentPathFolders.append(Folder(1,1,"root","/")); + _database = DataBaseManagement::loadDatabase(_target); + //_database.setDatabaseName(_target+"/library.ydb"); + /*if(!_database.open()) + return; //TODO avisar del problema*/ + //QSqlQuery pragma("PRAGMA foreign_keys = ON",_database); _database.transaction(); update(QDir(_source)); _database.commit(); @@ -199,10 +184,14 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo & file.close(); //hash Sha1 del primer 0.5MB + filesize QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size()); - Comic(_currentPathFolders.last().id,0,fileInfo.fileName(),relativePath,hash).insert(_database); - ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg"); - //ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+fileInfo.fileName()+".jpg"); - tc.create(); + Comic comic(_currentPathFolders.last().id,fileInfo.fileName(),relativePath,hash,_database); + comic.insert(_database); + if(!comic.hasCover()) + { + ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg"); + //ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+fileInfo.fileName()+".jpg"); + tc.create(); + } } void LibraryCreator::update(QDir dirS) diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h index 0bdeb425..69f5649b 100644 --- a/YACReaderLibrary/library_creator.h +++ b/YACReaderLibrary/library_creator.h @@ -39,7 +39,6 @@ void create(QDir currentDirectory); void update(QDir currentDirectory); void run(); - bool createTables(); qulonglong insertFolders();//devuelve el id del último folder añadido (último en la ruta) void insertComic(const QString & relativePath,const QFileInfo & fileInfo); //qulonglong insertFolder(qulonglong parentId,const Folder & folder); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 5e270eb0..6b19531b 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -44,7 +44,7 @@ void LibraryWindow::setupUI() void LibraryWindow::doLayout() { - QSplitter * sVertical = new QSplitter(Qt::Vertical); //spliter derecha + sVertical = new QSplitter(Qt::Vertical); //spliter derecha QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); //spliter principal //TODO: flowType is a global variable //CONFIG COMIC_FLOW-------------------------------------------------------- @@ -77,7 +77,7 @@ void LibraryWindow::doLayout() sVertical->setStretchFactor(1,0); */ //views - foldersView->setAnimated(true); + //foldersView->setAnimated(true); foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); foldersView->header()->hide(); @@ -335,6 +335,12 @@ void LibraryWindow::createActions() forceConverExtractedAction = new QAction(this); forceConverExtractedAction->setText(tr("Update cover")); forceConverExtractedAction->setIcon(QIcon(":/images/importCover.png")); + + hideComicViewAction = new QAction(this); + hideComicViewAction->setText(tr("Hide comic flow")); + hideComicViewAction->setIcon(QIcon(":/images/hideComicFlow.png")); + hideComicViewAction->setCheckable(true); + hideComicViewAction->setChecked(false); //------------------------------------------------------------------------- } @@ -447,6 +453,8 @@ void LibraryWindow::createToolBars() editInfoToolBar->addAction(selectAllComicsAction); editInfoToolBar->addSeparator(); editInfoToolBar->addAction(forceConverExtractedAction); + editInfoToolBar->addWidget(new QToolBarStretch()); + editInfoToolBar->addAction(hideComicViewAction); } void LibraryWindow::createMenus() @@ -538,6 +546,8 @@ void LibraryWindow::createConnections() //Comicts edition connect(selectAllComicsAction,SIGNAL(triggered()),comicView,SLOT(selectAll())); + connect(hideComicViewAction, SIGNAL(toggled(bool)),this, SLOT(hideComicFlow(bool))); + } void LibraryWindow::loadLibrary(const QString & name) @@ -553,7 +563,8 @@ void LibraryWindow::loadLibrary(const QString & name) loadCovers(QModelIndex()); - includeComicsCheckBox->setCheckState(Qt::Unchecked); + //includeComicsCheckBox->setCheckState(Qt::Unchecked); + foldersFilter->clear(); } else { @@ -587,9 +598,11 @@ void LibraryWindow::loadCovers(const QModelIndex & mi) if(foldersFilter->text()!="") { //setFoldersFilter(""); - row = static_cast(mi.internalPointer())->originalRow; - column = static_cast(mi.internalPointer())->originalColumn; - foldersFilter->clear(); + if(mi.isValid()) + { + index = static_cast(mi.internalPointer())->originalIndex; + foldersFilter->clear(); + } } unsigned long long int folderId = 0; if(mi.isValid()) @@ -996,14 +1009,14 @@ void LibraryWindow::setFoldersFilter(QString filter) if(filter.isEmpty() && dm->isFilterEnabled()) { dm->resetFilter(); - foldersView->collapseAll(); - foldersView->scrollTo(dm->index(row,column),QAbstractItemView::PositionAtTop); + foldersView->collapseAll(); + foldersView->scrollTo(index,QAbstractItemView::PositionAtTop); } else { if(!filter.isEmpty()) { - dm->setFilter(filter, false); + dm->setFilter(filter, includeComicsCheckBox->isChecked()); foldersView->expandAll(); } } @@ -1083,15 +1096,44 @@ void LibraryWindow::searchInFiles(int state) if(state == Qt::Checked) { - //dm->setFilter(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot); //crash, after update proxy filter + if(!foldersFilter->text().isEmpty()) + { + dm->setFilter(foldersFilter->text(), true); + foldersView->expandAll(); + } } else { - //dm->setFilter(QDir::Dirs|QDir::NoDotAndDotDot); //crash + if(!foldersFilter->text().isEmpty()) + { + dm->setFilter(foldersFilter->text(), false); + foldersView->expandAll(); + } } } QString LibraryWindow::currentPath() { return libraries.value(selectedLibrary->currentText()); +} + +void LibraryWindow::hideComicFlow(bool hide) +{ + if(hide) + { + QList sizes; + sizes.append(0); + int total = sVertical->sizes().at(0) + sVertical->sizes().at(1); + sizes.append(total); + sVertical->setSizes(sizes); + } + else + { + QList sizes; + int total = sVertical->sizes().at(0) + sVertical->sizes().at(1); + sizes.append(2*total/3); + sizes.append(total/3); + sVertical->setSizes(sizes); + } + } \ No newline at end of file diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 708c33a6..4a6e7158 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -31,6 +31,7 @@ class LibraryWindow : public QMainWindow Q_OBJECT private: QWidget * left; + QSplitter * sVertical; CreateLibraryDialog * createLibraryDialog; UpdateLibraryDialog * updateLibraryDialog; ExportLibraryDialog * exportLibraryDialog; @@ -51,8 +52,7 @@ private: QSize slideSizeF; //search filter QLineEdit * foldersFilter; - int row; //row a la que hay que hacer scroll automático después de limpiar el filtro - int column; //column a la que hay que hacer scroll automático después de limpiar el filtro + QModelIndex index; //index al que hay que hacer scroll después de pulsar sobre un folder filtrado QString previousFilter; QPushButton * clearFoldersFilter; QCheckBox * includeComicsCheckBox; @@ -86,6 +86,7 @@ private: QAction * toggleFullScreenAction; QAction * optionsAction; + //tree actions QAction * setRootIndexAction; QAction * expandAllNodesAction; QAction * colapseAllNodesAction; @@ -98,10 +99,12 @@ private: QAction * setAllAsNonReadAction; QAction * showHideMarksAction; + //edit info actions QAction * selectAllComicsAction; QAction * editSelectedComicsAction; QAction * asignOrderActions; QAction * forceConverExtractedAction; + QAction * hideComicViewAction; QToolBar * libraryToolBar; @@ -174,6 +177,7 @@ public: void setComicsReaded(); void setComicsUnreaded(); void searchInFiles(int); + void hideComicFlow(bool hide); }; #endif diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index afffa454..8f74b337 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -569,6 +569,8 @@ void PictureFlowSoftwareRenderer::init() int wh = size.height(); int w = (ww+1)/2; int h = (wh+1)/2; + if(h<10)//TODO a partir de qué h es seguro?? + return; #ifdef PICTUREFLOW_QT4 buffer = QImage(ww, wh, QImage::Format_RGB32); diff --git a/images/hideComicFlow.png b/images/hideComicFlow.png new file mode 100644 index 00000000..bfab264b Binary files /dev/null and b/images/hideComicFlow.png differ