Comparar commits
22 Commits
b588fd07be
...
776cbe4d30
Autor | SHA1 | Data | |
---|---|---|---|
776cbe4d30 | |||
101885ffe4 | |||
79d15fb628 | |||
95e855f325 | |||
2acfe6126a | |||
2d79d74e06 | |||
7c2461626d | |||
ae7f310ab2 | |||
2ab0750f3a | |||
f9eff3b5b2 | |||
84cf8837bd | |||
47c0358a25 | |||
7bae1183c6 | |||
9daaba2543 | |||
6b924c0f53 | |||
653089c475 | |||
f06e9a4f7b | |||
61001ed6cc | |||
e2c80b665e | |||
2a9292958b | |||
27ac3155d3 | |||
b72931cc9e |
@ -56,7 +56,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
||||
}
|
||||
if(key == "icon")
|
||||
{
|
||||
result.icon = QIcon::fromTheme(args);
|
||||
result.iconPath = args;
|
||||
}
|
||||
if(key == "exec")
|
||||
{
|
||||
@ -80,6 +80,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
||||
result.hidden = args == "true";
|
||||
}
|
||||
}
|
||||
result.type = EntryType::SYSTEM;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -112,19 +113,71 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
// TODO: better exception class
|
||||
throw new std::runtime_error("Failed to open file");
|
||||
}
|
||||
QHash<QString, QString> map;
|
||||
QTextStream stream(&file);
|
||||
while(!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine();
|
||||
QStringList splitted = line.split(" ");
|
||||
if(splitted.length() < 2)
|
||||
|
||||
int spacePos = line.indexOf(' ');
|
||||
if(spacePos == -1)
|
||||
{
|
||||
throw new ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
|
||||
}
|
||||
QString key = splitted[0];
|
||||
if(key == "arguments")
|
||||
|
||||
QString key = line.mid(0, spacePos);
|
||||
QString value = line.mid(spacePos + 1);
|
||||
|
||||
if(key == "" || value == "")
|
||||
{
|
||||
auto args = splitted.mid(1);
|
||||
throw new ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
|
||||
}
|
||||
map[key] = value;
|
||||
}
|
||||
|
||||
if(map.contains("inherit"))
|
||||
{
|
||||
auto entry = readEntryFromPath(map["inherit"]);
|
||||
if(entry)
|
||||
{
|
||||
result = entry.value();
|
||||
result.inherit = map["inherit"];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ConfigFormatException("Error attempting to read inherited entry");
|
||||
}
|
||||
}
|
||||
QString type = map["type"];
|
||||
if(!type.isEmpty())
|
||||
{
|
||||
if(type == "system")
|
||||
{
|
||||
throw new ConfigFormatException(".qsrun files cannot be designated as system entries " +
|
||||
path.toStdString());
|
||||
}
|
||||
else if(type == "inherit")
|
||||
{
|
||||
result.type = EntryType::INHERIT;
|
||||
}
|
||||
else if(type == "user")
|
||||
{
|
||||
result.type = EntryType::USER;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.type = EntryType::USER;
|
||||
}
|
||||
if(result.type != EntryType::INHERIT)
|
||||
{
|
||||
if(map.contains("arguments"))
|
||||
{
|
||||
auto args = map["arguments"].split(' ');
|
||||
QString merged;
|
||||
for(QString &str : args)
|
||||
{
|
||||
@ -153,42 +206,20 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
|
||||
}
|
||||
}
|
||||
if(key == "name")
|
||||
{
|
||||
result.name = splitted.mid(1).join(' ');
|
||||
}
|
||||
if(key == "icon")
|
||||
{
|
||||
result.icon = QIcon(splitted[1]);
|
||||
}
|
||||
if(key == "row")
|
||||
{
|
||||
result.row = splitted[1].toInt();
|
||||
}
|
||||
if(key == "col")
|
||||
{
|
||||
result.col = splitted[1].toInt();
|
||||
}
|
||||
if(key == "command")
|
||||
{
|
||||
result.command = splitted[1];
|
||||
}
|
||||
if(key == "key")
|
||||
{
|
||||
// QKeySequence sequence(splitted[1]);
|
||||
// result.keySequence = sequence;
|
||||
result.key = splitted[1].toLower();
|
||||
}
|
||||
if(key == "inherit")
|
||||
{
|
||||
auto entry = readEntryFromPath(resolveEntryPath(splitted[1]));
|
||||
if(entry)
|
||||
auto assignIfSourceNotEmpty = [](QString source, QString &val) {
|
||||
if(!source.isEmpty())
|
||||
{
|
||||
inheritedConfig = *entry;
|
||||
val = source;
|
||||
}
|
||||
}
|
||||
};
|
||||
assignIfSourceNotEmpty(map["key"].toLower(), result.key);
|
||||
assignIfSourceNotEmpty(map["command"], result.command);
|
||||
assignIfSourceNotEmpty(map["icon"], result.iconPath);
|
||||
assignIfSourceNotEmpty(map["name"], result.name);
|
||||
}
|
||||
return result.update(inheritedConfig);
|
||||
result.col = map["col"].toInt();
|
||||
result.row = map["row"].toInt();
|
||||
return result;
|
||||
}
|
||||
|
||||
QString EntryProvider::resolveEntryPath(QString path)
|
||||
@ -228,6 +259,7 @@ QVector<EntryConfig> EntryProvider::readConfig(QStringList paths)
|
||||
{
|
||||
if(!entry->hidden)
|
||||
{
|
||||
entry->entryPath = path;
|
||||
result.append(*entry);
|
||||
}
|
||||
}
|
||||
@ -246,6 +278,70 @@ QVector<EntryConfig> EntryProvider::getSystemEntries()
|
||||
return readConfig(this->systemEntriesDirsPaths);
|
||||
}
|
||||
|
||||
void EntryProvider::saveUserEntry(const EntryConfig &config)
|
||||
{
|
||||
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
|
||||
{
|
||||
throw std::runtime_error("Only user/inherited entries can be saved");
|
||||
}
|
||||
QString transitPath = config.entryPath + ".transit";
|
||||
QFile file{transitPath};
|
||||
if(!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
throw std::runtime_error("Error: Can not open file for writing");
|
||||
}
|
||||
QTextStream outStream(&file);
|
||||
outStream << "type" << " " << ((config.type == EntryType::USER) ? "user" : "inherit") << endl;
|
||||
if(!config.inherit.isEmpty())
|
||||
{
|
||||
outStream << "inherit" << " " << config.inherit << endl;
|
||||
}
|
||||
outStream << "row" << " " << config.row << endl;
|
||||
outStream << "col" << " " << config.col << endl;
|
||||
outStream << "hidden" << " " << config.hidden << endl;
|
||||
outStream << "key" << " " << config.key << endl;
|
||||
if(config.type == EntryType::USER)
|
||||
{
|
||||
if(!config.name.isEmpty())
|
||||
{
|
||||
outStream << "name" << " " << config.name << endl;
|
||||
}
|
||||
if(!config.command.isEmpty())
|
||||
{
|
||||
outStream << "command" << " " << config.command << endl;
|
||||
}
|
||||
if(!config.iconPath.isEmpty())
|
||||
{
|
||||
outStream << "icon" << " " << config.iconPath << endl;
|
||||
}
|
||||
if(!config.arguments.empty())
|
||||
{
|
||||
outStream << "arguments" << " " << config.arguments.join(' ') << endl;
|
||||
}
|
||||
}
|
||||
|
||||
outStream.flush();
|
||||
file.close();
|
||||
|
||||
// Qts don't work if file already exists and c++17... don't want to pull in the fs lib yet
|
||||
int ret = rename(transitPath.toStdString().c_str(), config.entryPath.toStdString().c_str());
|
||||
if(ret != 0)
|
||||
{
|
||||
qDebug() << strerror(errno);
|
||||
throw std::runtime_error("Failed to save entry file: Error during rename");
|
||||
}
|
||||
}
|
||||
|
||||
bool EntryProvider::deleteUserEntry(const EntryConfig &config)
|
||||
{
|
||||
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
|
||||
{
|
||||
throw std::runtime_error("Only user/inherited entries can be deleted");
|
||||
}
|
||||
QFile file{config.entryPath};
|
||||
return file.remove();
|
||||
}
|
||||
|
||||
template <class T> void assignIfDestDefault(T &dest, const T &source)
|
||||
{
|
||||
if(dest == T())
|
||||
@ -259,12 +355,16 @@ EntryConfig &EntryConfig::update(const EntryConfig &o)
|
||||
assignIfDestDefault(this->arguments, o.arguments);
|
||||
assignIfDestDefault(this->col, o.col);
|
||||
assignIfDestDefault(this->command, o.command);
|
||||
if(this->icon.isNull())
|
||||
if(this->iconPath.isEmpty())
|
||||
{
|
||||
this->icon = o.icon;
|
||||
this->iconPath = o.iconPath;
|
||||
}
|
||||
assignIfDestDefault(this->key, o.key);
|
||||
assignIfDestDefault(this->name, o.name);
|
||||
assignIfDestDefault(this->row, o.row);
|
||||
assignIfDestDefault(this->hidden, o.hidden);
|
||||
assignIfDestDefault(this->inherit, o.inherit);
|
||||
assignIfDestDefault(this->entryPath, o.entryPath);
|
||||
assignIfDestDefault(this->type, o.type);
|
||||
return *this;
|
||||
}
|
||||
|
@ -15,15 +15,25 @@ class ConfigFormatException : public std::runtime_error
|
||||
}
|
||||
};
|
||||
|
||||
enum EntryType
|
||||
{
|
||||
USER,
|
||||
INHERIT,
|
||||
SYSTEM
|
||||
};
|
||||
|
||||
class EntryConfig
|
||||
{
|
||||
public:
|
||||
EntryType type = SYSTEM;
|
||||
bool hidden = false;
|
||||
QString entryPath;
|
||||
QString key;
|
||||
QString name;
|
||||
QString command;
|
||||
QString iconPath;
|
||||
QStringList arguments;
|
||||
QIcon icon;
|
||||
QString inherit;
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
@ -46,6 +56,8 @@ class EntryProvider
|
||||
EntryProvider(QStringList userEntriesDirsPaths, QStringList systemEntriesDirsPaths);
|
||||
QVector<EntryConfig> getUserEntries();
|
||||
QVector<EntryConfig> getSystemEntries();
|
||||
void saveUserEntry(const EntryConfig &config);
|
||||
bool deleteUserEntry(const EntryConfig &config);
|
||||
};
|
||||
|
||||
#endif // ENTRYPROVIDER_H
|
||||
|
@ -13,16 +13,21 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QApplication>
|
||||
#include "entrypushbutton.h"
|
||||
|
||||
EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
|
||||
{
|
||||
this->setText(config.name);
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
this->setIcon(config.icon);
|
||||
if(!config.icon.availableSizes().isEmpty())
|
||||
QIcon icon = resolveIcon(config.iconPath);
|
||||
this->setIcon(icon);
|
||||
if(!icon.availableSizes().isEmpty())
|
||||
{
|
||||
auto sizes = config.icon.availableSizes();
|
||||
auto sizes = icon.availableSizes();
|
||||
QSize maxSize = sizes.first();
|
||||
for(QSize ¤t : sizes)
|
||||
{
|
||||
@ -35,17 +40,33 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
|
||||
}
|
||||
this->config = config;
|
||||
connect(this, SIGNAL(clicked()), this, SLOT(emitOwnClicked()));
|
||||
|
||||
systemEntryMenu.addAction("Add to favorites", [&] { emit addToFavourites(this->config); });
|
||||
userEntryMenu.addAction("Delete", [&] { emit deleteRequested(this->config); });
|
||||
}
|
||||
|
||||
|
||||
|
||||
QIcon EntryPushButton::resolveIcon(QString path)
|
||||
{
|
||||
if(!path.isEmpty())
|
||||
{
|
||||
if(path[0] == '/')
|
||||
{
|
||||
return QIcon(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
return QIcon::fromTheme(path);
|
||||
}
|
||||
}
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
void EntryPushButton::emitOwnClicked()
|
||||
{
|
||||
emit clicked(this->config);
|
||||
}
|
||||
|
||||
const EntryConfig &EntryPushButton::getEntryConfig()
|
||||
const EntryConfig &EntryPushButton::getEntryConfig() const
|
||||
{
|
||||
return this->config;
|
||||
}
|
||||
@ -65,12 +86,82 @@ void EntryPushButton::showName()
|
||||
this->setText(this->config.name);
|
||||
}
|
||||
|
||||
int EntryPushButton::getRow() const { return config.row; }
|
||||
int EntryPushButton::getCol() const { return config.col; }
|
||||
QString EntryPushButton::getName() const { return config.name; }
|
||||
QString EntryPushButton::getShortcutKey() const { return config.key; }
|
||||
void EntryPushButton::setShortcutKey(QString key) { this->config.key = key; }
|
||||
void EntryPushButton::setRow(int row) { this->config.row = row; }
|
||||
void EntryPushButton::setCol(int col) { this->config.col = col; }
|
||||
QStringList EntryPushButton::getArguments() const { return this->config.arguments; }
|
||||
QString EntryPushButton::getCommand() const { return this->config.command; }
|
||||
void EntryPushButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
dragStartPosition = event->pos();
|
||||
}
|
||||
if(event->button() == Qt::RightButton)
|
||||
{
|
||||
if(this->config.type == EntryType::USER || this->config.type == EntryType::INHERIT)
|
||||
{
|
||||
this->userEntryMenu.exec(QCursor::pos());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->systemEntryMenu.exec(QCursor::pos());
|
||||
}
|
||||
}
|
||||
return QPushButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void EntryPushButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if(this->config.type == EntryType::SYSTEM)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!(event->buttons() & Qt::LeftButton))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
QByteArray data;
|
||||
mimeData->setData(ENTRYBUTTON_MIME_TYPE_STR, data);
|
||||
drag->setMimeData(mimeData);
|
||||
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
||||
}
|
||||
|
||||
int EntryPushButton::getRow() const
|
||||
{
|
||||
return config.row;
|
||||
}
|
||||
int EntryPushButton::getCol() const
|
||||
{
|
||||
return config.col;
|
||||
}
|
||||
QString EntryPushButton::getName() const
|
||||
{
|
||||
return config.name;
|
||||
}
|
||||
QString EntryPushButton::getShortcutKey() const
|
||||
{
|
||||
return config.key;
|
||||
}
|
||||
void EntryPushButton::setShortcutKey(QString key)
|
||||
{
|
||||
this->config.key = key;
|
||||
}
|
||||
void EntryPushButton::setRow(int row)
|
||||
{
|
||||
this->config.row = row;
|
||||
}
|
||||
void EntryPushButton::setCol(int col)
|
||||
{
|
||||
this->config.col = col;
|
||||
}
|
||||
QStringList EntryPushButton::getArguments() const
|
||||
{
|
||||
return this->config.arguments;
|
||||
}
|
||||
QString EntryPushButton::getCommand() const
|
||||
{
|
||||
return this->config.command;
|
||||
}
|
||||
|
@ -18,20 +18,38 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QMouseEvent>
|
||||
#include <QMenu>
|
||||
|
||||
#include "entryprovider.h"
|
||||
|
||||
#define ENTRYBUTTON_MIME_TYPE_STR "application/x-qsrun-entrypushbutton"
|
||||
|
||||
class EntryPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
private:
|
||||
QMenu systemEntryMenu;
|
||||
QMenu userEntryMenu;
|
||||
EntryConfig config;
|
||||
private slots:
|
||||
QPoint dragStartPosition;
|
||||
|
||||
private slots:
|
||||
void emitOwnClicked();
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void clicked(const EntryConfig &config);
|
||||
public:
|
||||
void deleteRequested(EntryConfig &config);
|
||||
void addToFavourites(const EntryConfig &config);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
QIcon resolveIcon(QString path);
|
||||
|
||||
public:
|
||||
EntryPushButton(const EntryConfig &config);
|
||||
const EntryConfig &getEntryConfig();
|
||||
const EntryConfig &getEntryConfig() const;
|
||||
void setEntryConfig(const EntryConfig &config);
|
||||
void showShortcut();
|
||||
void showName();
|
||||
@ -46,6 +64,4 @@ public:
|
||||
void setShortcutKey(QString key);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // ENTRYPUSHBUTTON_H
|
||||
|
147
window.cpp
147
window.cpp
@ -37,6 +37,7 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
||||
createGui();
|
||||
initFromConfig();
|
||||
this->lineEdit->installEventFilter(this);
|
||||
this->setAcceptDrops(true);
|
||||
QFont font;
|
||||
font.setPointSize(48);
|
||||
font.setBold(true);
|
||||
@ -117,12 +118,54 @@ void Window::populateGrid(const QVector<EntryPushButton *> &list)
|
||||
}
|
||||
}
|
||||
|
||||
void Window::buttonClick(const EntryPushButton &config)
|
||||
void Window::executeConfig(const EntryConfig &config)
|
||||
{
|
||||
QProcess::startDetached(config.getCommand(), config.getArguments());
|
||||
QProcess::startDetached(config.command, config.arguments);
|
||||
this->closeWindow();
|
||||
}
|
||||
|
||||
void Window::addToFavourites(const EntryConfig &config)
|
||||
{
|
||||
std::pair<int, int> cell = getNextFreeCell();
|
||||
EntryConfig userConfig;
|
||||
userConfig.type = EntryType::INHERIT;
|
||||
userConfig.row = cell.first;
|
||||
userConfig.col = cell.second;
|
||||
userConfig.inherit = config.entryPath;
|
||||
QFileInfo fi{config.entryPath};
|
||||
QString entryName = fi.completeBaseName() + ".qsrun";
|
||||
QString entryPath;
|
||||
if(config.type == EntryType::SYSTEM)
|
||||
{
|
||||
entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName;
|
||||
}
|
||||
else
|
||||
{
|
||||
entryPath = fi.absoluteDir().absoluteFilePath(entryName);
|
||||
}
|
||||
userConfig.entryPath = entryPath;
|
||||
try
|
||||
{
|
||||
entryProvider->saveUserEntry(userConfig);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
QMessageBox::critical(this, "Failed to save item to favourites", e.what());
|
||||
return;
|
||||
}
|
||||
/*we only want to save a minimal, inherited config. but it should be a "complete" button
|
||||
when we add it to the favourites. the alternative would be to reload the whole config,
|
||||
but that's probably overkill. */
|
||||
userConfig.update(config);
|
||||
userEntryButtons.append(createEntryButton(userConfig));
|
||||
}
|
||||
|
||||
void Window::deleteEntry(EntryConfig &config)
|
||||
{
|
||||
this->entryProvider->deleteUserEntry(config);
|
||||
initFromConfig();
|
||||
}
|
||||
|
||||
void Window::closeWindow()
|
||||
{
|
||||
if(settingsProvider->singleInstanceMode())
|
||||
@ -136,6 +179,48 @@ void Window::closeWindow()
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<int, int> Window::getNextFreeCell()
|
||||
{
|
||||
/* Not the most efficient way perhaps but for now it'll do */
|
||||
std::sort(userEntryButtons.begin(), userEntryButtons.end(), [](EntryPushButton *a, EntryPushButton *b) {
|
||||
const EntryConfig &config_a = a->getEntryConfig();
|
||||
const EntryConfig &config_b = b->getEntryConfig();
|
||||
if(config_a.row < config_b.row)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(config_a.row > config_b.row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return config_a.col < config_b.col;
|
||||
});
|
||||
|
||||
int expectedRow = 1;
|
||||
int expectedCol = 1;
|
||||
int maxCols = this->settingsProvider->getMaxCols();
|
||||
for(EntryPushButton *current : userEntryButtons)
|
||||
{
|
||||
int currentRow = current->getEntryConfig().row;
|
||||
int currentCol = current->getEntryConfig().col;
|
||||
|
||||
if(currentRow != expectedRow || currentCol != expectedCol)
|
||||
{
|
||||
return {expectedRow, expectedCol};
|
||||
}
|
||||
if(expectedCol == maxCols)
|
||||
{
|
||||
expectedCol = 1;
|
||||
++expectedRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
++expectedCol;
|
||||
}
|
||||
}
|
||||
return {expectedRow, expectedCol};
|
||||
}
|
||||
|
||||
QStringList Window::generatePATHSuggestions(const QString &text)
|
||||
{
|
||||
QStringList results;
|
||||
@ -170,7 +255,7 @@ void Window::addPATHSuggestion(const QString &text)
|
||||
e.col = 0;
|
||||
e.row = 0;
|
||||
e.command = suggestions[0];
|
||||
e.icon = QIcon::fromTheme(suggestions[0]);
|
||||
e.iconPath = suggestions[0];
|
||||
EntryPushButton *button = createEntryButton(e);
|
||||
clearGrid();
|
||||
grid->addWidget(button, 0, 0);
|
||||
@ -247,7 +332,7 @@ void Window::lineEditTextChanged(QString text)
|
||||
e.arguments = arguments.mid(1);
|
||||
}
|
||||
e.command = arguments[0];
|
||||
e.icon = QIcon::fromTheme("utilities-terminal");
|
||||
e.iconPath = "utilities-terminal";
|
||||
|
||||
EntryPushButton *button = createEntryButton(e);
|
||||
clearGrid();
|
||||
@ -297,7 +382,7 @@ void Window::keyPressEvent(QKeyEvent *event)
|
||||
[&key](const EntryPushButton *y) { return y->getShortcutKey() == key; });
|
||||
if(it != buttonsInGrid.end())
|
||||
{
|
||||
buttonClick(**it);
|
||||
executeConfig((*it)->getEntryConfig());
|
||||
}
|
||||
}
|
||||
QWidget::keyPressEvent(event);
|
||||
@ -354,7 +439,9 @@ void Window::filterGridFor(QString filter)
|
||||
EntryPushButton *Window::createEntryButton(const EntryConfig &entry)
|
||||
{
|
||||
EntryPushButton *button = new EntryPushButton(entry);
|
||||
connect(button, &EntryPushButton::clicked, this, &Window::buttonClick);
|
||||
connect(button, &EntryPushButton::clicked, this, &Window::executeConfig);
|
||||
connect(button, &EntryPushButton::addToFavourites, this, &Window::addToFavourites);
|
||||
connect(button, &EntryPushButton::deleteRequested, this, &Window::deleteEntry);
|
||||
return button;
|
||||
}
|
||||
|
||||
@ -369,7 +456,7 @@ void Window::lineEditReturnPressed()
|
||||
|
||||
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0)
|
||||
{
|
||||
buttonClick(*buttonsInGrid[0]);
|
||||
executeConfig(buttonsInGrid[0]->getEntryConfig());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -405,3 +492,49 @@ void Window::focusInput()
|
||||
{
|
||||
this->lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void Window::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if(event->mimeData()->hasFormat(ENTRYBUTTON_MIME_TYPE_STR))
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::dropEvent(QDropEvent *event)
|
||||
{
|
||||
int count = grid->count();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
QLayoutItem *current = grid->itemAt(i);
|
||||
if(current->geometry().contains(event->pos()))
|
||||
{
|
||||
EntryPushButton *buttonAtDrop = (EntryPushButton *)current->widget();
|
||||
EntryPushButton *buttonAtSource = (EntryPushButton *)event->source();
|
||||
|
||||
int tmp_row = buttonAtSource->getRow();
|
||||
int tmp_col = buttonAtSource->getCol();
|
||||
|
||||
grid->addWidget(buttonAtSource, buttonAtDrop->getRow(), buttonAtDrop->getCol());
|
||||
buttonAtSource->setRow(buttonAtDrop->getRow());
|
||||
buttonAtSource->setCol(buttonAtDrop->getCol());
|
||||
|
||||
grid->addWidget(buttonAtDrop, tmp_row, tmp_col);
|
||||
buttonAtDrop->setRow(tmp_row);
|
||||
buttonAtDrop->setCol(tmp_col);
|
||||
|
||||
try
|
||||
{
|
||||
this->entryProvider->saveUserEntry(buttonAtDrop->getEntryConfig());
|
||||
this->entryProvider->saveUserEntry(buttonAtSource->getEntryConfig());
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
QMessageBox::critical(this, "Failed to rearrange items", e.what());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
27
window.h
27
window.h
@ -30,6 +30,9 @@
|
||||
#include <QThread>
|
||||
#include <QTreeWidget>
|
||||
#include <QLabel>
|
||||
#include <QMimeData>
|
||||
#include <QDebug>
|
||||
#include <QRect>
|
||||
#include "entrypushbutton.h"
|
||||
#include "calculationengine.h"
|
||||
#include "settingsprovider.h"
|
||||
@ -37,13 +40,17 @@
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
private:
|
||||
EntryProvider *entryProvider;
|
||||
SettingsProvider *settingsProvider;
|
||||
CalculationEngine calcEngine;
|
||||
QString calculationresult;
|
||||
QVector<EntryPushButton*> userEntryButtons;
|
||||
QVector<EntryPushButton*> systemEntryButtons;
|
||||
QVector<EntryPushButton *> userEntryButtons;
|
||||
QVector<EntryPushButton *> systemEntryButtons;
|
||||
QVector<EntryPushButton *> buttonsInGrid;
|
||||
QLabel calculationResultLabel;
|
||||
QString currentCalculationResult;
|
||||
@ -56,27 +63,31 @@ private:
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
QVector<EntryPushButton *> generateEntryButtons(const QVector<EntryConfig> &userEntryButtons);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void buttonClick(const EntryPushButton &config);
|
||||
void executeConfig(const EntryConfig &button);
|
||||
void addToFavourites(const EntryConfig &button);
|
||||
void deleteEntry(EntryConfig &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 addCalcResult(const QString &expression);
|
||||
void initTreeWidgets();
|
||||
QStringList generatePATHSuggestions(const QString &text);
|
||||
void closeWindow();
|
||||
private slots:
|
||||
std::pair<int, int> getNextFreeCell();
|
||||
|
||||
private slots:
|
||||
void lineEditReturnPressed();
|
||||
void showCalculationResultContextMenu(const QPoint &point);
|
||||
public:
|
||||
|
||||
public:
|
||||
Window(EntryProvider &entryProvider, SettingsProvider &settingsProvider);
|
||||
void setSystemConfig(const QVector<EntryConfig> &config);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void focusInput();
|
||||
~Window();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Carregando…
Referência em uma nova issue
Block a user