UI_Btn


class BaseVisitor
{
public:
 virtual ~BaseVisitor(void);
 virtual BOOL VisitUiType(UiType* pUiType);
 virtual BOOL VisitBtnEx(BtnEx* pBtn);
 virtual BOOL VisitCheckEx(CheckEx* pCheck);
 virtual BOOL VisitImgEx(ImgEx* pImgEx);
 virtual BOOL VisitCompositionExStart(CompositionEx* pCptEx);
 virtual BOOL VisitCompositionExEnd(CompositionEx* pCptEx);

protected:
 BaseVisitor(void);
};


//------------------------ UI TYPE -------------------------------------
class UiType
{//数据类
public:
 enum UI_STATE
 {
  UI_NORMAL = 0,
  UI_PRESS = 1,
  UI_FOCUS = 2,
  UI_DISENBLE = 3,
  UI_HIDE = 4,
 };

 

 virtual ~UiType();
 virtual BOOL   Accept(BaseVisitor* pGpsVistor) = 0;
 virtual void   Render(HDC& hDC) = 0;
 virtual BOOL   Init(int ID);
 virtual void   InitDest(int l, int t, int r, int b);
 virtual void   SetState(UI_STATE iState);
 virtual void   ToOldState();
 virtual int    GetID();
 virtual RECT   GetDest();
 virtual UI_STATE  GetState();
 virtual void   SetTxt(TCHAR* szTxt);
 virtual TCHAR*   GetTxt();
protected:
 UiType();
private:
 int   m_iThisID;
 RECT  m_rtDest;
 UI_STATE m_iCurState;
 UI_STATE m_iPreState;
 TCHAR  m_szTxt[64];
};

 

//-------------------------- Btn -------------------------------------
class BtnEx: public UiType
{
public:
 BtnEx();
 virtual ~BtnEx();
 virtual BOOL Accept(BaseVisitor* pGpsVistor);
 virtual void Render(HDC& hDC);
};
//----------------------------------------------------------------------

 

//-------------------------- CheckEx -------------------------------------
class CheckEx: public UiType
{
public:
 CheckEx();
 virtual ~CheckEx();
 virtual BOOL Accept(BaseVisitor* pGpsVistor);
 virtual void Render(HDC& hDC);
};
//----------------------------------------------------------------------


//-------------------------- ImgEx -------------------------------------
class ImgEx: public UiType
{
public:
 ImgEx();
 virtual ~ImgEx();
 virtual BOOL Accept(BaseVisitor* pGpsVistor);
 virtual void Render(HDC& hDC);
};
//----------------------------------------------------------------------

//-------------------------- CompositionEx ----------------------------
class CompositionEx: public UiType
{
public:
 CompositionEx();
 virtual ~CompositionEx();
 virtual BOOL Accept(BaseVisitor* pGpsVistor);
 virtual void Render(HDC& hDC);
 void Sharing(UiType* pUi);
 void Clear();
 BOOL IsHit(POINT pt);

 vector<UiType*> m_vpUi;
};
//----------------------------------------------------------------------

 

 

//---------------------------------------------------------------------------------------------------------------------

 

#pragma once
#include "../UiModel/BaseVisitor.h"
#include "../../../HDCMemo.h"
#include "../../../CE600.h"
#include "../../../COMImage.h"


class DecorateBtnSelf: private BtnEx
{
public:
 ~DecorateBtnSelf(){NULL;}

 using BtnEx::UI_STATE;
 using BtnEx::UI_NORMAL;
 using BtnEx::UI_PRESS;
 using BtnEx::UI_FOCUS;
 using BtnEx::UI_HIDE;
protected:
 DecorateBtnSelf(){NULL;}
};

class DecorateBtn: public DecorateBtnSelf
{
public:
 virtual ~DecorateBtn(void);
 virtual void Render(HDC& hDC) = 0;
 virtual BOOL Accept(BaseVisitor* pGpsVistor);
 virtual BOOL Init(int ID);
 virtual void    InitDest(int l, int t, int r, int b);
 virtual void SetTxt(TCHAR* szTxt);
 void   SetState(UI_STATE iState);
 void   ToOldState();
 int    GetID();
 RECT   GetDest();
 UI_STATE  GetState();
 void   SetTxtSytle(int iSize, COLORREF clsTxt, UINT nSign);
 void   SetTxtPos(RECT rtTxt);

protected:
 DecorateBtn(::BtnEx* pBtnEx);
 ::BtnEx*  m_pBtnEx;
 int    m_iTxtSize;
 COLORREF  m_clsTxt;
 UINT   m_nSign;
 RECT   m_rtTxt;
};

 

// --------------------- 无透明情况按钮 -----------------------------
class BtnColorStyle: public DecorateBtn
{
public:
 BtnColorStyle(::BtnEx* pBtnEx, COLORREF clrNor, COLORREF clrPre, COLORREF clrFou);
 ~BtnColorStyle();
 virtual void Render(HDC& hDC);

protected:
 COLORREF m_clrNor;
 COLORREF m_clrPre;
 COLORREF m_clrFou;
};


class BtnGroupStyle: public BtnColorStyle
{
public:
 BtnGroupStyle(::BtnEx* pBtnEx, COLORREF clrNor, COLORREF clrPre, COLORREF clrFou,
  HINSTANCEUserEx& hRes, int ImgNorID, int ImgPreID, int ImgFouID, RECT rtBtn, RECT rtImg);
 ~BtnGroupStyle();
 virtual void Render(HDC& hDC);

protected:
 HDCMemo *m_pImg[3];
};


class BtnScarfStyle: public BtnGroupStyle
{
public:
 BtnScarfStyle(::BtnEx* pBtnEx, COLORREF clrNor, COLORREF clrPre, COLORREF clrFou,
  HINSTANCEUserEx& hRes, int ImgNorID, int ImgPreID, int ImgFouID, RECT rtBtn, RECT rtImg,
  int ScarfID,RECT rtScarf);
 ~BtnScarfStyle();
 virtual void Render(HDC& hDC);
};

 

// --------------------- 含透明情况按钮 -----------------------------
class BtnAlphaStyle: public DecorateBtn
{
public:
 BtnAlphaStyle(::BtnEx* pBtnEx, HINSTANCEUserEx& hRes, int ImgNorPreID);
 ~BtnAlphaStyle();
 virtual void Render(HDC& hDC);

protected:
 IImageEx m_objAlphaImg;
 int   m_iUnitW;
};


class BtnAlpha2Style: public DecorateBtn
{
public:
 BtnAlpha2Style(::BtnEx* pBtnEx, HINSTANCEUserEx& hRes, RECT rtBtn,
  int iImgNorID, RECT rtNor,
  int iImgPreID, RECT rtPre);
 ~BtnAlpha2Style();
 virtual void Render(HDC& hDC);

protected:
 IImageEx m_objAlphaImgNor;
 IImageEx m_objAlphaImgPre;
 RECT  m_rtNor;
 RECT  m_rtPre;
};


class BtnAlpha2ScarfStyle: public BtnAlpha2Style
{
public:
 BtnAlpha2ScarfStyle(::BtnEx* pBtnEx, HINSTANCEUserEx& hRes, RECT rtBtn,
  int iImgNorID, RECT rtNor,
  int iImgPreID, RECT rtPre,
  int iImgScarfID,RECT rtScarf, BOOL bIsTop = FALSE);
 ~BtnAlpha2ScarfStyle();
 virtual void Render(HDC& hDC);

protected:
 IImageEx m_objAlphaImgScarf;
 RECT  m_rtScarf;
 BOOL  m_bIsTop;
};

 

//-------------------------------------------------------------------------------------------------------

 

 

 

#pragma once
#include "../UiModel/BaseVisitor.h"

 

class EventLBDown: public BaseVisitor
{
public:
 EventLBDown(POINT pt);
 virtual ~EventLBDown(void);
 virtual BOOL VisitBtnEx(BtnEx* pBtn);
 virtual BOOL VisitCheckEx(CheckEx* pCheck);

 int  GetHitID();

private:
 POINT m_ptPos;
 int   m_iFouceID;
};

class EventLBUp: public BaseVisitor
{
public:
 EventLBUp(POINT pt);
 virtual ~EventLBUp(void);
 virtual BOOL VisitCompositionExStart(CompositionEx* pCptEx);
 virtual BOOL VisitBtnEx(BtnEx* pBtn);
 virtual BOOL VisitCompositionExEnd(CompositionEx* pCptEx);
 int  GetHitID();

private:
 vector<BtnEx*> m_vpBtn;
 POINT m_ptPos;
 int   m_iFouceID;
};

#include "workplate.h" #include <QtWidgets> #include "ui/tabMain.h" #include "ui/tabSetting.h" #include "device/monitor.h" #include "thread/threadHmiRecv.h" #include "global/global.h" const char sMonitorMenu[HMI_MENU_SIZE][16] = { "主\n界\n面", //"设\n置", //"历\n史\n信\n息", }; #pragma execution_character_set("utf-8") workplate::workplate(QWidget *parent) : QDialog(parent) { if (nullptr == g_Monitor) { g_Monitor = new Monitor(this); } if (nullptr == g_ThreadHmiRecv) { g_ThreadHmiRecv = new ThreadHmiRecv(this); g_ThreadHmiRecv->start(); } this->setFixedSize(UI_WINDOW_W, UI_WINDOW_H); this->setWindowTitle(QString::fromLocal8Bit(gSystemTitleName)); this->setWindowIcon(QIcon(QPixmap(":/skin/icon/logo.png"))); mainBKG = new QWidget(this); mainBKG->setProperty("UIClass", "LinearBlack"); mainBKG->setGeometry(0, 0, UI_WINDOW_W, UI_WINDOW_H); int ix = UI_TAB_W + UI_SPACE_W; int iy = UI_MARGIN_H; iy += UI_LINE_H + UI_SPACE_H; menuBKG = new QWidget(mainBKG); menuBKG->setProperty("UIClass", "LinearBlack"); menuBKG->setGeometry(ix, iy, UI_BTN_H + 2 * UI_MARGIN_W, UI_WINDOW_H - iy); QButtonGroup* group = new QButtonGroup(this); group->setExclusive(true); ix = UI_MARGIN_W; iy = UI_MARGIN_H; QPushButton* btn = nullptr; for (int i = 0; i < HMI_MENU_SIZE; ++i) { btn = new QPushButton(QString::fromLocal8Bit(sMonitorMenu[i]), menuBKG); btn->setCheckable(true); btn->setGeometry(ix, iy, UI_BTN_H, UI_BTN_W); iy += UI_BTN_W + UI_SPACE_H; btn->setProperty("UIClass", "CheckPurple"); connect(btn, SIGNAL(clicked()), this, SLOT(slot_SwitchTab())); group->addButton(btn); m_vBtnSwitch.push_back(btn); } QWidget* tab = nullptr; /* 1.主界面 */ tab = new TabMain(mainBKG); m_vTables.push_back(tab); /* 设置 */ tab = new TabSetting(mainBKG); m_vTables.push_back(tab); /* 历史信息 */ tab = new QWidget(mainBKG); m_vTables.push_back(tab); for (int i = 0; i < m_vTables.size(); ++i) { m_vTables[i]->setGeometry(0, 0, UI_TAB_W, UI_TAB_H); } m_vBtnSwitch[HMI_MAIN]->setChecked(true); showTable(HMI_MAIN); } workplate::~workplate() { if (nullptr != g_ThreadHmiRecv) { g_ThreadHmiRecv->setRun(false); } } bool workplate::nativeEvent(const QByteArray& eventType, void* message, long* result) { MSG* msg = reinterpret_cast<MSG*>(message); switch (msg->message) { default: break; } return QDialog::nativeEvent(eventType, message, result); } void workplate::keyPressEvent(QKeyEvent* e) { switch (e->key()){ case Qt::Key_0: { g_Monitor->SendMsg((uint8_t*)"12345678", 8); } default: break; } } void workplate::closeEvent(QCloseEvent* e) { } void workplate::slot_SwitchTab() { const QPushButton* const btn = qobject_cast<QPushButton*>(sender()); if (btn == m_vBtnSwitch[HMI_MAIN]) { showTable(HMI_MAIN); } else if (btn == m_vBtnSwitch[HMI_SETTING]) { showTable(HMI_SETTING); } else if (btn == m_vBtnSwitch[HMI_HISTORY]) { showTable(HMI_HISTORY); } } void workplate::showTable(const uint8_t tab) { for (int i = 0; i < HMI_MENU_SIZE; ++i) { if (tab == i) { m_vTables[i]->setVisible(true); } else { m_vTables[i]->setVisible(false); } } } 详细分析这段代码,逐字逐句的
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值