TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkdesktopwrapper.cpp
Go to the documentation of this file.
1 #include "ttkdesktopwrapper.h"
2 #include "ttklibrary.h"
3 
4 #include <QScreen>
5 #include <QApplication>
6 #if !TTK_QT_VERSION_CHECK(5,0,0)
7 # include <QDesktopWidget>
8 #endif
9 
11 {
12  const QRect &sr = screenGeometry(index);
13  const QRect &dr = availableGeometry(index);
14 
15  TaskbarInfo info;
16  if(sr.left() != dr.left())
17  {
18  info.m_size = std::abs(sr.left() - dr.left());
20  }
21  else if(sr.right() != dr.right())
22  {
23  info.m_size = std::abs(sr.right() - dr.right());
25  }
26  else if(sr.top() != dr.top())
27  {
28  info.m_size = std::abs(sr.top() - dr.top());
30  }
31  else if(sr.bottom() != dr.bottom())
32  {
33  info.m_size = std::abs(sr.bottom() - dr.bottom());
35  }
36  else
37  {
38  info.m_size = 0;
40  }
41  return info;
42 }
43 
45 {
46 #if TTK_QT_VERSION_CHECK(5,0,0)
47  Q_UNUSED(index);
48  QScreen *screen = QApplication::primaryScreen();
49  return screen->availableGeometry();
50 #else
51  QDesktopWidget *widget = QApplication::desktop();
52  return widget->availableGeometry(index);
53 #endif
54 }
55 
57 {
58 #if TTK_QT_VERSION_CHECK(5,0,0)
59  const QList<QScreen*> &screens = QApplication::screens();
60  return (index < 0 || index >= screens.count()) ? QRect() : screens[index]->geometry();
61 #else
62  QDesktopWidget *widget = QApplication::desktop();
63  return widget->screenGeometry(index);
64 #endif
65 }
66 
68 {
69 #if TTK_QT_VERSION_CHECK(5,0,0)
70  const QList<QScreen*> &screens = QApplication::screens();
71  QRegion virtualGeometry;
72  for(QScreen *screen : screens)
73  {
74  virtualGeometry += screen->geometry();
75  }
76  return virtualGeometry.boundingRect();
77 #else
78  QDesktopWidget *widget = QApplication::desktop();
79  return widget->geometry();
80 #endif
81 }
82 
83 QPixmap TTKDesktopWrapper::grabWidget(QWidget *widget, const QRect &rect)
84 {
85 #if TTK_QT_VERSION_CHECK(5,0,0)
86  return widget->grab(rect);
87 #else
88  return QPixmap::grabWidget(widget, rect);
89 #endif
90 }
91 
92 QPixmap TTKDesktopWrapper::grabWindow(int x, int y, int w, int h)
93 {
94  QWidget widget(nullptr, Qt::Desktop);
95  widget.setVisible(false);
96  widget.setGeometry(geometry());
97 #if TTK_QT_VERSION_CHECK(5,0,0)
98  return QApplication::primaryScreen()->grabWindow(widget.winId(), x, y, w, h);
99 #else
100  return QPixmap::grabWindow(widget.winId(), x, y, w, h);
101 #endif
102 }
static QPixmap grabWidget(QWidget *widget, const QRect &rect)
static QRect geometry()
static QPixmap grabWindow(int x=0, int y=0, int w=-1, int h=-1)
static QRect availableGeometry(int index=0)
static QRect screenGeometry(int index=0)
static TaskbarInfo screenTaskbar(int index=0)