Implemented bookmarks toolbar for Qt4 front-end.

ver1_6_1
Chris Laurel 2008-04-21 23:06:14 +00:00
parent 161635ea8b
commit acec872b4a
4 changed files with 148 additions and 25 deletions

View File

@ -72,7 +72,7 @@ const QPoint DEFAULT_MAIN_WINDOW_POSITION(200, 200);
// Used when saving and restoring main window state; increment whenever
// new dockables or toolbars are added.
static const int CELESTIA_MAIN_WINDOW_VERSION = 9;
static const int CELESTIA_MAIN_WINDOW_VERSION = 11;
// Terrible hack required because context menu callback doesn't retain
@ -139,7 +139,8 @@ CelestiaAppWindow::CelestiaAppWindow() :
infoPanel(NULL),
eventFinder(NULL),
alerter(NULL),
m_bookmarkManager(NULL)
m_bookmarkManager(NULL),
m_bookmarkToolBar(NULL)
{
setObjectName("celestia-mainwin");
}
@ -279,6 +280,7 @@ void CelestiaAppWindow::init(const QString& qConfigFileName,
infoPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, infoPanel);
infoPanel->setVisible(false);
eventFinder = new EventFinder(m_appCore, tr("Event Finder"), this);
eventFinder->setObjectName("event-finder");
@ -311,30 +313,11 @@ void CelestiaAppWindow::init(const QString& qConfigFileName,
addToolBar(Qt::TopToolBarArea, guidesToolBar);
// Add dockable panels and toolbars to the view menu
viewMenu->addAction(timeToolBar->toggleViewAction());
viewMenu->addAction(guidesToolBar->toggleViewAction());
viewMenu->addSeparator();
viewMenu->addAction(toolsDock->toggleViewAction());
viewMenu->addAction(infoPanel->toggleViewAction());
viewMenu->addAction(eventFinder->toggleViewAction());
viewMenu->addSeparator();
QAction* fullScreenAction = new QAction(tr("Full screen"), this);
fullScreenAction->setCheckable(true);
fullScreenAction->setShortcut(tr("Shift+F11"));
connect(fullScreenAction, SIGNAL(triggered()), this, SLOT(slotToggleFullScreen()));
viewMenu->addAction(fullScreenAction);
// Give keyboard focus to the 3D view
glWidget->setFocus();
readSettings();
// Set the full screen check state only after reading settings
fullScreenAction->setChecked(isFullScreen());
m_bookmarkManager = new BookmarkManager(this);
// Load the bookmarks file and nitialize the bookmarks menu
@ -343,7 +326,33 @@ void CelestiaAppWindow::init(const QString& qConfigFileName,
populateBookmarkMenu();
connect(m_bookmarkManager, SIGNAL(bookmarkTriggered(const QString&)),
this, SLOT(slotBookmarkTriggered(const QString&)));
m_bookmarkToolBar = new BookmarkToolBar(m_bookmarkManager, this);
m_bookmarkToolBar->rebuild();
addToolBar(Qt::TopToolBarArea, m_bookmarkToolBar);
// Build the view menu
// Add dockable panels and toolbars to the view menu
viewMenu->addAction(timeToolBar->toggleViewAction());
viewMenu->addAction(guidesToolBar->toggleViewAction());
viewMenu->addAction(m_bookmarkToolBar->toggleViewAction());
viewMenu->addSeparator();
viewMenu->addAction(toolsDock->toggleViewAction());
viewMenu->addAction(infoPanel->toggleViewAction());
viewMenu->addAction(eventFinder->toggleViewAction());
viewMenu->addSeparator();
QAction* fullScreenAction = new QAction(tr("Full screen"), this);
fullScreenAction->setCheckable(true);
fullScreenAction->setShortcut(tr("Shift+F11"));
// Set the full screen check state only after reading settings
fullScreenAction->setChecked(isFullScreen());
connect(fullScreenAction, SIGNAL(triggered()), this, SLOT(slotToggleFullScreen()));
viewMenu->addAction(fullScreenAction);
// We use a timer with a null timeout value
// to add m_appCore->tick to Qt's event loop
QTimer *t = new QTimer(dynamic_cast<QObject *>(this));
@ -780,6 +789,7 @@ void CelestiaAppWindow::slotAddBookmark()
dialog.exec();
populateBookmarkMenu();
m_bookmarkToolBar->rebuild();
}
@ -789,6 +799,7 @@ void CelestiaAppWindow::slotOrganizeBookmarks()
dialog.exec();
populateBookmarkMenu();
m_bookmarkToolBar->rebuild();
}

View File

@ -28,6 +28,7 @@ class CelestiaActions;
class BookmarkManager;
class BookmarkToolBar;
class QUrl;
class CelestiaAppWindow : public QMainWindow
@ -130,6 +131,8 @@ class CelestiaAppWindow : public QMainWindow
CelestiaCore::Alerter* alerter;
BookmarkManager* m_bookmarkManager;
BookmarkToolBar* m_bookmarkToolBar;
QString m_dataDirPath;
};

View File

@ -186,6 +186,7 @@ BookmarkItem::removeChildren(int index, int count)
//m_children[index + i]->setPosition(0);
}
// TODO: delete the child
m_children.erase(m_children.begin() + index, m_children.begin() + index + count);
}
@ -613,7 +614,7 @@ BookmarkManager::populateBookmarkMenu(QMenu* menu)
QMenu*
BookmarkManager::createBookmarkMenu(QMenu* parent, const BookmarkItem* item)
BookmarkManager::createBookmarkMenu(QWidget* parent, const BookmarkItem* item)
{
QMenu* menu = new QMenu(item->title(), parent);
appendBookmarkMenuItems(menu, item);
@ -665,6 +666,87 @@ BookmarkManager::bookmarkMenuItemTriggered()
}
/*! Return the root folder for the bookmarks menu. */
BookmarkItem*
BookmarkManager::menuRootItem() const
{
// Menu root folder is always the first child of the root
if (m_root != NULL && m_root->childCount() > 0)
return m_root->child(0);
else
return NULL;
}
/*! Return the root folder for the bookmarks tool bar. */
BookmarkItem*
BookmarkManager::toolBarRootItem() const
{
// Tool bar root folder is always the second child of the root
if (m_root != NULL && m_root->childCount() > 1)
return m_root->child(1);
else
return NULL;
}
/***** BookmarkToolBar class *****/
BookmarkToolBar::BookmarkToolBar(BookmarkManager* manager, QWidget* parent) :
QToolBar(parent),
m_manager(manager)
{
setWindowTitle(tr("Bookmarks"));
setObjectName("bookmark-toolbar");
setFloatable(true);
setMovable(true);
setToolButtonStyle(Qt::ToolButtonTextOnly);
}
void
BookmarkToolBar::rebuild()
{
clear();
// Toolbar bookmarks
BookmarkItem* rootItem = m_manager->toolBarRootItem();
if (rootItem != NULL)
{
for (int i = 0; i < rootItem->childCount(); i++)
{
BookmarkItem* child = rootItem->child(i);
switch (child->type())
{
case BookmarkItem::Folder:
if (child->childCount() > 0)
{
QAction* menuAction = new QAction(child->title(), this);
QMenu* menu = m_manager->createBookmarkMenu(this, child);
menuAction->setMenu(menu);
addAction(menuAction);
}
break;
case BookmarkItem::Bookmark:
{
QAction* action = new QAction(child->title(), this);
action->setData(child->url());
connect(action, SIGNAL(triggered()), m_manager, SLOT(bookmarkMenuItemTriggered()));
addAction(action);
}
break;
case BookmarkItem::Separator:
addSeparator();
break;
}
}
}
}
// Proxy model that filters out all items in the bookmark list which
// are not folders.
class OnlyFoldersProxyModel : public QSortFilterProxyModel
@ -681,6 +763,11 @@ public:
BookmarkItem::Type type = static_cast<BookmarkItem::Type>(sourceModel()->data(index, BookmarkTreeModel::TypeRole).toInt());
return type == BookmarkItem::Folder;
}
int columnCount(const QModelIndex& parent) const
{
return qMin(QSortFilterProxyModel::columnCount(parent), 1);
}
};
@ -790,14 +877,18 @@ OrganizeBookmarksDialog::OrganizeBookmarksDialog(BookmarkManager* manager) :
m_manager(manager)
{
setupUi(this);
treeView->setModel(manager->model());
treeView->setSelectionMode(QAbstractItemView::SingleSelection);
treeView->setUniformRowHeights(true);
treeView->setDragEnabled(true);
treeView->setAcceptDrops(true);
treeView->setDragDropMode(QAbstractItemView::InternalMove);
treeView->setDropIndicatorShown(true);
treeView->setModel(manager->model());
treeView->header()->show();
treeView->resizeColumnToContents(0);
}

View File

@ -16,6 +16,7 @@
#include <QString>
#include <QList>
#include <QAbstractItemModel>
#include <QToolBar>
#include "ui/ui_addbookmark.h"
#include "ui/ui_newbookmarkfolder.h"
@ -131,10 +132,13 @@ public:
bool saveBookmarks(QIODevice* device);
void populateBookmarkMenu(QMenu* menu);
QMenu* createBookmarkMenu(QMenu* parent, const BookmarkItem* item);
QMenu* createBookmarkMenu(QWidget* parent, const BookmarkItem* item);
void appendBookmarkMenuItems(QMenu* menu, const BookmarkItem* item);
BookmarkTreeModel* model() const;
BookmarkItem* menuRootItem() const;
BookmarkItem* toolBarRootItem() const;
public slots:
void bookmarkMenuItemTriggered();
@ -148,6 +152,20 @@ private:
};
class BookmarkToolBar : public QToolBar
{
Q_OBJECT
public:
BookmarkToolBar(BookmarkManager *manager, QWidget* parent);
void rebuild();
private:
BookmarkManager* m_manager;
};
class AddBookmarkDialog : public QDialog, Ui_addBookmarkDialog
{
Q_OBJECT