finalcut/src/include/final/fbuttongroup.h

168 lines
5.9 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fbuttongroup.h - The FButtonGroup widget organizes FToggleButton *
* widgets in a group. *
* *
* This file is part of the Final Cut widget toolkit *
* *
2020-01-20 21:40:00 +01:00
* Copyright 2014-2020 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
*
* FButtonGroup
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FBUTTONGROUP_H
#define FBUTTONGROUP_H
2015-05-23 13:35:12 +02:00
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fscrollview.h"
#include "final/fwidgetcolors.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
2015-05-23 13:35:12 +02:00
// class forward declaration
2015-05-23 13:35:12 +02:00
class FToggleButton;
//----------------------------------------------------------------------
// class FButtonGroup
//----------------------------------------------------------------------
class FButtonGroup : public FScrollView
2015-05-23 13:35:12 +02:00
{
2017-09-11 03:06:02 +02:00
public:
// Constructors
explicit FButtonGroup (FWidget* = nullptr);
explicit FButtonGroup (const FString&, FWidget* = nullptr);
// Disable copy constructor
FButtonGroup (const FButtonGroup&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
2020-02-19 21:59:13 +01:00
~FButtonGroup() override;
2017-09-11 03:06:02 +02:00
// Disable copy assignment operator (=)
FButtonGroup& operator = (const FButtonGroup&) = delete;
2017-09-11 03:06:02 +02:00
// Accessor
2019-10-05 23:20:07 +02:00
const FString getClassName() const override;
2018-12-31 06:18:39 +01:00
FToggleButton* getFirstButton();
FToggleButton* getLastButton();
FToggleButton* getButton (int) const;
std::size_t getCount() const;
FString& getText();
2017-09-11 03:06:02 +02:00
// Mutator
2019-08-06 23:45:28 +02:00
bool setEnable(bool) override;
bool setEnable() override;
bool unsetEnable() override;
bool setDisable() override;
2018-12-31 06:18:39 +01:00
void setText (const FString&);
2017-09-11 03:06:02 +02:00
// Inquiries
2018-12-31 06:18:39 +01:00
bool isChecked(int) const;
bool hasFocusedButton() const;
bool hasCheckedButton() const;
2017-09-11 03:06:02 +02:00
// Methods
2019-08-06 23:45:28 +02:00
void hide() override;
2018-12-31 06:18:39 +01:00
void insert (FToggleButton*);
void remove (FToggleButton*);
2020-04-13 12:40:11 +02:00
void checkScrollSize (const FToggleButton*);
2018-12-31 06:18:39 +01:00
void checkScrollSize (const FRect&);
2017-09-11 03:06:02 +02:00
// Event handlers
2019-08-06 23:45:28 +02:00
void onMouseDown (FMouseEvent*) override;
void onAccel (FAccelEvent*) override;
void onFocusIn (FFocusEvent*) override;
2017-09-11 03:06:02 +02:00
protected:
// Mutator
2018-12-31 06:18:39 +01:00
void setHotkeyAccelerator();
2017-09-11 03:06:02 +02:00
// Methods
2019-08-06 23:45:28 +02:00
void draw() override;
2018-12-31 06:18:39 +01:00
void drawLabel();
2017-09-11 03:06:02 +02:00
private:
// Constants
2018-12-26 23:41:49 +01:00
static constexpr std::size_t NOT_SET = static_cast<std::size_t>(-1);
2017-09-11 03:06:02 +02:00
// Inquiries
bool isRadioButton (const FToggleButton*) const;
2017-09-11 03:06:02 +02:00
// Methods
2018-12-31 06:18:39 +01:00
void init();
void drawText (const FString&, std::size_t);
2018-12-31 06:18:39 +01:00
void directFocus();
2017-09-11 03:06:02 +02:00
// Callback method
2020-04-13 12:40:11 +02:00
void cb_buttonToggled (FWidget*, const FDataPtr);
// Data members
FString text{};
FObjectList buttonlist{};
2015-05-23 13:35:12 +02:00
};
// FButtonGroup inline functions
//----------------------------------------------------------------------
2019-10-05 23:20:07 +02:00
inline const FString FButtonGroup::getClassName() const
2015-05-23 13:35:12 +02:00
{ return "FButtonGroup"; }
//----------------------------------------------------------------------
inline bool FButtonGroup::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FButtonGroup::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FButtonGroup::setDisable()
{ return setEnable(false); }
2017-03-12 00:29:56 +01:00
//----------------------------------------------------------------------
inline std::size_t FButtonGroup::getCount() const
{ return buttonlist.size(); }
2017-03-12 00:29:56 +01:00
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline FString& FButtonGroup::getText()
2015-09-22 04:18:20 +02:00
{ return text; }
2015-05-23 13:35:12 +02:00
} // namespace finalcut
#endif // FBUTTONGROUP_H