Fix whitespace consistency
This commit is contained in:
@@ -129,7 +129,7 @@ QString CaptureButton::styleSheet() const {
|
||||
// get icon returns the icon for the type of button
|
||||
QIcon CaptureButton::icon() const {
|
||||
QString color(iconIsWhiteByColor(m_mainColor) ? "White" : "Black");
|
||||
QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
|
||||
QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
|
||||
.arg(color).arg(m_tool->iconName());
|
||||
return QIcon(iconPath);
|
||||
}
|
||||
@@ -187,15 +187,15 @@ static std::map<CaptureButton::ButtonType, int> buttonTypeOrder {
|
||||
{ CaptureButton::TYPE_RECTANGLE, 4 },
|
||||
{ CaptureButton::TYPE_CIRCLE, 5 },
|
||||
{ CaptureButton::TYPE_MARKER, 6 },
|
||||
{ CaptureButton::TYPE_SELECTIONINDICATOR, 8 },
|
||||
{ CaptureButton::TYPE_MOVESELECTION, 9 },
|
||||
{ CaptureButton::TYPE_UNDO, 10 },
|
||||
{ CaptureButton::TYPE_COPY, 11 },
|
||||
{ CaptureButton::TYPE_SAVE, 12 },
|
||||
{ CaptureButton::TYPE_EXIT, 13 },
|
||||
{ CaptureButton::TYPE_IMAGEUPLOADER, 14 },
|
||||
{ CaptureButton::TYPE_OPEN_APP, 15 },
|
||||
{ CaptureButton::TYPE_BLUR, 7 },
|
||||
{ CaptureButton::TYPE_SELECTIONINDICATOR, 8 },
|
||||
{ CaptureButton::TYPE_MOVESELECTION, 9 },
|
||||
{ CaptureButton::TYPE_UNDO, 10 },
|
||||
{ CaptureButton::TYPE_COPY, 11 },
|
||||
{ CaptureButton::TYPE_SAVE, 12 },
|
||||
{ CaptureButton::TYPE_EXIT, 13 },
|
||||
{ CaptureButton::TYPE_IMAGEUPLOADER, 14 },
|
||||
{ CaptureButton::TYPE_OPEN_APP, 15 },
|
||||
{ CaptureButton::TYPE_BLUR, 7 },
|
||||
};
|
||||
|
||||
int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b) {
|
||||
@@ -211,7 +211,7 @@ QVector<CaptureButton::ButtonType> CaptureButton::iterableButtonTypes = {
|
||||
CaptureButton::TYPE_RECTANGLE,
|
||||
CaptureButton::TYPE_CIRCLE,
|
||||
CaptureButton::TYPE_MARKER,
|
||||
CaptureButton::TYPE_BLUR,
|
||||
CaptureButton::TYPE_BLUR,
|
||||
CaptureButton::TYPE_SELECTIONINDICATOR,
|
||||
CaptureButton::TYPE_MOVESELECTION,
|
||||
CaptureButton::TYPE_UNDO,
|
||||
|
||||
@@ -34,22 +34,22 @@ public:
|
||||
// Don't forget to add the new types to CaptureButton::iterableButtonTypes
|
||||
// in the .cpp and the order value in the private array buttonTypeOrder
|
||||
enum ButtonType {
|
||||
TYPE_PENCIL = 0,
|
||||
TYPE_LINE = 1,
|
||||
TYPE_ARROW = 2,
|
||||
TYPE_SELECTION = 3,
|
||||
TYPE_RECTANGLE = 4,
|
||||
TYPE_CIRCLE = 5,
|
||||
TYPE_MARKER = 6,
|
||||
TYPE_SELECTIONINDICATOR = 7,
|
||||
TYPE_MOVESELECTION = 8,
|
||||
TYPE_UNDO = 9,
|
||||
TYPE_COPY = 10,
|
||||
TYPE_SAVE = 11,
|
||||
TYPE_EXIT = 12,
|
||||
TYPE_IMAGEUPLOADER = 13,
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_BLUR = 15,
|
||||
TYPE_PENCIL = 0,
|
||||
TYPE_LINE = 1,
|
||||
TYPE_ARROW = 2,
|
||||
TYPE_SELECTION = 3,
|
||||
TYPE_RECTANGLE = 4,
|
||||
TYPE_CIRCLE = 5,
|
||||
TYPE_MARKER = 6,
|
||||
TYPE_SELECTIONINDICATOR = 7,
|
||||
TYPE_MOVESELECTION = 8,
|
||||
TYPE_UNDO = 9,
|
||||
TYPE_COPY = 10,
|
||||
TYPE_SAVE = 11,
|
||||
TYPE_EXIT = 12,
|
||||
TYPE_IMAGEUPLOADER = 13,
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_BLUR = 15,
|
||||
};
|
||||
|
||||
CaptureButton() = delete;
|
||||
|
||||
@@ -64,11 +64,11 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
|
||||
m_LHandle = baseRect; m_THandle = baseRect;
|
||||
m_RHandle = baseRect; m_BHandle = baseRect;
|
||||
|
||||
m_handles << &m_TLHandle << &m_TRHandle << &m_BLHandle << &m_BRHandle
|
||||
m_handles << &m_TLHandle << &m_TRHandle << &m_BLHandle << &m_BRHandle
|
||||
<< &m_LHandle << &m_THandle << &m_RHandle << &m_BHandle;
|
||||
|
||||
m_sides << &m_TLHandle << &m_TRHandle << &m_BLHandle << &m_BRHandle
|
||||
<< &m_LSide << &m_TSide << &m_RSide << &m_BSide;
|
||||
m_sides << &m_TLHandle << &m_TRHandle << &m_BLHandle << &m_BRHandle
|
||||
<< &m_LSide << &m_TSide << &m_RSide << &m_BSide;
|
||||
|
||||
// set base config of the widget
|
||||
setWindowFlags(Qt::BypassWindowManagerHint
|
||||
@@ -225,8 +225,8 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
|
||||
// paint handlers
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBrush(m_uiColor);
|
||||
for(auto r: m_handles) {
|
||||
painter.drawRoundRect(*r, 100, 100);
|
||||
for(auto r: m_handles) {
|
||||
painter.drawRoundRect(*r, 100, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,8 +270,8 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
m_buttonHandler->hide();
|
||||
}
|
||||
if (m_newSelection) {
|
||||
m_selection = QRect(m_dragStartPoint, m_mousePos).normalized();
|
||||
updateHandles();
|
||||
m_selection = QRect(m_dragStartPoint, m_mousePos).normalized();
|
||||
updateHandles();
|
||||
update();
|
||||
} else if (!m_mouseOverHandle) {
|
||||
// Moving the whole selection
|
||||
@@ -291,7 +291,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
} if (!r.contains(QPoint(r.center().x(), m_selection.bottom()))) {
|
||||
m_selection.setBottom(r.bottom());
|
||||
}
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
} else {
|
||||
// Dragging a handle
|
||||
@@ -299,7 +299,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
QPoint offset = e->pos() - m_dragStartPoint;
|
||||
bool symmetryMod = qApp->keyboardModifiers() & Qt::ShiftModifier;
|
||||
|
||||
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_TSide
|
||||
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_TSide
|
||||
|| m_mouseOverHandle == &m_TRHandle)
|
||||
{ // dragging one of the top handles
|
||||
r.setTop(r.top() + offset.y());
|
||||
@@ -307,7 +307,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
r.setBottom(r.bottom() - offset.y());
|
||||
}
|
||||
}
|
||||
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_LSide
|
||||
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_LSide
|
||||
|| m_mouseOverHandle == &m_BLHandle)
|
||||
{ // dragging one of the left handles
|
||||
r.setLeft(r.left() + offset.x());
|
||||
@@ -315,7 +315,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
r.setRight(r.right() - offset.x());
|
||||
}
|
||||
}
|
||||
if (m_mouseOverHandle == &m_BLHandle || m_mouseOverHandle == &m_BSide
|
||||
if (m_mouseOverHandle == &m_BLHandle || m_mouseOverHandle == &m_BSide
|
||||
|| m_mouseOverHandle == &m_BRHandle)
|
||||
{ // dragging one of the bottom handles
|
||||
r.setBottom(r.bottom() + offset.y());
|
||||
@@ -323,7 +323,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
r.setTop(r.top() - offset.y());
|
||||
}
|
||||
}
|
||||
if (m_mouseOverHandle == &m_TRHandle || m_mouseOverHandle == &m_RSide
|
||||
if (m_mouseOverHandle == &m_TRHandle || m_mouseOverHandle == &m_RSide
|
||||
|| m_mouseOverHandle == &m_BRHandle)
|
||||
{ // dragging one of the right handles
|
||||
r.setRight(r.right() + offset.x());
|
||||
@@ -332,7 +332,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
m_selection = r.normalized();
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
} else if (m_mouseIsClicked && m_state != CaptureButton::TYPE_MOVESELECTION) {
|
||||
@@ -355,7 +355,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
return;
|
||||
}
|
||||
bool found = false;
|
||||
for (QRect *const r: m_sides) {
|
||||
for (QRect *const r: m_sides) {
|
||||
if (r->contains(e->pos())) {
|
||||
m_mouseOverHandle = r;
|
||||
found = true;
|
||||
@@ -399,25 +399,25 @@ void CaptureWidget::keyPressEvent(QKeyEvent *e) {
|
||||
&& m_selection.top() > rect().top()) {
|
||||
m_selection.moveTop(m_selection.top()-1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
} else if (e->key() == Qt::Key_Down
|
||||
&& m_selection.bottom() < rect().bottom()) {
|
||||
m_selection.moveBottom(m_selection.bottom()+1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
} else if (e->key() == Qt::Key_Left
|
||||
&& m_selection.left() > rect().left()) {
|
||||
m_selection.moveLeft(m_selection.left()-1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
} else if (e->key() == Qt::Key_Right
|
||||
&& m_selection.right() < rect().right()) {
|
||||
m_selection.moveRight(m_selection.right()+1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -516,7 +516,7 @@ void CaptureWidget::leftResize() {
|
||||
m_selection.setRight(m_selection.right()-1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateSizeIndicator();
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -526,7 +526,7 @@ void CaptureWidget::rightResize() {
|
||||
m_selection.setRight(m_selection.right()+1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateSizeIndicator();
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ void CaptureWidget::upResize() {
|
||||
m_selection.setBottom(m_selection.bottom()-1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateSizeIndicator();
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -546,7 +546,7 @@ void CaptureWidget::downResize() {
|
||||
m_selection.setBottom(m_selection.bottom()+1);
|
||||
m_buttonHandler->updatePosition(m_selection);
|
||||
updateSizeIndicator();
|
||||
updateHandles();
|
||||
updateHandles();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -578,16 +578,16 @@ void CaptureWidget::updateHandles() {
|
||||
m_RHandle.moveTopRight(QPoint(r.right() + s2, r.y() + r.height() / 2 - s2));
|
||||
m_BHandle.moveBottomLeft(QPoint(r.x() + r.width() / 2 - s2, r.bottom() + s2));
|
||||
|
||||
m_LSide = QRect(m_TLHandle.bottomLeft(), m_BLHandle.topRight());
|
||||
m_RSide = QRect(m_TRHandle.bottomLeft(), m_BRHandle.topRight());
|
||||
m_BSide = QRect(m_BLHandle.topRight(), m_BRHandle.bottomLeft());
|
||||
m_TSide = QRect(m_TLHandle.topRight(), m_TRHandle.bottomLeft());
|
||||
m_LSide = QRect(m_TLHandle.bottomLeft(), m_BLHandle.topRight());
|
||||
m_RSide = QRect(m_TRHandle.bottomLeft(), m_BRHandle.topRight());
|
||||
m_BSide = QRect(m_BLHandle.topRight(), m_BRHandle.bottomLeft());
|
||||
m_TSide = QRect(m_TLHandle.topRight(), m_TRHandle.bottomLeft());
|
||||
}
|
||||
|
||||
void CaptureWidget::updateSizeIndicator() {
|
||||
if (m_sizeIndButton){
|
||||
const QRect &selection = extendedSelection();
|
||||
m_sizeIndButton->setText(QStringLiteral("%1\n%2")
|
||||
m_sizeIndButton->setText(QStringLiteral("%1\n%2")
|
||||
.arg(selection.width())
|
||||
.arg(selection.height()));
|
||||
}
|
||||
@@ -605,9 +605,9 @@ void CaptureWidget::updateCursor() {
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
} else if (m_mouseOverHandle == &m_TRHandle || m_mouseOverHandle == &m_BLHandle) {
|
||||
setCursor(Qt::SizeBDiagCursor);
|
||||
} else if (m_mouseOverHandle == &m_LSide || m_mouseOverHandle == &m_RSide) {
|
||||
} else if (m_mouseOverHandle == &m_LSide || m_mouseOverHandle == &m_RSide) {
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
} else if (m_mouseOverHandle == &m_TSide || m_mouseOverHandle == &m_BSide) {
|
||||
} else if (m_mouseOverHandle == &m_TSide || m_mouseOverHandle == &m_BSide) {
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
}
|
||||
} else if (m_selection.contains(m_mousePos)) {
|
||||
|
||||
@@ -111,11 +111,11 @@ protected:
|
||||
// 1 letter: the handle on the middle of the corresponding side
|
||||
QRect m_TLHandle, m_TRHandle, m_BLHandle, m_BRHandle;
|
||||
QRect m_LHandle, m_THandle, m_RHandle, m_BHandle;
|
||||
// Side Rects
|
||||
QRect m_LSide, m_TSide, m_RSide, m_BSide;
|
||||
// Side Rects
|
||||
QRect m_LSide, m_TSide, m_RSide, m_BSide;
|
||||
// list containing the active habdlers
|
||||
QVector<QRect*> m_handles;
|
||||
QVector<QRect*> m_sides;
|
||||
QVector<QRect*> m_handles;
|
||||
QVector<QRect*> m_sides;
|
||||
|
||||
private:
|
||||
void initShortcuts();
|
||||
|
||||
@@ -37,7 +37,7 @@ ImageLabel::ImageLabel(QWidget *parent):
|
||||
|
||||
void ImageLabel::setScreenshot(const QPixmap &pixmap) {
|
||||
m_pixmap = pixmap;
|
||||
const QString tooltip = QStringLiteral("%1x%2 px").arg(m_pixmap.width())
|
||||
const QString tooltip = QStringLiteral("%1x%2 px").arg(m_pixmap.width())
|
||||
.arg(m_pixmap.height());
|
||||
setToolTip(tooltip);
|
||||
setScaledPixmap();
|
||||
|
||||
@@ -70,7 +70,7 @@ void ImgurUploader::handleReply(QNetworkReply *reply) {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QString data = QString::fromUtf8(reply->readAll());
|
||||
QString imageID = data.split("\"").at(5);
|
||||
QString url = QStringLiteral("http://i.imgur.com/%1.png").arg(imageID);
|
||||
QString url = QStringLiteral("http://i.imgur.com/%1.png").arg(imageID);
|
||||
m_imageURL.setUrl(url);
|
||||
onUploadOk();
|
||||
} else {
|
||||
|
||||
@@ -36,210 +36,211 @@
|
||||
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" }
|
||||
});
|
||||
{ "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)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
setWindowTitle(tr("Open With"));
|
||||
setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
setWindowTitle(tr("Open With"));
|
||||
|
||||
m_keepOpen = ConfigHandler().keepOpenAppLauncherValue();
|
||||
|
||||
QString dirLocal = QDir::homePath() + "/.local/share/applications/";
|
||||
QDir appsDirLocal(dirLocal);
|
||||
m_parser.processDirectory(appsDirLocal);
|
||||
QString dirLocal = QDir::homePath() + "/.local/share/applications/";
|
||||
QDir appsDirLocal(dirLocal);
|
||||
m_parser.processDirectory(appsDirLocal);
|
||||
|
||||
QString dir = "/usr/share/applications/";
|
||||
QDir appsDir(dir);
|
||||
m_parser.processDirectory(appsDir);
|
||||
QString dir = "/usr/share/applications/";
|
||||
QDir appsDir(dir);
|
||||
m_parser.processDirectory(appsDir);
|
||||
|
||||
initAppMap();
|
||||
initListWidget();
|
||||
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_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);
|
||||
|
||||
// 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);
|
||||
// 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_lineEdit->setFocus();
|
||||
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_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void AppLauncherWidget::launch(const QModelIndex &index) {
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
m_tempFile = FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to write in")
|
||||
+ QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
QString command = index.data(Qt::UserRole).toString().replace(
|
||||
return;
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::checkboxClicked(const bool enabled) {
|
||||
m_keepOpen = enabled;
|
||||
ConfigHandler().setKeepOpenAppLauncher(enabled);
|
||||
m_keepOpenCheckbox->setChecked(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;
|
||||
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);
|
||||
}
|
||||
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 = new QTabWidget;
|
||||
const int size = CaptureButton::buttonBaseSize();
|
||||
m_tabWidget->setIconSize(QSize(size, size));
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString &iconName = i.second;
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString &iconName = i.second;
|
||||
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QListWidget *itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
QListWidget *itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
|
||||
const QList<DesktopAppData> &appList = m_appsMap[cat];
|
||||
addAppsToListWidget(itemsWidget, appList);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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"});
|
||||
QStringList categories({"AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
"Graphics",
|
||||
"Network",
|
||||
"Office",
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility"});
|
||||
|
||||
m_appsMap = m_parser.getAppsByCategory(categories);
|
||||
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);
|
||||
// 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);
|
||||
connect(widget, &QListWidget::clicked,
|
||||
this, &AppLauncherWidget::launch);
|
||||
widget->setItemDelegate(new LauncherItemDelegate());
|
||||
widget->setViewMode(QListWidget::IconMode);
|
||||
widget->setResizeMode(QListView::Adjust);
|
||||
widget->setSpacing(4);
|
||||
widget->setFlow(QListView::LeftToRight);
|
||||
widget->setDragEnabled(false);
|
||||
widget->setMinimumWidth(CaptureButton::buttonBaseSize() * 11);
|
||||
connect(widget, &QListWidget::clicked,
|
||||
this, &AppLauncherWidget::launch);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::addAppsToListWidget(
|
||||
QListWidget *widget, const QList<DesktopAppData> &appList)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,26 +37,26 @@ public:
|
||||
private slots:
|
||||
void launch(const QModelIndex &index);
|
||||
void checkboxClicked(const bool enabled);
|
||||
void searchChanged(const QString &text);
|
||||
void searchChanged(const QString &text);
|
||||
|
||||
private:
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget *widget);
|
||||
void addAppsToListWidget(QListWidget *widget,
|
||||
const QList<DesktopAppData> &appList);
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget *widget);
|
||||
void addAppsToListWidget(QListWidget *widget,
|
||||
const QList<DesktopAppData> &appList);
|
||||
|
||||
DesktopFileParser m_parser;
|
||||
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;
|
||||
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
|
||||
|
||||
@@ -25,7 +25,7 @@ class LauncherItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LauncherItemDelegate(QObject *parent = nullptr);
|
||||
explicit LauncherItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
|
||||
@@ -22,39 +22,39 @@
|
||||
#include <QProcessEnvironment>
|
||||
|
||||
namespace {
|
||||
static const TerminalApp terminalApps[] = {
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
{ "gnome-terminal", "--" },
|
||||
{ "terminator", "-e" },
|
||||
{ "terminology", "-e" },
|
||||
{ "tilix", "-e" },
|
||||
{ "xterm", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
};
|
||||
static const TerminalApp terminalApps[] = {
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
{ "gnome-terminal", "--" },
|
||||
{ "terminator", "-e" },
|
||||
{ "terminology", "-e" },
|
||||
{ "tilix", "-e" },
|
||||
{ "xterm", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
};
|
||||
}
|
||||
|
||||
TerminalLauncher::TerminalLauncher(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
|
||||
TerminalApp TerminalLauncher::getPreferedTerminal() {
|
||||
TerminalApp res;
|
||||
for (const TerminalApp &app : terminalApps) {
|
||||
QString path = QStandardPaths::findExecutable(app.name);
|
||||
if (!path.isEmpty()) {
|
||||
res = app;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
TerminalApp res;
|
||||
for (const TerminalApp &app : terminalApps) {
|
||||
QString path = QStandardPaths::findExecutable(app.name);
|
||||
if (!path.isEmpty()) {
|
||||
res = app;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool TerminalLauncher::launchDetached(const QString &command) {
|
||||
TerminalApp app = getPreferedTerminal();
|
||||
QString s = app.name + " " + app.arg + " " + command;
|
||||
return QProcess::startDetached(s);
|
||||
TerminalApp app = getPreferedTerminal();
|
||||
QString s = app.name + " " + app.arg + " " + command;
|
||||
return QProcess::startDetached(s);
|
||||
}
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
#include <QObject>
|
||||
|
||||
struct TerminalApp {
|
||||
QString name;
|
||||
QString arg;
|
||||
QString name;
|
||||
QString arg;
|
||||
};
|
||||
|
||||
class TerminalLauncher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TerminalLauncher(QObject *parent = nullptr);
|
||||
explicit TerminalLauncher(QObject *parent = nullptr);
|
||||
|
||||
static bool launchDetached(const QString &command);
|
||||
static bool launchDetached(const QString &command);
|
||||
private:
|
||||
static TerminalApp getPreferedTerminal();
|
||||
static TerminalApp getPreferedTerminal();
|
||||
};
|
||||
|
||||
#endif // TERMINALLAUNCHER_H
|
||||
|
||||
@@ -40,8 +40,8 @@ QStringList addDashToOptionNames(const QStringList &names) {
|
||||
for (const QString &name: names) {
|
||||
// prepend "-" to single character options, and "--" to the others
|
||||
QString dashedName = (name.length() == 1) ?
|
||||
QStringLiteral("-%1").arg(name) :
|
||||
QStringLiteral("--%1").arg(name);
|
||||
QStringLiteral("-%1").arg(name) :
|
||||
QStringLiteral("--%1").arg(name);
|
||||
dashedNames << dashedName;
|
||||
}
|
||||
return dashedNames;
|
||||
@@ -57,7 +57,7 @@ QString optionsToString(const QList<CommandOption> &options,
|
||||
QStringList dashedOptions = addDashToOptionNames(option.names());
|
||||
QString joinedDashedOptions = dashedOptions.join(", ");
|
||||
if (!option.valueName().isEmpty()) {
|
||||
joinedDashedOptions += QStringLiteral(" <%1>")
|
||||
joinedDashedOptions += QStringLiteral(" <%1>")
|
||||
.arg(option.valueName());
|
||||
}
|
||||
if (joinedDashedOptions.length() > size) {
|
||||
@@ -75,7 +75,7 @@ QString optionsToString(const QList<CommandOption> &options,
|
||||
if(!dashedOptionList.isEmpty()) {
|
||||
result += "Options:\n";
|
||||
for (int i = 0; i < options.length(); ++i) {
|
||||
result += QStringLiteral(" %1 %2\n")
|
||||
result += QStringLiteral(" %1 %2\n")
|
||||
.arg(dashedOptionList.at(i).leftJustified(size, ' '))
|
||||
.arg(options.at(i).description());
|
||||
}
|
||||
@@ -87,7 +87,7 @@ QString optionsToString(const QList<CommandOption> &options,
|
||||
result += "Arguments:\n";
|
||||
}
|
||||
for (int i = 0; i < arguments.length(); ++i) {
|
||||
result += QStringLiteral(" %1 %2\n")
|
||||
result += QStringLiteral(" %1 %2\n")
|
||||
.arg(arguments.at(i).name().leftJustified(size, ' '))
|
||||
.arg(arguments.at(i).description());
|
||||
}
|
||||
@@ -119,7 +119,7 @@ bool CommandLineParser::processArgs(const QStringList &args,
|
||||
--actualIt;
|
||||
} else {
|
||||
ok = false;
|
||||
out << QStringLiteral("'%1' is not a valid argument.").arg(argument);
|
||||
out << QStringLiteral("'%1' is not a valid argument.").arg(argument);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
ok = isDoubleDashed ? arg.length() > 3 :
|
||||
arg.length() == 2;
|
||||
if (!ok) {
|
||||
out << QStringLiteral("the option %1 has a wrong format.").arg(arg);
|
||||
out << QStringLiteral("the option %1 has a wrong format.").arg(arg);
|
||||
return ok;
|
||||
}
|
||||
arg = isDoubleDashed ?
|
||||
@@ -157,12 +157,12 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (optionIt == endIt) {
|
||||
if (optionIt == endIt) {
|
||||
QString argName = actualNode->argument.name();
|
||||
if (argName.isEmpty()) {
|
||||
argName = qApp->applicationName();
|
||||
}
|
||||
out << QStringLiteral("the option '%1' is not a valid option "
|
||||
out << QStringLiteral("the option '%1' is not a valid option "
|
||||
"for the argument '%2'.").arg(arg)
|
||||
.arg(argName);
|
||||
ok = false;
|
||||
@@ -172,7 +172,7 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
CommandOption option = *optionIt;
|
||||
bool requiresValue = !(option.valueName().isEmpty());
|
||||
if (!requiresValue && equalsPos != -1) {
|
||||
out << QStringLiteral("the option '%1' contains a '=' and it doesn't "
|
||||
out << QStringLiteral("the option '%1' contains a '=' and it doesn't "
|
||||
"require a value.").arg(arg);
|
||||
ok = false;
|
||||
return ok;
|
||||
@@ -181,7 +181,7 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
if (actualIt+1 != args.cend()) {
|
||||
++actualIt;
|
||||
} else {
|
||||
out << QStringLiteral("Expected value after the option '%1'.").arg(arg);
|
||||
out << QStringLiteral("Expected value after the option '%1'.").arg(arg);
|
||||
ok = false;
|
||||
return ok;
|
||||
}
|
||||
@@ -237,7 +237,7 @@ bool CommandLineParser::parse(const QStringList &args) {
|
||||
}
|
||||
}
|
||||
if (!ok && !m_generalErrorMessage.isEmpty()) {
|
||||
out << QStringLiteral(" %1\n").arg(m_generalErrorMessage);
|
||||
out << QStringLiteral(" %1\n").arg(m_generalErrorMessage);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -335,8 +335,8 @@ void CommandLineParser::printHelp(QStringList args, const Node *node) {
|
||||
argName = qApp->applicationName();
|
||||
}
|
||||
QString argText = node->subNodes.isEmpty() ? "" : "[arguments]";
|
||||
helpText += QStringLiteral("Usage: %1 [%2-options] %3\n\n")
|
||||
.arg(args.join(" "))
|
||||
helpText += QStringLiteral("Usage: %1 [%2-options] %3\n\n")
|
||||
.arg(args.join(" "))
|
||||
.arg(argName).arg(argText);
|
||||
// add command options and subarguments
|
||||
QList<CommandArgument> subArgs;
|
||||
|
||||
@@ -46,10 +46,10 @@ void ButtonListView::initButtonList() {
|
||||
// when the background is lighter than gray, it uses the white icons
|
||||
QColor bgColor = this->palette().color(QWidget::backgroundRole());
|
||||
QString color = bgColor.valueF() < 0.6 ? "White" : "Black";
|
||||
QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
|
||||
QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
|
||||
.arg(color).arg(tool->iconName());
|
||||
if (t == CaptureButton::TYPE_SELECTIONINDICATOR) {
|
||||
iconPath = QStringLiteral(":/img/buttonIcons%1/size_indicator.png")
|
||||
iconPath = QStringLiteral(":/img/buttonIcons%1/size_indicator.png")
|
||||
.arg(color);
|
||||
}
|
||||
m_buttonItem->setIcon(QIcon(iconPath));
|
||||
|
||||
@@ -56,17 +56,17 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
|
||||
// visuals
|
||||
m_visuals = new VisualsEditor();
|
||||
addTab(m_visuals, QIcon(modifier + "graphics.png"),
|
||||
tr("Interface"));
|
||||
tr("Interface"));
|
||||
|
||||
// filename
|
||||
m_filenameEditor = new FileNameEditor();
|
||||
addTab(m_filenameEditor, QIcon(modifier + "name_edition.png"),
|
||||
tr("Filename Editor"));
|
||||
addTab(m_filenameEditor, QIcon(modifier + "name_edition.png"),
|
||||
tr("Filename Editor"));
|
||||
|
||||
// general
|
||||
m_generalConfig = new GeneneralConf();
|
||||
addTab(m_generalConfig, QIcon(modifier + "config.png"),
|
||||
tr("General"));
|
||||
addTab(m_generalConfig, QIcon(modifier + "config.png"),
|
||||
tr("General"));
|
||||
|
||||
// connect update sigslots
|
||||
connect(this, &ConfigWindow::updateChildren,
|
||||
|
||||
@@ -59,7 +59,7 @@ void FileNameEditor::initWidgets() {
|
||||
m_outputLabel = new QLineEdit(this);
|
||||
m_outputLabel->setDisabled(true);
|
||||
QString foreground = this->palette().foreground().color().name();
|
||||
m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
|
||||
m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
|
||||
QPalette pal = m_outputLabel->palette();
|
||||
QColor color = pal.color(QPalette::Disabled, m_outputLabel->backgroundRole());
|
||||
pal.setColor(QPalette::Active, m_outputLabel->backgroundRole(), color);
|
||||
|
||||
@@ -75,42 +75,42 @@ void GeneneralConf::autostartChanged(bool checked) {
|
||||
}
|
||||
|
||||
void GeneneralConf::importConfiguration() {
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Import"));
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Import"));
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QFile file(fileName);
|
||||
QTextCodec *codec = QTextCodec::codecForLocale();
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to read file."));
|
||||
return;
|
||||
}
|
||||
QString text = codec->toUnicode(file.readAll());
|
||||
file.close();
|
||||
QFile file(fileName);
|
||||
QTextCodec *codec = QTextCodec::codecForLocale();
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to read file."));
|
||||
return;
|
||||
}
|
||||
QString text = codec->toUnicode(file.readAll());
|
||||
file.close();
|
||||
|
||||
QFile config(ConfigHandler().configFilePath());
|
||||
if (!config.open(QFile::WriteOnly)) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to write file."));
|
||||
return;
|
||||
}
|
||||
config.write(codec->fromUnicode(text));
|
||||
config.close();
|
||||
QFile config(ConfigHandler().configFilePath());
|
||||
if (!config.open(QFile::WriteOnly)) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to write file."));
|
||||
return;
|
||||
}
|
||||
config.write(codec->fromUnicode(text));
|
||||
config.close();
|
||||
}
|
||||
|
||||
void GeneneralConf::exportFileConfiguration() {
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
|
||||
"flameshot.conf");
|
||||
QFile::copy(ConfigHandler().configFilePath(), fileName);
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
|
||||
"flameshot.conf");
|
||||
QFile::copy(ConfigHandler().configFilePath(), fileName);
|
||||
}
|
||||
|
||||
void GeneneralConf::resetConfiguration() {
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(
|
||||
this, tr("Confirm Reset"),
|
||||
tr("Are you sure you want to reset the configuration?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply == QMessageBox::Yes) {
|
||||
ConfigHandler().setDefaults();
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(
|
||||
this, tr("Confirm Reset"),
|
||||
tr("Are you sure you want to reset the configuration?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply == QMessageBox::Yes) {
|
||||
ConfigHandler().setDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,31 +151,31 @@ void GeneneralConf::initShowTrayIcon() {
|
||||
m_layout->addWidget(m_showTray);
|
||||
|
||||
connect(m_showTray, &QCheckBox::clicked, this,
|
||||
&GeneneralConf::showTrayIconChanged);
|
||||
&GeneneralConf::showTrayIconChanged);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GeneneralConf::initConfingButtons() {
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
m_layout->addStretch();
|
||||
QGroupBox *box = new QGroupBox(tr("Configuration File"));
|
||||
box->setFlat(true);
|
||||
box->setLayout(buttonLayout);
|
||||
m_layout->addWidget(box);
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
m_layout->addStretch();
|
||||
QGroupBox *box = new QGroupBox(tr("Configuration File"));
|
||||
box->setFlat(true);
|
||||
box->setLayout(buttonLayout);
|
||||
m_layout->addWidget(box);
|
||||
|
||||
m_exportButton = new QPushButton(tr("Export"));
|
||||
buttonLayout->addWidget(m_exportButton);
|
||||
connect(m_exportButton, &QPushButton::clicked, this,
|
||||
m_exportButton = new QPushButton(tr("Export"));
|
||||
buttonLayout->addWidget(m_exportButton);
|
||||
connect(m_exportButton, &QPushButton::clicked, this,
|
||||
&GeneneralConf::exportFileConfiguration);
|
||||
|
||||
m_importButton = new QPushButton(tr("Import"));
|
||||
buttonLayout->addWidget(m_importButton);
|
||||
connect(m_importButton, &QPushButton::clicked, this,
|
||||
&GeneneralConf::importConfiguration);
|
||||
m_importButton = new QPushButton(tr("Import"));
|
||||
buttonLayout->addWidget(m_importButton);
|
||||
connect(m_importButton, &QPushButton::clicked, this,
|
||||
&GeneneralConf::importConfiguration);
|
||||
|
||||
m_resetButton = new QPushButton(tr("Reset"));
|
||||
buttonLayout->addWidget(m_resetButton);
|
||||
connect(m_resetButton, &QPushButton::clicked, this,
|
||||
m_resetButton = new QPushButton(tr("Reset"));
|
||||
buttonLayout->addWidget(m_resetButton);
|
||||
connect(m_resetButton, &QPushButton::clicked, this,
|
||||
&GeneneralConf::resetConfiguration);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,10 +274,10 @@ int main(int argc, char *argv[]) {
|
||||
QString newFilename(parser.value(filenameOption));
|
||||
config.setFilenamePattern(newFilename);
|
||||
FileNameHandler fh;
|
||||
QTextStream(stdout)
|
||||
<< QStringLiteral("The new pattern is '%1'\n"
|
||||
"Parsed pattern example: %2\n").arg(newFilename)
|
||||
.arg(fh.parsedPattern());
|
||||
QTextStream(stdout)
|
||||
<< QStringLiteral("The new pattern is '%1'\n"
|
||||
"Parsed pattern example: %2\n").arg(newFilename)
|
||||
.arg(fh.parsedPattern());
|
||||
}
|
||||
if (tray) {
|
||||
QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot",
|
||||
|
||||
@@ -25,128 +25,128 @@
|
||||
DesktopFileParser::DesktopFileParser() {
|
||||
QString locale = QLocale().name();
|
||||
QString localeShort = QLocale().name().left(2);
|
||||
m_localeName = QStringLiteral("Name[%1]").arg(locale);
|
||||
m_localeDescription = QStringLiteral("Comment[%1]").arg(locale);
|
||||
m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort);
|
||||
m_localeDescriptionShort = QStringLiteral("Comment[%1]")
|
||||
m_localeName = QStringLiteral("Name[%1]").arg(locale);
|
||||
m_localeDescription = QStringLiteral("Comment[%1]").arg(locale);
|
||||
m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort);
|
||||
m_localeDescriptionShort = QStringLiteral("Comment[%1]")
|
||||
.arg(localeShort);
|
||||
m_defaultIcon = QIcon::fromTheme("application-x-executable");
|
||||
m_defaultIcon = QIcon::fromTheme("application-x-executable");
|
||||
}
|
||||
|
||||
DesktopAppData DesktopFileParser::parseDesktopFile(
|
||||
const QString &fileName, bool &ok) const
|
||||
const QString &fileName, bool &ok) const
|
||||
{
|
||||
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;
|
||||
QTextStream in(&file);
|
||||
// enter the desktop entry definition
|
||||
while (!in.atEnd() && in.readLine() != "[Desktop Entry]") {
|
||||
}
|
||||
// start parsing
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith("Icon")) {
|
||||
res.icon = QIcon::fromTheme(
|
||||
line.mid(line.indexOf("=")+1).trimmed(),
|
||||
m_defaultIcon);
|
||||
}
|
||||
else if (!nameLocaleSet && line.startsWith("Name")) {
|
||||
if (line.startsWith(m_localeName) ||
|
||||
line.startsWith(m_localeNameShort))
|
||||
{
|
||||
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_localeDescription) ||
|
||||
line.startsWith(m_localeDescriptionShort))
|
||||
{
|
||||
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("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")) {
|
||||
res.categories = line.mid(line.indexOf("=")+1).split(";");
|
||||
}
|
||||
else if (line == "NoDisplay=true") {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
else if (line == "Terminal=true") {
|
||||
res.showInTerminal = true;
|
||||
}
|
||||
// ignore the other entries
|
||||
else if (line.startsWith("[")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (res.exec.isEmpty() || res.name.isEmpty() || !isApplication) {
|
||||
ok = false;
|
||||
}
|
||||
return res;
|
||||
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;
|
||||
QTextStream in(&file);
|
||||
// enter the desktop entry definition
|
||||
while (!in.atEnd() && in.readLine() != "[Desktop Entry]") {
|
||||
}
|
||||
// start parsing
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith("Icon")) {
|
||||
res.icon = QIcon::fromTheme(
|
||||
line.mid(line.indexOf("=")+1).trimmed(),
|
||||
m_defaultIcon);
|
||||
}
|
||||
else if (!nameLocaleSet && line.startsWith("Name")) {
|
||||
if (line.startsWith(m_localeName) ||
|
||||
line.startsWith(m_localeNameShort))
|
||||
{
|
||||
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_localeDescription) ||
|
||||
line.startsWith(m_localeDescriptionShort))
|
||||
{
|
||||
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("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")) {
|
||||
res.categories = line.mid(line.indexOf("=")+1).split(";");
|
||||
}
|
||||
else if (line == "NoDisplay=true") {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
else if (line == "Terminal=true") {
|
||||
res.showInTerminal = true;
|
||||
}
|
||||
// ignore the other entries
|
||||
else if (line.startsWith("[")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (res.exec.isEmpty() || res.name.isEmpty() || !isApplication) {
|
||||
ok = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int DesktopFileParser::processDirectory(const QDir &dir) {
|
||||
QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
bool ok;
|
||||
int length = m_appList.length();
|
||||
for (QString file: entries){
|
||||
DesktopAppData app = parseDesktopFile(dir.absoluteFilePath(file), ok);
|
||||
if (ok) {
|
||||
m_appList.append(app);
|
||||
}
|
||||
}
|
||||
return m_appList.length() - length;
|
||||
QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
bool ok;
|
||||
int length = m_appList.length();
|
||||
for (QString file: entries){
|
||||
DesktopAppData app = parseDesktopFile(dir.absoluteFilePath(file), ok);
|
||||
if (ok) {
|
||||
m_appList.append(app);
|
||||
}
|
||||
}
|
||||
return m_appList.length() - length;
|
||||
}
|
||||
|
||||
QList<DesktopAppData> DesktopFileParser::getAppsByCategory(const QString &category) {
|
||||
QList<DesktopAppData> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
QList<DesktopAppData> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QMap<QString, QList<DesktopAppData>> DesktopFileParser::getAppsByCategory(
|
||||
const QStringList &categories)
|
||||
const QStringList &categories)
|
||||
{
|
||||
QMap<QString, QList<DesktopAppData>> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
for (const QString &category: categories) {
|
||||
if (app.categories.contains(category)) {
|
||||
res[category].append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
QMap<QString, QList<DesktopAppData>> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
for (const QString &category: categories) {
|
||||
if (app.categories.contains(category)) {
|
||||
res[category].append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -27,40 +27,40 @@ class QString;
|
||||
class QTextStream;
|
||||
|
||||
struct DesktopAppData {
|
||||
DesktopAppData() : showInTerminal() {}
|
||||
DesktopAppData() : showInTerminal() {}
|
||||
|
||||
DesktopAppData(
|
||||
QString name,
|
||||
QString description,
|
||||
QString exec,
|
||||
QIcon icon) :
|
||||
name(name),
|
||||
description(description),
|
||||
exec(exec),
|
||||
icon(icon),
|
||||
showInTerminal(false)
|
||||
{}
|
||||
DesktopAppData(
|
||||
QString name,
|
||||
QString description,
|
||||
QString exec,
|
||||
QIcon icon) :
|
||||
name(name),
|
||||
description(description),
|
||||
exec(exec),
|
||||
icon(icon),
|
||||
showInTerminal(false)
|
||||
{}
|
||||
|
||||
bool operator==(const DesktopAppData &other) const {
|
||||
return name == other.name;
|
||||
}
|
||||
bool operator==(const DesktopAppData &other) const {
|
||||
return name == other.name;
|
||||
}
|
||||
|
||||
QString name;
|
||||
QString description;
|
||||
QString exec;
|
||||
QStringList categories;
|
||||
QIcon icon;
|
||||
bool showInTerminal;
|
||||
QStringList categories;
|
||||
QIcon icon;
|
||||
bool showInTerminal;
|
||||
};
|
||||
|
||||
struct DesktopFileParser {
|
||||
DesktopFileParser();
|
||||
DesktopAppData parseDesktopFile(const QString &fileName, bool &ok) const;
|
||||
int processDirectory(const QDir &dir);
|
||||
DesktopFileParser();
|
||||
DesktopAppData parseDesktopFile(const QString &fileName, bool &ok) const;
|
||||
int processDirectory(const QDir &dir);
|
||||
|
||||
QList<DesktopAppData> getAppsByCategory(const QString &category);
|
||||
QMap<QString, QList<DesktopAppData>> getAppsByCategory(
|
||||
const QStringList &categories);
|
||||
QList<DesktopAppData> getAppsByCategory(const QString &category);
|
||||
QMap<QString, QList<DesktopAppData>> getAppsByCategory(
|
||||
const QStringList &categories);
|
||||
|
||||
private:
|
||||
QString m_localeName;
|
||||
@@ -68,8 +68,8 @@ private:
|
||||
QString m_localeNameShort;
|
||||
QString m_localeDescriptionShort;
|
||||
|
||||
QIcon m_defaultIcon;
|
||||
QList<DesktopAppData> m_appList;
|
||||
QIcon m_defaultIcon;
|
||||
QList<DesktopAppData> m_appList;
|
||||
};
|
||||
|
||||
#endif // DESKTOPFILEPARSE_H
|
||||
|
||||
@@ -38,30 +38,30 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) {
|
||||
#ifdef Q_OS_LINUX
|
||||
if(m_info.waylandDectected()) {
|
||||
QPixmap res;
|
||||
// handle screenshot based on DE
|
||||
// handle screenshot based on DE
|
||||
switch (m_info.windowManager()) {
|
||||
case m_info.GNOME: {
|
||||
case m_info.GNOME: {
|
||||
// https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/data/org.gnome.Shell.Screenshot.xml
|
||||
QString path = FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
QDBusInterface gnomeInterface(QStringLiteral("org.gnome.Shell"),
|
||||
QStringLiteral("/org/gnome/Shell/Screenshot"),
|
||||
QStringLiteral("org.gnome.Shell.Screenshot"));
|
||||
QDBusReply<bool> reply = gnomeInterface.call("Screenshot", false, false, path);
|
||||
if (reply.value()) {
|
||||
res = QPixmap(path);
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
QDBusInterface gnomeInterface(QStringLiteral("org.gnome.Shell"),
|
||||
QStringLiteral("/org/gnome/Shell/Screenshot"),
|
||||
QStringLiteral("org.gnome.Shell.Screenshot"));
|
||||
QDBusReply<bool> reply = gnomeInterface.call("Screenshot", false, false, path);
|
||||
if (reply.value()) {
|
||||
res = QPixmap(path);
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
} case m_info.KDE: {
|
||||
} case m_info.KDE: {
|
||||
// https://github.com/KDE/spectacle/blob/517a7baf46a4ca0a45f32fd3f2b1b7210b180134/src/PlatformBackends/KWinWaylandImageGrabber.cpp#L145
|
||||
QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Screenshot"),
|
||||
QStringLiteral("org.kde.kwin.Screenshot"));
|
||||
QDBusReply<QString> reply = kwinInterface.call("screenshotFullscreen");
|
||||
res = QPixmap(reply.value());
|
||||
break;
|
||||
} default:
|
||||
QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Screenshot"),
|
||||
QStringLiteral("org.kde.kwin.Screenshot"));
|
||||
QDBusReply<QString> reply = kwinInterface.call("screenshotFullscreen");
|
||||
res = QPixmap(reply.value());
|
||||
break;
|
||||
} default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
SystemNotification::SystemNotification(QObject *parent) : QObject(parent) {
|
||||
m_interface = new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
m_interface = new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user