123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "qminmaxwindowwidget.h"
- #include "qevent.h"
- #include "qtimer.h"
- QMinMaxWindowWidget::QMinMaxWindowWidget(QWidget *parent)
- : QWidget(parent), m_contrl(nullptr)
- {
- ui.setupUi(this);
- setAttribute(Qt::WA_DeleteOnClose, true);
- m_contentMargin = QMargins(3, 3, 3, 3);
- connect(ui.toolButtonClose, SIGNAL(clicked()), this, SLOT(closeWindow()));
- connect(ui.toolButtonMax, SIGNAL(clicked()), this, SLOT(switchWindow()));
- connect(ui.toolButtonMin, SIGNAL(clicked()), this, SLOT(minimizedWindow()));
- }
- QMinMaxWindowWidget::~QMinMaxWindowWidget()
- {
- }
- void QMinMaxWindowWidget::setControlWidget(QWidget * contrl)
- {
- m_contrl = contrl;
- if (m_contrl)m_contrl->installEventFilter(this);
- initalizeIcons();
- }
- bool QMinMaxWindowWidget::eventFilter(QObject * o, QEvent * e)
- {
- if (o == m_contrl){
- if (e->type() == QEvent::Show){
- QShowEvent * event = (QShowEvent *)e;
- QTimer::singleShot(100, this, &QMinMaxWindowWidget::initalizeIcons);
- }
- }
- return false;
- }
- void QMinMaxWindowWidget::initalizeIcons()
- {
- if (m_contrl&&m_contrl->isMaximized()){
- if (m_contrl->layout())
- {
- m_contentMargin = m_contrl->layout()->contentsMargins();
- m_contrl->layout()->setContentsMargins(QMargins(0, 0, 0, 0));
- }
- }
- }
- void QMinMaxWindowWidget::switchWindow()
- {
- if (m_contrl){
- if (m_contrl->isMaximized()){
- m_contrl->showNormal();
- if (m_contrl->layout())
- {
- m_contrl->layout()->setContentsMargins(QMargins(3, 3, 3, 3));
- }
- ui.toolButtonMax->setToolTip(QString::fromStdWString(L"×î´ó»¯"));
- }
- else{
- if (m_contrl->layout())
- {
- m_contrl->layout()->setContentsMargins(QMargins(0, 0, 0, 0));
- }
- m_contrl->showMaximized();
- ui.toolButtonMax->setToolTip(QString::fromStdWString(L"»¹Ô"));
- //QIcon icon;
- //icon.addFile(QString::fromLocal8Bit(":/conctrl/Resources/0huanyuan.png"));
- //ui.toolButtonMax->setIcon(icon);
- }
- }
- }
- void QMinMaxWindowWidget::minimizedWindow()
- {
- if (m_contrl)m_contrl->showMinimized();
- }
- void QMinMaxWindowWidget::closeWindow()
- {
- if (m_contrl){
- m_contrl->close();
- }
- }
- void QMinMaxWindowWidget::setMaxVisible(bool visible)
- {
- ui.toolButtonMax->setVisible(visible);
- }
- void QMinMaxWindowWidget::setMinVisible(bool visible)
- {
- ui.toolButtonMin->setVisible(visible);
- }
- void QMinMaxWindowWidget::setCloseVisible(bool visible)
- {
- ui.toolButtonClose->setVisible(visible);
- }
|