mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#ifndef VOUTLINE_H
|
|
#define VOUTLINE_H
|
|
|
|
#include <QTreeWidget>
|
|
#include <QVector>
|
|
#include <QMap>
|
|
#include <QChar>
|
|
#include "vtoc.h"
|
|
#include "vnavigationmode.h"
|
|
|
|
class QLabel;
|
|
|
|
class VOutline : public QTreeWidget, public VNavigationMode
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
VOutline(QWidget *parent = 0);
|
|
|
|
// Implementations for VNavigationMode.
|
|
void registerNavigation(QChar p_majorKey) Q_DECL_OVERRIDE;
|
|
void showNavigation() Q_DECL_OVERRIDE;
|
|
void hideNavigation() Q_DECL_OVERRIDE;
|
|
bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE;
|
|
|
|
signals:
|
|
void outlineItemActivated(const VAnchor &anchor);
|
|
|
|
public slots:
|
|
void updateOutline(const VToc &toc);
|
|
void updateCurHeader(const VAnchor &anchor);
|
|
|
|
protected:
|
|
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
|
|
|
private slots:
|
|
void handleCurItemChanged(QTreeWidgetItem *p_curItem, QTreeWidgetItem *p_preItem);
|
|
|
|
private:
|
|
// Update tree according to outline.
|
|
void updateTreeFromOutline();
|
|
|
|
// @index: the index in @headers.
|
|
void updateTreeByLevel(const QVector<VHeader> &headers, int &index, QTreeWidgetItem *parent,
|
|
QTreeWidgetItem *last, int level);
|
|
|
|
void expandTree();
|
|
void selectAnchor(const QString &anchor);
|
|
bool selectAnchorOne(QTreeWidgetItem *item, const QString &anchor);
|
|
void selectLineNumber(int lineNumber);
|
|
bool selectLineNumberOne(QTreeWidgetItem *item, int lineNumber);
|
|
QList<QTreeWidgetItem *> getVisibleItems() const;
|
|
QList<QTreeWidgetItem *> getVisibleChildItems(const QTreeWidgetItem *p_item) const;
|
|
|
|
// Fill the info of @p_item.
|
|
void fillItem(QTreeWidgetItem *p_item, const VHeader &p_header);
|
|
|
|
// Check if @p_toc is valid.
|
|
void checkOutline(const VToc &p_toc) const;
|
|
|
|
// Return NULL if no corresponding header in outline.
|
|
const VHeader *getHeaderFromItem(QTreeWidgetItem *p_item) const;
|
|
|
|
VToc outline;
|
|
VAnchor curHeader;
|
|
|
|
// Navigation Mode.
|
|
// Map second key to QTreeWidgetItem.
|
|
QMap<QChar, QTreeWidgetItem *> m_keyMap;
|
|
QVector<QLabel *> m_naviLabels;
|
|
};
|
|
|
|
#endif // VOUTLINE_H
|