From 8c3623e6337fd74c6569d0033ac9824d34b373d4 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 8 Feb 2014 18:14:38 +0100 Subject: [PATCH] [Bookmarks] BookmarksManager now uses new BookmarksTreeView --- src/lib/app/qupzilla.cpp | 1 + src/lib/bookmarks/bookmarks.cpp | 10 + src/lib/bookmarks/bookmarks.h | 3 + src/lib/bookmarks/bookmarksmanager.cpp | 590 +++++++------------------ src/lib/bookmarks/bookmarksmanager.h | 57 +-- src/lib/bookmarks/bookmarksmanager.ui | 138 +++--- src/lib/bookmarks/bookmarksmodel.cpp | 26 +- src/lib/bookmarks/bookmarksmodel.h | 4 +- src/lib/lib.pro | 6 +- 9 files changed, 270 insertions(+), 565 deletions(-) diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index 01baa869b..648d28c36 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -1514,6 +1514,7 @@ void QupZilla::loadFolderBookmarks(Menu* menu) void QupZilla::loadAddress(const QUrl &url) { + // TOOD: If current tab is pinned, it should open new tab instead weView()->setFocus(); weView()->load(url); } diff --git a/src/lib/bookmarks/bookmarks.cpp b/src/lib/bookmarks/bookmarks.cpp index 59b4643e5..713edd049 100644 --- a/src/lib/bookmarks/bookmarks.cpp +++ b/src/lib/bookmarks/bookmarks.cpp @@ -748,6 +748,11 @@ QString Bookmarks::fromTranslatedFolder(const QString &name) return folder; } +BookmarksModel* Bookmarks::model() const +{ + return m_model; +} + BookmarkItem* Bookmarks::rootItem() const { return m_root; @@ -765,6 +770,11 @@ bool Bookmarks::removeBookmark(BookmarkItem* item) return true; } +void Bookmarks::notifyBookmarkChanged(BookmarkItem* item) +{ + emit bookmarkChanged(item); +} + bool Bookmarks::canBeModified(BookmarkItem* item) const { return item != m_root && item != m_folderToolbar && item != m_folderMenu && item != m_folderUnsorted; diff --git a/src/lib/bookmarks/bookmarks.h b/src/lib/bookmarks/bookmarks.h index 658f34e8d..bd116d616 100644 --- a/src/lib/bookmarks/bookmarks.h +++ b/src/lib/bookmarks/bookmarks.h @@ -99,6 +99,7 @@ public: static QString toTranslatedFolder(const QString &name); static QString fromTranslatedFolder(const QString &name); + BookmarksModel* model() const; BookmarkItem* rootItem() const; bool canBeModified(BookmarkItem* item) const; @@ -106,6 +107,8 @@ public: void insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item); bool removeBookmark(BookmarkItem* item); + void notifyBookmarkChanged(BookmarkItem* item); + signals: void bookmarkAdded(const Bookmarks::Bookmark &bookmark); void bookmarkDeleted(const Bookmarks::Bookmark &bookmark); diff --git a/src/lib/bookmarks/bookmarksmanager.cpp b/src/lib/bookmarks/bookmarksmanager.cpp index ecc1a197b..d210af618 100644 --- a/src/lib/bookmarks/bookmarksmanager.cpp +++ b/src/lib/bookmarks/bookmarksmanager.cpp @@ -30,6 +30,8 @@ #include "iconchooser.h" #include "webtab.h" #include "qzsettings.h" +#include "bookmarkstree.h" +#include "bookmarkitem.h" #include #include @@ -39,14 +41,31 @@ #include #include +#include + BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) : QWidget(parent) - , m_isRefreshing(false) , ui(new Ui::BookmarksManager) , p_QupZilla(mainClass) , m_bookmarks(mApp->bookmarks()) + , m_blockDescriptionChangedSignal(false) { ui->setupUi(this); + + connect(ui->tree, SIGNAL(bookmarkActivated(BookmarkItem*)), this, SLOT(bookmarkActivated(BookmarkItem*))); + connect(ui->tree, SIGNAL(bookmarkCtrlActivated(BookmarkItem*)), this, SLOT(bookmarkCtrlActivated(BookmarkItem*))); + connect(ui->tree, SIGNAL(bookmarkShiftActivated(BookmarkItem*)), this, SLOT(bookmarkShiftActivated(BookmarkItem*))); + connect(ui->tree, SIGNAL(bookmarksSelected(QList)), this, SLOT(bookmarksSelected(QList))); + + // Disable edit box + updateEditBox(0); + + connect(ui->title, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited())); + connect(ui->address, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited())); + connect(ui->keyword, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited())); + connect(ui->description, SIGNAL(textChanged()), this, SLOT(descriptionEdited())); + +#if 0 ui->bookmarksTree->setViewType(BookmarksTree::ManagerView); ui->bookmarksTree->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -82,6 +101,72 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded); ui->bookmarksTree->sortByColumn(-1); +#endif +} + +BookmarksManager::~BookmarksManager() +{ + delete ui; +} + +void BookmarksManager::bookmarkActivated(BookmarkItem* item) +{ + // TODO: Open all children in tabs for folder? + if (item->type() != BookmarkItem::Url) { + return; + } + + getQupZilla()->loadAddress(item->url()); +} + +void BookmarksManager::bookmarkCtrlActivated(BookmarkItem* item) +{ + if (item->type() != BookmarkItem::Url) { + return; + } + + getQupZilla()->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition); +} + +void BookmarksManager::bookmarkShiftActivated(BookmarkItem* item) +{ + if (item->type() != BookmarkItem::Url) { + return; + } + + mApp->makeNewWindow(Qz::BW_NewWindow, item->url()); +} + +void BookmarksManager::bookmarksSelected(const QList &items) +{ + if (items.size() != 1) { + updateEditBox(0); + } + else { + updateEditBox(items.first()); + } +} + +void BookmarksManager::bookmarkEdited() +{ + Q_ASSERT(ui->tree->selectedBookmarks().count() == 1); + + BookmarkItem* item = ui->tree->selectedBookmarks().first(); + item->setTitle(ui->title->text()); + item->setUrl(QUrl::fromEncoded(ui->address->text().toUtf8())); + item->setKeyword(ui->keyword->text()); + item->setDescription(ui->description->toPlainText()); + + m_bookmarks->notifyBookmarkChanged(item); +} + +void BookmarksManager::descriptionEdited() +{ + // There is no textEdited() signal in QPlainTextEdit + // textChanged() is emitted also when text is changed programatically + if (!m_blockDescriptionChangedSignal) { + bookmarkEdited(); + } } void BookmarksManager::importBookmarks() @@ -99,9 +184,61 @@ void BookmarksManager::exportBookmarks() } } -void BookmarksManager::search(const QString &string) +void BookmarksManager::updateEditBox(BookmarkItem* item) { - ui->bookmarksTree->filterString(string); + setUpdatesEnabled(false); + m_blockDescriptionChangedSignal = true; + + bool editable = item && item->type() != BookmarkItem::Separator && m_bookmarks->canBeModified(item); + bool showAddressAndKeyword = item && item->type() == BookmarkItem::Url; + bool clearBox = !item; + + if (clearBox) { + ui->title->clear(); + ui->address->clear(); + ui->keyword->clear(); + ui->description->clear(); + + ui->title->setReadOnly(true); + ui->address->setReadOnly(true); + ui->keyword->setReadOnly(true); + ui->description->setReadOnly(true); + } + else { + ui->title->setText(item->title()); + ui->address->setText(item->url().toEncoded()); + ui->keyword->setText(item->keyword()); + ui->description->setPlainText(item->description()); + } + + ui->title->setReadOnly(!editable); + ui->address->setReadOnly(!editable); + ui->keyword->setReadOnly(!editable); + ui->description->setReadOnly(!editable); + + ui->labelAddress->setVisible(showAddressAndKeyword); + ui->address->setVisible(showAddressAndKeyword); + ui->labelKeyword->setVisible(showAddressAndKeyword); + ui->keyword->setVisible(showAddressAndKeyword); + + // Without removing widgets from layout, there is unwanted extra spacing + QFormLayout* l = static_cast(ui->editBox->layout()); + + if (showAddressAndKeyword) { + // Show Address + Keyword + l->insertRow(1, ui->labelAddress, ui->address); + l->insertRow(2, ui->labelKeyword, ui->keyword); + } + else { + // Hide Address + Keyword + l->removeWidget(ui->labelAddress); + l->removeWidget(ui->labelKeyword); + l->removeWidget(ui->address); + l->removeWidget(ui->keyword); + } + + m_blockDescriptionChangedSignal = false; + setUpdatesEnabled(true); } QupZilla* BookmarksManager::getQupZilla() @@ -119,136 +256,7 @@ void BookmarksManager::setMainWindow(QupZilla* window) } } -void BookmarksManager::addFolder(QWidget* parent, QString* folder, bool showInsertDialog, - const QString &bookmarkTitle, WebView* view) -{ - BookmarksTree* bookmarksTree = qobject_cast(sender()); - QDialog dialog(parent ? parent : this); - dialog.setWindowTitle(tr("Add new folder")); - QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, &dialog); - QLabel* labelParent = new QLabel(tr("Choose parent folder for new folder: "), &dialog); - QComboBox* combo = new QComboBox(&dialog); - combo->addItem(qIconProvider->fromTheme("bookmarks-organize"), tr("Bookmarks"), "NO_PARENT"); - combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar"); - combo->setCurrentIndex(0); - QLabel* labelFolder = new QLabel(tr("Choose name for new bookmark folder: "), &dialog); - QLineEdit* edit = new QLineEdit(&dialog); - QDialogButtonBox* box = new QDialogButtonBox(&dialog); - box->addButton(QDialogButtonBox::Ok); - box->addButton(QDialogButtonBox::Cancel); - connect(box, SIGNAL(rejected()), &dialog, SLOT(reject())); - connect(box, SIGNAL(accepted()), &dialog, SLOT(accept())); - layout->addWidget(labelParent); - layout->addWidget(combo); - layout->addWidget(labelFolder); - layout->addWidget(edit); - layout->addWidget(box); - dialog.exec(); - if (dialog.result() == QDialog::Rejected) { - return; - } - QString text = edit->text(); - if (text.isEmpty()) { - return; - } - - bool created = false; - if (combo->itemData(combo->currentIndex()).toString() == "bookmarksToolbar") { - created = m_bookmarks->createSubfolder(text); - } - else { - created = m_bookmarks->createFolder(text); - } - if (folder) { - *folder = (created ? text : ""); - } - - if (created && bookmarksTree && bookmarksTree->viewType() == BookmarksTree::ComboFolderView) { - bookmarksTree->refreshTree(); - } - - if (showInsertDialog) { - insertBookmark(view->url(), bookmarkTitle, view->icon(), created ? text : ""); - } -} - -void BookmarksManager::addSubfolder() -{ - QString text = QInputDialog::getText(this, tr("Add new subfolder"), tr("Choose name for new subfolder in bookmarks toolbar: ")); - if (text.isEmpty()) { - return; - } - - m_bookmarks->createSubfolder(text); -} - -void BookmarksManager::renameFolder() -{ - QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) { - return; - } - - if (!item->text(1).isEmpty()) { - return; - } - - QString folder = item->text(0); - - if (folder == _bookmarksMenu || folder == _bookmarksToolbar) { - return; - } - - QString text = QInputDialog::getText(this, tr("Rename Folder"), tr("Choose name for folder: "), QLineEdit::Normal, folder); - if (text.isEmpty()) { - return; - } - - m_bookmarks->renameFolder(folder, text); -} - -void BookmarksManager::renameBookmark() -{ - QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) { - return; - } - - ui->bookmarksTree->editItem(item, 0); -} - -void BookmarksManager::changeIcon() -{ - QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) { - return; - } - - int id = item->data(0, Qt::UserRole + 10).toInt(); - QIcon icon; - - IconChooser chooser(this); - icon = chooser.getIcon(); - - if (!icon.isNull()) { - m_bookmarks->changeIcon(id, icon); - } -} - -void BookmarksManager::itemChanged(QTreeWidgetItem* item) -{ - if (!item || m_isRefreshing || item->text(1).isEmpty()) { - return; - } - - QString name = item->text(0); - QUrl url = QUrl::fromEncoded(item->text(1).toUtf8()); - int id = item->data(0, Qt::UserRole + 10).toInt(); - - ui->bookmarksTree->deleteItem(item); - m_bookmarks->editBookmark(id, name, url, QString()); -} - +#if 0 void BookmarksManager::itemControlClicked(QTreeWidgetItem* item) { if (!item || item->text(1).isEmpty()) { @@ -271,47 +279,6 @@ void BookmarksManager::loadInNewTab() getQupZilla()->tabWidget()->addView(action->data().toUrl(), item->text(0), qzSettings->newTabPosition); } -void BookmarksManager::deleteItem() -{ - QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) { - return; - } - - QApplication::setOverrideCursor(Qt::WaitCursor); - - if (item->text(1).isEmpty()) { // Delete folder - QString folder = item->text(0); - m_bookmarks->removeFolder(folder); - - QApplication::restoreOverrideCursor(); - return; - } - - int id = item->data(0, Qt::UserRole + 10).toInt(); - m_bookmarks->removeBookmark(id); - QApplication::restoreOverrideCursor(); -} - -void BookmarksManager::addBookmark(WebView* view) -{ - insertBookmark(view->url(), view->title(), view->icon()); -} - -void BookmarksManager::moveBookmark() -{ - QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) { - return; - } - - if (QAction* action = qobject_cast(sender())) { - int id = item->data(0, Qt::UserRole + 10).toInt(); - - m_bookmarks->editBookmark(id, item->text(0), QUrl(), action->data().toString()); - } -} - void BookmarksManager::contextMenuRequested(const QPoint &position) { if (!ui->bookmarksTree->itemAt(position)) { @@ -370,268 +337,13 @@ void BookmarksManager::contextMenuRequested(const QPoint &position) QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } +#endif -void BookmarksManager::refreshTable() +// OLD + +void BookmarksManager::addBookmark(WebView* view) { - m_isRefreshing = true; - ui->bookmarksTree->refreshTree(); - m_isRefreshing = false; -} - -void BookmarksManager::addBookmark(const Bookmarks::Bookmark &bookmark) -{ - m_isRefreshing = true; - QString translatedFolder = Bookmarks::toTranslatedFolder(bookmark.folder); - QTreeWidgetItem* item = new QTreeWidgetItem(); - item->setText(0, bookmark.title); - item->setText(1, bookmark.url.toEncoded()); - item->setData(0, Qt::UserRole + 10, bookmark.id); - item->setData(0, Qt::UserRole + 11, bookmark.url); - item->setIcon(0, qIconProvider->iconFromImage(bookmark.image)); - item->setToolTip(0, bookmark.title); - item->setToolTip(1, bookmark.url.toEncoded()); - item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - - if (bookmark.inSubfolder) { - QList list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { - if (it->text(1).isEmpty()) { - it->addChild(item); - break; - } - } - } - } - else if (bookmark.folder != QLatin1String("unsorted")) { - ui->bookmarksTree->appendToParentItem(translatedFolder, item); - } - else { - ui->bookmarksTree->addTopLevelItem(item); - } - m_isRefreshing = false; -} - -void BookmarksManager::removeBookmark(const Bookmarks::Bookmark &bookmark) -{ - m_isRefreshing = true; - - if (bookmark.inSubfolder) { - QList list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive); - QTreeWidgetItem* subfolderItem = 0; - if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { - if (it->text(1).isEmpty()) { - subfolderItem = it; - break; - } - } - } - if (!subfolderItem) { - return; - } - - for (int i = 0; i < subfolderItem->childCount(); i++) { - QTreeWidgetItem* item = subfolderItem->child(i); - if (!item) { - continue; - } - - int id = item->data(0, Qt::UserRole + 10).toInt(); - - if (item->text(0) == bookmark.title && id == bookmark.id) { - ui->bookmarksTree->deleteItem(item); - return; - } - } - } - else if (bookmark.folder == QLatin1String("unsorted")) { - QList list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly); - if (list.count() == 0) { - return; - } - QTreeWidgetItem* item = list.at(0); - int id = item->data(0, Qt::UserRole + 10).toInt(); - - if (id == bookmark.id) { - ui->bookmarksTree->deleteItem(item); - } - } - else { - QList list = ui->bookmarksTree->findItems(Bookmarks::toTranslatedFolder(bookmark.folder), Qt::MatchExactly); - if (list.count() == 0) { - return; - } - QTreeWidgetItem* parentItem = list.at(0); - if (!parentItem) { - return; - } - for (int i = 0; i < parentItem->childCount(); i++) { - QTreeWidgetItem* item = parentItem->child(i); - if (!item) { - continue; - } - - int id = item->data(0, Qt::UserRole + 10).toInt(); - - if (item->text(0) == bookmark.title && id == bookmark.id) { - ui->bookmarksTree->deleteItem(item); - return; - } - } - } - m_isRefreshing = false; -} - -void BookmarksManager::bookmarkEdited(const Bookmarks::Bookmark &before, const Bookmarks::Bookmark &after) -{ - removeBookmark(before); - addBookmark(after); -} - -void BookmarksManager::changeBookmarkParent(const QString &name, const QByteArray &, int id, - const QUrl &, const QString &, const QString &newParent) -{ - QList list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive); - - QTreeWidgetItem* item = 0; - foreach (item, list) { - if (id == item->data(0, Qt::UserRole + 10).toInt()) { - break; - } - } - if (!item || id != item->data(0, Qt::UserRole + 10).toInt()) { - return; - } - - item->parent() ? item->parent()->removeChild(item) : ui->bookmarksTree->invisibleRootItem()->removeChild(item); - - QTreeWidgetItem* parent = 0; - if (newParent.isEmpty() || newParent == QLatin1String("unsorted")) { - parent = ui->bookmarksTree->invisibleRootItem(); - } - - if (!parent) { - list = ui->bookmarksTree->findItems(newParent, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() == 0) { - return; - } - parent = list.at(0); - if (!parent) { - return; - } - } - parent->addChild(item); -} - -void BookmarksManager::changeFolderParent(const QString &name, bool isSubfolder) -{ - QList list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive); - - if (list.count() == 0) { - return; - } - - QTreeWidgetItem* item = list.at(0); - if (!item) { - return; - } - - item->parent() ? item->parent()->removeChild(item) : ui->bookmarksTree->invisibleRootItem()->removeChild(item); - - QTreeWidgetItem* parent = 0; - if (isSubfolder) { - list = ui->bookmarksTree->findItems(_bookmarksToolbar, Qt::MatchExactly); - if (!list.isEmpty() && list.at(0)) { - parent = list.at(0); - } - } - else { - parent = ui->bookmarksTree->invisibleRootItem(); - } - if (!parent) { - return; - } - parent->addChild(item); -} - -void BookmarksManager::addFolder(const QString &name) -{ - m_isRefreshing = true; - - QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree); - item->setText(0, name); - item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - - if (name != _bookmarksToolbar && name != _bookmarksMenu) { - item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - } - else { - item->setFlags((item->flags() & ~Qt::ItemIsDragEnabled) | Qt::ItemIsDropEnabled); - } - - m_isRefreshing = false; -} - -void BookmarksManager::addSubfolder(const QString &name) -{ - m_isRefreshing = true; - - QList list = ui->bookmarksTree->findItems(_bookmarksToolbar, Qt::MatchExactly); - if (list.count() != 0) { - QTreeWidgetItem* item = new QTreeWidgetItem(list.at(0)); - item->setText(0, name); - item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - } - - m_isRefreshing = false; -} - -void BookmarksManager::removeFolder(const QString &name) -{ - QList list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() == 0) { - return; - } - - QTreeWidgetItem* folderItem = 0; - if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { - if (it->text(1).isEmpty()) { - folderItem = it; - break; - } - } - } - if (!folderItem) { - return; - } - - ui->bookmarksTree->deleteItem(folderItem); -} - -void BookmarksManager::renameFolder(const QString &before, const QString &after) -{ - QList list = ui->bookmarksTree->findItems(before, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() == 0) { - return; - } - - QTreeWidgetItem* folderItem = 0; - if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { - if (it->text(0) == before && it->text(1).isEmpty()) { - folderItem = it; - break; - } - } - } - if (!folderItem) { - return; - } - - folderItem->setText(0, after); + insertBookmark(view->url(), view->title(), view->icon()); } void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder) @@ -704,6 +416,12 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, con delete dialog; } +void BookmarksManager::search(const QString &string) +{ + Q_UNUSED(string) + //ui->bookmarksTree->filterString(string); +} + void BookmarksManager::insertAllTabs() { QDialog* dialog = new QDialog(getQupZilla()); @@ -766,7 +484,3 @@ void BookmarksManager::insertAllTabs() delete dialog; } -BookmarksManager::~BookmarksManager() -{ - delete ui; -} diff --git a/src/lib/bookmarks/bookmarksmanager.h b/src/lib/bookmarks/bookmarksmanager.h index ebd41f889..3d9e3dc56 100644 --- a/src/lib/bookmarks/bookmarksmanager.h +++ b/src/lib/bookmarks/bookmarksmanager.h @@ -21,7 +21,6 @@ #include #include -#include "bookmarks.h" #include "qz_namespace.h" namespace Ui @@ -29,11 +28,13 @@ namespace Ui class BookmarksManager; } -class QTreeWidgetItem; +class QUrl; class WebView; class QupZilla; class Bookmarks; +class BookmarkItem; + class QT_QUPZILLA_EXPORT BookmarksManager : public QWidget { Q_OBJECT @@ -41,52 +42,38 @@ class QT_QUPZILLA_EXPORT BookmarksManager : public QWidget public: explicit BookmarksManager(QupZilla* mainClass, QWidget* parent = 0); ~BookmarksManager(); - void addBookmark(WebView* view); - void insertBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder = QString()); - void setMainWindow(QupZilla* window); - - void search(const QString &string); public slots: - void refreshTable(); - void insertAllTabs(); private slots: - void deleteItem(); - void itemChanged(QTreeWidgetItem* item); - void addSubfolder(); - void addFolder(QWidget* parent = 0, QString* folder = 0, bool showInsertDialog = false, - const QString &bookmarkTitle = QString(), WebView* = 0); - void renameFolder(); - void contextMenuRequested(const QPoint &position); - void loadInNewTab(); - void itemControlClicked(QTreeWidgetItem* item); - void moveBookmark(); - void renameBookmark(); - void changeIcon(); + void bookmarkActivated(BookmarkItem* item); + void bookmarkCtrlActivated(BookmarkItem* item); + void bookmarkShiftActivated(BookmarkItem* item); + void bookmarksSelected(const QList &items); + + void bookmarkEdited(); + void descriptionEdited(); void importBookmarks(); void exportBookmarks(); - void addFolder(const QString &name); - void addSubfolder(const QString &name); - void removeFolder(const QString &name); - void renameFolder(const QString &before, const QString &after); - - void addBookmark(const Bookmarks::Bookmark &bookmark); - void removeBookmark(const Bookmarks::Bookmark &bookmark); - void bookmarkEdited(const Bookmarks::Bookmark &before, const Bookmarks::Bookmark &after); - - void changeBookmarkParent(const QString &name, const QByteArray &, int id, - const QUrl &, const QString &, const QString &newParent); - void changeFolderParent(const QString &name, bool isSubfolder); - private: + void updateEditBox(BookmarkItem* item); + QupZilla* getQupZilla(); - bool m_isRefreshing; Ui::BookmarksManager* ui; QPointer p_QupZilla; + Bookmarks* m_bookmarks; + bool m_blockDescriptionChangedSignal; + +public: + void addBookmark(WebView* view); + void insertBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder = QString()); + void setMainWindow(QupZilla* window); + void search(const QString &string); + void insertAllTabs(); + void refreshTable() {} }; #endif // BOOKMARKSMANAGER_H diff --git a/src/lib/bookmarks/bookmarksmanager.ui b/src/lib/bookmarks/bookmarksmanager.ui index 204337552..875c5d996 100644 --- a/src/lib/bookmarks/bookmarksmanager.ui +++ b/src/lib/bookmarks/bookmarksmanager.ui @@ -13,84 +13,82 @@ Bookmarks - - - - - Add Folder - - + + + - - - - Collapse All - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::CustomContextMenu - - - true - - - QAbstractItemView::ContiguousSelection - - - true - - - 330 - - - - Title - - - - - Url - - - - - - - - Expand All - - - - - - - Import and Export + + + + + 0 + 0 + + + + + + Title: + + + + + + + + + + Address: + + + + + + + + + + Keyword: + + + + + + + + + + Description + + + + + + + + 0 + 50 + + + + + 16777215 + 50 + + + + + - BookmarksTree - QTreeWidget -
bookmarkstree.h
+ BookmarksTreeView + QTreeView +
bookmarkstreeview.h
diff --git a/src/lib/bookmarks/bookmarksmodel.cpp b/src/lib/bookmarks/bookmarksmodel.cpp index 9e77ff61d..8e5af90f1 100644 --- a/src/lib/bookmarks/bookmarksmodel.cpp +++ b/src/lib/bookmarks/bookmarksmodel.cpp @@ -24,10 +24,9 @@ #include #include -//#define BOOKMARKSMODEL_DEBUG +#define BOOKMARKSMODEL_DEBUG #ifdef BOOKMARKSMODEL_DEBUG -#include #include "modeltest.h" #endif @@ -39,15 +38,6 @@ BookmarksModel::BookmarksModel(Bookmarks* bookmarks, QObject* parent) #ifdef BOOKMARKSMODEL_DEBUG new ModelTest(this, this); - - QTreeView* view = new QTreeView; - view->setModel(this); - view->setSelectionMode(QAbstractItemView::ExtendedSelection); - view->setDragEnabled(true); - view->setAcceptDrops(true); - view->setDropIndicatorShown(true); - view->expandAll(); - view->show(); #endif } @@ -123,7 +113,7 @@ QVariant BookmarksModel::data(const QModelIndex &index, int role) const case 0: return itm->title(); case 1: - return itm->url(); + return itm->url().toEncoded(); default: return QVariant(); } @@ -324,14 +314,14 @@ QModelIndex BookmarksModel::index(BookmarkItem* item) const return createIndex(parent->children().indexOf(item), 0, item); } -void BookmarksModel::bookmarkChanged(BookmarkItem* item) -{ - QModelIndex idx = index(item); - emit dataChanged(idx, idx); -} - BookmarkItem* BookmarksModel::item(const QModelIndex &index) const { BookmarkItem* itm = static_cast(index.internalPointer()); return itm ? itm : m_bookmarks->rootItem(); } + +void BookmarksModel::bookmarkChanged(BookmarkItem* item) +{ + QModelIndex idx = index(item); + emit dataChanged(idx, idx); +} diff --git a/src/lib/bookmarks/bookmarksmodel.h b/src/lib/bookmarks/bookmarksmodel.h index 12a7ff6ea..14f950b7a 100644 --- a/src/lib/bookmarks/bookmarksmodel.h +++ b/src/lib/bookmarks/bookmarksmodel.h @@ -61,6 +61,8 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(BookmarkItem* item) const; + BookmarkItem* item(const QModelIndex &index) const; + #if 0 bool removeRows(int row, int count, const QModelIndex &parent); #endif @@ -69,8 +71,6 @@ private slots: void bookmarkChanged(BookmarkItem* item); private: - BookmarkItem* item(const QModelIndex &index) const; - Bookmarks* m_bookmarks; }; diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 6fa15e064..89cd9633d 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -255,7 +255,8 @@ SOURCES += \ bookmarks/bookmarks.cpp \ bookmarks/bookmarkitem.cpp \ tools/json.cpp \ - bookmarks/bookmarksmodel.cpp + bookmarks/bookmarksmodel.cpp \ + bookmarks/bookmarkstreeview.cpp HEADERS += \ @@ -446,7 +447,8 @@ HEADERS += \ bookmarks/bookmarks.h \ bookmarks/bookmarkitem.h \ tools/json.h \ - bookmarks/bookmarksmodel.h + bookmarks/bookmarksmodel.h \ + bookmarks/bookmarkstreeview.h FORMS += \ preferences/autofillmanager.ui \