1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[Bookmarks] Draw separators in BookmarksTreeView

This commit is contained in:
nowrep 2014-02-09 17:27:55 +01:00
parent 549e20a31d
commit b3c4d5d8da
10 changed files with 132 additions and 17 deletions

View File

@ -31,11 +31,11 @@
Bookmarks::Bookmarks(QObject* parent)
: QObject(parent)
{
loadBookmarks();
init();
loadSettings();
}
void Bookmarks::loadBookmarks()
void Bookmarks::init()
{
m_root = new BookmarkItem(BookmarkItem::Root);
@ -78,6 +78,7 @@ void Bookmarks::loadBookmarks()
READ_FOLDER("other", m_folderUnsorted)
#undef READ_FOLDER
m_lastFolder = m_folderUnsorted;
m_model = new BookmarksModel(this, this);
}
@ -259,7 +260,6 @@ void Bookmarks::loadSettings()
settings.beginGroup("Bookmarks");
m_showMostVisited = settings.value("showMostVisited", true).toBool();
m_showOnlyIconsInToolbar = settings.value("showOnlyIconsInToolbar", false).toBool();
//m_lastFolder = settings.value("LastFolder", "unsorted").toString();
settings.endGroup();
}
@ -440,8 +440,7 @@ BookmarkItem* Bookmarks::unsortedFolder() const
BookmarkItem* Bookmarks::lastUsedFolder() const
{
// TODO: Make it actually return last used folder
return unsortedFolder();
return m_lastFolder;
}
bool Bookmarks::isBookmarked(const QUrl &url)
@ -507,6 +506,7 @@ void Bookmarks::insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item
Q_ASSERT(parent->isFolder());
Q_ASSERT(item);
m_lastFolder = parent;
m_model->addBookmark(parent, row, item);
emit bookmarkAdded(item);
}

View File

@ -74,13 +74,13 @@ public:
static QString toTranslatedFolder(const QString &name);
static QString fromTranslatedFolder(const QString &name);
BookmarksModel* model() const;
BookmarkItem* rootItem() const;
BookmarkItem* toolbarFolder() const;
BookmarkItem* menuFolder() const;
BookmarkItem* unsortedFolder() const;
BookmarkItem* lastUsedFolder() const;
BookmarksModel* model() const;
bool isBookmarked(const QUrl &url);
@ -106,7 +106,7 @@ signals:
void bookmarkChanged(BookmarkItem* item);
private:
void loadBookmarks();
void init();
void readBookmarks(const QVariantList &list, BookmarkItem* parent);
QVariantList writeBookmarks(BookmarkItem* parent);
@ -114,15 +114,16 @@ private:
void search(QList<BookmarkItem*>* items, BookmarkItem* parent, const QUrl &url) const;
void search(QList<BookmarkItem*>* items, BookmarkItem* parent, const QString &string, Qt::CaseSensitivity sensitive) const;
bool m_showMostVisited;
bool m_showOnlyIconsInToolbar;
BookmarkItem* m_root;
BookmarkItem* m_folderToolbar;
BookmarkItem* m_folderMenu;
BookmarkItem* m_folderUnsorted;
BookmarkItem* m_lastFolder;
BookmarksModel* m_model;
bool m_showMostVisited;
bool m_showOnlyIconsInToolbar;
};
typedef Bookmarks::Bookmark Bookmark;

View File

@ -0,0 +1,55 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 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 "bookmarksitemdelegate.h"
#include "bookmarkstreeview.h"
#include "bookmarksmodel.h"
#include "bookmarkitem.h"
#include <QStyleOptionFrameV3>
#include <QApplication>
#include <QStyle>
BookmarksItemDelegate::BookmarksItemDelegate(BookmarksTreeView* parent)
: QStyledItemDelegate(parent)
, m_tree(parent)
{
}
void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
if (index.data(BookmarksModel::TypeRole).toInt() == BookmarkItem::Separator) {
QStyleOptionFrameV3 opt;
opt.frameShape = QFrame::HLine;
opt.rect = option.rect;
// We need to fake continous line over 2 columns
if (m_tree->viewType() == BookmarksTreeView::BookmarksManagerViewType) {
if (index.column() == 1) {
opt.rect = m_lastRect;
}
else {
opt.rect.setWidth(opt.rect.width() + m_tree->columnWidth(1));
m_lastRect = opt.rect;
}
}
QApplication::style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter);
}
}

View File

@ -0,0 +1,41 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 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 BOOKMARKSITEMDELEGATE_H
#define BOOKMARKSITEMDELEGATE_H
#include <QStyledItemDelegate>
#include "qz_namespace.h"
class BookmarksTreeView;
class QT_QUPZILLA_EXPORT BookmarksItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit BookmarksItemDelegate(BookmarksTreeView* parent = 0);
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
BookmarksTreeView* m_tree;
mutable QRect m_lastRect;
};
#endif // BOOKMARKSITEMDELEGATE_H

View File

@ -27,6 +27,7 @@
#include "qztools.h"
#include <QMenu>
#include <QTimer>
BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
: QWidget(parent)
@ -208,6 +209,11 @@ void BookmarksManager::descriptionEdited()
}
}
void BookmarksManager::enableUpdates()
{
setUpdatesEnabled(true);
}
void BookmarksManager::importBookmarks()
{
BookmarksImportDialog* b = new BookmarksImportDialog(this);
@ -277,7 +283,9 @@ void BookmarksManager::updateEditBox(BookmarkItem* item)
}
m_blockDescriptionChangedSignal = false;
setUpdatesEnabled(true);
// Prevent flickering
QTimer::singleShot(10, this, SLOT(enableUpdates()));
}
bool BookmarksManager::bookmarkEditable(BookmarkItem* item) const

View File

@ -65,6 +65,7 @@ private slots:
void bookmarkEdited();
void descriptionEdited();
void enableUpdates();
void importBookmarks();
void exportBookmarks();

View File

@ -251,6 +251,10 @@ void BookmarksTools::openBookmarkInNewTab(QupZilla* window, BookmarkItem* item)
void BookmarksTools::openBookmarkInNewWindow(BookmarkItem* item)
{
if (!item->isUrl()) {
return;
}
item->setVisitCount(item->visitCount() + 1);
mApp->makeNewWindow(Qz::BW_NewWindow, item->url());
}

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "bookmarkstreeview.h"
#include "bookmarksitemdelegate.h"
#include "bookmarksmodel.h"
#include "bookmarkitem.h"
#include "bookmarks.h"
@ -37,6 +38,7 @@ BookmarksTreeView::BookmarksTreeView(QWidget* parent)
setDropIndicatorShown(true);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setContextMenuPolicy(Qt::CustomContextMenu);
setItemDelegate(new BookmarksItemDelegate(this));
header()->resizeSections(QHeaderView::ResizeToContents);
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(indexExpanded(QModelIndex)));

View File

@ -257,7 +257,8 @@ SOURCES += \
bookmarks/bookmarkstreeview.cpp \
bookmarks/bookmarkstools.cpp \
bookmarks/bookmarksmenu.cpp \
bookmarks/bookmarksicon.cpp
bookmarks/bookmarksicon.cpp \
bookmarks/bookmarksitemdelegate.cpp
HEADERS += \
@ -450,7 +451,8 @@ HEADERS += \
bookmarks/bookmarkstreeview.h \
bookmarks/bookmarkstools.h \
bookmarks/bookmarksmenu.h \
bookmarks/bookmarksicon.h
bookmarks/bookmarksicon.h \
bookmarks/bookmarksitemdelegate.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -71,15 +71,16 @@ void IconProvider::saveIcon(WebView* view)
QImage IconProvider::iconForUrl(const QUrl &url)
{
foreach (const Icon &ic, m_iconBuffer) {
if (ic.url == url) {
if (ic.url.toString().startsWith(url.toString())) {
return ic.image;
}
}
QSqlQuery query;
query.prepare("SELECT icon FROM icons WHERE url=?");
query.bindValue(0, url.toEncoded(QUrl::RemoveFragment));
query.prepare("SELECT icon FROM icons WHERE url LIKE ? LIMIT 1");
query.addBindValue(QString("%1%").arg(QString::fromUtf8(url.toEncoded(QUrl::RemoveFragment))));
query.exec();
if (query.next()) {
return QImage::fromData(query.value(0).toByteArray());
}