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 *
|
|
|
|
* *
|
|
|
|
* Copyright 2017-2018 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 <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class CheckList
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class CheckList : public finalcut::FDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit CheckList (finalcut::FWidget* = nullptr);
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
CheckList (const CheckList&) = delete;
|
2018-11-18 01:15:38 +01:00
|
|
|
// Destructor
|
|
|
|
~CheckList();
|
|
|
|
|
|
|
|
// Disable 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
|
|
|
|
virtual void onKeyPress (finalcut::FKeyEvent*);
|
|
|
|
virtual void onClose (finalcut::FCloseEvent*);
|
|
|
|
|
|
|
|
// Callback method
|
|
|
|
void cb_showList (finalcut::FWidget*, data_ptr);
|
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
CheckList::CheckList (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FDialog(parent)
|
|
|
|
{
|
|
|
|
setText (L"Shopping list");
|
|
|
|
setShadow();
|
|
|
|
setGeometry (int(1 + (parent->getWidth() - 30) / 2), 5, 30, 13);
|
|
|
|
listView.ignorePadding();
|
|
|
|
listView.setGeometry (1, 2, getWidth(), getHeight() - 1);
|
|
|
|
|
|
|
|
// Add columns to the view
|
|
|
|
listView.addColumn ("Item");
|
|
|
|
listView.addColumn ("Priority", 12);
|
|
|
|
|
|
|
|
// Set the type of sorting
|
|
|
|
listView.setColumnSortType (1, finalcut::fc::by_name);
|
|
|
|
listView.setColumnSortType (2, finalcut::fc::by_name);
|
|
|
|
|
|
|
|
// Statusbar at the bottom
|
|
|
|
finalcut::FString separator;
|
2018-12-06 02:28:24 +01:00
|
|
|
separator << ' ' << finalcut::fc::BoxDrawingsVertical << ' ';
|
2018-11-18 01:15:38 +01:00
|
|
|
listView.setStatusbarMessage ( finalcut::FString()
|
|
|
|
<< "<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()
|
|
|
|
{
|
|
|
|
std::string list[][2] =
|
|
|
|
{
|
|
|
|
{ "Milk", "Highest" },
|
|
|
|
{ "Cheese", "High" },
|
|
|
|
{ "Yoghurt", "Medium" },
|
|
|
|
{ "Bread", "Low" },
|
|
|
|
{ "Eggs", "High" },
|
|
|
|
{ "Toothpaste", "Medium" },
|
|
|
|
{ "Apples", "Lowest" },
|
|
|
|
{ "Bananas", "Medium" },
|
|
|
|
{ "Fish", "Medium" },
|
|
|
|
{ "Lemons", "Low" }
|
|
|
|
};
|
|
|
|
|
|
|
|
const int lastItem = int(sizeof(list) / sizeof(list[0])) - 1;
|
|
|
|
|
|
|
|
for (int i = 0; i <= lastItem; i++)
|
|
|
|
{
|
|
|
|
const finalcut::FStringList line (&list[i][0], &list[i][0] + 2);
|
|
|
|
finalcut::FObject::FObjectIterator iter = listView.insert (line);
|
2018-11-20 21:11:04 +01:00
|
|
|
finalcut::FListViewItem* 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'
|
|
|
|
|| ev->key() == finalcut::fc::Fkey_escape
|
|
|
|
|| ev->key() == finalcut::fc::Fkey_escape_mintty )
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
finalcut::FDialog::onKeyPress(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::onClose (finalcut::FCloseEvent* ev)
|
|
|
|
{
|
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CheckList::cb_showList (finalcut::FWidget*, data_ptr)
|
|
|
|
{
|
|
|
|
finalcut::FListViewIterator iter = listView.beginOfList();
|
|
|
|
finalcut::FString shopping_list;
|
|
|
|
|
|
|
|
while ( iter != listView.endOfList() )
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
const finalcut::FListViewItem* item = \
|
|
|
|
static_cast<finalcut::FListViewItem*>(*iter);
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
if ( item->isChecked() )
|
2018-12-06 02:28:24 +01:00
|
|
|
shopping_list << finalcut::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
|
|
|
|
app.setMainWidget(&d);
|
|
|
|
|
|
|
|
// Show and start the application
|
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|