/***********************************************************************
* fspinbox.h - Widget FSpinBox *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* *
* 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. *
* *
* 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 *
* . *
***********************************************************************/
/* Inheritance diagram
* ═══════════════════
*
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
* ▕ FVTerm ▏ ▕ FObject ▏
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
* ▲ ▲
* │ │
* └─────┬─────┘
* │
* ▕▔▔▔▔▔▔▔▔▔▏
* ▕ FWidget ▏
* ▕▁▁▁▁▁▁▁▁▁▏
* ▲
* │
* ▕▔▔▔▔▔▔▔▔▔▔▏
* ▕ FSpinBox ▏
* ▕▁▁▁▁▁▁▁▁▁▁▏
*/
#ifndef FSPINBOX_H
#define FSPINBOX_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only can be included directly."
#endif
#include
#include "final/fwidget.h"
namespace finalcut
{
// class forward declaration
class FLineEdit;
//----------------------------------------------------------------------
// class FSpinBox
//----------------------------------------------------------------------
class FSpinBox : public FWidget
{
public:
// Using-declaration
using FWidget::setGeometry;
// Constructors
explicit FSpinBox (FWidget* = nullptr);
// Disable copy constructor
FSpinBox (const FSpinBox&) = delete;
// Destructor
~FSpinBox() override;
// Disable copy assignment operator (=)
FSpinBox& operator = (const FSpinBox&) = delete;
// Accessors
FString getClassName() const override;
sInt64 getValue() const;
FString getPrefix() const;
FString getSuffix() const;
FLineEdit::label_o getLabelOrientation() const;
// Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize&
, bool = true ) override;
bool setEnable (bool) override;
bool setEnable() override;
bool unsetEnable() override;
bool setDisable() override;
bool setFocus (bool) override;
bool setFocus() override;
bool unsetFocus() override;
bool setShadow (bool);
bool setShadow();
bool unsetShadow();
void setValue (sInt64);
void setMinValue (sInt64);
void setMaxValue (sInt64);
void setRange (sInt64, sInt64);
void setPrefix (const FString&);
void setSuffix (const FString&);
void setLabelText (const FString&);
void setLabelOrientation (const FLineEdit::label_o);
// Inquiries
bool hasShadow() const;
// Methods
void hide() override;
// Event handlers
void onKeyPress (FKeyEvent*) override;
void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override;
void onWheel (FWheelEvent*) override;
void onTimer (FTimerEvent*) override;
private:
// Enumeration
enum spiningState
{
noSpin = 0,
spinUp = 1,
spinDown = 2
};
// Methods
void init();
void draw() override;
void updateInputField();
void increaseValue();
void decreaseValue();
void processActivate() const;
void processChanged() const;
void forceFocus();
// Callback methods
void cb_inputFieldActivate() const;
void cb_inputFieldChange (const FLineEdit&);
// Data members
FLineEdit input_field{this};
sInt64 value{0};
sInt64 min{std::numeric_limits::min()};
sInt64 max{std::numeric_limits::max()};
FString pfix{};
FString sfix{};
spiningState spining_state{FSpinBox::noSpin};
bool threshold_reached{false};
int threshold_time{500};
int repeat_time{80};
};
// FSpinBox inline functions
//----------------------------------------------------------------------
inline FString FSpinBox::getClassName() const
{ return "FSpinBox"; }
//----------------------------------------------------------------------
inline sInt64 FSpinBox::getValue() const
{ return value; }
//----------------------------------------------------------------------
inline FString FSpinBox::getPrefix() const
{ return pfix; }
//----------------------------------------------------------------------
inline FString FSpinBox::getSuffix() const
{ return sfix; }
//----------------------------------------------------------------------
inline FLineEdit::label_o FSpinBox::getLabelOrientation() const
{ return input_field.getLabelOrientation(); }
//----------------------------------------------------------------------
inline bool FSpinBox::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setShadow()
{ return setShadow(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::hasShadow() const
{ return getFlags().shadow; }
//----------------------------------------------------------------------
inline void FSpinBox::setLabelText (const FString& s)
{ input_field.setLabelText(s); }
//----------------------------------------------------------------------
inline void FSpinBox::setLabelOrientation (const FLineEdit::label_o o)
{ input_field.setLabelOrientation(o); }
} // namespace finalcut
#endif // FSPINBOX_H