From 9e3214a73a5cc38a9b4f0313d8a48c0374cb57a3 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Tue, 25 Jun 2019 09:13:38 -0400 Subject: refactored calculations --- src/modinfodialogimages.h | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/modinfodialogimages.h') diff --git a/src/modinfodialogimages.h b/src/modinfodialogimages.h index 88e22a6a..9c3e5746 100644 --- a/src/modinfodialogimages.h +++ b/src/modinfodialogimages.h @@ -91,17 +91,49 @@ private: } }; + struct PaintContext + { + QPainter painter; + int thumbSize; + QRect topRect; + + PaintContext(QWidget* w) + : painter(w), thumbSize(0) + { + } + }; + ScalableImage* m_image; std::vector m_files; std::vector m_supportedFormats; int m_margins, m_padding, m_border; + void getSupportedFormats(); + void scrollAreaResized(const QSize& s); void paintThumbnails(QPaintEvent* e); void thumbnailsMouseEvent(QMouseEvent* e); - bool needsReload(const File& file, const QSize& thumbSize) const; - QSize scaledImageSize(const QSize& originalSize, const QSize& thumbSize) const; + int calcThumbSize(int availableWidth) const; + int calcWidgetHeight(int availableWidth) const; + QRect calcTopThumbRect(int thumbSize) const; + std::pair calcVisibleRange( + int top, int bottom, int thumbSize) const; + + QRect calcBorderRect(const QRect& topRect, int thumbSize, std::size_t i) const; + QRect calcImageRect(const QRect& topRect, int thumbSize, std::size_t i) const; + QSize calcScaledImageSize( + const QSize& originalSize, const QSize& imageSize) const; + + void paintThumbnail(PaintContext& cx, std::size_t i); + void paintThumbnailBorder(PaintContext& cx, std::size_t i); + void paintThumbnailImage(PaintContext& cx, std::size_t i); + + const File* fileAtPos(const QPoint& p) const; + + bool needsReload(const File& file, const QSize& imageSize) const; + void reload(File& file, const QSize& imageSize); + void resizeWidget(); }; #endif // MODINFODIALOGIMAGES_H -- cgit v1.3.1