diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index f389c213..81f8d6b2 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -127,7 +127,8 @@ HEADERS += comic_flow.h \ yacreader_reading_lists_view.h \ add_label_dialog.h \ yacreader_history_controller.h \ - yacreader_navigation_controller.h + yacreader_navigation_controller.h \ + empty_label_widget.h SOURCES += comic_flow.cpp \ @@ -183,7 +184,8 @@ SOURCES += comic_flow.cpp \ yacreader_reading_lists_view.cpp \ add_label_dialog.cpp \ yacreader_history_controller.cpp \ - yacreader_navigation_controller.cpp + yacreader_navigation_controller.cpp \ + empty_label_widget.cpp include(./server/server.pri) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index a2027c46..07c56c1a 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -274,36 +274,50 @@ QStringList ComicModel::getPaths(const QString & _source) return paths; } -void ComicModel::setupModelData(unsigned long long int folderId,const QString & databasePath) +void ComicModel::setupFolderModelData(unsigned long long int folderId,const QString & databasePath) { - //QFile f(QCoreApplication::applicationDirPath()+"/performance.txt"); - //f.open(QIODevice::Append); - beginResetModel(); - //QElapsedTimer timer; - //timer.start(); - qDeleteAll(_data); - _data.clear(); + beginResetModel(); + qDeleteAll(_data); + _data.clear(); - //QTextStream txtS(&f); - //txtS << "TABLEMODEL: Tiempo de borrado: " << timer.elapsed() << "ms\r\n"; - _databasePath = databasePath; - QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); - { - //crear la consulta - //timer.restart(); - QSqlQuery selectQuery(db); - selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); - selectQuery.bindValue(":parentId", folderId); - selectQuery.exec(); - //txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n"; - //timer.restart(); - setupModelData(selectQuery); - //txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n"; - //selectQuery.finish(); - } - db.close(); - QSqlDatabase::removeDatabase(_databasePath); - endResetModel(); + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + if(_data.length()==0) + emit isEmpty(); +} + +void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QString &databasePath) +{ + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_label cl ON (c.id == cl.comic_id) " + "WHERE cl.label_id = :parentLabelId"); + selectQuery.bindValue(":parentLabelId", parentLabel); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); if(_data.length()==0) emit isEmpty(); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index 48d9ac65..3e808c3f 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -34,7 +34,8 @@ public: QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; - void setupModelData(unsigned long long int parentFolder,const QString & databasePath); + void setupFolderModelData(unsigned long long int parentFolder,const QString & databasePath); + void setupLabelModelData(unsigned long long int parentLabel, const QString & databasePath); //configures the model for showing the comics matching the filter criteria. void setupModelData(const SearchModifiers modifier, const QString & filter, const QString & databasePath); diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index 6057a106..9f7185be 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -73,6 +73,9 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const return QVariant(ReadingListModel::Separator); } + if (role == ReadingListModel::IDRole) + return item->getId(); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) return QVariant(); diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index ee50bef7..fb801d3c 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -52,6 +52,7 @@ public: enum Roles { TypeListsRole = Qt::UserRole + 1, + IDRole }; enum TypeList { diff --git a/YACReaderLibrary/empty_label_widget.cpp b/YACReaderLibrary/empty_label_widget.cpp new file mode 100644 index 00000000..35d2fe9d --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.cpp @@ -0,0 +1,49 @@ +#include "empty_label_widget.h" + +EmptyLabelWidget::EmptyLabelWidget(QWidget *parent) : + QWidget(parent) +{ +#ifdef Q_OS_MAC + backgroundColor = "#FFFFFF"; +#else + backgroundColor = "#2A2A2A"; +#endif + + QVBoxLayout * layout = new QVBoxLayout; + + iconLabel = new QLabel(); + iconLabel->setPixmap(QPixmap(":/images/empty_label.png")); + iconLabel->setAlignment(Qt::AlignCenter); + + //titleLabel->setText(tr("This label doesn't contain comics yet") + QString("

%1

").arg(tr("Drag and drop folders and comics here"))); + titleLabel = new QLabel(("This label doesn't contain comics yet")); + titleLabel->setAlignment(Qt::AlignCenter); + +#ifdef Q_OS_MAC + titleLabel->setStyleSheet("QLabel {color:#888888; font-size:24px;font-family:Arial;font-weight:bold;}"); +#else + titleLabel->setStyleSheet("QLabel {color:#CCCCCC; font-size:24px;font-family:Arial;font-weight:bold;}"); +#endif + + layout->addSpacing(100); + layout->addWidget(iconLabel); + layout->addSpacing(30); + layout->addWidget(titleLabel); + layout->addStretch(); + + setLayout(layout); +} + +void EmptyLabelWidget::setColor(YACReader::LabelColors color) +{ + //TODO tint the widget depending on color + //backgroundColor = "#FF0000"; + + //repaint(); +} + +void EmptyLabelWidget::paintEvent(QPaintEvent * event) +{ + QPainter painter (this); + painter.fillRect(0,0,width(),height(),QColor(backgroundColor)); +} diff --git a/YACReaderLibrary/empty_label_widget.h b/YACReaderLibrary/empty_label_widget.h new file mode 100644 index 00000000..ac76f722 --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.h @@ -0,0 +1,26 @@ +#ifndef EMPTY_LABEL_WIDGET_H +#define EMPTY_LABEL_WIDGET_H + +#include +#include "yacreader_global.h" + +class EmptyLabelWidget : public QWidget +{ + Q_OBJECT +public: + explicit EmptyLabelWidget(QWidget *parent = 0); + void setColor(YACReader::LabelColors color); + void paintEvent(QPaintEvent *event); + +signals: + +public slots: + +protected: + QLabel * iconLabel; + QLabel * titleLabel; + QString backgroundColor; + +}; + +#endif // EMPTY_LABEL_WIDGET_H diff --git a/YACReaderLibrary/images_osx.qrc b/YACReaderLibrary/images_osx.qrc index 65aed99b..9d873f1a 100644 --- a/YACReaderLibrary/images_osx.qrc +++ b/YACReaderLibrary/images_osx.qrc @@ -25,6 +25,7 @@ ../images/flow_to_grid.gif ../images/grid_to_flow.gif ../images/empty_folder_osx.png + ../images/empty_label_osx.png ../images/empty_search_osx.png ../images/iconSearch.png ../images/clearSearch.png diff --git a/YACReaderLibrary/images_win.qrc b/YACReaderLibrary/images_win.qrc index f0f62517..40f2f769 100644 --- a/YACReaderLibrary/images_win.qrc +++ b/YACReaderLibrary/images_win.qrc @@ -19,6 +19,7 @@ ../images/flow_to_grid.gif ../images/grid_to_flow.gif ../images/empty_folder.png + ../images/empty_label.png ../images/empty_search.png ../images/addNew_sidebar.png ../images/delete_sidebar.png diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 3a5f7e22..246fccc1 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -65,6 +65,7 @@ #include "grid_comics_view.h" #include "comics_view_transition.h" #include "empty_folder_widget.h" +#include "empty_label_widget.h" #include "edit_shortcuts_dialog.h" #include "shortcuts_manager.h" @@ -240,6 +241,7 @@ void LibraryWindow::doLayout() comicsView->setToolBar(editInfoToolBar); comicsViewStack->addWidget(comicsViewTransition = new ComicsViewTransition()); comicsViewStack->addWidget(emptyFolderWidget = new EmptyFolderWidget()); + comicsViewStack->addWidget(emptyLabelWidget = new EmptyLabelWidget()); comicsViewStack->addWidget(noSearchResultsWidget = new NoSearchResultsWidget()); comicsViewStack->addWidget(comicsView); @@ -2153,6 +2155,11 @@ void LibraryWindow::showEmptyFolderView() comicsViewStack->setCurrentWidget(emptyFolderWidget); } +void LibraryWindow::showEmptyLabelView() +{ + comicsViewStack->setCurrentWidget(emptyLabelWidget); +} + void LibraryWindow::showNoSearchResultsView() { comicsViewStack->setCurrentWidget(noSearchResultsWidget); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 7d81bb4f..8602d517 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -68,6 +68,7 @@ class ReadingListModel; class ReadingListModelProxy; class YACReaderReadingListsView; class YACReaderHistoryController; +class EmptyLabelWidget; #include "comic_db.h" @@ -121,6 +122,7 @@ private: QStackedWidget * comicsViewStack; ComicsViewTransition * comicsViewTransition; EmptyFolderWidget * emptyFolderWidget; + EmptyLabelWidget * emptyLabelWidget; NoSearchResultsWidget * noSearchResultsWidget; YACReaderFoldersView * foldersView; @@ -358,6 +360,7 @@ public slots: void toggleComicsView_delayed();//used in orther to avoid flickering; void showComicsView(); void showEmptyFolderView(); + void showEmptyLabelView(); void showNoSearchResultsView(); void toggleComicsView(); void checkSearchNumResults(int numResults); diff --git a/YACReaderLibrary/yacreader_navigation_controller.cpp b/YACReaderLibrary/yacreader_navigation_controller.cpp index 35a85a13..71543346 100644 --- a/YACReaderLibrary/yacreader_navigation_controller.cpp +++ b/YACReaderLibrary/yacreader_navigation_controller.cpp @@ -13,6 +13,8 @@ #include "comics_view.h" #include "empty_folder_widget.h" #include "yacreader_search_line_edit.h" +#include "yacreader_global.h" +#include "empty_label_widget.h" #include "QsLog.h" @@ -56,7 +58,7 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex qulonglong folderId = folderModelIndexToID(modelIndex); //check comics in folder with id = folderId - libraryWindow->comicsModel->setupModelData(folderId,libraryWindow->foldersModel->getDatabase()); + libraryWindow->comicsModel->setupFolderModelData(folderId,libraryWindow->foldersModel->getDatabase()); libraryWindow->comicsView->setModel(libraryWindow->comicsModel); //configure views @@ -77,6 +79,53 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex } void YACReaderNavigationController::loadListInfo(const QModelIndex &modelIndex) +{ + qulonglong id = modelIndex.data(ReadingListModel::IDRole).toULongLong(); + + switch(modelIndex.data(ReadingListModel::TypeListsRole).toInt()) + { + case ReadingListModel::SpecialList: + loadSpecialListInfo(id); + break; + + case ReadingListModel::Label: + loadLabelInfo(id); + break; + + case ReadingListModel::ReadingList: + loadReadingListInfo(id); + break; + } +} + +void YACReaderNavigationController::loadSpecialListInfo(const qulonglong id) +{ + +} + +void YACReaderNavigationController::loadLabelInfo(const qulonglong id) +{ + //check comics in folder with id = folderId + libraryWindow->comicsModel->setupLabelModelData(id,libraryWindow->foldersModel->getDatabase()); + libraryWindow->comicsView->setModel(libraryWindow->comicsModel); + + //configure views + if(libraryWindow->comicsModel->rowCount() > 0) + { + //updateView + libraryWindow->showComicsView(); + libraryWindow->disableComicsActions(false); + } + else{ + //showEmptyFolder + //loadEmptyLabelInfo(); //there is no info in an empty label by now, TODO design something + //TODO libraryWindow->emptyLabelWidget->setColor(YACReader::YRed); + libraryWindow->showEmptyLabelView(); + libraryWindow->disableComicsActions(true); + } +} + +void YACReaderNavigationController::loadReadingListInfo(const qulonglong id) { } diff --git a/YACReaderLibrary/yacreader_navigation_controller.h b/YACReaderLibrary/yacreader_navigation_controller.h index 5375adce..98bdb66f 100644 --- a/YACReaderLibrary/yacreader_navigation_controller.h +++ b/YACReaderLibrary/yacreader_navigation_controller.h @@ -30,6 +30,10 @@ public slots: void loadFolderInfo(const QModelIndex & modelIndex); void loadListInfo(const QModelIndex & modelIndex); + void loadSpecialListInfo(const qulonglong id); + void loadLabelInfo(const qulonglong id); + void loadReadingListInfo(const qulonglong id); + void loadPreviousStatus(); private: diff --git a/images/empty_label.png b/images/empty_label.png new file mode 100644 index 00000000..58ea44bc Binary files /dev/null and b/images/empty_label.png differ diff --git a/images/empty_label_osx.png b/images/empty_label_osx.png new file mode 100644 index 00000000..77a70667 Binary files /dev/null and b/images/empty_label_osx.png differ