ManaPlus
Public Member Functions | Protected Attributes
SetupItemTextField Class Reference

#include <setupitem.h>

Inheritance diagram for SetupItemTextField:
SetupItem ActionListener Widget2

Public Member Functions

 SetupItemTextField (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig, const UseBase64 useBase64)
 
 SetupItemTextField (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const std::string &def, const MainConfig mainConfig, const UseBase64 useBase64)
 
 ~SetupItemTextField ()
 
void createControls ()
 
void fromWidget ()
 
void toWidget ()
 
void action (const ActionEvent &event)
 
void apply (const std::string &eventName)
 
void cancel (const std::string &eventName)
 
void externalUpdated (const std::string &eventName)
 
void rereadValue ()
 
void save ()
 
void setUseBase64 (const UseBase64 b)
 
- Public Member Functions inherited from SetupItem
 ~SetupItem ()
 
void load ()
 
void setWidget (Widget *widget)
 
WidgetgetWidget () const
 
ConfigurationgetConfig () const
 
virtual std::string getActionEventId () const
 
virtual void doAction ()
 
virtual void externalUnloaded (const std::string &eventName)
 
MainConfig isMainConfig () const
 
void fixFirstItemSize (Widget *const widget)
 
void setValue (const std::string &str)
 
std::string getValue () const
 
std::string getEventName () const
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 

Protected Attributes

HorizontContainermHorizont
 
LabelmLabel
 
TextFieldmTextField
 
ButtonmButton
 
EditDialogmEditDialog
 
UseBase64 mUseBase64
 
- Protected Attributes inherited from SetupItem
std::string mText
 
std::string mDescription
 
std::string mKeyName
 
SetupTabScrollmParent
 
std::string mEventName
 
std::string mValue
 
std::string mDefault
 
WidgetmWidget
 
std::list< Widget * > mTempWidgets
 
int mValueType
 
MainConfig mMainConfig
 
bool mUseDefault
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Additional Inherited Members

- Public Types inherited from SetupItem
enum  { VBOOL = 0, VSTR, VINT, VNONE }
 
- Protected Member Functions inherited from SetupItem
 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
 
 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const std::string &def, const MainConfig mainConfig)
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 

Detailed Description

Definition at line 185 of file setupitem.h.

Constructor & Destructor Documentation

◆ SetupItemTextField() [1/2]

SetupItemTextField::SetupItemTextField ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const MainConfig  mainConfig,
const UseBase64  useBase64 
)

Definition at line 274 of file setupitem.cpp.

References createControls(), SetupItem::mValueType, and SetupItem::VSTR.

280  :
281  SetupItem(text, description, keyName, parent, eventName, mainConfig),
282  mHorizont(nullptr),
283  mLabel(nullptr),
284  mTextField(nullptr),
285  mButton(nullptr),
286  mEditDialog(nullptr),
287  mUseBase64(useBase64)
288 {
289  mValueType = VSTR;
290  createControls();
291 }
int mValueType
Definition: setupitem.h:146
Button * mButton
Definition: setupitem.h:235
UseBase64 mUseBase64
Definition: setupitem.h:237
EditDialog * mEditDialog
Definition: setupitem.h:236
TextField * mTextField
Definition: setupitem.h:234
HorizontContainer * mHorizont
Definition: setupitem.h:232
SetupItem(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
Definition: setupitem.cpp:54

◆ SetupItemTextField() [2/2]

SetupItemTextField::SetupItemTextField ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const std::string &  def,
const MainConfig  mainConfig,
const UseBase64  useBase64 
)

Definition at line 293 of file setupitem.cpp.

References createControls(), SetupItem::mValueType, and SetupItem::VSTR.

300  :
301  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
302  mHorizont(nullptr),
303  mLabel(nullptr),
304  mTextField(nullptr),
305  mButton(nullptr),
306  mEditDialog(nullptr),
307  mUseBase64(useBase64)
308 {
309  mValueType = VSTR;
310  createControls();
311 }
int mValueType
Definition: setupitem.h:146
Button * mButton
Definition: setupitem.h:235
UseBase64 mUseBase64
Definition: setupitem.h:237
EditDialog * mEditDialog
Definition: setupitem.h:236
TextField * mTextField
Definition: setupitem.h:234
HorizontContainer * mHorizont
Definition: setupitem.h:232
SetupItem(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
Definition: setupitem.cpp:54

◆ ~SetupItemTextField()

SetupItemTextField::~SetupItemTextField ( )

Definition at line 313 of file setupitem.cpp.

References mButton, mHorizont, mLabel, mTextField, and SetupItem::mWidget.

314 {
315  mHorizont = nullptr;
316  mWidget = nullptr;
317  mTextField = nullptr;
318  mLabel = nullptr;
319  mButton = nullptr;
320 }
Widget * mWidget
Definition: setupitem.h:142
Button * mButton
Definition: setupitem.h:235
TextField * mTextField
Definition: setupitem.h:234
HorizontContainer * mHorizont
Definition: setupitem.h:232

Member Function Documentation

◆ action()

void SetupItemTextField::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Reimplemented from SetupItem.

Definition at line 410 of file setupitem.cpp.

References Widget::addActionListener(), CREATEWIDGETR, fromWidget(), Widget::getActionEventId(), EditDialog::getMsg(), TextField::getText(), mEditDialog, SetupItem::mEventName, Modal_true, SetupItem::mText, mTextField, SetupItem::mWidget, and TextField::setText().

411 {
412  if (mTextField == nullptr)
413  return;
414 
415  const std::string &eventId = event.getId();
416  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
417  {
418  fromWidget();
419  }
420  else if (eventId == mEventName + "_EDIT")
421  {
423  mText,
424  mTextField->getText(),
425  mEventName + "_EDIT_OK",
426  300,
427  nullptr,
428  Modal_true);
430  }
431  else if (eventId == mEventName + "_EDIT_OK")
432  {
434  mEditDialog = nullptr;
435  }
436 }
std::string mEventName
Definition: setupitem.h:136
std::string getMsg() const
Definition: editdialog.h:65
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
const std::string & getActionEventId() const
Definition: widget.h:604
void setText(const std::string &text)
Definition: textfield.cpp:802
Widget * mWidget
Definition: setupitem.h:142
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
EditDialog * mEditDialog
Definition: setupitem.h:236
TextField * mTextField
Definition: setupitem.h:234
const std::string & getText() const
Definition: textfield.h:223
std::string mText
Definition: setupitem.h:128

◆ apply()

void SetupItemTextField::apply ( const std::string &  eventName)
virtual

Reimplemented from SetupItem.

Definition at line 438 of file setupitem.cpp.

References fromWidget(), SetupItem::mEventName, and save().

439 {
440  if (eventName != mEventName)
441  return;
442 
443  fromWidget();
444  save();
445 }
std::string mEventName
Definition: setupitem.h:136

◆ cancel()

void SetupItemTextField::cancel ( const std::string &  eventName)
virtual

Reimplemented from SetupItem.

Definition at line 337 of file setupitem.cpp.

References decodeBase64String(), SetupItem::load(), mUseBase64, SetupItem::mValue, toWidget(), and UseBase64_true.

338 {
339  load();
340  if (mUseBase64 == UseBase64_true)
342  toWidget();
343 }
void load()
Definition: setupitem.cpp:112
std::string decodeBase64String(std::string value)
Definition: base64.cpp:200
std::string mValue
Definition: setupitem.h:138
const bool UseBase64_true
Definition: usebase64.h:29
UseBase64 mUseBase64
Definition: setupitem.h:237

◆ createControls()

void SetupItemTextField::createControls ( )

Definition at line 361 of file setupitem.cpp.

References _, HorizontContainer::add(), VertContainer::add2(), Widget::addActionListener(), SetupTabScroll::addControl(), decodeBase64String(), SetupItem::fixFirstItemSize(), SetupTabScroll::getContainer(), SetupItem::load(), LoseFocusOnTab_true, mButton, SetupItem::mDescription, SetupItem::mEventName, mHorizont, mLabel, SetupItem::mParent, SetupItem::mText, mTextField, mUseBase64, SetupItem::mValue, SetupItem::mWidget, ToolTipListener::setToolTip(), Widget::setWidth(), and UseBase64_true.

Referenced by SetupItemTextField().

362 {
363  load();
364  if (mUseBase64 == UseBase64_true)
366  mHorizont = new HorizontContainer(this, 32, 2);
367 
368  mLabel = new Label(this, mText);
370  mTextField = new TextField(this,
371  mValue,
373  mParent,
374  mEventName,
375  false);
376  // TRANSLATORS: setup item button
377  mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
379  mTextField->setWidth(200);
381  mHorizont->add(mLabel);
384 
385  mParent->getContainer()->add2(mHorizont, true, 4);
386  mParent->addControl(this);
387  mParent->addControl(this, mEventName + "_EDIT");
388  mParent->addControl(this, mEventName + "_EDIT_OK");
389  mParent->addActionListener(this);
390  mWidget->addActionListener(this);
391  mButton->addActionListener(this);
392 }
void load()
Definition: setupitem.cpp:112
#define _(s)
Definition: gettext.h:34
std::string mEventName
Definition: setupitem.h:136
void addControl(SetupItem *const widget)
const bool LoseFocusOnTab_true
void setWidth(const int width)
Definition: widget.cpp:132
std::string decodeBase64String(std::string value)
Definition: base64.cpp:200
std::string mValue
Definition: setupitem.h:138
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
std::string mDescription
Definition: setupitem.h:130
Definition: button.h:94
VertContainer * getContainer() const
void add2(Widget *const widget, const bool resizable, const int spacing)
Definition: label.h:87
Widget * mWidget
Definition: setupitem.h:142
SetupTabScroll * mParent
Definition: setupitem.h:134
const bool UseBase64_true
Definition: usebase64.h:29
void add(Widget *const widget)
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:197
void setToolTip(const std::string &str)
Button * mButton
Definition: setupitem.h:235
UseBase64 mUseBase64
Definition: setupitem.h:237
TextField * mTextField
Definition: setupitem.h:234
HorizontContainer * mHorizont
Definition: setupitem.h:232
std::string mText
Definition: setupitem.h:128

◆ externalUpdated()

void SetupItemTextField::externalUpdated ( const std::string &  eventName)
virtual

Reimplemented from SetupItem.

Definition at line 345 of file setupitem.cpp.

References decodeBase64String(), SetupItem::load(), mUseBase64, SetupItem::mValue, toWidget(), and UseBase64_true.

346 {
347  load();
348  if (mUseBase64 == UseBase64_true)
350  toWidget();
351 }
void load()
Definition: setupitem.cpp:112
std::string decodeBase64String(std::string value)
Definition: base64.cpp:200
std::string mValue
Definition: setupitem.h:138
const bool UseBase64_true
Definition: usebase64.h:29
UseBase64 mUseBase64
Definition: setupitem.h:237

◆ fromWidget()

void SetupItemTextField::fromWidget ( )
virtual

Implements SetupItem.

Definition at line 394 of file setupitem.cpp.

References TextField::getText(), mTextField, and SetupItem::mValue.

Referenced by action(), and apply().

395 {
396  if (mTextField == nullptr)
397  return;
398 
400 }
std::string mValue
Definition: setupitem.h:138
TextField * mTextField
Definition: setupitem.h:234
const std::string & getText() const
Definition: textfield.h:223

◆ rereadValue()

void SetupItemTextField::rereadValue ( )
virtual

Reimplemented from SetupItem.

Definition at line 353 of file setupitem.cpp.

References decodeBase64String(), SetupItem::load(), mUseBase64, SetupItem::mValue, toWidget(), and UseBase64_true.

354 {
355  load();
356  if (mUseBase64 == UseBase64_true)
358  toWidget();
359 }
void load()
Definition: setupitem.cpp:112
std::string decodeBase64String(std::string value)
Definition: base64.cpp:200
std::string mValue
Definition: setupitem.h:138
const bool UseBase64_true
Definition: usebase64.h:29
UseBase64 mUseBase64
Definition: setupitem.h:237

◆ save()

void SetupItemTextField::save ( )
virtual

Reimplemented from SetupItem.

Definition at line 322 of file setupitem.cpp.

References encodeBase64String(), mUseBase64, SetupItem::mValue, SetupItem::save(), STD_MOVE, and UseBase64_true.

Referenced by apply().

323 {
324  if (mUseBase64 == UseBase64_true)
325  {
326  std::string normalValue = mValue;
328  SetupItem::save();
329  mValue = STD_MOVE(normalValue);
330  }
331  else
332  {
333  SetupItem::save();
334  }
335 }
std::string mValue
Definition: setupitem.h:138
const bool UseBase64_true
Definition: usebase64.h:29
#define STD_MOVE(var)
Definition: stdmove.h:27
std::string encodeBase64String(std::string value)
Definition: base64.cpp:185
UseBase64 mUseBase64
Definition: setupitem.h:237
virtual void save()
Definition: setupitem.cpp:145

◆ setUseBase64()

void SetupItemTextField::setUseBase64 ( const UseBase64  b)
inline

Definition at line 228 of file setupitem.h.

229  { mUseBase64 = b; }
UseBase64 mUseBase64
Definition: setupitem.h:237

◆ toWidget()

void SetupItemTextField::toWidget ( )
virtual

Implements SetupItem.

Definition at line 402 of file setupitem.cpp.

References mTextField, SetupItem::mValue, and TextField::setText().

Referenced by cancel(), externalUpdated(), and rereadValue().

403 {
404  if (mTextField == nullptr)
405  return;
406 
408 }
std::string mValue
Definition: setupitem.h:138
void setText(const std::string &text)
Definition: textfield.cpp:802
TextField * mTextField
Definition: setupitem.h:234

Field Documentation

◆ mButton

Button* SetupItemTextField::mButton
protected

Definition at line 235 of file setupitem.h.

Referenced by createControls(), and ~SetupItemTextField().

◆ mEditDialog

EditDialog* SetupItemTextField::mEditDialog
protected

Definition at line 236 of file setupitem.h.

Referenced by action().

◆ mHorizont

HorizontContainer* SetupItemTextField::mHorizont
protected

Definition at line 232 of file setupitem.h.

Referenced by createControls(), and ~SetupItemTextField().

◆ mLabel

Label* SetupItemTextField::mLabel
protected

Definition at line 233 of file setupitem.h.

Referenced by createControls(), and ~SetupItemTextField().

◆ mTextField

TextField* SetupItemTextField::mTextField
protected

Definition at line 234 of file setupitem.h.

Referenced by action(), createControls(), fromWidget(), toWidget(), and ~SetupItemTextField().

◆ mUseBase64

UseBase64 SetupItemTextField::mUseBase64
protected

Definition at line 237 of file setupitem.h.

Referenced by cancel(), createControls(), externalUpdated(), rereadValue(), and save().


The documentation for this class was generated from the following files: