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:
@@ -0,0 +1,141 @@
|
||||
#include "QtHistoryList.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include "utility/messaging/type/MessageToUndoRedoPosition.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "data/search/SearchMatch.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
QtHistoryItem::QtHistoryItem(const SearchMatch& match, size_t index, bool isCurrent)
|
||||
: index(index)
|
||||
{
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
std::string name = utility::elide(match.nodeType == Node::NODE_FILE ? match.text : match.name, utility::ELIDE_RIGHT, 100);
|
||||
|
||||
m_name = new QLabel(name.c_str(), this);
|
||||
m_name->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
m_name->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_name->setObjectName(isCurrent ? "history_item_current" : "history_item");
|
||||
m_name->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
layout->addWidget(m_name);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
std::string searchTextColor = scheme->getColor("search/popup/text");
|
||||
|
||||
std::string color;
|
||||
std::string hoverColor;
|
||||
std::string textColor = searchTextColor;
|
||||
std::string textHoverColor = searchTextColor;
|
||||
|
||||
if (match.searchType == SearchMatch::SEARCH_TOKEN)
|
||||
{
|
||||
color = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), false).fill;
|
||||
hoverColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), true).fill;
|
||||
textColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), false).text;
|
||||
textHoverColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), true).text;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string typeName = match.getSearchTypeName();
|
||||
|
||||
color = scheme->getSearchTypeColor(typeName, "fill");
|
||||
hoverColor = scheme->getSearchTypeColor(typeName, "fill", "hover");
|
||||
textColor = scheme->getSearchTypeColor(typeName, "text");
|
||||
textHoverColor = scheme->getSearchTypeColor(typeName, "text", "hover");;
|
||||
}
|
||||
|
||||
std::stringstream css;
|
||||
css << "QLabel { background-color:" << color << "; color:" << textColor << ";} ";
|
||||
|
||||
if (!isCurrent)
|
||||
{
|
||||
css << "QLabel:hover { background-color:" << hoverColor << "; color:" << textHoverColor << ";} ";
|
||||
}
|
||||
|
||||
m_name->setStyleSheet(css.str().c_str());
|
||||
|
||||
if (isCurrent)
|
||||
{
|
||||
QSize size = getSizeHint();
|
||||
|
||||
QtDeviceScaledPixmap pixmap(QString::fromStdString(ResourcePaths::getGuiPath().str() + "history_list/images/arrow.png"));
|
||||
pixmap.scaleToHeight(size.height() / 3);
|
||||
|
||||
QLabel* arrow = new QLabel(this);
|
||||
arrow->setPixmap(utility::colorizePixmap(pixmap.pixmap(), QColor(scheme->getColor("search/popup/text").c_str())));
|
||||
arrow->setGeometry(size.height() / 3, size.height() / 3, size.height() / 3, size.height() / 3);
|
||||
arrow->show();
|
||||
}
|
||||
}
|
||||
|
||||
QSize QtHistoryItem::getSizeHint() const
|
||||
{
|
||||
return QSize(m_name->fontMetrics().width(m_name->text()) + 40, m_name->fontMetrics().height() + 8);
|
||||
}
|
||||
|
||||
|
||||
QtHistoryList::QtHistoryList(const std::vector<SearchMatch>& history, size_t currentIndex)
|
||||
: m_currentIndex(currentIndex)
|
||||
{
|
||||
setObjectName("history_list");
|
||||
setWindowFlags(Qt::Popup);
|
||||
|
||||
for (size_t i = 0; i < history.size(); i++)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(this);
|
||||
QtHistoryItem* line = new QtHistoryItem(history[i], i, i == currentIndex);
|
||||
item->setSizeHint(line->getSizeHint());
|
||||
setItemWidget(item, line);
|
||||
}
|
||||
|
||||
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("history_list/history_list.css"))).c_str());
|
||||
|
||||
connect(this, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
|
||||
}
|
||||
|
||||
void QtHistoryList::showPopup(QPoint pos)
|
||||
{
|
||||
QSize size(50, 1);
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
QtHistoryItem* it = dynamic_cast<QtHistoryItem*>(itemWidget(item(i)));
|
||||
QSize itemSize = it->getSizeHint();
|
||||
if (itemSize.width() > size.width())
|
||||
{
|
||||
size.setWidth(itemSize.width());
|
||||
}
|
||||
|
||||
size.setHeight(size.height() + item(i)->sizeHint().height());
|
||||
}
|
||||
|
||||
setGeometry(pos.x(), pos.y(), size.width(), size.height());
|
||||
show();
|
||||
}
|
||||
|
||||
void QtHistoryList::onItemClicked(QListWidgetItem *item)
|
||||
{
|
||||
QtHistoryItem* historyItem = dynamic_cast<QtHistoryItem*>(itemWidget(item));
|
||||
if (historyItem)
|
||||
{
|
||||
if (historyItem->index != m_currentIndex)
|
||||
{
|
||||
MessageToUndoRedoPosition(historyItem->index).dispatch();
|
||||
}
|
||||
close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user