diff --git a/src/config/shortcutswidget.cpp b/src/config/shortcutswidget.cpp index afd1aabc..b11e9afa 100644 --- a/src/config/shortcutswidget.cpp +++ b/src/config/shortcutswidget.cpp @@ -33,8 +33,6 @@ #include #endif -#include - ShortcutsWidget::ShortcutsWidget(QWidget* parent) : QWidget(parent) { diff --git a/src/core/controller.cpp b/src/core/controller.cpp index f11c3f8f..2666d1e8 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -44,6 +44,8 @@ Controller::Controller() : m_captureWindow(nullptr) { + m_history = nullptr; + qApp->setQuitOnLastWindowClosed(false); // set default shortcusts if not set yet @@ -68,6 +70,11 @@ Controller::Controller() qApp->setStyleSheet(StyleSheet); } +Controller::~Controller() +{ + delete m_history; +} + Controller* Controller::getInstance() { static Controller c; @@ -297,8 +304,11 @@ void Controller::updateConfigComponents() void Controller::showRecentScreenshots() { - HistoryWidget* pHistory = new HistoryWidget(); - pHistory->exec(); + if (nullptr == m_history) { + m_history = new HistoryWidget(); + } + m_history->loadHistory(); + m_history->show(); } void Controller::startFullscreenCapture(const uint id) diff --git a/src/core/controller.h b/src/core/controller.h index 2308abcc..0cb9ee24 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -30,6 +30,7 @@ class ConfigWindow; class InfoWindow; class QSystemTrayIcon; class CaptureLauncher; +class HistoryWidget; using lambda = std::function; class Controller : public QObject @@ -40,6 +41,7 @@ public: static Controller* getInstance(); Controller(const Controller&) = delete; + ~Controller(); void operator=(const Controller&) = delete; void enableExports(); @@ -87,4 +89,6 @@ private: QPointer m_launcherWindow; QPointer m_configWindow; QPointer m_trayIcon; + + HistoryWidget* m_history; }; diff --git a/src/core/globalshortcutfilter.cpp b/src/core/globalshortcutfilter.cpp index 57f198ba..0a6c2ebe 100644 --- a/src/core/globalshortcutfilter.cpp +++ b/src/core/globalshortcutfilter.cpp @@ -17,14 +17,11 @@ #include "globalshortcutfilter.h" #include "src/core/controller.h" -#include "src/widgets/historywidget.h" #include GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent) : QObject(parent) { - m_history = nullptr; - // Forced Print Screen if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) { // ok - capture screen @@ -35,11 +32,6 @@ GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent) } } -GlobalShortcutFilter::~GlobalShortcutFilter() -{ - delete m_history; -} - bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType, void* message, long* result) @@ -56,10 +48,7 @@ bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType, // Show screenshots history if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) { - if (m_history == nullptr) { - m_history = new HistoryWidget(); - } - m_history->show(); + Controller::getInstance()->showRecentScreenshots(); } // Capture screen diff --git a/src/core/globalshortcutfilter.h b/src/core/globalshortcutfilter.h index 83137c84..3ed8f10d 100644 --- a/src/core/globalshortcutfilter.h +++ b/src/core/globalshortcutfilter.h @@ -20,8 +20,6 @@ #include #include -class HistoryWidget; - class GlobalShortcutFilter : public QObject , public QAbstractNativeEventFilter @@ -29,7 +27,6 @@ class GlobalShortcutFilter Q_OBJECT public: explicit GlobalShortcutFilter(QObject* parent = nullptr); - ~GlobalShortcutFilter(); bool nativeEventFilter(const QByteArray& eventType, void* message, @@ -43,5 +40,4 @@ private: quint32 nativeKeycode(Qt::Key key); bool registerShortcut(quint32 nativeKey, quint32 nativeMods); bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods); - HistoryWidget* m_history; }; diff --git a/src/utils/configshortcuts.cpp b/src/utils/configshortcuts.cpp index 7f957e36..8bc28d56 100644 --- a/src/utils/configshortcuts.cpp +++ b/src/utils/configshortcuts.cpp @@ -1,11 +1,9 @@ #include "configshortcuts.h" #include "src/tools/capturetool.h" -#include +#include ConfigShortcuts::ConfigShortcuts() {} -// QVector getButtons() - const QVector& ConfigShortcuts::captureShortcutsDefault( const QVector& buttons) { diff --git a/src/widgets/historywidget.cpp b/src/widgets/historywidget.cpp index 25df2ccd..4a80eddf 100644 --- a/src/widgets/historywidget.cpp +++ b/src/widgets/historywidget.cpp @@ -20,8 +20,6 @@ #include #include -#include - HistoryWidget::HistoryWidget(QWidget* parent) : QDialog(parent) { @@ -41,8 +39,6 @@ HistoryWidget::HistoryWidget(QWidget* parent) QWidget* widget = new QWidget(); scrollArea->setWidget(widget); widget->setLayout(m_pVBox); - - loadHistory(); } HistoryWidget::~HistoryWidget() @@ -50,8 +46,26 @@ HistoryWidget::~HistoryWidget() delete m_notification; } +void HistoryWidget::clearHistoryLayout(QLayout* layout) +{ + QLayoutItem* child; + while (layout->count() != 0) { + child = layout->takeAt(0); + if (child->layout() != 0) { + clearHistoryLayout(child->layout()); + } else if (child->widget() != 0) { + delete child->widget(); + } + + delete child; + } +} + void HistoryWidget::loadHistory() { + // clear old history if exists + clearHistoryLayout(m_pVBox); + // read history files History history = History(); QList historyFiles = history.history(); diff --git a/src/widgets/historywidget.h b/src/widgets/historywidget.h index abd4e0b9..b713f666 100644 --- a/src/widgets/historywidget.h +++ b/src/widgets/historywidget.h @@ -21,10 +21,11 @@ public: explicit HistoryWidget(QWidget* parent = nullptr); ~HistoryWidget(); -signals: + void loadHistory(); private: - void loadHistory(); + void clearHistoryLayout(QLayout* layout); + void addLine(const QString&, const QString&); void setEmptyMessage(); void removeItem(QLayout* pl, diff --git a/src/widgets/orientablepushbutton.cpp b/src/widgets/orientablepushbutton.cpp index f85b66d5..68cfdcc5 100644 --- a/src/widgets/orientablepushbutton.cpp +++ b/src/widgets/orientablepushbutton.cpp @@ -18,7 +18,6 @@ // Based on https://stackoverflow.com/a/53135675/964478 #include "orientablepushbutton.h" -#include #include #include #include