Ajout de getindex, setindex & setmark pour le Listview

This commit is contained in:
Nicolas H 2021-07-06 17:26:44 +00:00
parent cf37e826e9
commit ea7f53be41
4 changed files with 105 additions and 21 deletions

View File

@ -25,7 +25,6 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <final/final.h> #include <final/final.h>
using finalcut::FPoint; using finalcut::FPoint;
@ -61,10 +60,16 @@ class Listview final : public finalcut::FDialog
// Callback method // Callback method
void cb_showInMessagebox(); void cb_showInMessagebox();
void cb_showIndexInMessagebox();
void cb_doit();
void cb_doit2();
// Data members // Data members
finalcut::FListView listview{this}; finalcut::FListView listview{this};
finalcut::FButton quit{this}; finalcut::FButton quit{this};
finalcut::FButton Mark{this};
finalcut::FButton Index{this};
finalcut::FButton GIndex{this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -100,10 +105,11 @@ Listview::Listview (finalcut::FWidget* parent)
// Populate FListView with a list of items // Populate FListView with a list of items
populate(); populate();
// Quit button // Quit button
quit.setText (L"&Quit"); quit.setText (L"&Quit");
Mark.setText("&Mark");
Index.setText("&Getindex");
GIndex.setText("&Index");
// Add some function callbacks // Add some function callbacks
quit.addCallback quit.addCallback
( (
@ -118,6 +124,24 @@ Listview::Listview (finalcut::FWidget* parent)
"clicked", "clicked",
this, &Listview::cb_showInMessagebox this, &Listview::cb_showInMessagebox
); );
Mark.addCallback
(
"clicked",
this, &Listview::cb_doit
);
Index.addCallback
(
"clicked",
this, &Listview::cb_showIndexInMessagebox
);
GIndex.addCallback
(
"clicked",
this, &Listview::cb_doit2
);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -181,7 +205,10 @@ void Listview::initLayout()
// Set FListView geometry // Set FListView geometry
listview.setGeometry(FPoint{2, 1}, FSize{33, 14}); listview.setGeometry(FPoint{2, 1}, FSize{33, 14});
// Set quit button geometry // Set quit button geometry
quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); quit.setGeometry(FPoint{30, 16}, FSize{10, 1});
Index.setGeometry(FPoint{13, 16}, FSize{10, 1});
Mark.setGeometry(FPoint{1, 15}, FSize{10, 1});
GIndex.setGeometry(FPoint{1, 17}, FSize{10, 1});
FDialog::initLayout(); FDialog::initLayout();
} }
@ -191,6 +218,16 @@ void Listview::onClose (finalcut::FCloseEvent* ev)
finalcut::FApplication::closeConfirmationDialog (this, ev); finalcut::FApplication::closeConfirmationDialog (this, ev);
} }
//----------------------------------------------------------------------
void Listview::cb_doit()
{
listview.setmark(listview.getindex());
}
//----------------------------------------------------------------------
void Listview::cb_doit2()
{
listview.setindex(17);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Listview::cb_showInMessagebox() void Listview::cb_showInMessagebox()
{ {
@ -206,7 +243,18 @@ void Listview::cb_showInMessagebox()
, this ); , this );
info.show(); info.show();
} }
//----------------------------------------------------------------------
void Listview::cb_showIndexInMessagebox()
{
finalcut::FString index;
index.setNumber(listview.getindex());
finalcut::FMessageBox info ( "Test","The Index is :"+index
, finalcut::FMessageBox::ButtonType::Ok
, finalcut::FMessageBox::ButtonType::Reject
, finalcut::FMessageBox::ButtonType::Reject
, this );
info.show();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part

View File

@ -910,6 +910,7 @@ void FListView::clear()
{ {
itemlist.clear(); itemlist.clear();
current_iter = getNullIterator(); current_iter = getNullIterator();
mark_iter = getNullIterator();
first_visible_line = getNullIterator(); first_visible_line = getNullIterator();
last_visible_line = getNullIterator(); last_visible_line = getNullIterator();
recalculateVerticalBar (0); recalculateVerticalBar (0);
@ -1427,6 +1428,37 @@ inline void FListView::mapKeyFunctions()
key_map_result[FKey('-')] = [this] { return collapseSubtree(); }; key_map_result[FKey('-')] = [this] { return collapseSubtree(); };
} }
//----------------------------------------------------------------------
void FListView::setindex(int index)
{
if (index==-666)
current_iter=getNullIterator();
else
{
current_iter=itemlist.begin();
current_iter+=index;
scrollToY(index);
}
draw();
}
//----------------------------------------------------------------------
void FListView::setmark(int index)
{
if (index==-666)
current_iter=getNullIterator();
else
{
mark_iter=itemlist.begin();
mark_iter+=index;
scrollToY(index);
}
draw();
}
//----------------------------------------------------------------------
int FListView::getindex()
{
return current_iter.getPosition();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::processKeyAction (FKeyEvent* ev) void FListView::processKeyAction (FKeyEvent* ev)
{ {
@ -1608,6 +1640,8 @@ void FListView::drawList()
while ( iter != path_end && iter != itemlist_end && y < page_height ) while ( iter != path_end && iter != itemlist_end && y < page_height )
{ {
const bool is_current_line( iter == current_iter ); const bool is_current_line( iter == current_iter );
const bool is_current_mark( iter == mark_iter );
const bool is_current_selected=false;
const auto& item = static_cast<FListViewItem*>(*iter); const auto& item = static_cast<FListViewItem*>(*iter);
const int tree_offset = tree_view ? int(item->getDepth() << 1) + 1 : 0; const int tree_offset = tree_view ? int(item->getDepth() << 1) + 1 : 0;
const int checkbox_offset = item->isCheckable() ? 1 : 0; const int checkbox_offset = item->isCheckable() ? 1 : 0;
@ -1615,7 +1649,7 @@ void FListView::drawList()
print() << FPoint{2, 2 + int(y)}; print() << FPoint{2, 2 + int(y)};
// Draw one FListViewItem // Draw one FListViewItem
drawListLine (item, getFlags().focus, is_current_line); drawListLine (item, getFlags().focus, is_current_line, is_current_mark, is_current_selected);
if ( getFlags().focus && is_current_line ) if ( getFlags().focus && is_current_line )
{ {
@ -1651,10 +1685,10 @@ void FListView::drawList()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::drawListLine ( const FListViewItem* item void FListView::drawListLine ( const FListViewItem* item
, bool is_focus , bool is_focus
, bool is_current ) , bool is_current, bool is_mark, bool is_selected )
{ {
// Set line color and attributes // Set line color and attributes
setLineAttributes (is_current, is_focus); setLineAttributes (is_current, is_focus, is_mark, is_selected);
// Print the entry // Print the entry
const std::size_t indent = item->getDepth() << 1; // indent = 2 * depth const std::size_t indent = item->getDepth() << 1; // indent = 2 * depth
@ -1758,7 +1792,7 @@ void FListView::clearList()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::setLineAttributes ( bool is_current inline void FListView::setLineAttributes ( bool is_current
, bool is_focus ) const , bool is_focus, bool is_mark, bool is_selected ) const
{ {
const auto& wc = getColorTheme(); const auto& wc = getColorTheme();
setColor (wc->list_fg, wc->list_bg); setColor (wc->list_fg, wc->list_bg);
@ -1790,6 +1824,10 @@ inline void FListView::setLineAttributes ( bool is_current
else if ( is_focus && FTerm::getMaxColor() < 16 ) else if ( is_focus && FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
} }
if ( is_selected )
setColor ( FColor::White , FColor::Black );
if ( is_mark )
setColor ( FColor::White, FColor::Red );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -30,9 +30,7 @@
#endif #endif
/* Define to 1 if you have the `getttynam' function. */ /* Define to 1 if you have the `getttynam' function. */
#ifndef F_HAVE_GETTTYNAM /* #undef HAVE_GETTTYNAM */
#define F_HAVE_GETTTYNAM 1
#endif
/* Define to 1 if you have the `getuid' function. */ /* Define to 1 if you have the `getuid' function. */
#ifndef F_HAVE_GETUID #ifndef F_HAVE_GETUID
@ -50,9 +48,7 @@
#endif #endif
/* Define to 1 if GPM mouse is enabled */ /* Define to 1 if GPM mouse is enabled */
#ifndef F_HAVE_LIBGPM /* #undef HAVE_LIBGPM */
#define F_HAVE_LIBGPM 1
#endif
/* Define to 1 if you have the <linux/fb.h> header file. */ /* Define to 1 if you have the <linux/fb.h> header file. */
#ifndef F_HAVE_LINUX_FB_H #ifndef F_HAVE_LINUX_FB_H
@ -144,9 +140,7 @@
#endif #endif
/* Define to 1 if you have the <ttyent.h> header file. */ /* Define to 1 if you have the <ttyent.h> header file. */
#ifndef F_HAVE_TTYENT_H /* #undef HAVE_TTYENT_H */
#define F_HAVE_TTYENT_H 1
#endif
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#ifndef F_HAVE_UNISTD_H #ifndef F_HAVE_UNISTD_H

View File

@ -340,6 +340,9 @@ class FListView : public FWidget
bool unsetTreeView(); bool unsetTreeView();
// Methods // Methods
int getindex();
void setindex(int);
void setmark(int);
virtual int addColumn (const FString&, int = USE_MAX_SIZE); virtual int addColumn (const FString&, int = USE_MAX_SIZE);
void hide() override; void hide() override;
iterator insert (FListViewItem*); iterator insert (FListViewItem*);
@ -441,9 +444,9 @@ class FListView : public FWidget
void drawScrollbars() const; void drawScrollbars() const;
void drawHeadlines(); void drawHeadlines();
void drawList(); void drawList();
void drawListLine (const FListViewItem*, bool, bool); void drawListLine (const FListViewItem*, bool, bool, bool, bool);
void clearList(); void clearList();
void setLineAttributes (bool, bool) const; void setLineAttributes (bool, bool, bool, bool) const;
FString getCheckBox (const FListViewItem* item) const; FString getCheckBox (const FListViewItem* item) const;
FString getLinePrefix (const FListViewItem*, std::size_t) const; FString getLinePrefix (const FListViewItem*, std::size_t) const;
void drawSortIndicator (std::size_t&, std::size_t); void drawSortIndicator (std::size_t&, std::size_t);
@ -498,6 +501,7 @@ class FListView : public FWidget
FObjectList selflist{}; FObjectList selflist{};
FObjectList itemlist{}; FObjectList itemlist{};
FListViewIterator current_iter{}; FListViewIterator current_iter{};
FListViewIterator mark_iter{};
FListViewIterator first_visible_line{}; FListViewIterator first_visible_line{};
FListViewIterator last_visible_line{}; FListViewIterator last_visible_line{};
HeaderItems header{}; HeaderItems header{};