mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Merge branch 'master' of git://github.com/srazi/qupzilla into srazi-master
This commit is contained in:
commit
3aba5ac7a0
@ -47,6 +47,10 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->bookmarksTree->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
ui->bookmarksTree->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
||||||
|
ui->bookmarksTree->setDragDropReceiver(true, m_bookmarksModel);
|
||||||
|
|
||||||
connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
||||||
connect(ui->addFolder, SIGNAL(clicked()), this, SLOT(addFolder()));
|
connect(ui->addFolder, SIGNAL(clicked()), this, SLOT(addFolder()));
|
||||||
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||||
@ -60,6 +64,8 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
|||||||
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString)));
|
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
||||||
|
|
||||||
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
|
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
|
||||||
connect(ui->importBookmarks, SIGNAL(clicked(QPoint)), this, SLOT(importBookmarks()));
|
connect(ui->importBookmarks, SIGNAL(clicked(QPoint)), this, SLOT(importBookmarks()));
|
||||||
@ -322,11 +328,13 @@ void BookmarksManager::refreshTable()
|
|||||||
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
newItem->setText(0, _bookmarksMenu);
|
newItem->setText(0, _bookmarksMenu);
|
||||||
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
newItem->setFlags(newItem->flags() & ~Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(newItem);
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
||||||
|
|
||||||
QTreeWidgetItem* bookmarksToolbar = new QTreeWidgetItem(ui->bookmarksTree);
|
QTreeWidgetItem* bookmarksToolbar = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
bookmarksToolbar->setText(0, _bookmarksToolbar);
|
bookmarksToolbar->setText(0, _bookmarksToolbar);
|
||||||
bookmarksToolbar->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
bookmarksToolbar->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
bookmarksToolbar->setFlags(bookmarksToolbar->flags() & ~Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(bookmarksToolbar);
|
ui->bookmarksTree->addTopLevelItem(bookmarksToolbar);
|
||||||
|
|
||||||
query.exec("SELECT name FROM folders WHERE subfolder!='yes'");
|
query.exec("SELECT name FROM folders WHERE subfolder!='yes'");
|
||||||
@ -334,6 +342,7 @@ void BookmarksManager::refreshTable()
|
|||||||
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
newItem->setText(0, query.value(0).toString());
|
newItem->setText(0, query.value(0).toString());
|
||||||
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
newItem->setFlags(newItem->flags() | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(newItem);
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +377,7 @@ void BookmarksManager::refreshTable()
|
|||||||
item->setData(0, Qt::UserRole + 10, id);
|
item->setData(0, Qt::UserRole + 10, id);
|
||||||
item->setData(0, Qt::UserRole + 11, url);
|
item->setData(0, Qt::UserRole + 11, url);
|
||||||
item->setIcon(0, icon);
|
item->setIcon(0, icon);
|
||||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(item);
|
ui->bookmarksTree->addTopLevelItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,6 +386,7 @@ void BookmarksManager::refreshTable()
|
|||||||
newItem = new QTreeWidgetItem(bookmarksToolbar);
|
newItem = new QTreeWidgetItem(bookmarksToolbar);
|
||||||
newItem->setText(0, query.value(0).toString());
|
newItem->setText(0, query.value(0).toString());
|
||||||
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
newItem->setFlags(newItem->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
|
|
||||||
QSqlQuery query2;
|
QSqlQuery query2;
|
||||||
query2.prepare("SELECT title, url, id, icon FROM bookmarks WHERE folder=?");
|
query2.prepare("SELECT title, url, id, icon FROM bookmarks WHERE folder=?");
|
||||||
@ -397,7 +407,7 @@ void BookmarksManager::refreshTable()
|
|||||||
item->setData(0, Qt::UserRole + 10, id);
|
item->setData(0, Qt::UserRole + 10, id);
|
||||||
item->setData(0, Qt::UserRole + 11, url);
|
item->setData(0, Qt::UserRole + 11, url);
|
||||||
item->setIcon(0, icon);
|
item->setIcon(0, icon);
|
||||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +429,7 @@ void BookmarksManager::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
|||||||
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
||||||
item->setToolTip(0, bookmark.title);
|
item->setToolTip(0, bookmark.title);
|
||||||
item->setToolTip(1, bookmark.url.toEncoded());
|
item->setToolTip(1, bookmark.url.toEncoded());
|
||||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
|
|
||||||
if (bookmark.inSubfolder) {
|
if (bookmark.inSubfolder) {
|
||||||
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive);
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive);
|
||||||
@ -518,6 +528,72 @@ void BookmarksManager::bookmarkEdited(const BookmarksModel::Bookmark &before, co
|
|||||||
addBookmark(after);
|
addBookmark(after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarksManager::changeBookmarkParent(const QString &name, const QByteArray &, int id,
|
||||||
|
const QUrl &, const QString &, const QString &newParent)
|
||||||
|
{
|
||||||
|
QList<QTreeWidgetItem*> 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<QTreeWidgetItem*> 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)
|
void BookmarksManager::addFolder(const QString &name)
|
||||||
{
|
{
|
||||||
m_isRefreshing = true;
|
m_isRefreshing = true;
|
||||||
@ -526,6 +602,13 @@ void BookmarksManager::addFolder(const QString &name)
|
|||||||
item->setText(0, name);
|
item->setText(0, name);
|
||||||
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
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;
|
m_isRefreshing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,6 +621,7 @@ void BookmarksManager::addSubfolder(const QString &name)
|
|||||||
QTreeWidgetItem* item = new QTreeWidgetItem(list.at(0));
|
QTreeWidgetItem* item = new QTreeWidgetItem(list.at(0));
|
||||||
item->setText(0, name);
|
item->setText(0, name);
|
||||||
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isRefreshing = false;
|
m_isRefreshing = false;
|
||||||
|
@ -75,6 +75,10 @@ private slots:
|
|||||||
void removeBookmark(const BookmarksModel::Bookmark &bookmark);
|
void removeBookmark(const BookmarksModel::Bookmark &bookmark);
|
||||||
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
|
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::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:
|
private:
|
||||||
QupZilla* getQupZilla();
|
QupZilla* getQupZilla();
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url,
|
|||||||
bool BookmarksModel::changeIcon(int id, const QIcon &icon)
|
bool BookmarksModel::changeIcon(int id, const QIcon &icon)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT title, url, folder, icon FROM bookmarks WWHERE id=?");
|
query.prepare("SELECT title, url, folder, icon FROM bookmarks WHERE id=?");
|
||||||
query.addBindValue(id);
|
query.addBindValue(id);
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
@ -557,3 +557,74 @@ QString BookmarksModel::fromTranslatedFolder(const QString &name)
|
|||||||
}
|
}
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarksModel::changeBookmarkParent(int id, const QString &newParent, const QString &oldParent, bool* ok)
|
||||||
|
{
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("SELECT title, url, icon FROM bookmarks WHERE id=?");
|
||||||
|
query.addBindValue(id);
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
if (!query.next()) {
|
||||||
|
if (ok) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString title = query.value(0).toString();
|
||||||
|
QUrl url = query.value(1).toUrl();
|
||||||
|
QByteArray imageData = query.value(2).toByteArray();
|
||||||
|
|
||||||
|
query.prepare("UPDATE bookmarks SET folder = ? WHERE id = ?");
|
||||||
|
query.bindValue(0, BookmarksModel::fromTranslatedFolder(newParent));
|
||||||
|
query.bindValue(1, id);
|
||||||
|
|
||||||
|
if (!query.exec()) {
|
||||||
|
if (ok) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit bookmarkParentChanged(title, imageData, id, url, oldParent, newParent);
|
||||||
|
mApp->sendMessages(Qz::AM_BookmarksChanged, true);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksModel::changeFolderParent(const QString &name, bool isSubfolder, bool* ok)
|
||||||
|
{
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("UPDATE folders SET subfolder=? WHERE name=?");
|
||||||
|
query.bindValue(0, isSubfolder ? "yes" : "no");
|
||||||
|
query.bindValue(1, BookmarksModel::fromTranslatedFolder(name));
|
||||||
|
if (!query.exec()) {
|
||||||
|
if (ok) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit folderParentChanged(name, isSubfolder);
|
||||||
|
mApp->sendMessages(Qz::AM_BookmarksChanged, true);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BookmarksModel::bookmarkDropedLink(const QUrl &url, const QString &title, const QVariant &imageVariant, const QString &folder, bool *ok)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
QIcon icon = qIconProvider->iconFromImage(qvariant_cast<QImage>(imageVariant));
|
||||||
|
result = saveBookmark(url, title, icon, BookmarksModel::fromTranslatedFolder(folder));
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
*ok = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -109,13 +109,22 @@ signals:
|
|||||||
void bookmarkDeleted(const BookmarksModel::Bookmark &bookmark);
|
void bookmarkDeleted(const BookmarksModel::Bookmark &bookmark);
|
||||||
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
|
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
|
||||||
|
|
||||||
|
void bookmarkParentChanged(const QString &name, const QByteArray &imageData, int id,
|
||||||
|
const QUrl &url, const QString &oldParent, const QString &newParent);
|
||||||
|
|
||||||
void folderAdded(const QString &title);
|
void folderAdded(const QString &title);
|
||||||
void folderDeleted(const QString &title);
|
void folderDeleted(const QString &title);
|
||||||
|
|
||||||
void subfolderAdded(const QString &title);
|
void subfolderAdded(const QString &title);
|
||||||
void folderRenamed(const QString &before, const QString &after);
|
void folderRenamed(const QString &before, const QString &after);
|
||||||
|
|
||||||
|
void folderParentChanged(const QString &name, bool isSubfolder);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void bookmarkDropedLink(const QUrl &url, const QString &title, const QVariant &imageVariant,
|
||||||
|
const QString &folder = QLatin1String("unsorted"), bool* ok = 0);
|
||||||
|
void changeBookmarkParent(int id, const QString &newParent, const QString &oldParent, bool* ok = 0);
|
||||||
|
void changeFolderParent(const QString &name, bool isSubfolder, bool* ok = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_showMostVisited;
|
bool m_showMostVisited;
|
||||||
|
@ -60,6 +60,8 @@ BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent)
|
|||||||
connect(m_bookmarksModel, SIGNAL(subfolderAdded(QString)), this, SLOT(subfolderAdded(QString)));
|
connect(m_bookmarksModel, SIGNAL(subfolderAdded(QString)), this, SLOT(subfolderAdded(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(folderDeleted(QString)));
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(folderDeleted(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(folderRenamed(QString, QString)));
|
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(folderRenamed(QString, QString)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
||||||
|
|
||||||
setMaximumWidth(p_QupZilla->width());
|
setMaximumWidth(p_QupZilla->width());
|
||||||
|
|
||||||
@ -387,6 +389,41 @@ void BookmarksToolbar::folderRenamed(const QString &before, const QString &after
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarksToolbar::changeBookmarkParent(const QString &name, const QByteArray &imageData, int id,
|
||||||
|
const QUrl &url, const QString &oldParent, const QString &newParent)
|
||||||
|
{
|
||||||
|
if (oldParent != _bookmarksToolbar && newParent != _bookmarksToolbar) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool itemIsAboutToRemove = (newParent != _bookmarksToolbar);
|
||||||
|
|
||||||
|
Bookmark bookmark;
|
||||||
|
bookmark.id = id;
|
||||||
|
bookmark.url = url;
|
||||||
|
bookmark.title = name;
|
||||||
|
bookmark.folder = QLatin1String("bookmarksToolbar");
|
||||||
|
bookmark.image = QImage::fromData(imageData);
|
||||||
|
bookmark.inSubfolder = false;
|
||||||
|
|
||||||
|
if (itemIsAboutToRemove) {
|
||||||
|
removeBookmark(bookmark);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addBookmark(bookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksToolbar::changeFolderParent(const QString &name, bool isSubfolder)
|
||||||
|
{
|
||||||
|
if (!isSubfolder) {
|
||||||
|
folderDeleted(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
subfolderAdded(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
||||||
{
|
{
|
||||||
if (bookmark.folder != QLatin1String("bookmarksToolbar")) {
|
if (bookmark.folder != QLatin1String("bookmarksToolbar")) {
|
||||||
|
@ -68,6 +68,10 @@ private slots:
|
|||||||
void folderDeleted(const QString &name);
|
void folderDeleted(const QString &name);
|
||||||
void folderRenamed(const QString &before, const QString &after);
|
void folderRenamed(const QString &before, const QString &after);
|
||||||
|
|
||||||
|
void changeBookmarkParent(const QString &name, const QByteArray &imageData, int id,
|
||||||
|
const QUrl &url, const QString &oldParent, const QString &newParent);
|
||||||
|
void changeFolderParent(const QString &name, bool isSubfolder);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void dropEvent(QDropEvent* e);
|
void dropEvent(QDropEvent* e);
|
||||||
void dragEnterEvent(QDragEnterEvent* e);
|
void dragEnterEvent(QDragEnterEvent* e);
|
||||||
|
@ -41,6 +41,10 @@ BookmarksSideBar::BookmarksSideBar(QupZilla* mainClass, QWidget* parent)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->bookmarksTree->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
ui->bookmarksTree->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
||||||
|
ui->bookmarksTree->setDragDropReceiver(true, m_bookmarksModel);
|
||||||
|
|
||||||
ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
||||||
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||||
connect(ui->bookmarksTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
connect(ui->bookmarksTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
||||||
@ -54,6 +58,8 @@ BookmarksSideBar::BookmarksSideBar(QupZilla* mainClass, QWidget* parent)
|
|||||||
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
||||||
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString)));
|
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
||||||
|
connect(m_bookmarksModel, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(refreshTable()));
|
QTimer::singleShot(0, this, SLOT(refreshTable()));
|
||||||
}
|
}
|
||||||
@ -149,6 +155,7 @@ void BookmarksSideBar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
|||||||
item->setData(0, Qt::UserRole + 10, bookmark.id);
|
item->setData(0, Qt::UserRole + 10, bookmark.id);
|
||||||
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
||||||
item->setToolTip(0, bookmark.url.toEncoded());
|
item->setToolTip(0, bookmark.url.toEncoded());
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
|
|
||||||
if (bookmark.folder != QLatin1String("unsorted")) {
|
if (bookmark.folder != QLatin1String("unsorted")) {
|
||||||
ui->bookmarksTree->appendToParentItem(translatedFolder, item);
|
ui->bookmarksTree->appendToParentItem(translatedFolder, item);
|
||||||
@ -206,6 +213,13 @@ void BookmarksSideBar::addFolder(const QString &name)
|
|||||||
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
item->setText(0, name);
|
item->setText(0, name);
|
||||||
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksSideBar::removeFolder(const QString &name)
|
void BookmarksSideBar::removeFolder(const QString &name)
|
||||||
@ -234,6 +248,79 @@ void BookmarksSideBar::renameFolder(const QString &before, const QString &after)
|
|||||||
item->setText(0, after);
|
item->setText(0, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::changeBookmarkParent(const QString &name, const QByteArray &imageData, int id,
|
||||||
|
const QUrl &url, const QString &oldParent, const QString &newParent)
|
||||||
|
{
|
||||||
|
if (!newParent.isEmpty() && newParent != QLatin1String("unsorted")
|
||||||
|
&& newParent != _bookmarksUnsorted && !oldParent.isEmpty()
|
||||||
|
&& oldParent != QLatin1String("unsorted")
|
||||||
|
&& oldParent != _bookmarksUnsorted) { // old and new parent are not invisibleRootItem()
|
||||||
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(newParent, Qt::MatchExactly);
|
||||||
|
if (list.isEmpty()) { // newParent is a subfolder
|
||||||
|
list = ui->bookmarksTree->findItems(oldParent, Qt::MatchExactly);
|
||||||
|
if (list.isEmpty()) { // oldParent is a subfolder
|
||||||
|
return; // item was reparented from bookmarkToolbar(subfolder) to subfolder(bookmarkToolbar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> 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()) { // list is empty or item with 'id' was not found
|
||||||
|
// bookmark's oldParent was bookmarkToolbar(subfolder)
|
||||||
|
Bookmark bookmark;
|
||||||
|
bookmark.id = id;
|
||||||
|
bookmark.url = url;
|
||||||
|
bookmark.title = name;
|
||||||
|
bookmark.folder = BookmarksModel::fromTranslatedFolder(newParent.isEmpty() ? QLatin1String("unsorted") : newParent);
|
||||||
|
bookmark.image = QImage::fromData(imageData);
|
||||||
|
bookmark.inSubfolder = false;
|
||||||
|
addBookmark(bookmark);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* parent = 0;
|
||||||
|
if (newParent.isEmpty() || newParent == QLatin1String("unsorted") || newParent == _bookmarksUnsorted) {
|
||||||
|
parent = ui->bookmarksTree->invisibleRootItem();
|
||||||
|
}
|
||||||
|
item->parent() ? item->parent()->removeChild(item) : ui->bookmarksTree->invisibleRootItem()->removeChild(item);
|
||||||
|
|
||||||
|
if (!parent) {
|
||||||
|
list = ui->bookmarksTree->findItems(newParent, Qt::MatchExactly);
|
||||||
|
if (list.count() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = list.at(0);
|
||||||
|
if (!parent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::changeFolderParent(const QString &name, bool isSubfolder)
|
||||||
|
{
|
||||||
|
if (isSubfolder) { // folder moved to _bookmarksToolbar as a subfolder
|
||||||
|
removeFolder(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addFolder(name);
|
||||||
|
QList<Bookmark> bookmarksList = m_bookmarksModel->folderBookmarks(name);
|
||||||
|
foreach (const Bookmark & b, bookmarksList) {
|
||||||
|
addBookmark(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BookmarksSideBar::keyPressEvent(QKeyEvent* event)
|
void BookmarksSideBar::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
||||||
@ -262,6 +349,7 @@ void BookmarksSideBar::refreshTable()
|
|||||||
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
newItem->setText(0, _bookmarksMenu);
|
newItem->setText(0, _bookmarksMenu);
|
||||||
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
newItem->setFlags(newItem->flags() & ~Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(newItem);
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
||||||
|
|
||||||
query.exec("SELECT name FROM folders WHERE subfolder!='yes'");
|
query.exec("SELECT name FROM folders WHERE subfolder!='yes'");
|
||||||
@ -269,6 +357,7 @@ void BookmarksSideBar::refreshTable()
|
|||||||
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
newItem->setText(0, query.value(0).toString());
|
newItem->setText(0, query.value(0).toString());
|
||||||
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
newItem->setFlags(newItem->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(newItem);
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,6 +395,7 @@ void BookmarksSideBar::refreshTable()
|
|||||||
|
|
||||||
item->setData(0, Qt::UserRole + 10, id);
|
item->setData(0, Qt::UserRole + 10, id);
|
||||||
item->setIcon(0, icon);
|
item->setIcon(0, icon);
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||||
ui->bookmarksTree->addTopLevelItem(item);
|
ui->bookmarksTree->addTopLevelItem(item);
|
||||||
}
|
}
|
||||||
ui->bookmarksTree->expandAll();
|
ui->bookmarksTree->expandAll();
|
||||||
|
@ -61,6 +61,10 @@ private slots:
|
|||||||
void removeFolder(const QString &name);
|
void removeFolder(const QString &name);
|
||||||
void renameFolder(const QString &before, const QString &after);
|
void renameFolder(const QString &before, const QString &after);
|
||||||
|
|
||||||
|
void changeBookmarkParent(const QString &name, const QByteArray &imageData, int id,
|
||||||
|
const QUrl &url, const QString &oldParent, const QString &newParent);
|
||||||
|
void changeFolderParent(const QString &name, bool isSubfolder);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void keyPressEvent(QKeyEvent* event);
|
void keyPressEvent(QKeyEvent* event);
|
||||||
|
|
||||||
|
@ -16,8 +16,15 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "treewidget.h"
|
#include "treewidget.h"
|
||||||
|
#include "bookmarksmodel.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QSqlDatabase>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
const int ITEM_IS_TOPLEVEL = Qt::UserRole+20;
|
||||||
|
const int ITEM_PARENT_TITLE = Qt::UserRole+21;
|
||||||
|
|
||||||
TreeWidget::TreeWidget(QWidget* parent)
|
TreeWidget::TreeWidget(QWidget* parent)
|
||||||
: QTreeWidget(parent)
|
: QTreeWidget(parent)
|
||||||
@ -92,6 +99,211 @@ void TreeWidget::iterateAllItems(QTreeWidgetItem* parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::DropActions TreeWidget::supportedDropActions()
|
||||||
|
{
|
||||||
|
return Qt::CopyAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TreeWidget::mimeTypes() const
|
||||||
|
{
|
||||||
|
QStringList types;
|
||||||
|
types << QLatin1String("application/qupzilla.treewidgetitem.list");
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMimeData *TreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
|
||||||
|
{
|
||||||
|
QMimeData *data = new QMimeData();
|
||||||
|
QByteArray encodedData;
|
||||||
|
|
||||||
|
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||||
|
foreach (const QTreeWidgetItem* item, items) {
|
||||||
|
if (item) {
|
||||||
|
QTreeWidgetItem* clonedItem = item->clone();
|
||||||
|
bool parentIsRoot = false;
|
||||||
|
if (!item->parent() || item->parent() == invisibleRootItem()) {
|
||||||
|
parentIsRoot = true;
|
||||||
|
}
|
||||||
|
clonedItem->setData(0, ITEM_IS_TOPLEVEL, parentIsRoot );
|
||||||
|
clonedItem->setData(0, ITEM_PARENT_TITLE, (parentIsRoot ? QString() : item->parent()->text(0)) ) ;
|
||||||
|
clonedItem->write(stream);
|
||||||
|
delete clonedItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data->setData(QLatin1String("application/qupzilla.treewidgetitem.list"), encodedData);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TreeWidget::dropMimeData(QTreeWidgetItem *parent, int,
|
||||||
|
const QMimeData *data, Qt::DropAction action)
|
||||||
|
{
|
||||||
|
if (action == Qt::IgnoreAction) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent && !parent->text(1).isEmpty()) { // parent is a bookmark, go one level up!
|
||||||
|
parent = parent->parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parent) {
|
||||||
|
parent = invisibleRootItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
if (data->hasUrls()) {
|
||||||
|
QString folder = (parent == invisibleRootItem()) ? QLatin1String("unsorted") : parent->text(0);
|
||||||
|
QUrl url = data->urls().at(0);
|
||||||
|
QString title = data->text().isEmpty() ? url.host()+url.path() : data->text();
|
||||||
|
emit linkWasDroped(url, title, data->imageData(), folder, &ok);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data->hasFormat(QLatin1String("application/qupzilla.treewidgetitem.list")))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
setUpdatesEnabled(false);
|
||||||
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
|
QSqlDatabase db = QSqlDatabase::database();
|
||||||
|
db.transaction();
|
||||||
|
|
||||||
|
QByteArray ba = data->data(QLatin1String("application/qupzilla.treewidgetitem.list"));
|
||||||
|
QDataStream stream(&ba, QIODevice::ReadOnly);
|
||||||
|
if (stream.atEnd())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem;
|
||||||
|
item->read(stream);
|
||||||
|
bool parentIsRoot = item->data(0, ITEM_IS_TOPLEVEL).toBool();
|
||||||
|
QString oldParentTitle = item->data(0, ITEM_PARENT_TITLE).toString();
|
||||||
|
|
||||||
|
bool isFolder = (item && item->text(1).isEmpty());
|
||||||
|
if (isFolder && (item->text(0) == _bookmarksMenu ||
|
||||||
|
item->text(0) == _bookmarksToolbar)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parentIsOldParent = parentIsRoot ? (parent == invisibleRootItem()) : (oldParentTitle == parent->text(0));
|
||||||
|
if ( parentIsOldParent || (isFolder && parent != invisibleRootItem() &&
|
||||||
|
parent->text(0) != _bookmarksToolbar) ) {
|
||||||
|
// just 'Bookmarks In ToolBar' folder can have subfolders
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFolder) {
|
||||||
|
if (parent->text(0) == _bookmarksToolbar) {
|
||||||
|
emit folderParentChanged(item->text(0), true, &ok);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emit folderParentChanged(item->text(0), false, &ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emit bookmarkParentChanged(item->data(0, Qt::UserRole + 10).toInt(),
|
||||||
|
parent->text(0), oldParentTitle, &ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db.commit();
|
||||||
|
clearSelection();
|
||||||
|
setUpdatesEnabled(true);
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TreeWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
const QMimeData *mimeData = event->mimeData();
|
||||||
|
QTreeWidget::dragEnterEvent(event);
|
||||||
|
if (mimeData->hasUrls() || mimeData->hasFormat(QLatin1String("application/qupzilla.treewidgetitem.list"))) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TreeWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
|
const QMimeData *mimeData = event->mimeData();
|
||||||
|
bool accept = false;
|
||||||
|
if (mimeData->hasUrls()) {
|
||||||
|
accept = true;
|
||||||
|
}
|
||||||
|
else if (mimeData->hasFormat(QLatin1String("application/qupzilla.treewidgetitem.list"))) {
|
||||||
|
QTreeWidgetItem *itemUnderMouse = itemAt(event->pos());
|
||||||
|
bool underMouseIsFolder = (itemUnderMouse && itemUnderMouse->text(1).isEmpty());
|
||||||
|
int top = visualItemRect(itemUnderMouse).top();
|
||||||
|
int bottom = visualItemRect(itemUnderMouse).bottom();
|
||||||
|
int y = event->pos().y();
|
||||||
|
bool overEdgeOfItem = (y >= top-1 && y <= top+1) || (y <= bottom+1 && y >= bottom-1);
|
||||||
|
|
||||||
|
QByteArray ba = mimeData->data(QLatin1String("application/qupzilla.treewidgetitem.list"));
|
||||||
|
QDataStream stream(&ba, QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
QTreeWidgetItem *dragItem = new QTreeWidgetItem;
|
||||||
|
dragItem->read(stream);
|
||||||
|
bool parentIsRoot = dragItem->data(0, ITEM_IS_TOPLEVEL).toBool();
|
||||||
|
QString oldParentTitle = dragItem->data(0, ITEM_PARENT_TITLE).toString();
|
||||||
|
|
||||||
|
bool itemIsFolder = dragItem->text(1).isEmpty();
|
||||||
|
if (dragItem->text(0) != _bookmarksMenu
|
||||||
|
&& dragItem->text(0) != _bookmarksToolbar) {
|
||||||
|
if (!itemUnderMouse->parent() && !parentIsRoot && overEdgeOfItem) {
|
||||||
|
accept = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bool parentsAreDifferent = parentIsRoot
|
||||||
|
? itemUnderMouse->parent()
|
||||||
|
: (!itemUnderMouse->parent() || itemUnderMouse->parent()->text(0) != oldParentTitle);
|
||||||
|
bool canHasSubFolder = !itemUnderMouse->parent()
|
||||||
|
|| itemUnderMouse->parent() == invisibleRootItem()
|
||||||
|
|| itemUnderMouse->parent()->text(0) == _bookmarksToolbar;
|
||||||
|
|
||||||
|
if (!underMouseIsFolder && parentsAreDifferent) {
|
||||||
|
if (!itemIsFolder) {
|
||||||
|
accept = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!itemUnderMouse->parent()
|
||||||
|
|| dragItem->text(0) != itemUnderMouse->parent()->text(0)
|
||||||
|
&& canHasSubFolder) {
|
||||||
|
accept = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (underMouseIsFolder) {
|
||||||
|
if (itemIsFolder && itemUnderMouse->text(0) == _bookmarksToolbar
|
||||||
|
&& (parentIsRoot || oldParentTitle != _bookmarksToolbar)) {
|
||||||
|
accept = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!itemIsFolder && oldParentTitle != itemUnderMouse->text(0)) {
|
||||||
|
accept = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidget::dragMoveEvent(event);
|
||||||
|
if (accept) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QTreeWidgetItem*> TreeWidget::allItems()
|
QList<QTreeWidgetItem*> TreeWidget::allItems()
|
||||||
{
|
{
|
||||||
if (m_refreshAllItemsNeeded) {
|
if (m_refreshAllItemsNeeded) {
|
||||||
@ -222,3 +434,24 @@ void TreeWidget::deleteItems(const QList<QTreeWidgetItem*> &items)
|
|||||||
|
|
||||||
qDeleteAll(items);
|
qDeleteAll(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeWidget::setDragDropReceiver(bool enable, QObject* receiver)
|
||||||
|
{
|
||||||
|
if (!receiver) {
|
||||||
|
enable = false;
|
||||||
|
}
|
||||||
|
setDragEnabled(enable);
|
||||||
|
viewport()->setAcceptDrops(enable);
|
||||||
|
setDropIndicatorShown(enable);
|
||||||
|
if (enable) {
|
||||||
|
model()->setSupportedDragActions(Qt::CopyAction);
|
||||||
|
connect(this, SIGNAL(folderParentChanged(QString,bool,bool*)), receiver, SLOT(changeFolderParent(QString,bool,bool*)));
|
||||||
|
connect(this, SIGNAL(bookmarkParentChanged(int,QString,QString,bool*)), receiver, SLOT(changeBookmarkParent(int,QString,QString,bool*)));
|
||||||
|
connect(this, SIGNAL(linkWasDroped(QUrl,QString,QVariant,QString,bool*)), receiver, SLOT(bookmarkDropedLink(QUrl,QString,QVariant,QString,bool*)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
disconnect(this, SIGNAL(folderParentChanged(QString,bool,bool*)), receiver, SLOT(changeFolderParent(QString,bool,bool*)));
|
||||||
|
disconnect(this, SIGNAL(bookmarkParentChanged(int,QString,QString,bool*)), receiver, SLOT(changeBookmarkParent(int,QString,QString,bool*)));
|
||||||
|
disconnect(this, SIGNAL(linkWasDroped(QUrl,QString,QVariant,QString,bool*)), receiver, SLOT(bookmarkDropedLink(QUrl,QString,QVariant,QString,bool*)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -43,10 +43,16 @@ public:
|
|||||||
void deleteItem(QTreeWidgetItem* item);
|
void deleteItem(QTreeWidgetItem* item);
|
||||||
void deleteItems(const QList<QTreeWidgetItem*> &items);
|
void deleteItems(const QList<QTreeWidgetItem*> &items);
|
||||||
|
|
||||||
|
void setDragDropReceiver(bool enable, QObject* receiver = 0);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemControlClicked(QTreeWidgetItem* item);
|
void itemControlClicked(QTreeWidgetItem* item);
|
||||||
void itemMiddleButtonClicked(QTreeWidgetItem* item);
|
void itemMiddleButtonClicked(QTreeWidgetItem* item);
|
||||||
|
|
||||||
|
void linkWasDroped(const QUrl &url, const QString &title, const QVariant &imageVariant, const QString &folder, bool* ok);
|
||||||
|
void bookmarkParentChanged(int id, const QString &newParent, const QString &oldParent, bool* ok);
|
||||||
|
void folderParentChanged(const QString &name, bool isSubfolder, bool* ok);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void filterString(QString string);
|
void filterString(QString string);
|
||||||
void clear();
|
void clear();
|
||||||
@ -58,6 +64,13 @@ private:
|
|||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
void iterateAllItems(QTreeWidgetItem* parent);
|
void iterateAllItems(QTreeWidgetItem* parent);
|
||||||
|
|
||||||
|
Qt::DropActions supportedDropActions();
|
||||||
|
QStringList mimeTypes() const;
|
||||||
|
QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const;
|
||||||
|
bool dropMimeData(QTreeWidgetItem *parent, int, const QMimeData *data, Qt::DropAction action);
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
void dragMoveEvent(QDragMoveEvent* event);
|
||||||
|
|
||||||
bool m_refreshAllItemsNeeded;
|
bool m_refreshAllItemsNeeded;
|
||||||
QList<QTreeWidgetItem*> m_allTreeItems;
|
QList<QTreeWidgetItem*> m_allTreeItems;
|
||||||
ItemShowMode m_showMode;
|
ItemShowMode m_showMode;
|
||||||
|
Loading…
Reference in New Issue
Block a user