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

Merge branch 'master' of git://github.com/ff2000/qupzilla into ff2000-master

This commit is contained in:
nowrep 2012-09-11 10:52:08 +02:00
commit 6846a9a46c
3 changed files with 69 additions and 87 deletions

View File

@ -36,6 +36,7 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa
, m_view(view)
, m_bookmarksModel(mApp->bookmarksModel())
, m_speedDial(mApp->plugins()->speedDial())
, m_edited(false)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
@ -44,27 +45,12 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa
// it dynamically changes and so, it's not good choice for this widget.
setLayoutDirection(QApplication::layoutDirection());
m_bookmarkId = m_bookmarksModel->bookmarkId(m_url);
if (m_bookmarkId > 0) {
connect(ui->saveRemove, SIGNAL(clicked()), this, SLOT(removeBookmark()));
ui->saveRemove->setText(tr("Remove"));
}
else {
connect(ui->saveRemove, SIGNAL(clicked()), this, SLOT(saveBookmark()));
}
connect(ui->speeddialButton, SIGNAL(clicked()), this, SLOT(toggleSpeedDial()));
connect(ui->speeddialButton, SIGNAL(clicked(QPoint)), this, SLOT(toggleSpeedDial()));
const SpeedDial::Page &page = m_speedDial->pageForUrl(m_url);
ui->speeddialButton->setText(page.url.isEmpty() ? tr("Add to Speed Dial") : tr("Remove from Speed Dial"));
#ifndef KDE
// Use light color for QLabels even with Ubuntu Ambiance theme
QPalette pal = palette();
pal.setColor(QPalette::WindowText, QToolTip::palette().color(QPalette::ToolTipText));
ui->label_2->setPalette(pal);
ui->label_3->setPalette(pal);
#endif
ui->speeddialButton->setText(page.url.isEmpty() ?
tr("Add to Speed Dial") :
tr("Remove from Speed Dial"));
loadBookmark();
}
@ -81,13 +67,15 @@ void BookmarksWidget::loadBookmark()
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString());
}
m_bookmarkId = m_bookmarksModel->bookmarkId(m_url);
if (m_bookmarkId > 0) {
BookmarksModel::Bookmark bookmark = m_bookmarksModel->getBookmark(m_bookmarkId);
ui->name->setText(bookmark.title);
ui->folder->setCurrentIndex(ui->folder->findData(bookmark.folder));
ui->name->setEnabled(false);
ui->folder->setEnabled(false);
ui->saveRemove->setText(tr("Remove"));
connect(ui->name, SIGNAL(textEdited(QString)), SLOT(bookmarkEdited()));
connect(ui->folder, SIGNAL(currentIndexChanged(int)), SLOT(bookmarkEdited()));
}
else {
ui->name->setText(m_view->title());
@ -102,36 +90,49 @@ namespace
const int hideDelay = 270;
}
void BookmarksWidget::removeBookmark()
{
m_bookmarksModel->removeBookmark(m_url);
emit bookmarkDeleted();
QTimer::singleShot(hideDelay, this, SLOT(close()));
}
void BookmarksWidget::saveBookmark()
{
m_bookmarksModel->saveBookmark(m_url, ui->name->text(), m_view->icon(), ui->folder->currentText());
QTimer::singleShot(hideDelay, this, SLOT(close()));
}
void BookmarksWidget::toggleSpeedDial()
{
const SpeedDial::Page &page = m_speedDial->pageForUrl(m_url);
QString const dialText("<a href='toggle_dial'>%1</a>");
if (page.url.isEmpty()) {
m_speedDial->addPage(m_url, m_view->title());
ui->speeddialButton->setText(tr("Remove from Speed Dial"));
}
else {
m_speedDial->removePage(page);
ui->speeddialButton->setText(tr("Add to Speed Dial"));
}
QTimer::singleShot(hideDelay, this, SLOT(close()));
}
void BookmarksWidget::bookmarkEdited()
{
if (m_edited) {
return;
}
m_edited = true;
ui->saveRemove->setText(tr("Save"));
}
void BookmarksWidget::on_saveRemove_clicked(bool)
{
if (m_bookmarkId > 0) {
if (m_edited) {
m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString());
}
else {
m_bookmarksModel->removeBookmark(m_url);
emit bookmarkDeleted();
}
}
else {
m_bookmarksModel->saveBookmark(m_url, ui->name->text(), m_view->icon(), ui->folder->currentText());
}
QTimer::singleShot(hideDelay, this, SLOT(close()));
}
void BookmarksWidget::showAt(QWidget* _parent)
{
layout()->invalidate();
@ -142,8 +143,8 @@ void BookmarksWidget::showAt(QWidget* _parent)
show();
}
BookmarksWidget::~BookmarksWidget()
{
delete ui;
}

View File

@ -44,11 +44,9 @@ public:
signals:
void bookmarkDeleted();
public slots:
private slots:
void removeBookmark();
void saveBookmark();
void on_saveRemove_clicked(bool);
void bookmarkEdited();
void toggleSpeedDial();
@ -63,6 +61,7 @@ private:
WebView* m_view;
BookmarksModel* m_bookmarksModel;
SpeedDial* m_speedDial;
bool m_edited;
};
#endif // BOOKMARKSWIDGET_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>295</width>
<height>146</height>
<width>210</width>
<height>128</height>
</rect>
</property>
<property name="windowTitle">
@ -15,7 +15,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -30,60 +30,35 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="speeddialButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="ClickableLabel" name="speeddialButton">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Add to Speed Dial</string>
</property>
<property name="html-link-look" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="name"/>
</item>
</layout>
<widget class="QLineEdit" name="name"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Folder:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="folder">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
<widget class="QComboBox" name="folder">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>5</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -100,7 +75,7 @@
<item>
<widget class="QPushButton" name="saveRemove">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -114,6 +89,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ClickableLabel</class>
<extends>QLabel</extends>
<header>clickablelabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>