A FListView tree branch can now be expand and collapsed with a single click
This commit is contained in:
parent
4d955bc204
commit
d1f2de254d
|
@ -1,3 +1,7 @@
|
|||
2017-10-23 Markus Gans <guru.mail@muenster.de>
|
||||
* A FListView tree branch can now be expand and collapsed
|
||||
with a single click
|
||||
|
||||
2017-10-19 Markus Gans <guru.mail@muenster.de>
|
||||
* Optimized Color palette (less saturated colors)
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class FListViewItem : public FObject
|
|||
void setText (int, const FString&);
|
||||
|
||||
// Inquiry
|
||||
bool isExpand();
|
||||
bool isExpand() const;
|
||||
|
||||
// Methods
|
||||
FObjectIterator insert (FListViewItem*);
|
||||
|
@ -101,7 +101,7 @@ class FListViewItem : public FObject
|
|||
|
||||
private:
|
||||
// Inquiry
|
||||
bool isExpandable();
|
||||
bool isExpandable() const;
|
||||
|
||||
// Methods
|
||||
FObjectIterator appendItem (FListViewItem*);
|
||||
|
@ -133,11 +133,11 @@ inline uInt FListViewItem::getColumnCount() const
|
|||
{ return uInt(column_list.size()); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListViewItem::isExpand()
|
||||
inline bool FListViewItem::isExpand() const
|
||||
{ return is_expand; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListViewItem::isExpandable()
|
||||
inline bool FListViewItem::isExpandable() const
|
||||
{ return expandable; }
|
||||
|
||||
|
||||
|
@ -348,6 +348,7 @@ class FListView : public FWidget
|
|||
int scroll_distance;
|
||||
bool scroll_timer;
|
||||
bool tree_view;
|
||||
FPoint clicked_expander_pos;
|
||||
int xoffset;
|
||||
int nf_offset;
|
||||
int max_line_width;
|
||||
|
|
|
@ -443,6 +443,7 @@ FListView::FListView (FWidget* parent)
|
|||
, scroll_distance(1)
|
||||
, scroll_timer(false)
|
||||
, tree_view(false)
|
||||
, clicked_expander_pos(-1, -1)
|
||||
, xoffset(0)
|
||||
, nf_offset(0)
|
||||
, max_line_width(1)
|
||||
|
@ -706,6 +707,7 @@ void FListView::onKeyPress (FKeyEvent* ev)
|
|||
, pagesize = getClientHeight() - 1
|
||||
, key = ev->key();
|
||||
FListViewItem* item = getCurrentItem();
|
||||
clicked_expander_pos.setPoint(-1, -1);
|
||||
|
||||
switch ( key )
|
||||
{
|
||||
|
@ -879,15 +881,12 @@ void FListView::onKeyPress (FKeyEvent* ev)
|
|||
//----------------------------------------------------------------------
|
||||
void FListView::onMouseDown (FMouseEvent* ev)
|
||||
{
|
||||
if ( ev->getButton() != fc::LeftButton
|
||||
&& ev->getButton() != fc::RightButton )
|
||||
if ( ev->getButton() != fc::LeftButton )
|
||||
{
|
||||
clicked_expander_pos.setPoint(-1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ev->getButton() == fc::RightButton )
|
||||
return;
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
FWidget* focused_widget = getFocusWidget();
|
||||
|
@ -914,6 +913,15 @@ void FListView::onMouseDown (FMouseEvent* ev)
|
|||
if ( new_pos < int(getCount()) )
|
||||
setRelativePosition (mouse_y - 2);
|
||||
|
||||
if ( tree_view )
|
||||
{
|
||||
const FListViewItem* item = getCurrentItem();
|
||||
int indent = int(item->getDepth() << 1); // indent = 2 * depth
|
||||
|
||||
if ( item->isExpandable() && mouse_x - 2 == indent - xoffset )
|
||||
clicked_expander_pos = ev->getPos();
|
||||
}
|
||||
|
||||
if ( isVisible() )
|
||||
drawList();
|
||||
|
||||
|
@ -947,23 +955,40 @@ void FListView::onMouseUp (FMouseEvent* ev)
|
|||
if ( mouse_x > 1 && mouse_x < getWidth()
|
||||
&& mouse_y > 1 && mouse_y < getHeight() )
|
||||
{
|
||||
if ( tree_view )
|
||||
{
|
||||
FListViewItem* item = getCurrentItem();
|
||||
|
||||
if ( item->isExpandable() && clicked_expander_pos == ev->getPos() )
|
||||
{
|
||||
if ( item->isExpand() )
|
||||
item->collapse();
|
||||
else
|
||||
item->expand();
|
||||
|
||||
adjustSize();
|
||||
|
||||
if ( isVisible() )
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
processChanged();
|
||||
}
|
||||
}
|
||||
|
||||
clicked_expander_pos.setPoint(-1, -1);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListView::onMouseMove (FMouseEvent* ev)
|
||||
{
|
||||
if ( ev->getButton() != fc::LeftButton
|
||||
&& ev->getButton() != fc::RightButton )
|
||||
if ( ev->getButton() != fc::LeftButton )
|
||||
{
|
||||
clicked_expander_pos.setPoint(-1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ev->getButton() == fc::RightButton )
|
||||
return;
|
||||
|
||||
int first_line_position_before = first_visible_line.getPosition()
|
||||
, mouse_x = ev->getX()
|
||||
, mouse_y = ev->getY();
|
||||
|
@ -1082,6 +1107,8 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
|
|||
|
||||
processClick();
|
||||
}
|
||||
|
||||
clicked_expander_pos.setPoint(-1, -1);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue