ui: Fixed layout of QtBookmarkBrowser
* fixed window size and resizing * fixed layout and spacing * removed focus rects on Mac * fixed filter dropdown style for Mac * reuse button handling from QtWindow * use different colors for category and bookmark rows * allow clicking full row for expansion * show edit and delete button only on hover * ellide bookmark name when little space
This commit is contained in:
@@ -1,29 +1,32 @@
|
||||
#include "QtBookmark.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "qt/window/QtBookmarkCreator.h"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateBookmark.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkEditor.h"
|
||||
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "qt/window/QtBookmarkCreator.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
|
||||
QtBookmark::QtBookmark()
|
||||
: m_treeWidgetItem(NULL)
|
||||
, m_arrowImageName("arrow_right.png")
|
||||
, m_hovered(false)
|
||||
, m_ignoreNextResize(false)
|
||||
{
|
||||
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);
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
||||
QHBoxLayout* buttonsLayout = new QHBoxLayout();
|
||||
buttonsLayout->setSpacing(0);
|
||||
@@ -33,67 +36,60 @@ QtBookmark::QtBookmark()
|
||||
m_toggleCommentButton = new QPushButton();
|
||||
m_toggleCommentButton->setObjectName("comment_button");
|
||||
m_toggleCommentButton->setToolTip("Show Comment");
|
||||
m_toggleCommentButton->setText("");
|
||||
m_toggleCommentButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
m_toggleCommentButton->setIconSize(QSize(10, 10));
|
||||
utility::setWidgetRetainsSpaceWhenHidden(m_toggleCommentButton);
|
||||
buttonsLayout->addWidget(m_toggleCommentButton);
|
||||
|
||||
m_dateLabel = new QLabel();
|
||||
m_dateLabel->setObjectName("date_label");
|
||||
m_dateLabel->setText("n/a");
|
||||
buttonsLayout->addWidget(m_dateLabel);
|
||||
updateArrow();
|
||||
|
||||
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_dateLabel = new QLabel();
|
||||
m_dateLabel->setObjectName("date_label");
|
||||
buttonsLayout->addWidget(m_dateLabel);
|
||||
|
||||
buttonsLayout->addStretch();
|
||||
|
||||
m_editButton = new QPushButton();
|
||||
m_editButton->setObjectName("edit_button");
|
||||
m_editButton->setToolTip("Edit bookmark");
|
||||
m_editButton->setText("Edit");
|
||||
m_editButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
m_editButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_edit_icon.png").c_str()));
|
||||
utility::setWidgetRetainsSpaceWhenHidden(m_editButton);
|
||||
m_editButton->hide();
|
||||
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);
|
||||
m_deleteButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_delete_icon.png").c_str()));
|
||||
utility::setWidgetRetainsSpaceWhenHidden(m_deleteButton);
|
||||
m_deleteButton->hide();
|
||||
buttonsLayout->addWidget(m_deleteButton);
|
||||
|
||||
m_layout->addLayout(buttonsLayout);
|
||||
layout->addLayout(buttonsLayout);
|
||||
|
||||
m_comment = new QLabel();
|
||||
m_comment->setText("no comment");
|
||||
m_comment->hide();
|
||||
m_comment = new QLabel("");
|
||||
m_comment->setObjectName("bookmark_comment");
|
||||
m_comment->setWordWrap(true);
|
||||
m_layout->addWidget(m_comment);
|
||||
|
||||
m_comment->hide();
|
||||
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;
|
||||
@@ -109,11 +105,14 @@ void QtBookmark::setBookmark(const std::shared_ptr<Bookmark> bookmark)
|
||||
if (m_bookmark->getComment().length() > 0)
|
||||
{
|
||||
m_comment->setText(m_bookmark->getComment().c_str());
|
||||
m_activateButton->setToolTip(bookmark->getComment().c_str());
|
||||
m_toggleCommentButton->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_toggleCommentButton->hide();
|
||||
}
|
||||
m_dateLabel->setText(getDateString().c_str());
|
||||
|
||||
getDateString();
|
||||
m_dateLabel->setText(getDateString().c_str());
|
||||
}
|
||||
|
||||
Id QtBookmark::getBookmarkId() const
|
||||
@@ -131,31 +130,72 @@ void QtBookmark::setTreeWidgetItem(QTreeWidgetItem* treeWidgetItem)
|
||||
m_treeWidgetItem = treeWidgetItem;
|
||||
}
|
||||
|
||||
void QtBookmark::refreshStyle()
|
||||
void QtBookmark::commentToggled()
|
||||
{
|
||||
if (m_editButton != NULL)
|
||||
if (!m_toggleCommentButton->isVisible())
|
||||
{
|
||||
m_editButton->setText("");
|
||||
m_editButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_edit_icon.png").c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_deleteButton != NULL)
|
||||
m_ignoreNextResize = true;
|
||||
|
||||
if (m_comment->isVisible() == false)
|
||||
{
|
||||
m_deleteButton->setText("");
|
||||
m_deleteButton->setIcon(QPixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/bookmark_delete_icon.png").c_str()));
|
||||
m_arrowImageName = "arrow_down.png";
|
||||
m_comment->show();
|
||||
m_comment->setMinimumHeight(m_comment->heightForWidth(m_comment->width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_arrowImageName = "arrow_right.png";
|
||||
m_comment->hide();
|
||||
}
|
||||
|
||||
if (m_toggleCommentButton != NULL)
|
||||
updateArrow();
|
||||
|
||||
// forces the parent tree view to rescale
|
||||
if (m_treeWidgetItem)
|
||||
{
|
||||
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_treeWidgetItem->setExpanded(false);
|
||||
m_treeWidgetItem->setExpanded(true);
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
if (m_ignoreNextResize)
|
||||
{
|
||||
m_ignoreNextResize = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_activateButton->setText(m_bookmark->getDisplayName().c_str());
|
||||
QTimer::singleShot(10, this, SLOT(elideButtonText()));
|
||||
}
|
||||
|
||||
void QtBookmark::showEvent(QShowEvent* event)
|
||||
{
|
||||
elideButtonText();
|
||||
}
|
||||
|
||||
void QtBookmark::enterEvent(QEvent *event)
|
||||
{
|
||||
m_editButton->show();
|
||||
m_deleteButton->show();
|
||||
|
||||
m_hovered = true;
|
||||
updateArrow();
|
||||
}
|
||||
|
||||
void QtBookmark::leaveEvent(QEvent *event)
|
||||
{
|
||||
m_editButton->hide();
|
||||
m_deleteButton->hide();
|
||||
|
||||
m_hovered = false;
|
||||
updateArrow();
|
||||
}
|
||||
|
||||
void QtBookmark::activateClicked()
|
||||
{
|
||||
MessageActivateBookmark(m_bookmark).dispatch();
|
||||
@@ -182,39 +222,10 @@ void QtBookmark::deleteClicked()
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::commentToggled()
|
||||
void QtBookmark::elideButtonText()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
m_activateButton->setText(m_activateButton->fontMetrics().elidedText(
|
||||
m_bookmark->getDisplayName().c_str(), Qt::ElideMiddle, m_activateButton->width() - 16));
|
||||
}
|
||||
|
||||
void QtBookmark::handleMessage(MessageEditBookmark* message)
|
||||
@@ -228,6 +239,12 @@ void QtBookmark::handleMessage(MessageEditBookmark* message)
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::updateArrow()
|
||||
{
|
||||
QPixmap pixmap((ResourcePaths::getGuiPath() + "bookmark_view/images/" + m_arrowImageName).c_str());
|
||||
m_toggleCommentButton->setIcon(QIcon(utility::colorizePixmap(pixmap, m_hovered ? "black" : "#707070")));
|
||||
}
|
||||
|
||||
std::string QtBookmark::getDateString() const
|
||||
{
|
||||
std::string result = "n/a";
|
||||
@@ -248,7 +265,7 @@ std::string QtBookmark::getDateString() const
|
||||
{
|
||||
result = "today";
|
||||
}
|
||||
else if(creationDate.deltaDays(TimePoint::now()) == 1) // yesterday
|
||||
else if (creationDate.deltaDays(TimePoint::now()) == 1) // yesterday
|
||||
{
|
||||
result = "yesterday";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user