Ajout de getindex, setindex & setmark pour le Listview
This commit is contained in:
parent
cf37e826e9
commit
ea7f53be41
|
@ -25,7 +25,6 @@
|
|||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <final/final.h>
|
||||
|
||||
using finalcut::FPoint;
|
||||
|
@ -61,10 +60,16 @@ class Listview final : public finalcut::FDialog
|
|||
|
||||
// Callback method
|
||||
void cb_showInMessagebox();
|
||||
|
||||
void cb_showIndexInMessagebox();
|
||||
void cb_doit();
|
||||
void cb_doit2();
|
||||
|
||||
// Data members
|
||||
finalcut::FListView listview{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();
|
||||
|
||||
// Quit button
|
||||
quit.setText (L"&Quit");
|
||||
|
||||
Mark.setText("&Mark");
|
||||
Index.setText("&Getindex");
|
||||
GIndex.setText("&Index");
|
||||
// Add some function callbacks
|
||||
quit.addCallback
|
||||
(
|
||||
|
@ -118,6 +124,24 @@ Listview::Listview (finalcut::FWidget* parent)
|
|||
"clicked",
|
||||
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
|
||||
listview.setGeometry(FPoint{2, 1}, FSize{33, 14});
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
@ -191,6 +218,16 @@ void Listview::onClose (finalcut::FCloseEvent* 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()
|
||||
{
|
||||
|
@ -206,7 +243,18 @@ void Listview::cb_showInMessagebox()
|
|||
, this );
|
||||
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
|
||||
|
|
|
@ -910,6 +910,7 @@ void FListView::clear()
|
|||
{
|
||||
itemlist.clear();
|
||||
current_iter = getNullIterator();
|
||||
mark_iter = getNullIterator();
|
||||
first_visible_line = getNullIterator();
|
||||
last_visible_line = getNullIterator();
|
||||
recalculateVerticalBar (0);
|
||||
|
@ -1427,6 +1428,37 @@ inline void FListView::mapKeyFunctions()
|
|||
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)
|
||||
{
|
||||
|
@ -1608,6 +1640,8 @@ void FListView::drawList()
|
|||
while ( iter != path_end && iter != itemlist_end && y < page_height )
|
||||
{
|
||||
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 int tree_offset = tree_view ? int(item->getDepth() << 1) + 1 : 0;
|
||||
const int checkbox_offset = item->isCheckable() ? 1 : 0;
|
||||
|
@ -1615,7 +1649,7 @@ void FListView::drawList()
|
|||
print() << FPoint{2, 2 + int(y)};
|
||||
|
||||
// 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 )
|
||||
{
|
||||
|
@ -1651,10 +1685,10 @@ void FListView::drawList()
|
|||
//----------------------------------------------------------------------
|
||||
void FListView::drawListLine ( const FListViewItem* item
|
||||
, bool is_focus
|
||||
, bool is_current )
|
||||
, bool is_current, bool is_mark, bool is_selected )
|
||||
{
|
||||
// Set line color and attributes
|
||||
setLineAttributes (is_current, is_focus);
|
||||
setLineAttributes (is_current, is_focus, is_mark, is_selected);
|
||||
|
||||
// Print the entry
|
||||
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
|
||||
, bool is_focus ) const
|
||||
, bool is_focus, bool is_mark, bool is_selected ) const
|
||||
{
|
||||
const auto& wc = getColorTheme();
|
||||
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 )
|
||||
unsetBold();
|
||||
}
|
||||
if ( is_selected )
|
||||
setColor ( FColor::White , FColor::Black );
|
||||
if ( is_mark )
|
||||
setColor ( FColor::White, FColor::Red );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -30,9 +30,7 @@
|
|||
#endif
|
||||
|
||||
/* Define to 1 if you have the `getttynam' function. */
|
||||
#ifndef F_HAVE_GETTTYNAM
|
||||
#define F_HAVE_GETTTYNAM 1
|
||||
#endif
|
||||
/* #undef HAVE_GETTTYNAM */
|
||||
|
||||
/* Define to 1 if you have the `getuid' function. */
|
||||
#ifndef F_HAVE_GETUID
|
||||
|
@ -50,9 +48,7 @@
|
|||
#endif
|
||||
|
||||
/* Define to 1 if GPM mouse is enabled */
|
||||
#ifndef F_HAVE_LIBGPM
|
||||
#define F_HAVE_LIBGPM 1
|
||||
#endif
|
||||
/* #undef HAVE_LIBGPM */
|
||||
|
||||
/* Define to 1 if you have the <linux/fb.h> header file. */
|
||||
#ifndef F_HAVE_LINUX_FB_H
|
||||
|
@ -144,9 +140,7 @@
|
|||
#endif
|
||||
|
||||
/* Define to 1 if you have the <ttyent.h> header file. */
|
||||
#ifndef F_HAVE_TTYENT_H
|
||||
#define F_HAVE_TTYENT_H 1
|
||||
#endif
|
||||
/* #undef HAVE_TTYENT_H */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#ifndef F_HAVE_UNISTD_H
|
||||
|
|
|
@ -340,6 +340,9 @@ class FListView : public FWidget
|
|||
bool unsetTreeView();
|
||||
|
||||
// Methods
|
||||
int getindex();
|
||||
void setindex(int);
|
||||
void setmark(int);
|
||||
virtual int addColumn (const FString&, int = USE_MAX_SIZE);
|
||||
void hide() override;
|
||||
iterator insert (FListViewItem*);
|
||||
|
@ -441,9 +444,9 @@ class FListView : public FWidget
|
|||
void drawScrollbars() const;
|
||||
void drawHeadlines();
|
||||
void drawList();
|
||||
void drawListLine (const FListViewItem*, bool, bool);
|
||||
void drawListLine (const FListViewItem*, bool, bool, bool, bool);
|
||||
void clearList();
|
||||
void setLineAttributes (bool, bool) const;
|
||||
void setLineAttributes (bool, bool, bool, bool) const;
|
||||
FString getCheckBox (const FListViewItem* item) const;
|
||||
FString getLinePrefix (const FListViewItem*, std::size_t) const;
|
||||
void drawSortIndicator (std::size_t&, std::size_t);
|
||||
|
@ -498,6 +501,7 @@ class FListView : public FWidget
|
|||
FObjectList selflist{};
|
||||
FObjectList itemlist{};
|
||||
FListViewIterator current_iter{};
|
||||
FListViewIterator mark_iter{};
|
||||
FListViewIterator first_visible_line{};
|
||||
FListViewIterator last_visible_line{};
|
||||
HeaderItems header{};
|
||||
|
|
Loading…
Reference in New Issue