1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[Bookmarks] Removed BookmarksTree and renamed BookmarkIcon -> BookmarksIcon

This commit is contained in:
nowrep 2014-02-09 12:22:49 +01:00
parent 1f4272e45e
commit 2ea155560a
9 changed files with 28 additions and 328 deletions

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "bookmarkicon.h"
#include "bookmarksicon.h"
#include "bookmarkswidget.h"
#include "bookmarks.h"
#include "mainapplication.h"
@ -27,7 +27,7 @@
#include <QStyle>
#include <QContextMenuEvent>
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);

View File

@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef BOOKMARKICON_H
#define BOOKMARKICON_H
#ifndef BOOKMARKSICON_H
#define BOOKMARKSICON_H
#include <QUrl>
@ -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

View File

@ -1,240 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2012-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "bookmarkstree.h"
#include "iconprovider.h"
#include "bookmarks.h"
#include <QSqlQuery>
#include <QComboBox>
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<QTreeWidgetItem*> 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<QComboBox*>(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);
}
}
}
}

View File

@ -1,58 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2012-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#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

View File

@ -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 \

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
};