ui: bookmarks
can now bookmark tokens
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
#include "QtBookmark.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "qt/window/QtBookmarkCreator.h"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateBookmark.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkEditor.h"
|
||||
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
|
||||
QtBookmark::QtBookmark()
|
||||
: m_treeWidgetItem(NULL)
|
||||
{
|
||||
setObjectName("bookmark");
|
||||
|
||||
m_layout = new QVBoxLayout();
|
||||
m_layout->setSpacing(0);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(m_layout);
|
||||
|
||||
QHBoxLayout* buttonsLayout = new QHBoxLayout();
|
||||
buttonsLayout->setSpacing(0);
|
||||
buttonsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
buttonsLayout->setAlignment(Qt::AlignTop);
|
||||
|
||||
m_toggleCommentButton = new QPushButton();
|
||||
m_toggleCommentButton->setObjectName("comment_button");
|
||||
m_toggleCommentButton->setToolTip("Show Comment");
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
buttonsLayout->addWidget(m_toggleCommentButton);
|
||||
|
||||
m_dateLabel = new QLabel();
|
||||
m_dateLabel->setObjectName("date_label");
|
||||
m_dateLabel->setText("n/a");
|
||||
buttonsLayout->addWidget(m_dateLabel);
|
||||
|
||||
m_activateButton = new QPushButton();
|
||||
m_activateButton->setObjectName("activate_button");
|
||||
m_activateButton->setToolTip("Activate bookmark");
|
||||
m_activateButton->setText("Bookmark");
|
||||
m_activateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
buttonsLayout->addWidget(m_activateButton);
|
||||
|
||||
m_editButton = new QPushButton();
|
||||
m_editButton->setObjectName("edit_button");
|
||||
m_editButton->setToolTip("Edit bookmark");
|
||||
m_editButton->setText("Edit");
|
||||
m_editButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
buttonsLayout->addWidget(m_editButton);
|
||||
|
||||
m_deleteButton = new QPushButton();
|
||||
m_deleteButton->setObjectName("delete_button");
|
||||
m_deleteButton->setToolTip("Delete bookmark");
|
||||
m_deleteButton->setText("Delete");
|
||||
m_deleteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
buttonsLayout->addWidget(m_deleteButton);
|
||||
|
||||
m_layout->addLayout(buttonsLayout);
|
||||
|
||||
m_comment = new QLabel();
|
||||
m_comment->setText("no comment");
|
||||
m_comment->hide();
|
||||
m_comment->setWordWrap(true);
|
||||
m_layout->addWidget(m_comment);
|
||||
|
||||
|
||||
connect(m_activateButton, SIGNAL(clicked()), this, SLOT(activateClicked()));
|
||||
connect(m_editButton, SIGNAL(clicked()), this, SLOT(editClicked()));
|
||||
connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
||||
connect(m_toggleCommentButton, SIGNAL(clicked()), this, SLOT(commentToggled()));
|
||||
|
||||
refreshStyle();
|
||||
}
|
||||
|
||||
QtBookmark::~QtBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
void QtBookmark::setName(const std::string& name)
|
||||
{
|
||||
m_activateButton->setText(name.c_str());
|
||||
}
|
||||
|
||||
std::string QtBookmark::getName() const
|
||||
{
|
||||
return m_bookmark->getDisplayName();
|
||||
}
|
||||
|
||||
void QtBookmark::setBookmark(const std::shared_ptr<Bookmark> bookmark)
|
||||
{
|
||||
m_bookmark = bookmark;
|
||||
|
||||
m_activateButton->setText(bookmark->getDisplayName().c_str());
|
||||
|
||||
bool isValid = m_bookmark->isValid();
|
||||
|
||||
if (m_bookmark->isValid() == false)
|
||||
{
|
||||
m_activateButton->setEnabled(false);
|
||||
m_editButton->setEnabled(false);
|
||||
}
|
||||
|
||||
if (m_bookmark->getComment().length() > 0)
|
||||
{
|
||||
m_comment->setText(m_bookmark->getComment().c_str());
|
||||
m_activateButton->setToolTip(bookmark->getComment().c_str());
|
||||
}
|
||||
m_dateLabel->setText(getDateString().c_str());
|
||||
|
||||
getDateString();
|
||||
}
|
||||
|
||||
Id QtBookmark::getBookmarkId() const
|
||||
{
|
||||
return m_bookmark->getId();
|
||||
}
|
||||
|
||||
QTreeWidgetItem* QtBookmark::getTreeWidgetItem() const
|
||||
{
|
||||
return m_treeWidgetItem;
|
||||
}
|
||||
|
||||
void QtBookmark::setTreeWidgetItem(QTreeWidgetItem* treeWidgetItem)
|
||||
{
|
||||
m_treeWidgetItem = treeWidgetItem;
|
||||
}
|
||||
|
||||
void QtBookmark::refreshStyle()
|
||||
{
|
||||
if (m_editButton != NULL)
|
||||
{
|
||||
m_editButton->setText("");
|
||||
m_editButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_edit_icon.png").c_str()));
|
||||
}
|
||||
|
||||
if (m_deleteButton != NULL)
|
||||
{
|
||||
m_deleteButton->setText("");
|
||||
m_deleteButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_delete_icon.png").c_str()));
|
||||
}
|
||||
|
||||
if (m_toggleCommentButton != NULL)
|
||||
{
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_right.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
m_toggleCommentButton->setIconSize(QSize(10, 10));
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::activateClicked()
|
||||
{
|
||||
MessageActivateBookmark(m_bookmark).dispatch();
|
||||
}
|
||||
|
||||
void QtBookmark::editClicked()
|
||||
{
|
||||
MessageDisplayBookmarkEditor(m_bookmark).dispatch();
|
||||
}
|
||||
|
||||
void QtBookmark::deleteClicked()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Delete Bookmark");
|
||||
msgBox.setInformativeText("Do you really want to delete this bookmark?");
|
||||
QAbstractButton* yesButton = msgBox.addButton("Delete", QMessageBox::ButtonRole::YesRole);
|
||||
QAbstractButton* noButton = msgBox.addButton("Keep", QMessageBox::ButtonRole::NoRole);
|
||||
msgBox.setIcon(QMessageBox::Icon::Question);
|
||||
int ret = msgBox.exec();
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes)
|
||||
{
|
||||
MessageDeleteBookmark(m_bookmark->getId(), (dynamic_cast<EdgeBookmark*>(m_bookmark.get()) != NULL)).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::commentToggled()
|
||||
{
|
||||
// std::string text = m_toggleCommentButton->text().toStdString();
|
||||
|
||||
if (m_comment->isVisible() == false)
|
||||
{
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_down.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
m_toggleCommentButton->setIconSize(QSize(10, 10));
|
||||
m_comment->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_right.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
m_toggleCommentButton->setIconSize(QSize(10, 10));
|
||||
m_comment->hide();
|
||||
}
|
||||
|
||||
// forces the parent tree view to rescale
|
||||
if (m_treeWidgetItem)
|
||||
{
|
||||
m_treeWidgetItem->setExpanded(false);
|
||||
m_treeWidgetItem->setExpanded(true);
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::handleMessage(MessageEditBookmark* message)
|
||||
{
|
||||
if (m_bookmark->getId() == message->bookmarkId)
|
||||
{
|
||||
m_bookmark->setDisplayName(message->displayName);
|
||||
m_bookmark->setComment(message->comment);
|
||||
|
||||
m_activateButton->setText(message->displayName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string QtBookmark::getDateString() const
|
||||
{
|
||||
std::string result = "n/a";
|
||||
|
||||
TimePoint creationDate = m_bookmark->getTimeStamp();
|
||||
|
||||
float delta = TimePoint::now() - creationDate;
|
||||
|
||||
if (delta < 3600.0f) // less than an hour ago
|
||||
{
|
||||
result = std::to_string(int(delta / 60.0f)) + " minutes ago";
|
||||
}
|
||||
else if (delta < (3600.0f * 6.0f)) // less than 6 hours ago
|
||||
{
|
||||
result = std::to_string(int(delta / 3600.0f)) + " hours ago";
|
||||
}
|
||||
else if (creationDate.isSameDay(TimePoint::now())) // today
|
||||
{
|
||||
result = "today";
|
||||
}
|
||||
else if(creationDate.deltaDays(TimePoint::now()) == 1) // yesterday
|
||||
{
|
||||
result = "yesterday";
|
||||
}
|
||||
else // whenever
|
||||
{
|
||||
result = creationDate.getDDMMYYYYString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef QT_BOOKMARK_H
|
||||
#define QT_BOOKMARK_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmark.h"
|
||||
#include "utility/messaging/type/MessageEditBookmark.h"
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
class QtBookmark
|
||||
: public QFrame
|
||||
, public MessageListener<MessageEditBookmark>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtBookmark();
|
||||
virtual ~QtBookmark();
|
||||
|
||||
void setName(const std::string& name);
|
||||
std::string getName() const;
|
||||
|
||||
void setBookmark(const std::shared_ptr<Bookmark> bookmark);
|
||||
|
||||
Id getBookmarkId() const;
|
||||
|
||||
QTreeWidgetItem* getTreeWidgetItem() const;
|
||||
void setTreeWidgetItem(QTreeWidgetItem* treeWidgetItem);
|
||||
|
||||
void refreshStyle();
|
||||
|
||||
private slots:
|
||||
void activateClicked();
|
||||
void editClicked();
|
||||
void deleteClicked();
|
||||
void commentToggled();
|
||||
|
||||
private:
|
||||
void handleMessage(MessageEditBookmark* message);
|
||||
|
||||
std::string getDateString() const;
|
||||
|
||||
QVBoxLayout* m_layout;
|
||||
|
||||
QPushButton* m_activateButton;
|
||||
QPushButton* m_editButton;
|
||||
QPushButton* m_deleteButton;
|
||||
QPushButton* m_toggleCommentButton;
|
||||
|
||||
QLabel* m_comment;
|
||||
QLabel* m_dateLabel;
|
||||
|
||||
std::shared_ptr<Bookmark> m_bookmark;
|
||||
|
||||
QTreeWidgetItem* m_treeWidgetItem; // pointer to the bookmark category item in the treeView, allows to refresh tree view when a node changes in size (e.g. toggle comment)
|
||||
// not a nice solution to the problem, but couldn't find anything better yet (sizeHintChanged signal can't be emitted here...)
|
||||
};
|
||||
|
||||
#endif // QT_BOOKMARK_H
|
||||
@@ -0,0 +1,261 @@
|
||||
#include "QtBookmarkBar.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
#include "qt/window/QtBookmarkCreator.h"
|
||||
|
||||
#include "qt/window/QtMainWindow.h"
|
||||
|
||||
#include "qt/element/QtBookmark.h"
|
||||
|
||||
QtBookmarkBar::QtBookmarkBar()
|
||||
: m_displayBookmarksFunctor(std::bind(&QtBookmarkBar::doDisplayBookmarks, this, std::placeholders::_1))
|
||||
, m_displayBookmarkCreatorFunctor(std::bind(&QtBookmarkBar::doDisplayBookmarkCreator, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_displayBookmarkEditorFunctor(std::bind(&QtBookmarkBar::doDisplayBookmarkEditor, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_setCreateButtonStateFunctor(std::bind(&QtBookmarkBar::doSetCreateButtonState, this, std::placeholders::_1))
|
||||
, m_enableDisplayButtonFunctor(std::bind(&QtBookmarkBar::doEnableDisplayButton, this, std::placeholders::_1))
|
||||
, m_bookmarkBrowser(NULL)
|
||||
, m_createButtonState(BookmarkView::CreateButtonState::CANNOT_CREATE)
|
||||
{
|
||||
setObjectName("bookmark_bar");
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
||||
m_createBookmarkButton = new QPushButton(this);
|
||||
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
|
||||
layout->addWidget(m_createBookmarkButton);
|
||||
|
||||
m_createBookmarkButton->setEnabled(false);
|
||||
|
||||
connect(m_createBookmarkButton, SIGNAL(clicked()), this, SLOT(createBookmarkClicked()));
|
||||
|
||||
m_showBookmarksButton = new QPushButton(this);
|
||||
m_showBookmarksButton->setObjectName("show_bookmark_button");
|
||||
m_showBookmarksButton->setToolTip("Show bookmarks");
|
||||
m_showBookmarksButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
layout->addWidget(m_showBookmarksButton);
|
||||
|
||||
m_showBookmarksButton->setEnabled(false);
|
||||
|
||||
connect(m_showBookmarksButton, SIGNAL(clicked()), this, SLOT(showBookmarksClicked()));
|
||||
|
||||
refreshStyle();
|
||||
}
|
||||
|
||||
QtBookmarkBar::~QtBookmarkBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtBookmarkBar::refreshStyle()
|
||||
{
|
||||
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "bookmark_view/bookmark_view.css").c_str());
|
||||
|
||||
float height = std::max(ApplicationSettings::getInstance()->getFontSize() + 16, 30);
|
||||
|
||||
m_createBookmarkButton->setFixedHeight(height);
|
||||
m_showBookmarksButton->setFixedHeight(height);
|
||||
|
||||
std::string createImage = ResourcePaths::getGuiPath() + "bookmark_view/images/edit_bookmark_icon.png";
|
||||
std::string listImage = ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_list_icon.png";
|
||||
|
||||
m_createBookmarkButton->setIcon(utility::colorizePixmap(
|
||||
QPixmap(createImage.c_str()),
|
||||
ColorScheme::getInstance()->getColor("search/button/icon").c_str()
|
||||
));
|
||||
|
||||
m_showBookmarksButton->setIcon(utility::colorizePixmap(
|
||||
QPixmap(listImage.c_str()),
|
||||
ColorScheme::getInstance()->getColor("search/button/icon").c_str()
|
||||
));
|
||||
}
|
||||
|
||||
void QtBookmarkBar::displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
{
|
||||
m_displayBookmarksFunctor(bookmarks);
|
||||
}
|
||||
|
||||
void QtBookmarkBar::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_displayBookmarkCreatorFunctor(names, categories);
|
||||
}
|
||||
|
||||
void QtBookmarkBar::displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_displayBookmarkEditorFunctor(bookmark, categories);
|
||||
}
|
||||
|
||||
void QtBookmarkBar::setCreateButtonState(const BookmarkView::CreateButtonState& state)
|
||||
{
|
||||
m_setCreateButtonStateFunctor(state);
|
||||
}
|
||||
|
||||
void QtBookmarkBar::enableDisplayButton(bool enable)
|
||||
{
|
||||
m_enableDisplayButtonFunctor(enable);
|
||||
}
|
||||
|
||||
bool QtBookmarkBar::bookmarkBrowserIsVisible() const
|
||||
{
|
||||
if (m_bookmarkBrowser != NULL)
|
||||
{
|
||||
return m_bookmarkBrowser->isVisible();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkBar::createBookmarkClicked()
|
||||
{
|
||||
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 update or delete the Bookmark for the active Token?");
|
||||
QAbstractButton* editButton = msgBox.addButton("Edit", QMessageBox::ButtonRole::YesRole);
|
||||
QAbstractButton* deleteButton = msgBox.addButton("Delete", QMessageBox::ButtonRole::DestructiveRole);
|
||||
QAbstractButton* cancelButton = msgBox.addButton("Cancel", QMessageBox::ButtonRole::NoRole);
|
||||
msgBox.setIcon(QMessageBox::Icon::Question);
|
||||
int ret = msgBox.exec();
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes)
|
||||
{
|
||||
MessageDisplayBookmarkCreator().dispatch();
|
||||
}
|
||||
else if (ret == 1)
|
||||
{
|
||||
MessageDeleteBookmarkForActiveTokens().dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkBar::showBookmarksClicked()
|
||||
{
|
||||
MessageDisplayBookmarks(MessageDisplayBookmarks::BookmarkFilter::ALL, MessageDisplayBookmarks::BookmarkOrder::NONE).dispatch();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::handleMessage(MessageEnteredLicense* message)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
// actually only want to enable this when a project is loaded
|
||||
// maybe factor in licence later...
|
||||
// m_createBookmarkButton->setEnabled(true);
|
||||
// m_showBookmarksButton->setEnabled(true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doDisplayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doDisplayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(NULL, true, bookmark->getId());
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
bookmarkCreator->setDisplayName(bookmark->getDisplayName());
|
||||
bookmarkCreator->setComment(bookmark->getComment());
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
|
||||
bookmarkCreator->setIsEdge((dynamic_cast<EdgeBookmark*>(bookmark.get()) != NULL));
|
||||
|
||||
bookmarkCreator->show();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doDisplayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
{
|
||||
if (m_bookmarkBrowser == NULL)
|
||||
{
|
||||
m_bookmarkBrowser = new QtBookmarkBrowser();
|
||||
m_bookmarkBrowser->setupBookmarkBrowser();
|
||||
}
|
||||
|
||||
m_bookmarkBrowser->setBookmarks(bookmarks);
|
||||
m_bookmarkBrowser->show();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doSetCreateButtonState(const BookmarkView::CreateButtonState& state)
|
||||
{
|
||||
m_createButtonState = state;
|
||||
|
||||
std::string createImage = ResourcePaths::getGuiPath() + "bookmark_view/images/edit_bookmark_icon.png";
|
||||
|
||||
m_createBookmarkButton->setIcon(utility::colorizePixmap(
|
||||
QPixmap(createImage.c_str()),
|
||||
ColorScheme::getInstance()->getColor("search/button/icon").c_str()
|
||||
));
|
||||
|
||||
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);
|
||||
|
||||
std::string createImage = ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_active.png";
|
||||
|
||||
m_createBookmarkButton->setIcon(utility::colorizePixmap(
|
||||
QPixmap(createImage.c_str()),
|
||||
ColorScheme::getInstance()->getColor("search/button/icon").c_str()
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_createBookmarkButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doEnableDisplayButton(bool enable)
|
||||
{
|
||||
m_showBookmarksButton->setEnabled(enable);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#ifndef QT_BOOKMARK_BAR_H
|
||||
#define QT_BOOKMARK_BAR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <qtextedit.h>
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include "component/view/BookmarkView.h"
|
||||
#include "qt/window/QtBookmarkBrowser.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
#include "utility/messaging/type/MessageEnteredLicense.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
class QPushButton;
|
||||
|
||||
class QtBookmarkBar
|
||||
: public QFrame
|
||||
, public MessageListener<MessageEnteredLicense>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtBookmarkBar();
|
||||
virtual ~QtBookmarkBar();
|
||||
|
||||
void refreshStyle();
|
||||
|
||||
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);
|
||||
|
||||
void setCreateButtonState(const BookmarkView::CreateButtonState& state);
|
||||
void enableDisplayButton(bool enable);
|
||||
|
||||
bool bookmarkBrowserIsVisible() const;
|
||||
|
||||
private slots:
|
||||
void createBookmarkClicked();
|
||||
void showBookmarksClicked();
|
||||
|
||||
private:
|
||||
virtual void handleMessage(MessageEnteredLicense* message);
|
||||
|
||||
void doDisplayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
|
||||
void doDisplayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories);
|
||||
void doDisplayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories);
|
||||
void doSetCreateButtonState(const BookmarkView::CreateButtonState& state);
|
||||
void doEnableDisplayButton(bool enable);
|
||||
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
|
||||
QPushButton* m_createBookmarkButton;
|
||||
QPushButton* m_showBookmarksButton;
|
||||
|
||||
QtThreadedFunctor<std::vector<std::shared_ptr<Bookmark>>> m_displayBookmarksFunctor;
|
||||
QtThreadedFunctor<std::vector<std::string>, std::vector<BookmarkCategory>> m_displayBookmarkCreatorFunctor;
|
||||
QtThreadedFunctor<std::shared_ptr<Bookmark>, std::vector<BookmarkCategory>> m_displayBookmarkEditorFunctor;
|
||||
QtThreadedFunctor<BookmarkView::CreateButtonState> m_setCreateButtonStateFunctor;
|
||||
QtThreadedFunctor<bool> m_enableDisplayButtonFunctor;
|
||||
|
||||
QtBookmarkBrowser* m_bookmarkBrowser;
|
||||
|
||||
BookmarkView::CreateButtonState m_createButtonState;
|
||||
};
|
||||
|
||||
#endif // QT_BOOKMARK_BAR_H
|
||||
@@ -0,0 +1,145 @@
|
||||
#include "QtBookmarkCategory.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h"
|
||||
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
|
||||
QtBookmarkCategory::QtBookmarkCategory()
|
||||
: m_name(NULL)
|
||||
, m_layout(NULL)
|
||||
, m_deleteButton(NULL)
|
||||
, m_id(-1)
|
||||
, m_treeItem(NULL)
|
||||
{
|
||||
setObjectName("bookmark_category");
|
||||
|
||||
m_layout = new QHBoxLayout();
|
||||
m_layout->setSpacing(0);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(m_layout);
|
||||
|
||||
m_expandButton = new QPushButton();
|
||||
m_expandButton->setObjectName("category_expand_button");
|
||||
m_expandButton->setToolTip("Show/Hide bookmarks in this category");
|
||||
m_expandButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_down.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
m_expandButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
m_layout->addWidget(m_expandButton);
|
||||
|
||||
connect(m_expandButton, SIGNAL(clicked()), this, SLOT(expandClicked()));
|
||||
|
||||
m_name = new QLabel();
|
||||
m_name->setObjectName("category_name");
|
||||
m_name->setText("");
|
||||
m_layout->addWidget(m_name);
|
||||
|
||||
m_deleteButton = new QPushButton();
|
||||
m_deleteButton->setObjectName("category_delete_button");
|
||||
m_deleteButton->setToolTip("Delete this Bookmark Category and the containing Bookmarks");
|
||||
// m_deleteButton->setText("Delete");
|
||||
m_deleteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
m_deleteButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_delete_icon.png").c_str()));
|
||||
m_layout->addWidget(m_deleteButton);
|
||||
|
||||
connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
||||
}
|
||||
|
||||
QtBookmarkCategory::~QtBookmarkCategory()
|
||||
{
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::setName(const std::string& name)
|
||||
{
|
||||
if (m_name != NULL)
|
||||
{
|
||||
m_name->setText(name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string QtBookmarkCategory::getName() const
|
||||
{
|
||||
std::string result = "";
|
||||
|
||||
if (m_name != NULL)
|
||||
{
|
||||
result = m_name->text().toStdString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::setId(const Id id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
Id QtBookmarkCategory::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::setTreeWidgetItem(QTreeWidgetItem* treeItem)
|
||||
{
|
||||
m_treeItem = treeItem;
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::updateArrow()
|
||||
{
|
||||
if (m_treeItem != NULL)
|
||||
{
|
||||
if (m_treeItem->isExpanded())
|
||||
{
|
||||
m_expandButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_down.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_expandButton->setIcon(utility::createButtonIcon(
|
||||
ResourcePaths::getGuiPath() + "bookmark_view/images/arrow_right.png",
|
||||
"bookmark/button"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::expandClicked()
|
||||
{
|
||||
if (m_treeItem != NULL)
|
||||
{
|
||||
if (m_treeItem->isExpanded())
|
||||
{
|
||||
m_treeItem->setExpanded(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_treeItem->setExpanded(true);
|
||||
}
|
||||
|
||||
updateArrow();
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkCategory::deleteClicked()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Delete Category");
|
||||
msgBox.setInformativeText("Do you really want to delete this category AND all containing bookmarks?");
|
||||
QAbstractButton* yesButton = msgBox.addButton("Delete", QMessageBox::ButtonRole::YesRole);
|
||||
QAbstractButton* noButton = msgBox.addButton("Keep", QMessageBox::ButtonRole::NoRole);
|
||||
msgBox.setIcon(QMessageBox::Icon::Question);
|
||||
int ret = msgBox.exec();
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
MessageDeleteBookmarkCategoryWithBookmarks(m_id).dispatch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef QT_BOOKMARK_CATEGORY_H
|
||||
#define QT_BOOKMARK_CATEGORY_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QTreeWidget>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class QtBookmarkCategory
|
||||
: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtBookmarkCategory();
|
||||
~QtBookmarkCategory();
|
||||
|
||||
void setName(const std::string& name);
|
||||
std::string getName() const;
|
||||
|
||||
void setId(const Id id);
|
||||
Id getId() const;
|
||||
|
||||
void setTreeWidgetItem(QTreeWidgetItem* treeItem);
|
||||
|
||||
void updateArrow();
|
||||
|
||||
private slots:
|
||||
void expandClicked();
|
||||
void deleteClicked();
|
||||
|
||||
private:
|
||||
QHBoxLayout* m_layout;
|
||||
QLabel* m_name;
|
||||
|
||||
QPushButton* m_expandButton;
|
||||
QPushButton* m_deleteButton;
|
||||
|
||||
QTreeWidgetItem* m_treeItem; // store a pointer to the 'parent' tree item to enable the custom expand button
|
||||
|
||||
Id m_id;
|
||||
};
|
||||
|
||||
#endif // QT_BOOKMARK_CATEGORY_H
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
QtStatusBar::QtStatusBar()
|
||||
: m_text(this)
|
||||
, m_ideStatusText(this)
|
||||
{
|
||||
addWidget(new QWidget()); // add some space
|
||||
|
||||
@@ -42,6 +43,9 @@ QtStatusBar::QtStatusBar()
|
||||
addPermanentWidget(&m_errorButton);
|
||||
|
||||
connect(&m_errorButton, SIGNAL(clicked()), this, SLOT(showErrors()));
|
||||
|
||||
m_ideStatusText.setText("No IDE connected");
|
||||
addWidget(&m_ideStatusText);
|
||||
}
|
||||
|
||||
QtStatusBar::~QtStatusBar()
|
||||
@@ -86,6 +90,11 @@ void QtStatusBar::setErrorCount(ErrorCountInfo errorCount)
|
||||
}
|
||||
}
|
||||
|
||||
void QtStatusBar::setIdeStatus(const std::string& text)
|
||||
{
|
||||
m_ideStatusText.setText(text.c_str());
|
||||
}
|
||||
|
||||
void QtStatusBar::showStatus()
|
||||
{
|
||||
MessageShowStatus().dispatch();
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
void setText(const std::string& text, bool isError, bool showLoader);
|
||||
void setErrorCount(ErrorCountInfo errorCount);
|
||||
|
||||
void setIdeStatus(const std::string& text);
|
||||
|
||||
private slots:
|
||||
void showStatus();
|
||||
void showErrors();
|
||||
@@ -29,6 +31,8 @@ private:
|
||||
QPushButton m_text;
|
||||
QLabel m_loader;
|
||||
QPushButton m_errorButton;
|
||||
|
||||
QLabel m_ideStatusText;
|
||||
};
|
||||
|
||||
#endif // QT_STATUS_BAR_H
|
||||
|
||||
Reference in New Issue
Block a user