2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
#include "VBForm.h"
|
2019-06-07 11:48:27 +02:00
|
|
|
#include "VBPropertiesWindow.h"
|
2019-04-11 00:05:47 +02:00
|
|
|
#include "VBWidget.h"
|
2019-04-11 21:41:09 +02:00
|
|
|
#include "VBWidgetPropertyModel.h"
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/AboutDialog.h>
|
|
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2020-02-15 01:56:30 +01:00
|
|
|
#include <LibGUI/Menu.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/MenuBar.h>
|
|
|
|
|
#include <LibGUI/TableView.h>
|
|
|
|
|
#include <LibGUI/Widget.h>
|
|
|
|
|
#include <LibGUI/Window.h>
|
2019-04-11 00:05:47 +02:00
|
|
|
#include <fcntl.h>
|
2019-06-07 11:48:27 +02:00
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
2019-04-11 00:05:47 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
static RefPtr<GUI::Window> make_toolbox_window();
|
2019-04-11 21:41:09 +02:00
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2020-02-02 15:07:41 +01:00
|
|
|
GUI::Application app(argc, argv);
|
2019-04-11 00:05:47 +02:00
|
|
|
|
2019-09-21 20:04:00 +02:00
|
|
|
auto propbox = VBPropertiesWindow::construct();
|
2019-04-11 21:41:09 +02:00
|
|
|
|
2019-09-21 20:04:00 +02:00
|
|
|
auto form1 = VBForm::construct("Form1");
|
|
|
|
|
form1->on_widget_selected = [&](VBWidget* widget) {
|
2019-04-11 22:03:55 +02:00
|
|
|
propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
|
2019-04-11 21:41:09 +02:00
|
|
|
};
|
2019-04-11 00:05:47 +02:00
|
|
|
|
2020-04-21 16:01:00 +02:00
|
|
|
auto menubar = GUI::MenuBar::construct();
|
2020-04-04 12:18:40 +02:00
|
|
|
auto& app_menu = menubar->add_menu("Visual Builder");
|
|
|
|
|
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
2020-02-02 15:07:41 +01:00
|
|
|
GUI::Application::the().quit(0);
|
2019-04-11 00:05:47 +02:00
|
|
|
return;
|
|
|
|
|
}));
|
|
|
|
|
|
2020-04-04 12:18:40 +02:00
|
|
|
auto& file_menu = menubar->add_menu("File");
|
|
|
|
|
file_menu.add_action(GUI::Action::create("Dump Form", [&](auto&) {
|
2019-05-07 23:28:35 +02:00
|
|
|
form1->dump();
|
|
|
|
|
}));
|
2020-04-04 12:18:40 +02:00
|
|
|
file_menu.add_action(GUI::Action::create("Save Form...", { Mod_Ctrl, Key_S }, [&](auto&) {
|
2019-05-08 04:39:42 +02:00
|
|
|
form1->write_to_file("/tmp/form.frm");
|
|
|
|
|
}));
|
2019-04-11 00:05:47 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
auto window = GUI::Window::construct();
|
2019-04-11 03:34:37 +02:00
|
|
|
window->set_title(form1->name());
|
2019-04-11 04:01:17 +02:00
|
|
|
window->set_rect(120, 200, 640, 400);
|
2019-04-11 00:05:47 +02:00
|
|
|
window->set_main_widget(form1);
|
2019-07-23 18:20:00 +02:00
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
window->show();
|
|
|
|
|
|
2020-04-04 12:18:40 +02:00
|
|
|
auto& help_menu = menubar->add_menu("Help");
|
|
|
|
|
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
|
2020-02-06 13:39:17 +01:00
|
|
|
GUI::AboutDialog::show("Visual Builder", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-visual-builder.png"), window);
|
2019-09-17 20:16:14 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
app.set_menubar(move(menubar));
|
|
|
|
|
|
2019-09-21 18:34:06 +02:00
|
|
|
auto toolbox = make_toolbox_window();
|
2019-04-11 04:01:17 +02:00
|
|
|
toolbox->show();
|
|
|
|
|
|
2019-04-11 15:43:26 +02:00
|
|
|
propbox->show();
|
|
|
|
|
|
2019-06-29 12:06:46 +02:00
|
|
|
if (argc == 2) {
|
|
|
|
|
form1->load_from_file(argv[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
return app.exec();
|
|
|
|
|
}
|
2019-04-11 04:01:17 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
RefPtr<GUI::Window> make_toolbox_window()
|
2019-04-11 04:01:17 +02:00
|
|
|
{
|
2020-02-02 15:07:41 +01:00
|
|
|
auto window = GUI::Window::construct();
|
2019-04-11 04:01:17 +02:00
|
|
|
window->set_title("Widgets");
|
|
|
|
|
window->set_rect(20, 200, 80, 300);
|
|
|
|
|
|
2020-03-04 09:46:23 +01:00
|
|
|
auto& widget = window->set_main_widget<GUI::Widget>();
|
|
|
|
|
widget.set_fill_with_background_color(true);
|
|
|
|
|
widget.set_layout<GUI::VerticalBoxLayout>();
|
|
|
|
|
widget.layout()->set_spacing(0);
|
2019-04-11 04:13:11 +02:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& label_button = widget.add<GUI::Button>();
|
|
|
|
|
label_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
label_button.set_tooltip("GLabel");
|
|
|
|
|
label_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/label.png"));
|
|
|
|
|
label_button.on_click = [] {
|
2019-04-11 06:32:27 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GLabel);
|
2019-04-11 06:32:27 +02:00
|
|
|
};
|
|
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& button_button = widget.add<GUI::Button>();
|
|
|
|
|
button_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
button_button.set_tooltip("GButton");
|
|
|
|
|
button_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/button.png"));
|
|
|
|
|
button_button.on_click = [] {
|
2019-04-11 04:13:11 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GButton);
|
2019-04-11 04:13:11 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& spinbox_button = widget.add<GUI::Button>();
|
|
|
|
|
spinbox_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
spinbox_button.set_tooltip("GSpinBox");
|
|
|
|
|
spinbox_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/spinbox.png"));
|
|
|
|
|
spinbox_button.on_click = [] {
|
2019-04-11 04:13:11 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GSpinBox);
|
2019-04-11 04:13:11 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& editor_button = widget.add<GUI::Button>();
|
|
|
|
|
editor_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
editor_button.set_tooltip("GTextEditor");
|
|
|
|
|
editor_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/textbox.png"));
|
|
|
|
|
editor_button.on_click = [] {
|
2019-04-11 04:13:11 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GTextEditor);
|
2019-04-11 04:13:11 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& progress_bar_button = widget.add<GUI::Button>();
|
|
|
|
|
progress_bar_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
progress_bar_button.set_tooltip("GProgressBar");
|
|
|
|
|
progress_bar_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/progressbar.png"));
|
|
|
|
|
progress_bar_button.on_click = [] {
|
2019-04-11 06:08:06 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GProgressBar);
|
2019-04-11 06:08:06 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& slider_button = widget.add<GUI::Button>();
|
|
|
|
|
slider_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
slider_button.set_tooltip("GSlider");
|
|
|
|
|
slider_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/slider.png"));
|
|
|
|
|
slider_button.on_click = [] {
|
2019-04-30 16:18:05 +02:00
|
|
|
if (auto* form = VBForm::current())
|
|
|
|
|
form->insert_widget(VBWidgetType::GSlider);
|
|
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& checkbox_button = widget.add<GUI::Button>();
|
|
|
|
|
checkbox_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
checkbox_button.set_tooltip("GCheckBox");
|
|
|
|
|
checkbox_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/checkbox.png"));
|
|
|
|
|
checkbox_button.on_click = [] {
|
2019-04-11 06:32:27 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GCheckBox);
|
2019-04-11 06:32:27 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& radiobutton_button = widget.add<GUI::Button>();
|
|
|
|
|
radiobutton_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
radiobutton_button.set_tooltip("GRadioButton");
|
|
|
|
|
radiobutton_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/filled-radio-circle.png"));
|
|
|
|
|
radiobutton_button.on_click = [] {
|
2019-06-01 00:23:31 +02:00
|
|
|
if (auto* form = VBForm::current())
|
|
|
|
|
form->insert_widget(VBWidgetType::GRadioButton);
|
|
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& scrollbar_button = widget.add<GUI::Button>();
|
|
|
|
|
scrollbar_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
scrollbar_button.set_tooltip("GScrollBar");
|
|
|
|
|
scrollbar_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/scrollbar.png"));
|
|
|
|
|
scrollbar_button.on_click = [] {
|
2019-04-11 06:42:07 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GScrollBar);
|
2019-04-11 06:42:07 +02:00
|
|
|
};
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& groupbox_button = widget.add<GUI::Button>();
|
|
|
|
|
groupbox_button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
|
|
|
|
groupbox_button.set_tooltip("GGroupBox");
|
|
|
|
|
groupbox_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/groupbox.png"));
|
|
|
|
|
groupbox_button.on_click = [] {
|
2019-04-11 13:46:25 +02:00
|
|
|
if (auto* form = VBForm::current())
|
2019-04-11 16:13:19 +02:00
|
|
|
form->insert_widget(VBWidgetType::GGroupBox);
|
2019-04-11 13:46:25 +02:00
|
|
|
};
|
2019-04-11 04:01:17 +02:00
|
|
|
return window;
|
|
|
|
|
}
|