30 #ifndef KLFLIBVIEW_P_H
31 #define KLFLIBVIEW_P_H
35 #include <QApplication>
36 #include <QStringList>
37 #include <QAbstractItemView>
42 #include <QDragEnterEvent>
43 #include <QDragMoveEvent>
47 #include <QFileDialog>
49 #include <QDesktopServices>
53 #include <ui_klfliblocalfilewidget.h>
101 return kind == other.
kind && index == other.
index;
114 return NodeId((
ItemKind)((uid&UIDKindMask)>>UIDKindShift), uid&UIDIndexMask);
168 if (pContainsNonAllocated) {
170 for (insertPos = 0; insertPos < QList<N>::size() &&
QList<N>::at(insertPos).allocated; ++insertPos)
174 pContainsNonAllocated =
false;
186 node.allocated =
false;
187 pContainsNonAllocated =
true;
202 bool pContainsNonAllocated;
215 pIsFetchingMore =
false;
218 pLastSortOrder = Qt::DescendingOrder;
259 void fetchMore(NodeId parentId,
int batchCount = -1);
274 void treeInsertEntry(
const EntryNode& e,
bool isRebuildingCache =
false);
280 EntryNode
treeTakeEntry(
const NodeId& e,
bool notifyQtApi =
true);
290 bool notifyQtApi =
false,
bool newlyCreatedAreChildrenFetched =
true);
296 : cache(c), entrysorter(es), groupCategories(groupcategories)
307 bool groupCategories;
320 pLastSortPropId = propId;
321 pLastSortOrder = order;
325 void sortCategory(NodeId category, KLFLibModelSorter *sorter,
bool rootCall =
true);
365 EntryCache pEntryCache;
366 CategoryLabelCache pCategoryLabelCache;
372 void insertCategoryStringInSuggestionCache(
const QString& category)
374 insertCategoryStringInSuggestionCache(category.
split(
'/', QString::SkipEmptyParts));
378 void insertCategoryStringInSuggestionCache(
const QStringList& catelements)
381 for (
int kl = catelements.size()-1; kl >= 0; --kl) {
385 pCatListCache.insert(qLowerBound(pCatListCache.begin(), pCatListCache.end(), c), c);
389 bool pIsFetchingMore;
392 Qt::SortOrder pLastSortOrder;
394 KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE() ;
422 klfDbg(
"KLFLibDefViewCommon::evDragEnter: drop flags are "<<fl<<
"; this viewtype="<<
pViewType ) ;
425 thisView()->setDropIndicatorShown(showdropindic);
431 qDebug(
"Ignored drag enter event.");
435 klfDbg(
"Accepted drag enter event issued at pos="<<pos ) ;
437 QDragEnterEvent fakeevent(de->pos(), de->dropAction(), de->mimeData(), de->mouseButtons(),
438 de->keyboardModifiers());
439 qApp->sendEvent(
thisView()->viewport(), &fakeevent);
447 klfDbg(
"KLFLibDefViewCommon::evDragMove: flags are "<<fl<<
"; pos is "<<pos ) ;
456 de->setDropAction(Qt::MoveAction);
458 de->setDropAction(Qt::CopyAction);
462 QDragMoveEvent fakeevent(de->pos(), de->dropAction(), de->mimeData(), de->mouseButtons(),
463 de->keyboardModifiers());
464 qApp->sendEvent(
thisView()->viewport(), &fakeevent);
477 klfDbg(
"Delta is "<<delta ) ;
480 qApp->sendEvent(
thisView()->viewport(), &fakeevent);
486 klfDbg(
"Drop event at position="<<de->
pos() ) ;
488 de->keyboardModifiers());
489 qApp->sendEvent(
thisView()->viewport(), &fakeevent);
505 klfDbg(
"Normal DRAG..." ) ;
514 if (indexes.count() == 0)
524 Qt::DropAction defaultDropAction = Qt::IgnoreAction;
526 if (supportedActions & Qt::CopyAction &&
527 thisView()->dragDropMode() != QAbstractItemView::InternalMove)
528 defaultDropAction = Qt::CopyAction;
530 drag->exec(supportedActions, defaultDropAction);
535 Q_UNUSED(firstOrLast)
541 klfDbg(
"\texploring item it="<<it<<
"; bottom="<<
thisConstView()->visualRect(it).bottom() ) ;
595 if (
object ==
thisView()->viewport())
596 return event->pos() +
QPoint(horoffset, veroffset);
598 return thisView()->viewport()->mapFromGlobal(
thisView()->mapToGlobal(event->pos()))
599 +
QPoint(horoffset, veroffset);
600 return event->pos() +
QPoint(horoffset, veroffset);
606 qWarning()<<
"KLFLibDefViewCommon::setTheModel: model is NULL or not a KLFLibModel :"<<model<<
" !";
638 installEventFilter(
this);
639 viewport()->installEventFilter(
this);
644 return QTreeView::eventFilter(
object, event);
647 if (event->
type() == QEvent::DragEnter) {
649 }
else if (event->
type() == QEvent::DragMove) {
651 }
else if (event->
type() == QEvent::Drop) {
659 return QTreeView::eventFilter(
object, event);
663 QTreeView::setModel(model);
677 for (k = 0; k < mil.size(); ++k) {
681 while (idx.
parent().isValid()) {
707 QTreeView::paintEvent(event);
729 installEventFilter(
this);
730 viewport()->installEventFilter(
this);
738 if (event->
type() == QEvent::DragEnter) {
740 }
else if (event->
type() == QEvent::DragMove) {
742 }
else if (event->
type() == QEvent::Drop) {
750 return QListView::eventFilter(
object, event);
754 QListView::setModel(model);
760 scheduleDelayedItemsLayout();
764 klfDbg(
"scheduling an items layout...");
766 scheduleDelayedItemsLayout();
786 QListView::paintEvent(event);
792 virtual void startDrag(Qt::DropActions supportedActions) {
797 if (!event->spontaneous()) {
798 klfDbg(
"Show event! initialLayoutDone="<<pInitialLayoutDone<<
"; size hint="<<sizeHint());
799 if (!pInitialLayoutDone) {
800 scheduleDelayedItemsLayout();
801 pInitialLayoutDone =
true;
804 QListView::showEvent(event);
850 QDir::AllEntries|QDir::AllDirs|QDir::NoDotAndDotDot,
851 QDir::DirsFirst|QDir::IgnoreCase,
this);
854 fileNameCompleter->
setModel(dirModel);
855 txtFile->setCompleter(fileNameCompleter);
909 void readyToOpen(
bool ready);
917 emit readyToOpen(ready);
929 QString t = text.isNull() ? txtFile->text() : text;
939 QString path = txtFile->text();
946 pathfilter = pathft.
filter;
952 int pathfilterN = -1;
953 for (k = 0; k < pFileTypes.
size(); ++k) {
954 filters << pFileTypes[k].filter;
955 fpatterns << pFileTypes[k].filepattern;
956 if (pFileTypes[k].filter == pathfilter)
964 if (pathfilterN >= 0)
965 filters.removeAt(pathfilterN);
966 filters.prepend(tr(
"All Known Files (%1)").arg(fpatterns.
join(
" ")));
967 if (pathfilterN >= 0)
968 filters.prepend(pathfilter);
970 if (pathfilterN >= 0) {
971 filters.removeAt(pathfilterN);
972 filters.prepend(pathfilter);
975 filters.append(tr(
"All Files (*)"));
977 QString title = tr(
"Select Library Resource File");
984 qWarning()<<
"KLFLibLocalFileOpenWidget::browseFileName: bad bt="<<bt;
992 txtFile->setText(name);
1024 return txtFile->text();
1032 void readyToCreate(
bool ready);
QDataStream & operator<<(QDataStream &stream, const KLFLatexSymbol &s)
bool searchNodeMatches(const NodeId &nodeId, const QString &searchString, Qt::CaseSensitivity cs)
virtual QPoint scrollOffset() const
virtual bool eventFilter(QObject *object, QEvent *event)
KLFLibModelSorter(KLFLibModelCache *c, KLFLibEntrySorter *es, bool groupcategories)
setHotSpot(const QPoint &hotspot)
N takeNode(const NodeId &nid)
toNativeSeparators(const QString &pathName)
virtual QModelIndexList commonSelectedIndexes() const
Model for Item-Views displaying a library resource's contents.
ignore(const QRect &rectangle)
virtual QAbstractItemView * thisView()
virtual QImage dragImage(const QModelIndexList &indexes)
bool allChildrenFetched
TRUE if all the children of this node have been fetched and stored into children, FALSE if possibly t...
fromNativeSeparators(const QString &pathName)
QList< KLFLib::entryId > entryIdList(const QModelIndexList &indexlist)
A cached value of the size of value in Preview.
setMimeData(QMimeData *data)
qint32 entryId
An entry ID.
split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive)
void dumpNodeTree(NodeId node, int indent=0)
QPoint scrollOffset() const
QString fullCategoryPath
The full category path of this category eg. "Physics/General Relativity".
virtual void setModel(QAbstractItemModel *model)
static const UIDType UIDIndexMask
setPixmap(const QPixmap &pixmap)
QString categoryLabel
The last element in fullCategoryPath eg. "General Relativity".
void ensureNotMinimalist(NodeId nodeId, int count=-1)
QAbstractItemView * thisView()
virtual uint dropFlags(QDragMoveEvent *event, QAbstractItemView *view)
IndexType cacheFindCategoryLabel(QStringList catelements, bool createIfNotExists=false, bool notifyQtApi=false, bool newlyCreatedAreChildrenFetched=true)
setModel(QAbstractItemModel *model)
const QAbstractItemView * thisConstView() const
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
void ensureExpandedTo(const QModelIndexList &mil)
#define klfDbg(streamableItems)
fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
int getNodeRow(NodeId nodeid)
CategoryLabelNode & getCategoryLabelNodeRef(NodeId nodeid)
join(const QString &separator)
QList< KLFLib::entryId > entryIdForIndexList(const QModelIndexList &indexlist)
virtual void commonInternalDrag(Qt::DropActions a)=0
bool canFetchMore(NodeId parentId)
virtual void modelInitialized()
bool operator==(const NodeId &other) const
virtual void commonStartDrag(Qt::DropActions supportedActions)
The Latex Code of the equation.
static QList< int > minimalistEntryPropIds()
void fetchMore(NodeId parentId, int batchCount=-1)
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
QString nodeValue(NodeId node, int propId=KLFLibEntry::Latex)
EntryNode(const EntryNode ©)
virtual bool setTheModel(QAbstractItemModel *m)
void sortCategory(NodeId category, KLFLibModelSorter *sorter, bool rootCall=true)
QPoint mousePressedContentsPos
NodeId(ItemKind k=ItemKind(EntryKind), IndexType i=-1)
void unlinkNode(const NodeId &nid)
QModelIndex createIndexFromId(NodeId nodeid, int row, int column)
update(const QModelIndex &index)
accept(const QRect &rectangle)
void startDrag(Qt::DropActions supportedActions)
NodeId nextNode(NodeId n)
NodeId prevNode(NodeId n)
EntryNode & getEntryNodeRef(NodeId nodeid, bool requireNotMinimalist=false)
void setSortingBy(int propId, Qt::SortOrder order)
EntryNode pInvalidEntryNode
virtual void paintEvent(QPaintEvent *event)
rowsInserted(const QModelIndex &parent, int start, int end)
KLFLibModelCache(KLFLibModel *model)
virtual QPoint eventPos(QObject *object, QDragEnterEvent *event)
QModelIndex curVisibleIndex(bool firstOrLast) const
NodeId getNodeForIndex(const QModelIndex &index)
virtual bool evDragEnter(QDragEnterEvent *de, const QPoint &pos)
setScheme(const QString &scheme)
virtual void showEvent(QShowEvent *event)
bool isAllocated(IndexType i)
void treeInsertEntry(const EntryNode &e, bool isRebuildingCache=false)
KLFLibDefaultView * pDView
static const quint8 UIDKindShift
bool allocated
Whether this node is used. when false, this Node object is just unused memory space in the cache list...
virtual const QAbstractItemView * thisConstView() const
The Category to which eq. belongs (path-style string)
virtual bool evDragMove(QDragMoveEvent *de, const QPoint &pos)
UIDType universalId() const
#define KLF_DEBUG_TIME_BLOCK(msg)
QModelIndexList commonSelectedIndexes() const
virtual QModelIndexList commonSelectedIndexes() const =0
Tags about the equation (string)
virtual QPoint eventPos(QObject *object, QDragEnterEvent *event, int horoffset, int veroffset)
virtual ~KLFLibModelCache()
bool entryIsValid() const
QPointF sizeToPointF(const QSizeF &s)
virtual const QAbstractItemView * thisConstView() const =0
virtual void setModel(QAbstractItemModel *model)
virtual void commonInternalDrag(Qt::DropActions a)
void commonInternalDrag(Qt::DropActions)
bool operator!=(const NodeId &other) const
QModelIndexList findEntryIdList(const QList< KLFLib::entryId > &eidlist)
KLFLibDefViewCommon(KLFLibDefaultView *dview)
NodeId lastNode(NodeId n)
QString lastFileDialogPath
KLFLibDefListView(KLFLibDefaultView *parent)
QStringList categoryListCache()
An entry (single formula) in the library.
Node & getNodeRef(NodeId nodeid)
void unlinkNode(IndexType index)
KLFLibDefTreeView(KLFLibDefaultView *parent)
virtual void modelInitialized()
getSaveFileName(QWidget *parent=0, const QString &caption=QString()
virtual QAbstractItemView * thisView()=0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
static const UIDType UIDInvalid
virtual QPoint scrollOffset() const =0
Node getNode(NodeId nodeid)
virtual bool evDrop(QDropEvent *de, const QPoint &pos)
CategoryLabelNode(const CategoryLabelNode ©)
KLFLibEntrySorter * entrySorter()
QSizeF pointToSizeF(const QPointF &p)
static const UIDType UIDKindMask
Utility class for sorting library entry items.
QPoint eventPos(QObject *object, QDragEnterEvent *event)
getOpenFileName(QWidget *parent=0, const QString &caption=QString()
virtual ~KLFLibDefViewCommon()
expand(const QModelIndex &index)
virtual bool eventFilter(QObject *object, QEvent *event)
virtual void slotSelectAll(bool expandItems=false)
virtual QModelIndex walkNextIndex(const QModelIndex &cur)
Call repeatedly to walk all indexes (once each exactly, first column only)
NodeCache< EntryNode > EntryCache
The Date/Time at which the equation was evaluated.
struct KLFConfig::@4 LibraryBrowser
static NodeId fromUID(UIDType uid)
virtual void paintEvent(QPaintEvent *event)
void updateData(const QList< KLFLib::entryId > &entryIdList, int modifyType)
exactMatch(const QString &str)
IndexType insertNewNode(const N &n)
virtual void startDrag(Qt::DropActions supportedActions)
EntryNode treeTakeEntry(const NodeId &e, bool notifyQtApi=true)
NodeId findEntryId(KLFLib::entryId eId)
KLFLibDefaultView::ViewType pViewType
fromLocalFile(const QString &localFile)
N takeNode(IndexType index)
NodeCache< CategoryLabelNode > CategoryLabelCache