|
|
/******************************************************************************
|
|
|
Copyright(C):2015~2018 hzleaper
|
|
|
FileName:$FILE_BASE$.$FILE_EXT$
|
|
|
Author:zhikun wu
|
|
|
Email:zk.wu@hzleaper.com
|
|
|
Tools:vs2010 pc on company
|
|
|
Created:$DATE$
|
|
|
History:$DAY$:$MONTH$:$YEAR$ $HOUR$:$MINUTE$
|
|
|
*******************************************************************************/
|
|
|
#ifndef __TP_MAIN_HEADER_H
|
|
|
#define __TP_MAIN_HEADER_H
|
|
|
|
|
|
//#define _LOAD_MAIN_DLL_STATIC
|
|
|
#include "tpGuiHeader.h"
|
|
|
|
|
|
#include <QtWidgets\qwidget.h>
|
|
|
#include <QtCore\qprocess.h>
|
|
|
#include <QtGui\qicon.h>
|
|
|
#include <QtWidgets\qlistwidget.h>
|
|
|
#include <QtCore\qstring.h>
|
|
|
#include <QtCore\qobject.h>
|
|
|
#include <QtGui\qimage.h>
|
|
|
#include <QtGui\qpainter.h>
|
|
|
#include <QtWidgets\qcombobox.h>
|
|
|
#include <QtWidgets\qaction.h>
|
|
|
#include <QtWidgets\qpushbutton.h>
|
|
|
#include <QtWidgets\qlineedit.h>
|
|
|
#include <QtWidgets\qcheckbox.h>
|
|
|
#include <QtWidgets\qlcdnumber.h>
|
|
|
#include <QtWidgets\qlabel.h>
|
|
|
#include <QtWidgets\qcombobox.h>
|
|
|
#include <QtWidgets\qstatusbar.h>
|
|
|
#include <QRadioButton>
|
|
|
#include <QPlainTextEdit>
|
|
|
#include <QSpinBox>
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
|
|
//#include "tpProtocol.h"
|
|
|
class TP_PROTOCOL_MESSAGE;
|
|
|
|
|
|
typedef QList<QWidget*> QWidgetList;
|
|
|
typedef QList<QObject*> QObjectList;
|
|
|
typedef QMap<QString, QString> QStrStrMap;
|
|
|
|
|
|
class IMainFilter
|
|
|
{
|
|
|
public:
|
|
|
IMainFilter() {}
|
|
|
virtual ~IMainFilter() {}
|
|
|
virtual int InitMain() = 0;
|
|
|
virtual void FreeMain() = 0;
|
|
|
|
|
|
// 事件响应函数,如果返回true:则代表后续不需要响应此事件。
|
|
|
// TODO - 现在代码很多没有利用这个返回值。
|
|
|
virtual QWidget* CreateWidget(const QString & className, QWidget * parent, const QString& name) = 0;
|
|
|
virtual bool ActionTrigger(class QAction* pAction, bool bChecked) = 0;
|
|
|
virtual bool OnPaint(QWidget* watched, QPaintEvent* event) = 0;
|
|
|
virtual bool ButtonClicked(class QObject* pButton, bool bChecked) = 0;
|
|
|
virtual bool OnToggled(class QObject* pButton, bool bChecked) = 0;
|
|
|
virtual bool OnPolished(QWidget * watched, QEvent * event) = 0;
|
|
|
virtual bool OnComboxCurrentChanged(QObject * watched, int index) = 0;
|
|
|
virtual bool OnInitMainWindow(QObject * watched) = 0;
|
|
|
virtual bool OnProcessFinished(class QProcess* p, int exitCode, QProcess::ExitStatus exitStatus) = 0;
|
|
|
virtual bool OnProcessError(class QProcess* p, QProcess::ProcessError error) = 0;
|
|
|
virtual bool OnValueChanged(QObject* watched, int i) = 0;
|
|
|
virtual bool OnValueChanged(QObject* watched, double v) = 0;
|
|
|
virtual bool OnValueChanged(QObject* watched, const QString& text) = 0;
|
|
|
virtual bool OnStateChanged(QObject* watched, int state) = 0;
|
|
|
virtual bool OnCurrentChanged(QObject* watched, int index) = 0;
|
|
|
virtual bool OnDoubleClicked(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnMousePress(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnMouseRelease(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnMouseMove(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnNonClientAreaMouseMove(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnNonClientAreaMouseButtonPress(QObject* watched, QMouseEvent* event) = 0;
|
|
|
virtual bool OnKeyPress(QObject* watched, QKeyEvent* event) = 0;
|
|
|
virtual bool OnKeyRelease(QObject* watched, QKeyEvent* event) = 0;
|
|
|
virtual bool OnResize(QWidget* watched, QResizeEvent* event) = 0;
|
|
|
virtual bool OnWidgetClosed(QWidget* watched, QCloseEvent* event) = 0;
|
|
|
virtual bool OnDeferredDelete(QObject* wathced, QEvent* event) = 0;
|
|
|
virtual bool OnVersionUpdate(const QString& sOldVersion, const QString& sNewVersion) = 0;
|
|
|
virtual bool OnLineEditCursorPositionChanged(class QLineEdit* pObj, int nOld, int nNew) = 0;
|
|
|
virtual bool OnLineEditEditingFinished(class QLineEdit* pObj) = 0;
|
|
|
virtual bool OnLineEditSelectionChanged(class QLineEdit* pObj) = 0;
|
|
|
virtual bool OnLineEditTextChanged(class QLineEdit* pObj, const QString& text) = 0;
|
|
|
virtual bool OnLineEditTextEdited(class QLineEdit* pObj, const QString& text) = 0;
|
|
|
virtual bool OnWidgetShow(QWidget* pWidget, QShowEvent* event) = 0;
|
|
|
virtual bool OnWidgetHide(QWidget* pWidget, QHideEvent* event) = 0;
|
|
|
virtual bool OnWheel(QWidget* pWidget, QWheelEvent* event) = 0;
|
|
|
virtual bool onItemSelectionChanged(QWidget* pWidget) = 0;
|
|
|
virtual void onIPCResponse(QSharedPointer<TP_PROTOCOL_MESSAGE> pmsg) = 0;
|
|
|
virtual void OnHandleMessage(const QStringList& listFilterKey, const QJsonObject& jsonObj) = 0;
|
|
|
};
|
|
|
|
|
|
class IMainCallback
|
|
|
{
|
|
|
public:
|
|
|
IMainCallback() {}
|
|
|
virtual ~IMainCallback() {}
|
|
|
//更新某个窗口的的接口,在非UI线程中更新窗口时,会用signal-slot切换到UI Thread更新窗口
|
|
|
virtual void IUpdateWidget(QWidget* w) = 0;
|
|
|
virtual void IUpdateWidget(const QString& skey, const QObject* parent = NULL) = 0;
|
|
|
//获取DLL路径列表,数据在app.json中配置
|
|
|
virtual QStringList IDllPaths() = 0;
|
|
|
//三个设置Widget的包装函数,舍弃,用下面的 tpfunc_ 开头的inline全局函数
|
|
|
virtual void ISetComboBoxText(const QString& name, const QStrStrMap& textData, QObject* parent = NULL) = 0;
|
|
|
virtual void ISetEditText(const QString& name, const QString& text, QObject* parent = NULL) = 0;
|
|
|
virtual void ISetValue(const QString& name, const QVariant& text, QObject* parent = NULL) = 0;
|
|
|
virtual QObjectList IFindObjects(const QString& objName, QObject* parent = NULL) = 0;
|
|
|
virtual QObjectList IFindObjects(const QStringList& objNames, QObject* parent = NULL) = 0;
|
|
|
virtual QWidgetList FindWidgets(const QString& objName, QObject* parent = NULL) = 0;
|
|
|
virtual QWidgetList FindWidgets(const QRegExp& regExp, QObject* parent = NULL) = 0;
|
|
|
virtual bool IQueueJson(const QString& key, const QJsonObject& json) = 0;
|
|
|
virtual bool IQueuePicture(const QString& name, QImage& img, const QString& format) = 0;
|
|
|
virtual QWidget* IGetWidget(const QString& sKey) = 0;
|
|
|
virtual bool IDelWidget(const QString& sKey) = 0;
|
|
|
virtual bool IDelWidget(QWidget* pWdg) = 0;
|
|
|
virtual void IThumbnailItemAppend(const char* name, const QIcon& icon, const QString& text) = 0;
|
|
|
virtual void IThumbnailItemRemove(const char* name) = 0;
|
|
|
virtual void ISetComboBoxTextData(const QString& name, const QTpStrStrMap& textData, QObject* parent = NULL) = 0;
|
|
|
virtual QJsonObject IJsonUser() = 0;
|
|
|
virtual void ILogString(const QString& str) = 0;
|
|
|
virtual bool IGetUserInfo(QString& user, QString& level) = 0;
|
|
|
virtual bool ISetFilter(QObject* pObject) = 0;
|
|
|
virtual void ISendIPCPackage(TP_PROTOCOL_MESSAGE& msg) = 0;
|
|
|
|
|
|
virtual void IHandleMessage(const QStringList& listFilterKey, const QJsonObject& jsonObj) = 0;
|
|
|
};
|
|
|
|
|
|
//inline functions for conveniece
|
|
|
|
|
|
inline QString tpfunc_main_path(IMainCallback* pCb)
|
|
|
{
|
|
|
if (NULL == pCb)
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
QStringList dllPaths = pCb->IDllPaths();
|
|
|
if (dllPaths.size() == 0)
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
return dllPaths.last();
|
|
|
}
|
|
|
|
|
|
inline bool tpfunc_get_lineedit_text(QString& text, IMainCallback* pCb, const QString& name, QObject* parent = NULL)
|
|
|
{
|
|
|
QWidgetList wdgList = pCb->FindWidgets(name, parent);
|
|
|
for (QWidgetList::iterator it = wdgList.begin(); it != wdgList.end(); ++it)
|
|
|
{
|
|
|
QLineEdit* pEdit = qobject_cast<QLineEdit*>(*it);
|
|
|
if (NULL != pEdit)
|
|
|
{
|
|
|
text = pEdit->text();
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
inline bool tpfunc_get_combobox_current_data(QVariant& v, IMainCallback* pCb, const QString& name, QObject* parent = NULL)
|
|
|
{
|
|
|
QWidgetList wdgList = pCb->FindWidgets(name, parent);
|
|
|
for (QWidgetList::iterator it = wdgList.begin(); it != wdgList.end(); ++it)
|
|
|
{
|
|
|
QComboBox* pCombo = qobject_cast<QComboBox*>(*it);
|
|
|
if (NULL != pCombo)
|
|
|
{
|
|
|
v = pCombo->currentData();
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
inline QListWidgetItem* tpfunc_text_2_listwidget_item(QListWidget* pList, const QString& text, bool bAdd = true)
|
|
|
{
|
|
|
if (NULL == pList)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
if (bAdd)
|
|
|
{
|
|
|
return new QListWidgetItem(text, pList);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
QList<QListWidgetItem*> items = pList->findItems(text, Qt::MatchFixedString);
|
|
|
for (QList<QListWidgetItem*>::iterator it = items.begin(); it != items.end(); ++it)
|
|
|
{
|
|
|
pList->removeItemWidget(*it);
|
|
|
delete *it;
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
inline void tpfunc_set_value(const QString& name, const QVariant& value, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
pCb->ISetValue(name, value, parent);
|
|
|
}
|
|
|
|
|
|
|
|
|
inline QVariant tpfunc_get_value(const QString& name, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QVariantMap vMap;
|
|
|
QTpWidgetList wgtList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wgtList.begin(); it != wgtList.end(); ++it)
|
|
|
{
|
|
|
QLineEdit* pEdit = qobject_cast<QLineEdit*>(*it);
|
|
|
if (NULL != pEdit)
|
|
|
{
|
|
|
return pEdit->text();
|
|
|
}
|
|
|
|
|
|
QLabel* pLabel = qobject_cast<QLabel*>(*it);
|
|
|
if (NULL != pLabel)
|
|
|
{
|
|
|
return pLabel->text();
|
|
|
}
|
|
|
|
|
|
QCheckBox* pBox = qobject_cast<QCheckBox*>(*it);
|
|
|
if (NULL != pBox)
|
|
|
{
|
|
|
return pBox->checkState();
|
|
|
}
|
|
|
|
|
|
QComboBox* pCombo = qobject_cast<QComboBox*>(*it);
|
|
|
if (NULL != pCombo)
|
|
|
{
|
|
|
QVariant v = pCombo->currentData();
|
|
|
if (v.isValid())
|
|
|
{
|
|
|
return v;
|
|
|
}
|
|
|
return pCombo->currentText();
|
|
|
}
|
|
|
|
|
|
QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(*it);
|
|
|
if (pSpinBox){
|
|
|
return pSpinBox->value();
|
|
|
}
|
|
|
|
|
|
QDoubleSpinBox* pDSpinBox = qobject_cast<QDoubleSpinBox*>(*it);
|
|
|
if (pDSpinBox){
|
|
|
return pDSpinBox->value();
|
|
|
}
|
|
|
|
|
|
QLCDNumber* pLcd = qobject_cast<QLCDNumber*>(*it);
|
|
|
if (NULL != pLcd)
|
|
|
{
|
|
|
return pLcd->value();
|
|
|
}
|
|
|
}
|
|
|
return QVariant();
|
|
|
}
|
|
|
|
|
|
inline void tpfunc_qcombobox_add_item(const QString& name, const QStringList& texts, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QTpWidgetList wgtList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wgtList.begin(); it != wgtList.end(); ++it)
|
|
|
{
|
|
|
QComboBox* pCombo = qobject_cast<QComboBox*>(*it);
|
|
|
if (NULL == pCombo)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
pCombo->addItems(texts);
|
|
|
}
|
|
|
}
|
|
|
inline void tpfunc_qcombobox_add_item(const QString& name, const QString& text, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QTpWidgetList wgtList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wgtList.begin(); it != wgtList.end(); ++it)
|
|
|
{
|
|
|
QComboBox* pCombo = qobject_cast<QComboBox*>(*it);
|
|
|
if (NULL == pCombo)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
pCombo->addItem(text);
|
|
|
}
|
|
|
}
|
|
|
inline void tpfunc_qcombobox_del_item(const QString& name, const QString& text, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QTpWidgetList wgtList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wgtList.begin(); it != wgtList.end(); ++it)
|
|
|
{
|
|
|
QComboBox* pCombo = qobject_cast<QComboBox*>(*it);
|
|
|
if (NULL == pCombo)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
int index = pCombo->findText(text);
|
|
|
if (-1 != index)
|
|
|
{
|
|
|
pCombo->removeItem(index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
inline void tpfunc_qlistwidget_add_item(const QString& name, const QStringList& texts, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QTpWidgetList wgtList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wgtList.begin(); it != wgtList.end(); ++it)
|
|
|
{
|
|
|
QListWidget* pList = qobject_cast<QListWidget*>(*it);
|
|
|
if (NULL == pList)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
pList->addItems(texts);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
inline QWidget* tpfunc_widget_by_property(QObject* pObj, bool bDoubleClicked, IMainCallback* pCb)
|
|
|
{
|
|
|
if (NULL == pObj)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
QString uiFile;
|
|
|
if (bDoubleClicked)
|
|
|
{
|
|
|
uiFile = tp_check_string_property(TP_PROP_STRING_DOUBLE_CLICKED_TO_OPEN_UI_FILE, pObj);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
uiFile = tp_check_string_property(TP_PROP_STRING_CLICKED_TO_OPEN_UI_FILE, pObj);
|
|
|
}
|
|
|
if (uiFile.isEmpty())
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
QWidget* pWg = pCb->IGetWidget(uiFile);
|
|
|
if (NULL != pWg)
|
|
|
{
|
|
|
pWg->setProperty(TP_PROP_STRING_OPENED_BY_OBJECT, pObj->objectName());
|
|
|
}
|
|
|
//pWg->show();
|
|
|
return pWg;
|
|
|
}
|
|
|
|
|
|
inline void tpfunc_widget_enable(const QString& name, bool bEnable, QObject* parent, IMainCallback* pCb)
|
|
|
{
|
|
|
QWidgetList wList = pCb->FindWidgets(name, parent);
|
|
|
for (QTpWidgetList::Iterator it = wList.begin(); it != wList.end(); ++it)
|
|
|
{
|
|
|
(*it)->setEnabled(bEnable);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
inline void tpfunc_message_to_status(const QString& msg, IMainCallback* pCb, QObject* parent = NULL)
|
|
|
{
|
|
|
QWidgetList wList = pCb->FindWidgets("statusbar", parent);
|
|
|
for (QTpWidgetList::Iterator it = wList.begin(); it != wList.end(); ++it)
|
|
|
{
|
|
|
QStatusBar* pStatus = qobject_cast<QStatusBar*>(*it);
|
|
|
if (NULL != pStatus)
|
|
|
{
|
|
|
pStatus->clearMessage();
|
|
|
pStatus->showMessage(msg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
#ifdef TPMAIN_EXPORTS
|
|
|
#define MAIN_API extern "C" __declspec(dllexport)
|
|
|
#else
|
|
|
#ifndef _LOAD_MAIN_DLL_STATIC
|
|
|
#define MAIN_API extern "C"
|
|
|
#else
|
|
|
#define MAIN_API extern "C" __declspec(dllimport)
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
MAIN_API IMainFilter* Main_Create(IMainCallback* pMainCb);
|
|
|
MAIN_API void Main_Delete(IMainFilter* pMain);
|
|
|
|
|
|
#endif |