Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
add posibility to sort files ascending or descending
Browse files Browse the repository at this point in the history
  • Loading branch information
luspi committed Nov 16, 2014
1 parent d155fa6 commit 62c0f54
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 20 deletions.
13 changes: 13 additions & 0 deletions globalsettings.h
Expand Up @@ -417,6 +417,7 @@ class GlobalSettings : public QObject {
bool quickSettings;
// Sort images by
QString sortby;
bool sortbyAscending;

// Are quickinfos hidden?
bool hidecounter;
Expand Down Expand Up @@ -514,6 +515,7 @@ class GlobalSettings : public QObject {
map.insert("KnownFileTypesQtExtras",knownFileTypesQtExtras);
map.insert("KnownFileTypesGm",knownFileTypesGm);
map.insert("SortImagesBy",sortby);
map.insert("SortImagesAscending",sortbyAscending);

map.insert("WindowMode",windowmode);
map.insert("WindowDecoration",windowDecoration);
Expand Down Expand Up @@ -608,6 +610,7 @@ class GlobalSettings : public QObject {
knownFileTypes = knownFileTypesQt + "," + knownFileTypesGm;

sortby = "name";
sortbyAscending = true;

windowmode = false;
windowDecoration = false;
Expand Down Expand Up @@ -737,6 +740,11 @@ class GlobalSettings : public QObject {
if(all.contains("SortImagesBy="))
sortby = all.split("SortImagesBy=").at(1).split("\n").at(0);

if(all.contains("SortImagesAscending=1"))
sortbyAscending = true;
else if(all.contains("SortImagesAscending=0"))
sortbyAscending = false;

if(all.contains("WindowMode=1"))
windowmode = true;
else if(all.contains("WindowMode=0"))
Expand Down Expand Up @@ -1077,6 +1085,7 @@ class GlobalSettings : public QObject {
cont += QString("BorderAroundImg=%1\n").arg(borderAroundImg);
cont += QString("QuickSettings=%1\n").arg(int(quickSettings));
cont += QString("SortImagesBy=%1\n").arg(sortby);
cont += QString("SortImagesAscending=%1\n").arg(int(sortbyAscending));

cont += "\n[Quickinfo]\n";

Expand Down Expand Up @@ -1188,6 +1197,10 @@ public slots:
sortby = changedSet.value("SortImagesBy").toString();
applySet["thumb"] = true;
}
if(changedSet.keys().contains("SortImagesAscending")) {
sortbyAscending = changedSet.value("SortImagesAscending").toBool();
applySet["thumb"] = true;
}

if(changedSet.keys().contains("WindowMode")) {
windowmode = changedSet.value("WindowMode").toBool();
Expand Down
Binary file added img/sortascending.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/sortdescending.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mainwindow.cpp
Expand Up @@ -2487,7 +2487,7 @@ void MainWindow::updateSettings(QMap<QString, QVariant> settings) {

if(globVar->verbose) std::clog << "Passing updated settings to subclasses" << std::endl;

viewThumbs->globSet = settings;
viewThumbs->setGlobSet(settings);
viewThumbs->view->globSet = settings;
viewBig->globSet = settings;

Expand Down
2 changes: 2 additions & 0 deletions resImg.qrc
Expand Up @@ -56,5 +56,7 @@
<file>img/scale.png</file>
<file>img/save.png</file>
<file>img/closingx.png</file>
<file>img/sortdescending.png</file>
<file>img/sortascending.png</file>
</qresource>
</RCC>
27 changes: 12 additions & 15 deletions thumbnails/thumbnails.cpp
Expand Up @@ -71,9 +71,7 @@ Thumbnails::Thumbnails(QWidget *parent, bool v, QMap<QString,QVariant> set) : QW
}

bool Thumbnails::compareNamesFileInfo_name(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {

return (s1fileinfo.fileName().compare(s2fileinfo.fileName(), Qt::CaseInsensitive)<=0);

}

// Algorithm used for sorting a directory using natural sort
Expand Down Expand Up @@ -137,7 +135,6 @@ bool Thumbnails::compareNamesFileInfo_naturalname(const QFileInfo& s1fileinfo,co
if (!n1.isEmpty() && !n2.isEmpty())
return (n+n1).toInt() < (n+n2).toInt();
else {

// not a number has to win over a number.. number could have ended earlier... same prefix..
if (!n1.isEmpty())
return false;
Expand All @@ -152,21 +149,11 @@ bool Thumbnails::compareNamesFileInfo_naturalname(const QFileInfo& s1fileinfo,co
}

bool Thumbnails::compareNamesFileInfo_date(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {

QDateTime s1 = s1fileinfo.created();
QDateTime s2 = s2fileinfo.created();

return (s1.secsTo(s2) > 0);

return s1fileinfo.created().secsTo(s2fileinfo.created()) > 0;
}

bool Thumbnails::compareNamesFileInfo_size(const QFileInfo &s1fileinfo, const QFileInfo &s2fileinfo) {

qint64 s1 = s1fileinfo.size();
qint64 s2 = s2fileinfo.size();

return s1>s2;

return s1fileinfo.size()>s2fileinfo.size();
}

// The animation function
Expand Down Expand Up @@ -263,6 +250,16 @@ void Thumbnails::loadDir(bool amReloadingDir) {
else
qSort(allImgsInfo.begin(),allImgsInfo.end(),compareNamesFileInfo_name);

// If we want to sort in descending order, we simply reverse the order here
// NOTE: using qSwap() on half the items is very fast
if(!globSet.value("SortImagesAscending").toBool()) {
const int listSize = allImgsInfo.size();
const int maxSwap = allImgsInfo.size()/2;
for (int i = 0; i < maxSwap; ++i) {
qSwap(allImgsInfo[i], allImgsInfo[listSize - 1 -i]);
}
}

// Storing number of images
counttot = allImgsInfo.length();

Expand Down
6 changes: 4 additions & 2 deletions thumbnails/thumbnails.h
Expand Up @@ -48,8 +48,7 @@ class Thumbnails : public QWidget {

bool verbose;

// The global settings
QMap<QString,QVariant> globSet;
void setGlobSet(QMap<QString,QVariant> set) { globSet = set; }

// The Graphicsview
ThumbnailView *view;
Expand Down Expand Up @@ -100,6 +99,9 @@ class Thumbnails : public QWidget {
void removeFilter() { imageFilter.clear(); }

private:
// The global settings
QMap<QString,QVariant> globSet;

QString currentfile;
QString currentdir;

Expand Down
20 changes: 18 additions & 2 deletions widgets/quicksettings.cpp
Expand Up @@ -44,7 +44,7 @@ QuickSettings::QuickSettings(QMap<QString, QVariant> set, bool v, QWidget *paren
mouseTrickerEnable = true;

// The dimensions of the widget (shown and hidden)
rectShown = QRect(0,50,300,450);
rectShown = QRect(0,50,300,500);
rectHidden = QRect(-10,-10,10,10);

// Initially the widget it hidden
Expand All @@ -60,8 +60,15 @@ QuickSettings::QuickSettings(QMap<QString, QVariant> set, bool v, QWidget *paren
CustomLabel *desc = new CustomLabel(tr("Change settings with one click. They are saved and applied immediately. If you're unsure what a setting does, check the full settings for descriptions."));

// Adjust sort by
CustomLabel *sortbyLabel = new CustomLabel(tr("Sort images by"));
CustomLabel *sortbyLabel = new CustomLabel(tr("Sort by"));
sortby = new CustomComboBox;
sort_asc = new CustomRadioButton;
sort_asc->setIcon(QIcon(":/img/sortascending.png"));
sort_des = new CustomRadioButton;
sort_des->setIcon(QIcon(":/img/sortdescending.png"));
QButtonGroup *grp = new QButtonGroup;
grp->addButton(sort_asc);
grp->addButton(sort_des);
sortby->setPadding(4);
sortby->addItem(tr("Name"),"name");
sortby->addItem(tr("Natural Name"),"naturalname");
Expand All @@ -70,6 +77,8 @@ QuickSettings::QuickSettings(QMap<QString, QVariant> set, bool v, QWidget *paren
QHBoxLayout *sortbyLay = new QHBoxLayout;
sortbyLay->addWidget(sortbyLabel);
sortbyLay->addWidget(sortby);
sortbyLay->addWidget(sort_asc);
sortbyLay->addWidget(sort_des);
sortbyLay->addStretch();

// The different settings that can be adjusted
Expand Down Expand Up @@ -102,6 +111,8 @@ QuickSettings::QuickSettings(QMap<QString, QVariant> set, bool v, QWidget *paren

// Save & Apply settings instantly
connect(sortby, SIGNAL(currentTextChanged(QString)), this, SLOT(settingChanged()));
connect(sort_asc, SIGNAL(clicked()), this, SLOT(settingChanged()));
connect(sort_des, SIGNAL(clicked()), this, SLOT(settingChanged()));
connect(composite, SIGNAL(clicked()), this, SLOT(settingChanged()));
connect(fakedtrans, SIGNAL(clicked()), this, SLOT(settingChanged()));
connect(imagebg, SIGNAL(clicked()), this, SLOT(settingChanged()));
Expand Down Expand Up @@ -212,6 +223,8 @@ void QuickSettings::loadSettings() {
break;
}
}
sort_asc->setChecked(globSet.value("SortImagesAscending").toBool());
sort_des->setChecked(!globSet.value("SortImagesAscending").toBool());

composite->setChecked(globSet.value("Composite").toBool());
fakedtrans->setChecked(globSet.value("BackgroundImageScreenshot").toBool());
Expand All @@ -229,6 +242,7 @@ void QuickSettings::loadSettings() {
windowdeco->setEnabled(windowmode->isChecked());

defaults.clear();
defaults.insert("SortImagesAscending",sort_asc->isChecked());
defaults.insert("SortImagesBy",sort);
defaults.insert("Composite",composite->isChecked());
defaults.insert("BackgroundImageScreenshot",composite->isChecked());
Expand All @@ -252,6 +266,8 @@ void QuickSettings::settingChanged() {

if(defaults.value("SortImagesBy").toString() != sortby->currentData().toString())
changedSet.insert("SortImagesBy",sortby->currentData());
if(defaults.value("SortImagesAscending").toBool() != sort_asc->isChecked())
changedSet.insert("SortImagesAscending",sort_asc->isChecked());

changedSet.insert("Composite",composite->isChecked());
changedSet.insert("BackgroundImageScreenshot",fakedtrans->isChecked());
Expand Down
3 changes: 3 additions & 0 deletions widgets/quicksettings.h
Expand Up @@ -30,6 +30,7 @@
#include <QPainter>
#include <QStyleOption>
#include <QSignalMapper>
#include <QButtonGroup>

class QuickSettings : public QWidget {

Expand Down Expand Up @@ -73,6 +74,8 @@ class QuickSettings : public QWidget {


CustomComboBox *sortby;
CustomRadioButton *sort_asc;
CustomRadioButton *sort_des;

CustomRadioButton *composite;
CustomRadioButton *fakedtrans;
Expand Down

0 comments on commit 62c0f54

Please sign in to comment.