diff --git a/src/core/controller.cpp b/src/core/controller.cpp index f11c3f8f..fe0c713b 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -298,6 +298,7 @@ void Controller::updateConfigComponents() void Controller::showRecentScreenshots() { HistoryWidget* pHistory = new HistoryWidget(); + pHistory->loadHistory(); pHistory->exec(); } diff --git a/src/core/globalshortcutfilter.cpp b/src/core/globalshortcutfilter.cpp index 57f198ba..a956a1ae 100644 --- a/src/core/globalshortcutfilter.cpp +++ b/src/core/globalshortcutfilter.cpp @@ -58,6 +58,7 @@ bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType, if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) { if (m_history == nullptr) { m_history = new HistoryWidget(); + m_history->loadHistory(); } m_history->show(); } diff --git a/src/widgets/historywidget.cpp b/src/widgets/historywidget.cpp index 25df2ccd..f35c382a 100644 --- a/src/widgets/historywidget.cpp +++ b/src/widgets/historywidget.cpp @@ -41,8 +41,6 @@ HistoryWidget::HistoryWidget(QWidget* parent) QWidget* widget = new QWidget(); scrollArea->setWidget(widget); widget->setLayout(m_pVBox); - - loadHistory(); } HistoryWidget::~HistoryWidget() @@ -50,8 +48,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,