finalcut/examples/busy.cpp

137 lines
4.1 KiB
C++
Raw Normal View History

2020-06-11 21:38:33 +02:00
/***********************************************************************
* busy.cpp - Shows the use of the FBusyIndicator *
* *
* This file is part of the FINAL CUT widget toolkit *
2020-06-11 21:38:33 +02:00
* *
* Copyright 2020-2021 Markus Gans *
2020-06-11 21:38:33 +02:00
* *
* 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 *
2020-06-11 21:38:33 +02:00
* the License, or (at your option) any later version. *
* *
* FINAL CUT is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
2020-06-11 21:38:33 +02:00
* 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::FRect;
using finalcut::FSize;
//----------------------------------------------------------------------
// class Dialog
//----------------------------------------------------------------------
class Dialog final : public finalcut::FDialog
{
public:
explicit Dialog (FWidget* parent = nullptr);
private:
void initLayout() override;
2020-06-11 21:38:33 +02:00
void adjustSize() override;
// Event handler
void onTimer (finalcut::FTimerEvent*) override;
// Callback method
2020-08-11 23:04:46 +02:00
void cb_start();
2020-06-11 21:38:33 +02:00
// Data members
finalcut::FSpinBox seconds{this};
finalcut::FButton start{"&Start", this};
finalcut::FButton quit{"&Quit", this};
finalcut::FBusyIndicator busy_indicator{this};
};
//----------------------------------------------------------------------
Dialog::Dialog (FWidget* parent)
: finalcut::FDialog{parent}
{
seconds.setLabelText ("Seconds");
seconds.setRange (0, 60);
seconds.setValue (3);
// Add button callbacks
seconds.addCallback
(
"activate",
2020-08-11 23:04:46 +02:00
this, &Dialog::cb_start
2020-06-11 21:38:33 +02:00
);
start.addCallback
(
"clicked",
2020-08-11 23:04:46 +02:00
this, &Dialog::cb_start
2020-06-11 21:38:33 +02:00
);
quit.addCallback
(
"clicked",
2020-08-11 23:04:46 +02:00
finalcut::getFApplication(),
&finalcut::FApplication::cb_exitApp,
this
2020-06-11 21:38:33 +02:00
);
}
//----------------------------------------------------------------------
void Dialog::initLayout()
{
FDialog::setText ("Dialog");
FDialog::setGeometry (FPoint{26, 5}, FSize{28, 10});
seconds.setGeometry (FPoint{10, 2}, FSize{10, 1});
start.setGeometry (FPoint{2, 6}, FSize{10, 1});
quit.setGeometry (FPoint{15, 6}, FSize{10, 1});
FDialog::initLayout();
}
//----------------------------------------------------------------------
2020-06-11 21:38:33 +02:00
void Dialog::adjustSize()
{
2020-06-11 23:00:18 +02:00
finalcut::FDialog::adjustSize();
2020-10-04 02:55:15 +02:00
auto x = int((getDesktopWidth() - getWidth()) / 2);
const int y = 5;
2020-06-11 21:38:33 +02:00
if ( x < 1 )
x = 1;
2020-06-11 21:38:33 +02:00
setPos (FPoint{x, y}, false);
2020-06-11 21:38:33 +02:00
}
//----------------------------------------------------------------------
void Dialog::onTimer (finalcut::FTimerEvent*)
{
2020-07-19 14:15:02 +02:00
delOwnTimers();
2020-06-11 21:38:33 +02:00
busy_indicator.stop();
}
//----------------------------------------------------------------------
2020-08-11 23:04:46 +02:00
void Dialog::cb_start()
2020-06-11 21:38:33 +02:00
{
if ( seconds.getValue() < 1 )
return;
busy_indicator.start();
2020-06-11 23:00:18 +02:00
addTimer(int(seconds.getValue() * 1000));
2020-06-11 21:38:33 +02:00
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
finalcut::FApplication app(argc, argv);
Dialog dialog(&app);
finalcut::FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}