File indexing completed on 2022-09-27 16:31:45

0001 /*
0002     SPDX-FileCopyrightText: 2015-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "environmentplaintextedit.h"
0009 #include <KLocalizedString>
0010 #include <QPaintEvent>
0011 #include <QPainter>
0012 
0013 EnvironmentPlainTextEdit::EnvironmentPlainTextEdit(QWidget *parent)
0014     : QTextEdit(parent)
0015 {
0016 }
0017 
0018 EnvironmentPlainTextEdit::~EnvironmentPlainTextEdit() = default;
0019 
0020 void EnvironmentPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
0021 {
0022     if (document()->isEmpty()) {
0023         return;
0024     }
0025     QTextEdit::contextMenuEvent(event);
0026 }
0027 
0028 void EnvironmentPlainTextEdit::paintEvent(QPaintEvent *event)
0029 {
0030     if (document()->isEmpty()) {
0031         QPainter p(viewport());
0032 
0033         QFont font = p.font();
0034         font.setItalic(true);
0035         p.setFont(font);
0036 
0037         if (!mTextColor.isValid()) {
0038             slotGeneralPaletteChanged();
0039         }
0040         p.setPen(mTextColor);
0041 
0042         p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter, i18n("No rules have been defined in the environment variable \"QT_LOGGING_RULES\"."));
0043     } else {
0044         QTextEdit::paintEvent(event);
0045     }
0046 }
0047 
0048 void EnvironmentPlainTextEdit::slotGeneralPaletteChanged()
0049 {
0050     const QPalette palette = viewport()->palette();
0051     QColor color = palette.text().color();
0052     color.setAlpha(128);
0053     mTextColor = color;
0054 }