Kate
expandingwidgetmodel.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef EXPANDING_WIDGET_MODEL_H 00022 #define EXPANDING_WIDGET_MODEL_H 00023 00024 #include <QAbstractTableModel> 00025 #include <QtCore/QHash> 00026 #include <QIcon> 00027 #include <QPersistentModelIndex> 00028 #include <QPointer> 00029 00030 class KWidget; 00031 class QTreeView; 00032 class QTextEdit; 00033 00037 class ExpandingWidgetModel : public QAbstractTableModel { 00038 Q_OBJECT 00039 public: 00040 00041 ExpandingWidgetModel( QWidget* parent ); 00042 virtual ~ExpandingWidgetModel(); 00043 00044 enum ExpandingType { 00045 NotExpandable=0, 00046 Expandable, 00047 Expanded 00048 }; 00049 00052 bool canExpandCurrentItem() const; 00054 bool canCollapseCurrentItem() const; 00056 void setCurrentItemExpanded( bool ); 00057 00058 void clearMatchQualities(); 00059 00061 void clearExpanding(); 00062 00064 bool isExpandable(const QModelIndex& index) const; 00065 00066 enum ExpansionType { 00067 NotExpanded = 0, 00068 ExpandDownwards, //The additional(expanded) information is shown UNDER the original information 00069 ExpandUpwards //The additional(expanded) information is shown ABOVE the original information 00070 }; 00071 00073 ExpansionType isPartiallyExpanded(const QModelIndex& index) const; 00074 00076 bool isExpanded(const QModelIndex & row) const; 00078 void setExpanded(QModelIndex index, bool expanded); 00079 00081 int expandingWidgetsHeight() const; 00082 00085 QWidget* expandingWidget(const QModelIndex & row) const; 00086 00088 int partiallyExpandWidgetHeight() const; 00097 00098 virtual void rowSelected(const QModelIndex & row); 00099 00101 QRect partialExpandRect(const QModelIndex & row) const; 00102 00103 QString partialExpandText(const QModelIndex & row) const; 00104 00107 void placeExpandingWidget(const QModelIndex & row); 00108 00109 virtual QTreeView* treeView() const = 0; 00110 00112 virtual bool indexIsItem(const QModelIndex& index) const = 0; 00113 00115 virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; 00116 00118 QModelIndex partiallyExpandedRow() const; 00119 00121 uint matchColor(const QModelIndex& index) const; 00122 00123 public slots: 00125 void placeExpandingWidgets(); 00126 00127 protected: 00131 virtual int contextMatchQuality(const QModelIndex & index) const = 0; 00132 00133 //Makes sure m_expandedIcon and m_collapsedIcon are loaded 00134 void cacheIcons() const; 00135 00136 static QIcon m_expandedIcon; 00137 static QIcon m_collapsedIcon; 00138 00139 //Does not update the view 00140 void partiallyUnExpand(const QModelIndex& index); 00141 //Finds out the basic height of the row represented by the given index. Basic means without respecting any expansion. 00142 int basicRowHeight( const QModelIndex& index ) const; 00143 00144 private: 00145 QMap<QModelIndex, ExpansionType> m_partiallyExpanded; 00146 // Store expanding-widgets and cache whether items can be expanded 00147 mutable QMap<QModelIndex, ExpandingType> m_expandState; 00148 QMap< QModelIndex, QPointer<QWidget> > m_expandingWidgets; //Map rows to their expanding-widgets 00149 QMap< QModelIndex, int > m_contextMatchQualities; //Map rows to their context-match qualities(undefined if unknown, else 0 to 10). Not used yet, eventually remove. 00150 }; 00151 00152 00160 QList<QVariant> mergeCustomHighlighting( QStringList strings, QList<QVariantList> highlights, int gapBetweenStrings = 0 ); 00161 #endif
KDE 4.6 API Reference