diff options
author | Arno <arno@disconnect.de> | 2018-03-31 21:44:36 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-03-31 21:44:36 +0200 |
commit | 82ccb81006d8e82c7f0d9a5febe632e198452425 (patch) | |
tree | f64d63abcb86b651b622ead70d4e4569ee863aed | |
parent | ab8c38e0c2d5370d2ef5c54bd2f8c414d49deb92 (diff) | |
download | SheMov-82ccb81006d8e82c7f0d9a5febe632e198452425.tar.gz SheMov-82ccb81006d8e82c7f0d9a5febe632e198452425.tar.bz2 SheMov-82ccb81006d8e82c7f0d9a5febe632e198452425.zip |
View picture on doubleclick
Use lightweight viewer from ShemovCleaner for this. Unfortunately
PictureViewer2 is overengineered for this.
-rw-r--r-- | fswidget.cpp | 12 | ||||
-rw-r--r-- | fswidget.h | 5 | ||||
-rw-r--r-- | shemov.pro | 6 | ||||
-rw-r--r-- | viewer.cpp | 94 | ||||
-rw-r--r-- | viewer.h | 27 |
5 files changed, 141 insertions, 3 deletions
diff --git a/fswidget.cpp b/fswidget.cpp index ce65574..7cce362 100644 --- a/fswidget.cpp +++ b/fswidget.cpp @@ -23,10 +23,12 @@ #include "helper.h" #include "newmoviewizard.h" #include "fsproxy.h" +#include "viewer.h" FSWidget::FSWidget(QWidget *parent) : QWidget(parent) { mMovieWizard = new NewMovieWizard(this); mMovieWizard->setMinimumWidth(1024); + mViewer = new Viewer; setPalette(qApp->palette()); setupWidget(); } @@ -117,6 +119,7 @@ void FSWidget::setupWidget(){ mFileView->setUniformRowHeights(true); mFileView->setSelectionBehavior(QAbstractItemView::SelectRows); mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); + connect(mFileView, &QTreeView::doubleClicked, this, &FSWidget::doubleClicked); mModel = new QStandardItemModel; mProxy = new FSProxy; mProxy->setSourceModel(mModel); @@ -293,6 +296,7 @@ void FSWidget::gatherData(const QString &curDir){ item->setData(fi.absoluteFilePath(), FullPathRole); item->setData(fi.size(), SizeRole); item->setData(seconds, DurationRole); + item->setData(mimeType.name(), MimeRole); items << item; } items[0]->setText(fi.fileName()); @@ -417,3 +421,11 @@ void FSWidget::unpack(){ } } } + +void FSWidget::doubleClicked(const QModelIndex &idx){ + QString mime = idx.data(MimeRole).toString(); + if(mime.startsWith("image")){ + mViewer->setFile(idx.data(FullPathRole).toString()); + } + mViewer->showMaximized(); +} @@ -10,12 +10,13 @@ class QStandardItemModel; class QSortFilterProxyModel; class QContextMenuEvent; class NewMovieWizard; +class Viewer; class FSProxy; class FSWidget : public QWidget { Q_OBJECT public: - enum CustomRoles { FullPathRole = Qt::UserRole + 1, DurationRole = Qt::UserRole + 2, SizeRole = Qt::UserRole + 3 }; + enum CustomRoles { FullPathRole = Qt::UserRole + 1, DurationRole = Qt::UserRole + 2, SizeRole = Qt::UserRole + 3, MimeRole = Qt::UserRole + 4 }; explicit FSWidget(QWidget *parent = nullptr); ~FSWidget(); @@ -37,6 +38,7 @@ class FSWidget : public QWidget { int queryCount(QSqlQuery &q, const QString &arg); void filterMime(const QString &mime); void unpack(); + void doubleClicked(const QModelIndex &idx); signals: void message(QString msg); @@ -49,6 +51,7 @@ class FSWidget : public QWidget { QStandardItemModel *mModel; FSProxy *mProxy; NewMovieWizard *mMovieWizard; + Viewer *mViewer; int mQueryCount; }; @@ -49,7 +49,8 @@ SOURCES = main.cpp \ copyworker.cpp \ randomtab.cpp \ fswidget.cpp \ - fsproxy.cpp + fsproxy.cpp \ + viewer.cpp HEADERS = \ filesystemdirproxy.h \ filesystemwidget.h \ @@ -93,7 +94,8 @@ HEADERS = \ copyworker.h \ randomtab.h \ fswidget.h \ - fsproxy.h + fsproxy.h \ + viewer.h LIBS += -lmagic -lXfixes -lX11 -lMagick++-6.Q16HDRI INCLUDEPATH += /usr/include/ImageMagick-6/ RESOURCES = shemov.qrc diff --git a/viewer.cpp b/viewer.cpp new file mode 100644 index 0000000..fec9c81 --- /dev/null +++ b/viewer.cpp @@ -0,0 +1,94 @@ +#include <QLabel>
+#include <QHBoxLayout>
+#include <QDesktopWidget>
+#include <QApplication>
+#include <QFileInfo>
+#include <QMimeDatabase>
+#include <QDir>
+#include <QWheelEvent>
+
+#include "helper.h"
+#include "viewer.h"
+
+Viewer::Viewer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mCurIndex(-1) {
+ QDesktopWidget *dw = qApp->desktop();
+ setAutoFillBackground(true);
+ setBackgroundRole(QPalette::AlternateBase);
+ mLabel = new QLabel;
+ mLabel->setAlignment(Qt::AlignCenter);
+ mMaxSize = dw->size();
+ //90 is an arbitrary value, but it works :)
+ mMaxSize.setHeight(mMaxSize.height() - 90);
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ mainLayout->addWidget(mLabel);
+ setLayout(mainLayout);
+}
+
+void Viewer::setFile(const QString &file, bool allFiles){
+ mFiles.clear();
+ mCurIndex = -1;
+ QFileInfo fi(file);
+ QMimeDatabase db;
+ QMimeType mt = db.mimeTypeForFile(fi);
+ if(mt.name().startsWith("image")){
+ mFiles << fi.absoluteFilePath();
+ }
+ if(allFiles){
+ for(auto curFi : fi.dir().entryInfoList()){
+ if(!mFiles.contains(curFi.absoluteFilePath())){
+ QMimeType mt = db.mimeTypeForFile(curFi);
+ if(mt.name().startsWith("image")){
+ mFiles << curFi.absoluteFilePath();
+ }
+ }
+ }
+ }
+ if(!mFiles.isEmpty()){
+ mCurIndex = 0;
+ displayFile(mCurIndex);
+ }
+}
+
+void Viewer::preview(const QString &file){
+ mFiles.clear();
+ mCurIndex = -1;
+ QPixmap pm = Helper::preview(file);
+ mLabel->setPixmap(pm);
+ QString winTitle = QString(tr("%1 Viewer: [Preview %2]")).arg(qApp->applicationName()).arg(file);
+ setWindowTitle(winTitle);
+ adjustSize();
+}
+
+
+void Viewer::wheelEvent(QWheelEvent *event){
+ if(mCurIndex == -1){
+ return;
+ }
+ QPoint numDeg = event->angleDelta() / 8;
+ if(numDeg.y() < 0){ //this is scrolling down -> next!
+ if(mCurIndex + 1 >= mFiles.count()){
+ mCurIndex = 0;
+ }else{
+ ++mCurIndex;
+ }
+ }else if(numDeg.y() > 0){
+ if(mCurIndex - 1 < 0){
+ mCurIndex = mFiles.count() - 1;
+ }else{
+ --mCurIndex;
+ }
+ }
+ displayFile(mCurIndex);
+ event->accept();
+}
+
+void Viewer::displayFile(int index){
+ if(index < 0){
+ return;
+ }
+ QPixmap pm(mFiles.at(mCurIndex));
+ pm = pm.scaled(mMaxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ mLabel->setPixmap(pm);
+ QString winTitle = QString(tr("%1 Viewer [%2]")).arg(qApp->applicationName()).arg(mFiles.at(mCurIndex));
+ setWindowTitle(winTitle);
+}
diff --git a/viewer.h b/viewer.h new file mode 100644 index 0000000..a790b9a --- /dev/null +++ b/viewer.h @@ -0,0 +1,27 @@ +#ifndef VIEWER_H
+#define VIEWER_H
+
+#include <QWidget>
+
+class QLabel;
+
+class Viewer : public QWidget {
+ public:
+ Viewer(QWidget *parent = 0, Qt::WindowFlags f = 0);
+ void setFile(const QString &file, bool allFiles = true);
+ void preview(const QString &file);
+
+ protected:
+ virtual void wheelEvent(QWheelEvent *event);
+
+ private slots:
+ void displayFile(int index);
+
+ private:
+ int mCurIndex;
+ QLabel *mLabel;
+ QStringList mFiles;
+ QSize mMaxSize;
+};
+
+#endif // VIEWER_H
|