PIVX Core  5.6.99
P2P Digital Currency
pfborderimage.h
Go to the documentation of this file.
1 // Copyright (c) 2019 The PIVX Core 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 PIVX_QT_PFBORDERIMAGE_H
6 #define PIVX_QT_PFBORDERIMAGE_H
7 
8 #include <QPainter>
9 #include <QPixmap>
10 #include <QWidget>
11 #include <QFrame>
12 
13 class PFBorderImage : public QFrame
14 {
15  Q_OBJECT
16 
17 public:
18  explicit PFBorderImage(QWidget *parent = nullptr) : QFrame(parent) {};
20 
21 #if defined(Q_OS_MAC)
22 
23  void load(QString path) {
24  if (img.isNull() && !path.isNull()) img = QPixmap(path);
25  }
26 
27 protected:
28 
29  void paintEvent(QPaintEvent *event) override {
30  QSize currentSize = size();
31  if (cachedSize != currentSize && checkSize(currentSize)) {
32  cachedSize = currentSize;
33  scaledImg = img.scaled(cachedSize);
34  }
35  QPainter painter(this);
36  painter.drawPixmap(0, 0, scaledImg);
37  QWidget::paintEvent(event);
38  }
39 
40  bool checkSize(QSize currentSize) {
41  // Do not scale the image if the window change are imperceptible for the human's eye.
42  int pixelatedImageValue = 50;
43  return (currentSize.width() > cachedSize.width() + pixelatedImageValue) || (currentSize.width() < cachedSize.width() - pixelatedImageValue)
44  || (currentSize.height() > cachedSize.height() + pixelatedImageValue) || (currentSize.height() < cachedSize.height() - pixelatedImageValue);
45  }
46 
47  QPixmap img;
48  QPixmap scaledImg;
49  QSize cachedSize;
50 
51 #endif
52 
53 };
54 
55 #endif // PIVX_QT_PFBORDERIMAGE_H
PFBorderImage(QWidget *parent=nullptr)
Definition: pfborderimage.h:18