Skip to content

Commit

Permalink
much faster CatalogWindow
Browse files Browse the repository at this point in the history
- remove limitation volume counts
- background volumes initialization
- scroll vertical for ListMode on CatalogWindow
- bugfixed: CatalogWindow as modeless, can't accept drop files
- known problem: mouse wheel scroll is slow on CatalogWindow when ListMode -> Icon/IconNoText changed
  • Loading branch information
kanryu committed May 12, 2017
1 parent 02b037b commit bc1787e
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 78 deletions.
8 changes: 5 additions & 3 deletions QuickViewer/QuickViewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ QT += core gui opengl concurrent opengl-private sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

VERSION = 0.6.2
VERSION = 0.6.3

TARGET = QuickViewer
TEMPLATE = app
Expand Down Expand Up @@ -104,7 +104,8 @@ SOURCES += main.cpp \
catalog/fileexplorermodel.cpp \
catalog/managedatabasedialog.cpp \
catalog/thumbnailmanager.cpp \
sidesplitter.cpp
sidesplitter.cpp \
catalog/volumeitemmodel.cpp

HEADERS += mainwindow.h \
imageview.h \
Expand All @@ -126,7 +127,8 @@ HEADERS += mainwindow.h \
catalog/qc_init.h \
catalog/thumbnailmanager.h \
sidesplitter.h \
stdafx.h
stdafx.h \
catalog/volumeitemmodel.h

win32 {
SOURCES += mainwindowforwindows.cpp
Expand Down
189 changes: 118 additions & 71 deletions QuickViewer/catalog/catalogwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <QtWidgets>
#ifdef Q_OS_WIN
#include <Windows.h>
#endif

#include "ui_catalogwindow.h"
#include "ui_mainwindow.h"
Expand All @@ -12,9 +15,14 @@ CatalogWindow::CatalogWindow(QWidget *parent, Ui::MainWindow *uiMain)
: QWidget(parent)
, ui(new Ui::CatalogWindow)
, m_folderViewMenu(this)
, m_itemModel(this)
{
ui->setupUi(this);

// VolumeView
m_itemModel.setViewMode(qApp->CatalogViewModeSetting());
ui->volumeList->setModel(&m_itemModel);

// SearchCombo
connect(ui->searchCombo->lineEdit(), SIGNAL(editingFinished()), this, SLOT(on_searchTextFinished()));
ui->searchCombo->lineEdit()->setPlaceholderText(tr("Input Search words and Press Enter-key"));
Expand All @@ -39,16 +47,22 @@ CatalogWindow::~CatalogWindow()
void CatalogWindow::setThumbnailManager(ThumbnailManager *manager)
{
m_thumbManager = manager;
m_volumes = m_thumbManager->volumes2();
searchByWord(true);
m_volumes = m_thumbManager->volumes();

on_folderViewIcon_triggered();
switch(qApp->CatalogViewModeSetting()) {
case qvEnums::List: on_folderViewList_triggered(); break;
case qvEnums::Icon: on_folderViewIcon_triggered(); break;
case qvEnums::IconNoText: on_folderViewNotext_triggered(); break;
}
searchByWord(true);
}

void CatalogWindow::setAsToplevelWindow()
{
ui->menuBar->setVisible(true);
ui->statusLabel->setWordWrap(false);
setAttribute(Qt::WA_DropSiteRegistered, false);
setAcceptDrops(true);
}

void CatalogWindow::setAsInnerWidget()
Expand All @@ -65,71 +79,79 @@ bool CatalogWindow::isCatalogSearching()

void CatalogWindow::resetVolumes()
{
bool withText = !ui->actionFolderViewIconNoText->isChecked();
ui->volumeList->clear();
foreach(VolumeThumbRecord* vtr, m_volumeSearch) {
if(vtr->thumbnail.isEmpty())
continue;
auto item = new QListWidgetItem;
// if(vtr->icon.isNull()) {
// vtr->icon = QIcon(QPixmap::fromImage(QImage::fromData(vtr->thumbnail)));
// }
item->setIcon(vtr->icon);
// item->setIcon(QIcon(QPixmap::fromImage(QImage::fromData(vtr->thumbnail))));
item->setData(Qt::UserRole, vtr->path);
if(withText) {
if(qApp->TitleWithoutOptions())
item->setText(vtr->name);
else
item->setText(vtr->realname);
}
ui->volumeList->addItem(item);
}
m_itemModel.setVolumes(&m_volumeSearch);
if(m_volumes.size() > 0) {
QString volumestxt = QString(tr("(%1/%2) volumes listed."))
.arg(m_volumeSearch.size()).arg(m_volumes.size());
ui->statusLabel->setText(volumestxt);
}
return;

ui->volumeList->setIconSize(QSize(96,96));
ui->volumeList->setResizeMode(QListView::Adjust);
switch(qApp->CatalogViewModeSetting()) {
case qvEnums::List:
ui->volumeList->setWrapping(true);
ui->volumeList->setWordWrap(true);
ui->volumeList->setGridSize(QSize(150, 170));
ui->volumeList->setDragEnabled(false);
ui->volumeList->setTextElideMode(Qt::ElideRight);

ui->volumeList->setViewMode(QListView::ListMode);
ui->volumeList->setGridSize(QSize(300, 100));
ui->volumeList->setFlow(QListView::TopToBottom);
ui->volumeList->setUniformItemSizes(false);
break;
case qvEnums::Icon:
ui->volumeList->setWrapping(true);
ui->volumeList->setWordWrap(true);
ui->volumeList->setGridSize(QSize(150, 170));
ui->volumeList->setDragEnabled(false);
ui->volumeList->setTextElideMode(Qt::ElideRight);

ui->volumeList->setViewMode(QListView::IconMode);
ui->volumeList->setWordWrap(true);
ui->volumeList->setGridSize(QSize(150, 170));
ui->volumeList->setFlow(QListView::LeftToRight);
ui->volumeList->setUniformItemSizes(false);
break;
case qvEnums::IconNoText:
ui->volumeList->setWrapping(true);
ui->volumeList->setWordWrap(true);
ui->volumeList->setDragEnabled(false);
ui->volumeList->setTextElideMode(Qt::ElideRight);

ui->volumeList->setViewMode(QListView::IconMode);
ui->volumeList->setGridSize(QSize(100, 100));
ui->volumeList->setFlow(QListView::LeftToRight);
ui->volumeList->setUniformItemSizes(false);
}
// bool withText = !ui->actionFolderViewIconNoText->isChecked();
// ui->volumeList->clear();
// foreach(VolumeThumbRecord* vtr, m_volumeSearch) {
// if(vtr->thumbnail.isEmpty())
// continue;
// auto item = new QListWidgetItem;
//// if(vtr->icon.isNull()) {
//// vtr->icon = QIcon(QPixmap::fromImage(QImage::fromData(vtr->thumbnail)));
//// }
// item->setIcon(vtr->icon);
//// item->setIcon(QIcon(QPixmap::fromImage(QImage::fromData(vtr->thumbnail))));
// item->setData(Qt::UserRole, vtr->path);
// if(withText) {
// if(qApp->TitleWithoutOptions())
// item->setText(vtr->name);
// else
// item->setText(vtr->realname);
// }
// ui->volumeList->addItem(item);
// }
// if(m_volumes.size() > 0) {
// QString volumestxt = QString(tr("(%1/%2) volumes listed."))
// .arg(m_volumeSearch.size()).arg(m_volumes.size());
// ui->statusLabel->setText(volumestxt);
// }

// ui->volumeList->setIconSize(QSize(96,96));
// ui->volumeList->setResizeMode(QListView::Adjust);
// switch(qApp->CatalogViewModeSetting()) {
// case qvEnums::List:
// ui->volumeList->setWrapping(true);
// ui->volumeList->setWordWrap(true);
// ui->volumeList->setGridSize(QSize(150, 170));
// ui->volumeList->setDragEnabled(false);
// ui->volumeList->setTextElideMode(Qt::ElideRight);

// ui->volumeList->setViewMode(QListView::ListMode);
// ui->volumeList->setGridSize(QSize(300, 100));
// ui->volumeList->setFlow(QListView::TopToBottom);
// ui->volumeList->setUniformItemSizes(false);
// break;
// case qvEnums::Icon:
// ui->volumeList->setWrapping(true);
// ui->volumeList->setWordWrap(true);
// ui->volumeList->setGridSize(QSize(150, 170));
// ui->volumeList->setDragEnabled(false);
// ui->volumeList->setTextElideMode(Qt::ElideRight);

// ui->volumeList->setViewMode(QListView::IconMode);
// ui->volumeList->setWordWrap(true);
// ui->volumeList->setGridSize(QSize(150, 170));
// ui->volumeList->setFlow(QListView::LeftToRight);
// ui->volumeList->setUniformItemSizes(false);
// break;
// case qvEnums::IconNoText:
// ui->volumeList->setWrapping(true);
// ui->volumeList->setWordWrap(true);
// ui->volumeList->setDragEnabled(false);
// ui->volumeList->setTextElideMode(Qt::ElideRight);

// ui->volumeList->setViewMode(QListView::IconMode);
// ui->volumeList->setGridSize(QSize(100, 100));
// ui->volumeList->setFlow(QListView::LeftToRight);
// ui->volumeList->setUniformItemSizes(false);
// }
}

void CatalogWindow::searchByWord(bool doForce)
Expand All @@ -149,8 +171,8 @@ void CatalogWindow::searchByWord(bool doForce)
QString title = qApp->SearchTitleWithOptions() ? vtr.nameNoCase : vtr.realnameNoCase;
if(!searchwords.match(title))
continue;
if(qApp->MaxShowFrontpage() < ++cnt)
break;
// if(qApp->MaxShowFrontpage() < ++cnt)
// break;
m_volumeSearch.append(const_cast<VolumeThumbRecord*>(&vtr));
}
resetVolumes();
Expand All @@ -175,7 +197,7 @@ void CatalogWindow::dropEvent(QDropEvent *e)
dialog.dropEvent(e);
dialog.exec();

m_volumes = m_thumbManager->volumes2();
m_volumes = m_thumbManager->volumes();
searchByWord(true);

resetVolumes();
Expand All @@ -200,6 +222,12 @@ void CatalogWindow::on_folderViewList_triggered()
ui->actionFolderViewList->setChecked(true);
ui->actionFolderViewIcon->setChecked(false);
ui->actionFolderViewIconNoText->setChecked(false);
m_itemModel.setViewMode(qvEnums::List);
ui->volumeList->setResizeMode(QListView::Adjust);
ui->volumeList->setGridSize(QSize(300, 100));
ui->volumeList->setViewMode(QListView::ListMode);
ui->volumeList->setUniformItemSizes(true);

resetVolumes();
}

Expand All @@ -209,6 +237,12 @@ void CatalogWindow::on_folderViewIcon_triggered()
ui->actionFolderViewList->setChecked(false);
ui->actionFolderViewIcon->setChecked(true);
ui->actionFolderViewIconNoText->setChecked(false);
m_itemModel.setViewMode(qvEnums::Icon);
ui->volumeList->setResizeMode(QListView::Adjust);
ui->volumeList->setGridSize(QSize(150, 170));
ui->volumeList->setViewMode(QListView::IconMode);
ui->volumeList->setUniformItemSizes(true);

resetVolumes();
}

Expand All @@ -218,6 +252,12 @@ void CatalogWindow::on_folderViewNotext_triggered()
ui->actionFolderViewList->setChecked(false);
ui->actionFolderViewIcon->setChecked(false);
ui->actionFolderViewIconNoText->setChecked(true);
m_itemModel.setViewMode(qvEnums::IconNoText);
ui->volumeList->setResizeMode(QListView::Adjust);
ui->volumeList->setViewMode(QListView::IconMode);
ui->volumeList->setGridSize(QSize(100, 100));
ui->volumeList->setUniformItemSizes(true);

resetVolumes();
}

Expand All @@ -227,16 +267,14 @@ void CatalogWindow::on_manageDatabase_triggered()
dialog.setThumbnailManager(m_thumbManager);
dialog.exec();

m_volumes = m_thumbManager->volumes2();
m_volumes = m_thumbManager->volumes();
searchByWord(true);

resetVolumes();
}

void CatalogWindow::on_searchTextChanged(QString search)
{
qDebug() << search;
if(m_volumes.size() < qApp->MaxSearchByCharChanged())
// if(m_volumes.size() < qApp->MaxSearchByCharChanged())
searchByWord();
return;
}
Expand All @@ -259,11 +297,18 @@ void CatalogWindow::on_itemDoubleClicked(QListWidgetItem *item)
emit openVolume(path);
}

void CatalogWindow::on_itemDoubleClicked(const QModelIndex &index)
{
int row = index.row();
if(row >= m_volumeSearch.size())
return;
emit openVolume(m_volumeSearch[row]->path);
}

void CatalogWindow::on_searchTitleWithOptions_triggered(bool enable)
{
qApp->setSearchTitleWithOptions(enable);
resetVolumes();

searchByWord(true);
}

void CatalogWindow::on_catalogTitleWithoutOptions_triggered(bool enable)
Expand All @@ -286,6 +331,8 @@ SearchWords::SearchWords(const QString &searchNoCase)
}
isEmpty = false;
foreach(const QString& s, searchNoCase.trimmed().split(" ")) {
if(s.isEmpty())
continue;
if(s[0] == '-')
nomatches << s.mid(1);
else
Expand Down
3 changes: 3 additions & 0 deletions QuickViewer/catalog/catalogwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QMainWindow>
#include <QListWidget>
#include "thumbnailmanager.h"
#include "volumeitemmodel.h"

namespace Ui {
class CatalogWindow;
Expand Down Expand Up @@ -50,6 +51,7 @@ public slots:
void on_searchTextIndexChanged(QString search);
void on_searchTextFinished();
void on_itemDoubleClicked(QListWidgetItem * item);
void on_itemDoubleClicked(const QModelIndex & index);
void on_searchTitleWithOptions_triggered(bool enable);
void on_catalogTitleWithoutOptions_triggered(bool enable);

Expand All @@ -69,6 +71,7 @@ public slots:
QList<VolumeThumbRecord*> m_volumeSearch;
QMenu m_folderViewMenu;
QString m_lastSearchWord;
VolumeItemModel m_itemModel;
};

#endif // CATALOGWINDOW_H
Loading

0 comments on commit bc1787e

Please sign in to comment.