Commit 5cf29723 authored by Eike Ziller's avatar Eike Ziller Committed by Eike Ziller

Help: Clean up bookmarks widget

Remove unused buttons, and unify style with other views (e.g. no focus
rect on OS X) by using the common navigation tree view class.

Change-Id: I51ce1806507e45077bcbf6b8589585bb15eae712
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 46dfd21c
......@@ -325,7 +325,7 @@ void HelpPlugin::setupUi()
shortcutMap.insert(searchItem->id(), cmd);
BookmarkManager *manager = &LocalHelpManager::bookmarkManager();
BookmarkWidget *bookmarkWidget = new BookmarkWidget(manager, 0, false);
BookmarkWidget *bookmarkWidget = new BookmarkWidget(manager);
bookmarkWidget->setWindowTitle(tr(Constants::SB_BOOKMARKS));
auto bookmarkItem = new SideBarItem(bookmarkWidget, QLatin1String(Constants::HELP_BOOKMARKS));
connect(bookmarkWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
......
......@@ -297,7 +297,7 @@ void HelpWidget::addSideBar()
: tr("Ctrl+Shift+I")));
shortcutMap.insert(QLatin1String(Constants::HELP_INDEX), cmd);
auto bookmarkWidget = new BookmarkWidget(&LocalHelpManager::bookmarkManager(), 0, false);
auto bookmarkWidget = new BookmarkWidget(&LocalHelpManager::bookmarkManager());
bookmarkWidget->setWindowTitle(tr(Constants::SB_BOOKMARKS));
bookmarkWidget->setOpenInNewPageActionVisible(false);
auto bookmarkItem = new Core::SideBarItem(bookmarkWidget,
......
......@@ -296,15 +296,12 @@ bool BookmarkDialog::eventFilter(QObject *object, QEvent *e)
// #pragma mark -- BookmarkWidget
BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent,
bool showButtons)
BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent)
: QWidget(parent)
, addButton(0)
, removeButton(0)
, bookmarkManager(manager)
, m_isOpenInNewPageActionVisible(true)
{
setup(showButtons);
setup();
installEventFilter(this);
}
......@@ -337,12 +334,6 @@ void BookmarkWidget::filterChanged()
filterBookmarkModel->setSourceModel(bookmarkManager->treeBookmarkModel());
}
if (addButton)
addButton->setEnabled(searchBookmarks);
if (removeButton)
removeButton->setEnabled(searchBookmarks);
filterBookmarkModel->setFilterRegExp(regExp);
const QModelIndex &index = treeView->indexAt(QPoint(1, 1));
......@@ -422,7 +413,7 @@ void BookmarkWidget::customContextMenuRequested(const QPoint &point)
}
}
void BookmarkWidget::setup(bool showButtons)
void BookmarkWidget::setup()
{
regExp.setPatternSyntax(QRegExp::FixedString);
regExp.setCaseSensitivity(Qt::CaseInsensitive);
......@@ -449,40 +440,8 @@ void BookmarkWidget::setup(bool showButtons)
SLOT(filterChanged()));
treeView = new TreeView(this);
treeView->setFrameStyle(QFrame::NoFrame);
vlayout->addWidget(treeView);
#ifdef Q_OS_MAC
# define SYSTEM "mac"
#else
# define SYSTEM "win"
#endif
if (showButtons) {
QLayout *hlayout = new QHBoxLayout();
vlayout->addItem(hlayout);
hlayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding));
addButton = new QToolButton(this);
addButton->setText(tr("Add"));
addButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/"
SYSTEM "/addtab.png")));
addButton->setAutoRaise(true);
addButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
hlayout->addWidget(addButton);
connect(addButton, SIGNAL(clicked()), this, SIGNAL(addBookmark()));
removeButton = new QToolButton(this);
removeButton->setText(tr("Remove"));
removeButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/"
SYSTEM "/closetab.png")));
removeButton->setAutoRaise(true);
removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
hlayout->addWidget(removeButton);
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
}
filterBookmarkModel = new QSortFilterProxyModel(this);
treeView->setModel(filterBookmarkModel);
......@@ -490,7 +449,6 @@ void BookmarkWidget::setup(bool showButtons)
treeView->setAcceptDrops(true);
treeView->setAutoExpandDelay(1000);
treeView->setDropIndicatorShown(true);
treeView->header()->setVisible(false);
treeView->viewport()->installEventFilter(this);
treeView->setContextMenuPolicy(Qt::CustomContextMenu);
......@@ -545,13 +503,13 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e)
switch (ke->key()) {
default: break;
case Qt::Key_Up: {
case Qt::Key_Down:
case Qt::Key_Up:
case Qt::Key_Down: {
treeView->subclassKeyPressEvent(ke);
} break;
case Qt::Key_Enter: {
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Return: {
index = treeView->selectionModel()->currentIndex();
if (index.isValid()) {
QString data = index.data(Qt::UserRole + 10).toString();
......
......@@ -32,6 +32,8 @@
#include "ui_bookmarkdialog.h"
#include <utils/navigationtreeview.h>
#include <QUrl>
#include <QObject>
#include <QString>
......@@ -92,15 +94,15 @@ private:
QSortFilterProxyModel *proxyModel;
};
class TreeView : public QTreeView
class TreeView : public Utils::NavigationTreeView
{
Q_OBJECT
public:
TreeView(QWidget* parent = 0) : QTreeView(parent) {}
TreeView(QWidget* parent = 0) : Utils::NavigationTreeView(parent) {}
void subclassKeyPressEvent(QKeyEvent* event)
{
QTreeView::keyPressEvent(event);
Utils::NavigationTreeView::keyPressEvent(event);
}
};
......@@ -109,8 +111,7 @@ class BookmarkWidget : public QWidget
Q_OBJECT
public:
explicit BookmarkWidget(BookmarkManager *manager, QWidget *parent = 0,
bool showButtons = true);
explicit BookmarkWidget(BookmarkManager *manager, QWidget *parent = 0);
~BookmarkWidget();
void setOpenInNewPageActionVisible(bool visible);
......@@ -128,7 +129,7 @@ private slots:
void customContextMenuRequested(const QPoint &point);
private:
void setup(bool showButtons);
void setup();
void expandItems();
bool eventFilter(QObject *object, QEvent *event);
......@@ -136,8 +137,6 @@ private:
QRegExp regExp;
TreeView *treeView;
Utils::FancyLineEdit *searchField;
QToolButton *addButton;
QToolButton *removeButton;
BookmarkManager *bookmarkManager;
QSortFilterProxyModel* filterBookmarkModel;
bool m_isOpenInNewPageActionVisible;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment