FINAL CUT
ftooltip.h
1 /***********************************************************************
2 * ftooltip.h - Widget FToolTip *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2016-2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTerm ▏ ▕ FObject ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲ ▲
30  * │ │
31  * └─────┬─────┘
32  * │
33  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▏
39  * ▕ FWindow ▏
40  * ▕▁▁▁▁▁▁▁▁▁▏
41  * ▲
42  * │
43  * ▕▔▔▔▔▔▔▔▔▔▔▏
44  * ▕ FToolTip ▏
45  * ▕▁▁▁▁▁▁▁▁▁▁▏
46  */
47 
48 #ifndef FTOOLTIP_H
49 #define FTOOLTIP_H
50 
51 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
52  #error "Only <final/final.h> can be included directly."
53 #endif
54 
55 #include <vector>
56 
57 #include "final/widget/fwindow.h"
58 
59 namespace finalcut
60 {
61 
62 //----------------------------------------------------------------------
63 // class FToolTip
64 //----------------------------------------------------------------------
65 
66 class FToolTip : public FWindow
67 {
68  public:
69  // Constructors
70  explicit FToolTip (FWidget* = nullptr);
71  explicit FToolTip (const FString&, FWidget* = nullptr);
72 
73  // Destructor
74  ~FToolTip () override;
75 
76  // Accessors
77  auto getClassName() const -> FString override;
78  auto getText() const -> FString;
79 
80  // Mutators
81  void setText (const FString&);
82  void enableAutoTrim();
83  void disableAutoTrim();
84  void resetColors() override;
85  void setBorder (bool = true);
86  void unsetBorder();
87 
88  // Inquiries
89  auto hasBorder() const -> bool;
90 
91  // Methods
92  void show() override;
93 
94  // Event handler
95  void onMouseDown (FMouseEvent*) override;
96 
97  private:
98  // Methods
99  void init();
100  void draw() override;
101  void calculateDimensions();
102  void initLayout() override;
103  void adjustSize() override;
104 
105  // Data members
106  FString text{};
107  FStringList text_components{};
108  bool text_auto_trim{true};
109  std::size_t max_line_width{0};
110  std::size_t text_num_lines{0};
111 };
112 
113 
114 // FToolTip inline functions
115 //----------------------------------------------------------------------
116 inline auto FToolTip::getClassName() const -> FString
117 { return "FToolTip"; }
118 
119 //----------------------------------------------------------------------
120 inline auto FToolTip::getText() const -> FString
121 { return text; }
122 
123 //----------------------------------------------------------------------
124 inline void FToolTip::enableAutoTrim()
125 { text_auto_trim = true; }
126 
127 //----------------------------------------------------------------------
128 inline void FToolTip::disableAutoTrim()
129 { text_auto_trim = false; }
130 
131 //----------------------------------------------------------------------
132 inline void FToolTip::unsetBorder()
133 { setBorder(false); }
134 
135 //----------------------------------------------------------------------
136 inline auto FToolTip::hasBorder() const -> bool
137 { return ! getFlags().feature.no_border; }
138 
139 } // namespace finalcut
140 
141 #endif // FTOOLTIP_H
Definition: fwindow.h:67
Definition: fevent.h:144
Definition: class_template.cpp:25
Definition: ftooltip.h:66
Definition: fstring.h:79
Definition: fwidget.h:129