Ver Fonte

V1.6.5
1、修改完成了时间选择器,触发关闭非常灵敏了

Apple há 1 semana atrás
pai
commit
e874f1911e
2 ficheiros alterados com 44 adições e 29 exclusões
  1. 41 26
      common/SelectTime/timewidget.cpp
  2. 3 3
      common/SelectTime/timewidget.h

+ 41 - 26
common/SelectTime/timewidget.cpp

@@ -164,7 +164,7 @@ void TimeWidget::setEditLineEnable(bool enable)
     {
         if(m_pTimePopupWidget != nullptr && m_pTimePopupWidget->isVisible())
         {
-            m_isBanPopupShow = true;
+            // m_isBanPopupShow = true;
             ShowPopupArea(false);
             UpdateProperty(this, "hover", false);
         }
@@ -204,11 +204,7 @@ void TimeWidget::setQSS()
 /* 点击了时间图标 */
 void TimeWidget::do_pBtn_tip_Clicked()
 {
-    if(m_pTimePopupWidget == nullptr)
-    {
-        return;
-    }
-    if(m_pTimePopupWidget->isVisible())
+    if((m_pTimePopupWidget != nullptr) && (m_pTimePopupWidget->isVisible()))
     {
         return;
     }
@@ -224,6 +220,16 @@ void TimeWidget::do_pBtn_tip_Clicked()
  */
 bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
 {
+    /* 判断是否被禁用了 */
+    if(!this->isEnabled())
+    {
+        return QWidget::eventFilter(obj, e);
+    }
+    /* 判断是否是鼠标点击事件 */
+    if(e == nullptr || obj == nullptr)
+    {
+        return QWidget::eventFilter(obj, e);
+    }
     if (obj == ui->dateTimeEdit) 
     {
         if(e->type() == QEvent::Wheel && m_isDisableWheel)
@@ -234,15 +240,13 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
         if (e->type() == QEvent::FocusIn && m_type == EditLine)
         {
             /* 如果Popup正在关闭 */
-
-                if(m_isBanPopupShow == true)
-                {
-                    m_isBanPopupShow = false;
-                    /* 这里需要再次失去焦点,否则下次点击编辑栏无法弹出Popup */
-                    ui->dateTimeEdit->clearFocus();
-                    return QWidget::eventFilter(obj, e);
-                }
-            
+            // if(m_isBanPopupShow == true)
+            // {
+            //     m_isBanPopupShow = false;
+            //     /* 这里需要再次失去焦点,否则下次点击编辑栏无法弹出Popup */
+            //     ui->dateTimeEdit->clearFocus();
+            //     return QWidget::eventFilter(obj, e);
+            // }
             
             //qInfo() << "dateTimeEdit focusIn";
             ShowPopupArea(true);
@@ -274,13 +278,12 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
             UpdateProperty(this, "hover", false);
         }
     }
-    /* 判断是不是显示区外面,是的话就隐藏 */
-    QMouseEvent* pMouse = reinterpret_cast<QMouseEvent*>(e);
-    if (nullptr != pMouse) 
+    /* 鼠标点击事件,判断是不是显示区外面,是的话就隐藏,是内部就显示弹窗 */
+    if(e->type() == QEvent::MouseButtonPress)
     {
-        if (pMouse->type() == QEvent::MouseButtonPress) 
+        QMouseEvent* pMouse = reinterpret_cast<QMouseEvent*>(e);
+        if (nullptr != pMouse) 
         {
-            //qInfo() << "focusOut";
             QPoint gtl = this->mapToGlobal(rect().topLeft());
             QRect rc(gtl.x(), gtl.y(), width(), height()); // 全局位置判断
             if (!rc.contains(pMouse->globalPos())) 
@@ -296,10 +299,10 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
                 }
                 /* 如果焦点不在编辑栏,Popup窗口隐藏后,编辑栏会重新获取焦点,将会再次跳出Popup窗口
                     因此在其没有焦点的时候设置 m_isBanPopupShow ,防止Popup隐藏后编辑栏再次获取焦点再次弹出Popup */
-                if(!ui->dateTimeEdit->hasFocus())
-                {
-                    m_isBanPopupShow = true;
-                }
+                // if(!ui->dateTimeEdit->hasFocus())
+                // {
+                //     m_isBanPopupShow = true;
+                // }
                 
                 ShowPopupArea(false);
                 UpdateProperty(this, "hover", false);
@@ -309,8 +312,19 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
                     this->close();
                 }
             }
+            else 
+            {
+                /* 鼠标点击在了编辑栏内部 */
+                if(m_wdgTimeArea != nullptr && m_wdgTimeArea->isVisible())
+                {
+                    return QWidget::eventFilter(obj, e);
+                }
+                ShowPopupArea(true);
+                UpdateProperty(this, "hover", true);
+            }
         }
     }
+    
 
     return QWidget::eventFilter(obj, e);
 }
@@ -328,6 +342,7 @@ void TimeWidget::moveEvent(QMoveEvent *event)
     }
 }
 
+
 /* 这个用来实时修改编辑栏的时间 */
 void TimeWidget::do_dateTimeChanged(const QTime& dt)
 {
@@ -358,7 +373,7 @@ void TimeWidget::do_closePopup(bool isOk)
     {
         ui->dateTimeEdit->setTime(m_formerDateTime.time());
     }
-    m_isBanPopupShow = true;
+    // m_isBanPopupShow = true;
     ShowPopupArea(false);
     UpdateProperty(this, "hover", false);
     if(m_type == Dialog)
@@ -521,7 +536,7 @@ void TimeWidget::Init()
     ui->dateTimeEdit->setTime(t);
     ui->lbl_tip->hide();
     /* 使用这个阻止show的时候获取焦点自动弹出Popup */
-    m_isBanPopupShow = true;
+    // m_isBanPopupShow = true;
     ui->dateTimeEdit->show();
     m_formerDateTime.setTime(t);
 

+ 3 - 3
common/SelectTime/timewidget.h

@@ -14,6 +14,7 @@
  *  4、使用Dialog模式的时候,点击空白处隐藏就会close掉,然后发送新的时间信号
  *  5、使用Dialog模式,执行execShow()函数,会阻塞运行,直到关闭
  *  6、如果需要对比修改之前和之后的时间,需要使用Popup的方式修改时间,禁止在编辑栏直接修改
+ *  7、设置启用与关闭调用 setEditLineEnable(bool enable) 函数,不要使用默认的 setEnabled函数
 */
 
 
@@ -66,7 +67,7 @@ public:
     void setEditLine(int w, int h);
     /* 设置禁止使用滚轮修改时间 */
     void setWheelDisabled(bool disabled);
-    /* 设置启用与否*/
+    /* 设置启用与否 */
     void setEditLineEnable(bool enable);
 
     /* 设置QSS */
@@ -79,7 +80,6 @@ protected:
     bool eventFilter(QObject* obj, QEvent* e) override;
     void moveEvent(QMoveEvent *event) override;
 
-
 private slots:
     /* 点击了时间图标 */
     void do_pBtn_tip_Clicked();
@@ -111,7 +111,7 @@ private:
     // int m_width = 0;                            /* TimeArea宽度 */
 
     bool m_isDisableWheel = false;          // 禁用滚轮修改时间
-    bool m_isBanPopupShow = false;             /* 禁止Popup显示,这个标志位用于关闭Popup弹窗时设置的,防止QEditLine获取焦点后再显示 */
+    // bool m_isBanPopupShow = false;             /* 禁止Popup显示,这个标志位用于关闭Popup弹窗时设置的,防止QEditLine获取焦点后再显示 */
 
     QDateTime m_formerDateTime;                  /* 修改前的时间  */
 };