From bcd38cca6299d7a36de7f23e1bf2e57ed64e9752 Mon Sep 17 00:00:00 2001 From: Albert S Date: Wed, 4 Jul 2018 17:09:21 +0200 Subject: [PATCH] Added context menu for calculation results, don't create now label on every result --- window.cpp | 35 +++++++++++++++++++++++------------ window.h | 4 ++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/window.cpp b/window.cpp index 3fc50b0..c949fc5 100644 --- a/window.cpp +++ b/window.cpp @@ -40,6 +40,16 @@ Window::Window(const QVector &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 Window::generateEntryButtons(const QVector &configs) { QVector 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) diff --git a/window.h b/window.h index 963b3e6..c809b90 100644 --- a/window.h +++ b/window.h @@ -29,6 +29,7 @@ #include #include #include +#include #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 userEntryButtons; QVector systemEntryButtons; QVector 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);