Advertisement
Guest User

More work with taskbar

a guest
Jul 17th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.11 KB | None | 0 0
  1. diff --git a/src/mainwin.cpp b/src/mainwin.cpp
  2. index 3bbd663b..724e8ce0 100644
  3. --- a/src/mainwin.cpp
  4. +++ b/src/mainwin.cpp
  5. @@ -71,6 +71,7 @@
  6.  #include <QtAlgorithms>
  7.  #ifdef Q_OS_WIN
  8.  #include <windows.h>
  9. +#include "widgets/thumbnailtoolbar.h"
  10.  #endif
  11.  #ifdef HAVE_X11
  12.  #include <x11windowsystem.h>
  13. @@ -154,6 +155,7 @@ public:
  14.  
  15.  #ifdef Q_OS_WIN
  16.      DWORD deactivationTickCount;
  17. +    QPointer<PsiThumbnailToolBar> thumbnailToolBar_;
  18.  #endif
  19.  
  20.      void        registerActions();
  21. @@ -510,16 +512,9 @@ MainWin::MainWin(bool _onTop, bool _asTool, PsiCon *psi) :
  22.  
  23.      buildToolbars();
  24.      // setUnifiedTitleAndToolBarOnMac(true);
  25. +
  26.  #ifdef Q_OS_WIN
  27. -    thumbnailToolBar_ = new PsiThumbnailToolBar(this, windowHandle());
  28. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::openOptions, this, &MainWin::doOptions);
  29. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::setOnline, this,
  30. -            [this]() { d->getAction("status_online")->trigger(); });
  31. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::setOffline, this,
  32. -            [this]() { d->getAction("status_offline")->trigger(); });
  33. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::runActiveEvent, this, &MainWin::doRecvNextEvent);
  34. -    connect(psi->contactList(), &PsiContactList::queueChanged, this,
  35. -            [this]() { thumbnailToolBar_->updateToolBar(d->nextAmount > 0); });
  36. +    updateWinTaskbar(_asTool);
  37.  #endif
  38.  
  39.      connect(qApp, SIGNAL(dockActivated()), SLOT(dockActivated()));
  40. @@ -752,6 +747,9 @@ void MainWin::setWindowOpts(bool _onTop, bool _asTool)
  41.  
  42.      setWindowFlags(flags);
  43.      show();
  44. +#ifdef Q_OS_WIN
  45. +    updateWinTaskbar(_asTool);
  46. +#endif
  47.  }
  48.  
  49.  void MainWin::setUseDock(bool use)
  50. @@ -1478,6 +1476,26 @@ bool MainWin::nativeEvent(const QByteArray &eventType, MSG *msg, long *result)
  51.      }
  52.      return false;
  53.  }
  54. +
  55. +void MainWin::updateWinTaskbar(bool enabled)
  56. +{
  57. +    if(! enabled) {
  58. +        if(!d->thumbnailToolBar_) {
  59. +            d->thumbnailToolBar_ = new PsiThumbnailToolBar(this, windowHandle());
  60. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::openOptions, this, &MainWin::doOptions);
  61. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::setOnline, this,
  62. +                    [this]() { d->getAction("status_online")->trigger(); });
  63. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::setOffline, this,
  64. +                    [this]() { d->getAction("status_offline")->trigger(); });
  65. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::runActiveEvent, this, &MainWin::doRecvNextEvent);
  66. +            connect(d->psi->contactList(), &PsiContactList::queueChanged, this,
  67. +                    [this]() { d->thumbnailToolBar_->updateToolBar(d->nextAmount > 0); });
  68. +        }
  69. +    }
  70. +    else {
  71. +        delete d->thumbnailToolBar_;
  72. +    }
  73. +}
  74.  #endif
  75.  
  76.  void MainWin::updateCaption()
  77. diff --git a/src/mainwin.h b/src/mainwin.h
  78. index 02f38fde..802f064e 100644
  79. --- a/src/mainwin.h
  80. +++ b/src/mainwin.h
  81. @@ -22,9 +22,6 @@
  82.  
  83.  #include "advwidget.h"
  84.  #include "xmpp_status.h"
  85. -#ifdef Q_OS_WIN
  86. -#include "widgets/thumbnailtoolbar.h"
  87. -#endif
  88.  
  89.  #include <QList>
  90.  #include <QMainWindow>
  91. @@ -188,14 +185,15 @@ private:
  92.  
  93.      void buildStatusMenu(GlobalStatusMenu *statusMenu);
  94.  
  95. +#ifdef Q_OS_WIN
  96. +    void updateWinTaskbar(bool enabled);
  97. +#endif
  98. +
  99.  private:
  100.      class Private;
  101.      Private *d;
  102.      friend class Private;
  103.      QList<PsiToolBar *> toolbars_;
  104. -#ifdef Q_OS_WIN
  105. -    PsiThumbnailToolBar *thumbnailToolBar_;
  106. -#endif
  107.  };
  108.  
  109.  #endif // MAINWIN_H
  110. diff --git a/src/widgets/thumbnailtoolbar.cpp b/src/widgets/thumbnailtoolbar.cpp
  111. index 9a062616..46ee57ce 100644
  112. --- a/src/widgets/thumbnailtoolbar.cpp
  113. +++ b/src/widgets/thumbnailtoolbar.cpp
  114. @@ -26,7 +26,7 @@
  115.  PsiThumbnailToolBar::PsiThumbnailToolBar(QObject *parent, QWindow *parentWindow) :
  116.      QWinThumbnailToolBar(parent), optionsBtn_(new QWinThumbnailToolButton(this)),
  117.      onlineStatusBtn_(new QWinThumbnailToolButton(this)), offlineStatusBtn_(new QWinThumbnailToolButton(this)),
  118. -    eventsBtn_(new QWinThumbnailToolButton(this))
  119. +    eventsBtn_(new QWinThumbnailToolButton(this)), taskbarBtn_(new QWinTaskbarButton(parent))
  120.  {
  121.      // ToolTips
  122.      optionsBtn_->setToolTip(tr("Options"));
  123. @@ -58,6 +58,7 @@ PsiThumbnailToolBar::PsiThumbnailToolBar(QObject *parent, QWindow *parentWindow)
  124.      addButton(offlineStatusBtn_);
  125.      addButton(optionsBtn_);
  126.      setWindow(parentWindow);
  127. +    taskbarBtn_->setWindow(parentWindow);
  128.  }
  129.  
  130.  void PsiThumbnailToolBar::updateToolBar(bool hasEvents) { eventsBtn_->setEnabled(hasEvents); }
  131. diff --git a/src/widgets/thumbnailtoolbar.h b/src/widgets/thumbnailtoolbar.h
  132. index 4a9c72c5..6e78fdec 100644
  133. --- a/src/widgets/thumbnailtoolbar.h
  134. +++ b/src/widgets/thumbnailtoolbar.h
  135. @@ -21,6 +21,7 @@
  136.  
  137.  #include <QObject>
  138.  #include <QWinThumbnailToolBar>
  139. +#include <QWinTaskbarButton>
  140.  
  141.  class QWindow;
  142.  
  143. @@ -41,5 +42,6 @@ private:
  144.      QWinThumbnailToolButton *onlineStatusBtn_;
  145.      QWinThumbnailToolButton *offlineStatusBtn_;
  146.      QWinThumbnailToolButton *eventsBtn_;
  147. +    QWinTaskbarButton *taskbarBtn_;
  148.  };
  149.  #endif // THUMBNAIL_TOOLBAR_H
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement