1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2012-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "gui/widgets/tabstrip.h" |
23 |
|
|
|
24 |
|
|
#include "gui/widgets/button.h" |
25 |
|
|
|
26 |
|
|
#include "utils/foreach.h" |
27 |
|
|
|
28 |
|
|
#include "debug.h" |
29 |
|
|
|
30 |
|
3 |
TabStrip::TabStrip(const Widget2 *const widget, |
31 |
|
|
const std::string &group, |
32 |
|
|
const int height, |
33 |
|
3 |
const int spacing) : |
34 |
|
|
WidgetGroup(widget, group, height, spacing), |
35 |
|
3 |
mPressFirst(true) |
36 |
|
|
{ |
37 |
|
3 |
mAllowLogic = false; |
38 |
|
3 |
} |
39 |
|
|
|
40 |
|
2 |
TabStrip::TabStrip(const Widget2 *const widget, |
41 |
|
|
const int height, |
42 |
|
2 |
const int spacing) : |
43 |
|
|
WidgetGroup(widget, "", height, spacing), |
44 |
✓✗ |
8 |
mPressFirst(true) |
45 |
|
|
{ |
46 |
|
2 |
mAllowLogic = false; |
47 |
|
2 |
} |
48 |
|
|
|
49 |
|
24 |
Widget *TabStrip::createWidget(const std::string &text, |
50 |
|
|
const bool pressed) const |
51 |
|
|
{ |
52 |
|
|
Button *const widget = new Button(this, |
53 |
✓✗ |
24 |
BUTTON_SKIN); |
54 |
|
24 |
widget->setStick(true); |
55 |
|
24 |
widget->setCaption(text); |
56 |
|
24 |
widget->adjustSize(); |
57 |
✓✓✗✓ ✗✓ |
24 |
if (((mCount == 0) && mPressFirst) || pressed) |
58 |
|
|
widget->setPressed(true); |
59 |
|
72 |
widget->setTag(CAST_S32(mWidgets.size())); |
60 |
|
24 |
return widget; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
void TabStrip::action(const ActionEvent &event) |
64 |
|
|
{ |
65 |
|
|
WidgetGroup::action(event); |
66 |
|
|
if (event.getSource() != nullptr) |
67 |
|
|
{ |
68 |
|
|
Widget *const widget = event.getSource(); |
69 |
|
|
Button *const button = static_cast<Button*>(widget); |
70 |
|
|
if (button == nullptr) |
71 |
|
|
return; |
72 |
|
|
if (button->isPressed2()) |
73 |
|
|
{ |
74 |
|
|
FOR_EACH (WidgetListConstIterator, iter, mWidgets) |
75 |
|
|
{ |
76 |
|
|
if (*iter != widget) |
77 |
|
|
{ |
78 |
|
|
Button *const button2 = static_cast<Button*>(*iter); |
79 |
|
|
button2->setPressed(false); |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
else |
84 |
|
|
{ |
85 |
|
|
button->setPressed(true); |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
void TabStrip::nextTab() |
91 |
|
|
{ |
92 |
|
|
FOR_EACH (WidgetListConstIterator, iter, mWidgets) |
93 |
|
|
{ |
94 |
|
|
Button *button = static_cast<Button*>(*iter); |
95 |
|
|
if (button->isPressed2()) |
96 |
|
|
{ |
97 |
|
|
button->setPressed(false); |
98 |
|
|
++iter; |
99 |
|
|
if (iter == mWidgets.end()) |
100 |
|
|
iter = mWidgets.begin(); |
101 |
|
|
button = static_cast<Button*>(*iter); |
102 |
|
|
action(ActionEvent(button, button->getActionEventId())); |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
void TabStrip::prevTab() |
109 |
|
|
{ |
110 |
|
|
FOR_EACH (WidgetListConstIterator, iter, mWidgets) |
111 |
|
|
{ |
112 |
|
|
Button *button = static_cast<Button*>(*iter); |
113 |
|
|
if (button->isPressed2()) |
114 |
|
|
{ |
115 |
|
|
button->setPressed(false); |
116 |
|
|
if (iter == mWidgets.begin()) |
117 |
|
|
iter = mWidgets.end(); |
118 |
|
|
if (iter == mWidgets.begin()) |
119 |
|
|
return; |
120 |
|
|
--iter; |
121 |
|
|
button = static_cast<Button*>(*iter); |
122 |
|
|
action(ActionEvent(button, button->getActionEventId())); |
123 |
|
|
return; |
124 |
|
|
} |
125 |
|
|
} |
126 |
✓✗✓✗
|
3 |
} |