Giter Site home page Giter Site logo

pmfoss / simpleimagebrowser Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 1.83 MB

This project demonstrates a way to customize the class QListView of the Qt framework. It does not claim to be completed or to provide and support a program for productive use.

License: BSD 3-Clause "New" or "Revised" License

C++ 98.55% QMake 1.45%
cpp listview qt customization

simpleimagebrowser's Introduction

Simple Image Browser

Screenshot

Description

This project demonstrates a way to customize the class QListView of the Qt framework. It does not claim to be completed or to provide and support a program for productive use. The usable versions are Qt5 (tested 5.15) and Qt6 (tested 6.4).

The main goals are:

  • customize items,
  • showing or hiding of section labels and
  • sorting of these parts separately from each other.

The following diagram shows the developed classes starting with the abbreviation IB (Image Browser) and its relations to realize the goals. All classes with a starting Q are part of Qt framework.

classes

Goals

This section descripts the realization of the named goals. All mentioned components are joined in class IBImageListWidget, which is implemented in the files ibimagelistwidget.hpp and ibimagelistwidget.cpp.

Customize items

The customization of QListView items is very simple. Its generalizing class QAbstractItemView provides the possiblity to use an object of the class QAbstractItemDelegate which provides the method paint. The specializion to this class with the overriding of this method makes it possible to customize the items. The delegate class has another advantage. It supplies the size of an item for the QListView class and it is possible to display items with different sizes. The implementation of this part is located in the files ibitemdelegate.hpp and ibitemdelegate.cpp.

Section labels

The goal for showing or hiding of section labels is closely related to the QListView data/items. For the realizion a so-called model (QAbstractItemModel) is necessary which is used by a QAbstractItemView to display items. It manages and prepares the displaying data. The classes of QAbstractItemView are only responsible for the rendering of the items. A detailed overview of that can be found in the Qt Documentation. A QListView instance can only handle 1-dimensional models or one specific column of a multidimensional model.

In case of the project, it is advantageous to organize the data in a 2-dimensional structure consisting of section items (IBImageListSectionItem) and images items (IBImageListImageItem) that stored in a main list (IBImageListSectionList). This simply helps to achieve the stated goals. The image items contains all image data (path, size, thumbnail, last modifed date and so on) and are stored in a list of the section items. The section items, in turn, are only consists of an ID and the list of image items. The main list finally stores and manages the section items with its image items and transforms the 2-dimensional data in 1-dimensional data. The tasks of the project model (IBImageListModel) are to populate the structure, to invoke its managment and to interface the data to the QListView instances.

If no section labels are to be displayed, the structure contains only one section item with an empty ID and all image items.

The item property of having different sizes, described in section Customize items, allows displaying section and image items. Section items are span the entired width of the view and must resize when the view is resized. The image items have a static size.

Sorting

Sorting the different parts is very simple with the described structure. The class IBImageListSectionItem sorts the image items and the class IBImageListSectionList sorts the sections.

Others

In Addition, the model class initialize a thread instance of class (IBThumbnailLoader), that loads the thumbnails of the image items. This approach allows a nonblocking use of the resulting application.

The implementation of this part is located in the files ibimagelistmodel.hpp and ibimagelistmodel.hpp.

Compiling

git clone https://github.com/pmfoss/simpleimagebrowser
cd simpleimagebrowser 
qmake
make
./simpleimagebrowser

License

BSD-3-Clause license

simpleimagebrowser's People

Stargazers

Zübeyir Bodur avatar Eugene Berge avatar Huey Yeng avatar  avatar Muby avatar Tom M. avatar

Watchers

Muby avatar Martin Pietsch avatar

simpleimagebrowser's Issues

Thumb when lot of image

First of all ! Good job !

One remark regarding the generation of thumbs. If you have a directory with a lot of image, and when you open it, you scroll at the end you have to wait for the full generation to be able to preview the thumb of the last image of the directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.