ui: Fixes and improvements for bookmarks
* moved bookmark buttons behind search bar * suggest qualified name when creating, file name for files * fixed bug when updating bookmark category * changed comment toggle arrow * changed edit and delete icons * fixed undo for edge bookmarks * keep categories always alphabetical regardless of subsorting * keep category expansion state when opening and closing browser * removed QtBookmarkBar, moved logic into QtBookmarkView * added bookmarks Menu with shortcuts Ctrl + D: Create Bookmark Ctrl + B: Bookmark Manager
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
#include "qt/view/QtBookmarkView.h"
|
||||
|
||||
#include "qt/window/QtBookmarkBrowser.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "qt/window/QtBookmarkCreator.h"
|
||||
#include "qt/window/QtBookmarkBrowser.h"
|
||||
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "component/controller/RefreshController.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
QtBookmarkView::QtBookmarkView(ViewLayout* viewLayout)
|
||||
: BookmarkView(viewLayout)
|
||||
, m_refreshViewFunctor(std::bind(&QtBookmarkView::doRefreshView, this))
|
||||
, m_bookmarkBrowser(nullptr)
|
||||
, m_createButtonState(BookmarkView::CreateButtonState::CANNOT_CREATE)
|
||||
{
|
||||
m_widget = new QtBookmarkBar();
|
||||
setStyleSheet();
|
||||
m_widget = new QFrame();
|
||||
}
|
||||
|
||||
QtBookmarkView::~QtBookmarkView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtBookmarkView::createWidgetWrapper()
|
||||
@@ -30,33 +39,203 @@ void QtBookmarkView::createWidgetWrapper()
|
||||
|
||||
void QtBookmarkView::initView()
|
||||
{
|
||||
m_widget->setObjectName("bookmark_bar");
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
m_widget->setLayout(layout);
|
||||
|
||||
m_createBookmarkButton = new QPushButton();
|
||||
m_createBookmarkButton->setObjectName("bookmark_button");
|
||||
m_createBookmarkButton->setToolTip("create a bookmark for the active symbol");
|
||||
m_createBookmarkButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_createBookmarkButton->setEnabled(false);
|
||||
layout->addWidget(m_createBookmarkButton);
|
||||
|
||||
connect(m_createBookmarkButton, SIGNAL(clicked()), this, SLOT(createBookmarkClicked()));
|
||||
|
||||
m_showBookmarksButton = new QPushButton();
|
||||
m_showBookmarksButton->setObjectName("show_bookmark_button");
|
||||
m_showBookmarksButton->setToolTip("Show bookmarks");
|
||||
m_showBookmarksButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
m_showBookmarksButton->setEnabled(false);
|
||||
layout->addWidget(m_showBookmarksButton);
|
||||
|
||||
connect(m_showBookmarksButton, SIGNAL(clicked()), this, SLOT(showBookmarksClicked()));
|
||||
|
||||
setStyleSheet();
|
||||
refreshStyle();
|
||||
}
|
||||
|
||||
void QtBookmarkView::refreshView()
|
||||
{
|
||||
m_refreshViewFunctor();
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
setStyleSheet();
|
||||
refreshStyle();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::setCreateButtonState(const CreateButtonState& state)
|
||||
{
|
||||
m_widget->setCreateButtonState(state);
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_createButtonState = state;
|
||||
|
||||
m_createBookmarkButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/edit_bookmark_icon.png",
|
||||
"search/button"
|
||||
));
|
||||
|
||||
if (state == BookmarkView::CreateButtonState::CAN_CREATE)
|
||||
{
|
||||
m_createBookmarkButton->setEnabled(true);
|
||||
}
|
||||
else if (state == BookmarkView::CreateButtonState::CANNOT_CREATE)
|
||||
{
|
||||
m_createBookmarkButton->setEnabled(false);
|
||||
}
|
||||
else if (state == BookmarkView::CreateButtonState::ALREADY_CREATED)
|
||||
{
|
||||
m_createBookmarkButton->setEnabled(true);
|
||||
|
||||
m_createBookmarkButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_active.png",
|
||||
"search/button"
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_createBookmarkButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::enableDisplayBookmarks(bool enable)
|
||||
{
|
||||
m_widget->enableDisplayButton(enable);
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_showBookmarksButton->setEnabled(enable);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool QtBookmarkView::bookmarkBrowserIsVisible() const
|
||||
{
|
||||
return m_widget->bookmarkBrowserIsVisible();
|
||||
if (m_bookmarkBrowser != nullptr)
|
||||
{
|
||||
return m_bookmarkBrowser->isVisible();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkView::doRefreshView()
|
||||
void QtBookmarkView::createBookmarkClicked()
|
||||
{
|
||||
setStyleSheet();
|
||||
m_widget->refreshStyle();
|
||||
if (m_createButtonState == BookmarkView::CreateButtonState::CAN_CREATE)
|
||||
{
|
||||
MessageDisplayBookmarkCreator().dispatch();
|
||||
}
|
||||
else if (m_createButtonState == BookmarkView::CreateButtonState::ALREADY_CREATED)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Edit Bookmark");
|
||||
msgBox.setInformativeText("Do you want to edit or delete the bookmark for this symbol?");
|
||||
msgBox.addButton("Edit", QMessageBox::ButtonRole::YesRole);
|
||||
msgBox.addButton("Delete", QMessageBox::ButtonRole::NoRole);
|
||||
QPushButton* cancelButton = msgBox.addButton("Cancel", QMessageBox::ButtonRole::RejectRole);
|
||||
msgBox.setDefaultButton(cancelButton);
|
||||
msgBox.setIcon(QMessageBox::Icon::Question);
|
||||
int ret = msgBox.exec();
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes
|
||||
{
|
||||
MessageDisplayBookmarkCreator().dispatch();
|
||||
}
|
||||
else if (ret == 1)
|
||||
{
|
||||
MessageDeleteBookmarkForActiveTokens().dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkView::showBookmarksClicked()
|
||||
{
|
||||
MessageDisplayBookmarks().dispatch();
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
if (m_bookmarkBrowser == nullptr)
|
||||
{
|
||||
m_bookmarkBrowser = new QtBookmarkBrowser();
|
||||
m_bookmarkBrowser->setupBookmarkBrowser();
|
||||
}
|
||||
|
||||
m_bookmarkBrowser->setBookmarks(bookmarks);
|
||||
m_bookmarkBrowser->show();
|
||||
m_bookmarkBrowser->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator();
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
|
||||
std::string displayName = "";
|
||||
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
displayName += names[i];
|
||||
|
||||
if (i < names.size() - 1)
|
||||
{
|
||||
displayName += "; ";
|
||||
}
|
||||
}
|
||||
|
||||
bookmarkCreator->setDisplayName(displayName);
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(nullptr, true, bookmark->getId());
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
bookmarkCreator->setDisplayName(bookmark->getName());
|
||||
bookmarkCreator->setComment(bookmark->getComment());
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
|
||||
bookmarkCreator->setIsEdge((dynamic_cast<EdgeBookmark*>(bookmark.get()) != nullptr));
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::setStyleSheet()
|
||||
@@ -64,17 +243,20 @@ void QtBookmarkView::setStyleSheet()
|
||||
m_widget->setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "bookmark_view/bookmark_view.css").c_str());
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
void QtBookmarkView::refreshStyle()
|
||||
{
|
||||
m_widget->displayBookmarks(bookmarks);
|
||||
}
|
||||
float height = std::max(ApplicationSettings::getInstance()->getFontSize() + 16, 30);
|
||||
|
||||
void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_widget->displayBookmarkCreator(names, categories);
|
||||
}
|
||||
m_createBookmarkButton->setFixedHeight(height);
|
||||
m_showBookmarksButton->setFixedHeight(height);
|
||||
|
||||
void QtBookmarkView::displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_widget->displayBookmarkEditor(bookmark, categories);
|
||||
}
|
||||
m_createBookmarkButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/edit_bookmark_icon.png",
|
||||
"search/button"
|
||||
));
|
||||
|
||||
m_showBookmarksButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_list_icon.png",
|
||||
"search/button"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -3,12 +3,18 @@
|
||||
|
||||
#include "component/view/BookmarkView.h"
|
||||
|
||||
#include "qt/element/QtBookmarkBar.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
class QFrame;
|
||||
class QPushButton;
|
||||
class QtBookmarkBrowser;
|
||||
|
||||
class QtBookmarkView
|
||||
: public BookmarkView
|
||||
: public QObject
|
||||
, public BookmarkView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtBookmarkView(ViewLayout* viewLayout);
|
||||
virtual ~QtBookmarkView();
|
||||
@@ -22,19 +28,29 @@ public:
|
||||
virtual void enableDisplayBookmarks(bool enable);
|
||||
|
||||
virtual bool bookmarkBrowserIsVisible() const;
|
||||
|
||||
|
||||
private slots:
|
||||
void createBookmarkClicked();
|
||||
void showBookmarksClicked();
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
|
||||
void setStyleSheet();
|
||||
|
||||
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
|
||||
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories);
|
||||
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories);
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
void setStyleSheet();
|
||||
void refreshStyle();
|
||||
|
||||
QtBookmarkBar* m_widget;
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
|
||||
QFrame* m_widget;
|
||||
|
||||
QPushButton* m_createBookmarkButton;
|
||||
QPushButton* m_showBookmarksButton;
|
||||
|
||||
QtBookmarkBrowser* m_bookmarkBrowser;
|
||||
|
||||
BookmarkView::CreateButtonState m_createButtonState;
|
||||
};
|
||||
|
||||
#endif // QT_BOOKMARK_VIEW_H
|
||||
#endif // QT_BOOKMARK_VIEW_H
|
||||
|
||||
@@ -482,6 +482,11 @@ void QtGraphView::doRebuildGraph(
|
||||
finishedTransition();
|
||||
}
|
||||
|
||||
if (graph)
|
||||
{
|
||||
m_graph = graph;
|
||||
}
|
||||
|
||||
QGraphicsView* view = getView();
|
||||
|
||||
size_t activeNodeCount = 0;
|
||||
@@ -504,7 +509,8 @@ void QtGraphView::doRebuildGraph(
|
||||
}
|
||||
}
|
||||
|
||||
if (graph->getTrailMode() == Graph::TRAIL_NONE)
|
||||
Graph::TrailMode trailMode = m_graph ? m_graph->getTrailMode() : Graph::TRAIL_NONE;
|
||||
if (trailMode == Graph::TRAIL_NONE)
|
||||
{
|
||||
QPointF center = itemsBoundingRect(m_nodes).center();
|
||||
Vec2i o = GraphViewStyle::alignOnRaster(Vec2i(center.x(), center.y()));
|
||||
@@ -524,7 +530,7 @@ void QtGraphView::doRebuildGraph(
|
||||
{
|
||||
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
|
||||
{
|
||||
createEdge(view, edge.get(), &visibleEdgeIds, graph->getTrailMode());
|
||||
createEdge(view, edge.get(), &visibleEdgeIds, trailMode);
|
||||
}
|
||||
}
|
||||
for (std::shared_ptr<DummyEdge> edge : edges)
|
||||
@@ -535,12 +541,6 @@ void QtGraphView::doRebuildGraph(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (graph)
|
||||
{
|
||||
m_graph = graph;
|
||||
}
|
||||
|
||||
m_centerActiveNode = params.centerActiveNode;
|
||||
m_scrollToTop = params.scrollToTop;
|
||||
m_isIndexedList = params.isIndexedList;
|
||||
|
||||
Reference in New Issue
Block a user