demos/browser/bookmarks.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    70     , m_loaded(false)
    70     , m_loaded(false)
    71     , m_saveTimer(new AutoSaver(this))
    71     , m_saveTimer(new AutoSaver(this))
    72     , m_bookmarkRootNode(0)
    72     , m_bookmarkRootNode(0)
    73     , m_bookmarkModel(0)
    73     , m_bookmarkModel(0)
    74 {
    74 {
    75     connect(this, SIGNAL(entryAdded(BookmarkNode *)),
    75     connect(this, SIGNAL(entryAdded(BookmarkNode*)),
    76             m_saveTimer, SLOT(changeOccurred()));
    76             m_saveTimer, SLOT(changeOccurred()));
    77     connect(this, SIGNAL(entryRemoved(BookmarkNode *, int, BookmarkNode *)),
    77     connect(this, SIGNAL(entryRemoved(BookmarkNode*,int,BookmarkNode*)),
    78             m_saveTimer, SLOT(changeOccurred()));
    78             m_saveTimer, SLOT(changeOccurred()));
    79     connect(this, SIGNAL(entryChanged(BookmarkNode *)),
    79     connect(this, SIGNAL(entryChanged(BookmarkNode*)),
    80             m_saveTimer, SLOT(changeOccurred()));
    80             m_saveTimer, SLOT(changeOccurred()));
    81 }
    81 }
    82 
    82 
    83 BookmarksManager::~BookmarksManager()
    83 BookmarksManager::~BookmarksManager()
    84 {
    84 {
   360 BookmarksModel::BookmarksModel(BookmarksManager *bookmarkManager, QObject *parent)
   360 BookmarksModel::BookmarksModel(BookmarksManager *bookmarkManager, QObject *parent)
   361     : QAbstractItemModel(parent)
   361     : QAbstractItemModel(parent)
   362     , m_endMacro(false)
   362     , m_endMacro(false)
   363     , m_bookmarksManager(bookmarkManager)
   363     , m_bookmarksManager(bookmarkManager)
   364 {
   364 {
   365     connect(bookmarkManager, SIGNAL(entryAdded(BookmarkNode *)),
   365     connect(bookmarkManager, SIGNAL(entryAdded(BookmarkNode*)),
   366             this, SLOT(entryAdded(BookmarkNode *)));
   366             this, SLOT(entryAdded(BookmarkNode*)));
   367     connect(bookmarkManager, SIGNAL(entryRemoved(BookmarkNode *, int, BookmarkNode *)),
   367     connect(bookmarkManager, SIGNAL(entryRemoved(BookmarkNode*,int,BookmarkNode*)),
   368             this, SLOT(entryRemoved(BookmarkNode *, int, BookmarkNode *)));
   368             this, SLOT(entryRemoved(BookmarkNode*,int,BookmarkNode*)));
   369     connect(bookmarkManager, SIGNAL(entryChanged(BookmarkNode *)),
   369     connect(bookmarkManager, SIGNAL(entryChanged(BookmarkNode*)),
   370             this, SLOT(entryChanged(BookmarkNode *)));
   370             this, SLOT(entryChanged(BookmarkNode*)));
   371 }
   371 }
   372 
   372 
   373 QModelIndex BookmarksModel::index(BookmarkNode *node) const
   373 QModelIndex BookmarksModel::index(BookmarkNode *node) const
   374 {
   374 {
   375     BookmarkNode *parent = node->parent();
   375     BookmarkNode *parent = node->parent();
   731 
   731 
   732 BookmarksMenu::BookmarksMenu(QWidget *parent)
   732 BookmarksMenu::BookmarksMenu(QWidget *parent)
   733     : ModelMenu(parent)
   733     : ModelMenu(parent)
   734     , m_bookmarksManager(0)
   734     , m_bookmarksManager(0)
   735 {
   735 {
   736     connect(this, SIGNAL(activated(const QModelIndex &)),
   736     connect(this, SIGNAL(activated(QModelIndex)),
   737             this, SLOT(activated(const QModelIndex &)));
   737             this, SLOT(activated(QModelIndex)));
   738     setMaxRows(-1);
   738     setMaxRows(-1);
   739     setHoverRole(BookmarksModel::UrlStringRole);
   739     setHoverRole(BookmarksModel::UrlStringRole);
   740     setSeparatorRole(BookmarksModel::SeparatorRole);
   740     setSeparatorRole(BookmarksModel::SeparatorRole);
   741 }
   741 }
   742 
   742 
   790     tree->setAlternatingRowColors(true);
   790     tree->setAlternatingRowColors(true);
   791     QFontMetrics fm(font());
   791     QFontMetrics fm(font());
   792     int header = fm.width(QLatin1Char('m')) * 40;
   792     int header = fm.width(QLatin1Char('m')) * 40;
   793     tree->header()->resizeSection(0, header);
   793     tree->header()->resizeSection(0, header);
   794     tree->header()->setStretchLastSection(true);
   794     tree->header()->setStretchLastSection(true);
   795     connect(tree, SIGNAL(activated(const QModelIndex&)),
   795     connect(tree, SIGNAL(activated(QModelIndex)),
   796             this, SLOT(open()));
   796             this, SLOT(open()));
   797     tree->setContextMenuPolicy(Qt::CustomContextMenu);
   797     tree->setContextMenuPolicy(Qt::CustomContextMenu);
   798     connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)),
   798     connect(tree, SIGNAL(customContextMenuRequested(QPoint)),
   799             this, SLOT(customContextMenuRequested(const QPoint &)));
   799             this, SLOT(customContextMenuRequested(QPoint)));
   800     connect(addFolderButton, SIGNAL(clicked()),
   800     connect(addFolderButton, SIGNAL(clicked()),
   801             this, SLOT(newFolder()));
   801             this, SLOT(newFolder()));
   802     expandNodes(m_bookmarksManager->bookmarks());
   802     expandNodes(m_bookmarksManager->bookmarks());
   803     setAttribute(Qt::WA_DeleteOnClose);
   803     setAttribute(Qt::WA_DeleteOnClose);
   804 }
   804 }
   882     , m_bookmarksModel(model)
   882     , m_bookmarksModel(model)
   883 {
   883 {
   884     connect(this, SIGNAL(actionTriggered(QAction*)), this, SLOT(triggered(QAction*)));
   884     connect(this, SIGNAL(actionTriggered(QAction*)), this, SLOT(triggered(QAction*)));
   885     setRootIndex(model->index(0, 0));
   885     setRootIndex(model->index(0, 0));
   886     connect(m_bookmarksModel, SIGNAL(modelReset()), this, SLOT(build()));
   886     connect(m_bookmarksModel, SIGNAL(modelReset()), this, SLOT(build()));
   887     connect(m_bookmarksModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(build()));
   887     connect(m_bookmarksModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(build()));
   888     connect(m_bookmarksModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(build()));
   888     connect(m_bookmarksModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(build()));
   889     connect(m_bookmarksModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(build()));
   889     connect(m_bookmarksModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(build()));
   890     setAcceptDrops(true);
   890     setAcceptDrops(true);
   891 }
   891 }
   892 
   892 
   893 void BookmarksToolBar::dragEnterEvent(QDragEnterEvent *event)
   893 void BookmarksToolBar::dragEnterEvent(QDragEnterEvent *event)
   894 {
   894 {
   954             QToolButton *button = new QToolButton(this);
   954             QToolButton *button = new QToolButton(this);
   955             button->setPopupMode(QToolButton::InstantPopup);
   955             button->setPopupMode(QToolButton::InstantPopup);
   956             button->setArrowType(Qt::DownArrow);
   956             button->setArrowType(Qt::DownArrow);
   957             button->setText(idx.data().toString());
   957             button->setText(idx.data().toString());
   958             ModelMenu *menu = new ModelMenu(this);
   958             ModelMenu *menu = new ModelMenu(this);
   959             connect(menu, SIGNAL(activated(const QModelIndex &)),
   959             connect(menu, SIGNAL(activated(QModelIndex)),
   960                     this, SLOT(activated(const QModelIndex &)));
   960                     this, SLOT(activated(QModelIndex)));
   961             menu->setModel(m_bookmarksModel);
   961             menu->setModel(m_bookmarksModel);
   962             menu->setRootIndex(idx);
   962             menu->setRootIndex(idx);
   963             menu->addAction(new QAction(menu));
   963             menu->addAction(new QAction(menu));
   964             button->setMenu(menu);
   964             button->setMenu(menu);
   965             button->setToolButtonStyle(Qt::ToolButtonTextOnly);
   965             button->setToolButtonStyle(Qt::ToolButtonTextOnly);