modernize: Reformat ALL the source... again!
[quassel.git] / src / qtui / settingspages / itemviewsettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "itemviewsettingspage.h"
22
23 #include <QSignalMapper>
24
25 #include "colorbutton.h"
26 #include "qtui.h"
27 #include "qtuistyle.h"
28
29 ItemViewSettingsPage::ItemViewSettingsPage(QWidget* parent)
30     : SettingsPage(tr("Interface"), tr("Chat & Nick Lists"), parent)
31     , _mapper(new QSignalMapper(this))
32 {
33     ui.setupUi(this);
34
35     _networkItem = new QTreeWidgetItem(ui.bufferViewPreview, QStringList(tr("Network")));
36     _networkItem->setFlags(Qt::NoItemFlags);
37
38     _inactiveBufferItem = new QTreeWidgetItem(_networkItem, QStringList(tr("Inactive")));
39     _defaultBufferItem = new QTreeWidgetItem(_networkItem, QStringList(tr("Normal")));
40     _unreadBufferItem = new QTreeWidgetItem(_networkItem, QStringList(tr("Unread messages")));
41     _highlightedBufferItem = new QTreeWidgetItem(_networkItem, QStringList(tr("Highlight")));
42     _activeBufferItem = new QTreeWidgetItem(_networkItem, QStringList(tr("Other activity")));
43
44     ui.bufferViewPreview->expandAll();
45
46     foreach (ColorButton* button, findChildren<ColorButton*>()) {
47         connect(button, &ColorButton::colorChanged, _mapper, selectOverload<>(&QSignalMapper::map));
48         _mapper->setMapping(button, button);
49     }
50     connect(_mapper, selectOverload<QWidget*>(&QSignalMapper::mapped), this, &ItemViewSettingsPage::updateBufferViewPreview);
51
52     initAutoWidgets();
53 }
54
55 void ItemViewSettingsPage::save()
56 {
57     SettingsPage::save();
58     QtUi::style()->generateSettingsQss();
59     QtUi::style()->reload();
60 }
61
62 void ItemViewSettingsPage::updateBufferViewPreview(QWidget* widget)
63 {
64     auto* button = qobject_cast<ColorButton*>(widget);
65     if (!button)
66         return;
67
68     QString objName = button->objectName();
69     if (objName == "defaultBufferColor") {
70         _networkItem->setForeground(0, button->color());
71         _defaultBufferItem->setForeground(0, button->color());
72     }
73     else if (objName == "inactiveBufferColor")
74         _inactiveBufferItem->setForeground(0, button->color());
75     else if (objName == "activeBufferColor")
76         _activeBufferItem->setForeground(0, button->color());
77     else if (objName == "unreadBufferColor")
78         _unreadBufferItem->setForeground(0, button->color());
79     else if (objName == "highlightedBufferColor")
80         _highlightedBufferItem->setForeground(0, button->color());
81 }