1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

Added bookmarks sidebar + bookmark icon + docktitlebar classes

This commit is contained in:
nowrep 2011-04-15 20:46:51 +02:00
parent b81de62f24
commit be70ac9f2d
7 changed files with 321 additions and 0 deletions

View File

@ -0,0 +1,58 @@
#include "bookmarkicon.h"
#include "mainapplication.h"
#include "qupzilla.h"
#include "bookmarksmodel.h"
#include "bookmarkswidget.h"
BookmarkIcon::BookmarkIcon(QupZilla* mainClass, QWidget* parent)
: ClickableLabel(parent)
, p_QupZilla(mainClass)
, m_bookmarksModel(0)
{
setPixmap(QPixmap(":/icons/locationbar/starg.png"));
setCursor(Qt::PointingHandCursor);
setStyleSheet("margin-bottom: 2px;");
setToolTip(tr("Bookmark this Page"));
setFocusPolicy(Qt::ClickFocus);
m_bookmarksModel = mApp->bookmarksModel();
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(bookmarkAdded(BookmarksModel::Bookmark)));
connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(bookmarkDeleted(BookmarksModel::Bookmark)));
}
void BookmarkIcon::iconClicked()
{
QUrl url = p_QupZilla->weView()->url();
if (m_bookmarksModel->isBookmarked(url)) {
BookmarksWidget* menu = new BookmarksWidget(m_bookmarksModel->bookmarkId(url), p_QupZilla->locationBar());
menu->showAt(this);
} else
m_bookmarksModel->saveBookmark(p_QupZilla->weView());
}
void BookmarkIcon::checkBookmark(const QUrl &url)
{
if (m_lastUrl == url)
return;
if (m_bookmarksModel->isBookmarked(url))
setBookmarkSaved();
else
setBookmarkDisabled();
m_lastUrl = url;
}
void BookmarkIcon::bookmarkDeleted(const BookmarksModel::Bookmark &bookmark)
{
if (bookmark.url == m_lastUrl)
setBookmarkDisabled();
}
void BookmarkIcon::bookmarkAdded(const BookmarksModel::Bookmark &bookmark)
{
if (bookmark.url == m_lastUrl)
setBookmarkSaved();
}

View File

@ -0,0 +1,45 @@
#ifndef BOOKMARKICON_H
#define BOOKMARKICON_H
#include <QUrl>
#include "clickablelabel.h"
#include "bookmarksmodel.h"
class QupZilla;
class BookmarksModel;
class BookmarkIcon : public ClickableLabel
{
Q_OBJECT
public:
explicit BookmarkIcon(QupZilla* mainClass, QWidget* parent = 0);
void checkBookmark(const QUrl &url);
signals:
public slots:
private slots:
void iconClicked();
void bookmarkAdded(const BookmarksModel::Bookmark &bookmark);
void bookmarkDeleted(const BookmarksModel::Bookmark &bookmark);
private:
inline void setBookmarkSaved()
{
setPixmap(QPixmap(":/icons/locationbar/star.png"));
setToolTip(tr("Edit this bookmark"));
}
inline void setBookmarkDisabled()
{
setPixmap(QPixmap(":/icons/locationbar/starg.png"));
setToolTip(tr("Bookmark this Page"));
}
QupZilla* p_QupZilla;
BookmarksModel* m_bookmarksModel;
QUrl m_lastUrl;
};
#endif // BOOKMARKICON_H

View File

@ -0,0 +1,53 @@
#ifndef BOOKMARKSSIDEBAR_H
#define BOOKMARKSSIDEBAR_H
#include <QWidget>
#include <QTreeWidgetItem>
#include <QInputDialog>
#include <QPointer>
#include "bookmarksmodel.h"
namespace Ui {
class BookmarksSideBar;
}
class WebView;
class QupZilla;
class BookmarksModel;
class BookmarksSideBar : public QWidget
{
Q_OBJECT
public:
explicit BookmarksSideBar(QupZilla* mainClass, QWidget* parent = 0);
~BookmarksSideBar();
void setMainWindow(QupZilla* window);
public slots:
void refreshTable();
private slots:
void deleteItem();
void contextMenuRequested(const QPoint &position);
void loadInNewTab();
void itemControlClicked(QTreeWidgetItem* item);
void itemDoubleClicked(QTreeWidgetItem* item);
void moveBookmark();
void addBookmark(const BookmarksModel::Bookmark &bookmark);
void removeBookmark(const BookmarksModel::Bookmark &bookmark);
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
void addFolder(const QString &name);
void removeFolder(const QString &name);
private:
QupZilla* getQupZilla();
bool m_isRefreshing;
Ui::BookmarksSideBar* ui;
QPointer<QupZilla> p_QupZilla;
BookmarksModel* m_bookmarksModel;
};
#endif // BOOKMARKSSIDEBAR_H

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BookmarksSideBar</class>
<widget class="QWidget" name="BookmarksSideBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>486</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="search">
<property name="placeholderText">
<string>Search...</string>
</property>
</widget>
</item>
<item>
<widget class="TreeWidget" name="bookmarksTree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>330</number>
</attribute>
<column>
<property name="text">
<string notr="true">Bookmark</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TreeWidget</class>
<extends>QTreeWidget</extends>
<header>treewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,23 @@
#include "docktitlebarwidget.h"
DockTitleBarWidget::DockTitleBarWidget(const QString &title, QWidget* parent) :
QWidget(parent)
{
setupUi(this);
#ifdef Q_WS_X11
closeButton->setIcon(QIcon(style()->standardIcon(QStyle::SP_DialogCloseButton).pixmap(16,16)));
#else
closeButton->setIcon(QIcon(QIcon(":/icons/faenza/close.png").pixmap(16,16)));
#endif
label->setText(title);
connect(closeButton, SIGNAL(clicked()), parent, SLOT(close()));
}
void DockTitleBarWidget::setTitle(const QString &title)
{
label->setText(title);
}
DockTitleBarWidget::~DockTitleBarWidget()
{
}

View File

@ -0,0 +1,21 @@
#ifndef DOCKTITLEBARWIDGET_H
#define DOCKTITLEBARWIDGET_H
#include <QWidget>
#include "ui_docktitlebarwidget.h"
class DockTitleBarWidget : public QWidget, public Ui_DockTitleBarWidget
{
Q_OBJECT
public:
explicit DockTitleBarWidget(const QString &title, QWidget* parent = 0);
~DockTitleBarWidget();
void setTitle(const QString &title);
private:
};
#endif // DOCKTITLEBARWIDGET_H

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockTitleBarWidget</class>
<widget class="QWidget" name="DockTitleBarWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>667</width>
<height>24</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="closeButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>