2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* listbox.cpp - Example for using a FListBox widget *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-19 21:59:13 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +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 *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01: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/>. *
|
|
|
|
***********************************************************************/
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2019-08-06 23:45:28 +02:00
|
|
|
#include <memory>
|
2017-04-23 18:54:46 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-05-19 22:16:50 +02:00
|
|
|
|
2018-12-26 23:41:49 +01:00
|
|
|
using namespace finalcut;
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// Global application object
|
2018-12-29 19:01:47 +01:00
|
|
|
static std::weak_ptr<FString> temp_str;
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// Function prototypes
|
2018-12-26 23:41:49 +01:00
|
|
|
void doubleToItem ( FListBoxItem&
|
2020-09-18 17:13:52 +02:00
|
|
|
, FDataAccess* container
|
|
|
|
, std::size_t index);
|
2018-12-26 23:41:49 +01:00
|
|
|
FString& doubleToString (std::list<double>::const_iterator iter);
|
|
|
|
FString& mapToString ( std::map<FString
|
|
|
|
, FString>::const_iterator iter );
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
// Lazy conversion insert function
|
2018-12-26 23:41:49 +01:00
|
|
|
void doubleToItem ( FListBoxItem& item
|
2020-09-18 17:13:52 +02:00
|
|
|
, FDataAccess* container
|
|
|
|
, std::size_t index )
|
2017-05-19 22:16:50 +02:00
|
|
|
{
|
2020-09-18 17:13:52 +02:00
|
|
|
typedef std::list<double> DblList;
|
2020-09-18 22:40:51 +02:00
|
|
|
DblList& dbl_list = flistboxhelper::getContainer<DblList>(container);
|
2020-09-18 17:13:52 +02:00
|
|
|
std::list<double>::iterator iter = dbl_list.begin();
|
2017-05-19 22:16:50 +02:00
|
|
|
std::advance (iter, index);
|
2018-12-26 23:41:49 +01:00
|
|
|
item.setText (FString() << *iter);
|
2020-09-18 17:13:52 +02:00
|
|
|
item.setData (*iter);
|
2017-05-19 22:16:50 +02:00
|
|
|
}
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
// Insert converter functions
|
2018-12-26 23:41:49 +01:00
|
|
|
FString& doubleToString (std::list<double>::const_iterator iter)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-12-29 19:01:47 +01:00
|
|
|
auto temp = temp_str.lock();
|
|
|
|
return temp->setNumber(*iter);
|
2017-04-23 18:54:46 +02:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:41:49 +01:00
|
|
|
FString& mapToString ( std::map<FString
|
2019-12-16 11:14:24 +01:00
|
|
|
, FString>::const_iterator iter )
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-12-29 19:01:47 +01:00
|
|
|
auto temp = temp_str.lock();
|
|
|
|
return *temp = iter->first + ": " + iter->second;
|
2017-04-23 18:54:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Listbox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Listbox final : public FDialog
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Listbox (FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Listbox (const Listbox&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~Listbox() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
Listbox& operator = (const Listbox&) = delete;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onClose (FCloseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data member
|
2018-12-03 03:22:36 +01:00
|
|
|
std::list<double> double_list{};
|
2018-12-26 23:41:49 +01:00
|
|
|
FListBox list1{this};
|
|
|
|
FListBox list2{this};
|
|
|
|
FListBox list3{this};
|
2020-09-25 00:48:58 +02:00
|
|
|
FButton quit{this};
|
2017-04-23 18:54:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-26 23:41:49 +01:00
|
|
|
Listbox::Listbox (FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FDialog{parent}
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-12-29 19:01:47 +01:00
|
|
|
auto temp = std::make_shared<FString>();
|
|
|
|
temp_str = temp;
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 1
|
2018-10-03 22:23:55 +02:00
|
|
|
//----------
|
2020-05-02 00:07:35 +02:00
|
|
|
list1.setGeometry(FPoint{2, 1}, FSize{18, 10});
|
2018-10-03 22:23:55 +02:00
|
|
|
list1.setText ("FListBoxItem");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int i{1}; i < 30; i++)
|
2020-05-02 00:07:35 +02:00
|
|
|
list1.insert (L"----- " + (FString{} << i) + L" -----");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 2
|
2018-10-03 22:23:55 +02:00
|
|
|
//----------
|
2020-04-13 12:40:11 +02:00
|
|
|
for (int i{1}; i <= 15; i++)
|
|
|
|
double_list.push_back(2 * double(i) + (double(i) / 100));
|
2017-05-19 22:47:13 +02:00
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
list2.setGeometry(FPoint{21, 1}, FSize{10, 10});
|
2018-10-03 22:23:55 +02:00
|
|
|
list2.setText ("double");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
2019-10-05 23:20:07 +02:00
|
|
|
// Insert via lazy conversion on print
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
2020-09-18 17:13:52 +02:00
|
|
|
list2.insert (double_list, doubleToItem); // (container, converter)
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
2019-10-05 23:20:07 +02:00
|
|
|
// Direct insert of the complete list
|
2017-05-19 22:16:50 +02:00
|
|
|
//
|
2018-10-03 22:23:55 +02:00
|
|
|
//list2.insert (double_list.begin(), double_list.end(), doubleToString);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// listbox 3
|
2018-10-03 22:23:55 +02:00
|
|
|
//----------
|
2018-12-26 23:41:49 +01:00
|
|
|
std::map<FString, FString> TLD;
|
2017-04-23 18:54:46 +02:00
|
|
|
TLD["com"] = "Commercial";
|
|
|
|
TLD["org"] = "Organization";
|
|
|
|
TLD["net"] = "Network";
|
|
|
|
TLD["edu"] = "Education";
|
|
|
|
TLD["gov"] = "Government";
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
list3.insert (TLD.begin(), TLD.end(), mapToString);
|
2020-05-02 00:07:35 +02:00
|
|
|
list3.setGeometry(FPoint{32, 1}, FSize{21, 10});
|
2018-10-03 22:23:55 +02:00
|
|
|
list3.setText ("key: value");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
// Quit button
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.setGeometry(FPoint{42, 12}, FSize{10, 1});
|
|
|
|
quit.setText (L"&Quit");
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-08-01 00:56:12 +02:00
|
|
|
// Add quit button function callback
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.addCallback
|
2017-04-23 18:54:46 +02:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
finalcut::getFApplication(),
|
|
|
|
&finalcut::FApplication::cb_exitApp,
|
|
|
|
this
|
2017-04-23 18:54:46 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
Listbox::~Listbox() // destructor
|
2018-12-19 22:04:02 +01:00
|
|
|
{ }
|
2017-04-23 18:54:46 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-26 23:41:49 +01:00
|
|
|
void Listbox::onClose (FCloseEvent* ev)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
FApplication::closeConfirmationDialog (this, ev);
|
2017-04-23 18:54:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2018-12-26 23:41:49 +01:00
|
|
|
FApplication app(argc, argv);
|
2017-04-23 18:54:46 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2017-04-23 18:54:46 +02:00
|
|
|
Listbox d(&app);
|
|
|
|
d.setText (L"Listbox");
|
2020-05-02 00:07:35 +02:00
|
|
|
d.setGeometry ( FPoint{int(1 + (app.getWidth() - 56) / 2), 5}
|
|
|
|
, FSize{56, 16} );
|
2017-04-23 18:54:46 +02:00
|
|
|
d.setShadow();
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog d as main widget
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget(&d);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2017-04-23 18:54:46 +02:00
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|