1 /*
2 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "levelPrintPage.h"
8
9 #include <KLocalizedString>
10
11 #include <QButtonGroup>
12 #include <QCheckBox>
13 #include <QGridLayout>
14 #include <QLabel>
15
16 #include "ksystemlog_debug.h"
17 #include "logLevel.h"
18 #include "logViewWidgetItem.h"
19
20 #include "globals.h"
21
LevelPrintPage(QWidget * parent)22 LevelPrintPage::LevelPrintPage(QWidget *parent)
23 : QWidget(parent)
24 {
25 setWindowTitle(i18n("Log Level Printing"));
26
27 mPageLayout = new QVBoxLayout(this);
28
29 mLblChoose = new QLabel(this);
30 // m_lblChoose->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0,
31 // m_lblChoose->sizePolicy().hasHeightForWidth() ) );
32 mLblChoose->setText(i18n("Choose which log levels you wish to print in color."));
33 mPageLayout->addWidget(mLblChoose);
34
35 mBtnGroup = new QButtonGroup(this);
36 /*
37 i18n("Log Levels"),
38 m_btnGroup->setColumnLayout(0, Qt::Vertical );
39 m_btnGroup->layout()->setSpacing( 6 );
40 m_btnGroup->layout()->setMargin( 11 );
41 m_btnGroupLayout = new QGridLayout( m_btnGroup->layout() );
42 m_btnGroupLayout->setAlignment( Qt::AlignTop );
43 */
44
45 int row = 0;
46 int col = 0;
47 const auto logLevels = Globals::instance().logLevels();
48 mLevelCheckBoxes.reserve(logLevels.count());
49 for (LogLevel *level : logLevels) {
50 auto button = new QCheckBox(level->name(), this); //, m_btnGroup, 0
51
52 mLevelCheckBoxes.append(button);
53 mBtnGroup->addButton(button, level->id());
54 mBtnGroupLayout->addWidget(button, row, col);
55
56 qCDebug(KSYSTEMLOG) << "name: " << level->name() << " id: " << level->id();
57
58 row++;
59 if (row >= 4) {
60 row = 0;
61 col++;
62 }
63 }
64
65 // m_pageLayout->addWidget(m_btnGroup);
66 }
67
~LevelPrintPage()68 LevelPrintPage::~LevelPrintPage()
69 {
70 // no need to delete child widgets, Qt does it all for us
71 }
72
73 /* QPrinter Port: comment out as dialog page is not currently being used, so not ported
74
75 void LevelPrintPage::getOptions( QMap<QString,QString>& opts, bool incldef ) {
76 foreach(LogLevel* level, Globals::instance().logLevels()) {
77 QString key = "kde-ksystemlog-print_" + level->name();
78
79
80 QCheckBox* checkBox = static_cast<QCheckBox*>(m_btnGroup->find(level->id()));
81 if(checkBox) {
82 if (checkBox->isChecked())
83 opts[ key ] = "1";
84 else
85 opts[ key ] = "0";
86 }
87
88 }
89 }
90
91 void LevelPrintPage::setOptions( const QMap<QString,QString>& opts ) {
92 foreach(LogLevel* level, Globals::instance().logLevels()) {
93 QString key = "kde-ksystemlog-print_" + level->name();
94 QString use = opts[ key ];
95
96 int chk = use.toInt();
97
98
99 QCheckBox* checkBox = static_cast<QCheckBox*>(m_btnGroup->find(level->id()));
100 if(checkBox) {
101 if(chk)
102 checkBox->setChecked(true);
103 else
104 checkBox->setChecked(false);
105 }
106
107
108 }
109 }
110
111 */
112
isValid(QString &)113 bool LevelPrintPage::isValid(QString & /*msg*/)
114 {
115 return true;
116 }
117