1 /**
2 * File name: painter.cpp
3 * Project: Redkite (A small GUI toolkit)
4 *
5 * Copyright (C) 2019 Iurie Nistor <http://quamplex.com>
6 *
7 * This file is part of Redkite.
8 *
9 * Redkite is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "RkMain.h"
25 #include "RkWidget.h"
26 #include "RkLog.h"
27 #include "RkLineEdit.h"
28
29 class Button: public RkWidget {
30 public:
Button(RkWidget * parent)31 Button(RkWidget *parent)
32 : RkWidget(parent)
33 , isToggled{false} {}
34
35 RK_DECL_ACT(toggled, toggled(bool b), RK_ARG_TYPE(bool), RK_ARG_VAL(b));
36
37 protected:
mouseButtonPressEvent(RkMouseEvent * event)38 void mouseButtonPressEvent(RkMouseEvent *event) final
39 {
40 isToggled = !isToggled;
41 action toggled(isToggled);
42 }
43
44 private:
45 bool isToggled;
46 };
47
48 class LineEditExample: public RkWidget {
49 public:
LineEditExample(RkMain * app)50 LineEditExample(RkMain *app)
51 : RkWidget(app)
52 {
53 setSize(350, 350);
54 RK_LOG_DEBUG("------ 1");
55 auto lineEdit = new RkLineEdit(this);
56 auto font = lineEdit->font();
57 font.setSize(30);
58 lineEdit->setFont(font);
59 lineEdit->setSize(300, 50);
60 lineEdit->setPosition((width() - lineEdit->width()) / 2,
61 (height() - lineEdit->height()) / 2);
62 lineEdit->setTitle("RkLineEdit1");
63 lineEdit->setBorderWidth(1);
64 lineEdit->setBorderColor(80, 80, 80);
65 RK_ACT_BIND(lineEdit,
66 textEdited,
67 RK_ACT_ARGS(const std::string &text),
68 this, onUpdateText(text));
69 lineEdit->show();
70 RK_LOG_DEBUG("------ 2");
71 lineEdit = new RkLineEdit(this);
72 font = lineEdit->font();
73 font.setSize(30);
74 lineEdit->setFont(font);
75 lineEdit->setSize(300, 50);
76 lineEdit->setPosition((width() - lineEdit->width()) / 2,
77 (height() - lineEdit->height()) / 2 + 10 + lineEdit->height());
78 lineEdit->setTitle("RkLineEdit2");
79 lineEdit->setBorderWidth(1);
80 lineEdit->setBorderColor(80, 80, 80);
81 RK_ACT_BIND(lineEdit,
82 textEdited,
83 RK_ACT_ARGS(const std::string &text),
84 this, onUpdateText(text));
85 show();
86 lineEdit->show();
87 RK_LOG_DEBUG("------ 3");
88 auto button = new Button(this);
89 button->setBackgroundColor(100, 200, 100);
90 button->setFixedSize(50, 25);
91 button->show();
92 RK_ACT_BIND(button,
93 toggled,
94 RK_ACT_ARGS(bool toggled),
95 this, openDialog());
96 }
97
98 protected:
keyPressEvent(RkKeyEvent * event)99 void keyPressEvent(RkKeyEvent *event)
100 {
101 }
mouseMoveEvent(RkMouseEvent * event)102 void mouseMoveEvent(RkMouseEvent *event)
103 {
104 }
onUpdateText(const std::string & text)105 void onUpdateText(const std::string &text)
106 {
107 }
108
openDialog()109 void openDialog()
110 {
111 auto dialog = new RkWidget(this, Rk::WindowFlags::Dialog);
112 dialog->setSize(50, 50);
113 dialog->show();
114 }
115 };
116
main(int arc,char ** argv)117 int main(int arc, char **argv)
118 {
119 RkMain app(arc, argv);
120
121 auto widget = new LineEditExample(&app);
122 widget->setTitle("Line Edit Example");
123 return app.exec();
124 }
125