2018-11-18 01:15:38 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* checklist.cpp - Example for FListView widget with checkboxes *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2018-11-18 01:15:38 +01:00
|
|
|
* *
|
2021-02-09 22:01:21 +01:00
|
|
|
* Copyright 2017-2021 Markus Gans *
|
2018-11-18 01:15:38 +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 *
|
2018-11-18 01:15:38 +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 *
|
2018-11-18 01:15:38 +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/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
2020-10-08 16:46:14 +02:00
|
|
|
#include <array>
|
2018-11-18 01:15:38 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
2020-04-17 02:49:33 +02:00
|
|
|
using finalcut::FRect;
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FSize;
|
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class CheckList
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class CheckList final : public finalcut::FDialog
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit CheckList (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
CheckList (const CheckList&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~CheckList() override = default;
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
CheckList& operator = (const CheckList&) = delete;
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2018-11-18 01:15:38 +01:00
|
|
|
// Method
|
|
|
|
void populate();
|
2021-03-28 23:19:01 +02:00
|
|
|
void initLayout() override;
|
2020-10-04 00:59:21 +02:00
|
|
|
void adjustSize() override;
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onKeyPress (finalcut::FKeyEvent*) override;
|
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Callback method
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_showList();
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-09-25 00:48:58 +02:00
|
|
|
finalcut::FListView listview{this};
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FStatusBar status_bar{this};
|
2018-11-18 01:15:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
CheckList::CheckList (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2020-10-05 04:24:14 +02:00
|
|
|
setShadow(); // Instead of the transparent window shadow
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.ignorePadding();
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Add columns to the view
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.addColumn ("Item");
|
|
|
|
listview.addColumn ("Priority", 9);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Set the type of sorting
|
2020-12-31 20:45:10 +01:00
|
|
|
listview.setColumnSortType (1, finalcut::SortType::Name);
|
|
|
|
listview.setColumnSortType (2, finalcut::SortType::Name);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Statusbar at the bottom
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FString separator{};
|
2020-12-31 20:45:10 +01:00
|
|
|
separator << ' ' << finalcut::UniChar::BoxDrawingsVertical << ' ';
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.setStatusbarMessage ( finalcut::FString{}
|
2018-11-18 01:15:38 +01:00
|
|
|
<< "<Q> exit" << separator
|
|
|
|
<< "<Space> select an item" << separator
|
|
|
|
<< "<Enter> see your pick list");
|
|
|
|
|
|
|
|
// Populate FListView with a list of items
|
|
|
|
populate();
|
|
|
|
|
|
|
|
// Add callback method
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.addCallback
|
2018-11-18 01:15:38 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &CheckList::cb_showList
|
2018-11-18 01:15:38 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::populate()
|
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
constexpr std::array<std::array<const char*, 2>, 10> list =
|
|
|
|
{{
|
|
|
|
{{ "Milk", "Highest" }},
|
|
|
|
{{ "Cheese", "High" }},
|
|
|
|
{{ "Yoghurt", "Medium" }},
|
|
|
|
{{ "Bread", "Low" }},
|
|
|
|
{{ "Eggs", "High" }},
|
|
|
|
{{ "Toothpaste", "Medium" }},
|
|
|
|
{{ "Apples", "Lowest" }},
|
|
|
|
{{ "Bananas", "Medium" }},
|
|
|
|
{{ "Fish", "Medium" }},
|
|
|
|
{{ "Lemons", "Low" }}
|
|
|
|
}};
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2019-10-14 01:44:24 +02:00
|
|
|
for (const auto& line : list)
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
const finalcut::FStringList string_line (line.begin(), line.end());
|
2020-09-25 00:48:58 +02:00
|
|
|
auto iter = listview.insert (string_line);
|
2018-12-15 00:50:09 +01:00
|
|
|
auto item = static_cast<finalcut::FListViewItem*>(*iter);
|
2018-11-18 01:15:38 +01:00
|
|
|
item->setCheckable(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-28 23:19:01 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::initLayout()
|
|
|
|
{
|
|
|
|
FDialog::setText (L"Shopping list");
|
|
|
|
const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0;
|
|
|
|
FDialog::setSize (FSize{28 + nf_offset, 13} );
|
|
|
|
listview.setGeometry ( FPoint{1 + int(nf_offset), 2}
|
|
|
|
, FSize{getWidth() - nf_offset, getHeight() - 1} );
|
|
|
|
FDialog::initLayout();
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:59:21 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::adjustSize()
|
|
|
|
{
|
|
|
|
finalcut::FDialog::adjustSize();
|
|
|
|
setPos(FPoint{int(1 + (getDesktopWidth() - getWidth()) / 2), 5});
|
|
|
|
}
|
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::onKeyPress (finalcut::FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->key() == finalcut::FKey('q')
|
|
|
|
|| ev->key() == finalcut::FKey::Escape
|
|
|
|
|| ev->key() == finalcut::FKey::Escape_mintty )
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
finalcut::FDialog::onKeyPress(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::onClose (finalcut::FCloseEvent* ev)
|
|
|
|
{
|
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void CheckList::cb_showList()
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FString shopping_list{};
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2020-10-08 05:55:32 +02:00
|
|
|
for (auto item : listview.getData())
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
|
|
|
if ( item->isChecked() )
|
2020-12-31 20:45:10 +01:00
|
|
|
shopping_list << finalcut::UniChar::Bullet << ' ' << item->getText(1) << '\n';
|
2018-11-18 01:15:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( shopping_list.isEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create and show tooltip for two seconds
|
|
|
|
finalcut::FToolTip picklist(this);
|
|
|
|
picklist.setText (shopping_list);
|
|
|
|
picklist.show();
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Create the application object
|
|
|
|
finalcut::FApplication app(argc, argv);
|
|
|
|
|
|
|
|
// Create main dialog object
|
|
|
|
CheckList d(&app);
|
|
|
|
|
|
|
|
// Set dialog d as main widget
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget(&d);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Show and start the application
|
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|