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 *
|
|
|
|
* *
|
2019-01-05 22:58:06 +01:00
|
|
|
* Copyright 2017-2019 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;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class CheckList
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CheckList : public finalcut::FDialog
|
|
|
|
{
|
|
|
|
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
|
|
|
|
~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
|
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
|
2018-12-27 00:14:46 +01:00
|
|
|
void cb_showList (finalcut::FWidget*, 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)
|
|
|
|
: finalcut::FDialog(parent)
|
|
|
|
{
|
|
|
|
setText (L"Shopping list");
|
|
|
|
setShadow();
|
2019-09-28 03:13:06 +02:00
|
|
|
setGeometry ( FPoint(int(1 + (parent->getWidth() - 28) / 2), 5)
|
|
|
|
, FSize(28, 13) );
|
2018-11-18 01:15:38 +01:00
|
|
|
listView.ignorePadding();
|
2019-01-21 03:42:18 +01:00
|
|
|
listView.setGeometry (FPoint(1, 2), FSize(getWidth(), 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
|
|
|
|
finalcut::FString separator;
|
2019-04-26 21:06:04 +02:00
|
|
|
separator << ' ' << 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()
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void CheckList::cb_showList (finalcut::FWidget*, FDataPtr)
|
2018-11-18 01:15:38 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = listView.beginOfList();
|
2018-11-18 01:15:38 +01:00
|
|
|
finalcut::FString shopping_list;
|
|
|
|
|
|
|
|
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
|
|
|
|
app.setMainWidget(&d);
|
|
|
|
|
|
|
|
// Show and start the application
|
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|