diff options
| author | matgic78 <matgic78@gmail.com> | 2010-01-15 17:20:51 +0100 | 
|---|---|---|
| committer | matgic78 <matgic78@gmail.com> | 2010-02-06 11:22:47 +0100 | 
| commit | 544094302a51b919b1eea86b313ec10d47533a08 (patch) | |
| tree | 3532f1fb834ebc3ef9e46c6cc85edf92019c3a78 /src/rekonqpage | |
| parent | tmp commit (diff) | |
| download | rekonq-544094302a51b919b1eea86b313ec10d47533a08.tar.xz | |
A new approach for choosing previews : a bar appears, then you browse to the page you want to preview, and then you click a button
Diffstat (limited to 'src/rekonqpage')
| -rw-r--r-- | src/rekonqpage/newtabpage.cpp | 36 | ||||
| -rw-r--r-- | src/rekonqpage/newtabpage.h | 11 | ||||
| -rw-r--r-- | src/rekonqpage/previewchooser.cpp | 157 | ||||
| -rw-r--r-- | src/rekonqpage/previewchooser.h | 70 | ||||
| -rw-r--r-- | src/rekonqpage/previewselectorbar.cpp | 138 | ||||
| -rw-r--r-- | src/rekonqpage/previewselectorbar.h | 60 | 
6 files changed, 231 insertions, 241 deletions
| diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index 78928bca..b075c186 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -36,7 +36,8 @@  #include "application.h"  #include "mainwindow.h"  #include "mainview.h" -#include "previewchooser.h" +#include "websnap.h" +#include "previewselectorbar.h"  // KDE Includes  #include <KStandardDirs> @@ -48,7 +49,6 @@  // Qt Includes  #include <QFile> -#include <websnap.h>  NewTabPage::NewTabPage(QWebFrame *frame) @@ -86,10 +86,8 @@ void NewTabPage::generate(KUrl url)          if(url.directory() == QString("preview/modify"))          {              int index = url.fileName().toInt(); -            QString url = m_root.findFirst("#preview" + QVariant(index).toString() + " > a").attribute("href"); -            PreviewChooser *pc = new PreviewChooser(index, url); -            connect(pc, SIGNAL(urlChoosed(int,KUrl)), SLOT(setPreview(int,KUrl))); -            pc->show(); +            Application::instance()->mainWindow()->findChild<PreviewSelectorBar *>() +                        ->enable(index, qobject_cast< WebPage* >(m_root.webFrame()->page()));              return;          }      } @@ -260,9 +258,6 @@ void NewTabPage::snapFinished()  void NewTabPage::removePreview(int index)  { -    QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); -     -          QStringList names = ReKonfig::previewNames();      QStringList urls = ReKonfig::previewUrls(); @@ -272,9 +267,9 @@ void NewTabPage::removePreview(int index)      ReKonfig::setPreviewNames(names);      ReKonfig::setPreviewUrls(urls); -    // sync file data      ReKonfig::self()->writeConfig(); +    QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString());      prev.replace(emptyPreview(index));  } @@ -285,18 +280,33 @@ void NewTabPage::setPreview(int index, KUrl url)          return;      QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); +    prev.replace(loadingPreview(index, url)); +     +} + + +void NewTabPage::setPreview(int index, WebPage* page) +{ +    KUrl url = page->mainFrame()->url(); +    WebSnap::savePreview(WebSnap::renderPreview(*page), url); +     +    QStringList names = ReKonfig::previewNames();      QStringList urls = ReKonfig::previewUrls(); +          urls.replace(index, url.toMimeDataString()); +    names.replace(index, page->mainFrame()->title()); +     +    ReKonfig::setPreviewNames(names);      ReKonfig::setPreviewUrls(urls); +          ReKonfig::self()->writeConfig(); - -    prev.replace(loadingPreview(index, url)); - +    setPreview(index, url);  } +  void NewTabPage::browsingMenu(const KUrl ¤tUrl)  {      QList<QWebElement> navItems; diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h index cdc3cb31..742d9209 100644 --- a/src/rekonqpage/newtabpage.h +++ b/src/rekonqpage/newtabpage.h @@ -55,10 +55,19 @@ public:       */      void generate(KUrl url = KUrl("about:home")); -protected slots: +public slots:      void snapFinished();      void removePreview(int index); +     +    /** +        Used for recently closed tabs +    */      void setPreview(int index, KUrl url); +     +    /** +        Used for favorites +    */ +    void setPreview(int index, WebPage *page);  protected:  // these are the function to build the new tab page      void browsingMenu(const KUrl ¤tUrl); diff --git a/src/rekonqpage/previewchooser.cpp b/src/rekonqpage/previewchooser.cpp deleted file mode 100644 index 79bdb068..00000000 --- a/src/rekonqpage/previewchooser.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* 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 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy  -* defined in Section 14 of version 3 of the license. -*  -* 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/>. -* -* ============================================================ */ - - -// Self Includes -#include "previewchooser.h" - -// Local Includes -#include "rekonq.h" -#include <bookmarkstreemodel.h> -#include <bookmarksproxy.h> -#include <mainview.h> -#include <webtab.h> - -// Qt Includes -#include <QLabel> -#include <QVBoxLayout> - -// KDE Includes -#include <KLineEdit> -#include <KLocalizedString> - - -PreviewChooser::PreviewChooser(int previewIndex, QString url) -        : KDialog(0) -        , m_treeView(new QTreeView) -        , m_model(new QStandardItemModel) -        , m_previewIndex(previewIndex) -{ -    setMinimumSize(350, 100); -    setWindowTitle(i18n("Set Page to preview")); -    setModal(true); -     -    setButtons(KDialog::Cancel | KDialog::Apply | KDialog::Ok); -    //setDefaultButton(KDialog::Ok); -    connect(this, SIGNAL(buttonClicked(KDialog::ButtonCode)), this, SLOT(buttonClicked(KDialog::ButtonCode))); -     -    m_treeView->setUniformRowHeights(true); -    m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows); -    m_treeView->setTextElideMode(Qt::ElideRight); -    m_treeView->setHeaderHidden(true); -    m_treeView->setIndentation(0); -     -    QWidget *mainWidget = new QWidget(this); - -    // add url bar -    QHBoxLayout *urlLayout = new QHBoxLayout; -    urlLayout->setContentsMargins(5, 0, 0, 0); -    QLabel *searchLabel = new QLabel(i18n("adress:")); -    urlLayout->addWidget(searchLabel); -    m_line = new KLineEdit; -     -    // setup view -    QVBoxLayout *vBoxLayout = new QVBoxLayout; -    vBoxLayout->setContentsMargins(0, 0, 0, 0); -    vBoxLayout->addLayout(urlLayout); -    vBoxLayout->addWidget(m_treeView); -    mainWidget->setLayout(vBoxLayout); -    setMainWidget(mainWidget); -     -    refreshModel(); -    connect(Application::instance()->mainWindow()->mainView(), SIGNAL(tabsChanged()), SLOT(refreshModel())); -     -    m_treeView->setModel(m_model); -     -    connect(m_treeView, SIGNAL(activated(QModelIndex)), SLOT(setUrl(QModelIndex))); -     -    connect(m_line, SIGNAL(textChanged(QString)), SLOT(urlChanged())); -    urlLayout->addWidget(m_line); -     -    if(url.isEmpty() || url.startsWith("about:")) -        m_line->setText(QString("http://")); -    else -    { -        m_line->setText(url); -        m_line->setSelection(8, m_line->text().size()); -    } -     -    enableButtonApply(false); -    setFocusProxy(mainWidget); -    mainWidget->setFocusProxy(m_line); -} - - -PreviewChooser::~PreviewChooser() -{ -    delete m_model; -} - - - -void PreviewChooser::refreshModel() -{ -    m_model->clear(); -    MainView *mv = Application::instance()->mainWindow()->mainView(); -    for(int i=0; i < mv->count(); ++i) -    { -        WebView *view = qobject_cast<WebView *>(mv->webTab(i)->view()); -         -        if(view->url().scheme() != "about") -        { -            QStandardItem *it = new QStandardItem(Application::icon(view->url()), view->title()); -            it->setData(QVariant(view->url()), Qt::ToolTipRole); -            m_model->appendRow(it); -        } -    } -} - -void PreviewChooser::setUrl(QModelIndex i) -{ -    if(!i.data().canConvert(QVariant::String)) -        return; -     -    m_line->setText(i.data(Qt::ToolTipRole).toString()); -} - - -void PreviewChooser::buttonClicked(KDialog::ButtonCode code) -{ -    if(code == KDialog::Apply || (code == KDialog::Ok && isButtonEnabled(KDialog::Apply))) -    { -        emit urlChoosed(m_previewIndex, KUrl(m_line->text())); -        enableButtonApply(false); -    } -     -    if(code == KDialog::Cancel || code == KDialog::Ok) -    { -        close(); -        deleteLater(); -    } -} - - -void PreviewChooser::urlChanged() -{ -    enableButtonApply(true); -} - diff --git a/src/rekonqpage/previewchooser.h b/src/rekonqpage/previewchooser.h deleted file mode 100644 index 3eae71db..00000000 --- a/src/rekonqpage/previewchooser.h +++ /dev/null @@ -1,70 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* 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 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy  -* defined in Section 14 of version 3 of the license. -*  -* 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 PREVIEWCHOOSER_H -#define PREVIEWCHOOSER_H - - -// Local Includes -#include "application.h" - -// KDE Includes -#include <KLineEdit> -#include <KDialog> - -// Qt Includes -#include <QWidget> -#include <QTreeView> -#include <QStandardItemModel> - -// Forward Declarations -class KUrl; - - -class PreviewChooser : public KDialog -{ -Q_OBJECT - -public: -    explicit PreviewChooser(int previewIndex, QString url); -    virtual ~PreviewChooser(); - -signals: -    void urlChoosed(int, const KUrl &); -     -public slots: -    void refreshModel(); -    void setUrl(QModelIndex i); -    void buttonClicked(KDialog::ButtonCode code); -    void urlChanged(); - -private: -    QTreeView *m_treeView; -    QStandardItemModel *m_model; -     -    KLineEdit *m_line; -     -    int m_previewIndex; -}; - -#endif // PREVIEWCHOOSER_H diff --git a/src/rekonqpage/previewselectorbar.cpp b/src/rekonqpage/previewselectorbar.cpp new file mode 100644 index 00000000..04e7f0ac --- /dev/null +++ b/src/rekonqpage/previewselectorbar.cpp @@ -0,0 +1,138 @@ +/* +    <one line to give the program's name and a brief idea of what it does.> +    Copyright (C) <year>  <name of author> + +    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/>. + +*/ + + +// Auto Includes +#include "previewselectorbar.h" + +// KDE Includes +#include <KIcon> +#include <KLocalizedString> + +// Qt Includes +#include <QToolButton> +#include <QHBoxLayout> +#include <QString> + + +PreviewSelectorBar::PreviewSelectorBar(QWidget* parent) +        : QWidget(parent) +        , m_button(0) +        , m_label(0) +        , m_page(0) +{ +    hide(); +} + + +void PreviewSelectorBar::setup() +{ +    if(m_button != 0) +        return; +     +    m_label = new QLabel(i18n("Please go to the page you want to preview"), this); +    m_label->setWordWrap(true); +     +    QToolButton *closeButton = new QToolButton(this); +    closeButton->setAutoRaise(true); +    closeButton->setIcon(KIcon("dialog-close")); +    connect(closeButton, SIGNAL(clicked(bool)), SLOT(hide())); +     +    m_button = new QPushButton(KIcon("insert-image"), i18n("Set to this page"), this); +    connect(m_button, SIGNAL(clicked(bool)), SLOT(clicked())); +     +    // layout +    QHBoxLayout *layout = new QHBoxLayout(this); +    layout->addWidget(closeButton); +    layout->addStretch(); +    layout->addWidget(m_label); +    layout->addWidget(m_button); +     +    setLayout(layout); +} + + +void PreviewSelectorBar::setPage(WebPage* page) +{ +    m_page = page; +    verifyUrl(); +} + + +void PreviewSelectorBar::verifyUrl() +{ +    if(m_page->mainFrame()->url().scheme() != "about") +    { +        m_button->setEnabled(true); +        m_button->setToolTip(""); +    } +    else +    { +        m_button->setEnabled(false); +        m_button->setToolTip(i18n("You can't set this page as preview")); +    } +} + + +void PreviewSelectorBar::enable(int previewIndex, WebPage* page) +{ +    if(m_page != 0) +        disconnect(m_page, 0, this, 0); + +     +    setup(); +    m_previewIndex = previewIndex; +    m_page = page; +     +    verifyUrl(); +     +    show(); +     +    connect(page, SIGNAL(loadStarted()), SLOT(loadProgress())); +    connect(page, SIGNAL(loadProgress(int)), SLOT(loadProgress())); +    connect(page, SIGNAL(loadFinished(bool)), SLOT(loadFinished())); +    connect(page->mainFrame(), SIGNAL(urlChanged(QUrl)), SLOT(verifyUrl())); +} + + +void PreviewSelectorBar::loadProgress() +{ +    m_button->setEnabled(false); +    m_button->setToolTip(i18n("Page is loading...")); +} + + + +void PreviewSelectorBar::loadFinished() +{ +    m_button->setEnabled(true); +    m_button->setToolTip(""); +     +    verifyUrl(); +} + + +void PreviewSelectorBar::clicked() +{ +    m_page->newTabPage()->setPreview(m_previewIndex, m_page); +    m_page->mainFrame()->load(KUrl("about:favorites")); +    hide(); +} + + diff --git a/src/rekonqpage/previewselectorbar.h b/src/rekonqpage/previewselectorbar.h new file mode 100644 index 00000000..aa011fe4 --- /dev/null +++ b/src/rekonqpage/previewselectorbar.h @@ -0,0 +1,60 @@ +/* +    <one line to give the program's name and a brief idea of what it does.> +    Copyright (C) <year>  <name of author> + +    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 PREVIEWSELECTORBAR_H +#define PREVIEWSELECTORBAR_H + +// Local Includes +#include "webpage.h" + +// Qt Includes +#include <QWidget> +#include <QPushButton> +#include <QLabel> + +class PreviewSelectorBar : public QWidget +{ +    Q_OBJECT +     +    public: +        PreviewSelectorBar(QWidget *parent = 0); +         +        void setPage(WebPage *page); +         +    public slots: +        void enable(int previewIndex, WebPage *page); +        void clicked(); +         +        void loadProgress(); +        void loadFinished(); +         +        void verifyUrl(); +         +    private: +        void setup(); +         +        QPushButton *m_button; +        QLabel *m_label; +         +        int m_previewIndex; +        WebPage *m_page; +     +}; + +#endif // PREVIEWSELECTORBAR_H | 
