finalcut/examples/input-dialog.cpp

142 lines
4.9 KiB
C++

/***********************************************************************
* input-dialog.cpp - An input field example *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <final/final.h>
using finalcut::FPoint;
using finalcut::FSize;
// function prototypes
void cb_quit (finalcut::FWidget*, FDataPtr);
void cb_publish (finalcut::FWidget*, FDataPtr);
//----------------------------------------------------------------------
// callback functions
//----------------------------------------------------------------------
void cb_quit (finalcut::FWidget*, FDataPtr data)
{
auto app = static_cast<finalcut::FApplication*>(data);
app->quit();
}
void cb_publish (finalcut::FWidget* widget, FDataPtr data)
{
auto cbox1 = static_cast<finalcut::FCheckBox*>(widget);
auto cbox2 = static_cast<finalcut::FCheckBox*>(data);
if ( cbox1->isChecked() )
cbox2->setEnable();
else
{
cbox2->unsetChecked();
cbox2->setDisable();
}
cbox2->redraw();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
// Create the application object
finalcut::FApplication app(argc, argv);
// Create a simple dialog box
finalcut::FDialog dgl(&app);
dgl.setText ("Data input");
dgl.setGeometry (FPoint(4, 2), FSize(37, 22));
dgl.setShadow();
// Create input fields
finalcut::FLineEdit name_field (&dgl);
finalcut::FLineEdit email_field (&dgl);
finalcut::FLineEdit org_field (&dgl);
finalcut::FLineEdit city_field (&dgl);
finalcut::FLineEdit st_field (&dgl);
finalcut::FLineEdit c_field (&dgl);
name_field.setLabelText (L"&Name");
email_field.setLabelText (L"&Email");
org_field.setLabelText (L"Or&ganization");
city_field.setLabelText (L"&City");
st_field.setLabelText (L"&State");
c_field.setLabelText (L"&Country");
name_field.setGeometry (FPoint(15, 1), FSize(19, 1));
email_field.setGeometry (FPoint(15, 3), FSize(19, 1));
org_field.setGeometry (FPoint(15, 5), FSize(19, 1));
city_field.setGeometry (FPoint(15, 7), FSize(19, 1));
st_field.setGeometry (FPoint(15, 9), FSize(19, 1));
c_field.setGeometry (FPoint(15, 11), FSize(4, 1));
// Create the button group
finalcut::FButtonGroup radioButtonGroup ("Sex", &dgl);
radioButtonGroup.setGeometry(FPoint(2, 13), FSize(13, 4));
// Create radio buttons
finalcut::FRadioButton male ("&Male", &radioButtonGroup);
finalcut::FRadioButton female ("&Female", &radioButtonGroup);
male.setGeometry (FPoint(1, 1), FSize(8, 1));
female.setGeometry (FPoint(1, 2), FSize(10, 1));
// Create another button group
finalcut::FButtonGroup checkButtonGroup ("&Data options", &dgl);
checkButtonGroup.setGeometry(FPoint(16, 13), FSize(19, 4));
// Create checkbox buttons
finalcut::FCheckBox check1 ("Save data", &checkButtonGroup);
finalcut::FCheckBox check2 ("Encrypt data", &checkButtonGroup);
check1.setGeometry (FPoint(1, 1), FSize(13, 1));
check2.setGeometry (FPoint(1, 2), FSize(16, 1));
check2.setDisable();
// Create a OK button
finalcut::FButton btn("&OK", &dgl);
btn.setGeometry (FPoint(24, 18), FSize(10, 1));
// Connect checkbox signal "clicked" with a callback function
check1.addCallback
(
"clicked",
F_FUNCTION_CALLBACK (&cb_publish),
&check2
);
// Connect the button signal "clicked" with the callback function
btn.addCallback
(
"clicked",
F_FUNCTION_CALLBACK (&cb_quit),
&app
);
// Set dialog object as main widget
app.setMainWidget(&dgl);
// Show and start the application
dgl.show();
return app.exec();
}