Ablility to select additional folders
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "imagegallery.h"
|
||||
#include <QPixmap>
|
||||
#include <QImageReader>
|
||||
|
||||
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent)
|
||||
#include <QFileInfo>
|
||||
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent), currentColumnCount(1)
|
||||
{
|
||||
scrollArea = new QScrollArea(this);
|
||||
scrollWidget = new QWidget(scrollArea);
|
||||
scrollLayout = new QVBoxLayout(scrollWidget);
|
||||
gridLayout = new QGridLayout(scrollWidget);
|
||||
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setWidget(scrollWidget);
|
||||
@@ -20,14 +20,16 @@ void ImageGallery::addImage(const QString &imagePath)
|
||||
{
|
||||
QLabel *imageLabel = new QLabel(scrollWidget);
|
||||
QPixmap pixmap(imagePath);
|
||||
imageLabel->setPixmap(pixmap.scaledToWidth(400, Qt::SmoothTransformation));
|
||||
imageLabel->setPixmap(pixmap.scaledToWidth(200, Qt::SmoothTransformation));
|
||||
imageLabel->setAlignment(Qt::AlignCenter);
|
||||
|
||||
scrollLayout->addWidget(imageLabel);
|
||||
imageLabels.append(imageLabel);
|
||||
|
||||
int row = gridLayout->count() / currentColumnCount;
|
||||
int column = gridLayout->count() % currentColumnCount;
|
||||
|
||||
gridLayout->addWidget(imageLabel, row, column);
|
||||
}
|
||||
void ImageGallery::addImagesFromDirectory(const QString &directoryPath){
|
||||
QDir directory(directoryPath);
|
||||
void ImageGallery::addImagesFromDirectory(QDir &directory){
|
||||
QStringList filters;
|
||||
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
|
||||
|
||||
@@ -44,3 +46,26 @@ void ImageGallery::addImagesFromDirectory(const QString &directoryPath){
|
||||
addImage(fileInfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
void ImageGallery::setColumns(int columns)
|
||||
{
|
||||
if (columns < 1) {
|
||||
columns = 1; // Minimalna liczba kolumn to 1
|
||||
}
|
||||
|
||||
currentColumnCount = columns;
|
||||
|
||||
// Usuń wszystkie obrazy z layoutu
|
||||
QLayoutItem *item;
|
||||
while ((item = gridLayout->takeAt(0))) {
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
|
||||
// Dodaj obrazy ponownie z nową liczbą kolumn
|
||||
QList<QLabel*> labels = scrollWidget->findChildren<QLabel*>();
|
||||
for (int i = 0; i < labels.size(); ++i) {
|
||||
int row = i / currentColumnCount;
|
||||
int column = i % currentColumnCount;
|
||||
gridLayout->addWidget(labels[i], row, column);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user