Open App tool: design changes
- Search bar with realtime search - Show all app categories by default
This commit is contained in:
@@ -92,7 +92,6 @@ SOURCES += src/main.cpp\
|
||||
src/utils/desktopfileparse.cpp \
|
||||
src/capture/workers/launcher/launcheritemdelegate.cpp \
|
||||
src/capture/tools/blurtool.cpp \
|
||||
src/capture/workers/launcher/moreappswidget.cpp \
|
||||
src/capture/workers/launcher/terminallauncher.cpp
|
||||
|
||||
HEADERS += \
|
||||
@@ -150,7 +149,6 @@ HEADERS += \
|
||||
src/utils/desktopfileparse.h \
|
||||
src/capture/workers/launcher/launcheritemdelegate.h \
|
||||
src/capture/tools/blurtool.h \
|
||||
src/capture/workers/launcher/moreappswidget.h \
|
||||
src/capture/workers/launcher/terminallauncher.h
|
||||
|
||||
RESOURCES += \
|
||||
|
||||
@@ -20,15 +20,32 @@
|
||||
#include "src/capture/workers/launcher/launcheritemdelegate.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "terminallauncher.h"
|
||||
#include "moreappswidget.h"
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QProcess>
|
||||
#include <QPixmap>
|
||||
#include <QListView>
|
||||
#include <QTabWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QHBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace {
|
||||
|
||||
QMap<QString, QString> catIconNames({
|
||||
{ "Multimedia", "applications-multimedia" },
|
||||
{ "Development","applications-development" },
|
||||
{ "Graphics", "applications-graphics" },
|
||||
{ "Network", "preferences-system-network" },
|
||||
{ "Office", "applications-office" },
|
||||
{ "Science", "applications-science" },
|
||||
{ "Settings", "preferences-desktop" },
|
||||
{ "System", "preferences-system" },
|
||||
{ "Utility", "applications-utilities" }
|
||||
});
|
||||
}
|
||||
|
||||
AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
QWidget(parent), m_pixmap(p)
|
||||
@@ -47,72 +64,53 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
QDir appsDir(dir);
|
||||
m_parser.processDirectory(appsDir);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
QListWidget *listView = new QListWidget(this);
|
||||
listView->setItemDelegate(new LauncherItemDelegate());
|
||||
listView->setViewMode(QListWidget::IconMode);
|
||||
listView->setResizeMode(QListView::Adjust);
|
||||
listView->setSpacing(4);
|
||||
listView->setFlow(QListView::LeftToRight);
|
||||
listView->setDragEnabled(false);
|
||||
listView->setMinimumSize(375, 210);
|
||||
|
||||
QList<DesktopAppData> appList = m_parser.getAppsByCategory("Graphics");
|
||||
appList.append(DesktopAppData(QObject::tr("Other Application"), "", ".",
|
||||
QIcon::fromTheme("applications-other")
|
||||
));
|
||||
|
||||
for (auto app: appList) {
|
||||
QListWidgetItem *buttonItem = new QListWidgetItem(listView);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole+1, app.showInTerminal);
|
||||
QColor foregroundColor = this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
connect(listView, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
initAppMap();
|
||||
initListWidget();
|
||||
|
||||
m_terminalCheckbox = new QCheckBox(tr("Launch in terminal"), this);
|
||||
m_keepOpenCheckbox = new QCheckBox(tr("Keep open after selection"), this);
|
||||
m_keepOpenCheckbox->setChecked(ConfigHandler().keepOpenAppLauncherValue());
|
||||
connect(m_keepOpenCheckbox, &QCheckBox::clicked, this, &AppLauncherWidget::checkboxClicked);
|
||||
|
||||
m_layout->addWidget(listView);
|
||||
// search items
|
||||
m_lineEdit = new QLineEdit;
|
||||
connect(m_lineEdit, &QLineEdit::textChanged,
|
||||
this, &AppLauncherWidget::searchChanged);
|
||||
m_filterList = new QListWidget;
|
||||
m_filterList->hide();
|
||||
configureListView(m_filterList);
|
||||
connect(m_filterList, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->addWidget(m_filterList);
|
||||
m_layout->addWidget(m_tabWidget);
|
||||
m_layout->addWidget(m_lineEdit);
|
||||
m_layout->addWidget(m_keepOpenCheckbox);
|
||||
m_layout->addWidget(m_terminalCheckbox);
|
||||
m_keepOpenCheckbox->setChecked(ConfigHandler().keepOpenAppLauncherValue());
|
||||
m_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void AppLauncherWidget::launch(const QModelIndex &index) {
|
||||
QString command = index.data(Qt::UserRole).toString().replace(
|
||||
QRegExp("(\%.)"), m_tempFile);
|
||||
if (command == ".") {
|
||||
MoreAppsWidget *widget = new MoreAppsWidget(m_pixmap, m_parser);
|
||||
connect(widget, &MoreAppsWidget::appClicked,
|
||||
this, &AppLauncherWidget::launch);
|
||||
m_layout->takeAt(0)->widget()->deleteLater();
|
||||
m_layout->insertWidget(0, widget);
|
||||
} else {
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
m_tempFile = FileNameHandler().generateAbsolutePath("/tmp") + ".png";
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
// TO DO
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to write in /tmp."));
|
||||
return;
|
||||
}
|
||||
bool inTerminal = index.data(Qt::UserRole+1).toBool() ||
|
||||
m_terminalCheckbox->isChecked();
|
||||
if (inTerminal) {
|
||||
ok = TerminalLauncher::launchDetached(command);
|
||||
if (!ok) {
|
||||
// TO DO
|
||||
}
|
||||
} else {
|
||||
QProcess::startDetached(command);
|
||||
}
|
||||
QString command = index.data(Qt::UserRole).toString().replace(
|
||||
QRegExp("(\%.)"), m_tempFile);
|
||||
bool inTerminal = index.data(Qt::UserRole+1).toBool() ||
|
||||
m_terminalCheckbox->isChecked();
|
||||
if (inTerminal) {
|
||||
bool ok = TerminalLauncher::launchDetached(command);
|
||||
if (!ok) {
|
||||
QMessageBox::about(this, tr("Error"),
|
||||
tr("Unable to launch in terminal."));
|
||||
}
|
||||
} else {
|
||||
QProcess::startDetached(command);
|
||||
}
|
||||
if (!m_keepOpen) {
|
||||
close();
|
||||
@@ -124,3 +122,122 @@ void AppLauncherWidget::checkboxClicked(const bool enabled) {
|
||||
ConfigHandler().setKeepOpenAppLauncher(enabled);
|
||||
m_keepOpenCheckbox->setChecked(enabled);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::searchChanged(const QString &text) {
|
||||
if (text.isEmpty()) {
|
||||
m_filterList->hide();
|
||||
m_tabWidget->show();
|
||||
} else {
|
||||
m_tabWidget->hide();
|
||||
m_filterList->show();
|
||||
m_filterList->clear();
|
||||
QRegExp regexp(text, Qt::CaseInsensitive, QRegExp::Wildcard);
|
||||
QList<DesktopAppData> apps;
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
const QList<DesktopAppData> &appList = m_appsMap[cat];
|
||||
for (const DesktopAppData &app: appList) {
|
||||
if (!apps.contains(app) && (app.name.contains(regexp) ||
|
||||
app.description.contains(regexp) ))
|
||||
{
|
||||
apps.append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
addAppsToListWidget(m_filterList, apps);
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::initListWidget() {
|
||||
m_tabWidget = new QTabWidget;
|
||||
m_tabWidget->setIconSize(QSize(30, 30));
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString &iconName = i.second;
|
||||
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QListWidget *itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
|
||||
const QList<DesktopAppData> &appList = m_appsMap[cat];
|
||||
addAppsToListWidget(itemsWidget, appList);
|
||||
|
||||
m_tabWidget->addTab(itemsWidget, QIcon::fromTheme(iconName), "");
|
||||
m_tabWidget->setTabToolTip(m_tabWidget->count(), cat);
|
||||
if (cat == "Graphics") {
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->count() -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::initAppMap() {
|
||||
QStringList categories({"AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
"Graphics",
|
||||
"Network",
|
||||
"Office",
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility"});
|
||||
|
||||
m_appsMap = m_parser.getAppsByCategory(categories);
|
||||
|
||||
// Unify multimedia.
|
||||
QList<DesktopAppData> multimediaList;
|
||||
QStringList multimediaNames;
|
||||
multimediaNames << "AudioVideo" << "Audio" << "Video";
|
||||
for (const QString &name : multimediaNames) {
|
||||
if(!m_appsMap.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : m_appsMap[name]) {
|
||||
if (!multimediaList.contains(i)) {
|
||||
multimediaList.append(i);
|
||||
}
|
||||
}
|
||||
m_appsMap.remove(name);
|
||||
}
|
||||
m_appsMap.insert("Multimedia", multimediaList);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::configureListView(QListWidget *widget) {
|
||||
widget->setItemDelegate(new LauncherItemDelegate());
|
||||
widget->setViewMode(QListWidget::IconMode);
|
||||
widget->setResizeMode(QListView::Adjust);
|
||||
widget->setSpacing(4);
|
||||
widget->setFlow(QListView::LeftToRight);
|
||||
widget->setDragEnabled(false);
|
||||
widget->setMinimumSize(375, 210);
|
||||
connect(widget, &QListWidget::clicked,
|
||||
this, &AppLauncherWidget::launch);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::addAppsToListWidget(
|
||||
QListWidget *widget, const QList<DesktopAppData> &appList)
|
||||
{
|
||||
for (const DesktopAppData &app: appList) {
|
||||
QListWidgetItem *buttonItem = new QListWidgetItem(widget);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole+1, app.showInTerminal);
|
||||
QColor foregroundColor =
|
||||
this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,13 @@
|
||||
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
|
||||
class QTabWidget;
|
||||
class QCheckBox;
|
||||
class QVBoxLayout;
|
||||
class QLineEdit;
|
||||
class QListWidget;
|
||||
|
||||
class AppLauncherWidget: public QWidget
|
||||
{
|
||||
@@ -33,16 +37,26 @@ public:
|
||||
private slots:
|
||||
void launch(const QModelIndex &index);
|
||||
void checkboxClicked(const bool enabled);
|
||||
void searchChanged(const QString &text);
|
||||
|
||||
private:
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget *widget);
|
||||
void addAppsToListWidget(QListWidget *widget,
|
||||
const QList<DesktopAppData> &appList);
|
||||
|
||||
DesktopFileParser m_parser;
|
||||
QPixmap m_pixmap;
|
||||
QString m_tempFile;
|
||||
bool m_keepOpen;
|
||||
QMap<QString, QList<DesktopAppData>> m_appsMap;
|
||||
QCheckBox *m_keepOpenCheckbox;
|
||||
QCheckBox *m_terminalCheckbox;
|
||||
QVBoxLayout *m_layout;
|
||||
|
||||
QLineEdit *m_lineEdit;
|
||||
QListWidget *m_filterList;
|
||||
QTabWidget *m_tabWidget;
|
||||
};
|
||||
|
||||
#endif // APPLAUNCHERWIDGET_H
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
#include "moreappswidget.h"
|
||||
#include "src/capture/workers/launcher/launcheritemdelegate.h"
|
||||
#include <QPixmap>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabWidget>
|
||||
#include <QListView>
|
||||
#include <QListWidgetItem>
|
||||
#include <QMap>
|
||||
|
||||
// implement search, open custom and choose terminal
|
||||
|
||||
MoreAppsWidget::MoreAppsWidget(
|
||||
const QPixmap &pixmap,
|
||||
const DesktopFileParser &parser,
|
||||
QWidget *parent) :
|
||||
QWidget(parent), m_pixmap(pixmap)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
setWindowTitle(tr("Open With"));
|
||||
|
||||
DesktopFileParser ctor_parser = std::move(parser);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_tabs = new QTabWidget;
|
||||
m_tabs->setIconSize(QSize(30, 30));
|
||||
m_layout->addWidget(m_tabs);
|
||||
|
||||
QStringList categories({"AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
"Graphics",
|
||||
"Network",
|
||||
"Office",
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility"});
|
||||
|
||||
QMap<QString, QList<DesktopAppData>> appsMap =
|
||||
ctor_parser.getAppsByCategory(categories);
|
||||
|
||||
// Unify multimedia.
|
||||
QList<DesktopAppData> multimediaList;
|
||||
QStringList multimediaNames;
|
||||
multimediaNames << "AudioVideo" << "Audio" << "Video";
|
||||
for (const QString &name : multimediaNames) {
|
||||
if(!appsMap.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : appsMap[name]) {
|
||||
if (!multimediaList.contains(i)) {
|
||||
multimediaList.append(i);
|
||||
}
|
||||
}
|
||||
appsMap.remove(name);
|
||||
}
|
||||
appsMap.insert("Multimedia", multimediaList);
|
||||
|
||||
QMap<QString, QString> catIconNames({
|
||||
{ "Multimedia", "applications-multimedia" },
|
||||
{ "Development","applications-development" },
|
||||
{ "Graphics", "applications-graphics" },
|
||||
{ "Network", "preferences-system-network" },
|
||||
{ "Office", "applications-office" },
|
||||
{ "Science", "applications-science" },
|
||||
{ "Settings", "preferences-desktop" },
|
||||
{ "System", "preferences-system" },
|
||||
{ "Utility", "applications-utilities" }
|
||||
});
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString &iconName = i.second;
|
||||
|
||||
if (!appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QListWidget *listView = new QListWidget();
|
||||
listView->setItemDelegate(new LauncherItemDelegate());
|
||||
listView->setViewMode(QListWidget::IconMode);
|
||||
listView->setResizeMode(QListView::Adjust);
|
||||
listView->setSpacing(4);
|
||||
listView->setFlow(QListView::LeftToRight);
|
||||
listView->setDragEnabled(false);
|
||||
listView->setMinimumSize(375, 210);
|
||||
connect(listView, &QListWidget::clicked,
|
||||
this, &MoreAppsWidget::appClicked);
|
||||
|
||||
QList<DesktopAppData> appList = appsMap[cat];
|
||||
for (auto app: appList) {
|
||||
QListWidgetItem *buttonItem = new QListWidgetItem(listView);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole+1, app.showInTerminal);
|
||||
QColor foregroundColor =
|
||||
this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
m_tabs->addTab(listView, QIcon::fromTheme(iconName), "");
|
||||
m_tabs->setTabToolTip(m_tabs->count(), cat);
|
||||
if (cat == "Graphics") {
|
||||
m_tabs->setCurrentIndex(m_tabs->count() -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef MOREAPPSWIDGET_H
|
||||
#define MOREAPPSWIDGET_H
|
||||
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include <QWidget>
|
||||
|
||||
class QPixmap;
|
||||
class QVBoxLayout;
|
||||
class QTabWidget;
|
||||
|
||||
class MoreAppsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MoreAppsWidget(const QPixmap &pixmap,
|
||||
const DesktopFileParser &parser,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void appClicked(const QModelIndex &index);
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QVBoxLayout *m_layout;
|
||||
QTabWidget *m_tabs;
|
||||
|
||||
};
|
||||
|
||||
#endif // MOREAPPSWIDGET_H
|
||||
@@ -6,18 +6,18 @@
|
||||
|
||||
namespace {
|
||||
static const TerminalApp terminalApps[] = {
|
||||
{ "xterm", "-e" },
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
{ "gnome-terminal", "--" },
|
||||
{ "terminator", "-e" },
|
||||
{ "terminology", "-e" },
|
||||
{ "tilix", "-e" },
|
||||
{ "xterm", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user