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 186 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 275 of file setupitem.cpp.

281  :
282  SetupItem(text, description, keyName, parent, eventName, mainConfig),
283  mHorizont(nullptr),
284  mLabel(nullptr),
285  mTextField(nullptr),
286  mButton(nullptr),
287  mEditDialog(nullptr),
288  mUseBase64(useBase64)
289 {
290  mValueType = VSTR;
291  createControls();
292 }
EditDialog * mEditDialog
Definition: setupitem.h:237
UseBase64 mUseBase64
Definition: setupitem.h:238
Button * mButton
Definition: setupitem.h:236
TextField * mTextField
Definition: setupitem.h:235
HorizontContainer * mHorizont
Definition: setupitem.h:233
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:55
int mValueType
Definition: setupitem.h:147

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

◆ 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 294 of file setupitem.cpp.

301  :
302  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
303  mHorizont(nullptr),
304  mLabel(nullptr),
305  mTextField(nullptr),
306  mButton(nullptr),
307  mEditDialog(nullptr),
308  mUseBase64(useBase64)
309 {
310  mValueType = VSTR;
311  createControls();
312 }

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

◆ ~SetupItemTextField()

SetupItemTextField::~SetupItemTextField ( )

Definition at line 314 of file setupitem.cpp.

315 {
316  mHorizont = nullptr;
317  mWidget = nullptr;
318  mTextField = nullptr;
319  mLabel = nullptr;
320  mButton = nullptr;
321 }
Widget * mWidget
Definition: setupitem.h:143

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

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 415 of file setupitem.cpp.

416 {
417  if (mTextField == nullptr)
418  return;
419 
420  const std::string &eventId = event.getId();
421  if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
422  {
423  fromWidget();
424  }
425  else if (eventId == mEventName + "_EDIT")
426  {
428  mText,
429  mTextField->getText(),
430  mEventName + "_EDIT_OK",
431  300,
432  nullptr,
433  Modal_true);
435  }
436  else if (eventId == mEventName + "_EDIT_OK")
437  {
439  mEditDialog = nullptr;
440  }
441 }
std::string getMsg() const
Definition: editdialog.h:65
std::string mText
Definition: setupitem.h:129
std::string mEventName
Definition: setupitem.h:137
const std::string & getText() const
Definition: textfield.h:224
void setText(const std::string &text)
Definition: textfield.cpp:803
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
const std::string & getActionEventId() const
Definition: widget.h:605
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
const bool Modal_true
Definition: modal.h:30

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

◆ apply()

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

Reimplemented from SetupItem.

Definition at line 443 of file setupitem.cpp.

444 {
445  if (eventName != mEventName)
446  return;
447 
448  fromWidget();
449  save();
450 }

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

◆ cancel()

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

Reimplemented from SetupItem.

Definition at line 338 of file setupitem.cpp.

339 {
340  load();
341  if (mUseBase64 == UseBase64_true)
343  toWidget();
344 }
std::string decodeBase64String(std::string value)
Definition: base64.cpp:203
std::string mValue
Definition: setupitem.h:139
void load()
Definition: setupitem.cpp:113
const bool UseBase64_true
Definition: usebase64.h:30

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

◆ createControls()

void SetupItemTextField::createControls ( )

Definition at line 362 of file setupitem.cpp.

363 {
364  load();
365  if (mUseBase64 == UseBase64_true)
367  mHorizont = new HorizontContainer(this, 32, 2);
368 
369  mLabel = new Label(this, mText);
371  mTextField = new TextField(this,
372  mValue,
374  mParent,
375  mEventName,
376  false);
377  mButton = new Button(this,
378  // TRANSLATORS: setup item button
379  _("Edit"),
380  mEventName + "_EDIT",
381  BUTTON_SKIN,
382  mParent);
384  mTextField->setWidth(200);
386  mHorizont->add(mLabel);
389 
390  mParent->getContainer()->add2(mHorizont, true, 4);
391  mParent->addControl(this);
392  mParent->addControl(this, mEventName + "_EDIT");
393  mParent->addControl(this, mEventName + "_EDIT_OK");
394  mParent->addActionListener(this);
395  mWidget->addActionListener(this);
396  mButton->addActionListener(this);
397 }
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
void add(Widget *const widget)
Definition: label.h:91
SetupTabScroll * mParent
Definition: setupitem.h:135
std::string mDescription
Definition: setupitem.h:131
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:198
void addControl(SetupItem *const widget)
VertContainer * getContainer() const
void setToolTip(const std::string &str)
void add2(Widget *const widget, const bool resizable, const int spacing)
void setWidth(const int width)
Definition: widget.cpp:133
#define _(s)
Definition: gettext.h:35
const bool LoseFocusOnTab_true

References _, HorizontContainer::add(), VertContainer::add2(), Widget::addActionListener(), SetupTabScroll::addControl(), BUTTON_SKIN, 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().

◆ externalUpdated()

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

Reimplemented from SetupItem.

Definition at line 346 of file setupitem.cpp.

347 {
348  load();
349  if (mUseBase64 == UseBase64_true)
351  toWidget();
352 }

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

◆ fromWidget()

void SetupItemTextField::fromWidget ( )
virtual

Implements SetupItem.

Definition at line 399 of file setupitem.cpp.

400 {
401  if (mTextField == nullptr)
402  return;
403 
405 }

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

Referenced by action(), and apply().

◆ rereadValue()

void SetupItemTextField::rereadValue ( )
virtual

Reimplemented from SetupItem.

Definition at line 354 of file setupitem.cpp.

355 {
356  load();
357  if (mUseBase64 == UseBase64_true)
359  toWidget();
360 }

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

◆ save()

void SetupItemTextField::save ( )
virtual

Reimplemented from SetupItem.

Definition at line 323 of file setupitem.cpp.

324 {
325  if (mUseBase64 == UseBase64_true)
326  {
327  std::string normalValue = mValue;
329  SetupItem::save();
330  mValue = STD_MOVE(normalValue);
331  }
332  else
333  {
334  SetupItem::save();
335  }
336 }
std::string encodeBase64String(std::string value)
Definition: base64.cpp:188
virtual void save()
Definition: setupitem.cpp:146
#define STD_MOVE(var)
Definition: stdmove.h:28

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

Referenced by apply().

◆ setUseBase64()

void SetupItemTextField::setUseBase64 ( const UseBase64  b)
inline

Definition at line 229 of file setupitem.h.

230  { mUseBase64 = b; }

References mUseBase64.

◆ toWidget()

void SetupItemTextField::toWidget ( )
virtual

Implements SetupItem.

Definition at line 407 of file setupitem.cpp.

408 {
409  if (mTextField == nullptr)
410  return;
411 
413 }

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

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

Field Documentation

◆ mButton

Button* SetupItemTextField::mButton
protected

Definition at line 236 of file setupitem.h.

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

◆ mEditDialog

EditDialog* SetupItemTextField::mEditDialog
protected

Definition at line 237 of file setupitem.h.

Referenced by action().

◆ mHorizont

HorizontContainer* SetupItemTextField::mHorizont
protected

Definition at line 233 of file setupitem.h.

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

◆ mLabel

Label* SetupItemTextField::mLabel
protected

Definition at line 234 of file setupitem.h.

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

◆ mTextField

TextField* SetupItemTextField::mTextField
protected

Definition at line 235 of file setupitem.h.

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

◆ mUseBase64

UseBase64 SetupItemTextField::mUseBase64
protected

Definition at line 238 of file setupitem.h.

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


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