Added context menu for calculation results, don't create now label on every result

This commit is contained in:
Albert S. 2018-07-04 17:09:21 +02:00
parent fe26454f85
commit bcd38cca62
2 changed files with 27 additions and 12 deletions

View File

@ -40,6 +40,16 @@ Window::Window(const QVector<EntryConfig> &configs, const QString &dbpath)
searchThread.start();
initTreeWidgets();
this->lineEdit->installEventFilter(this);
QFont font;
font.setPointSize(48);
font.setBold(true);
calculationResultLabel.setFont(font);
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
calculationResultLabel.setAlignment(Qt::AlignCenter);
calculationResultLabel.setWordWrap(true);
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this, &Window::showCalculationResultContextMenu);
}
@ -71,7 +81,7 @@ void Window::showSearchResultsContextMenu(const QPoint &point)
{
return;
}
QMenu menu("Test", this);
QMenu menu("SearchResult", this);
menu.addAction("Copy filename to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(0));});
menu.addAction("Copy full path to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(1)); });
menu.addAction("Open containing folder", [&] {
@ -83,6 +93,14 @@ void Window::showSearchResultsContextMenu(const QPoint &point)
menu.exec(QCursor::pos());
}
void Window::showCalculationResultContextMenu(const QPoint &point)
{
QMenu menu("Calc", this);
menu.addAction("Copy result", [&] { QGuiApplication::clipboard()->setText(currentCalculationResult); });
menu.addAction("Copy full content", [&] { QGuiApplication::clipboard()->setText(calculationResultLabel.text()); });
menu.exec(QCursor::pos());
}
QVector<EntryPushButton*> Window::generateEntryButtons(const QVector<EntryConfig> &configs)
{
QVector<EntryPushButton*> result;
@ -182,17 +200,10 @@ void Window::clearGrid()
void Window::addCalcResult(const QString &expression)
{
clearGrid();
QString calculationresult = calcEngine.evaluate(expression);
QLabel *lbl = new QLabel();
lbl->setText(expression + ": " + calculationresult);
lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
lbl->setAlignment(Qt::AlignCenter);
lbl->setWordWrap(true);
QFont font;
font.setPointSize(48);
font.setBold(true);
lbl->setFont(font);
grid->addWidget(lbl, 0, 0);
currentCalculationResult = calcEngine.evaluate(expression);
calculationResultLabel.setText(expression + ": " + currentCalculationResult);
calculationResultLabel.setVisible(true);
grid->addWidget(&calculationResultLabel, 0, 0);
}
//main problem here there is no easy event compression (clearing emit queue and only processing the last one)

View File

@ -29,6 +29,7 @@
#include <QVector>
#include <QThread>
#include <QTreeWidget>
#include <QLabel>
#include "config.h"
#include "entrypushbutton.h"
#include "calculationengine.h"
@ -41,10 +42,12 @@ class Window : public QWidget
QThread searchThread;
SearchWorker *searchWorker;
CalculationEngine calcEngine;
QString calculationresult;
QVector<EntryPushButton*> userEntryButtons;
QVector<EntryPushButton*> systemEntryButtons;
QVector<EntryPushButton *> buttonsInGrid;
QTreeWidget treeFileSearchResults;
QLabel caluclationResultLabel;
QString queuedFileSearch;
QString queuedContentSearch;
void createGui();
@ -70,6 +73,7 @@ class Window : public QWidget
void handleCancelledSearch();
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
void showSearchResultsContextMenu(const QPoint &point);
void showCalculationResultContextMenu(const QPoint &point);
signals:
void beginFileSearch(const QString &query);
void beginContentSearch(const QString &query);