File indexing completed on 2024-05-19 13:39:56
0001 /* 0002 This file is part of the Okteta KPart module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2004, 2009 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 "browserextension.hpp" 0010 0011 // part 0012 #include "part.hpp" 0013 // Okteta Kasten 0014 #include <Kasten/Okteta/ByteArrayViewProfileSynchronizer> 0015 #include <Kasten/Okteta/ByteArrayView> 0016 #include <Kasten/Okteta/ByteArrayDocument> 0017 // KF 0018 #include <KActionCollection> 0019 // Qt 0020 #include <QClipboard> 0021 #include <QApplication> 0022 #include <QDataStream> 0023 #include <QAction> 0024 0025 OktetaBrowserExtension::OktetaBrowserExtension(OktetaPart* part) 0026 : KParts::BrowserExtension(part) 0027 , mPart(part) 0028 { 0029 setObjectName(QStringLiteral("oktetapartbrowserextension")); 0030 0031 connect(mPart, SIGNAL(hasSelectedDataChanged(bool)), 0032 SLOT(onSelectionChanged(bool))); 0033 0034 Q_EMIT enableAction("copy", false); 0035 Q_EMIT enableAction("print", true); 0036 } 0037 0038 void OktetaBrowserExtension::copy() 0039 { 0040 QMimeData* data = mPart->byteArrayView()->copySelectedData(); 0041 if (!data) { 0042 return; 0043 } 0044 0045 QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard); 0046 } 0047 0048 void OktetaBrowserExtension::print() 0049 { 0050 QAction* printAction = mPart->actionCollection()->action(QStringLiteral("file_print")); 0051 if (printAction) { 0052 printAction->trigger(); 0053 } 0054 } 0055 0056 void OktetaBrowserExtension::onSelectionChanged(bool hasSelection) 0057 { 0058 Q_EMIT enableAction("copy", hasSelection); 0059 } 0060 0061 void OktetaBrowserExtension::saveState(QDataStream& stream) 0062 { 0063 KParts::BrowserExtension::saveState(stream); 0064 0065 Kasten::ByteArrayView* view = mPart->byteArrayView(); 0066 Kasten::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer = view->synchronizer(); 0067 0068 const QString viewProfileId = viewProfileSynchronizer ? viewProfileSynchronizer->viewProfileId() : QString(); 0069 0070 stream 0071 << view->zoomLevel() 0072 0073 << (int)view->offsetColumnVisible() 0074 << view->offsetCoding() 0075 << view->visibleByteArrayCodings() 0076 0077 << (int)view->layoutStyle() 0078 << view->noOfBytesPerLine() 0079 << view->noOfGroupedBytes() 0080 0081 << (int)view->valueCoding() 0082 << view->charCodingName() 0083 << (int)view->showsNonprinting() 0084 // << view->xOffset() << view->yOffset() 0085 << view->cursorPosition() 0086 // << (int)view->isCursorBehind() 0087 // << view->activeCoding() 0088 0089 << view->viewModus() 0090 0091 << viewProfileId 0092 ; 0093 } 0094 0095 void OktetaBrowserExtension::restoreState(QDataStream& stream) 0096 { 0097 KParts::BrowserExtension::restoreState(stream); 0098 0099 double zoomLevel; 0100 0101 int offsetColumnVisible; 0102 int offsetCoding; 0103 int visibleCodings; 0104 0105 int layoutStyle; 0106 int noOfBytesPerLine; 0107 int noOfGroupedBytes; 0108 0109 int valueCoding; 0110 QString charCodingName; 0111 int showsNonprinting; 0112 // int x, y; 0113 int position; 0114 // int cursorBehind; 0115 // int activeCoding; 0116 0117 int viewModus; 0118 0119 QString viewProfileId; 0120 0121 stream 0122 >> zoomLevel 0123 0124 >> offsetColumnVisible 0125 >> offsetCoding 0126 >> visibleCodings 0127 0128 >> layoutStyle 0129 >> noOfBytesPerLine 0130 >> noOfGroupedBytes 0131 0132 >> valueCoding 0133 >> charCodingName 0134 >> showsNonprinting 0135 >> position 0136 // >> cursorBehind 0137 // >> activeCoding 0138 >> viewModus 0139 >> viewProfileId 0140 ; 0141 0142 Kasten::ByteArrayView* view = mPart->byteArrayView(); 0143 0144 Kasten::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer = view->synchronizer(); 0145 if (viewProfileSynchronizer) { 0146 viewProfileSynchronizer->setViewProfileId(viewProfileId); 0147 } 0148 0149 view->setZoomLevel(zoomLevel); 0150 0151 view->setViewModus(viewModus); 0152 0153 view->toggleOffsetColumn(offsetColumnVisible != 0); 0154 view->setOffsetCoding(offsetCoding); 0155 view->setVisibleByteArrayCodings(visibleCodings); 0156 0157 view->setLayoutStyle(layoutStyle); 0158 view->setNoOfBytesPerLine(noOfBytesPerLine); 0159 view->setNoOfGroupedBytes(noOfGroupedBytes); 0160 0161 view->setValueCoding(valueCoding); 0162 view->setCharCoding(charCodingName); 0163 view->setShowsNonprinting(showsNonprinting != 0); 0164 // view->setColumnsPos( x, y ); 0165 view->setCursorPosition(position); // , cursorBehind ); 0166 // view->setActiveCoding( (Okteta::ByteArrayColumnView::CodingTypeId)activeCoding ); 0167 } 0168 0169 #include "moc_browserextension.cpp"