diff --git a/calculationengine.cpp b/calculationengine.cpp index 48af452..6629c59 100644 --- a/calculationengine.cpp +++ b/calculationengine.cpp @@ -18,11 +18,12 @@ CalculationEngine::CalculationEngine() { - if (!CALCULATOR) { - new Calculator(); - CALCULATOR->terminateThreads(); - CALCULATOR->setPrecision(16); - } + if (!CALCULATOR) + { + new Calculator(); + CALCULATOR->terminateThreads(); + CALCULATOR->setPrecision(16); + } //stolen from krunner's qalculate engine /*eo.auto_post_conversion = POST_CONVERSION_BEST; @@ -50,8 +51,6 @@ QString CalculationEngine::evaluate(const QString &expression) QByteArray ba = expression.toLatin1(); const char *ctext = ba.data(); MathStructure result = CALCULATOR->calculate(ctext, this->eo); - result.format(po); + result.format(po); return result.print(po).c_str(); - - } diff --git a/calculationengine.h b/calculationengine.h index 553b369..e9db604 100644 --- a/calculationengine.h +++ b/calculationengine.h @@ -26,12 +26,12 @@ class CalculationEngine { private: - EvaluationOptions eo; - PrintOptions po; + EvaluationOptions eo; + PrintOptions po; public: - CalculationEngine(); - QString evaluate(const QString &expression); + CalculationEngine(); + QString evaluate(const QString &expression); }; #endif // CALCULATIONENGINE_H diff --git a/config.cpp b/config.cpp index 0cd93b5..e888d06 100644 --- a/config.cpp +++ b/config.cpp @@ -157,7 +157,7 @@ EntryConfig ConfigReader::readFromFile(const QString &path) } if(key == "row") { - result.row = splitted[1].toInt(); + result.row = splitted[1].toInt(); } if(key == "col") { diff --git a/config.h b/config.h index 331299d..57fd68a 100644 --- a/config.h +++ b/config.h @@ -24,14 +24,14 @@ #include class EntryConfig { - public: - QString key; - QString name; - QString command; - QStringList arguments; - QIcon icon; - int row=0; - int col=0; +public: + QString key; + QString name; + QString command; + QStringList arguments; + QIcon icon; + int row=0; + int col=0; @@ -39,21 +39,21 @@ class EntryConfig class ConfigReader { - private: - QStringList configPaths; - EntryConfig readFromFile(const QString &path); - EntryConfig readFromDesktopFile(const QString &path); - QStringList desktopIgnoreArgs; - public: - ConfigReader(QStringList paths); - QVector readConfig(); +private: + QStringList configPaths; + EntryConfig readFromFile(const QString &path); + EntryConfig readFromDesktopFile(const QString &path); + QStringList desktopIgnoreArgs; +public: + ConfigReader(QStringList paths); + QVector readConfig(); }; class ConfigFormatException : public std::runtime_error { public: - ConfigFormatException() : std::runtime_error("Error in configuration file, misformated line?") {}; - ConfigFormatException(const std::string &str) : std::runtime_error(str) {}; + ConfigFormatException() : std::runtime_error("Error in configuration file, misformated line?") {}; + ConfigFormatException(const std::string &str) : std::runtime_error(str) {}; }; #endif diff --git a/configprovider.h b/configprovider.h index 699eabd..3c3e549 100644 --- a/configprovider.h +++ b/configprovider.h @@ -6,13 +6,13 @@ class ConfigProvider { private: - QSettings *settings; - QString configDirPath; + QSettings *settings; + QString configDirPath; public: - ConfigProvider(QString configDirPath, QSettings &settings); - QVector getUserEntries(); - QVector getSystemEntries(); - bool singleInstanceMode(); + ConfigProvider(QString configDirPath, QSettings &settings); + QVector getUserEntries(); + QVector getSystemEntries(); + bool singleInstanceMode(); }; #endif // CONFIGPROVIDER_H diff --git a/entrypushbutton.h b/entrypushbutton.h index c697cf9..4892cd1 100644 --- a/entrypushbutton.h +++ b/entrypushbutton.h @@ -21,29 +21,29 @@ #include "config.h" class EntryPushButton : public QPushButton { - Q_OBJECT + Q_OBJECT private: - EntryConfig config; + EntryConfig config; private slots: - void emitOwnClicked(); + void emitOwnClicked(); signals: - void clicked(const EntryConfig &config); + void clicked(const EntryConfig &config); public: - EntryPushButton(const EntryConfig &config); - const EntryConfig &getEntryConfig(); - void setEntryConfig(const EntryConfig &config); - void showShortcut(); - void showName(); - int getRow() const; - int getCol() const; - QString getName() const; - QString getShortcutKey() const; - QStringList getArguments() const; - QString getCommand() const; - void setRow(int row); - void setCol(int col); - void setShortcutKey(QString key); + EntryPushButton(const EntryConfig &config); + const EntryConfig &getEntryConfig(); + void setEntryConfig(const EntryConfig &config); + void showShortcut(); + void showName(); + int getRow() const; + int getCol() const; + QString getName() const; + QString getShortcutKey() const; + QStringList getArguments() const; + QString getCommand() const; + void setRow(int row); + void setCol(int col); + void setShortcutKey(QString key); }; diff --git a/main.cpp b/main.cpp index b08f458..c0fee98 100644 --- a/main.cpp +++ b/main.cpp @@ -72,14 +72,14 @@ int main(int argc, char *argv[]) } Window *w = new Window { configProvider }; QObject::connect(&server, &SingleInstanceServer::receivedMaximizationRequest, [&w]{ - if(w != nullptr) - { - qInfo() << "maximizing as requested by other instance"; - w->showMaximized(); - w->activateWindow(); - w->raise(); - } - }); + if(w != nullptr) + { + qInfo() << "maximizing as requested by other instance"; + w->showMaximized(); + w->activateWindow(); + w->raise(); + } + }); w->showMaximized(); } diff --git a/singleinstanceserver.h b/singleinstanceserver.h index 382af0e..e6f6fdb 100644 --- a/singleinstanceserver.h +++ b/singleinstanceserver.h @@ -6,16 +6,16 @@ class SingleInstanceServer : public QObject { - Q_OBJECT + Q_OBJECT private: - QLocalServer server; + QLocalServer server; private slots: - void handleNewConnection(); + void handleNewConnection(); public: - SingleInstanceServer(); - bool listen(QString socketPath); - signals: - void receivedMaximizationRequest(); + SingleInstanceServer(); + bool listen(QString socketPath); +signals: + void receivedMaximizationRequest(); }; #endif // SINGLEINSTANCESERVER_H diff --git a/window.cpp b/window.cpp index 4953f7f..917f4e7 100644 --- a/window.cpp +++ b/window.cpp @@ -1,18 +1,18 @@ /* - * Copyright (c) 2018 Albert S. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ + * Copyright (c) 2018 Albert S. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ #include #include #include @@ -94,20 +94,20 @@ QVector Window::generateEntryButtons(const QVectorsetLayout(grid); - sa->setWidget(w); - sa->setWidgetResizable(true); - vbox->setAlignment(Qt::AlignTop); - vbox->addWidget(lineEdit); - vbox->addWidget(sa); + QVBoxLayout *vbox = new QVBoxLayout(this); + QScrollArea *sa = new QScrollArea; + grid = new QGridLayout(); + lineEdit = new QLineEdit(); + QWidget *w = new QWidget(this); + w->setLayout(grid); + sa->setWidget(w); + sa->setWidgetResizable(true); + vbox->setAlignment(Qt::AlignTop); + vbox->addWidget(lineEdit); + vbox->addWidget(sa); - connect(lineEdit, &QLineEdit::textChanged, this, [this](QString newtext) { this->lineEditTextChanged(newtext); }); - connect(lineEdit, &QLineEdit::returnPressed, this, &Window::lineEditReturnPressed); + connect(lineEdit, &QLineEdit::textChanged, this, [this](QString newtext) { this->lineEditTextChanged(newtext); }); + connect(lineEdit, &QLineEdit::returnPressed, this, &Window::lineEditReturnPressed); } void Window::populateGrid(const QVector &list) @@ -151,7 +151,6 @@ QStringList Window::generatePATHSuggestions(const QString &text) QString entry = info.baseName(); if(entry.startsWith(text)) { - results.append(entry); } } @@ -242,7 +241,7 @@ void Window::lineEditTextChanged(QString text) addPATHSuggestion(text); if(this->grid->count() == 0) { - + QStringList arguments = text.split(" "); EntryConfig e; e.name = "Execute: " + text; @@ -252,7 +251,7 @@ void Window::lineEditTextChanged(QString text) } e.command = arguments[0]; e.icon = QIcon::fromTheme("utilities-terminal"); - + EntryPushButton *button = createEntryButton(e); clearGrid(); grid->addWidget(button, 0, 0); @@ -281,7 +280,7 @@ void Window::keyPressEvent(QKeyEvent *event) { qApp->quit(); } - + if(event->modifiers() & Qt::ControlModifier && buttonsInGrid.count() > 0) { @@ -300,7 +299,7 @@ void Window::keyPressEvent(QKeyEvent *event) QKeySequence seq(event->key()); QString key = seq.toString().toLower(); - + auto it = std::find_if(buttonsInGrid.begin(), buttonsInGrid.end(), [&key](const EntryPushButton *y) { return y->getShortcutKey() == key; }); if(it != buttonsInGrid.end()) { @@ -349,8 +348,8 @@ void Window::filterGridFor(QString filter) } } } - } - + } + } @@ -358,7 +357,7 @@ void Window::filterGridFor(QString filter) { populateGrid(this->userEntryButtons); } - + } EntryPushButton * Window::createEntryButton(const EntryConfig &entry) diff --git a/window.h b/window.h index 310888e..3059216 100644 --- a/window.h +++ b/window.h @@ -38,42 +38,42 @@ class Window : public QWidget { Q_OBJECT - private: - ConfigProvider *configProvider; - CalculationEngine calcEngine; - QString calculationresult; - QVector userEntryButtons; - QVector systemEntryButtons; - QVector buttonsInGrid; - QLabel calculationResultLabel; - QString currentCalculationResult; - QString queuedFileSearch; - QString queuedContentSearch; - void initFromConfig(); - void createGui(); - void filterGridFor(QString filter); - void populateGrid(const QVector &list); - void keyReleaseEvent(QKeyEvent *event); - QVector generateEntryButtons(const QVector &userEntryButtons); - void keyPressEvent(QKeyEvent *event); - void buttonClick(const EntryPushButton &config); - QLineEdit *lineEdit; - QGridLayout *grid; - EntryPushButton *createEntryButton(const EntryConfig &config); - void lineEditTextChanged(QString text); - void addPATHSuggestion(const QString &text); - void clearGrid(); - void addCalcResult(const QString & expression); - void initTreeWidgets(); - QStringList generatePATHSuggestions(const QString &text); - private slots: - void lineEditReturnPressed(); - void showCalculationResultContextMenu(const QPoint &point); - public: - Window(ConfigProvider &configProvider); - void setSystemConfig(const QVector &config); - bool eventFilter(QObject *obj, QEvent *event); - ~Window(); +private: + ConfigProvider *configProvider; + CalculationEngine calcEngine; + QString calculationresult; + QVector userEntryButtons; + QVector systemEntryButtons; + QVector buttonsInGrid; + QLabel calculationResultLabel; + QString currentCalculationResult; + QString queuedFileSearch; + QString queuedContentSearch; + void initFromConfig(); + void createGui(); + void filterGridFor(QString filter); + void populateGrid(const QVector &list); + void keyReleaseEvent(QKeyEvent *event); + QVector generateEntryButtons(const QVector &userEntryButtons); + void keyPressEvent(QKeyEvent *event); + void buttonClick(const EntryPushButton &config); + QLineEdit *lineEdit; + QGridLayout *grid; + EntryPushButton *createEntryButton(const EntryConfig &config); + void lineEditTextChanged(QString text); + void addPATHSuggestion(const QString &text); + void clearGrid(); + void addCalcResult(const QString & expression); + void initTreeWidgets(); + QStringList generatePATHSuggestions(const QString &text); +private slots: + void lineEditReturnPressed(); + void showCalculationResultContextMenu(const QPoint &point); +public: + Window(ConfigProvider &configProvider); + void setSystemConfig(const QVector &config); + bool eventFilter(QObject *obj, QEvent *event); + ~Window(); };