From b87a805af7b066159ff4f10ff9c30fd7428ea706 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 24 Jan 2010 19:17:58 +0100 Subject: Fixing panels With this commit I fixed panel behaviour && saved some bytes in their definition. This will help hacking there (they are pretty the same now, I just have no time to let them inherit from a parent "rekonq panel" class) and will save some bytes in rekonq footprint :) --- src/history/historypanel.cpp | 82 +++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 31 deletions(-) (limited to 'src/history/historypanel.cpp') diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp index 42497f9e..08dc3800 100644 --- a/src/history/historypanel.cpp +++ b/src/history/historypanel.cpp @@ -29,25 +29,52 @@ #include "historypanel.h" #include "historypanel.moc" +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "application.h" +#include "historymodels.h" + // Qt Includes #include #include #include +#include + // KDE Includes #include #include -HistoryPanel::HistoryPanel(QWidget *parent) - : QWidget(parent) - , m_historyTreeView(new QTreeView) - , m_treeProxyModel(new TreeProxyModel(this)) +HistoryPanel::HistoryPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) +{ + setup(); + setShown(ReKonfig::showHistoryPanel()); +} + + +HistoryPanel::~HistoryPanel() +{ + // Save side panel's state + ReKonfig::setShowHistoryPanel(!isHidden()); +} + + +void HistoryPanel::setup() { - m_historyTreeView->setUniformRowHeights(true); - m_historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); - m_historyTreeView->setTextElideMode(Qt::ElideMiddle); - m_historyTreeView->setAlternatingRowColors(true); + setObjectName("historyPanel"); + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + QWidget *ui = new QWidget(this); + + QTreeView *historyTreeView = new QTreeView(this); + historyTreeView->setUniformRowHeights(true); + historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); + historyTreeView->setTextElideMode(Qt::ElideMiddle); + historyTreeView->setAlternatingRowColors(true); // add search bar QHBoxLayout *hBoxLayout = new QHBoxLayout; @@ -60,42 +87,35 @@ HistoryPanel::HistoryPanel(QWidget *parent) QWidget *searchBar = new QWidget; searchBar->setLayout(hBoxLayout); - // setup view + // setup layout QVBoxLayout *vBoxLayout = new QVBoxLayout; vBoxLayout->setContentsMargins(0, 0, 0, 0); vBoxLayout->addWidget(searchBar); - vBoxLayout->addWidget(m_historyTreeView); - setLayout(vBoxLayout); + vBoxLayout->addWidget(historyTreeView); + + // add it to the UI + ui->setLayout(vBoxLayout); + setWidget(ui); //- HistoryManager *historyManager = Application::historyManager(); QAbstractItemModel *model = historyManager->historyTreeModel(); - m_treeProxyModel->setSourceModel(model); - m_historyTreeView->setModel(m_treeProxyModel); - m_historyTreeView->setExpanded(m_treeProxyModel->index(0, 0), true); - m_historyTreeView->header()->hideSection(1); + TreeProxyModel *treeProxyModel = new TreeProxyModel(this); + treeProxyModel->setSourceModel(model); + historyTreeView->setModel(treeProxyModel); + historyTreeView->setExpanded(treeProxyModel->index(0, 0), true); + historyTreeView->header()->hideSection(1); QFontMetrics fm(font()); int header = fm.width(QLatin1Char('m')) * 40; - m_historyTreeView->header()->resizeSection(0, header); - - connect(search, SIGNAL(textChanged(QString)), m_treeProxyModel, SLOT(setFilterFixedString(QString))); - connect(m_historyTreeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); -} - + historyTreeView->header()->resizeSection(0, header); -HistoryPanel::~HistoryPanel() -{ - delete m_treeProxyModel; - delete m_historyTreeView; + connect(search, SIGNAL(textChanged(QString)), treeProxyModel, SLOT(setFilterFixedString(QString))); + connect(historyTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &))); } -void HistoryPanel::open() +void HistoryPanel::itemActivated(const QModelIndex &item) { - QModelIndex index = m_historyTreeView->currentIndex(); - if (!index.parent().isValid()) - return; - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); + emit openUrl( item.data(HistoryModel::UrlRole).toUrl() ); } - -- cgit v1.2.1