Skip to content

Commit

Permalink
add support to Rename, change background color, bugfixed
Browse files Browse the repository at this point in the history
- support to Rename current image file, only for folders
- support to change background color, can be checkered pattern
- bugfixed: if set max volume cache < 4, changing the volume resulted in an unauthorized termination
- buffixed: If the volume is already read, even if you specify the file of the folder and open the volume, the read file was opened
  • Loading branch information
kanryu committed Jul 4, 2017
1 parent 391deec commit 9ac7966
Show file tree
Hide file tree
Showing 21 changed files with 790 additions and 164 deletions.
11 changes: 7 additions & 4 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.7.6
VERSION = 0.7.7

TARGET = QuickViewer
TEMPLATE = app
Expand Down Expand Up @@ -139,7 +139,8 @@ SOURCES += \
src/main.cpp \
src/mainwindow.cpp \
src/mainwindowforwindows.cpp \
src/optionsdialog.cpp
src/optionsdialog.cpp \
src/renamedialog.cpp

HEADERS += \
src/qv_init.h \
Expand Down Expand Up @@ -195,7 +196,8 @@ HEADERS += \
src/mainwindowforwindows.h \
src/qv_init.h \
src/stdafx.h \
src/optionsdialog.h
src/optionsdialog.h \
src/renamedialog.h

win32 {
SOURCES += src/mainwindowforwindows.cpp
Expand All @@ -215,7 +217,8 @@ FORMS += \
src/catalog/catalogwindow.ui \
src/catalog/createdb.ui \
src/folderview/folderwindow.ui \
src/optionsdialog.ui
src/optionsdialog.ui \
src/renamedialog.ui

RESOURCES += \
toolbar.qrc
Expand Down
30 changes: 24 additions & 6 deletions QuickViewer/src/imageview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ImageView::ImageView(QWidget *parent)
setRenderer(OpenGL);

setMouseTracking(true);

resetBackgroundColor();

}

Expand Down Expand Up @@ -94,6 +94,24 @@ void ImageView::toggleSlideShow()
m_slideshowTimer->start(qApp->SlideShowWait());
}

void ImageView::resetBackgroundColor()
{
// QColor bg = qApp->BackgroundColor();
// setStyleSheet(QString("background-color:") + bg.name(QColor::HexArgb));
if(!qApp->UseCheckeredPattern()) {
setBackgroundBrush(QBrush(qApp->BackgroundColor(), Qt::SolidPattern));
return;
}
QPixmap pix(16, 16);
pix.fill(qApp->BackgroundColor());
QPainter paint(&pix);
QBrush brush2(qApp->BackgroundColor2(), Qt::SolidPattern);
paint.fillRect(QRect(0, 0, 8, 8), brush2);
paint.fillRect(QRect(8, 8, 8, 8), brush2);
QBrush brush(pix);
setBackgroundBrush(brush);
}

void ImageView::on_volumeChanged_triggered(QString path)
{
m_pageRotations = QVector<int>(m_pageManager->size());
Expand Down Expand Up @@ -166,11 +184,11 @@ void ImageView::readyForPaint() {
repaint();
}

void ImageView::paintEvent(QPaintEvent *event)
{
// readyForPaint();
QGraphicsView::paintEvent(event);
}
//void ImageView::paintEvent(QPaintEvent *event)
//{
//// readyForPaint();
// QGraphicsView::paintEvent(event);
//}

void ImageView::resizeEvent(QResizeEvent *event)
{
Expand Down
3 changes: 2 additions & 1 deletion QuickViewer/src/imageview.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ImageView : public QGraphicsView
bool isSlideShow() const { return m_slideshowTimer != nullptr; }
void toggleSlideShow();
void setWillFullscreen(bool fullscreen) { m_isFullScreen = fullscreen; }
void resetBackgroundColor();

signals:
/**
Expand All @@ -72,7 +73,7 @@ class ImageView : public QGraphicsView
void mouseMoveEvent(QMouseEvent *event);
// void mousePressEvent(QMouseEvent *event);
// void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event) override;
// void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
// void dragEnterEvent(QDragEnterEvent *event) { event->accept(); qDebug() << "ImageView::dragEnterEvent"; }
// void dropEvent( QDropEvent *e ) {qDebug() << "ImageView::dropEvent";}
Expand Down
22 changes: 20 additions & 2 deletions QuickViewer/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "optionsdialog.h"
#include "catalogwindow.h"
#include "folderwindow.h"
#include "renamedialog.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Expand Down Expand Up @@ -848,9 +849,16 @@ void MainWindow::on_openKeyConfig_triggered()
void MainWindow::on_openOptionsDialog_triggered()
{
OptionsDialog dialog(this);
int result = dialog.exec();
if(result == QDialog::Accepted) {
QColor back = qApp->BackgroundColor();
QColor back2 = qApp->BackgroundColor2();
bool checkered = qApp->UseCheckeredPattern();
if(dialog.exec() == QDialog::Accepted) {
dialog.reflectResults();
if(back != qApp->BackgroundColor()
|| back2 != qApp->BackgroundColor2()
|| checkered != qApp->UseCheckeredPattern()) {
ui->graphicsView->resetBackgroundColor();
}
}
}

Expand Down Expand Up @@ -888,6 +896,16 @@ void MainWindow::on_mailAttachment_triggered()
setMailAttachment(path);
}

void MainWindow::on_renameImageFile_triggered()
{
if(!m_pageManager.isFolder() || m_pageManager.currentPageCount() == 0)
return;
RenameDialog dialog(this, m_pageManager.realVolumePath(), m_pageManager.currentPageName());
if(dialog.exec() == QDialog::Accepted) {
m_pageManager.loadVolume(QDir(m_pageManager.realVolumePath()).absoluteFilePath(dialog.newName()));
}
}

void MainWindow::on_deletePage_triggered()
{
if(m_pageManager.currentPageCount() <= 0 || !m_pageManager.isFolder())
Expand Down
1 change: 1 addition & 0 deletions QuickViewer/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public slots:
void on_deletePage_triggered();
void on_exitApplicationOrFullscreen_triggered();
void on_mailAttachment_triggered();
void on_renameImageFile_triggered();

// Shaders
void on_shaderNearestNeighbor_triggered();
Expand Down
32 changes: 23 additions & 9 deletions QuickViewer/src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@
<property name="lineWidth">
<number>0</number>
</property>
<property name="backgroundBrush">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</property>
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
</property>
Expand Down Expand Up @@ -322,6 +313,7 @@
<addaction name="actionCopyPage"/>
<addaction name="actionCopyFile"/>
<addaction name="actionDeletePage"/>
<addaction name="actionRenameImageFile"/>
<addaction name="actionMailAttachment"/>
<addaction name="separator"/>
<addaction name="actionOpenFiler"/>
Expand Down Expand Up @@ -980,6 +972,11 @@
<string>&amp;Options Config</string>
</property>
</action>
<action name="actionRenameImageFile">
<property name="text">
<string>Rename the image</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down Expand Up @@ -2098,6 +2095,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionRenameImageFile</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>on_renameImageFile_triggered()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>350</x>
<y>294</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>on_file_changed(QString)</slot>
Expand Down Expand Up @@ -2154,5 +2167,6 @@
<slot>on_openVolumeWithProgress_triggered(bool)</slot>
<slot>on_showReadProgress_triggered(bool)</slot>
<slot>on_openOptionsDialog_triggered()</slot>
<slot>on_renameImageFile_triggered()</slot>
</slots>
</ui>
2 changes: 2 additions & 0 deletions QuickViewer/src/models/filevolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ IFileVolume::IFileVolume(QObject *parent, IFileLoader* loader, PageManager* page
, m_cacheMode(CacheMode::Normal)
, m_pageManager(pageManager)
, m_imageCache(20)
, m_openedWithSpecifiedImageFile(false)
{
m_filelist = m_loader->contents();
}
Expand Down Expand Up @@ -146,6 +147,7 @@ static IFileVolume* CreateVolumeImpl(QObject* parent, QString path, PageManager*
QString dirpath = dir.canonicalPath();
IFileVolume* fvd = new IFileVolume(parent, qApp->ShowSubfolders() ? new FileLoaderSubDirectory(parent, path) : new FileLoaderDirectory(parent, dirpath), pageManager);
fvd->findImageByName(path.mid(dirpath.length()+1));
fvd->setOpenedWithSpecifiedImageFile(true);
return fvd;
}
return nullptr;
Expand Down
5 changes: 4 additions & 1 deletion QuickViewer/src/models/filevolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class IFileVolume : public QObject

const ImageContent currentImage() { return m_cacheMode == NoAsync ? m_currentCacheSync : m_currentCache.result(); }
QString volumePath() { return m_loader->volumePath(); }
QString realVolumePath() { return m_loader->realVolumePath(); }

bool nextPage();
bool prevPage();
Expand Down Expand Up @@ -112,7 +113,8 @@ class IFileVolume : public QObject
// QString getIndexedImageName(int idx) { return m_filelist[idx]; }
// QString currentImageName() const { return m_filelist[m_cnt]; }
const ImageContent getIndexedImageContent(int idx);

bool openedWithSpecifiedImageFile() { return m_openedWithSpecifiedImageFile; }
void setOpenedWithSpecifiedImageFile(bool openedWithSpecifiedImageFile) { m_openedWithSpecifiedImageFile = openedWithSpecifiedImageFile; }

protected:
/**
Expand All @@ -132,6 +134,7 @@ class IFileVolume : public QObject
IFileLoader* m_loader;
CacheMode m_cacheMode;
PageManager* m_pageManager;
bool m_openedWithSpecifiedImageFile;
};


Expand Down
5 changes: 3 additions & 2 deletions QuickViewer/src/models/pagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void PageManager::nextVolume()
} else {
addVolumeCache(path, true);
}
if(matchCount >= PRE_LOAD_VOLUMES)
if(matchCount >= qApp->MaxVolumesCache()*3/2-1)
break;
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ void PageManager::prevVolume()
} else {
addVolumeCache(path, true);
}
if(matchCount >= PRE_LOAD_VOLUMES)
if(matchCount >= qApp->MaxVolumesCache()*3/2-1)
break;
}
}
Expand Down Expand Up @@ -134,6 +134,7 @@ IFileVolume* PageManager::addVolumeCache(QString path, bool onlyCover)
// change page by progress.ini
QString volumepath = QDir::fromNativeSeparators(newer->volumePath());
if(qApp->OpenVolumeWithProgress()
&& !newer->openedWithSpecifiedImageFile()
&& qApp->bookshelfManager()->contains(volumepath)) {
BookProgress book = qApp->bookshelfManager()->at(volumepath);
newer->findPageByIndex(book.Current);
Expand Down
2 changes: 2 additions & 0 deletions QuickViewer/src/models/pagemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PageManager : public QObject
int idx = m_fileVolume->size()-1==m_currentPage ? m_currentPage-1 : m_currentPage+1;
return QDir::toNativeSeparators(m_fileVolume->getPathByIndex(idx));
}
QString currentPageName() { return m_pages[0].Path; }

/**
* @brief currentPageNumAsString: for the label text on PageBar
Expand All @@ -64,6 +65,7 @@ class PageManager : public QObject
*/
QString currentPageStatusAsString() const;
QString volumePath(){ return m_fileVolume ? m_fileVolume->volumePath() : ""; }
QString realVolumePath() { return m_fileVolume ? m_fileVolume->realVolumePath() : ""; }
bool isArchive() {
if(!m_fileVolume) return false;
return m_fileVolume->isArchive();
Expand Down
16 changes: 12 additions & 4 deletions QuickViewer/src/models/qvapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void QVApplication::registDefaultKeyMap()
m_keyConfigDefauls["actionZoomIn"] = QKeySequence("K, Num++");
m_keyConfigDefauls["actionZoomOut"] = QKeySequence("J, Num+-");

m_keyConfigDefauls["actionRenameImageFile"] = QKeySequence("F2");
m_keyConfigDefauls["actionShowFolder"] = QKeySequence("F4");
m_keyConfigDefauls["actionShowCatalog"] = QKeySequence("Ctrl+/, F6");
m_keyConfigDefauls["actionSlideShow"] = QKeySequence("F7");
Expand Down Expand Up @@ -138,6 +139,7 @@ void QVApplication::registActions(Ui::MainWindow *ui)
registAction("actionCopyFile", ui->actionCopyFile);
registAction("actionDeletePage", ui->actionDeletePage);
registAction("actionMailAttachment", ui->actionMailAttachment);
registAction("actionRenameImageFile", ui->actionRenameImageFile);

// Shader
registAction("actionShaderNearestNeighbor", ui->actionShaderNearestNeighbor);
Expand All @@ -148,6 +150,7 @@ void QVApplication::registActions(Ui::MainWindow *ui)

// Help
registAction("actionOpenKeyConfig", ui->actionOpenKeyConfig);
registAction("actionOpenOptionsDialog", ui->actionOpenOptionsDialog);
registAction("actionCheckVersion", ui->actionCheckVersion);
registAction("actionProjectWeb", ui->actionProjectWeb);
registAction("actionAppVersion", ui->actionAppVersion);
Expand Down Expand Up @@ -243,6 +246,9 @@ void QVApplication::loadSettings()
#else
m_maxVolumesCache = m_settings.value("MaxVolumesCache", 1).toInt();
#endif
m_backgroundColor = QColor(m_settings.value("BackgroundColor", "0x797979").toString().toUInt(nullptr, 16));
m_backgroundColor2 = QColor(m_settings.value("BackgroundColor2", "0x5e5e5e").toString().toUInt(nullptr, 16));
m_useCheckeredPattern = m_settings.value("UseCheckeredPattern", true).toBool();
m_settings.endGroup();

m_settings.beginGroup("WindowState");
Expand Down Expand Up @@ -294,11 +300,7 @@ void QVApplication::loadSettings()
m_settings.endGroup();

m_settings.beginGroup("Shader");
#ifdef Q_OS_WIN
QString effectstring = m_settings.value("Effect", "BilinearAndCpuBicubic").toString();
#else
QString effectstring = m_settings.value("Effect", "Bilinear").toString();
#endif
m_effect = ShaderManager::stringToShaderEffect(effectstring);
m_bicubicShaderPath = m_settings.value("BicubicShaderPath", "shaders/bicubic.frag").toString();
m_lanczosShaderPath = m_settings.value("LanczosShaderPath", "shaders/lanczos.frag").toString();
Expand All @@ -325,6 +327,12 @@ void QVApplication::saveSettings()
m_settings.setValue("ShowSubfolders", m_showSubfolders);
m_settings.setValue("SlideShowWait", m_slideShowWait);
m_settings.setValue("MaxVolumesCache", m_maxVolumesCache);
QString rgbstring;
rgbstring.setNum(m_backgroundColor.rgb(), 16);
m_settings.setValue("BackgroundColor", rgbstring);
rgbstring.setNum(m_backgroundColor2.rgb(), 16);
m_settings.setValue("BackgroundColor2", rgbstring);
m_settings.setValue("UseCheckeredPattern", m_useCheckeredPattern);
m_settings.endGroup();

m_settings.beginGroup("WindowState");
Expand Down
Loading

0 comments on commit 9ac7966

Please sign in to comment.