[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project

src/klflibview.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klflibview.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2010 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id: klflibview.h 517 2010-09-27 12:46:50Z philippe $ */
00023 
00024 #ifndef KLFLIBVIEW_H
00025 #define KLFLIBVIEW_H
00026 
00027 #include <QAbstractItemModel>
00028 #include <QAbstractItemDelegate>
00029 #include <QMimeData>
00030 #include <QEvent>
00031 #include <QWidget>
00032 #include <QDialog>
00033 #include <QAbstractButton>
00034 #include <QTreeView>
00035 #include <QItemSelectionModel>
00036 #include <QTextDocument>
00037 #include <QTextCharFormat>
00038 #include <QStandardItemModel>
00039 #include <QListView>
00040 
00041 #include <klfdefs.h>
00042 #include <klflib.h>
00043 #include <klfsearchbar.h>
00044 #include <klfguiutil.h>
00045 
00046 
00047 namespace KLFLib {
00048   enum RestoreMode {
00049     RestoreLatex = 0x0001,
00050     RestoreStyle = 0x0002,
00051 
00052     RestoreLatexAndStyle = RestoreLatex|RestoreStyle,
00053     RestoreAll = 0xFFFF
00054   };
00055 };
00056 
00057 
00059 
00082 class KLF_EXPORT KLFAbstractLibView : public QWidget
00083 {
00084   Q_OBJECT
00085 public:
00086   KLFAbstractLibView(QWidget *parent);
00087   virtual ~KLFAbstractLibView() { }
00088 
00089   virtual KLFLibResourceEngine * resourceEngine() const { return pResourceEngine; }
00090 
00092 
00102   virtual QUrl url() const = 0;
00103 
00105 
00130   virtual uint compareUrlTo(const QUrl& other, uint interestFlags = 0xFFFFFFFF) const = 0;
00131 
00132 
00134   inline bool validResourceEngine() const { return pResourceEngine != NULL; }
00135 
00136   virtual void setResourceEngine(KLFLibResourceEngine *resource);
00137 
00139   virtual KLFLibEntryList selectedEntries() const = 0;
00140 
00143   virtual QList<KLFLib::entryId> selectedEntryIds() const = 0;
00144 
00153   virtual QList<QAction*> addContextMenuActions(const QPoint& pos);
00154 
00156   virtual QVariantMap saveGuiState() const = 0;
00157 
00160   virtual bool restoreGuiState(const QVariantMap& state) = 0;
00161 
00165   virtual QStringList getCategorySuggestions() = 0;
00166 
00167   virtual KLFSearchable * searchable() { return NULL; }
00168 
00169 signals:
00177   void requestRestore(const KLFLibEntry& entry, uint restoreflags = KLFLib::RestoreLatexAndStyle);
00181   void requestRestoreStyle(const KLFStyle& style);
00182 
00184   void resourceDataChanged(const QList<KLFLib::entryId>& entryIdList);
00185 
00187   void entriesSelected(const KLFLibEntryList& entries);
00188 
00191   void moreCategorySuggestions(const QStringList& categorylist);
00192 
00198   void operationStartReportingProgress(KLFProgressReporter *progressReporter, const QString& descriptiveText);
00199 
00200 public slots:
00201   virtual void updateResourceEngine() = 0;
00202   virtual void updateResourceProp(int propId) = 0;
00203   virtual void updateResourceData(const QString& subres, int modifyType,
00204                                   const QList<KLFLib::entryId>& entryIdList) = 0;
00206   virtual void updateResourceDefaultSubResourceChanged(const QString& newSubResource);
00207 
00214   //  virtual bool writeEntryProperty(int property, const QVariant& value) = 0;
00215 
00216   /* * Provides a reasonable default implementation that should suit for most purposes. */
00217   //  virtual bool writeEntryCategory(const QString& category)
00218   //  { return writeEntryProperty(KLFLibEntry::Category, category); }
00219 
00220   /* * Provides a reasonable default implementation that should suit for most purposes. */
00221   //  virtual bool writeEntryTags(const QString& tags)
00222   //  { return writeEntryProperty(KLFLibEntry::Tags, tags); }
00223 
00224   //  virtual bool deleteSelected(bool requireConfirm = true);
00225 
00226   //   virtual bool insertEntries(const KLFLibEntryList& entries);
00227 
00228   /* * Provides a reasonable default implementation that should suit for most purposes. */
00229   //   virtual bool insertEntry(const KLFLibEntry& entry)
00230   //   { return insertEntries(KLFLibEntryList() << entry); }
00231 
00238   virtual bool selectEntries(const QList<KLFLib::entryId>& idList) = 0;
00239 
00241   virtual void restore(uint restoreFlags = KLFLib::RestoreLatexAndStyle) = 0;
00243   virtual void restoreWithStyle() { restore(KLFLib::RestoreLatexAndStyle); }
00245   virtual void restoreLatexOnly() { restore(KLFLib::RestoreLatex); }
00246 
00252   virtual void wantMoreCategorySuggestions();
00253 
00254 private:
00255   KLFLibResourceEngine *pResourceEngine;
00256 };
00257 
00258 
00259 // -----------------
00260 
00261 class KLF_EXPORT KLFLibViewFactory : public QObject
00262 {
00263   Q_OBJECT
00264 public:
00265   KLFLibViewFactory(const QStringList& viewTypeIdentifiers, QObject *parent = NULL);
00266   virtual ~KLFLibViewFactory();
00267 
00272   virtual QStringList viewTypeIdentifiers() { return pViewTypeIdentifiers; }
00273 
00276   virtual QString viewTypeTitle(const QString& viewTypeIdent) const = 0;
00277 
00282   virtual bool canCreateLibView(const QString& viewTypeIdent, KLFLibResourceEngine *engine) = 0;
00283 
00286   virtual KLFAbstractLibView * createLibView(const QString& viewTypeIdent, QWidget *parent,
00287                                              KLFLibResourceEngine *resourceEngine) = 0;
00288 
00293   static QString defaultViewTypeIdentifier();
00294 
00297   static KLFLibViewFactory *findFactoryFor(const QString& viewTypeIdentifier);
00298 
00301   static QStringList allSupportedViewTypeIdentifiers();
00303   static QList<KLFLibViewFactory*> allFactories() { return pRegisteredFactories; }
00304 
00305 private:
00306   QStringList pViewTypeIdentifiers;
00307 
00308   static void registerFactory(KLFLibViewFactory *factory);
00309   static void unRegisterFactory(KLFLibViewFactory *factory);
00310 
00311   static QList<KLFLibViewFactory*> pRegisteredFactories;
00312 
00313 };
00314 
00315 
00316 // --------------------
00317 
00318 
00319 
00321 
00339 class KLF_EXPORT KLFLibWidgetFactory : public QObject, public KLFFactoryBase
00340 {
00341   Q_OBJECT
00342 public:
00351   typedef KLFLibEngineFactory::Parameters Parameters;
00352   
00355   KLFLibWidgetFactory(QObject *parent);
00356 
00359   static KLFLibWidgetFactory * findFactoryFor(const QString& wtype);
00360 
00363   static QStringList allSupportedWTypes();
00364 
00365 
00367 
00368   virtual QStringList supportedTypes() const = 0;
00369 
00371 
00374   virtual QString widgetTypeTitle(const QString& wtype) const = 0;
00375 
00389   virtual QWidget * createPromptUrlWidget(QWidget *wparent, const QString& wtype,
00390                                           QUrl defaultlocation = QUrl()) = 0;
00391 
00394   virtual QUrl retrieveUrlFromWidget(const QString& wtype, QWidget *widget) = 0;
00395 
00398   virtual bool hasCreateWidget(const QString& wtype) const;
00399 
00406   virtual QWidget *createPromptCreateParametersWidget(QWidget *wparent, const QString& wtype,
00407                                                       const Parameters& defaultparameters = Parameters());
00424   virtual Parameters retrieveCreateParametersFromWidget(const QString& wtype, QWidget *widget);
00425 
00428   virtual bool hasSaveToWidget(const QString& wtype) const;
00433   virtual QWidget *createPromptSaveToWidget(QWidget *wparent, const QString& wtype,
00434                                             KLFLibResourceEngine *resource, const QUrl& defaultUrl);
00437   virtual QUrl retrieveSaveToUrlFromWidget(const QString& wtype, QWidget *widget);
00438 
00439 
00440 private:
00441   static KLFFactoryManager pFactoryManager;
00442 };
00443 
00444 
00445 
00446 
00447 
00448 // -----------------
00449 
00450 class KLFLibModelCache;
00451 
00459 class KLF_EXPORT KLFLibModel : public QAbstractItemModel
00460 {
00461   Q_OBJECT
00462 public:
00463   enum FlavorFlag {
00464     LinearList = 0x0001,
00465     IconViewList = LinearList,
00466     CategoryTree = 0x0002,
00467     DisplayTypeMask = 0x000f,
00468 
00469     GroupSubCategories = 0x1000
00470   };
00471 
00472   KLFLibModel(KLFLibResourceEngine *resource, uint flavorFlags = LinearList|GroupSubCategories,
00473               QObject *parent = NULL);
00474   virtual ~KLFLibModel();
00475 
00476   enum ItemKind { EntryKind, CategoryLabelKind };
00477   enum {
00478     ItemKindItemRole = Qt::UserRole+768, // = 800 in Qt 4.4, nice in debugging messages ;-)
00479     EntryContentsTypeItemRole,
00480     EntryIdItemRole,
00481     FullEntryItemRole,
00482     CategoryLabelItemRole,
00483     FullCategoryPathItemRole
00484   };
00485 
00492   static inline int entryItemRole(int propertyId) { return (Qt::UserRole+788) + propertyId; } // = 820+propId
00494   static inline int entryPropIdForItemRole(int role)  { return role - (Qt::UserRole+788); } // = role - 820
00495   
00496   virtual void setResource(KLFLibResourceEngine *resource);
00497 
00498   virtual KLFLibResourceEngine * resource() { return pResource; }
00499 
00500   virtual QUrl url() const;
00501 
00511   virtual void setFlavorFlags(uint flags, uint modify_mask = 0xffffffff);
00512   virtual uint flavorFlags() const;
00513   inline uint displayType() const { return flavorFlags() & DisplayTypeMask; }
00514 
00516   virtual void prefetch(const QModelIndexList& index) const;
00517   virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
00518   virtual Qt::ItemFlags flags(const QModelIndex& index) const;
00519   virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
00520   virtual QVariant headerData(int section, Qt::Orientation orientation,
00521                               int role = Qt::DisplayRole) const;
00522   virtual bool hasIndex(int row, int column,
00523                         const QModelIndex &parent = QModelIndex()) const;
00524   virtual QModelIndex index(int row, int column,
00525                             const QModelIndex &parent = QModelIndex()) const;
00526   virtual QModelIndex parent(const QModelIndex &index) const;
00527   virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
00528   virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
00529 
00530   virtual bool canFetchMore(const QModelIndex& parent) const;
00531   virtual void fetchMore(const QModelIndex& parent);
00532 
00533   virtual Qt::DropActions supportedDropActions() const;
00534 
00535   virtual QStringList mimeTypes() const;
00536   virtual QMimeData *mimeData(const QModelIndexList& indexes) const;
00537 
00538   virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
00539                             int column, const QModelIndex& parent);
00540 
00541   enum { DropWillAccept = 0x0001,
00542          DropWillCategorize = 0x0002,
00543          DropWillMove = 0x0004 };
00544   virtual uint dropFlags(QDragMoveEvent *event, QAbstractItemView *view);
00545 
00546   virtual QImage dragImage(const QModelIndexList& indexes);
00547 
00548   virtual int entryColumnContentsPropertyId(int column) const;
00549   virtual int columnForEntryPropertyId(int entryPropertyId) const;
00550 
00551   virtual bool isDesendantOf(const QModelIndex& child, const QModelIndex& ancestor);
00552 
00553   virtual QStringList categoryList() const;
00554 
00555   virtual void updateData(const QList<KLFLib::entryId>& entryIdList, int modifyType);
00556 
00558   virtual QModelIndex walkNextIndex(const QModelIndex& cur);
00560   virtual QModelIndex walkPrevIndex(const QModelIndex& cur);
00561 
00562   virtual KLFLib::entryId entryIdForIndex(const QModelIndex& index) const;
00563   virtual QModelIndex findEntryId(KLFLib::entryId eid) const;
00564   virtual QList<KLFLib::entryId> entryIdForIndexList(const QModelIndexList& indexlist) const;
00565   virtual QModelIndexList findEntryIdList(const QList<KLFLib::entryId>& eidlist) const;
00566 
00567   virtual int fetchBatchCount() const { return pFetchBatchCount; }
00568 
00569 
00571   virtual void redoSort();
00572 
00574   virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00575 
00577   virtual KLFLibEntrySorter * entrySorter() { return pEntrySorter; }
00578 
00580   virtual void setEntrySorter(KLFLibEntrySorter *entrySorter);
00581 
00582 signals:
00584   void operationStartReportingProgress(KLFProgressReporter *progressReporter, const QString& descriptiveText);
00585 
00586 public slots:
00587 
00588   virtual QModelIndex searchFind(const QString& queryString, const QModelIndex& fromIndex
00589                                  = QModelIndex(), bool forward = true);
00590   virtual QModelIndex searchFindNext(bool forward);
00591   virtual void searchAbort();
00592 
00593   //   virtual bool changeEntries(const QModelIndexList& items, int property, const QVariant& value);
00594   //   virtual bool insertEntries(const KLFLibEntryList& entries);
00595   //   virtual bool deleteEntries(const QModelIndexList& items);
00596 
00597   virtual void completeRefresh();
00598 
00600   virtual void setFetchBatchCount(int count) { pFetchBatchCount = count; }
00601 
00602 private:
00603 
00604   friend class KLFLibModelCache;
00605 
00606   KLFLibResourceEngine *pResource;
00607 
00608   unsigned int pFlavorFlags;
00609 
00610   int pFetchBatchCount;
00611 
00612   KLFLibModelCache *pCache;
00613 
00614   KLFLibEntrySorter *pEntrySorter;
00615 
00616   struct PersistentId {
00617     int kind;
00618     KLFLib::entryId entry_id;
00619     QString categorylabel_fullpath;
00620     int column;
00621   };
00622   friend QDebug& operator<<(QDebug&, const PersistentId&);
00623 
00624   QList<PersistentId> persistentIdList(const QModelIndexList& persistentindexlist);
00625   QModelIndexList newPersistentIndexList(const QList<PersistentId>& persistentidlist);
00626 
00627   void startLayoutChange(bool withQtLayoutChangedSignal = true);
00628   void endLayoutChange(bool withQtLayoutChangedSignal = true);
00629 
00630   QModelIndexList pLytChgIndexes;
00631   QList<PersistentId> pLytChgIds;
00632 
00633   void updateCacheSetupModel();
00634 
00635   QString pSearchString;
00636   QModelIndex pSearchCurNode;
00637   bool pSearchAborted;
00638 
00639   bool dropCanInternal(const QMimeData *data);
00640 
00641   KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE() ;
00642 };
00643 
00644 
00645 
00646 // -----------------
00647 
00648 
00649 class KLF_EXPORT KLFLibViewDelegate : public QAbstractItemDelegate
00650 {
00651   Q_OBJECT
00652 
00653   Q_PROPERTY(QSize previewSize READ previewSize WRITE setPreviewSize) ;
00654 public:
00658   KLFLibViewDelegate(QObject *parent);
00659   virtual ~KLFLibViewDelegate();
00660 
00661   inline QSize previewSize() const { return pPreviewSize; }
00662 
00663   virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option,
00664                                 const QModelIndex& index) const;
00665   virtual bool editorEvent(QEvent *event,QAbstractItemModel *model, const QStyleOptionViewItem& option,
00666                            const QModelIndex& index);
00667   virtual void paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
00668   virtual void setEditorData(QWidget *editor, const QModelIndex& index) const;
00669   virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
00670   virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
00671   virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem& option,
00672                                     const QModelIndex& index) const;
00673 
00674   virtual void setSearchString(const QString& s) { pSearchString = s; }
00675   virtual void setSearchIndex(const QModelIndex& index) { pSearchIndex = index; }
00676   virtual void setSelectionModel(QItemSelectionModel *sm) { pSelModel = sm; }
00682   virtual void setTheTreeView(QTreeView *theTreeView) { pTheTreeView = theTreeView; }
00683   //  virtual void setIndexExpanded(const QModelIndex& index, bool isexpanded) {
00684   //    pExpandedIndexes[QPersistentModelIndex(index)] = isexpanded;
00685   //  }
00686 
00687   virtual bool autoBackgroundItems() const { return pAutoBackgroundItems; }
00688   virtual void setAutoBackgroundItems(bool autoBgItems) { pAutoBackgroundItems = autoBgItems; }
00689   virtual QColor autoBackgroundColor() const { return pAutoBackgroundColor; }
00690   virtual void setAutoBackgroundColor(const QColor& autoBgColor) { pAutoBackgroundColor = autoBgColor; }
00691 
00692 public slots:
00693   void setPreviewSize(const QSize& psize) { pPreviewSize = psize; }
00694 
00695 protected:
00696   struct PaintPrivate {
00697     QPainter *p;
00698     QBrush background;
00699     const QStyleOptionViewItem *option;
00700     bool isselected;
00701     QRect innerRectText;
00702     QRect innerRectImage;
00703   };
00704 
00705   virtual void paintEntry(PaintPrivate *p, const QModelIndex& index) const;
00706   virtual void paintCategoryLabel(PaintPrivate *p, const QModelIndex& index) const;
00707 
00708   enum { PTF_HighlightSearch        = 0x0001,
00709          PTF_HighlightSearchCurrent = 0x0002,
00710          PTF_SelUnderline           = 0x0004,
00711          PTF_ForceRichTextRender    = 0x0008,
00712          PTF_FontLarge              = 0x0010,
00713          PTF_FontTT                 = 0x0020
00714   };
00715   virtual void paintText(PaintPrivate *p, const QString& text, uint flags = PTF_HighlightSearch) const;
00716 
00717   virtual bool indexHasSelectedDescendant(const QModelIndex& parent) const;
00718   virtual bool selectionIntersectsIndexChildren(const QItemSelection& selection,
00719                                                 const QModelIndex& parent) const;
00721   virtual bool func_indexHasSelectedDescendant(const QModelIndex& parent, const QTime& timer,
00722                                                int timeLimitMs) const;
00723 
00724 private:
00725   QString pSearchString;
00726   QModelIndex pSearchIndex;
00727   QItemSelectionModel *pSelModel;
00728   QTreeView *pTheTreeView; 
00729 
00730   QSize pPreviewSize;
00731 
00732   bool pAutoBackgroundItems;
00733   QColor pAutoBackgroundColor;
00734 
00735   //  QMap<QPersistentModelIndex, bool> pExpandedIndexes;
00736 
00737   struct ColorRegion {
00738     ColorRegion(QTextCharFormat f = QTextCharFormat(), int s = -1, int l = 0)
00739       : fmt(f), start(s), len(l) { }
00740     QTextCharFormat fmt; int start; int len;
00741     bool operator<(const ColorRegion& other) const {
00742       return start < other.start;
00743     }
00744   };
00745   friend QDebug& operator<<(QDebug&, const ColorRegion&);
00746 };
00747 
00748 // -----------------
00749 
00753 class KLF_EXPORT KLFLibDefaultView : public KLFAbstractLibView, public KLFSearchable
00754 {
00755   Q_OBJECT
00756   Q_PROPERTY(bool autoBackgroundItems READ autoBackgroundItems WRITE setAutoBackgroundItems) ;
00757   Q_PROPERTY(QColor autoBackgroundColor READ autoBackgroundColor WRITE setAutoBackgroundColor) ;
00758 
00759   Q_PROPERTY(QListView::Flow iconViewFlow READ iconViewFlow WRITE setIconViewFlow) ;
00760 
00761   Q_PROPERTY(QSize previewSize READ previewSize WRITE setPreviewSize) ;
00762 
00763 public:
00764   enum ViewType { CategoryTreeView, ListTreeView, IconView };
00765   KLFLibDefaultView(QWidget *parent, ViewType viewtype = CategoryTreeView);
00766   virtual ~KLFLibDefaultView();
00767 
00768   virtual QUrl url() const;
00769   virtual uint compareUrlTo(const QUrl& other, uint interestFlags = 0xFFFFFFFF) const;
00770 
00771   inline QSize previewSize() const { return pDelegate->previewSize(); }
00772 
00773   bool groupSubCategories() const { return pGroupSubCategories; }
00774 
00775   virtual bool event(QEvent *e);
00776   virtual bool eventFilter(QObject *o, QEvent *e);
00777 
00778   virtual KLFLibEntryList selectedEntries() const;
00779   virtual QList<KLFLib::entryId> selectedEntryIds() const;
00780 
00781   ViewType viewType() const { return pViewType; }
00782 
00783   virtual QList<QAction*> addContextMenuActions(const QPoint& pos);
00784 
00785   virtual QVariantMap saveGuiState() const;
00786   virtual bool restoreGuiState(const QVariantMap& state);
00787 
00789   virtual QModelIndex currentVisibleIndex() const;
00790 
00791   bool autoBackgroundItems() const { return pDelegate->autoBackgroundItems(); }
00792   QColor autoBackgroundColor() const { return pDelegate->autoBackgroundColor(); }
00793 
00794   QListView::Flow iconViewFlow() const;
00795 
00796   virtual QStringList getCategorySuggestions();
00797 
00798   virtual KLFSearchable * searchable() { return this; }
00799 
00800 public slots:
00801   //   virtual bool writeEntryProperty(int property, const QVariant& value);
00802   //   virtual bool deleteSelected(bool requireConfirmation = true);
00803   //   virtual bool insertEntries(const KLFLibEntryList& entries);
00804   virtual bool selectEntries(const QList<KLFLib::entryId>& idList);
00805 
00806   virtual bool searchFind(const QString& queryString, bool forward = true);
00807   virtual bool searchFindNext(bool forward);
00808   virtual void searchAbort();
00809 
00810   virtual void restore(uint restoreflags = KLFLib::RestoreLatexAndStyle);
00811 
00812   virtual void showColumns(int propIdColumn, bool show);
00813   virtual void sortBy(int propIdColumn, Qt::SortOrder sortorder);
00814 
00818   virtual void slotSelectAll(bool expandItems = false);
00819   virtual void slotRefresh();
00820   virtual void slotRelayoutIcons();
00821 
00822   void setPreviewSize(const QSize& size) { pDelegate->setPreviewSize(size); }
00823 
00824   void setAutoBackgroundItems(bool on) { pDelegate->setAutoBackgroundItems(on); }
00825   void setAutoBackgroundColor(const QColor& c) { pDelegate->setAutoBackgroundColor(c); }
00826 
00830   void setIconViewFlow(QListView::Flow flow);
00831 
00834   void setGroupSubCategories(bool yesOrNo) { pGroupSubCategories = yesOrNo; }
00835 
00836   void updateDisplay();
00837 
00838 protected:
00839   virtual void updateResourceEngine();
00840   virtual void updateResourceProp(int propId);
00841   virtual void updateResourceData(const QString& subRes, int modifyType,
00842                                   const QList<KLFLib::entryId>& entryIdList);
00843   virtual void updateResourceOwnData(const QList<KLFLib::entryId>& entryIdList);
00844 
00845   virtual void showEvent(QShowEvent *event);
00846 
00847   enum SelectAllFlags { ExpandItems = 0x01, NoSignals = 0x02 } ;
00848 
00849 protected slots:
00850   void slotViewSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
00851 
00859   virtual void slotSelectAll(const QModelIndex& parent, uint selectFlags);
00860   
00861   void slotViewItemClicked(const QModelIndex& index);
00862   void slotEntryDoubleClicked(const QModelIndex& index);
00863 
00864   void slotShowColumnSenderAction(bool showCol);
00865 
00866   // called from model
00867   void slotResourceDataChanged(const QModelIndex& topLeft, const QModelIndex& botRight);
00868 
00869   void slotPreviewSizeFromActionSender();
00870   void slotPreviewSizeActionsRefreshChecked();
00871 
00872 private:
00873   ViewType pViewType;
00874   QAbstractItemView *pView;
00875   KLFLibViewDelegate *pDelegate;
00876   KLFLibModel *pModel;
00877 
00878   bool pGroupSubCategories;
00879 
00880   QList<QAction*> pCommonActions;
00881   QList<QAction*> pShowColumnActions;
00882   QMenu *pPreviewSizeMenu;
00883   QList<QAction*> pIconViewActions;
00884 
00885   QList<QAction*> pViewActionsWithShortcut;
00886 
00887   bool pEventFilterNoRecurse;
00888 
00889   QModelIndexList selectedEntryIndexes() const;
00890 
00891   bool func_selectAll(const QModelIndex& parent, uint flags, QTime *tm, KLFDelayedPleaseWaitPopup *pleaseWait);
00892 
00893 private slots:
00894   void searchFound(const QModelIndex& i);
00895 
00896 protected:
00897   KLF_DEBUG_DECLARE_REF_INSTANCE( QFileInfo(url().path()).fileName()+":"
00898                                   +(resourceEngine()?resourceEngine()->defaultSubResource():"[NULL]")
00899                                   +"|viewtype="+QString::number(pViewType)  ) ;
00900 };
00901 
00902 // -----------------
00903 
00904 class KLF_EXPORT KLFLibDefaultViewFactory : public KLFLibViewFactory
00905 {
00906   Q_OBJECT
00907 public:
00908   KLFLibDefaultViewFactory(QObject *parent = NULL);
00909   virtual ~KLFLibDefaultViewFactory() { }
00910 
00911   virtual QString viewTypeTitle(const QString& viewTypeIdent) const;
00912 
00913   virtual bool canCreateLibView(const QString& /*viewTypeIdent*/,
00914                                 KLFLibResourceEngine */*engine*/) { return true; }
00915 
00916   virtual KLFAbstractLibView * createLibView(const QString& viewTypeIdent, QWidget *parent,
00917                                              KLFLibResourceEngine *resourceEngine);
00918 };
00919 
00920 
00921 
00922 // -----------------
00923 
00924 namespace Ui {
00925   class KLFLibOpenResourceDlg;
00926   class KLFLibCreateResourceDlg;
00927   class KLFLibResPropEditor;
00928   class KLFLibNewSubResDlg;
00929 };
00930 
00932 class KLF_EXPORT KLFLibOpenResourceDlg : public QDialog
00933 {
00934   Q_OBJECT
00935 public:
00936   KLFLibOpenResourceDlg(const QUrl& defaultlocation = QUrl(), QWidget *parent = 0);
00937   virtual ~KLFLibOpenResourceDlg();
00938 
00939   virtual QUrl url() const;
00940 
00941   static QUrl queryOpenResource(const QUrl& defaultlocation = QUrl(), QWidget *parent = 0);
00942 
00943 protected slots:
00944 
00945   virtual void updateReadyToOpenFromSender(bool isready);
00946   virtual void updateReadyToOpen();
00947 
00948 protected:
00949   virtual QUrl retrieveRawUrl() const;
00950 
00951 private:
00952   Ui::KLFLibOpenResourceDlg *pUi;
00953   QAbstractButton *btnGo;
00954 };
00955 
00956 // --
00957 
00958 
00959 class KLF_EXPORT KLFLibCreateResourceDlg : public QDialog
00960 {
00961   Q_OBJECT
00962 public:
00963   typedef KLFLibEngineFactory::Parameters Parameters;
00964 
00965   KLFLibCreateResourceDlg(const QString& defaultWtype, QWidget *parent = 0);
00966   virtual ~KLFLibCreateResourceDlg();
00967 
00968   virtual Parameters getCreateParameters() const;
00969 
00970   static KLFLibResourceEngine *createResource(const QString& defaultWtype, QObject *resourceParent,
00971                                               QWidget *parent = 0);
00972 
00973 public slots:
00974 
00975   virtual void accept();
00976   virtual void reject();
00977 
00978 protected slots:
00979 
00980   virtual void updateReadyToCreateFromSender(bool isready);
00981   virtual void updateReadyToCreate();
00982 
00983 private:
00984   Ui::KLFLibOpenResourceDlg *pUi;
00985   QAbstractButton *btnGo;
00986 
00987   Parameters pParam;
00988 };
00989 
00990 
00991 // --
00992 
00993 class KLF_EXPORT KLFLibResPropEditor : public QWidget
00994 {
00995   Q_OBJECT
00996 public:
00997   KLFLibResPropEditor(KLFLibResourceEngine *resource, QWidget *parent = 0);
00998   virtual ~KLFLibResPropEditor();
00999 
01000 public slots:
01001   bool apply();
01002 
01003 protected slots:
01004   void slotResourcePropertyChanged(int propId);
01005   void slotSubResourcePropertyChanged(const QString& subResource, int propId);
01006   void on_btnAdvanced_toggled(bool on);
01007   void advPropEdited(QStandardItem *item);
01008   void advSubResPropEdited(QStandardItem *item);
01009   void on_cbxSubResource_currentIndexChanged(int newSubResItemIndex);
01010 
01011   void updateResourceProperties();
01012   void updateSubResourceProperties();
01013   void updateSubResources(const QString& curSubResource = QString());
01014 
01015 private:
01016   KLFLibResourceEngine *pResource;
01017   bool pSuppSubRes;
01018   bool pSuppSubResProps;
01019   Ui::KLFLibResPropEditor *U;
01020   QStandardItemModel *pPropModel;
01021   QStandardItemModel *pSubResPropModel;
01022 
01023   QString curSubResource() const;
01024 };
01025 
01026 class KLF_EXPORT KLFLibResPropEditorDlg : public QDialog
01027 {
01028   Q_OBJECT
01029 public:
01030   KLFLibResPropEditorDlg(KLFLibResourceEngine *resource, QWidget *parent = 0);
01031   virtual ~KLFLibResPropEditorDlg();
01032 
01033 public slots:
01034   void applyAndClose();
01035   void cancelAndClose();
01036 
01037 private:
01038   KLFLibResPropEditor *pEditor;
01039 };
01040 
01041 
01042 
01043 
01044 class KLF_EXPORT KLFLibNewSubResDlg : public QDialog
01045 {
01046   Q_OBJECT
01047 public:
01048   KLFLibNewSubResDlg(KLFLibResourceEngine *resource, QWidget *parent = 0);
01049   virtual ~KLFLibNewSubResDlg();
01050 
01051   QString newSubResourceName() const;
01052   QString newSubResourceTitle() const;
01053 
01059   static QString createSubResourceIn(KLFLibResourceEngine *resource, QWidget *parent = 0);
01060 
01065   static QString makeSubResInternalName(const QString& title);
01066 
01067 private slots:
01068   void on_txtTitle_textChanged(const QString& text);
01069   void on_txtName_textChanged(const QString& text);
01070 
01071 private:
01072   Ui::KLFLibNewSubResDlg *u;
01073 
01074   bool isAutoName;
01075 };
01076 
01077 
01078 
01079 
01080 
01092 class KLF_EXPORT KLFLibLocalFileSchemeGuesser
01093 {
01094 public:
01095   KLFLibLocalFileSchemeGuesser();
01096   virtual ~KLFLibLocalFileSchemeGuesser();
01097 
01099 
01114   virtual QString guessScheme(const QString& fileName) const = 0;
01115 };
01116 
01117 
01118 
01120 
01132 class KLF_EXPORT KLFLibBasicWidgetFactory : public KLFLibWidgetFactory
01133 {
01134   Q_OBJECT
01135 public:
01137   struct LocalFileType {
01138     QString scheme; 
01139     QString filepattern; 
01140     QString filter; 
01141   };
01142 
01143   KLFLibBasicWidgetFactory(QObject *parent = NULL);
01144   virtual ~KLFLibBasicWidgetFactory();
01145 
01146   virtual QStringList supportedTypes() const;
01147 
01148   virtual QString widgetTypeTitle(const QString& wtype) const;
01149 
01150   virtual QWidget * createPromptUrlWidget(QWidget *parent, const QString& scheme,
01151                                           QUrl defaultlocation = QUrl());
01152   virtual QUrl retrieveUrlFromWidget(const QString& scheme, QWidget *widget);
01153 
01154   virtual bool hasCreateWidget(const QString& /*wtype*/) const { return true; }
01155 
01161   virtual QWidget * createPromptCreateParametersWidget(QWidget *parent, const QString& scheme,
01162                                                        const Parameters& defaultparameters = Parameters());
01163 
01171   virtual Parameters retrieveCreateParametersFromWidget(const QString& wtype, QWidget *widget);
01172 
01173 
01178   static void addLocalFileType(const LocalFileType& fileType);
01179   static QList<LocalFileType> localFileTypes();
01180 
01185   static QString guessLocalFileScheme(const QString& fileName);
01186 
01187 protected:
01188   static QList<LocalFileType> pLocalFileTypes;
01189   static QList<KLFLibLocalFileSchemeGuesser*> pSchemeGuessers;
01190 
01191   friend class KLFLibLocalFileSchemeGuesser;
01192 
01197   static void addLocalFileSchemeGuesser(KLFLibLocalFileSchemeGuesser *schemeguesser);
01198 
01199   static void removeLocalFileSchemeGuesser(KLFLibLocalFileSchemeGuesser *schemeguesser);
01200 
01201 };
01202 
01203 
01204 
01205 
01206 
01207 #endif

Generated by doxygen 1.7.3