summaryrefslogtreecommitdiff
path: root/src/rekonqpage/previewchooser.cpp
diff options
context:
space:
mode:
authormatgic78 <matgic78@gmail.com>2009-12-26 13:00:53 +0100
committermatgic78 <matgic78@gmail.com>2010-02-06 11:22:46 +0100
commit18b87086d1a0e472662f3883962b60dbe57e215f (patch)
tree05642e5ccafe858222463e2bfddaad850c05de95 /src/rekonqpage/previewchooser.cpp
parentVarious changes: (diff)
downloadrekonq-18b87086d1a0e472662f3883962b60dbe57e215f.tar.xz
First expermimental implementation of a new way of choosing a preview
Diffstat (limited to 'src/rekonqpage/previewchooser.cpp')
-rw-r--r--src/rekonqpage/previewchooser.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/rekonqpage/previewchooser.cpp b/src/rekonqpage/previewchooser.cpp
new file mode 100644
index 00000000..a7c86d12
--- /dev/null
+++ b/src/rekonqpage/previewchooser.cpp
@@ -0,0 +1,143 @@
+/* ============================================================
+*
+* 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>
+
+// Qt Includes
+#include <QLabel>
+#include <QVBoxLayout>
+
+// KDE Includes
+#include <KLineEdit>
+#include <KLocalizedString>
+
+
+PreviewChooser::PreviewChooser(int previewIndex)
+ : 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;
+ connect(m_line, SIGNAL(textChanged(QString)), SLOT(urlChanged()));
+ urlLayout->addWidget(m_line);
+
+ // 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)));
+}
+
+
+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->webView(i));
+
+ if(view->url().scheme() == "about:")
+ continue;
+
+ QStandardItem *it = new QStandardItem(view->icon(), view->title());
+ it->setData(QVariant(view->url()), Qt::ToolTipRole);
+ m_model->insertRow(i, 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)
+ {
+ emit urlChoosed(m_previewIndex, KUrl(m_line->text()));
+ enableButtonApply(false);
+ }
+
+ if(code == KDialog::Cancel || code == KDialog::Ok)
+ {
+ close();
+ deleteLater();
+ }
+}
+
+
+void PreviewChooser::urlChanged()
+{
+ enableButtonApply(true);
+}
+