#pragma once #include #include "IxDynObj.h" #include "iPlugin_global.h" #include #include #include #include #include "iBase_global.h" #include #include class CustomStyle : public QProxyStyle { public: CustomStyle(QStyle *baseStyle = 0) : QProxyStyle(baseStyle) {} void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if(control == QStyle::CC_TitleBar) { const QStyleOptionTitleBar* styleOpt = qstyleoption_cast(option); if (styleOpt != nullptr) { painter->save(); painter->setRenderHint(QPainter::Antialiasing); QRect rectMin = subControlRect(QStyle::CC_TitleBar, styleOpt, widget->isMinimized() ? QStyle::SC_TitleBarNormalButton : QStyle::SC_TitleBarMinButton, widget); QRect rectMax = subControlRect(QStyle::CC_TitleBar, styleOpt, widget->isMaximized() ? QStyle::SC_TitleBarNormalButton : QStyle::SC_TitleBarMaxButton, widget); QRect rectClose = subControlRect(QStyle::CC_TitleBar, styleOpt, QStyle::SC_TitleBarCloseButton, widget); painter->setBrush(styleOpt->state & State_Active ? QColor("#C0DCF2") : QColor("#DEF0FE")); painter->drawRect(styleOpt->rect); QRect rect = styleOpt->rect; //由于高度变化 rectMin.setTop(0);rectMin.setHeight(rect.height()); rectMax.setTop(0);rectMax.setHeight(rect.height()); rectClose.setTop(0);rectClose.setHeight(rect.height()); QSize IconSize = QSize(rect.height(), rect.height()); // 关闭按钮 QPixmap pixIconClose = zxLoadIcon("Titlebar_Close").pixmap(IconSize); drawButton(painter, rectClose, pixIconClose, IconSize); // 最大化按钮 QPixmap pixIconMax = zxLoadIcon(widget->isMaximized() ? "Titlebar_Normal" : "Titlebar_Max").pixmap(IconSize); drawButton(painter, rectMax, pixIconMax, IconSize); // 最小化按钮 QPixmap pixIconMin = zxLoadIcon(widget->isMinimized() ? "Titlebar_Normal" : "Titlebar_Min").pixmap(IconSize); drawButton(painter, rectMin, pixIconMin, IconSize); float fSize = (float) IconSize.height() * 2 / 3; // 图标和标题文本 QRectF iconRect(rect.left() + 2, rect.top(), IconSize.height(), IconSize.height()); QRectF rcIcon(iconRect.center().rx()-fSize/2, iconRect.center().ry() - fSize/2, fSize, fSize); painter->drawPixmap(rcIcon.toRect(), styleOpt->icon.pixmap(QSize(16, 16))); QRectF rcTitle(rcIcon.right() + fSize, rect.top(), rectMin.left() - (rcIcon.right() + fSize), IconSize.height()); painter->drawText(rcTitle, styleOpt->text, QTextOption(Qt::AlignLeft | Qt::AlignVCenter)); painter->restore(); return; } } else { QProxyStyle::drawComplexControl(control, option, painter, widget); } } void drawButton(QPainter *painter, const QRectF &buttonRect, const QPixmap &icon, const QSize size) const { //绘制位置计算取1/2 float fSize = (float) size.height() * 1 / 2; QRectF rcIcon(buttonRect.center().rx()-fSize/2, buttonRect.center().ry() - fSize/2, fSize, fSize); painter->drawPixmap(rcIcon.toRect(), icon); } }; // 主要重载其信号响应 class I_PLUGIN_EXPORT MdiSubWindowEx : public QMdiSubWindow { Q_OBJECT public: MdiSubWindowEx(bool bNovelQss, QWidget* parent = 0); ~MdiSubWindowEx(); void setBindingObj(IxDynObj* p); IxDynObj* getBindingObj(); protected: bool eventFilter(QObject*, QEvent*); void showEvent(QShowEvent *event); void hideEvent(QHideEvent* event); void changeEvent(QEvent* event); void closeEvent(QCloseEvent* event); void resizeEvent(QResizeEvent* event); void mouseDoubleClickEvent(QMouseEvent* event); signals: // b:返回的是,是否允许关闭 void sigConformClosing(bool& b); // 一旦关闭后,通知刷新状态 void sigMdiClosed(); private: IxDynObj* m_pBindingObj; //这是绑定的Obj对象 }; //Mdi中的子项 class I_PLUGIN_EXPORT SubMdiSubWindowEx : public MdiSubWindowEx { Q_OBJECT public: SubMdiSubWindowEx(bool bNovelQss, QWidget* parent = 0); ~SubMdiSubWindowEx(); };