Miam-Player  0.8.0
A nice music player
paintablewidget.h
Go to the documentation of this file.
1 #ifndef PAINTABLEWIDGET_H
2 #define PAINTABLEWIDGET_H
3 
4 #include <QApplication>
5 #include <QPainter>
6 #include <QWidget>
7 
8 #include "miamcore_global.h"
9 
16 class MIAMCORE_LIBRARY PaintableWidget : public QWidget
17 {
18  Q_OBJECT
19 private:
20  bool _left, _top, _right, _bottom, _halfTop;
21 
22 public:
23  explicit PaintableWidget(QWidget *parent)
24  : QWidget(parent)
25  , _left(false)
26  , _top(false)
27  , _right(false)
28  , _bottom(false)
29  , _halfTop(true)
30  {}
31 
32  inline void setFrameBorder(bool left, bool top, bool right, bool bottom)
33  {
34  _left = left;
35  _top = top;
36  _right = right;
37  _bottom = bottom;
38  }
39 
40  inline void setHalfTopBorder(bool b) { _halfTop = b; }
41 
42 protected:
43  virtual void paintEvent(QPaintEvent *) override
44  {
45  QPainter p(this);
46  p.setPen(Qt::NoPen);
47  p.setBrush(QApplication::palette().base());
48  p.drawRect(this->rect());
49  p.setPen(QApplication::palette().mid().color());
50  if ((_left && isLeftToRight()) || (_right && !isLeftToRight())) {
51  p.drawLine(rect().x(), rect().y(), rect().x(), rect().y() + rect().height());
52  }
53  if (_top) {
54  if (_halfTop) {
55  if (isLeftToRight()) {
56  p.drawLine(rect().center().x() + 1, rect().y(), rect().x() + rect().width(), rect().y());
57  } else {
58  p.drawLine(rect().x(), rect().y(), rect().center().x(), rect().y());
59  }
60  } else {
61  p.drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
62  }
63  }
64  if ((_right && isLeftToRight()) || (_left && !isLeftToRight())) {
65  p.drawLine(rect().x() + rect().width() - extra, rect().y(), rect().x() + rect().width() - extra, rect().y() + rect().height());
66  }
67  if (_bottom) {
68  p.drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());
69  }
70  }
71 };
72 
73 #endif // PAINTABLEWIDGET_H
PaintableWidget(QWidget *parent)
Definition: paintablewidget.h:23
The PaintableWidget class is a small class which can react to color change.
Definition: paintablewidget.h:16
int const extra
Definition: miamcore_global.h:18
virtual void paintEvent(QPaintEvent *) override
Definition: paintablewidget.h:43
void setHalfTopBorder(bool b)
Definition: paintablewidget.h:40
#define MIAMCORE_LIBRARY
Definition: miamcore_global.h:11
void setFrameBorder(bool left, bool top, bool right, bool bottom)
Definition: paintablewidget.h:32