ManaPlus
emotewindow.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 #include "gui/models/colormodel.h"
24 #include "gui/models/namesmodel.h"
25 
27 
28 #include "gui/widgets/colorpage.h"
30 #include "gui/widgets/emotepage.h"
31 #include "gui/widgets/scrollarea.h"
32 #include "gui/widgets/tabbedarea.h"
33 
34 #include "utils/delete2.h"
35 #include "utils/foreach.h"
36 #include "utils/gettext.h"
37 
39 
40 #include "resources/imageset.h"
41 
42 #include "resources/db/textdb.h"
43 
44 #include "resources/image/image.h"
45 
46 #include "debug.h"
47 
49 static const int fontSizeListSize = 2;
50 
51 static const char *const fontSizeList[] =
52 {
53  // TRANSLATORS: font size
54  N_("Normal font"),
55  // TRANSLATORS: font size
56  N_("Bold font"),
57 };
58 
60  // TRANSLATORS: emotes window name
61  Window(_("Emotes"), Modal_false, nullptr, "emotes.xml"),
62  mTabs(CREATEWIDGETR(TabbedArea, this)),
63  mEmotePage(new EmotePage(this)),
64  mColorModel(ColorModel::createDefault(this)),
65  mColorPage(CREATEWIDGETR(ColorPage, this, mColorModel, "colorpage.xml")),
66  mScrollColorPage(new ScrollArea(this, mColorPage, Opaque_false,
67  "emotepage.xml")),
68  mFontModel(new NamesModel),
69  mFontPage(CREATEWIDGETR(ListBox, this, mFontModel, "")),
70  mScrollFontPage(new ScrollArea(this, mFontPage, Opaque_false,
71  "fontpage.xml")),
72  mTextModel(new NamesModel),
73  mTextPage(CREATEWIDGETR(ListBox, this, mTextModel, "")),
74  mScrollTextPage(new ScrollArea(this, mTextPage, Opaque_false,
75  "textpage.xml")),
76  mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16))
77 {
78  setShowTitle(false);
79  setResizable(true);
80 
81  if (setupWindow != nullptr)
83 
84  addMouseListener(this);
85 }
86 
88 {
90  const int pad2 = mPadding * 2;
91  const int width = 200;
92  const int height = 150;
93  setWidth(width + pad2);
94  setHeight(height + pad2);
95  add(mTabs);
97  mTabs->setWidth(width);
98  mTabs->setHeight(height);
99  center();
100 
108 
110 
111  mFontPage->setCenter(true);
112  mTextPage->setCenter(true);
113 
114  if ((mImageSet != nullptr) && mImageSet->size() >= 3)
115  {
116  for (int f = 0; f < 3; f ++)
117  {
118  Image *const image = mImageSet->get(f);
119  if (image != nullptr)
120  image->incRef();
121  }
122 
126  }
127  else
128  {
129  // TRANSLATORS: emotes tab name
130  mTabs->addTab(_("Emotes"), mEmotePage);
131  // TRANSLATORS: emotes tab name
132  mTabs->addTab(_("Colors"), mScrollColorPage);
133  // TRANSLATORS: emotes tab name
134  mTabs->addTab(_("Fonts"), mScrollFontPage);
135  }
136  // TRANSLATORS: emotes tab name
137  mTabs->addTab(_("T"), mScrollTextPage);
138 
139  mEmotePage->setActionEventId("emote");
140  mColorPage->setActionEventId("color");
141  mFontPage->setActionEventId("font");
142  mTextPage->setActionEventId("text");
143 }
144 
146 {
147  mTabs->removeAll(false);
159  if (mImageSet != nullptr)
160  {
161  mImageSet->decRef();
162  mImageSet = nullptr;
163  }
164 }
165 
167 {
169  if (dictionary != nullptr)
170  {
171  mTextModel->clear();
172  const STD_VECTOR<std::string> &texts = TextDb::getTexts();
173  FOR_EACH (StringVectCIter, it, texts)
174  {
176  }
177  }
178 }
179 
181 {
183 }
184 
185 std::string EmoteWindow::getSelectedEmote() const
186 {
187  const int index = mEmotePage->getSelectedIndex();
188  if (index < 0)
189  return std::string();
190 
191  char chr[2];
192  chr[0] = CAST_8('0' + index);
193  chr[1] = 0;
194  return std::string("%%").append(&chr[0]);
195 }
196 
198 {
199  const int index = mEmotePage->getSelectedIndex();
201  if (index >= 0)
203 }
204 
205 std::string EmoteWindow::getSelectedColor() const
206 {
207  const int index = mColorPage->getSelected();
208  if (index < 0)
209  return std::string();
210 
211  char chr[2];
212  chr[0] = CAST_8('0' + index);
213  chr[1] = 0;
214  return std::string("##").append(&chr[0]);
215 }
216 
218 {
219  return mTextPage->getSelected();
220 }
221 
223 {
226 }
227 
228 std::string EmoteWindow::getSelectedFont() const
229 {
230  const int index = mFontPage->getSelected();
231  if (index < 0)
232  return std::string();
233 
234  if (index == 0)
235  return "##b";
236  return "##B";
237 }
238 
240 {
241  mFontPage->setSelected(-1);
243 }
244 
246 {
247  mTextPage->setSelected(-1);
249 }
250 
252 {
253  mEmotePage->addActionListener(listener);
254  mColorPage->addActionListener(listener);
255  mFontPage->addActionListener(listener);
256  mTextPage->addActionListener(listener);
257 }
258 
260 {
261  Window::widgetResized(event);
262  const int pad2 = mPadding * 2;
263  const int width = mDimension.width;
264  const int height = mDimension.height;
265 
266  mTabs->setSize(width - pad2, height - pad2);
271  mEmotePage->widgetResized(event);
272 }
273 
274 void EmoteWindow::widgetMoved(const Event &event)
275 {
276  Window::widgetMoved(event);
277  mEmotePage->widgetResized(event);
278 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void clearText()
void setHeight(int height)
Definition: tabbedarea.cpp:754
static const int fontSizeListSize
Definition: emotewindow.cpp:49
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
#define _(s)
Definition: gettext.h:34
int width
Definition: rect.h:218
void setSelected(const int selected)
Definition: listbox.cpp:398
void removeAll(const bool del)
Definition: tabbedarea.cpp:727
void adjustWidget(Widget *const widget) const
Definition: tabbedarea.cpp:264
int getWidth() const
Definition: widget.h:220
void clearColor()
Image * get(const size_type i) const
Definition: imageset.cpp:66
void setWidth(const int width)
Definition: widget.cpp:132
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
ColorModel * mColorModel
Definition: emotewindow.h:75
int mPadding
Definition: window.h:617
const bool Visible_true
Definition: visible.h:29
ListBox * mTextPage
Definition: emotewindow.h:82
#define N_(s)
Definition: gettext.h:35
void widgetMoved(const Event &event)
virtual void decRef()
Definition: resource.cpp:49
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:322
Definition: window.h:98
void setShowTitle(bool flag)
Definition: window.h:234
void clear()
Definition: namesmodel.h:49
void postInit()
Definition: emotewindow.cpp:87
NamesModel * mFontModel
Definition: emotewindow.h:78
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
#define delete2(var)
Definition: delete2.h:24
ScrollArea * mScrollTextPage
Definition: emotewindow.h:83
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
PoDict * dictionary
Definition: podict.cpp:28
const StringVect & getTexts()
Definition: textdb.cpp:91
void registerWindowForReset(Window *const window)
void addListeners(ActionListener *const listener)
void add(const std::string &str)
Definition: namesmodel.h:52
ImageSet * mImageSet
Definition: emotewindow.h:84
#define new
Definition: debug_new.h:147
Tab * getTabByIndex(const int index) const
Definition: tabbedarea.cpp:713
void clearFont()
#define CAST_8
Definition: cast.h:24
void widgetResized(const Event &event)
Definition: window.cpp:650
int getTitlePadding() const
Definition: window.h:601
TabbedArea * mTabs
Definition: emotewindow.h:73
ColorPage * mColorPage
Definition: emotewindow.h:76
void resetAction()
Definition: emotepage.cpp:154
size_type size() const
Definition: imageset.h:72
void clearEmote()
const bool Visible_false
Definition: visible.h:29
EmoteWindow * emoteWindow
Definition: emotewindow.cpp:48
int getSelectedIndex() const
Definition: emotepage.h:58
void widgetResized(const Event &event)
NamesModel * mTextModel
Definition: emotewindow.h:81
void setWidth(int width)
Definition: tabbedarea.cpp:747
virtual void add(Widget *const widget)
int getSelected() const
Definition: listbox.h:167
#define nullptr
Definition: localconsts.h:44
std::string getSelectedEmote() const
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
const bool Opaque_false
Definition: opaque.h:29
Definition: theme.h:52
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void setSize(int width, int height)
Definition: tabbedarea.cpp:761
int height
Definition: rect.h:223
void widgetResized(const Event &event)
Definition: emotepage.cpp:159
void setCenter(const bool b)
Definition: listbox.h:149
std::string getSelectedFont() const
ListBox * mFontPage
Definition: emotewindow.h:79
void widgetMoved(const Event &event)
Definition: window.cpp:715
ScrollArea * mScrollColorPage
Definition: emotewindow.h:77
void setHeight(const int height)
Definition: widget.cpp:139
virtual void incRef()
Definition: resource.cpp:37
virtual void setVisible(Visible visible)
Definition: window.cpp:773
void center()
Definition: window.cpp:1412
static const char *const fontSizeList[]
Definition: emotewindow.cpp:51
void fillFromArray(const char *const *const arr, const std::size_t size)
Definition: namesmodel.cpp:51
Definition: event.h:77
EmotePage * mEmotePage
Definition: emotewindow.h:74
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
void setResizable(const bool resize)
Definition: window.cpp:622
void resetAction()
Definition: colorpage.cpp:109
int getSelectedTextIndex() const
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
void setTitleBarHeight(unsigned int height)
Definition: window.h:512
const std::string getStr(const std::string &str)
Definition: podict.cpp:44
Rect mDimension
Definition: widget.h:1100
int getPadding() const
Definition: window.h:503
void postInit()
Definition: window.cpp:248
ScrollArea * mScrollFontPage
Definition: emotewindow.h:80
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:237
std::string getSelectedColor() const
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)