aboutsummaryrefslogtreecommitdiff
path: root/qdeduper
diff options
context:
space:
mode:
Diffstat (limited to 'qdeduper')
-rw-r--r--qdeduper/imageitem.cpp24
-rw-r--r--qdeduper/imageitem.hpp10
-rw-r--r--qdeduper/mingui.cpp25
3 files changed, 50 insertions, 9 deletions
diff --git a/qdeduper/imageitem.cpp b/qdeduper/imageitem.cpp
index 9ee7c6f..2958e06 100644
--- a/qdeduper/imageitem.cpp
+++ b/qdeduper/imageitem.cpp
@@ -128,15 +128,18 @@ QSize ImageItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMod
ret.setHeight(vpsz.height() / index.model()->rowCount() - lw->spacing());
ret.setHeight(std::max(min_height + extra_height, ret.height()));
ret.setHeight(std::min(max_height + extra_height, ret.height()));
+ if (singlemode) ret.setHeight(vpsz.height());
#if DEBUGPAINT
qDebug() << "sizehint" << index.row() << ret;
#endif
return ret;
}
-void ImageItemDelegate::resize(const QModelIndex &index)
+void ImageItemDelegate::resize()
{
- Q_EMIT sizeHintChanged(index);
+ if (im)
+ for (int i = 0; i < im->rowCount(); ++i)
+ Q_EMIT sizeHintChanged(im->index(i, 0));
}
void ImageItemDelegate::setScrollbarMargins(int vw, int hh)
@@ -144,3 +147,20 @@ void ImageItemDelegate::setScrollbarMargins(int vw, int hh)
this->vw = vw;
this->hh = hh;
}
+
+void ImageItemDelegate::set_single_item_mode(bool enabled)
+{
+ if (enabled == singlemode) return;
+ singlemode = enabled;
+ resize();
+}
+
+bool ImageItemDelegate::is_single_item_mode()
+{
+ return singlemode;
+}
+
+void ImageItemDelegate::set_model(QAbstractItemModel *m)
+{
+ im = m;
+}
diff --git a/qdeduper/imageitem.hpp b/qdeduper/imageitem.hpp
index 43fb0c8..b6d775e 100644
--- a/qdeduper/imageitem.hpp
+++ b/qdeduper/imageitem.hpp
@@ -3,6 +3,7 @@
#include <QStandardItem>
#include <QAbstractItemDelegate>
+#include <QAbstractItemModel>
#include <QStyleOptionViewItem>
#include <QModelIndex>
@@ -30,11 +31,18 @@ private:
const static int HKSHDS = 2;
int vw = -1;
int hh = -1;
+ bool singlemode = false;
+ QAbstractItemModel *im = nullptr;
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
- void resize(const QModelIndex &index);
+ void resize();
void setScrollbarMargins(int vw, int hh);
+
+ void set_single_item_mode(bool enabled);
+ bool is_single_item_mode();
+
+ void set_model(QAbstractItemModel *m);
Q_SIGNALS:
void sizeHintChanged(const QModelIndex &index);
};
diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp
index f93fda3..29cf416 100644
--- a/qdeduper/mingui.cpp
+++ b/qdeduper/mingui.cpp
@@ -16,6 +16,7 @@
#include <QMouseEvent>
#include <QScrollBar>
#include <QToolBar>
+#include <QTimer>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
@@ -95,6 +96,7 @@ DeduperMainWindow::DeduperMainWindow()
id = new ImageItemDelegate();
id->setScrollbarMargins(lv->verticalScrollBar()->width(),
lv->horizontalScrollBar()->height());
+ id->set_model(im);
lv->setItemDelegate(id);
lv->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
lv->setResizeMode(QListView::ResizeMode::Adjust);
@@ -131,7 +133,21 @@ DeduperMainWindow::DeduperMainWindow()
QAction *sa = new QAction();
sa->setShortcut(QKeySequence(Qt::Modifier::SHIFT | k));
QObject::connect(sa, &QAction::triggered, std::bind(&DeduperMainWindow::mark_all_but, this, i));
- selhk.push_back(a);
+ selhk.push_back(sa);
+ QAction *ca = new QAction();
+ ca->setShortcut(QKeySequence(Qt::Modifier::CTRL | k));
+ QObject::connect(ca, &QAction::triggered, [this, i] {
+ if (i >= im->rowCount()) return;
+ if (id->is_single_item_mode())
+ id->set_single_item_mode(false);
+ else
+ {
+ id->set_single_item_mode(true);
+ QTimer::singleShot(5, [this, i] {
+ lv->scrollTo(im->index(i, 0), QAbstractItemView::ScrollHint::PositionAtTop);});
+ }
+ });
+ selhk.push_back(ca);
}
this->addActions(selhk);
@@ -656,11 +672,8 @@ bool DeduperMainWindow::eventFilter(QObject *obj, QEvent *e)
{
if (e->type() == QEvent::Type::Resize)
{
- if (im && id && obj == lv)
- for (int i = 0; i < im->rowCount(); ++i)
- {
- id->resize(im->indexFromItem(im->item(i)));
- }
+ if (id && obj == lv)
+ id->resize();
return false;
}
return false;