aboutsummaryrefslogtreecommitdiff
path: root/mingui
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-12 11:48:39 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-12 11:48:39 -0400
commitaf5ff1296572ff55e86a5867b9e841014871123b (patch)
tree1878b7f232431f9dad82df6b7bad1e7909e91592 /mingui
parentdbd44af7c6452f630a664df0b00b2d17bdef2f06 (diff)
downloaddeduper-af5ff1296572ff55e86a5867b9e841014871123b.tar.xz
mingui adjustments. Fix image item rendering.
Always remove scrollbar dimensions from viewport. Elide filenames if needed. Use a splitter in the main widget instead of a fixed layout.
Diffstat (limited to 'mingui')
-rw-r--r--mingui/imageitem.cpp31
-rw-r--r--mingui/imageitem.hpp3
-rw-r--r--mingui/mingui.cpp20
-rw-r--r--mingui/mingui.hpp3
4 files changed, 41 insertions, 16 deletions
diff --git a/mingui/imageitem.cpp b/mingui/imageitem.cpp
index 470a2f2..6fee930 100644
--- a/mingui/imageitem.cpp
+++ b/mingui/imageitem.cpp
@@ -6,7 +6,6 @@
#include <QFileInfo>
#include <QPixmap>
#include <QListView>
-#include <QScrollBar>
#include <QFontMetrics>
#include <QPainter>
#include <QLocale>
@@ -84,21 +83,19 @@ void ImageItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
painter->setFont(option.font);
painter->setPen(option.widget->palette().color(QPalette::ColorGroup::Normal, QPalette::ColorRole::Text));
painter->drawText(r, infos, topt);
- r = option.fontMetrics.boundingRect(fns);
- r.moveTopRight(QPoint(option.rect.right() - MARGIN - BORDER, ftopright.y() + (hkbg.height() - r.height()) / 2));
- painter->drawText(r, fns, topt);
+ topt.setAlignment(Qt::AlignmentFlag::AlignRight);
+ r.setLeft(r.right());
+ r.setRight(imr.right());
+ QString efns = option.fontMetrics.elidedText(fns, Qt::TextElideMode::ElideMiddle, r.width());
+ painter->drawText(r, efns, topt);
}
QSize ImageItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const QListView *lw = qobject_cast<const QListView*>(option.widget);
QSize vpsz = lw->maximumViewportSize();
- QScrollBar *vsc = lw->verticalScrollBar();
- if (vsc->isVisible())
- vpsz.setWidth(vpsz.width() - vsc->size().width());
- QScrollBar *hsc = lw->horizontalScrollBar();
- if (hsc->isVisible())
- vpsz.setHeight(vpsz.height() - vsc->size().height());
+ vpsz.setWidth(vpsz.width() - vw);
+ vpsz.setHeight(vpsz.height() - hh);
QPixmap pm = index.data(Qt::ItemDataRole::DecorationRole).value<QPixmap>();
QSize onscsz = pm.size() / pm.devicePixelRatioF();
int imh = onscsz.height();
@@ -112,7 +109,15 @@ QSize ImageItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMod
int min_height = 64;
int max_height = imh;
+ QSize dim = index.data(ImageItem::ImageItemRoles::dimension_role).value<QSize>();
+ qint64 fsz = index.data(ImageItem::ImageItemRoles::file_size_role).value<qint64>();
+ QString infos = QString("%1 x %2, %3")
+ .arg(dim.width()).arg(dim.height())
+ .arg(QLocale::system().formattedDataSize(fsz, 3));
+ int textw = option.fontMetrics.boundingRect(infos).width() + fm.height() + 2 * HKPADD + 48;
+
QSize ret(vpsz);
+ if (textw > vpsz.width()) ret.setWidth(textw);
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()));
@@ -123,3 +128,9 @@ void ImageItemDelegate::resize(const QModelIndex &index)
{
Q_EMIT sizeHintChanged(index);
}
+
+void ImageItemDelegate::setScrollbarMargins(int vw, int hh)
+{
+ this->vw = vw;
+ this->hh = hh;
+}
diff --git a/mingui/imageitem.hpp b/mingui/imageitem.hpp
index 8c9397e..43fb0c8 100644
--- a/mingui/imageitem.hpp
+++ b/mingui/imageitem.hpp
@@ -28,10 +28,13 @@ private:
const static int HKPADD = 4;
const static int LINESP = 4;
const static int HKSHDS = 2;
+ int vw = -1;
+ int hh = -1;
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 setScrollbarMargins(int vw, int hh);
Q_SIGNALS:
void sizeHintChanged(const QModelIndex &index);
};
diff --git a/mingui/mingui.cpp b/mingui/mingui.cpp
index 192b491..8a9fa57 100644
--- a/mingui/mingui.cpp
+++ b/mingui/mingui.cpp
@@ -8,7 +8,9 @@
#include <QDebug>
#include <QCloseEvent>
#include <QMouseEvent>
+#include <QScrollBar>
#include <QAction>
+#include <QSplitter>
#include <QString>
#include <QScrollArea>
#include <QListView>
@@ -51,25 +53,31 @@ MinGuiWidget::MinGuiWidget()
this->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont));
this->setWindowTitle("deduper minigui");
this->setLayout(new QVBoxLayout(this));
- QWidget *everything_except_statusbar = new QWidget(this);
sb = new QStatusBar(this);
sb->addPermanentWidget(permamsg = new QLabel());
QLabel *opm = new QLabel();
- opm->setText("z: previous group, m: next group, x: mark all for deletion, c: unmark all, click: toggle, shift+click: open, shift+return: save list");
+ opm->setText("placeholder status bar text");
sb->addWidget(opm);
- this->layout()->addWidget(everything_except_statusbar);
+ l = new QSplitter(Qt::Orientation::Horizontal, this);
+ l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ this->layout()->addWidget(l);
this->layout()->addWidget(sb);
- l = new QHBoxLayout(everything_except_statusbar);
- everything_except_statusbar->setLayout(l);
infopanel = new QTextEdit(this);
infopanel->setReadOnly(true);
+ infopanel->setMinimumWidth(80);
lw = new QListView(this);
im = new QStandardItemModel(this);
lw->setModel(im);
+ lw->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
+ lw->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
id = new ImageItemDelegate();
+ id->setScrollbarMargins(lw->verticalScrollBar()->width(),
+ lw->horizontalScrollBar()->height());
lw->setItemDelegate(id);
lw->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
lw->setResizeMode(QListView::ResizeMode::Adjust);
+ lw->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
+ lw->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
for (size_t i = 0; i < keys.size(); ++i)
{
@@ -144,6 +152,8 @@ MinGuiWidget::MinGuiWidget()
});
l->addWidget(lw);
l->addWidget(infopanel);
+ l->setStretchFactor(0, 3);
+ l->setStretchFactor(1, 1);
marked.clear();
infopanel->setText("bleh");
infopanel->setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum);
diff --git a/mingui/mingui.hpp b/mingui/mingui.hpp
index 6e1f6c2..f0efda6 100644
--- a/mingui/mingui.hpp
+++ b/mingui/mingui.hpp
@@ -15,6 +15,7 @@ class QStatusBar;
class QScrollArea;
class QTextEdit;
class QListView;
+class QSplitter;
class QStandardItemModel;
class ImageItemDelegate;
@@ -24,7 +25,7 @@ class MinGuiWidget : public QWidget
{
Q_OBJECT
private:
- QHBoxLayout *l;
+ QSplitter *l;
QTextEdit *infopanel;
QLabel *permamsg;
QStatusBar *sb;