1 //=============================================================================
2 //
3 //   File : OptionsWidget_windowList.cpp
4 //   Creation date : Wed Jan 16 04:30:39 2002 GMT by Szymon Stefanek
5 //
6 //   This file is part of the KVIrc IRC client distribution
7 //   Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
8 //
9 //   This program is FREE software. You can redistribute it and/or
10 //   modify it under the terms of the GNU General Public License
11 //   as published by the Free Software Foundation; either version 2
12 //   of the License, or (at your option) any later version.
13 //
14 //   This program is distributed in the HOPE that it will be USEFUL,
15 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 //   See the GNU General Public License for more details.
18 //
19 //   You should have received a copy of the GNU General Public License
20 //   along with this program. If not, write to the Free Software Foundation,
21 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 //=============================================================================
24 
25 #include "OptionsWidget_windowList.h"
26 
27 #include "kvi_settings.h"
28 #include "KviLocale.h"
29 #define _WANT_OPTION_FLAGS_
30 #include "KviOptions.h"
31 
32 #include <string>
33 #include <vector>
34 
OptionsWidget_windowList(QWidget * parent)35 OptionsWidget_windowList::OptionsWidget_windowList(QWidget * parent)
36     : KviOptionsWidget(parent)
37 {
38 	setObjectName("windowlist_options_widget");
39 	createLayout();
40 
41 	KviTalHBox * hbox = new KviTalHBox(this);
42 	(void)new QLabel(__tr2qs_ctx("Window list type:", "options"), hbox);
43 	m_pWindowListType = new QComboBox(hbox);
44 	m_pWindowListType->addItem(__tr2qs_ctx("Tree", "options"));
45 	m_pWindowListType->addItem(__tr2qs_ctx("Classic", "options"));
46 	m_pWindowListType->setCurrentIndex(KVI_OPTION_BOOL(KviOption_boolUseTreeWindowList) ? 0 : 1);
47 	addWidgetToLayout(hbox, 0, 0, 0, 0);
48 
49 	addBoolSelector(0, 1, 0, 1, __tr2qs_ctx("Sort windows by name", "options"), KviOption_boolSortWindowListItemsByName);
50 	addBoolSelector(0, 2, 0, 2, __tr2qs_ctx("Show window icons in window list", "options"), KviOption_boolUseWindowListIcons);
51 	KviBoolSelector * b = addBoolSelector(0, 3, 0, 3, __tr2qs_ctx("Show activity meter in window list", "options"), KviOption_boolUseWindowListActivityMeter);
52 	mergeTip(b, __tr2qs_ctx("This option enables the usage of the window list activity meter. "
53 	                        "Each window entry will have a small indicator of the activity that is going on in that window. "
54 	                        "The indicator is a small square that changes colors, dark colors mean low activity, "
55 	                        "while bright colors signal high activity. KVIrc also uses some heuristics to determine "
56 	                        "whether the activity is somewhat \"human\" or it is generated by automated entities (such as bots "
57 	                        "or IRC servers). \"Human\" activity causes the indicator to be shaded red while automated "
58 	                        "activity causes the indicator to be shaded blue.", "options"));
59 
60 	addBoolSelector(0, 4, 0, 4, __tr2qs_ctx("Show IRC context indicator in window list", "options"), KviOption_boolUseWindowListIrcContextIndicator);
61 	addBoolSelector(0, 5, 0, 5, __tr2qs_ctx("Enable window tooltips", "options"), KviOption_boolShowWindowListToolTips);
62 	addBoolSelector(0, 6, 0, 6, __tr2qs_ctx("Allow the window list to be moved", "options"), KviOption_boolShowTreeWindowListHandle);
63 	addBoolSelector(0, 7, 0, 7, __tr2qs_ctx("Show user flag for channels", "options"), KviOption_boolShowUserFlagForChannelsInWindowList);
64 
65 	addRowSpacer(0, 8, 0, 8);
66 }
67 
68 OptionsWidget_windowList::~OptionsWidget_windowList()
69     = default;
70 
commit()71 void OptionsWidget_windowList::commit()
72 {
73 	// we need to add this flag manually to the reset list because there's no other
74 	// option in this options widget that uses it.
75 	mergeResetFlag(KviOption_resetUpdateWindowList);
76 	KVI_OPTION_BOOL(KviOption_boolUseTreeWindowList) = (m_pWindowListType->currentIndex() == 0);
77 
78 	KviOptionsWidget::commit();
79 }
80 
OptionsWidget_windowListTree(QWidget * parent)81 OptionsWidget_windowListTree::OptionsWidget_windowListTree(QWidget * parent)
82     : KviOptionsWidget(parent)
83 {
84 	setObjectName("treewindowlist_options_widget");
85 }
86 
87 OptionsWidget_windowListTree::~OptionsWidget_windowListTree()
88     = default;
89 
addAlertLevels(KviOptionsWidget * widget,KviTalGroupBox * g)90 void addAlertLevels(KviOptionsWidget * widget, KviTalGroupBox * g)
91 {
92 	const QString available_options_text = __tr2qs_ctx("The following events trigger this alert level:", "options");
93 	const int alert_levels[5] = {
94 		KviOption_colorTreeWindowListHighlight1Foreground,
95 		KviOption_colorTreeWindowListHighlight2Foreground,
96 		KviOption_colorTreeWindowListHighlight3Foreground,
97 		KviOption_colorTreeWindowListHighlight4Foreground,
98 		KviOption_colorTreeWindowListHighlight5Foreground
99 	};
100 
101 	// Add alert levels 1 through 5
102 	for (int alert_level = KVI_MSGTYPE_MINLEVEL + 1; alert_level < KVI_MSGTYPE_MAXLEVEL + 1; alert_level++)
103 	{
104 		// Add the color selector
105 		QString alert_level_qstr = "Alert level " + QString::number(alert_level) + ":";
106 		QByteArray alert_level_ba = alert_level_qstr.toUtf8();
107 		const int highlight_enum = alert_levels[alert_level - 1];
108 		KviColorSelector * sel = widget->addColorSelector(g, __tr2qs_ctx(alert_level_ba.constData(), "options"), highlight_enum);
109 
110 		// Accumulate all message types for this alert level
111 		std::vector<QString> alert_list;
112 		for (int i = 0; i < KVI_NUM_MSGTYPE_OPTIONS; i++)
113 		{
114 			KviMessageTypeSettingsOption setting = g_msgtypeOptionsTable[i];
115 			if (setting.option.level() == alert_level) {
116 				// Trim the prefix off the setting name and store
117 				alert_list.push_back(setting.name.mid(KVI_MSGTYPE_OPTIONS_PREFIX_LEN));
118 			}
119 		}
120 		std::sort(alert_list.begin(), alert_list.end());
121 
122 		// Create the help text
123 		QString help_text = available_options_text + "<br>";
124 		for (const auto& alert_type : alert_list)
125 		{
126 			if (alert_type != &alert_list.back())
127 				help_text += alert_type + ", ";
128 			else
129 				help_text += alert_type;
130 		}
131 		widget->mergeTip(sel, help_text);
132 	}
133 }
134 
OptionsWidget_windowListTreeForeground(QWidget * parent)135 OptionsWidget_windowListTreeForeground::OptionsWidget_windowListTreeForeground(QWidget * parent)
136     : KviOptionsWidget(parent)
137 {
138 	setObjectName("treewindowlist_options_widget");
139 	createLayout();
140 
141 	addFontSelector(0, 0, 0, 0, __tr2qs_ctx("Font:", "options"), KviOption_fontTreeWindowList);
142 
143 	KviTalGroupBox * g = addGroupBox(0, 1, 0, 1, Qt::Horizontal, __tr2qs_ctx("Text/Alert Colors", "options"));
144 
145 	addColorSelector(g, __tr2qs_ctx("Normal:", "options"), KviOption_colorTreeWindowListForeground);
146 	addColorSelector(g, __tr2qs_ctx("Selected:", "options"), KviOption_colorTreeWindowListActiveForeground);
147 	addAlertLevels(this, g);
148 
149 	addColorSelector(0, 2, 0, 2, __tr2qs_ctx("Progress bar color:", "options"), KviOption_colorTreeWindowListProgress);
150 
151 	addRowSpacer(0, 3, 0, 3);
152 }
153 
154 OptionsWidget_windowListTreeForeground::~OptionsWidget_windowListTreeForeground()
155     = default;
156 
OptionsWidget_windowListTreeBackground(QWidget * parent)157 OptionsWidget_windowListTreeBackground::OptionsWidget_windowListTreeBackground(QWidget * parent)
158     : KviOptionsWidget(parent)
159 {
160 	setObjectName("treewindowlist_options_widget");
161 	createLayout();
162 
163 	KviTalGroupBox * g = addGroupBox(0, 0, 1, 0, Qt::Horizontal, __tr2qs_ctx("Background Colors", "options"));
164 	addColorSelector(g, __tr2qs_ctx("Normal:", "options"), KviOption_colorTreeWindowListBackground);
165 	addColorSelector(g, __tr2qs_ctx("Selected:", "options"), KviOption_colorTreeWindowListActiveBackground);
166 
167 	addPixmapSelector(0, 1, 1, 1, __tr2qs_ctx("Background image:", "options"), KviOption_pixmapTreeWindowListBackground);
168 
169 	addLabel(0, 2, 0, 2, __tr2qs_ctx("Horizontal align:", "options"));
170 	m_pHorizontalAlign = new QComboBox(this);
171 	addWidgetToLayout(m_pHorizontalAlign, 1, 2, 1, 2);
172 
173 	addLabel(0, 3, 0, 3, __tr2qs_ctx("Vertical align:", "options"));
174 	m_pVerticalAlign = new QComboBox(this);
175 	addWidgetToLayout(m_pVerticalAlign, 1, 3, 1, 3);
176 
177 	m_pHorizontalAlign->addItem(__tr2qs_ctx("Tile", "options"));
178 	m_pHorizontalAlign->addItem(__tr2qs_ctx("Left", "options"));
179 	m_pHorizontalAlign->addItem(__tr2qs_ctx("Right", "options"));
180 	m_pHorizontalAlign->addItem(__tr2qs_ctx("Center", "options"));
181 
182 	m_pVerticalAlign->addItem(__tr2qs_ctx("Tile", "options"));
183 	m_pVerticalAlign->addItem(__tr2qs_ctx("Top", "options"));
184 	m_pVerticalAlign->addItem(__tr2qs_ctx("Bottom", "options"));
185 	m_pVerticalAlign->addItem(__tr2qs_ctx("Center", "options"));
186 
187 	switch(KVI_OPTION_UINT(KviOption_uintTreeWindowListPixmapAlign) & Qt::AlignHorizontal_Mask)
188 	{
189 		case Qt::AlignLeft:
190 			m_pHorizontalAlign->setCurrentIndex(1);
191 			break;
192 		case Qt::AlignRight:
193 			m_pHorizontalAlign->setCurrentIndex(2);
194 			break;
195 		case Qt::AlignHCenter:
196 			m_pHorizontalAlign->setCurrentIndex(3);
197 			break;
198 		default:
199 			m_pHorizontalAlign->setCurrentIndex(0);
200 	}
201 
202 	switch(KVI_OPTION_UINT(KviOption_uintTreeWindowListPixmapAlign) & Qt::AlignVertical_Mask)
203 	{
204 		case Qt::AlignTop:
205 			m_pVerticalAlign->setCurrentIndex(1);
206 			break;
207 		case Qt::AlignBottom:
208 			m_pVerticalAlign->setCurrentIndex(2);
209 			break;
210 		case Qt::AlignVCenter:
211 			m_pVerticalAlign->setCurrentIndex(3);
212 			break;
213 		default:
214 			m_pVerticalAlign->setCurrentIndex(0);
215 	}
216 
217 	layout()->setRowStretch(1, 1);
218 }
219 
220 OptionsWidget_windowListTreeBackground::~OptionsWidget_windowListTreeBackground()
221     = default;
222 
commit()223 void OptionsWidget_windowListTreeBackground::commit()
224 {
225 	KviOptionsWidget::commit();
226 
227 	int iFlags = 0;
228 	switch(m_pHorizontalAlign->currentIndex())
229 	{
230 		case 1:
231 			iFlags |= Qt::AlignLeft;
232 			break;
233 		case 2:
234 			iFlags |= Qt::AlignRight;
235 			break;
236 		case 3:
237 			iFlags |= Qt::AlignHCenter;
238 			break;
239 	}
240 	switch(m_pVerticalAlign->currentIndex())
241 	{
242 		case 1:
243 			iFlags |= Qt::AlignTop;
244 			break;
245 		case 2:
246 			iFlags |= Qt::AlignBottom;
247 			break;
248 		case 3:
249 			iFlags |= Qt::AlignVCenter;
250 			break;
251 	}
252 
253 	KVI_OPTION_UINT(KviOption_uintTreeWindowListPixmapAlign) = iFlags;
254 }
255 
OptionsWidget_windowListTreeFeatures(QWidget * parent)256 OptionsWidget_windowListTreeFeatures::OptionsWidget_windowListTreeFeatures(QWidget * parent)
257     : KviOptionsWidget(parent)
258 {
259 	setObjectName("treewindowlist_options_widget");
260 	createLayout();
261 
262 	KviUIntSelector * u;
263 
264 	u = addUIntSelector(0, 1, 0, 1, __tr2qs_ctx("Minimum width:", "options"), KviOption_uintTreeWindowListMinimumWidth, 24, 1024, 125);
265 	u->setSuffix(__tr2qs_ctx(" pixels", "options"));
266 	addBoolSelector(0, 3, 0, 3, __tr2qs_ctx("Mouse wheel changes the active window instead of scrolling the scrollbar", "options"), KviOption_boolWheelScrollsWindowsList);
267 
268 	addRowSpacer(0, 4, 0, 4);
269 }
270 
271 OptionsWidget_windowListTreeFeatures::~OptionsWidget_windowListTreeFeatures()
272     = default;
273 
OptionsWidget_windowListClassic(QWidget * parent)274 OptionsWidget_windowListClassic::OptionsWidget_windowListClassic(QWidget * parent)
275     : KviOptionsWidget(parent)
276 {
277 	setObjectName("classicwindowlist_options_widget");
278 	createLayout();
279 
280 	KviUIntSelector * u;
281 
282 	addFontSelector(0, 0, 0, 0, __tr2qs_ctx("Font:", "options"), KviOption_fontWindowList);
283 	KviTalGroupBox * g = addGroupBox(0, 1, 0, 1, Qt::Horizontal, __tr2qs_ctx("Text/Alert Colors", "options"));
284 	addColorSelector(g, __tr2qs_ctx("Normal:", "options"), KviOption_colorWindowListNormalText);
285 	addColorSelector(g, __tr2qs_ctx("Minimized:", "options"), KviOption_colorWindowListMinimizedText);
286 	addAlertLevels(this, g);
287 
288 	addColorSelector(0, 2, 0, 2, __tr2qs_ctx("Progress bar color:", "options"), KviOption_colorWindowListProgressBar);
289 	u = addUIntSelector(0, 3, 0, 3, __tr2qs_ctx("Minimum width of buttons:", "options"), KviOption_uintWindowListButtonMinWidth, 24, 9999, 100);
290 	u->setSuffix(__tr2qs_ctx(" pixels", "options"));
291 	addBoolSelector(0, 4, 0, 4, __tr2qs_ctx("Set maximum button width", "options"), KviOption_boolClassicWindowListSetMaximumButtonWidth);
292 	u = addUIntSelector(0, 5, 0, 5, __tr2qs_ctx("Maximum width of buttons:", "options"), KviOption_uintClassicWindowListMaximumButtonWidth, 24, 9999, 100);
293 	u->setSuffix(__tr2qs_ctx(" pixels", "options"));
294 	addBoolSelector(0, 6, 0, 6, __tr2qs_ctx("Use flat buttons", "options"), KviOption_boolUseFlatClassicWindowListButtons);
295 	addBoolSelector(0, 7, 0, 7, __tr2qs_ctx("Show close button on window list items", "options"), KviOption_boolUseWindowListCloseButton);
296 
297 	addRowSpacer(0, 8, 0, 8);
298 }
299 
300 OptionsWidget_windowListClassic::~OptionsWidget_windowListClassic()
301     = default;
302