mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-01-06 17:13:58 +00:00
Add OpenWith... tool
This commit is contained in:
@@ -86,7 +86,11 @@ SOURCES += src/main.cpp\
|
||||
src/core/resourceexporter.cpp \
|
||||
src/capture/widget/notifierbox.cpp \
|
||||
src/utils/desktopinfo.cpp \
|
||||
src/utils/dbusutils.cpp
|
||||
src/utils/dbusutils.cpp \
|
||||
src/capture/workers/launcher/applauncherwidget.cpp \
|
||||
src/capture/tools/applauncher.cpp \
|
||||
src/utils/desktopfileparse.cpp \
|
||||
src/capture/workers/launcher/launcheritemdelegate.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/capture/widget/buttonhandler.h \
|
||||
@@ -137,7 +141,11 @@ HEADERS += \
|
||||
src/core/resourceexporter.h \
|
||||
src/capture/widget/notifierbox.h \
|
||||
src/utils/desktopinfo.h \
|
||||
src/utils/dbusutils.h
|
||||
src/utils/dbusutils.h \
|
||||
src/capture/workers/launcher/applauncherwidget.h \
|
||||
src/capture/tools/applauncher.h \
|
||||
src/utils/desktopfileparse.h \
|
||||
src/capture/workers/launcher/launcheritemdelegate.h
|
||||
|
||||
RESOURCES += \
|
||||
graphics.qrc
|
||||
|
||||
@@ -39,5 +39,7 @@
|
||||
<file>img/configBlack/name_edition.png</file>
|
||||
<file>img/buttonIconsBlack/size_indicator.png</file>
|
||||
<file>img/buttonIconsWhite/size_indicator.png</file>
|
||||
<file>img/buttonIconsBlack/open_with.png</file>
|
||||
<file>img/buttonIconsWhite/open_with.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
img/buttonIconsBlack/open_with.png
Normal file
BIN
img/buttonIconsBlack/open_with.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 270 B |
1
img/buttonIconsBlack/open_with.svg
Normal file
1
img/buttonIconsBlack/open_with.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 4H5c-1.11 0-2 .9-2 2v12c0 1.1.89 2 2 2h4v-2H5V8h14v10h-4v2h4c1.1 0 2-.9 2-2V6c0-1.1-.89-2-2-2zm-7 6l-4 4h3v6h2v-6h3l-4-4z"/></svg>
|
||||
|
After Width: | Height: | Size: 226 B |
BIN
img/buttonIconsWhite/open_with.png
Normal file
BIN
img/buttonIconsWhite/open_with.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 292 B |
65
img/buttonIconsWhite/open_with.svg
Normal file
65
img/buttonIconsWhite/open_with.svg
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
version="1.1"
|
||||
id="svg4"
|
||||
sodipodi:docname="open_with_.svg"
|
||||
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">
|
||||
<metadata
|
||||
id="metadata10">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs8" />
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1328"
|
||||
inkscape:window-height="739"
|
||||
id="namedview6"
|
||||
showgrid="false"
|
||||
inkscape:zoom="18.873951"
|
||||
inkscape:cx="16.78602"
|
||||
inkscape:cy="10.666114"
|
||||
inkscape:window-x="38"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg4" />
|
||||
<path
|
||||
d="M19 4H5c-1.11 0-2 .9-2 2v12c0 1.1.89 2 2 2h4v-2H5V8h14v10h-4v2h4c1.1 0 2-.9 2-2V6c0-1.1-.89-2-2-2zm-7 6l-4 4h3v6h2v-6h3l-4-4z"
|
||||
id="path2"
|
||||
style="fill:#ffffff;fill-opacity:1" />
|
||||
<path
|
||||
style="fill:#ffffff;stroke-width:0.09588913"
|
||||
d="M 4.198234,19.778391 C 3.7176061,19.568619 3.2251261,18.939838 3.1058504,18.383675 2.9582027,17.695218 2.958749,6.3034296 3.1064628,5.6146641 3.2377064,5.0026963 3.8101581,4.3320483 4.3300656,4.181169 4.5640205,4.1132743 7.143815,4.0896738 12.220084,4.1089894 l 7.542403,0.028699 0.36845,0.2932257 c 0.202647,0.1612741 0.465536,0.4832555 0.584199,0.7155141 l 0.215751,0.4222884 V 11.97605 c 0,6.919572 0.009,6.789901 -0.507995,7.344116 -0.512385,0.549308 -0.73473,0.591284 -3.131972,0.591284 h -2.20927 v -0.910946 -0.910947 h 1.965727 1.965727 V 13.006811 7.9240647 l -7.023878,0.024595 -7.023879,0.024595 v 5.0341793 5.034179 l 1.9896994,0.02592 1.9896994,0.02592 v 0.909001 0.909001 l -2.2294222,-0.0037 c -1.61992,-0.0027 -2.3080677,-0.03808 -2.5170896,-0.129306 z"
|
||||
id="path23"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#ffffff;stroke-width:0.09588913"
|
||||
d="M 11.054307,16.938887 V 13.966324 H 9.5922933 8.1302801 l 1.9414589,-1.941459 1.941459,-1.941458 1.941459,1.941458 1.941459,1.941459 h -1.462014 -1.462013 v 2.972563 2.972563 h -0.958891 -0.958891 z"
|
||||
id="path25"
|
||||
inkscape:connector-curvature="0" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
63
src/capture/tools/applauncher.cpp
Normal file
63
src/capture/tools/applauncher.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "applauncher.h"
|
||||
|
||||
AppLauncher::AppLauncher(QObject *parent) : CaptureTool(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int AppLauncher::id() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AppLauncher::isSelectable() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString AppLauncher::iconName() const {
|
||||
return "open_with.png";
|
||||
}
|
||||
|
||||
QString AppLauncher::name() const {
|
||||
return tr("App Launcher");
|
||||
}
|
||||
|
||||
QString AppLauncher::description() const {
|
||||
return tr("Choose an app to open the capture");
|
||||
}
|
||||
|
||||
CaptureTool::ToolWorkType AppLauncher::toolType() const {
|
||||
return TYPE_WORKER;
|
||||
}
|
||||
|
||||
void AppLauncher::processImage(
|
||||
QPainter &painter,
|
||||
const QVector<QPoint> &points,
|
||||
const QColor &color,
|
||||
const int thickness)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(points);
|
||||
Q_UNUSED(color);
|
||||
Q_UNUSED(thickness);
|
||||
}
|
||||
|
||||
void AppLauncher::onPressed() {
|
||||
Q_EMIT requestAction(REQ_OPEN_APP);
|
||||
}
|
||||
46
src/capture/tools/applauncher.h
Normal file
46
src/capture/tools/applauncher.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef APPOPENER_H
|
||||
#define APPOPENER_H
|
||||
|
||||
#include "capturetool.h"
|
||||
|
||||
class AppLauncher : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncher(QObject *parent = nullptr);
|
||||
|
||||
int id() const override;
|
||||
bool isSelectable() const override;
|
||||
ToolWorkType toolType() const override;
|
||||
|
||||
QString iconName() const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
void processImage(
|
||||
QPainter &painter,
|
||||
const QVector<QPoint> &points,
|
||||
const QColor &color,
|
||||
const int thickness) override;
|
||||
|
||||
void onPressed() override;
|
||||
};
|
||||
|
||||
#endif // APPOPENER_H
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
REQ_TO_CLIPBOARD,
|
||||
REQ_UPLOAD_TO_IMGUR,
|
||||
REQ_MOVE_MODE,
|
||||
REQ_OPEN_APP,
|
||||
};
|
||||
|
||||
explicit CaptureTool(QObject *parent = nullptr);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "selectiontool.h"
|
||||
#include "sizeindicatortool.h"
|
||||
#include "undotool.h"
|
||||
#include "applauncher.h"
|
||||
|
||||
ToolFactory::ToolFactory(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -84,6 +85,9 @@ CaptureTool* ToolFactory::CreateTool(
|
||||
case CaptureButton::TYPE_UNDO:
|
||||
tool = new UndoTool(parent);
|
||||
break;
|
||||
case CaptureButton::TYPE_OPEN_APP:
|
||||
tool = new AppLauncher(parent);
|
||||
break;
|
||||
default:
|
||||
tool = nullptr;
|
||||
break;
|
||||
|
||||
@@ -190,6 +190,7 @@ static std::map<CaptureButton::ButtonType, int> buttonTypeOrder {
|
||||
{ CaptureButton::TYPE_SAVE, 11 },
|
||||
{ CaptureButton::TYPE_EXIT, 12 },
|
||||
{ CaptureButton::TYPE_IMAGEUPLOADER, 13 },
|
||||
{ CaptureButton::TYPE_OPEN_APP, 14 },
|
||||
};
|
||||
|
||||
int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b) {
|
||||
@@ -197,7 +198,6 @@ int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b) {
|
||||
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size() : it->second;
|
||||
}
|
||||
|
||||
|
||||
QVector<CaptureButton::ButtonType> CaptureButton::iterableButtonTypes = {
|
||||
CaptureButton::TYPE_PENCIL,
|
||||
CaptureButton::TYPE_LINE,
|
||||
@@ -213,4 +213,5 @@ QVector<CaptureButton::ButtonType> CaptureButton::iterableButtonTypes = {
|
||||
CaptureButton::TYPE_SAVE,
|
||||
CaptureButton::TYPE_EXIT,
|
||||
CaptureButton::TYPE_IMAGEUPLOADER,
|
||||
CaptureButton::TYPE_OPEN_APP,
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
TYPE_SAVE,
|
||||
TYPE_EXIT,
|
||||
TYPE_IMAGEUPLOADER,
|
||||
TYPE_OPEN_APP,
|
||||
};
|
||||
|
||||
CaptureButton() = delete;
|
||||
|
||||
@@ -470,6 +470,9 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
|
||||
case CaptureTool::REQ_UPLOAD_TO_IMGUR:
|
||||
uploadToImgur();
|
||||
break;
|
||||
case CaptureTool::REQ_OPEN_APP:
|
||||
openWithProgram();
|
||||
break;
|
||||
case CaptureTool::REQ_MOVE_MODE:
|
||||
m_state = CaptureButton::TYPE_MOVESELECTION;
|
||||
if (m_lastPressedButton) {
|
||||
@@ -613,6 +616,12 @@ void CaptureWidget::uploadToImgur() {
|
||||
close();
|
||||
}
|
||||
|
||||
void CaptureWidget::openWithProgram() {
|
||||
m_captureDone = true;
|
||||
ResourceExporter().captureToProgram(pixmap());
|
||||
close();
|
||||
}
|
||||
|
||||
QRect CaptureWidget::extendedSelection() const {
|
||||
if (m_selection.isNull())
|
||||
return QRect();
|
||||
|
||||
@@ -60,6 +60,7 @@ private slots:
|
||||
void copyScreenshot();
|
||||
void saveScreenshot();
|
||||
void uploadToImgur();
|
||||
void openWithProgram();
|
||||
bool undo();
|
||||
|
||||
void leftResize();
|
||||
|
||||
91
src/capture/workers/launcher/applauncherwidget.cpp
Normal file
91
src/capture/workers/launcher/applauncherwidget.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "applauncherwidget.h"
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/capture/workers/launcher/launcheritemdelegate.h"
|
||||
#include <QDir>
|
||||
#include <QVector>
|
||||
#include <QProcess>
|
||||
#include <QPixmap>
|
||||
#include <QListView>
|
||||
#include <QListWidgetItem>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
QWidget(parent), m_pixmap(p)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
m_tempFile = FileNameHandler().generateAbsolutePath("/tmp") + ".png";
|
||||
bool ok = p.save(m_tempFile);
|
||||
if (!ok) {
|
||||
// TO DO
|
||||
return;
|
||||
}
|
||||
QString dir = "/usr/share/applications/";
|
||||
QString dirLocal = "~/.local/share/applications/";
|
||||
QDir appsDirLocal(dirLocal);
|
||||
QDir appsDir(dir);
|
||||
|
||||
QStringList entries = appsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
QStringList entriesLocal = appsDirLocal.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
|
||||
DesktopFileParse parser;
|
||||
QList<DesktopAppData> appList;
|
||||
for (QString file: entries){
|
||||
DesktopAppData app = parser.parseDesktopFile(dir + file, ok);
|
||||
if (ok) {
|
||||
appList.append(app);
|
||||
}
|
||||
}
|
||||
for (QString file: entriesLocal){
|
||||
DesktopAppData app = parser.parseDesktopFile(dirLocal + file, ok);
|
||||
if (ok) {
|
||||
appList.append(app);
|
||||
}
|
||||
}
|
||||
auto layout = new QHBoxLayout(this);
|
||||
auto *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);
|
||||
|
||||
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);
|
||||
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);
|
||||
layout->addWidget(listView);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::launch(const QModelIndex &index) {
|
||||
QString command = index.data(Qt::UserRole).toString().replace(
|
||||
QRegExp("(\%.)"), m_tempFile);
|
||||
QProcess::startDetached(command);
|
||||
}
|
||||
38
src/capture/workers/launcher/applauncherwidget.h
Normal file
38
src/capture/workers/launcher/applauncherwidget.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef APPLAUNCHERWIDGET_H
|
||||
#define APPLAUNCHERWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class AppLauncherWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncherWidget(const QPixmap &p, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QString m_tempFile;
|
||||
|
||||
private slots:
|
||||
void launch(const QModelIndex &index);
|
||||
|
||||
};
|
||||
|
||||
#endif // APPLAUNCHERWIDGET_H
|
||||
63
src/capture/workers/launcher/launcheritemdelegate.cpp
Normal file
63
src/capture/workers/launcher/launcheritemdelegate.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "launcheritemdelegate.h"
|
||||
#include <QPainter>
|
||||
|
||||
launcherItemDelegate::launcherItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void launcherItemDelegate::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
const QRect &rect = option.rect;
|
||||
if (option.state & (QStyle::State_Selected | QStyle::State_MouseOver)) {
|
||||
painter->save();
|
||||
painter->setPen(Qt::transparent);
|
||||
painter->setBrush(QPalette().highlight());
|
||||
painter->drawRect(rect.x(), rect.y(),
|
||||
rect.width() -1, rect.height() -1);
|
||||
painter->restore();
|
||||
}
|
||||
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
|
||||
const int iconSide = 40;
|
||||
const int halfIcon = iconSide/2;
|
||||
const int halfWidth = rect.width()/2;
|
||||
const int halfHeight = rect.height()/2;
|
||||
painter->drawPixmap(rect.x() + (halfWidth - halfIcon),
|
||||
rect.y()+ (halfHeight/2 - halfIcon),
|
||||
iconSide, iconSide,
|
||||
icon.pixmap(QSize(iconSide, iconSide)));
|
||||
const QRect textRect(rect.x(), rect.y() + halfHeight,
|
||||
rect.width(), halfHeight);
|
||||
painter->drawText(textRect, Qt::TextWordWrap | Qt::AlignHCenter,
|
||||
index.data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
QSize launcherItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
return QSize(100, 100);
|
||||
}
|
||||
40
src/capture/workers/launcher/launcheritemdelegate.h
Normal file
40
src/capture/workers/launcher/launcheritemdelegate.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef LAUNCHERITEMDELEGATE_H
|
||||
#define LAUNCHERITEMDELEGATE_H
|
||||
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class launcherItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit launcherItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // LAUNCHERITEMDELEGATE_H
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "src/capture/workers/imgur/imguruploader.h"
|
||||
#include "src/capture/workers/screenshotsaver.h"
|
||||
#include "src/capture/workers/graphicalscreenshotsaver.h"
|
||||
#include "src/capture/workers/launcher/applauncherwidget.h"
|
||||
|
||||
ResourceExporter::ResourceExporter() {
|
||||
|
||||
@@ -41,3 +42,8 @@ void ResourceExporter::captureToImgur(const QPixmap &p) {
|
||||
auto w = new ImgurUploader(p);
|
||||
w->show();
|
||||
}
|
||||
|
||||
void ResourceExporter::captureToProgram(const QPixmap &p) {
|
||||
auto w = new AppLauncherWidget(p);
|
||||
w->show();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
void captureToFile(const QPixmap &p, const QString &path);
|
||||
void captureToFileUi(const QPixmap &p);
|
||||
void captureToImgur(const QPixmap &p);
|
||||
void captureToProgram(const QPixmap &p);
|
||||
};
|
||||
|
||||
#endif // RESOURCEEXPORTER_H
|
||||
|
||||
99
src/utils/desktopfileparse.cpp
Normal file
99
src/utils/desktopfileparse.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "desktopfileparse.h"
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QLocale>
|
||||
|
||||
DesktopFileParse::DesktopFileParse() {
|
||||
QString locale = QLocale().name();
|
||||
m_localeName = QString("Name[%1]").arg(locale);
|
||||
m_localeDescription = QString("Comment[%1]").arg(locale);
|
||||
}
|
||||
|
||||
DesktopAppData DesktopFileParse::parseDesktopFile(
|
||||
const QString &fileName, bool &ok)
|
||||
{
|
||||
DesktopAppData res;
|
||||
ok = true;
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
ok = false;
|
||||
return res;
|
||||
}
|
||||
bool nameLocaleSet = false;
|
||||
bool descriptionLocaleSet = false;
|
||||
bool isApplication = false;
|
||||
bool isGraphics = false;
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith("Icon")) {
|
||||
res.icon = QIcon::fromTheme(
|
||||
line.mid(line.indexOf("=")+1).trimmed());
|
||||
}
|
||||
else if (!nameLocaleSet && line.startsWith("Name")) {
|
||||
if (line.startsWith(m_localeName)) {
|
||||
res.name = line.mid(line.indexOf("=")+1).trimmed();
|
||||
nameLocaleSet = true;
|
||||
} else if (line.startsWith("Name=")) {
|
||||
res.name = line.mid(line.indexOf("=")+1).trimmed();
|
||||
}
|
||||
}
|
||||
else if (!descriptionLocaleSet && line.startsWith("Comment")) {
|
||||
if (line.startsWith(m_localeName)) {
|
||||
res.description = line.mid(line.indexOf("=")+1).trimmed();
|
||||
descriptionLocaleSet = true;
|
||||
} else if (line.startsWith("Comment=")) {
|
||||
res.description = line.mid(line.indexOf("=")+1).trimmed();
|
||||
}
|
||||
}
|
||||
else if (line.startsWith("MimeType") &&
|
||||
!line.contains("image/png"))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
else if (line.startsWith("Exec")) {
|
||||
if (line.contains("%")) {
|
||||
res.exec = line.mid(line.indexOf("=")+1)
|
||||
.trimmed();
|
||||
} else {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (line.startsWith("Type")) {
|
||||
if (line.contains("Application")) {
|
||||
isApplication = true;
|
||||
}
|
||||
}
|
||||
else if (line.startsWith("Categories")) {
|
||||
if (line.contains("Graphics")) {
|
||||
isGraphics = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (res.exec.isEmpty() || res.name.isEmpty() || !isApplication ||
|
||||
!isGraphics) {
|
||||
ok = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
44
src/utils/desktopfileparse.h
Normal file
44
src/utils/desktopfileparse.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef DESKTOPFILEPARSE_H
|
||||
#define DESKTOPFILEPARSE_H
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
class QFile;
|
||||
class QString;
|
||||
class QTextStream;
|
||||
|
||||
struct DesktopAppData {
|
||||
QIcon icon;
|
||||
QString name;
|
||||
QString description;
|
||||
QString exec;
|
||||
};
|
||||
|
||||
struct DesktopFileParse {
|
||||
DesktopFileParse();
|
||||
DesktopAppData parseDesktopFile(const QString &fileName, bool &ok);
|
||||
|
||||
private:
|
||||
QString m_localeName;
|
||||
QString m_localeDescription;
|
||||
|
||||
};
|
||||
|
||||
#endif // DESKTOPFILEPARSE_H
|
||||
Reference in New Issue
Block a user