You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Include/iBase/iProperty/ZxPtyPano.h

212 lines
4.5 KiB
C

#pragma once
#include <QPixmap>
#include <QVector>
#include <QString>
#include <QHash>
#include <QVector>
#include <QSet>
#include <QAbstractScrollArea>
#include "ZxDynamic.h"
#include "ZxPtyItem.h"
#include "iProperty_global.h"
class ZxPtyFileManager;
class ZxPtyAttributeFile;
class ZxXpfNode;
// 绘图属性载体
class I_PROPERTY_EXPORT ZxPtyPano
: public QAbstractScrollArea
, virtual public IxPtyPano
, virtual public IxDynObj
{
Q_OBJECT
ZX_DECLARE_DYNAMIC
public:
explicit ZxPtyPano();
~ZxPtyPano();
// 入口
virtual void beginSession(const QString& configName, IxInterface* pSessionOwner);
virtual void endSession();
// 具体对象
virtual void beginObject(IxPtySource* p);
virtual void endObject();
// 组及项添加
virtual IxPtyItem* addGroup(const QString& key, bool expand = true, bool visible = true);
virtual IxPtyItem* add(ZX_PROPERTY_CHANGED_CALLBACK callback, \
const QString& key, \
const QVariant& var);
// 检索
virtual IxPtyItem* findPropertyItem(const QString& sKey);
// 清空
virtual void clear(IxInterface* pSessionOwner);
// 获取当前配置文件. 这个文件是根据上层应用模块设置的配置名来加载的, 每次填表都会更新.
ZxPtyAttributeFile* getAttributeFile();
// 对象体
IxPtySource* getCurObject() { return m_pObject; }
signals:
// 显示某项的tips
void sigShowItemTips(const QString& help);
protected slots:
void slotConfigReloaded();
public:
virtual void paintEvent(QPaintEvent *);
virtual void mousePressEvent(QMouseEvent *);
virtual void mouseDoubleClickEvent(QMouseEvent* e);
virtual void mouseReleaseEvent(QMouseEvent *);
virtual void mouseMoveEvent(QMouseEvent *);
virtual void resizeEvent(QResizeEvent *);
private:
void paintGrid(QPainter& painter);
void paintHeader(QPainter& painter);
void paintGroups(QPainter& painter);
void paintItems(QPainter& painter);
void onActiveItemChanged(ZxPtyItem* item);
enum HitTestPart
{
htNone,
htExpander,
htLeftCol,
htRightCol,
htSplit
};
class HitTestResult
{
public:
int row;
HitTestPart part;
bool isValid() const;
int col();
};
private:
// 创建
ZxPtyItem* getOrCreate(const QString& key, \
const QVariant& initVar, \
bool* bJustCreated);
IxPtyItemEditor* createEditor(const QString& name);
void releaseEditor(IxPtyItemEditor* p);
// 配置关联
ZxXpfNode* getItemConfig(const QString& key);
int getAndIncObjectSn();
// 布局相关
void updateLayout();
void doLayout();
void saveXSplit();
void loadXSplit();
void normalizeXSplit();
QRect getLeftRect(int nVirtualRow);
QRect getRightRect(int nVirtualRow);
int indentWidth() const;
int right() const;
int getVerticalScrollPos() const;
void scrollContentsBy(int dx, int dy);
// 鼠标交互
HitTestResult hitTest(int x, int y);
// 项展开
void expand(ZxPtyItem* p);
void collapse(ZxPtyItem* p);
// 项激活
void activateItem(ZxPtyItem* p);
void updateItem(ZxPtyItem* item); // 刷新重绘
void clearItems();
private:
// 关联对象及载体
QHash<QString, ZxPtyItem*> m_hashPtyItems;
ZxPtyFileManager* m_pConfigManager;
mutable ZxPtyAttributeFile* m_pAttribueFile;
mutable QString m_sConfig;
IxPtySource* m_pObject;
IxPtyItem* m_pCurrentItem;
int m_nObjectCount;
int m_nSessionId;
IxInterface* m_pSessionOwner;
QHash<QString, int> m_hashObjSns;
bool m_bInitializingSession;
// 布局及鼠标交互相关
bool m_bHitSplit;
int m_xSplit;
bool m_bNeedLayout;
QVector<ZxPtyItem*> m_vecRealRows;
QVector<ZxPtyItem*> m_vecVirtualRows;
// 项展开折叠图标
QPixmap m_pixExpand;
QPixmap m_pixCollapse;
// 颜色
QColor m_vecBackColors[3];
QColor m_clrFrameBack;
// 其它
double m_dNextItemOrder;
bool m_bClearEntered;
QList<ZxPtyItem*> m_listItemsToBeDeleted;
// 控件池
typedef QVector<IxPtyItemEditor*> ItemEditorVector;
QHash<QString, ItemEditorVector> m_hashEditorPools;
// 内部布局涉及的遍历
int m_nRowHeight;
int m_nIndentWidth;
int m_nIconWidth;
int m_nIconMarginH;
int m_nIconMarginV;
int m_nPaddingLeft;
int m_nPaddingRight;
int m_nPaddingBottom;
int m_nCellPaddingV;
int m_nCellPaddingH;
int m_nCellSpacing;
friend class ZxPtyFileManager;
friend class ZxPtyItem;
};