Compare commits
No commits in common. "5eb09540c618c0e2bbee360e0b9991dece6bcd0c" and "edb781580e9f6db5a78528ca218628403f15e40d" have entirely different histories.
5eb09540c6
...
edb781580e
@ -1,6 +1,6 @@
|
|||||||
#include "settingsprovider.h"
|
#include "settingsprovider.h"
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
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,12 +19,9 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
#ifndef SETTINGSPROVIDER_H
|
#ifndef SETTINGSPROVIDER_H
|
||||||
#define SETTINGSPROVIDER_H
|
#define SETTINGSPROVIDER_H
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
87
window.cpp
87
window.cpp
@ -1,35 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020 Albert S. <mail at quitesimple dot org>
|
* Copyright (c) 2018-2019 Albert S. <mail at quitesimple dot org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
* copyright notice and this permission notice appear in all copies.
|
* copyright notice and this permission notice appear in all copies.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <QClipboard>
|
#include <QProcess>
|
||||||
#include <QDate>
|
#include <QProcessEnvironment>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFileIconProvider>
|
|
||||||
#include <QHeaderView>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QFileIconProvider>
|
||||||
|
#include <QDebug>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QProcess>
|
#include <QClipboard>
|
||||||
#include <QProcessEnvironment>
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
#include "entryprovider.h"
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "entryprovider.h"
|
||||||
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
||||||
{
|
{
|
||||||
this->entryProvider = &entryProvider;
|
this->entryProvider = &entryProvider;
|
||||||
@ -44,12 +43,13 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
|||||||
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
calculationResultLabel.setAlignment(Qt::AlignCenter);
|
calculationResultLabel.setAlignment(Qt::AlignCenter);
|
||||||
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||||
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this,
|
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this, &Window::showCalculationResultContextMenu);
|
||||||
&Window::showCalculationResultContextMenu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::initFromConfig()
|
void Window::initFromConfig()
|
||||||
@ -77,9 +77,9 @@ void Window::showCalculationResultContextMenu(const QPoint &point)
|
|||||||
menu.exec(QCursor::pos());
|
menu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<EntryPushButton *> Window::generateEntryButtons(const QVector<EntryConfig> &configs)
|
QVector<EntryPushButton*> Window::generateEntryButtons(const QVector<EntryConfig> &configs)
|
||||||
{
|
{
|
||||||
QVector<EntryPushButton *> result;
|
QVector<EntryPushButton*> result;
|
||||||
for(const EntryConfig &config : configs)
|
for(const EntryConfig &config : configs)
|
||||||
{
|
{
|
||||||
EntryPushButton *button = createEntryButton(config);
|
EntryPushButton *button = createEntryButton(config);
|
||||||
@ -167,8 +167,8 @@ void Window::addPATHSuggestion(const QString &text)
|
|||||||
{
|
{
|
||||||
EntryConfig e;
|
EntryConfig e;
|
||||||
e.name = suggestions[0];
|
e.name = suggestions[0];
|
||||||
e.col = 0;
|
e.col=0;
|
||||||
e.row = 0;
|
e.row=0;
|
||||||
e.command = suggestions[0];
|
e.command = suggestions[0];
|
||||||
e.icon = QIcon::fromTheme(suggestions[0]);
|
e.icon = QIcon::fromTheme(suggestions[0]);
|
||||||
EntryPushButton *button = createEntryButton(e);
|
EntryPushButton *button = createEntryButton(e);
|
||||||
@ -198,6 +198,7 @@ void Window::addCalcResult(const QString &expression)
|
|||||||
calculationResultLabel.setText(labelText);
|
calculationResultLabel.setText(labelText);
|
||||||
calculationResultLabel.setVisible(true);
|
calculationResultLabel.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
QFont currentFont = calculationResultLabel.font();
|
QFont currentFont = calculationResultLabel.font();
|
||||||
int calculatedPointSize = currentFont.pointSize();
|
int calculatedPointSize = currentFont.pointSize();
|
||||||
QFontMetrics fm(currentFont);
|
QFontMetrics fm(currentFont);
|
||||||
@ -220,7 +221,7 @@ void Window::addCalcResult(const QString &expression)
|
|||||||
grid->addWidget(&calculationResultLabel, 0, 0);
|
grid->addWidget(&calculationResultLabel, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// main problem here there is no easy event compression (clearing emit queue and only processing the last one)
|
//main problem here there is no easy event compression (clearing emit queue and only processing the last one)
|
||||||
void Window::lineEditTextChanged(QString text)
|
void Window::lineEditTextChanged(QString text)
|
||||||
{
|
{
|
||||||
if(text.length() >= 2)
|
if(text.length() >= 2)
|
||||||
@ -267,11 +268,11 @@ void Window::keyReleaseEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QWidget::keyReleaseEvent(event);
|
QWidget::keyReleaseEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Window::keyPressEvent(QKeyEvent *event)
|
void Window::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
bool closeWindow =
|
bool closeWindow = ((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape);
|
||||||
((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape);
|
|
||||||
if(closeWindow)
|
if(closeWindow)
|
||||||
{
|
{
|
||||||
this->closeWindow();
|
this->closeWindow();
|
||||||
@ -293,8 +294,7 @@ void Window::keyPressEvent(QKeyEvent *event)
|
|||||||
QKeySequence seq(event->key());
|
QKeySequence seq(event->key());
|
||||||
QString key = seq.toString().toLower();
|
QString key = seq.toString().toLower();
|
||||||
|
|
||||||
auto it = std::find_if(buttonsInGrid.begin(), buttonsInGrid.end(),
|
auto it = std::find_if(buttonsInGrid.begin(), buttonsInGrid.end(), [&key](const EntryPushButton *y) { return y->getShortcutKey() == key; });
|
||||||
[&key](const EntryPushButton *y) { return y->getShortcutKey() == key; });
|
|
||||||
if(it != buttonsInGrid.end())
|
if(it != buttonsInGrid.end())
|
||||||
{
|
{
|
||||||
buttonClick(**it);
|
buttonClick(**it);
|
||||||
@ -324,7 +324,6 @@ 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))
|
||||||
@ -336,7 +335,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 == MAX_COLS)
|
if(curcol == 3)
|
||||||
{
|
{
|
||||||
curcol = 0;
|
curcol = 0;
|
||||||
++currow;
|
++currow;
|
||||||
@ -344,14 +343,18 @@ void Window::filterGridFor(QString filter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
populateGrid(this->userEntryButtons);
|
populateGrid(this->userEntryButtons);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntryPushButton *Window::createEntryButton(const EntryConfig &entry)
|
EntryPushButton * Window::createEntryButton(const EntryConfig &entry)
|
||||||
{
|
{
|
||||||
EntryPushButton *button = new EntryPushButton(entry);
|
EntryPushButton *button = new EntryPushButton(entry);
|
||||||
connect(button, &EntryPushButton::clicked, this, &Window::buttonClick);
|
connect(button, &EntryPushButton::clicked, this, &Window::buttonClick);
|
||||||
@ -367,7 +370,8 @@ void Window::lineEditReturnPressed()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0)
|
|
||||||
|
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0 )
|
||||||
{
|
{
|
||||||
buttonClick(*buttonsInGrid[0]);
|
buttonClick(*buttonsInGrid[0]);
|
||||||
return;
|
return;
|
||||||
@ -383,7 +387,7 @@ bool Window::eventFilter(QObject *obj, QEvent *event)
|
|||||||
{
|
{
|
||||||
if(obj == this->lineEdit)
|
if(obj == this->lineEdit)
|
||||||
{
|
{
|
||||||
if(event->type() == QEvent::KeyPress)
|
if (event->type() == QEvent::KeyPress)
|
||||||
{
|
{
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
if(keyEvent->key() == Qt::Key_Tab)
|
if(keyEvent->key() == Qt::Key_Tab)
|
||||||
@ -392,11 +396,12 @@ bool Window::eventFilter(QObject *obj, QEvent *event)
|
|||||||
if(suggestions.length() == 1)
|
if(suggestions.length() == 1)
|
||||||
{
|
{
|
||||||
this->lineEdit->setText(suggestions[0] + " ");
|
this->lineEdit->setText(suggestions[0] + " ");
|
||||||
this->lineEdit->setCursorPosition(this->lineEdit->text().length() + 1);
|
this->lineEdit->setCursorPosition(this->lineEdit->text().length()+1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return QObject::eventFilter(obj, event);
|
return QObject::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user