1/* Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
2 http://woboq.com/blog/property-bindings-in-cpp.html
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5associated documentation files (the "Software"), to deal in the Software without restriction,
6including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
7and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
8subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all copies or substantial
11portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
16OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18*/
19
20
21#include "property_qobject.h"
22
23#include <QtWidgets/QWidget>
24#include <QtCore/qcoreevent.h>
25
26namespace QtWrapper {
27
28template<class Base> struct Widget : Base {
29 template<typename... Args> Widget(Args &&...args) : Base(std::forward<Args>(args)...) {}
30 property_wrapper<QRect> geometry{
31 [this](const QRect &r){ this->setGeometry(r); },
32 [this]() { return this->Base::geometry(); } };
33
34private:
35 virtual bool event(QEvent* e) override {
36 switch(e->type()) {
37 case QEvent::Move:
38 case QEvent::Resize:
39 geometry.notify();
40 break;
41 default:
42 break;
43 }
44 return Base::event(e);
45 }
46};
47
48template<class Base> struct Label : Widget<Base> {
49 template<typename... Args> Label(Args &&...args) : Widget<Base>(std::forward<Args>(args)...) {}
50 property_qobject<QString> text{ this, "text" };
51};
52
53template<class Base> struct LineEdit : Widget<Base> {
54 template<typename... Args> LineEdit(Args &&...args) : Widget<Base>(std::forward<Args>(args)...) {}
55 property_qobject<QString> text{ this, "text" };
56};
57
58
59template<class Base> struct AbstractSlider : Widget<Base> {
60 template<typename... Args> AbstractSlider(Args &&...args) : Widget<Base>(std::forward<Args>(args)...) {}
61 property_qobject<int> minimum{ this, "minimum" };
62 property_qobject<int> maximum{ this, "maximum" };
63 property_qobject<int> value{ this, "value" };
64};
65
66}
67