ui: Fixed history dropdown click opened again when clicking on history button on Windows

This commit is contained in:
Eberhard Graether
2017-12-15 15:38:43 +01:00
parent 76f5ee1dc0
commit 618ed72241
7 changed files with 52 additions and 10 deletions
+5 -5
View File
@@ -51,12 +51,12 @@ std::string TimeStamp::getDDMMYYYYString() const
size_t TimeStamp::deltaMS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_milliseconds();
return abs((m_time - other.m_time).total_milliseconds());
}
size_t TimeStamp::deltaS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_seconds();
return abs((m_time - other.m_time).total_seconds());
}
bool TimeStamp::isSameDay(const TimeStamp& other) const
@@ -74,11 +74,11 @@ bool TimeStamp::isSameDay(const TimeStamp& other) const
size_t TimeStamp::deltaDays(const TimeStamp& other) const
{
boost::gregorian::date_duration deltaDate = m_time.date() - other.m_time.date();
return size_t(std::abs(deltaDate.days()));
return abs(deltaDate.days());
}
long TimeStamp::deltaHours(const TimeStamp& other) const
size_t TimeStamp::deltaHours(const TimeStamp& other) const
{
boost::posix_time::time_duration delta = m_time - other.m_time;
return delta.total_seconds() / 3600;
return abs(delta.total_seconds() / 3600);
}
+1 -1
View File
@@ -31,7 +31,7 @@ public:
// days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
size_t deltaDays(const TimeStamp& other) const;
long deltaHours(const TimeStamp& other) const;
size_t deltaHours(const TimeStamp& other) const;
private:
boost::posix_time::ptime m_time;
+1 -1
View File
@@ -256,7 +256,7 @@ std::string QtBookmark::getDateString() const
{
result = "today";
}
else if (creationDate.deltaDays(now) == 1) // yesterday
else if (now.deltaDays(creationDate) == 1) // yesterday
{
result = "yesterday";
}
+5
View File
@@ -152,6 +152,11 @@ void QtHistoryList::showPopup(QPoint pos)
show();
}
void QtHistoryList::closeEvent(QCloseEvent* event)
{
emit closed();
}
void QtHistoryList::onItemClicked(QListWidgetItem *item)
{
QtHistoryItem* historyItem = dynamic_cast<QtHistoryItem*>(m_list->itemWidget(item));
+6 -1
View File
@@ -32,17 +32,22 @@ private:
};
class QtHistoryList
: public QWidget
{
Q_OBJECT
signals:
void closed();
public:
QtHistoryList(const std::vector<SearchMatch>& history, size_t currentIndex);
void showPopup(QPoint pos);
protected:
void closeEvent(QCloseEvent* event);
private slots:
void onItemClicked(QListWidgetItem *item);
+28 -2
View File
@@ -15,6 +15,8 @@
QtUndoRedo::QtUndoRedo()
: m_pressed(false)
, m_historyList(nullptr)
, m_historyHiddenAt(TimeStamp::now())
{
setObjectName("undo_redo_bar");
@@ -62,6 +64,11 @@ QtUndoRedo::~QtUndoRedo()
void QtUndoRedo::buttonPressed()
{
if (TimeStamp::now().deltaMS(m_historyHiddenAt) < 250)
{
return;
}
m_pressed = true;
QTimer::singleShot(250, this, &QtUndoRedo::showHistory);
m_historyButton->setAttribute(Qt::WA_UnderMouse, false);
@@ -91,6 +98,12 @@ void QtUndoRedo::showHistory()
{
m_pressed = false;
if (m_historyList)
{
m_historyList->deleteLater();
m_historyList = nullptr;
}
m_undoButton->setDown(false);
m_redoButton->setDown(false);
m_historyButton->setDown(false);
@@ -99,11 +112,24 @@ void QtUndoRedo::showHistory()
m_redoButton->setAttribute(Qt::WA_UnderMouse, false);
m_historyButton->setAttribute(Qt::WA_UnderMouse, false);
QtHistoryList* list = new QtHistoryList(m_history, m_currentIndex);
m_historyList = new QtHistoryList(m_history, m_currentIndex);
QPoint pos = m_undoButton->mapToGlobal(m_undoButton->pos());
list->showPopup(QPoint(pos.x(), pos.y() + m_undoButton->size().height() + 5));
m_historyList->showPopup(QPoint(pos.x(), pos.y() + m_undoButton->size().height() + 5));
connect(m_historyList, &QtHistoryList::closed, this, &QtUndoRedo::hidHistory);
}
}
void QtUndoRedo::hidHistory()
{
if (m_historyList)
{
m_historyList->deleteLater();
m_historyList = nullptr;
m_historyHiddenAt = TimeStamp::now();
}
}
+6
View File
@@ -5,8 +5,10 @@
#include <QFrame>
#include "data/search/SearchMatch.h"
#include "utility/TimeStamp.h"
class QPushButton;
class QtHistoryList;
class QtUndoRedo
: public QFrame
@@ -31,6 +33,7 @@ private slots:
void redoReleased();
void showHistory();
void hidHistory();
private:
QPushButton* m_undoButton;
@@ -41,6 +44,9 @@ private:
size_t m_currentIndex;
bool m_pressed;
QtHistoryList* m_historyList;
TimeStamp m_historyHiddenAt;
};
#endif // QT_UNDO_REDO_H