File indexing completed on 2025-01-05 05:23:54

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "bytearraytextstreamencoderpreview.hpp"
0010 
0011 // lib
0012 #include "abstractbytearraystreamencoder.hpp"
0013 // KF
0014 #include <KLocalizedString>
0015 // Qt
0016 #include <QFontDatabase>
0017 #include <QTextEdit>
0018 
0019 namespace Kasten {
0020 
0021 ByteArrayTextStreamEncoderPreview::ByteArrayTextStreamEncoderPreview(AbstractByteArrayStreamEncoder* encoder)
0022     : mEncoder(encoder)
0023 {
0024     mWidget = new QTextEdit(); // TODO: use Kate for syntax highlighting
0025     mWidget->setReadOnly(true);
0026     mWidget->setLineWrapMode(QTextEdit::NoWrap);
0027     mWidget->setToolTip(i18n("The preview uses maximal the first 100 bytes."));
0028 
0029     // TODO: find a signal/event emitted when fixedfont changes
0030 //     connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged,
0031 //              this, &ByteArrayTextStreamEncoderPreview::setFixedFontByGlobalSettings );
0032     setFixedFontByGlobalSettings();
0033 
0034     connect(mEncoder, &AbstractByteArrayStreamEncoder::settingsChanged, this, &ByteArrayTextStreamEncoderPreview::update);
0035 }
0036 
0037 ByteArrayTextStreamEncoderPreview::~ByteArrayTextStreamEncoderPreview()
0038 {
0039     delete mWidget;
0040 }
0041 
0042 QWidget* ByteArrayTextStreamEncoderPreview::widget() const { return mWidget; }
0043 
0044 void ByteArrayTextStreamEncoderPreview::setData(AbstractModel* model, const AbstractModelSelection* selection)
0045 {
0046     mModel = model;
0047     mSelection = selection;
0048 
0049     update();
0050 }
0051 
0052 void ByteArrayTextStreamEncoderPreview::update()
0053 {
0054     if (mModel) {
0055         mWidget->setText(mEncoder->previewData(mModel, mSelection));
0056     }
0057 }
0058 
0059 void ByteArrayTextStreamEncoderPreview::setFixedFontByGlobalSettings()
0060 {
0061     mWidget->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
0062 }
0063 
0064 }
0065 
0066 #include "moc_bytearraytextstreamencoderpreview.cpp"