wintaskbarprogress.h raw

   1  // Copyright (c) 2025 The Limenka Knots developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef LIMENKA_QT_WINTASKBARPROGRESS_H
   6  #define LIMENKA_QT_WINTASKBARPROGRESS_H
   7  
   8  #include <QAbstractNativeEventFilter>
   9  #include <QObject>
  10  #include <QPointer>
  11  
  12  class QWidget;
  13  class QWindow;
  14  struct ITaskbarList3;
  15  
  16  class WinTaskbarProgress : public QObject, public QAbstractNativeEventFilter
  17  {
  18      Q_OBJECT
  19  
  20  public:
  21      explicit WinTaskbarProgress(QObject *parent = nullptr);
  22      ~WinTaskbarProgress();
  23  
  24      void setWindow(QWidget* widget);
  25      void setValue(int value);
  26      void setVisible(bool visible);
  27  
  28  #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
  29      bool nativeEventFilter(const QByteArray &eventType, void *pMessage, qintptr *pnResult) override;
  30  #else
  31      bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) override;
  32  #endif
  33  
  34  private:
  35      QPointer<QWindow> m_window;
  36      int m_value = 0;
  37      bool m_visible = false;
  38      ITaskbarList3* m_taskbar_button = nullptr;
  39      unsigned int m_taskbar_button_created_msg = 0;
  40      bool m_taskbar_ready = false;
  41  
  42      void updateProgress();
  43      void initTaskbarButton();
  44      void releaseTaskbarButton();
  45  };
  46  
  47  #endif // LIMENKA_QT_WINTASKBARPROGRESS_H
  48