From 682cac6c2ce4cf21b9a2f4314cc452060f389b20 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 14 Dec 2009 00:00:19 +0100 Subject: Just some stupid fixes --- src/bookmarks/bookmarkspanel.cpp | 52 +++-- src/bookmarks/bookmarkspanel.h | 5 +- src/bookmarks/bookmarksproxy.cpp | 59 +++-- src/bookmarks/bookmarkstreemodel.cpp | 430 ++++++++++++++++++++--------------- src/clicktoflash.cpp | 7 +- src/mainview.cpp | 28 ++- src/webinspectordock.cpp | 7 +- src/webview.cpp | 2 +- 8 files changed, 352 insertions(+), 238 deletions(-) diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index a09e0058..97097fbb 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -24,8 +24,11 @@ * ============================================================ */ -// rekonq includes +// Self Includes #include "bookmarkspanel.h" +#include "bookmarkspanel.moc" + +// Local Includes #include "bookmarkstreemodel.h" #include "bookmarksproxy.h" @@ -42,11 +45,11 @@ #include #include -BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags): - QDockWidget(title, parent, flags) -{ - setup(); +BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) +{ + setup(); setShown(ReKonfig::showBookmarksPanel()); } @@ -54,22 +57,23 @@ BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::Window BookmarksPanel::~BookmarksPanel() { ReKonfig::setShowBookmarksPanel(!isHidden()); - - delete ui; + delete ui; } + void BookmarksPanel::bookmarkActivated( const QModelIndex &index ) { - if( index.isValid() ) - emit openUrl( qVariantValue< KUrl >( index.data( Qt::UserRole ) ) ); + if( index.isValid() ) + emit openUrl( qVariantValue< KUrl >( index.data( Qt::UserRole ) ) ); } + void BookmarksPanel::setup() { - setObjectName("bookmarksPanel"); + setObjectName("bookmarksPanel"); setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - ui = new QWidget(this); + ui = new QWidget(this); // setup search bar QHBoxLayout *searchLayout = new QHBoxLayout; @@ -79,16 +83,16 @@ void BookmarksPanel::setup() KLineEdit *search = new KLineEdit; search->setClearButtonShown(true); searchLayout->addWidget(search); - searchLabel->setBuddy( search ); + searchLabel->setBuddy( search ); - // setup tree view - QTreeView *treeView = new QTreeView(ui); + // setup tree view + QTreeView *treeView = new QTreeView(ui); treeView->setUniformRowHeights(true); treeView->setSelectionBehavior(QAbstractItemView::SelectRows); treeView->setTextElideMode(Qt::ElideMiddle); treeView->setAlternatingRowColors(true); - treeView->header()->hide(); - treeView->setRootIsDecorated( false ); + treeView->header()->hide(); + treeView->setRootIsDecorated( false ); // put everything together QVBoxLayout *vBoxLayout = new QVBoxLayout; @@ -96,15 +100,15 @@ void BookmarksPanel::setup() vBoxLayout->addLayout(searchLayout); vBoxLayout->addWidget(treeView); - // add it to the UI + // add it to the UI ui->setLayout(vBoxLayout); - setWidget(ui); + setWidget(ui); - BookmarksTreeModel *model = new BookmarksTreeModel( this ); - BookmarksProxy *proxy = new BookmarksProxy(ui); - proxy->setSourceModel( model ); - treeView->setModel( proxy ); + BookmarksTreeModel *model = new BookmarksTreeModel( this ); + BookmarksProxy *proxy = new BookmarksProxy(ui); + proxy->setSourceModel( model ); + treeView->setModel( proxy ); - connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); - connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); + connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); + connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); } diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h index 8c3e6121..b7c0b5ed 100644 --- a/src/bookmarks/bookmarkspanel.h +++ b/src/bookmarks/bookmarkspanel.h @@ -34,6 +34,7 @@ class KUrl; class QModelIndex; + class BookmarksPanel : public QDockWidget { Q_OBJECT @@ -47,10 +48,10 @@ signals: void openUrl(const KUrl &); private slots: - void bookmarkActivated( const QModelIndex &index ); + void bookmarkActivated( const QModelIndex &index ); private: - void setup(); + void setup(); QWidget *ui; }; diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp index 87d1ce71..e94fbeff 100644 --- a/src/bookmarks/bookmarksproxy.cpp +++ b/src/bookmarks/bookmarksproxy.cpp @@ -1,29 +1,56 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes #include "bookmarksproxy.h" +#include "bookmarksproxy.moc" -BookmarksProxy::BookmarksProxy( QObject *parent ): - QSortFilterProxyModel( parent ) + +BookmarksProxy::BookmarksProxy( QObject *parent ) + : QSortFilterProxyModel( parent ) { } + bool BookmarksProxy::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const { - QModelIndex idx = sourceModel()->index( source_row, 0, source_parent ); - -// return idx.data().toString().contains( filterRegExp() ); - return recursiveMatch( idx ); + QModelIndex idx = sourceModel()->index( source_row, 0, source_parent ); + return recursiveMatch( idx ); } + bool BookmarksProxy::recursiveMatch( const QModelIndex &index ) const { - if( index.data().toString().contains( filterRegExp() ) ) { - return true; - } - - for( int childRow = 0; childRow < sourceModel()->rowCount( index ); ++childRow ) { - if( recursiveMatch( sourceModel()->index( childRow, 0, index ) ) ) { - return true; - } - } + if( index.data().toString().contains( filterRegExp() ) ) + return true; - return false; + for( int childRow = 0; childRow < sourceModel()->rowCount( index ); ++childRow ) + { + if( recursiveMatch( sourceModel()->index( childRow, 0, index ) ) ) + return true; + } + return false; } diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp index b5690a9b..140fa9c8 100644 --- a/src/bookmarks/bookmarkstreemodel.cpp +++ b/src/bookmarks/bookmarkstreemodel.cpp @@ -1,6 +1,34 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes #include "bookmarkstreemodel.h" +#include "bookmarkstreemodel.moc" -// rekonq includes +// Local Includes #include "application.h" #include "bookmarksmanager.h" @@ -8,248 +36,288 @@ #include #include + class BookmarksTreeModel::BtmItem { public: - BtmItem(const KBookmark &bm): - m_parent(0), m_kbm(bm) - { - } - ~BtmItem() - { - qDeleteAll(m_children); - } - - QVariant data( int role = Qt::DisplayRole ) const - { - if( m_kbm.isNull() ) - return QVariant();// should only happen for root item - - if( role == Qt::DisplayRole ) - return m_kbm.text(); - if( role == Qt::DecorationRole ) - return KIcon( m_kbm.icon() ); - if( role == Qt::UserRole ) - return m_kbm.url(); - - return QVariant(); - } - - int row() const - { - if(m_parent) - return m_parent->m_children.indexOf( const_cast< BtmItem* >( this ) ); - return 0; - } - int childCount() const - { - return m_children.count(); - } - BtmItem* child( int n ) - { - Q_ASSERT(n>=0); - Q_ASSERT(nm_parent = this; - m_children << child; - } - void clear() - { - qDeleteAll(m_children); - m_children.clear(); - } + BtmItem(const KBookmark &bm) + : m_parent(0) + , m_kbm(bm) + { + } + + + ~BtmItem() + { + qDeleteAll(m_children); + } + + + QVariant data( int role = Qt::DisplayRole ) const + { + if( m_kbm.isNull() ) + return QVariant(); // should only happen for root item + + if( role == Qt::DisplayRole ) + return m_kbm.text(); + if( role == Qt::DecorationRole ) + return KIcon( m_kbm.icon() ); + if( role == Qt::UserRole ) + return m_kbm.url(); + + return QVariant(); + } + + + int row() const + { + if(m_parent) + return m_parent->m_children.indexOf( const_cast< BtmItem* >( this ) ); + return 0; + } + + + int childCount() const + { + return m_children.count(); + } -private: - BtmItem *m_parent; - QList< BtmItem* > m_children; - KBookmark m_kbm; + BtmItem* child( int n ) + { + Q_ASSERT(n>=0); + Q_ASSERT(nm_parent = this; + m_children << child; + } + + + void clear() + { + qDeleteAll(m_children); + m_children.clear(); + } + +private: + BtmItem *m_parent; + QList< BtmItem* > m_children; + KBookmark m_kbm; }; -BookmarksTreeModel::BookmarksTreeModel(QObject *parent): - QAbstractItemModel(parent), m_root(0) + +// ------------------------------------------------------------------------------------- + + +BookmarksTreeModel::BookmarksTreeModel(QObject *parent) + : QAbstractItemModel(parent) + , m_root(0) { - resetModel(); - connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( changed(QString,QString) ), this, SLOT( bookmarksChanged(QString) ) ); - connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( bookmarksChanged(QString) ), this, SLOT( bookmarksChanged(QString) ) ); + resetModel(); + connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( changed(QString,QString) ), this, SLOT( bookmarksChanged(QString) ) ); + connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( bookmarksChanged(QString) ), this, SLOT( bookmarksChanged(QString) ) ); } + BookmarksTreeModel::~BookmarksTreeModel() { - delete m_root; + delete m_root; } + int BookmarksTreeModel::rowCount(const QModelIndex &parent) const { - BtmItem *parentItem = 0; - if( !parent.isValid() ) { - parentItem = m_root; - } - else { - parentItem = static_cast< BtmItem* >( parent.internalPointer() ); - } - - return parentItem->childCount(); + BtmItem *parentItem = 0; + if( !parent.isValid() ) + { + parentItem = m_root; + } + else + { + parentItem = static_cast< BtmItem* >( parent.internalPointer() ); + } + + return parentItem->childCount(); } -int BookmarksTreeModel::columnCount(const QModelIndex &/*parent*/) const + +int BookmarksTreeModel::columnCount(const QModelIndex &parent) const { - // name - return 1; + Q_UNUSED(parent) + // name + return 1; } + QVariant BookmarksTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { - if( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 ) - return i18n( "Bookmark" ); + if( orientation == Qt::Horizontal + && role == Qt::DisplayRole + && section == 0 + ) + return i18n( "Bookmark" ); - return QVariant(); + return QVariant(); } -Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &/*index*/) const + +Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &index) const { - return Qt::ItemIsEnabled|Qt::ItemIsSelectable; + Q_UNUSED(index) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } + QModelIndex BookmarksTreeModel::index(int row, int column, const QModelIndex &parent) const { - if( !hasIndex( row, column, parent ) ) { - return QModelIndex(); - } - - BtmItem *parentItem; - - if( !parent.isValid() ) { - parentItem = m_root; - } - else { - parentItem = static_cast< BtmItem* >( parent.internalPointer() ); - } - - BtmItem *childItem = parentItem->child( row ); - if( childItem ) { - return createIndex( row, column, childItem ); - } - - return QModelIndex(); + if( !hasIndex( row, column, parent ) ) + { + return QModelIndex(); + } + + BtmItem *parentItem; + + if( !parent.isValid() ) + { + parentItem = m_root; + } + else + { + parentItem = static_cast< BtmItem* >( parent.internalPointer() ); + } + + BtmItem *childItem = parentItem->child( row ); + if( childItem ) + { + return createIndex( row, column, childItem ); + } + + return QModelIndex(); } + QModelIndex BookmarksTreeModel::parent(const QModelIndex &index) const { - if( !index.isValid() ) { - return QModelIndex(); - } + if( !index.isValid() ) + { + return QModelIndex(); + } - BtmItem *childItem = static_cast< BtmItem* >( index.internalPointer() ); - BtmItem *parentItem = childItem->parent(); + BtmItem *childItem = static_cast< BtmItem* >( index.internalPointer() ); + BtmItem *parentItem = childItem->parent(); - if( parentItem == m_root ) { - return QModelIndex(); - } + if( parentItem == m_root ) + { + return QModelIndex(); + } - return createIndex( parentItem->row(), 0, parentItem ); + return createIndex( parentItem->row(), 0, parentItem ); } + QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const { - if( !index.isValid() ) { - return QVariant(); - } - - BtmItem *node = static_cast< BtmItem* >( index.internalPointer() ); - if( node && node == m_root ) { - if( role == Qt::DisplayRole ) - return i18n( "Bookmarks" ); - else if( role == Qt::DecorationRole ) - return KIcon( "bookmarks" ); - } - else if( node ) { - return node->data( role ); - } - - return QVariant(); + if( !index.isValid() ) + { + return QVariant(); + } + + BtmItem *node = static_cast< BtmItem* >( index.internalPointer() ); + if( node && node == m_root ) + { + if( role == Qt::DisplayRole ) + return i18n( "Bookmarks" ); + if( role == Qt::DecorationRole ) + return KIcon( "bookmarks" ); + } + else + { + if( node ) + return node->data( role ); + } + + return QVariant(); } -// bool BookmarksTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) -// { -// } void BookmarksTreeModel::bookmarksChanged( const QString &groupAddress ) { -// qDebug( "bookmarksChanged '%s'", qPrintable( groupAddress ) ); - - if( groupAddress.isEmpty() ) { - resetModel(); - return; - } - - BtmItem *node = m_root; - QModelIndex nodeIndex; - - QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) ); - foreach( QString sIndex, indexChain ) { - bool ok; - int i = sIndex.toInt( &ok ); - if( !ok ) - break; - - if( i < 0 || i >= node->childCount() ) - break; - - node = node->child( i ); - nodeIndex = index( i, 0, nodeIndex ); - } -// qDebug( " changed: '%s'(0-%d)", ( node == m_root ? "ROOT" : qPrintable( node->data().toString() ) ), node->childCount() ); - emit dataChanged( index( 0, 0, nodeIndex ), index( node->childCount(), 0, nodeIndex ) ); + if( groupAddress.isEmpty() ) + { + resetModel(); + return; + } + + BtmItem *node = m_root; + QModelIndex nodeIndex; + + QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) ); + foreach( QString sIndex, indexChain ) + { + bool ok; + int i = sIndex.toInt( &ok ); + if( !ok ) + break; + + if( i < 0 || i >= node->childCount() ) + break; + + node = node->child( i ); + nodeIndex = index( i, 0, nodeIndex ); + } + emit dataChanged( index( 0, 0, nodeIndex ), index( node->childCount(), 0, nodeIndex ) ); } + void BookmarksTreeModel::resetModel() { - setRoot(Application::bookmarkProvider()->rootGroup()); + setRoot(Application::bookmarkProvider()->rootGroup()); } + void BookmarksTreeModel::setRoot(KBookmarkGroup bmg) { - delete m_root; - m_root = new BtmItem(KBookmark()); + delete m_root; + m_root = new BtmItem(KBookmark()); - if( bmg.isNull() ) { - return; - } + if( bmg.isNull() ) + return; - populate( m_root, bmg ); - - reset(); + populate( m_root, bmg ); + reset(); } + void BookmarksTreeModel::populate( BtmItem *node, KBookmarkGroup bmg) { - node->clear(); + node->clear(); - if( bmg.isNull() ) { - return; - } + if( bmg.isNull() ) + return; - KBookmark bm = bmg.first(); - while( !bm.isNull() ) { - BtmItem *newChild = new BtmItem( bm ); - if( bm.isGroup() ) - populate( newChild, bm.toGroup() ); + KBookmark bm = bmg.first(); + while( !bm.isNull() ) + { + BtmItem *newChild = new BtmItem( bm ); + if( bm.isGroup() ) + populate( newChild, bm.toGroup() ); - node->appendChild( newChild ); - bm = bmg.next( bm ); - } + node->appendChild( newChild ); + bm = bmg.next( bm ); + } } diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp index b6ea1093..b6e1df34 100644 --- a/src/clicktoflash.cpp +++ b/src/clicktoflash.cpp @@ -50,15 +50,20 @@ * ============================================================ */ +// Self Includes #include "clicktoflash.h" +#include "clicktoflash.moc" +// KDE Includes +#include + +// Qt Includes #include #include #include #include #include -#include ClickToFlash::ClickToFlash(QUrl pluginUrl, QWidget *parent) diff --git a/src/mainview.cpp b/src/mainview.cpp index d2105dcd..3285c630 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -312,7 +312,10 @@ void MainView::currentChanged(int index) WebView *MainView::webView(int index) const { - if (this->widget(index) && this->widget(index)->layout() && this->widget(index)->layout()->itemAt(1)) //TODO: find why it crashes when closetab without that. + if( this->widget(index) + && this->widget(index)->layout() + && this->widget(index)->layout()->itemAt(1) //TODO: find why it crashes when closetab without that. + ) { QWidget *widget = this->widget(index)->layout()->itemAt(1)->widget(); if (WebView *webView = qobject_cast(widget)) @@ -328,19 +331,24 @@ WebView *MainView::webView(int index) const WebView *MainView::newWebView(bool focused, bool nearParent) { - QWidget* w=new QWidget; - QVBoxLayout* l=new QVBoxLayout(w); + QWidget* w = new QWidget; + QVBoxLayout* l = new QVBoxLayout; l->setMargin(0); - QWidget* messageBar=new QWidget; // should be deleted on tab close? - QVBoxLayout* l2=new QVBoxLayout(messageBar); - l->addWidget(messageBar); - + + // this messageBar with its relative layout is useful to embed widget, + // like the wallet bar and so on + QWidget* messageBar = new QWidget; // should be deleted on tab close? // yes! + QVBoxLayout* l2 = new QVBoxLayout; + messageBar->setLayout(l2); messageBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); messageBar->hide(); - WebView *webView = new WebView(w,messageBar); // should be deleted on tab close? + l->addWidget(messageBar); + + WebView *webView = new WebView(w, messageBar); // should be deleted on tab close? l->addWidget(webView); webView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + w->setLayout(l); // connecting webview with mainview connect(webView, SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted())); @@ -505,8 +513,8 @@ void MainView::closeTab(int index) QWidget *webView = this->webView(index); removeTab(index); updateTabBar(); // UI operation: do it ASAP!! - webView->deleteLater(); // webView is scheduled for deletion. - + webView->deleteLater(); // webView is scheduled for deletion. + emit tabsChanged(); if (hasFocus && count() > 0) diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp index 51fdbdaf..f91df31a 100644 --- a/src/webinspectordock.cpp +++ b/src/webinspectordock.cpp @@ -25,18 +25,19 @@ // Self Includes #include "webinspectordock.h" +#include "webinspectordock.moc" // Local Includes #include "webview.h" #include "webpage.h" -// Qt Includes -#include - // KDE Includes #include "KAction" #include "KDebug" +// Qt Includes +#include + WebInspectorDock::WebInspectorDock(QString title, QWidget *parent) : QDockWidget(title, parent) diff --git a/src/webview.cpp b/src/webview.cpp index 568c5981..97ec4984 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -60,8 +60,8 @@ WebView::WebView(QWidget* parent, QWidget* messageWidget) : KWebView(parent, false) - , m_messageWidget(messageWidget) , m_page( new WebPage(this) ) + , m_messageWidget(messageWidget) , m_progress(0) , m_mousePos(QPoint(0,0)) { -- cgit v1.2.1