比较提交
10 次代码提交
wip/clipar
...
4315de0e76
作者 | SHA1 | 提交日期 | |
---|---|---|---|
4315de0e76 | |||
f0387db468 | |||
6e4f0ecabf | |||
2df37212dd | |||
b13815a924 | |||
bb74d156c9 | |||
f9038f3098 | |||
042b53a0be | |||
64d3223fb2 | |||
adfb065358 |
@ -25,7 +25,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
// TODO: better exception class
|
||||
throw new std::runtime_error("Failed to open file");
|
||||
throw std::runtime_error("Failed to open file");
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
// There should be nothing preceding this group in the desktop entry file but possibly one or more comments.
|
||||
@ -120,7 +120,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
// TODO: better exception class
|
||||
throw new std::runtime_error("Failed to open file");
|
||||
throw std::runtime_error("Failed to open file");
|
||||
}
|
||||
QHash<QString, QString> map;
|
||||
QTextStream stream(&file);
|
||||
@ -131,7 +131,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
int spacePos = line.indexOf(' ');
|
||||
if(spacePos == -1)
|
||||
{
|
||||
throw new ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
|
||||
throw ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
|
||||
}
|
||||
|
||||
QString key = line.mid(0, spacePos);
|
||||
@ -139,7 +139,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
|
||||
if(key == "" || value == "")
|
||||
{
|
||||
throw new ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
|
||||
throw ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
|
||||
}
|
||||
map[key] = value;
|
||||
}
|
||||
@ -154,7 +154,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ConfigFormatException("Error attempting to read inherited entry");
|
||||
throw ConfigFormatException("Error attempting to read inherited entry");
|
||||
}
|
||||
}
|
||||
QString type = map["type"];
|
||||
@ -162,7 +162,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
{
|
||||
if(type == "system")
|
||||
{
|
||||
throw new ConfigFormatException(".qsrun files cannot be designated as system entries " +
|
||||
throw ConfigFormatException(".qsrun files cannot be designated as system entries " +
|
||||
path.toStdString());
|
||||
}
|
||||
else if(type == "inherit")
|
||||
@ -175,7 +175,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
|
||||
throw ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -309,7 +309,10 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
|
||||
outStream << "row" << " " << config.row << endl;
|
||||
outStream << "col" << " " << config.col << endl;
|
||||
outStream << "hidden" << " " << config.hidden << endl;
|
||||
outStream << "key" << " " << config.key << endl;
|
||||
if(!config.key.isEmpty())
|
||||
{
|
||||
outStream << "key" << " " << config.key << endl;
|
||||
}
|
||||
if(config.type == EntryType::USER)
|
||||
{
|
||||
if(!config.name.isEmpty())
|
||||
|
@ -19,7 +19,8 @@ enum EntryType
|
||||
{
|
||||
USER,
|
||||
INHERIT,
|
||||
SYSTEM
|
||||
SYSTEM,
|
||||
DYNAMIC
|
||||
};
|
||||
|
||||
class EntryConfig
|
||||
|
@ -33,19 +33,7 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
|
||||
icon = resolveIcon(config.iconPath);
|
||||
}
|
||||
this->setIcon(icon);
|
||||
if(!icon.availableSizes().isEmpty())
|
||||
{
|
||||
auto sizes = icon.availableSizes();
|
||||
QSize maxSize = sizes.first();
|
||||
for(QSize ¤t : sizes)
|
||||
{
|
||||
if(current.width() > maxSize.width())
|
||||
{
|
||||
maxSize = current;
|
||||
}
|
||||
}
|
||||
this->setIconSize(maxSize);
|
||||
}
|
||||
this->setIconSize(QSize{256, 256});
|
||||
this->config = config;
|
||||
connect(this, SIGNAL(clicked()), this, SLOT(emitOwnClicked()));
|
||||
|
||||
@ -106,7 +94,7 @@ void EntryPushButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->userEntryMenu.exec(QCursor::pos());
|
||||
}
|
||||
else
|
||||
else if(this->config.type == EntryType::SYSTEM)
|
||||
{
|
||||
this->systemEntryMenu.exec(QCursor::pos());
|
||||
}
|
||||
@ -116,7 +104,7 @@ void EntryPushButton::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void EntryPushButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if(this->config.type == EntryType::SYSTEM)
|
||||
if(this->config.type == EntryType::SYSTEM || this->config.type == EntryType::DYNAMIC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
72
window.cpp
72
window.cpp
@ -120,7 +120,7 @@ void Window::populateGrid(const QVector<EntryPushButton *> &list)
|
||||
|
||||
void Window::executeConfig(const EntryConfig &config)
|
||||
{
|
||||
if(config.isTerminalCommand)
|
||||
if(config.isTerminalCommand || QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
|
||||
{
|
||||
QString cmd = settingsProvider->getTerminalCommand();
|
||||
cmd.replace("%c", config.command);
|
||||
@ -166,6 +166,7 @@ void Window::addToFavourites(const EntryConfig &config)
|
||||
when we add it to the favourites. the alternative would be to reload the whole config,
|
||||
but that's probably overkill. */
|
||||
userConfig.update(config);
|
||||
userConfig.key = "";
|
||||
userEntryButtons.append(createEntryButton(userConfig));
|
||||
}
|
||||
|
||||
@ -265,6 +266,7 @@ void Window::addPATHSuggestion(const QString &text)
|
||||
e.row = 0;
|
||||
e.command = suggestions[0];
|
||||
e.iconPath = suggestions[0];
|
||||
e.type = EntryType::DYNAMIC;
|
||||
EntryPushButton *button = createEntryButton(e);
|
||||
clearGrid();
|
||||
grid->addWidget(button, 0, 0);
|
||||
@ -342,6 +344,7 @@ void Window::lineEditTextChanged(QString text)
|
||||
}
|
||||
e.command = arguments[0];
|
||||
e.iconPath = "utilities-terminal";
|
||||
e.type = EntryType::DYNAMIC;
|
||||
|
||||
EntryPushButton *button = createEntryButton(e);
|
||||
clearGrid();
|
||||
@ -381,7 +384,10 @@ void Window::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
for(EntryPushButton *button : buttonsInGrid)
|
||||
{
|
||||
button->showShortcut();
|
||||
if(!button->getEntryConfig().key.isEmpty())
|
||||
{
|
||||
button->showShortcut();
|
||||
}
|
||||
}
|
||||
|
||||
QKeySequence seq(event->key());
|
||||
@ -397,6 +403,27 @@ void Window::keyPressEvent(QKeyEvent *event)
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
int Window::rankConfig(const EntryConfig &config, QString filter) const
|
||||
{
|
||||
if(config.command.startsWith(filter, Qt::CaseInsensitive))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(config.command.contains(filter, Qt::CaseInsensitive))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(config.name.startsWith(filter, Qt::CaseInsensitive))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if(config.name.contains(filter, Qt::CaseInsensitive))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Window::filterGridFor(QString filter)
|
||||
{
|
||||
if(filter.length() > 0)
|
||||
@ -405,7 +432,8 @@ void Window::filterGridFor(QString filter)
|
||||
bool userEntryMatch = false;
|
||||
for(EntryPushButton *button : this->userEntryButtons)
|
||||
{
|
||||
if(button->getName().contains(filter, Qt::CaseInsensitive))
|
||||
if(button->getName().contains(filter, Qt::CaseInsensitive) ||
|
||||
button->getCommand().contains(filter, Qt::CaseInsensitive))
|
||||
{
|
||||
button->setVisible(true);
|
||||
grid->addWidget(button, button->getRow(), button->getCol());
|
||||
@ -415,26 +443,38 @@ void Window::filterGridFor(QString filter)
|
||||
}
|
||||
if(!userEntryMatch)
|
||||
{
|
||||
QVector<RankedButton> rankedEntries;
|
||||
int currow = 0;
|
||||
int curcol = 0;
|
||||
int i = 1;
|
||||
const int MAX_COLS = this->settingsProvider->getMaxCols();
|
||||
for(EntryPushButton *button : this->systemEntryButtons)
|
||||
{
|
||||
if(button->getName().contains(filter, Qt::CaseInsensitive))
|
||||
int ranking = rankConfig(button->getEntryConfig(), filter);
|
||||
if(ranking > -1)
|
||||
{
|
||||
button->setVisible(true);
|
||||
if(i < 10)
|
||||
{
|
||||
button->setShortcutKey(QString::number(i++));
|
||||
}
|
||||
grid->addWidget(button, currow, curcol++);
|
||||
this->buttonsInGrid.append(button);
|
||||
if(curcol == MAX_COLS)
|
||||
{
|
||||
curcol = 0;
|
||||
++currow;
|
||||
}
|
||||
RankedButton rb;
|
||||
rb.button = button;
|
||||
rb.ranking = ranking;
|
||||
rankedEntries.append(rb);
|
||||
}
|
||||
}
|
||||
std::sort(rankedEntries.begin(), rankedEntries.end(),
|
||||
[](const RankedButton &a, const RankedButton &b) -> bool { return a.ranking < b.ranking; });
|
||||
for(RankedButton &rankedButton : rankedEntries)
|
||||
{
|
||||
EntryPushButton *button = rankedButton.button;
|
||||
button->setVisible(true);
|
||||
if(i < 10)
|
||||
{
|
||||
button->setShortcutKey(QString::number(i++));
|
||||
}
|
||||
grid->addWidget(button, currow, curcol++);
|
||||
this->buttonsInGrid.append(button);
|
||||
if(curcol == MAX_COLS)
|
||||
{
|
||||
curcol = 0;
|
||||
++currow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
window.h
9
window.h
@ -37,6 +37,13 @@
|
||||
#include "calculationengine.h"
|
||||
#include "settingsprovider.h"
|
||||
|
||||
class RankedButton
|
||||
{
|
||||
public:
|
||||
EntryPushButton *button = nullptr;
|
||||
int ranking;
|
||||
};
|
||||
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -77,7 +84,7 @@ class Window : public QWidget
|
||||
QStringList generatePATHSuggestions(const QString &text);
|
||||
void closeWindow();
|
||||
std::pair<int, int> getNextFreeCell();
|
||||
|
||||
int rankConfig(const EntryConfig &config, QString filter) const;
|
||||
private slots:
|
||||
void lineEditReturnPressed();
|
||||
void showCalculationResultContextMenu(const QPoint &point);
|
||||
|
在新工单中引用
屏蔽一个用户