2018-11-18 01:15:38 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* checklist.cpp - Example for FListView widget with checkboxes *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2018-11-18 01:15:38 +01:00
|
|
|
* *
|
|
|
|
* 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 <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
2019-04-26 21:06:04 +02:00
|
|
|
namespace fc = finalcut::fc;
|
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:
|
2020-04-17 02:49:33 +02:00
|
|
|
// Using-declaration
|
|
|
|
using FDialog::setGeometry;
|
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
// 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-02-19 21:59:13 +01:00
|
|
|
~CheckList() override;
|
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();
|
|
|
|
|
|
|
|
// 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-04-13 12:40:11 +02:00
|
|
|
void cb_showList (const finalcut::FWidget*, const FDataPtr);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FListView listView{this};
|
|
|
|
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-04-19 20:38:52 +02:00
|
|
|
// Dialog settings
|
|
|
|
// Avoids calling a virtual function from the constructor
|
|
|
|
// (CERT, OOP50-CPP)
|
|
|
|
FDialog::setText (L"Shopping list");
|
2020-05-16 22:24:36 +02:00
|
|
|
const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0;
|
2020-05-02 00:07:35 +02:00
|
|
|
FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5}
|
|
|
|
, FSize{28 + nf_offset, 13} );
|
2020-04-19 20:38:52 +02:00
|
|
|
setShadow();
|
2018-11-18 01:15:38 +01:00
|
|
|
listView.ignorePadding();
|
2020-05-02 00:07:35 +02:00
|
|
|
listView.setGeometry ( FPoint{1 + int(nf_offset), 2}
|
|
|
|
, FSize{getWidth() - nf_offset, getHeight() - 1} );
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Add columns to the view
|
|
|
|
listView.addColumn ("Item");
|
2019-09-28 03:13:06 +02:00
|
|
|
listView.addColumn ("Priority", 9);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Set the type of sorting
|
2019-04-26 21:06:04 +02:00
|
|
|
listView.setColumnSortType (1, fc::by_name);
|
|
|
|
listView.setColumnSortType (2, fc::by_name);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
// Statusbar at the bottom
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FString separator{};
|
2019-04-26 21:06:04 +02:00
|
|
|
separator << ' ' << fc::BoxDrawingsVertical << ' ';
|
2020-05-02 00:07:35 +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
|
|
|
|
listView.addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, &CheckList::cb_showList)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
CheckList::~CheckList() // destructor
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::populate()
|
|
|
|
{
|
2019-01-05 22:58:06 +01:00
|
|
|
const std::string list[][2] =
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
|
|
|
{ "Milk", "Highest" },
|
|
|
|
{ "Cheese", "High" },
|
|
|
|
{ "Yoghurt", "Medium" },
|
|
|
|
{ "Bread", "Low" },
|
|
|
|
{ "Eggs", "High" },
|
|
|
|
{ "Toothpaste", "Medium" },
|
|
|
|
{ "Apples", "Lowest" },
|
|
|
|
{ "Bananas", "Medium" },
|
|
|
|
{ "Fish", "Medium" },
|
|
|
|
{ "Lemons", "Low" }
|
|
|
|
};
|
|
|
|
|
2019-10-14 01:44:24 +02:00
|
|
|
for (const auto& line : list)
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2019-10-14 01:44:24 +02:00
|
|
|
const finalcut::FStringList string_line (&line[0], &line[0] + 2);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::onKeyPress (finalcut::FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ev->key() == 'q'
|
2019-04-26 21:06:04 +02:00
|
|
|
|| ev->key() == fc::Fkey_escape
|
|
|
|
|| ev->key() == fc::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-04-13 12:40:11 +02:00
|
|
|
void CheckList::cb_showList (const finalcut::FWidget*, const FDataPtr)
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = listView.beginOfList();
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FString shopping_list{};
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
while ( iter != listView.endOfList() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
const auto item = static_cast<finalcut::FListViewItem*>(*iter);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
if ( item->isChecked() )
|
2019-04-26 21:06:04 +02:00
|
|
|
shopping_list << fc::Bullet << ' '
|
2018-11-20 21:11:04 +01:00
|
|
|
<< item->getText(1) << '\n';
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|