QtPdWidgets  2.3.1
Text.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009 - 2013 Florian Pose <fp@igh-essen.com>
4  *
5  * This file is part of the QtPdWidgets library.
6  *
7  * The QtPdWidgets library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of the License,
10  * or (at your option) any later version.
11  *
12  * The QtPdWidgets library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the QtPdWidgets Library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  ****************************************************************************/
22 
23 #ifndef PD_TEXT_H
24 #define PD_TEXT_H
25 
26 #include <QFrame>
27 #include <QHash>
28 #include <QTimer>
29 
30 #include "Export.h"
31 #include <QtPdCom1/ScalarSubscriber.h>
32 #include <QtPdCom1/ScalarVariable.h>
33 
34 namespace Pd {
35 
36 class Text;
37 
38 /****************************************************************************/
39 
43  public QtPdCom::BoolVariable
44 {
45  Q_OBJECT
46 
47  public:
49  ~TextCondition();
50 
51  QString getText() const;
52  void setText(const QString &);
53 
54  bool getInvert() const;
55  void setInvert(bool);
56 
57  private:
58  struct PD_PRIVATE Impl;
59  std::unique_ptr<Impl> impl;
60 };
61 
62 /****************************************************************************/
63 
69  public QFrame, public QtPdCom::ScalarSubscriber
70 {
71  Q_OBJECT
72 
73  friend class TextCondition;
74 
75  Q_PROPERTY(Qt::Alignment alignment
76  READ getAlignment WRITE setAlignment RESET resetAlignment)
77  Q_PROPERTY(QString prefix
78  READ getPrefix WRITE setPrefix RESET resetPrefix)
79  Q_PROPERTY(QString suffix
80  READ getSuffix WRITE setSuffix RESET resetSuffix)
81  Q_PROPERTY(bool conditionActive READ getConditionActive)
82 
83  public:
84  Text(QWidget *parent = 0);
85  virtual ~Text();
86 
87  Qt::Alignment getAlignment() const;
88  void setAlignment(Qt::Alignment);
89  void resetAlignment();
90 
91  QString getPrefix() const;
92  void setPrefix(const QString &);
93  void resetPrefix();
94 
95  QString getSuffix() const;
96  void setSuffix(const QString &);
97  void resetSuffix();
98 
99  void clearData(); // pure-virtual from ScalarSubscriber
100 
101  int getValue() const;
102  void setValue(int);
103 
109  struct Value {
110  QString text;
111  QColor color;
112  QFont font;
115  const QString &t = QString(),
116  QColor c = QColor(),
117  const QFont &f = QFont()
118  ):
119  text(t), color(c), font(f) {}
120  };
121 
127  class Q_DECL_EXPORT Hash: public QHash<int, Value> {
128  public:
129  void insert(
130  int position,
131  const QString &t = QString(),
132  QColor c = QColor(),
133  const QFont &f = QFont());
134  };
135  void setHash(const Hash *);
136 
137  void updateValueText();
138 
139  TextCondition *addCondition(PdCom::Variable,
140  const QString & = QString(), bool = false);
141  TextCondition *addCondition(PdCom::Process *, const QString &,
142  const QString & = QString(), bool = false);
143  void clearConditions();
144 
145  bool getConditionActive() const;
146 
147  protected:
148  bool event(QEvent *) override;
149  void paintEvent(QPaintEvent *) override;
150 
151  private:
152  struct PD_PRIVATE Impl;
153  std::unique_ptr<Impl> impl;
154 
155  PD_PRIVATE void newValues(std::chrono::nanoseconds) override;
156 
157  private slots:
158  PD_PRIVATE void conditionChanged();
159  PD_PRIVATE void conditionTimeout();
160 };
161 
162 /****************************************************************************/
163 
164 } // namespace
165 
166 #endif
QFont font
Font to use.
Definition: Text.h:112
Definition: Bar.h:36
Value(const QString &t=QString(), QColor c=QColor(), const QFont &f=QFont())
Definition: Text.h:114
#define PD_PRIVATE
Definition: Export.h:28
QString text
Displayed text.
Definition: Text.h:110
Value type.
Definition: Text.h:109
Text display widget.
Definition: Text.h:68
Definition: Text.cpp:34
#define PD_PUBLIC
Definition: Export.h:33
Definition: Text.cpp:102
QColor color
Text color.
Definition: Text.h:111
std::unique_ptr< Impl > impl
Definition: Text.h:153
Value hash type.
Definition: Text.h:127
std::unique_ptr< Impl > impl
Definition: Text.h:59
Condition type.
Definition: Text.h:42