2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* flabel.cpp - Widget FLabel *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-01-20 21:40:00 +01:00
|
|
|
* Copyright 2014-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* 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/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FLabel ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FLABEL_H
|
|
|
|
#define FLABEL_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
2017-09-17 21:32:46 +02:00
|
|
|
|
|
|
|
#include "final/fwidget.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-09-25 21:37:19 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FLabel
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FLabel : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setEnable;
|
|
|
|
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FLabel (FWidget* = nullptr);
|
|
|
|
explicit FLabel (const FString&, FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FLabel (const FLabel&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~FLabel() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
FLabel& operator = (const FLabel&) = delete;
|
|
|
|
|
2017-09-20 05:44:41 +02:00
|
|
|
// Overloaded operators
|
|
|
|
FLabel& operator = (const FString&);
|
2019-11-16 21:48:59 +01:00
|
|
|
template <typename typeT>
|
|
|
|
FLabel& operator << (const typeT&);
|
2018-12-06 02:28:24 +01:00
|
|
|
FLabel& operator << (fc::SpecialCharacter);
|
2017-09-20 05:44:41 +02:00
|
|
|
FLabel& operator << (const wchar_t);
|
2020-07-12 15:25:21 +02:00
|
|
|
const FLabel& operator >> (FString&) const;
|
2017-09-20 05:44:41 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2020-10-04 00:59:21 +02:00
|
|
|
FString getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
FWidget* getAccelWidget();
|
2020-07-12 15:25:21 +02:00
|
|
|
fc::text_alignment getAlignment() const;
|
2018-12-31 06:18:39 +01:00
|
|
|
FString& getText();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2018-12-31 06:18:39 +01:00
|
|
|
void setAccelWidget (FWidget* = nullptr);
|
2019-09-28 03:13:06 +02:00
|
|
|
void setAlignment (fc::text_alignment);
|
|
|
|
bool setEmphasis (bool);
|
2018-12-31 06:18:39 +01:00
|
|
|
bool setEmphasis();
|
|
|
|
bool unsetEmphasis();
|
2020-06-06 21:10:06 +02:00
|
|
|
void resetColors() override;
|
2019-09-28 03:13:06 +02:00
|
|
|
bool setReverseMode (bool);
|
2018-12-31 06:18:39 +01:00
|
|
|
bool setReverseMode();
|
|
|
|
bool unsetReverseMode();
|
2019-08-06 23:45:28 +02:00
|
|
|
bool setEnable (bool) override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void setNumber (uLong);
|
|
|
|
void setNumber (long);
|
|
|
|
void setNumber (float, int = FLT_DIG);
|
|
|
|
void setNumber (double, int = DBL_DIG);
|
|
|
|
void setNumber (lDouble, int = LDBL_DIG);
|
|
|
|
void setText (const FString&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiries
|
2020-05-02 00:07:35 +02:00
|
|
|
bool hasEmphasis() const;
|
|
|
|
bool hasReverseMode() 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 clear();
|
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;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback method
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_accelWidgetDestroyed();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
2018-10-17 22:12:52 +02:00
|
|
|
// Constants
|
2020-10-04 00:59:21 +02:00
|
|
|
static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
|
2018-10-17 22:12:52 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void init();
|
|
|
|
void setHotkeyAccelerator();
|
2020-07-12 15:25:21 +02:00
|
|
|
std::size_t getAlignOffset (const std::size_t) const;
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void drawMultiLine();
|
|
|
|
void drawSingleLine();
|
2020-04-19 20:38:52 +02:00
|
|
|
void printLine (FString&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2019-09-08 02:04:24 +02:00
|
|
|
FStringList multiline_text{};
|
|
|
|
FString text{};
|
|
|
|
FWidget* accel_widget{nullptr};
|
|
|
|
fc::text_alignment alignment{fc::alignLeft};
|
2019-10-01 23:14:00 +02:00
|
|
|
std::size_t align_offset{0};
|
|
|
|
std::size_t hotkeypos{NOT_SET};
|
|
|
|
std::size_t column_width{0};
|
2020-06-06 21:10:06 +02:00
|
|
|
FColor emphasis_color{fc::Default};
|
|
|
|
FColor ellipsis_color{fc::Default};
|
2019-09-08 02:04:24 +02:00
|
|
|
bool multiline{false};
|
|
|
|
bool emphasis{false};
|
|
|
|
bool reverse_mode{false};
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// FLabel inline functions
|
2019-11-16 21:48:59 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename typeT>
|
|
|
|
inline FLabel& FLabel::operator << (const typeT& s)
|
|
|
|
{
|
|
|
|
FString str{};
|
|
|
|
str << s;
|
|
|
|
setText(text + str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-10-04 00:59:21 +02:00
|
|
|
inline FString FLabel::getClassName() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return "FLabel"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-29 00:45:45 +01:00
|
|
|
inline FWidget* FLabel::getAccelWidget ()
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return accel_widget; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 15:25:21 +02:00
|
|
|
inline fc::text_alignment FLabel::getAlignment() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return alignment; }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString& FLabel::getText()
|
|
|
|
{ return text; }
|
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::setEmphasis (bool enable)
|
|
|
|
{ return (emphasis = enable); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::setEmphasis()
|
|
|
|
{ return setEmphasis(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::unsetEmphasis()
|
|
|
|
{ return setEmphasis(false); }
|
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::setReverseMode (bool enable)
|
|
|
|
{ return (reverse_mode = enable); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::setReverseMode()
|
|
|
|
{ return setReverseMode(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FLabel::unsetReverseMode()
|
|
|
|
{ return setReverseMode(false); }
|
|
|
|
|
2017-09-20 05:44:41 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::setNumber (uLong num)
|
|
|
|
{ setText(FString().setNumber(num)); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::setNumber (long num)
|
|
|
|
{ setText(FString().setNumber(num)); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::setNumber (float num, int precision)
|
|
|
|
{ setText(FString().setNumber(num, precision)); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::setNumber (double num, int precision)
|
|
|
|
{ setText(FString().setNumber(num, precision)); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::setNumber (lDouble num, int precision)
|
|
|
|
{ setText(FString().setNumber(num, precision)); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FLabel::hasEmphasis() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{ return emphasis; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FLabel::hasReverseMode() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{ return reverse_mode; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-20 05:44:41 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FLabel::clear()
|
|
|
|
{ text.clear(); }
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FLABEL_H
|