2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fbuttongroup.cpp - The FButtonGroup widget organizes FToggleButton *
|
|
|
|
* widgets in a group. *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-02 03:00:07 +01:00
|
|
|
* Copyright 2014-2019 Markus Gans *
|
2017-11-04 07:03:53 +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/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/fbuttongroup.h"
|
2019-09-28 03:13:06 +02:00
|
|
|
#include "final/fcolorpair.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fevent.h"
|
|
|
|
#include "final/fsize.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fstatusbar.h"
|
|
|
|
#include "final/ftogglebutton.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FButtonGroup
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FButtonGroup::FButtonGroup(FWidget* parent)
|
2017-02-20 00:00:53 +01:00
|
|
|
: FScrollView(parent)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
|
2017-02-20 00:00:53 +01:00
|
|
|
: FScrollView(parent)
|
2018-12-03 03:22:36 +01:00
|
|
|
, text{txt}
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
setText(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FButtonGroup::~FButtonGroup() // destructor
|
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2019-09-08 02:04:24 +02:00
|
|
|
toggle_button->setGroup(nullptr);
|
2015-05-23 13:35:12 +02:00
|
|
|
iter = buttonlist.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FButtonGroup
|
2017-03-12 00:29:56 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-11-03 05:04:27 +01:00
|
|
|
FToggleButton* FButtonGroup::getButton (int index) const
|
2017-03-12 00:29:56 +01:00
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return 0;
|
|
|
|
|
2018-01-02 20:38:45 +01:00
|
|
|
if ( index <= 0 || index > int(getCount()) )
|
2017-03-12 00:29:56 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2018-01-02 20:38:45 +01:00
|
|
|
std::advance (iter, index - 1);
|
2017-03-12 00:29:56 +01:00
|
|
|
return static_cast<FToggleButton*>(*iter);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FToggleButton* FButtonGroup::getFirstButton()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = FWidget::getFirstFocusableWidget(buttonlist);
|
|
|
|
auto toggle_button = static_cast<FToggleButton*>(widget);
|
2017-01-28 22:03:15 +01:00
|
|
|
return toggle_button;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FToggleButton* FButtonGroup::getLastButton()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto widget = FWidget::getLastFocusableWidget(buttonlist);
|
|
|
|
auto toggle_button = static_cast<FToggleButton*>(widget);
|
2017-01-28 22:03:15 +01:00
|
|
|
return toggle_button;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
bool FButtonGroup::setEnable (bool enable)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-22 23:50:10 +01:00
|
|
|
FWidget::setEnable(enable);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( enable )
|
2016-11-02 00:37:58 +01:00
|
|
|
setHotkeyAccelerator();
|
|
|
|
else
|
|
|
|
delAccelerator();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
return enable;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FButtonGroup::setText (const FString& txt)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
text.setString(txt);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-11-12 01:33:16 +01:00
|
|
|
delAccelerator();
|
2016-11-02 00:37:58 +01:00
|
|
|
setHotkeyAccelerator();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-12 00:29:56 +01:00
|
|
|
bool FButtonGroup::isChecked (int index) const
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto button = getButton(index);
|
2017-03-12 00:29:56 +01:00
|
|
|
|
|
|
|
if ( button )
|
|
|
|
return button->isChecked();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FButtonGroup::hasFocusedButton() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->hasFocus() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-12 00:29:56 +01:00
|
|
|
bool FButtonGroup::hasCheckedButton() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2016-11-02 00:37:58 +01:00
|
|
|
return true;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::hide()
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
FColor fg{}, bg{};
|
2015-05-23 13:35:12 +02:00
|
|
|
FWidget::hide();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto parent_widget = getParentWidget();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! buttonlist.empty() )
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-10-01 23:14:00 +02:00
|
|
|
// Hide items
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->hide();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
const auto& wc = getFWidgetColors();
|
2016-08-21 21:27:44 +02:00
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
setColor (fg, bg);
|
2019-08-25 22:16:00 +02:00
|
|
|
std::size_t size = getWidth();
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-09-25 23:53:48 +02:00
|
|
|
return;
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
// Hide border
|
|
|
|
unsetViewportPrint();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int y{0}; y < int(getHeight()); y++)
|
2019-10-01 23:14:00 +02:00
|
|
|
print() << FPoint(1, 1 + y) << FString(size, L' ');
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
setViewportPrint();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-21 18:48:38 +01:00
|
|
|
void FButtonGroup::insert (FToggleButton* button)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 22:47:45 +02:00
|
|
|
if ( ! button )
|
|
|
|
return;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( button->getGroup() )
|
|
|
|
button->getGroup()->remove(button);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
// setChecked the first FRadioButton
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( buttonlist.size() == 1 )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto first_button = static_cast<FToggleButton*>(*buttonlist.begin());
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( isRadioButton(first_button) )
|
|
|
|
first_button->setChecked();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
button->setGroup(this);
|
|
|
|
buttonlist.push_back(button);
|
|
|
|
|
|
|
|
button->addCallback
|
|
|
|
(
|
|
|
|
"toggled",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled)
|
2015-05-23 13:35:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-12-21 18:48:38 +01:00
|
|
|
void FButtonGroup::remove (FToggleButton* button)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 22:47:45 +02:00
|
|
|
if ( ! button || buttonlist.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = buttonlist.begin();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
while ( iter != buttonlist.end() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(*iter);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button == button )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
iter = buttonlist.erase(iter);
|
2019-09-08 02:04:24 +02:00
|
|
|
button->setGroup(nullptr);
|
2015-05-23 13:35:12 +02:00
|
|
|
button->delCallback(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 00:29:56 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::checkScrollSize (FToggleButton* button)
|
|
|
|
{
|
|
|
|
// Check and adjust the scroll size
|
|
|
|
|
|
|
|
checkScrollSize (button->getGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::checkScrollSize (const FRect& r)
|
|
|
|
{
|
|
|
|
// Check and adjust the scroll size
|
|
|
|
|
|
|
|
FRect scrollgeometry (1, 1, getScrollWidth(), getScrollHeight());
|
|
|
|
|
|
|
|
if ( ! scrollgeometry.contains(r) )
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
FRect r_combined (scrollgeometry.combined(r));
|
2019-01-21 03:42:18 +01:00
|
|
|
setScrollSize (r_combined.getSize());
|
2017-03-12 00:29:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FButtonGroup::onMouseDown (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
directFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::onAccel (FAccelEvent*)
|
|
|
|
{
|
|
|
|
directFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
|
|
|
{
|
2019-10-01 23:14:00 +02:00
|
|
|
in_ev->ignore(); // Change default value to ignore
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( isRadioButton(toggle_button) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = getFocusWidget();
|
2019-09-01 23:29:27 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->setFocus();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-03-12 00:29:56 +01:00
|
|
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
|
|
|
FApplication::sendEvent(this, &cfi);
|
|
|
|
|
|
|
|
FFocusEvent in (fc::FocusIn_Event);
|
|
|
|
FApplication::sendEvent(toggle_button, &in);
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( in.isAccepted() )
|
|
|
|
in_ev->accept();
|
|
|
|
|
2016-06-19 23:18:53 +02:00
|
|
|
if ( prev_element )
|
|
|
|
prev_element->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-09-28 03:13:06 +02:00
|
|
|
} // end of range-based for loop
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! in_ev->isAccepted() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
in_ev->accept();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto prev_element = getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
2015-05-23 13:35:12 +02:00
|
|
|
focusFirstChild();
|
2016-01-17 02:57:08 +01:00
|
|
|
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
2015-05-23 13:35:12 +02:00
|
|
|
focusLastChild();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( prev_element )
|
|
|
|
prev_element->redraw();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( getFocusWidget() )
|
|
|
|
getFocusWidget()->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( getStatusBar() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
getStatusBar()->drawMessage();
|
2015-05-23 13:35:12 +02:00
|
|
|
updateTerminal();
|
2019-10-08 04:37:19 +02:00
|
|
|
flushOutputBuffer();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// protected methods of FButtonGroup
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::setHotkeyAccelerator()
|
|
|
|
{
|
2019-10-01 23:14:00 +02:00
|
|
|
setHotkeyViaString (this, text);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FButtonGroup::draw()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
setColor();
|
2017-02-20 00:00:53 +01:00
|
|
|
clearArea();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2017-02-20 00:00:53 +01:00
|
|
|
|
|
|
|
FScrollView::draw();
|
|
|
|
drawLabel();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::drawLabel()
|
|
|
|
{
|
|
|
|
if ( text.isNull() || text.isEmpty() )
|
|
|
|
return;
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
FString label_text{};
|
2019-08-25 22:16:00 +02:00
|
|
|
FString txt{" " + text + " "};
|
2017-02-20 00:00:53 +01:00
|
|
|
unsetViewportPrint();
|
2019-10-01 23:14:00 +02:00
|
|
|
auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
|
2018-02-17 19:12:48 +01:00
|
|
|
|
|
|
|
if ( hasBorder() )
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setPrintPos (FPoint(2, 1));
|
2018-02-17 19:12:48 +01:00
|
|
|
else
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setPrintPos (FPoint(0, 1));
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
drawText (label_text, hotkeypos);
|
2018-02-17 19:12:48 +01:00
|
|
|
setViewportPrint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FButtonGroup
|
|
|
|
//----------------------------------------------------------------------
|
2019-04-26 23:48:38 +02:00
|
|
|
bool FButtonGroup::isRadioButton (const FToggleButton* button) const
|
2018-02-17 19:12:48 +01:00
|
|
|
{
|
|
|
|
if ( ! button )
|
|
|
|
return false;
|
|
|
|
|
2019-10-06 00:36:58 +02:00
|
|
|
return bool( button->getClassName() == "FRadioButton" );
|
2018-02-17 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::init()
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
const auto& wc = getFWidgetColors();
|
2018-02-17 19:12:48 +01:00
|
|
|
setForegroundColor (wc.label_fg);
|
|
|
|
setBackgroundColor (wc.label_bg);
|
2019-09-28 03:13:06 +02:00
|
|
|
setMinimumSize (FSize(7, 3));
|
2018-02-17 19:12:48 +01:00
|
|
|
buttonlist.clear(); // no buttons yet
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-01 23:14:00 +02:00
|
|
|
void FButtonGroup::drawText ( const FString& label_text
|
|
|
|
, std::size_t hotkeypos )
|
2018-02-17 19:12:48 +01:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
const auto& wc = getFWidgetColors();
|
2019-10-01 23:14:00 +02:00
|
|
|
std::size_t column_width = getColumnWidth(label_text);
|
|
|
|
std::size_t length = label_text.getLength();
|
2019-09-28 03:13:06 +02:00
|
|
|
bool ellipsis{false};
|
|
|
|
|
|
|
|
if ( column_width > getClientWidth() )
|
|
|
|
{
|
|
|
|
std::size_t len = getClientWidth() - 3;
|
2019-10-01 23:14:00 +02:00
|
|
|
FString s = finalcut::getColumnSubString (label_text, 1, len);
|
2019-09-28 03:13:06 +02:00
|
|
|
length = s.getLength();
|
|
|
|
ellipsis = true;
|
|
|
|
}
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( isEnabled() )
|
|
|
|
setColor(wc.label_emphasis_fg, wc.label_bg);
|
|
|
|
else
|
|
|
|
setColor(wc.label_inactive_fg, wc.label_inactive_bg);
|
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (std::size_t z{0}; z < length; z++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( (z == hotkeypos) && getFlags().active )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getFlags().no_underline )
|
2016-11-02 00:37:58 +01:00
|
|
|
setUnderline();
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
print (label_text[z]);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getFlags().no_underline )
|
2016-11-02 00:37:58 +01:00
|
|
|
unsetUnderline();
|
|
|
|
|
|
|
|
setColor (wc.label_emphasis_fg, wc.label_bg);
|
|
|
|
}
|
|
|
|
else
|
2019-10-01 23:14:00 +02:00
|
|
|
print (label_text[z]);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
if ( ellipsis ) // Print ellipsis
|
|
|
|
print() << FColorPair (wc.label_ellipsis_fg, wc.label_bg) << "..";
|
|
|
|
|
2017-12-25 21:17:08 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::directFocus()
|
|
|
|
{
|
|
|
|
if ( ! hasFocusedButton() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
bool found_checked{false};
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2017-01-28 22:03:15 +01:00
|
|
|
|
|
|
|
if ( toggle_button->isChecked() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-01-28 22:03:15 +01:00
|
|
|
if ( isRadioButton(toggle_button) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
found_checked = true;
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2017-01-28 22:03:15 +01:00
|
|
|
toggle_button->setFocus();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
focused_widget = getFocusWidget();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-09-28 03:13:06 +02:00
|
|
|
} // end of range-based for loop
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! found_checked )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto focused_widget = getFocusWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
focusFirstChild();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
|
|
|
|
focused_widget = getFocusWidget();
|
|
|
|
|
|
|
|
if ( focused_widget )
|
|
|
|
focused_widget->redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( getStatusBar() )
|
|
|
|
{
|
|
|
|
getStatusBar()->drawMessage();
|
|
|
|
updateTerminal();
|
2019-10-08 04:37:19 +02:00
|
|
|
flushOutputBuffer();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2019-01-02 03:00:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FButtonGroup::cb_buttonToggled (FWidget* widget, FDataPtr)
|
|
|
|
{
|
|
|
|
auto button = static_cast<FToggleButton*>(widget);
|
|
|
|
|
|
|
|
if ( ! button->isChecked() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( buttonlist.empty() )
|
|
|
|
return;
|
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& item : buttonlist)
|
2019-01-02 03:00:07 +01:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
auto toggle_button = static_cast<FToggleButton*>(item);
|
2019-01-02 03:00:07 +01:00
|
|
|
|
|
|
|
if ( toggle_button != button
|
|
|
|
&& toggle_button->isChecked()
|
|
|
|
&& isRadioButton(toggle_button) )
|
|
|
|
{
|
|
|
|
toggle_button->unsetChecked();
|
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( toggle_button->isShown() )
|
2019-01-02 03:00:07 +01:00
|
|
|
toggle_button->redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|