From 2ea155560a28c8c252f66ea94ad3a2b35e4d3015 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 9 Feb 2014 12:22:49 +0100 Subject: [PATCH] [Bookmarks] Removed BookmarksTree and renamed BookmarkIcon -> BookmarksIcon --- .../{bookmarkicon.cpp => bookmarksicon.cpp} | 22 +- .../{bookmarkicon.h => bookmarksicon.h} | 10 +- src/lib/bookmarks/bookmarkstree.cpp | 240 ------------------ src/lib/bookmarks/bookmarkstree.h | 58 ----- src/lib/lib.pro | 10 +- src/lib/navigation/locationbar.cpp | 4 +- src/lib/navigation/locationbar.h | 4 +- src/lib/popupwindow/popuplocationbar.cpp | 4 +- src/lib/popupwindow/popuplocationbar.h | 4 +- 9 files changed, 28 insertions(+), 328 deletions(-) rename src/lib/bookmarks/{bookmarkicon.cpp => bookmarksicon.cpp} (85%) rename src/lib/bookmarks/{bookmarkicon.h => bookmarksicon.h} (88%) delete mode 100644 src/lib/bookmarks/bookmarkstree.cpp delete mode 100644 src/lib/bookmarks/bookmarkstree.h diff --git a/src/lib/bookmarks/bookmarkicon.cpp b/src/lib/bookmarks/bookmarksicon.cpp similarity index 85% rename from src/lib/bookmarks/bookmarkicon.cpp rename to src/lib/bookmarks/bookmarksicon.cpp index edcf09073..4301228f3 100644 --- a/src/lib/bookmarks/bookmarkicon.cpp +++ b/src/lib/bookmarks/bookmarksicon.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ -#include "bookmarkicon.h" +#include "bookmarksicon.h" #include "bookmarkswidget.h" #include "bookmarks.h" #include "mainapplication.h" @@ -27,7 +27,7 @@ #include #include -BookmarkIcon::BookmarkIcon(QWidget* parent) +BookmarksIcon::BookmarksIcon(QWidget* parent) : ClickableLabel(parent) , m_view(0) , m_bookmark(0) @@ -45,12 +45,12 @@ BookmarkIcon::BookmarkIcon(QWidget* parent) connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked())); } -void BookmarkIcon::setWebView(WebView* view) +void BookmarksIcon::setWebView(WebView* view) { m_view = view; } -void BookmarkIcon::checkBookmark(const QUrl &url, bool forceCheck) +void BookmarksIcon::checkBookmark(const QUrl &url, bool forceCheck) { if (!forceCheck && m_lastUrl == url) { return; @@ -69,17 +69,17 @@ void BookmarkIcon::checkBookmark(const QUrl &url, bool forceCheck) m_lastUrl = url; } -void BookmarkIcon::bookmarksChanged() +void BookmarksIcon::bookmarksChanged() { checkBookmark(m_lastUrl, true); } -void BookmarkIcon::speedDialChanged() +void BookmarksIcon::speedDialChanged() { checkBookmark(m_lastUrl, true); } -void BookmarkIcon::iconClicked() +void BookmarksIcon::iconClicked() { if (!m_view || m_view->url().scheme() == QLatin1String("qupzilla")) { return; @@ -89,7 +89,7 @@ void BookmarkIcon::iconClicked() widget->showAt(parentWidget()); } -void BookmarkIcon::setBookmarkSaved() +void BookmarksIcon::setBookmarkSaved() { setProperty("bookmarked", QVariant(true)); style()->unpolish(this); @@ -97,7 +97,7 @@ void BookmarkIcon::setBookmarkSaved() setToolTip(tr("Edit this bookmark")); } -void BookmarkIcon::setBookmarkDisabled() +void BookmarksIcon::setBookmarkDisabled() { setProperty("bookmarked", QVariant(false)); style()->unpolish(this); @@ -105,13 +105,13 @@ void BookmarkIcon::setBookmarkDisabled() setToolTip(tr("Bookmark this Page")); } -void BookmarkIcon::contextMenuEvent(QContextMenuEvent* ev) +void BookmarksIcon::contextMenuEvent(QContextMenuEvent* ev) { // Prevent propagating to LocationBar ev->accept(); } -void BookmarkIcon::mousePressEvent(QMouseEvent* ev) +void BookmarksIcon::mousePressEvent(QMouseEvent* ev) { ClickableLabel::mousePressEvent(ev); diff --git a/src/lib/bookmarks/bookmarkicon.h b/src/lib/bookmarks/bookmarksicon.h similarity index 88% rename from src/lib/bookmarks/bookmarkicon.h rename to src/lib/bookmarks/bookmarksicon.h index 7cbb5be3c..2013b2244 100644 --- a/src/lib/bookmarks/bookmarkicon.h +++ b/src/lib/bookmarks/bookmarksicon.h @@ -15,8 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ -#ifndef BOOKMARKICON_H -#define BOOKMARKICON_H +#ifndef BOOKMARKSICON_H +#define BOOKMARKSICON_H #include @@ -26,11 +26,11 @@ class WebView; class BookmarkItem; -class QT_QUPZILLA_EXPORT BookmarkIcon : public ClickableLabel +class QT_QUPZILLA_EXPORT BookmarksIcon : public ClickableLabel { Q_OBJECT public: - explicit BookmarkIcon(QWidget* parent = 0); + explicit BookmarksIcon(QWidget* parent = 0); void setWebView(WebView* view); void checkBookmark(const QUrl &url, bool forceCheck = false); @@ -53,4 +53,4 @@ private: QUrl m_lastUrl; }; -#endif // BOOKMARKICON_H +#endif // BOOKMARKSICON_H diff --git a/src/lib/bookmarks/bookmarkstree.cpp b/src/lib/bookmarks/bookmarkstree.cpp deleted file mode 100644 index 99e750158..000000000 --- a/src/lib/bookmarks/bookmarkstree.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2012-2014 S. Razi Alavizadeh -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ - -#include "bookmarkstree.h" -#include "iconprovider.h" -#include "bookmarks.h" - -#include -#include - -BookmarksTree::BookmarksTree(QWidget* parent) - : TreeWidget(parent) - , m_viewType(ManagerView) -{ -} - -void BookmarksTree::setViewType(BookmarksTree::BookmarkView viewType) -{ - if (viewType != m_viewType) { - if (m_viewType == ComboFolderView) { - setItemsExpandable(true); - setRootIsDecorated(true); - setIndentation(20); //QTreeView default indentation - } - else if (viewType == ComboFolderView) { - setItemsExpandable(false); - setRootIsDecorated(false); - setIndentation(10); - } - m_viewType = viewType; - } -} - -void BookmarksTree::drawBranches(QPainter* painter, const QRect &rect, const QModelIndex &index) const -{ - if (m_viewType == ComboFolderView) { - return; - } - - TreeWidget::drawBranches(painter, rect, index); -} - -void BookmarksTree::refreshTree() -{ - setUpdatesEnabled(false); - clear(); - - QSqlQuery query; - QTreeWidgetItem* rootItem = invisibleRootItem(); - if (m_viewType == ExportFolderView) { - rootItem = new QTreeWidgetItem(this); - rootItem->setText(0, tr("Bookmarks")); - rootItem->setIcon(0, qIconProvider->fromTheme("bookmarks-organize")); - addTopLevelItem(rootItem); - } - - if (m_viewType == ComboFolderView) { - QTreeWidgetItem* newItem = new QTreeWidgetItem(rootItem); - newItem->setText(0, _bookmarksUnsorted); - newItem->setData(0, Qt::UserRole, "unsorted"); - newItem->setIcon(0, QIcon(":/icons/theme/unsortedbookmarks.png")); - addTopLevelItem(newItem); - } - - QTreeWidgetItem* newItem = new QTreeWidgetItem(rootItem); - newItem->setText(0, _bookmarksMenu); - newItem->setData(0, Qt::UserRole, "bookmarksMenu"); - newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - if (m_viewType != ComboFolderView) { - newItem->setFlags((newItem->flags() & ~Qt::ItemIsDragEnabled) | Qt::ItemIsDropEnabled); - } - addTopLevelItem(newItem); - - QTreeWidgetItem* bookmarksToolbar = 0; - if (m_viewType != SideBarView) { - bookmarksToolbar = new QTreeWidgetItem(rootItem); - bookmarksToolbar->setText(0, _bookmarksToolbar); - bookmarksToolbar->setData(0, Qt::UserRole, "bookmarksToolbar"); - bookmarksToolbar->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - if (m_viewType != ComboFolderView) { - bookmarksToolbar->setFlags((bookmarksToolbar->flags() & ~Qt::ItemIsDragEnabled) - | Qt::ItemIsDropEnabled); - } - addTopLevelItem(bookmarksToolbar); - } - - query.exec("SELECT name FROM folders WHERE subfolder!='yes'"); - while (query.next()) { - newItem = new QTreeWidgetItem(rootItem); - newItem->setText(0, query.value(0).toString()); - newItem->setData(0, Qt::UserRole, query.value(0).toString()); - newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - newItem->setFlags(newItem->flags() | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled); - addTopLevelItem(newItem); - } - if (m_viewType == ComboFolderView) { - QTreeWidgetItem* newFolder = new QTreeWidgetItem(rootItem); - newFolder->setText(0, tr("New Folder...")); - newFolder->setData(0, Qt::UserRole + 12, "NEW_FOLDER"); - newFolder->setIcon(0, style()->standardIcon(QStyle::SP_FileDialogNewFolder)); - } - - if (m_viewType != ComboFolderView) { - query.exec("SELECT title, url, id, folder, icon FROM bookmarks"); - while (query.next()) { - QString title = query.value(0).toString(); - QUrl url = query.value(1).toUrl(); - int id = query.value(2).toInt(); - QString folder = query.value(3).toString(); - QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(4).toByteArray())); - QTreeWidgetItem* item; - if (folder == QLatin1String("bookmarksMenu")) { - folder = _bookmarksMenu; - } - if (folder == QLatin1String("bookmarksToolbar")) { - folder = _bookmarksToolbar; - } - - if (folder != QLatin1String("unsorted")) { - QList findParent = findItems(folder, 0); - if (findParent.count() != 1) { - continue; - } - - item = new QTreeWidgetItem(findParent.at(0)); - - } - else { - item = new QTreeWidgetItem(rootItem); - } - - item->setText(0, title); - item->setText(1, url.toEncoded()); - - if (m_viewType != SideBarView) { - item->setToolTip(0, title); - item->setToolTip(1, url.toEncoded()); - // Qt::ItemIsEditable just Manager!! - item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled); - } - else { - item->setToolTip(0, url.toEncoded()); - item->setFlags(item->flags() | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled); - } - - item->setData(0, Qt::UserRole + 10, id); - item->setData(0, Qt::UserRole + 11, url); - item->setIcon(0, icon); - addTopLevelItem(item); - } - } - - if (m_viewType != SideBarView) { - query.exec("SELECT name FROM folders WHERE subfolder='yes'"); - while (query.next()) { - newItem = new QTreeWidgetItem(bookmarksToolbar); - newItem->setText(0, query.value(0).toString()); - newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); - if (m_viewType != ComboFolderView && m_viewType != ExportFolderView) { - newItem->setFlags(newItem->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - QSqlQuery query2; - query2.prepare("SELECT title, url, id, icon FROM bookmarks WHERE folder=?"); - query2.addBindValue(query.value(0).toString()); - query2.exec(); - while (query2.next()) { - QString title = query2.value(0).toString(); - QUrl url = query2.value(1).toUrl(); - int id = query2.value(2).toInt(); - QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query2.value(3).toByteArray())); - QTreeWidgetItem* item = new QTreeWidgetItem(newItem); - - item->setText(0, title); - item->setText(1, url.toEncoded()); - item->setToolTip(0, title); - item->setToolTip(1, url.toEncoded()); - - item->setData(0, Qt::UserRole + 10, id); - item->setData(0, Qt::UserRole + 11, url); - item->setIcon(0, icon); - item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled); - } - } - } - } - - expandAll(); - setUpdatesEnabled(true); -} - -void BookmarksTree::activeItemChange(int index, QComboBox* combo, const QString &title, WebView* view) -{ - if (!combo) { - combo = qobject_cast(sender()); - } - if (!combo) { - return; - } - QString data = combo->itemData(index, Qt::UserRole + 12).toString(); - if (data == "NEW_FOLDER") { - if (combo->parentWidget()->objectName() == "BookmarksWidget") { - emit requestNewFolder(this, 0, true, title, view); - } - else { - QString folder; - emit requestNewFolder(this, &folder, false, QString(), 0); - if (!folder.isEmpty()) { - int ind = combo->findText(folder); - // QComboBox::find() returns index related to the item's parent - if (ind == -1) { - QModelIndex rootIndex = combo->rootModelIndex(); - combo->setRootModelIndex(combo->model()->index(combo->findText(_bookmarksToolbar), 0)); - combo->setCurrentIndex(combo->findText(folder)); - combo->setRootModelIndex(rootIndex); - } - else { - combo->setCurrentIndex(ind); - } - } - else { - combo->setCurrentIndex(0); - } - } - } -} diff --git a/src/lib/bookmarks/bookmarkstree.h b/src/lib/bookmarks/bookmarkstree.h deleted file mode 100644 index f9c2948cb..000000000 --- a/src/lib/bookmarks/bookmarkstree.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2012-2014 S. Razi Alavizadeh -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef BOOKMARKSTREE_H -#define BOOKMARKSTREE_H - -#include "treewidget.h" -#include "qz_namespace.h" - -class QComboBox; -class WebView; -class TreeWidget; - -class QT_QUPZILLA_EXPORT BookmarksTree : public TreeWidget -{ - Q_OBJECT -public: - enum BookmarkView { - SideBarView, - ManagerView, - ComboFolderView, // I should found a better name ;) - ExportFolderView // reserved for export functionality! - }; - - BookmarksTree(QWidget* parent = 0); - - BookmarksTree::BookmarkView viewType() {return m_viewType;} - void setViewType(BookmarksTree::BookmarkView viewType); - -protected: - void drawBranches(QPainter* painter, const QRect &rect, const QModelIndex &index) const; - -public slots: - void refreshTree(); - void activeItemChange(int index, QComboBox* combo = 0, const QString &title = QString(), WebView* = 0); - -private: - BookmarkView m_viewType; - -signals: - void requestNewFolder(QWidget*, QString*, bool, QString, WebView*); -}; -#endif // BOOKMARKSTREE_H diff --git a/src/lib/lib.pro b/src/lib/lib.pro index c0e6f221c..e99a7ac5d 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -133,7 +133,6 @@ SOURCES += \ adblock/adblockicon.cpp \ tools/docktitlebarwidget.cpp \ sidebar/bookmarkssidebar.cpp \ - bookmarks/bookmarkicon.cpp \ sidebar/historysidebar.cpp \ desktopnotifications/desktopnotification.cpp \ desktopnotifications/desktopnotificationsfactory.cpp \ @@ -225,7 +224,6 @@ SOURCES += \ network/schemehandlers/adblockschemehandler.cpp \ network/schemehandlers/fileschemehandler.cpp \ tools/listitemdelegate.cpp \ - bookmarks/bookmarkstree.cpp \ tools/html5permissions/html5permissionsmanager.cpp \ tools/html5permissions/html5permissionsnotification.cpp \ tools/html5permissions/html5permissionsdialog.cpp \ @@ -258,7 +256,8 @@ SOURCES += \ bookmarks/bookmarksmodel.cpp \ bookmarks/bookmarkstreeview.cpp \ bookmarks/bookmarkstools.cpp \ - bookmarks/bookmarksmenu.cpp + bookmarks/bookmarksmenu.cpp \ + bookmarks/bookmarksicon.cpp HEADERS += \ @@ -322,7 +321,6 @@ HEADERS += \ adblock/adblockicon.h \ tools/docktitlebarwidget.h \ sidebar/bookmarkssidebar.h \ - bookmarks/bookmarkicon.h \ sidebar/historysidebar.h \ desktopnotifications/desktopnotification.h \ desktopnotifications/desktopnotificationsfactory.h \ @@ -417,7 +415,6 @@ HEADERS += \ network/schemehandlers/adblockschemehandler.h \ network/schemehandlers/fileschemehandler.h \ tools/listitemdelegate.h \ - bookmarks/bookmarkstree.h \ tools/html5permissions/html5permissionsmanager.h \ tools/html5permissions/html5permissionsnotification.h \ tools/html5permissions/html5permissionsdialog.h \ @@ -452,7 +449,8 @@ HEADERS += \ bookmarks/bookmarksmodel.h \ bookmarks/bookmarkstreeview.h \ bookmarks/bookmarkstools.h \ - bookmarks/bookmarksmenu.h + bookmarks/bookmarksmenu.h \ + bookmarks/bookmarksicon.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 36ad8254b..1421a0260 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -23,7 +23,7 @@ #include "clickablelabel.h" #include "webpage.h" #include "tabwidget.h" -#include "bookmarkicon.h" +#include "bookmarksicon.h" #include "progressbar.h" #include "statusbarmessage.h" #include "toolbutton.h" @@ -62,7 +62,7 @@ LocationBar::LocationBar(QupZilla* mainClass) setObjectName("locationbar"); setDragEnabled(true); - m_bookmarkIcon = new BookmarkIcon(this); + m_bookmarkIcon = new BookmarksIcon(this); m_goIcon = new GoIcon(this); m_rssIcon = new RssIcon(this); m_siteIcon = new SiteIcon(p_QupZilla, this); diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index c5536651d..48ebb2d4c 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -29,7 +29,7 @@ class LineEdit; class LocationCompleter; class ClickableLabel; class TabbedWebView; -class BookmarkIcon; +class BookmarksIcon; class SiteIcon; class GoIcon; class RssIcon; @@ -105,7 +105,7 @@ private: LocationCompleter m_completer; - BookmarkIcon* m_bookmarkIcon; + BookmarksIcon* m_bookmarkIcon; GoIcon* m_goIcon; RssIcon* m_rssIcon; SiteIcon* m_siteIcon; diff --git a/src/lib/popupwindow/popuplocationbar.cpp b/src/lib/popupwindow/popuplocationbar.cpp index 273adf432..4618a2590 100644 --- a/src/lib/popupwindow/popuplocationbar.cpp +++ b/src/lib/popupwindow/popuplocationbar.cpp @@ -20,7 +20,7 @@ #include "toolbutton.h" #include "qztools.h" #include "iconprovider.h" -#include "bookmarkicon.h" +#include "bookmarksicon.h" #include "autofillicon.h" #include "rssicon.h" #include "webpage.h" @@ -54,7 +54,7 @@ PopupLocationBar::PopupLocationBar(QWidget* parent) m_siteIcon->setIcon(qIconProvider->emptyWebIcon()); m_siteIcon->setFixedSize(26, 26); - m_bookmarkIcon = new BookmarkIcon(this); + m_bookmarkIcon = new BookmarksIcon(this); m_rssIcon = new RssIcon(this); m_autofillIcon = new AutoFillIcon(this); diff --git a/src/lib/popupwindow/popuplocationbar.h b/src/lib/popupwindow/popuplocationbar.h index 4b8295e87..6f123f659 100644 --- a/src/lib/popupwindow/popuplocationbar.h +++ b/src/lib/popupwindow/popuplocationbar.h @@ -27,7 +27,7 @@ class QLabel; class PopupSiteIcon; class PopupWebView; class AutoFillIcon; -class BookmarkIcon; +class BookmarksIcon; class RssIcon; class QT_QUPZILLA_EXPORT PopupLocationBar : public LineEdit @@ -56,7 +56,7 @@ private: PopupSiteIcon* m_siteIcon; AutoFillIcon* m_autofillIcon; - BookmarkIcon* m_bookmarkIcon; + BookmarksIcon* m_bookmarkIcon; RssIcon* m_rssIcon; };