ui: Added history of last active symbols to UI and menu (issue 151)
* holding down back or forward button shows list of current back-forward stack * added narrow button between back and forward to show the list * added History menu * moved back and forward actions to History menu * show chronological list of recently active symbols in History menu bug id = 151 fortune cookie message = Dein Geschäft wird gut laufen und expandieren.
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTimer>
|
||||
|
||||
#include "utility/messaging/type/MessageUndo.h"
|
||||
#include "utility/messaging/type/MessageRedo.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/element/QtHistoryList.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
QtUndoRedo::QtUndoRedo()
|
||||
: m_pressed(false)
|
||||
{
|
||||
setObjectName("undo_redo_bar");
|
||||
|
||||
@@ -21,11 +24,17 @@ QtUndoRedo::QtUndoRedo()
|
||||
m_undoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_undoButton->setEnabled(false);
|
||||
|
||||
m_historyButton = new QPushButton(this);
|
||||
m_historyButton->setObjectName("history_button");
|
||||
m_historyButton->setToolTip("history");
|
||||
m_historyButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_historyButton->setEnabled(false);
|
||||
|
||||
m_redoButton = new QPushButton(this);
|
||||
m_redoButton->setObjectName("redo_button");
|
||||
m_redoButton->setToolTip("forward");
|
||||
m_redoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_redoButton->setEnabled(false);
|
||||
m_redoButton->setEnabled(false);
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
@@ -33,47 +42,97 @@ QtUndoRedo::QtUndoRedo()
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_undoButton);
|
||||
layout->addWidget(m_historyButton);
|
||||
layout->addWidget(m_redoButton);
|
||||
|
||||
connect(m_undoButton, SIGNAL(clicked()), this, SLOT(undo()));
|
||||
connect(m_redoButton, SIGNAL(clicked()), this, SLOT(redo()));
|
||||
connect(m_undoButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
|
||||
connect(m_redoButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
|
||||
connect(m_historyButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
|
||||
|
||||
refreshStyle();
|
||||
connect(m_undoButton, SIGNAL(released()), this, SLOT(undoReleased()));
|
||||
connect(m_redoButton, SIGNAL(released()), this, SLOT(redoReleased()));
|
||||
connect(m_historyButton, SIGNAL(released()), this, SLOT(showHistory()));
|
||||
|
||||
refreshStyle();
|
||||
}
|
||||
|
||||
QtUndoRedo::~QtUndoRedo()
|
||||
{
|
||||
}
|
||||
|
||||
void QtUndoRedo::undo()
|
||||
void QtUndoRedo::buttonPressed()
|
||||
{
|
||||
MessageUndo().dispatch();
|
||||
m_pressed = true;
|
||||
QTimer::singleShot(250, this, SLOT(showHistory()));
|
||||
m_historyButton->setAttribute(Qt::WA_UnderMouse, false);
|
||||
}
|
||||
|
||||
void QtUndoRedo::redo()
|
||||
void QtUndoRedo::undoReleased()
|
||||
{
|
||||
MessageRedo().dispatch();
|
||||
if (m_pressed)
|
||||
{
|
||||
m_pressed = false;
|
||||
MessageUndo().dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtUndoRedo::redoReleased()
|
||||
{
|
||||
if (m_pressed)
|
||||
{
|
||||
m_pressed = false;
|
||||
MessageRedo().dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtUndoRedo::showHistory()
|
||||
{
|
||||
if (m_pressed)
|
||||
{
|
||||
m_pressed = false;
|
||||
|
||||
m_undoButton->setDown(false);
|
||||
m_redoButton->setDown(false);
|
||||
m_historyButton->setDown(false);
|
||||
|
||||
m_undoButton->setAttribute(Qt::WA_UnderMouse, false);
|
||||
m_redoButton->setAttribute(Qt::WA_UnderMouse, false);
|
||||
m_historyButton->setAttribute(Qt::WA_UnderMouse, false);
|
||||
|
||||
QtHistoryList* list = 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));
|
||||
}
|
||||
}
|
||||
|
||||
void QtUndoRedo::setUndoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_undoButton->setEnabled(enabled);
|
||||
m_undoButton->setEnabled(enabled);
|
||||
QtContextMenu::getInstance()->enableUndo(enabled);
|
||||
|
||||
}
|
||||
|
||||
void QtUndoRedo::setRedoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_redoButton->setEnabled(enabled);
|
||||
m_redoButton->setEnabled(enabled);
|
||||
QtContextMenu::getInstance()->enableRedo(enabled);
|
||||
}
|
||||
|
||||
void QtUndoRedo::updateHistory(const std::vector<SearchMatch>& searchMatches, size_t currentIndex)
|
||||
{
|
||||
m_history = searchMatches;
|
||||
m_currentIndex = currentIndex;
|
||||
m_historyButton->setEnabled(m_history.size() > 1);
|
||||
}
|
||||
|
||||
void QtUndoRedo::refreshStyle()
|
||||
{
|
||||
float height = std::max(ApplicationSettings::getInstance()->getFontSize() + 16, 30);
|
||||
|
||||
m_undoButton->setFixedHeight(height);
|
||||
m_redoButton->setFixedHeight(height);
|
||||
m_historyButton->setFixedHeight(height);
|
||||
|
||||
m_undoButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath().str() + "undoredo_view/images/arrow_left.png",
|
||||
@@ -84,4 +143,9 @@ void QtUndoRedo::refreshStyle()
|
||||
ResourcePaths::getGuiPath().str() + "undoredo_view/images/arrow_right.png",
|
||||
"search/button"
|
||||
));
|
||||
|
||||
m_historyButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath().str() + "undoredo_view/images/history.png",
|
||||
"search/button"
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user