From 7fb9508d805f6f08adad56709ff5f709fcb2d1ee Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 20 Aug 2008 16:54:35 +0000 Subject: [PATCH] a tree view widget for now there is only this one that should be enough also for simple lists to not overpopulate the widget list svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=850021 --- CMakeLists.txt | 3 ++ includes/TreeView | 1 + widgets/treeview.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ widgets/treeview.h | 78 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 includes/TreeView create mode 100644 widgets/treeview.cpp create mode 100644 widgets/treeview.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ed80af8b..1eeede3ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,7 @@ set(plasma_LIB_SRCS widgets/signalplotter.cpp widgets/slider.cpp widgets/tabbar.cpp + widgets/treeview.cpp widgets/textedit.cpp widgets/webcontent.cpp ) @@ -189,6 +190,7 @@ install(FILES widgets/signalplotter.h widgets/slider.h widgets/tabbar.h + widgets/treeview.h widgets/textedit.h widgets/webcontent.h DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel) @@ -252,6 +254,7 @@ includes/TabBar includes/TextEdit includes/ToolTipManager includes/Theme +includes/TreeView includes/UiLoader includes/View includes/Version diff --git a/includes/TreeView b/includes/TreeView new file mode 100644 index 000000000..a7cf84550 --- /dev/null +++ b/includes/TreeView @@ -0,0 +1 @@ +#include "../../plasma/widgets/treeview.h" diff --git a/widgets/treeview.cpp b/widgets/treeview.cpp new file mode 100644 index 000000000..7bd44e6fb --- /dev/null +++ b/widgets/treeview.cpp @@ -0,0 +1,90 @@ +/* + * Copyright 2008 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "treeview.h" + +#include +#include +#include + +#include + +#include "private/style.h" + + +class TreeViewPrivate +{ +public: + TreeViewPrivate() + { + } + + ~TreeViewPrivate() + { + } +}; + +TreeView::TreeView(QGraphicsWidget *parent) + : QGraphicsProxyWidget(parent), + d(new TreeViewPrivate) +{ + QTreeView* native = new QTreeView; + setWidget(native); + native->setAttribute(Qt::WA_NoSystemBackground); + native->viewport()->setAutoFillBackground(false); + native->setFrameStyle(QFrame::NoFrame); + native->setIconSize(QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium)); + + Plasma::Style *style = new Plasma::Style(); + native->verticalScrollBar()->setStyle(style); + native->horizontalScrollBar()->setStyle(style); +} + +TreeView::~TreeView() +{ + delete d; +} + +void TreeView::setModel(QAbstractItemModel *model) +{ + nativeWidget()->setModel(model); +} + +QAbstractItemModel *TreeView::model() +{ + return nativeWidget()->model(); +} + +void TreeView::setStyleSheet(const QString &stylesheet) +{ + widget()->setStyleSheet(stylesheet); +} + +QString TreeView::styleSheet() +{ + return widget()->styleSheet(); +} + +QTreeView* TreeView::nativeWidget() const +{ + return static_cast(widget()); +} + +#include + diff --git a/widgets/treeview.h b/widgets/treeview.h new file mode 100644 index 000000000..892471e92 --- /dev/null +++ b/widgets/treeview.h @@ -0,0 +1,78 @@ +/* + * Copyright 2008 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#ifndef PLASMA_TREEVIEW_H +#define PLASMA_TREEVIEW_H + +#include + +class QTreeView; +class QAbstractItemModel; + + +class TreeViewPrivate; + +class TreeView : public QGraphicsProxyWidget +{ + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel) + Q_PROPERTY(QGraphicsWidget* parentWidget READ parentWidget) + Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) + Q_PROPERTY(QTreeView* nativeWidget READ nativeWidget) + +public: + explicit TreeView(QGraphicsWidget *parent = 0); + ~TreeView(); + + /** + * Sets a model for this weather view + * + * @arg model the model to display + */ + void setModel(QAbstractItemModel *model); + + /** + * @return the model shown by this view + */ + QAbstractItemModel *model(); + + /** + * Sets the stylesheet used to control the visual display of this TreeView + * + * @arg stylesheet a CSS string + */ + void setStyleSheet(const QString &stylesheet); + + /** + * @return the stylesheet currently used with this widget + */ + QString styleSheet(); + + /** + * @return the native widget wrapped by this TreeView + */ + QTreeView* nativeWidget() const; + +private: + TreeViewPrivate * const d; +}; + +#endif // multiple inclusion guard