File: setuppagecolors.cpp

package info (click to toggle)
klog 2.4.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,228 kB
  • sloc: cpp: 51,678; makefile: 15
file content (357 lines) | stat: -rw-r--r-- 13,895 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/***************************************************************************
                          setuppagecolors.cpp  -  description
                             -------------------
    begin                : nov 2011
    copyright            : (C) 2011 by Jaime Robles
    email                : jaime@robles.es
 ***************************************************************************/

/*****************************************************************************
 * This file is part of KLog.                                             *
 *                                                                           *
 *    KLog is free software: you can redistribute it and/or modify        *
 *    it under the terms of the GNU General Public License as published by   *
 *    the Free Software Foundation, either version 3 of the License, or      *
 *    (at your option) any later version.                                    *
 *                                                                           *
 *    KLog is distributed in the hope that it will be useful,             *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *    GNU General Public License for more details.                           *
 *                                                                           *
 *    You should have received a copy of the GNU General Public License      *
 *    along with KLog.  If not, see <https://www.gnu.org/licenses/>.       *
 *                                                                           *
 *****************************************************************************/

//#include <QDebug>

#include "setuppagecolors.h"


SetupPageColors::SetupPageColors(QWidget *parent) : QWidget(parent)
{
       //qDebug() << "SetupPageColors::SetupPageColors";

    newOneColorButton = new QPushButton;
    neededColorButton = new QPushButton;
    workedColorButton = new QPushButton;
    confirmedColorButton = new QPushButton;
    defaultColorButton = new QPushButton;
    wsjtxColorButton = new QPushButton;
    klogColorButton = new QPushButton;
    darkModeButton = new QPushButton;

    newOneColorButton->setText(tr("New One"));
    neededColorButton->setText(tr("Needed in this band"));
    workedColorButton->setText(tr("Worked in this band"));
    confirmedColorButton->setText(tr("Confirmed in this band"));
    defaultColorButton->setText(tr("Default"));
    wsjtxColorButton->setText(tr("WSJT-X palette"));
    klogColorButton->setText(tr("Default palette"));
    darkModeButton->setText(tr("Dark Mode"));

    newOneColorButton->setToolTip(tr("Color when the DXCC is an ATNO (All Time New One)."));
    neededColorButton->setToolTip(tr("This DXCC was worked before in another band but not in the selected band. It may be needed due to the CQ, ITU, Grid, ..."));
    workedColorButton->setToolTip(tr("Worked DXCC, but not confirmed in this band."));
    confirmedColorButton->setToolTip(tr("DXCC is confirmed in this band."));
    defaultColorButton->setToolTip(tr("Default color."));
    wsjtxColorButton->setToolTip(tr("Sets a palette of colors similar to the one used in WSJT-X."));
    klogColorButton->setToolTip(tr("Sets the default palette."));
    darkModeButton->setToolTip(tr("Sets the Dark Mode"));

    newOneColorButton->setAutoFillBackground ( true );

    QVBoxLayout *buttonsLayout = new QVBoxLayout;

    buttonsLayout->addWidget(newOneColorButton);
    buttonsLayout->addWidget(neededColorButton);
    buttonsLayout->addWidget(workedColorButton);
    buttonsLayout->addWidget(confirmedColorButton);
    buttonsLayout->addWidget(defaultColorButton);

    QHBoxLayout *schemasLayout = new QHBoxLayout;
    schemasLayout->setSpacing(40);
    schemasLayout->addWidget(wsjtxColorButton);
    schemasLayout->addWidget(klogColorButton);
    schemasLayout->addWidget(darkModeButton);

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addLayout(buttonsLayout, 0, 0);
    mainLayout->addLayout(schemasLayout, 1, 0);
    //setLayout(buttonsLayout);
    setLayout(mainLayout);

    connect(newOneColorButton, SIGNAL(clicked()), this, SLOT(slotNewOneColorButtonClicked()) );
    connect(neededColorButton, SIGNAL(clicked()), this, SLOT(slotNeededColorButtonClicked()) );
    connect(workedColorButton, SIGNAL(clicked()), this, SLOT(slotWorkedColorButtonClicked()) );
    connect(confirmedColorButton, SIGNAL(clicked()), this, SLOT(slotConfirmedColorButtonClicked()) );
    connect(defaultColorButton, SIGNAL(clicked()), this, SLOT(slotDefaultColorButtonClicked()) );
    connect(wsjtxColorButton, SIGNAL(clicked()), this, SLOT(slotWSJTXButtonClicked()) );
    connect(klogColorButton, SIGNAL(clicked()), this, SLOT(slotKLogButtonClicked()) );
    connect(darkModeButton, SIGNAL(clicked()), this, SLOT(slotSetDarkMode()) );

    setDefaultColors();

       //qDebug() << "SetupPageColors::SetupPageColors - END";
}

SetupPageColors::~SetupPageColors()
{;
}

void SetupPageColors::setDefaultColors()
{
    setNewOneColor("#FF0000");
    setNeededColor("#FF8C00");
    setWorkedColor("#FFD700");
    setConfirmedColor("#32CD32");
    setDefaultColor("#00BFFF");
}

void SetupPageColors::setWSJTXColors()
{
    setNewOneColor("#FF00FF");      // New DXCC
    setNeededColor("#FFAAFF");      // New DXCC on Band
    setWorkedColor("#00BFFF");      // Like Default, WSJT-X does not make any difference
    setConfirmedColor("#00BFFF");   // Like Default, WSJT-X does not make any difference
    setDefaultColor("#00BFFF");
}

void SetupPageColors::slotNewOneColorButtonClicked()
{
       //qDebug()  << "SetupPageColors::slotNewOneColorButtonClicked ";
    QString style = "* { background-color: ";
    style = style + (giveColor(newOneColorButton->palette().color(QPalette::Button))).name(QColor::HexRgb);
    style = style + "; }";
    newOneColorButton->setStyleSheet(style);
}

void SetupPageColors::slotNeededColorButtonClicked ()
{
       //qDebug()  << "SetupPageColors::slotNeededColorButtonClicked ";
    QString style = "* { background-color: ";
    style = style + (giveColor(neededColorButton->palette().color(QPalette::Button))).name(QColor::HexRgb);
    style = style + "; }";
    neededColorButton->setStyleSheet(style);
}

void SetupPageColors::slotWorkedColorButtonClicked ()
{
       //qDebug()  << "SetupPageColors::slotWorkedColorButtonClicked ";
    QString style = "* { background-color: ";
    style = style + (giveColor(workedColorButton->palette().color(QPalette::Button))).name(QColor::HexRgb);
    style = style + "; }";
    workedColorButton->setStyleSheet(style);
}

void SetupPageColors::slotConfirmedColorButtonClicked ()
{
       //qDebug()  << "SetupPageColors::slotNeededColorButtonClicked ";
    QString style = "* { background-color: ";
    style = style + (giveColor(confirmedColorButton->palette().color(QPalette::Button))).name(QColor::HexRgb);
    style = style + "; }";
    confirmedColorButton->setStyleSheet(style);
}

void SetupPageColors::slotDefaultColorButtonClicked()
{
       //qDebug()  << "SetupPageColors::slotDefaultColorButtonClicked ";
    QString style = "* { background-color: ";
    style = style + (giveColor(defaultColorButton->palette().color(QPalette::Button))).name(QColor::HexRgb);
    style = style + "; }";
    defaultColorButton->setStyleSheet(style);
}

QColor SetupPageColors::giveColor (QColor c)
{
  // Receives the actual color, shows the user a color picker and returns the color that the user selects.
  QColor colorb;
  color = c;
  colorb = color;
  color = QColorDialog::getColor (color, this, tr("Choose a color"));
  if (color.isValid ())
    {
            //qDebug()  << "SetupPageColors::giveColor valid color: " << color.name(QColor::HexRgb);
      return color;
    }
  else
    {
           //qDebug()  << "SetupPageColors::giveColor NOT valid color";
      return colorb;
    }
}

QString SetupPageColors::getNewOneColor()
{
       //qDebug()  << "SetupPageColors::getNewOneColor: " << (newOneColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
    return (newOneColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
}

QString SetupPageColors::getNeededColor()
{
    return (neededColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
}

QString SetupPageColors::getWorkedColor()
{
    return (workedColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
}

QString SetupPageColors::getConfirmedColor()
{
    return (confirmedColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
}

QString SetupPageColors::getDefaultColor()
{
    return (defaultColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
}

void SetupPageColors::setNewOneColor(const QString &_c)
{
    //qDebug() << Q_FUNC_INFO << ": " << _c;
    QString style = "* { background-color: ";
    style = style + _c;
    style = style + "; }";
    newOneColorButton->setStyleSheet(style);
}

void SetupPageColors::setNeededColor(const QString &_c)
{
    QString style = "* { background-color: ";
    style = style + _c;
    style = style + "; }";
    neededColorButton->setStyleSheet(style);
}

void SetupPageColors::setWorkedColor(const QString &_c)
{
    QString style = "* { background-color: ";
    style = style + _c;
    style = style + "; }";
    workedColorButton->setStyleSheet(style);
}

void SetupPageColors::setConfirmedColor(const QString &_c)
{
    QString style = "* { background-color: ";
    style = style + _c;
    style = style + "; }";
    confirmedColorButton->setStyleSheet(style);
}

void SetupPageColors::setDefaultColor(const QString &_c)
{
    QString style = "* { background-color: ";
    style = style + _c;
    style = style + "; }";
    defaultColorButton->setStyleSheet(style);
}

void SetupPageColors::slotWSJTXButtonClicked()
{
    setWSJTXColors();
}

void SetupPageColors::slotKLogButtonClicked()
{
    setDefaultColors();
}

void SetupPageColors::loadDarkMode()
{// Reads the config to setup the DarkMode
    //qDebug() << Q_FUNC_INFO;
    QSettings settings(util->getCfgFile (), QSettings::IniFormat);
    settings.beginGroup ("Colors");
    setDarkMode (settings.value("DarkMode", false).toBool ());
    settings.endGroup ();
}

void SetupPageColors::slotSetDarkMode()
{
    setDarkMode (!darkMode);
}

QString SetupPageColors::getDarkMode()
{
    //qDebug() << Q_FUNC_INFO;
    return util->boolToQString(darkMode);
}

void SetupPageColors::setDarkMode(const bool _d)
{
    //qDebug() << Q_FUNC_INFO << ": " << util->boolToQString (_d);
    darkMode = _d;
    if (darkMode)
    {
        //QApplication::setStyle(QStyleFactory::create("Fusion"));
        QApplication::setStyle("fusion");

        QPalette p;
        p = qApp->palette();
        p.setColor(QPalette::Window, QColor(53,53,53));
        p.setColor(QPalette::Text, Qt::white);
        p.setColor(QPalette::Button, QColor(53,53,53));
        p.setColor(QPalette::Highlight, QColor(142,45,197));
        p.setColor(QPalette::ButtonText, Qt::white);
        p.setColor(QPalette::WindowText, Qt::white);
        p.setColor(QPalette::Base, QColor(100,100,100));
        p.setColor(QPalette::ToolTipBase, Qt::white);
        p.setColor(QPalette::ToolTipText, Qt::black);
        qApp->setPalette(p);
        darkModeButton->setText(tr("Light Mode"));
        //darkMode = true;
    }
    else
    {
        //QApplication::setStyle(QStyleFactory::create("Fusion"));
        QApplication::setStyle("fusion");
        QPalette p;
        p = qApp->palette();
        p.setColor(QPalette::Window, QColor(244,246,246));
        p.setColor(QPalette::Text, Qt::black);
        p.setColor(QPalette::Button, QColor(234,237,237));
        p.setColor(QPalette::Highlight, QColor(40,120,240));
        p.setColor(QPalette::ButtonText, Qt::black);
        p.setColor(QPalette::WindowText, QColor(33,47,60));
        p.setColor(QPalette::Base, Qt::white);
        p.setColor(QPalette::ToolTipBase, Qt::white);
        p.setColor(QPalette::ToolTipText, Qt::black);
        qApp->setPalette(p);
        darkModeButton->setText(tr("Dark Mode"));
        //darkMode = false;
    }
    emit darkModeChanged(darkMode);
}

void SetupPageColors::saveSettings()
{
    //qDebug() << Q_FUNC_INFO ;
    QSettings settings(util->getCfgFile (), QSettings::IniFormat);
    settings.beginGroup ("Colors");
    //qDebug() << Q_FUNC_INFO << ": Saving NewOneColor: " << (newOneColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb);
    settings.setValue ("NewOneColor", (newOneColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb));
    settings.setValue ("NeededColor", (neededColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb));
    settings.setValue ("WorkedColor", (workedColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb));
    settings.setValue ("ConfirmedColor", (confirmedColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb));
    settings.setValue ("DefaultColor", (defaultColorButton->palette().color(QPalette::Button)).name(QColor::HexRgb));
    settings.setValue ("DarkMode", QVariant(darkMode));
    settings.endGroup ();
}

void SetupPageColors::loadSettings()
{
    //qDebug() << Q_FUNC_INFO;
    QSettings settings(util->getCfgFile (), QSettings::IniFormat);
    settings.beginGroup ("Colors");

    setNewOneColor (settings.value("NewOneColor", "#FF0000").toString ());
    //settings.value("interval").toInt();
    setNeededColor (settings.value("NeededColor", "#FF8C00").toString ());
    setWorkedColor (settings.value("WorkedColor", "#FFD700").toString ());
    setConfirmedColor (settings.value("ConfirmedColor", "#32CD32").toString ());
    setDefaultColor (settings.value("DefaultColor", "#00BFFF").toString ());
    setDarkMode (settings.value("DarkMode", false).toBool ());
    settings.endGroup ();
}