window: get number of columns from config

This commit is contained in:
Albert S. 2020-09-07 23:29:10 +02:00
parent 416bfa6314
commit 5eb09540c6
3 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#include "settingsprovider.h" #include "settingsprovider.h"
#include <QFileInfo>
#include <QDir> #include <QDir>
#include <QFileInfo>
SettingsProvider::SettingsProvider(QSettings &settings) SettingsProvider::SettingsProvider(QSettings &settings)
{ {
@ -9,9 +9,9 @@ SettingsProvider::SettingsProvider(QSettings &settings)
QStringList SettingsProvider::userEntriesPaths() const QStringList SettingsProvider::userEntriesPaths() const
{ {
//TODO: make it configurable, but we stick with this for now. // TODO: make it configurable, but we stick with this for now.
QFileInfo fi(this->settings->fileName()); QFileInfo fi(this->settings->fileName());
return { fi.absoluteDir().absolutePath() }; return {fi.absoluteDir().absolutePath()};
} }
QStringList SettingsProvider::systemApplicationsEntriesPaths() const QStringList SettingsProvider::systemApplicationsEntriesPaths() const
@ -19,9 +19,12 @@ QStringList SettingsProvider::systemApplicationsEntriesPaths() const
return settings->value("sysAppsPaths", "/usr/share/applications/").toStringList(); return settings->value("sysAppsPaths", "/usr/share/applications/").toStringList();
} }
int SettingsProvider::getMaxCols() const
{
return settings->value("maxColumns", 3).toInt();
}
bool SettingsProvider::singleInstanceMode() const bool SettingsProvider::singleInstanceMode() const
{ {
return settings->value("singleInstance", true).toBool(); return settings->value("singleInstance", true).toBool();
} }

View File

@ -1,17 +1,19 @@
#ifndef SETTINGSPROVIDER_H #ifndef SETTINGSPROVIDER_H
#define SETTINGSPROVIDER_H #define SETTINGSPROVIDER_H
#include <stdexcept>
#include <QSettings> #include <QSettings>
#include <stdexcept>
class SettingsProvider class SettingsProvider
{ {
private: private:
QSettings *settings; QSettings *settings;
public:
public:
SettingsProvider(QSettings &settings); SettingsProvider(QSettings &settings);
virtual QStringList userEntriesPaths() const; virtual QStringList userEntriesPaths() const;
virtual QStringList systemApplicationsEntriesPaths() const; virtual QStringList systemApplicationsEntriesPaths() const;
virtual int getMaxCols() const;
virtual bool singleInstanceMode() const; virtual bool singleInstanceMode() const;
}; };

View File

@ -28,8 +28,8 @@
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QScrollArea> #include <QScrollArea>
#include "window.h"
#include "entryprovider.h" #include "entryprovider.h"
#include "window.h"
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider) Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
{ {
this->entryProvider = &entryProvider; this->entryProvider = &entryProvider;
@ -324,6 +324,7 @@ void Window::filterGridFor(QString filter)
int currow = 0; int currow = 0;
int curcol = 0; int curcol = 0;
int i = 1; int i = 1;
const int MAX_COLS = this->settingsProvider->getMaxCols();
for(EntryPushButton *button : this->systemEntryButtons) for(EntryPushButton *button : this->systemEntryButtons)
{ {
if(button->getName().contains(filter, Qt::CaseInsensitive)) if(button->getName().contains(filter, Qt::CaseInsensitive))
@ -335,7 +336,7 @@ void Window::filterGridFor(QString filter)
} }
grid->addWidget(button, currow, curcol++); grid->addWidget(button, currow, curcol++);
this->buttonsInGrid.append(button); this->buttonsInGrid.append(button);
if(curcol == 3) if(curcol == MAX_COLS)
{ {
curcol = 0; curcol = 0;
++currow; ++currow;