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

Šī revīzija ir iekļauta:
Albert S. 2018-07-04 17:09:21 +02:00
vecāks fe26454f85
revīzija bcd38cca62
2 mainīti faili ar 27 papildinājumiem un 12 dzēšanām

Parādīt failu

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

Parādīt failu

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