diff --git a/kasten/controllers/document/info/documentinfoview.cpp b/kasten/controllers/document/info/documentinfoview.cpp index 8087e943..337e28cb 100644 --- a/kasten/controllers/document/info/documentinfoview.cpp +++ b/kasten/controllers/document/info/documentinfoview.cpp @@ -1,192 +1,192 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "documentinfoview.hpp" // #include "documentinfotool.hpp" // KF5 #include #include #include #include #include // Qt #include #include #include #include #include #include namespace Kasten { DocumentInfoView::DocumentInfoView(DocumentInfoTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // icon mIconLabel = new QLabel(this); // int bsize = 66 + 2 * mIconLabel->style()->pixelMetric( QStyle::PM_ButtonMargin ); // mIconLabel->setFixedSize(bsize, bsize); mIconLabel->setFixedHeight(KIconLoader::SizeEnormous); mIconLabel->setMinimumWidth(KIconLoader::SizeEnormous); mIconLabel->setAlignment(Qt::AlignHCenter); baseLayout->addWidget(mIconLabel); // file label mDocumentTitleLabel = new QLabel(this); QFont font = mDocumentTitleLabel->font(); font.setBold(true); mDocumentTitleLabel->setFont(font); mDocumentTitleLabel->setAlignment(Qt::AlignHCenter); mDocumentTitleLabel->setWordWrap(true); mDocumentTitleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); baseLayout->addWidget(mDocumentTitleLabel); // separator KSeparator* separator = new KSeparator(Qt::Horizontal, this); baseLayout->addWidget(separator); // property grid auto* propertyGrid = new QGridLayout(); // unknown rows propertyGrid->setColumnStretch(0, 0); propertyGrid->setColumnStretch(1, 1); int currentPropertyRow = 0; // type property QLabel* label = new QLabel(i18n("Type:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); mMimeTypeLabel = new QLabel(QString(), this); propertyGrid->addWidget(mMimeTypeLabel, currentPropertyRow++, 1); // location property label = new QLabel(i18n("Location:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); mLocationLabel = new KSqueezedTextLabel(this); // force the layout direction to be always LTR mLocationLabel->setLayoutDirection(Qt::LeftToRight); // but if we are in RTL mode, align the text to the right // otherwise the text is on the wrong side of the dialog if (layoutDirection() == Qt::RightToLeft) { mLocationLabel->setAlignment(Qt::AlignRight); } // TODO: for some reason if building with enable_final flag the compiler sees // an ambiguous conversion without the explicit Qt::TextInteractionFlags(...) mLocationLabel->setTextInteractionFlags(Qt::TextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)); propertyGrid->addWidget(mLocationLabel, currentPropertyRow++, 1); // size property label = new QLabel(i18n("Size:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); mSizeLabel = new QLabel(this); propertyGrid->addWidget(mSizeLabel, currentPropertyRow++, 1); #if 0 label = new QLabel(i18n("Created/Loaded:"), this); // TODO: make adjustable depending on document propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); currentPropertyRow++; label = new QLabel(i18n("Last modified:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); currentPropertyRow++; label = new QLabel(i18n("Last synchronized:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); currentPropertyRow++; // last accessed from remote KDateTime dt;// = item.time(KFileItem::CreationTime); if (!dt.isNull()) { label = new QLabel(i18n("Created:"), this); propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight); label = new QLabel(KLocale::global()->formatDateTime(dt), this); propertyGrid->addWidget(label, currentPropertyRow++, 2); } #endif baseLayout->addLayout(propertyGrid); baseLayout->addStretch(10); connect(mTool, &DocumentInfoTool::documentTitleChanged, this, &DocumentInfoView::onDocumentTitleChanged); connect(mTool, &DocumentInfoTool::documentMimeTypeChanged, this, &DocumentInfoView::onMimeTypeChanged); connect(mTool, &DocumentInfoTool::locationChanged, this, &DocumentInfoView::onLocationChanged); connect(mTool, &DocumentInfoTool::documentSizeChanged, this, &DocumentInfoView::onDocumentSizeChanged); onDocumentTitleChanged(mTool->documentTitle()); onMimeTypeChanged(mTool->mimeType()); onLocationChanged(mTool->location()); onDocumentSizeChanged(mTool->documentSize()); } DocumentInfoView::~DocumentInfoView() = default; void DocumentInfoView::onDocumentTitleChanged(const QString& documentTitle) { mDocumentTitleLabel->setText(documentTitle); } void DocumentInfoView::onMimeTypeChanged(const QMimeType& mimeType) { QString mimeTypeComment; QPixmap mimeTypeIcon; if (!mimeType.isValid()) { mimeTypeComment = QStringLiteral("-"); // mimeTypeIcon = ? } else { mimeTypeComment = mimeType.comment(); mimeTypeIcon = KIconLoader::global()->loadIcon(mimeType.iconName(), KIconLoader::Desktop, KIconLoader::SizeEnormous); } mIconLabel->setPixmap(mimeTypeIcon); mMimeTypeLabel->setText(mimeTypeComment); } void DocumentInfoView::onLocationChanged(const QString& location) { const QString entry = location.isEmpty() ? i18nc("There is no storage location assigned to yet.", "[None]") : location; mLocationLabel->setText(entry); } void DocumentInfoView::onDocumentSizeChanged(int newSize) { const QString size = (newSize != -1) ? KIO::convertSize(newSize) + QLatin1String(" (") + QLocale().toString(newSize) + QLatin1Char(')') : QStringLiteral("-"); mSizeLabel->setText(size); } } diff --git a/kasten/controllers/view/bookmarks/bookmarksview.cpp b/kasten/controllers/view/bookmarks/bookmarksview.cpp index 6f686d73..bd24ef0b 100644 --- a/kasten/controllers/view/bookmarks/bookmarksview.cpp +++ b/kasten/controllers/view/bookmarks/bookmarksview.cpp @@ -1,203 +1,203 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bookmarksview.hpp" // tool #include "bookmarklistmodel.hpp" #include "bookmarkstool.hpp" // Okteta core #include // KF5 #include #include // Qt #include #include #include #include namespace Kasten { BookmarksView::BookmarksView(BookmarksTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { mBookmarkListModel = new BookmarkListModel(mTool, this); connect(mBookmarkListModel, &BookmarkListModel::modelReset, this, &BookmarksView::onBookmarkSelectionChanged); auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // bookmarks list mBookmarkListView = new QTreeView(this); mBookmarkListView->setObjectName(QStringLiteral("BookmarkListView")); mBookmarkListView->setRootIsDecorated(false); mBookmarkListView->setItemsExpandable(false); mBookmarkListView->setUniformRowHeights(true); mBookmarkListView->setAllColumnsShowFocus(true); mBookmarkListView->setSelectionMode(QAbstractItemView::ExtendedSelection); mBookmarkListView->setModel(mBookmarkListModel); mBookmarkListView->header()->setSectionResizeMode(QHeaderView::Interactive); connect(mBookmarkListView, &QTreeView::doubleClicked, this, &BookmarksView::onBookmarkDoubleClicked); connect(mBookmarkListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &BookmarksView::onBookmarkSelectionChanged); baseLayout->addWidget(mBookmarkListView, 10); // actions TODO: make this view work like the filebrowser, with actions on top? auto* actionsLayout = new QHBoxLayout(); const KGuiItem createBookmarkGuiItem = KGuiItem(QString() /*i18n("C&opy")*/, QStringLiteral("bookmark-new"), i18nc("@info:tooltip", "Creates a new bookmark for the current cursor position."), i18nc("@info:whatsthis", "If you press this button, a new bookmark will be created " "for the current cursor position.")); mCreateBookmarkButton = new QPushButton(this); KGuiItem::assign(mCreateBookmarkButton, createBookmarkGuiItem); mCreateBookmarkButton->setEnabled(mTool->canCreateBookmark()); connect(mCreateBookmarkButton, &QPushButton::clicked, this, &BookmarksView::onCreateBookmarkButtonClicked); connect(mTool, &BookmarksTool::canCreateBookmarkChanged, mCreateBookmarkButton, &QPushButton::setEnabled); actionsLayout->addWidget(mCreateBookmarkButton); const KGuiItem deleteBookmarkGuiItem = KGuiItem(QString() /*i18n("&Go to")*/, QStringLiteral("edit-delete"), i18nc("@info:tooltip", "Deletes all the selected bookmarks."), i18nc("@info:whatsthis", "If you press this button, all bookmarks which are " "selected will be deleted.")); mDeleteBookmarksButton = new QPushButton(this); KGuiItem::assign(mDeleteBookmarksButton, deleteBookmarkGuiItem); connect(mDeleteBookmarksButton, &QPushButton::clicked, this, &BookmarksView::onDeleteBookmarkButtonClicked); actionsLayout->addWidget(mDeleteBookmarksButton); actionsLayout->addStretch(); const KGuiItem gotoGuiItem = KGuiItem(QString() /*i18n("&Go to")*/, QStringLiteral("go-jump"), i18nc("@info:tooltip", "Moves the cursor to the selected bookmark."), i18nc("@info:whatsthis", "If you press this button, the cursor is moved to the position " "of the bookmark which has been last selected.")); mGotoBookmarkButton = new QPushButton(this); KGuiItem::assign(mGotoBookmarkButton, gotoGuiItem); connect(mGotoBookmarkButton, &QPushButton::clicked, this, &BookmarksView::onGotoBookmarkButtonClicked); actionsLayout->addWidget(mGotoBookmarkButton); const KGuiItem renameGuiItem = KGuiItem(QString() /*i18n("&Go to")*/, QStringLiteral("edit-rename"), i18nc("@info:tooltip", "Enables renaming of the selected bookmark."), i18nc("@info:whatsthis", "If you press this button, the name of the bookmark " "which was last selected can be edited.")); mRenameBookmarkButton = new QPushButton(this); KGuiItem::assign(mRenameBookmarkButton, renameGuiItem); connect(mRenameBookmarkButton, &QPushButton::clicked, this, &BookmarksView::onRenameBookmarkButtonClicked); actionsLayout->addWidget(mRenameBookmarkButton); baseLayout->addLayout(actionsLayout); onBookmarkSelectionChanged(); } BookmarksView::~BookmarksView() = default; void BookmarksView::onBookmarkDoubleClicked(const QModelIndex& index) { const int column = index.column(); const bool isOffsetColum = (column == BookmarkListModel::OffsetColumnId); if (isOffsetColum) { mTool->gotoBookmark(mBookmarkListModel->bookmark(index)); } } void BookmarksView::onBookmarkSelectionChanged() { const QItemSelectionModel* selectionModel = mBookmarkListView->selectionModel(); // TODO: selectionModel->selectedIndexes() is a expensive operation, // but with Qt 4.4.3 hasSelection() has the flaw to return true with a current index const bool hasSelection = !selectionModel->selectedIndexes().isEmpty(); mDeleteBookmarksButton->setEnabled(hasSelection); const bool bookmarkSelected = selectionModel->isSelected(selectionModel->currentIndex()); mRenameBookmarkButton->setEnabled(bookmarkSelected); mGotoBookmarkButton->setEnabled(bookmarkSelected); } void BookmarksView::onCreateBookmarkButtonClicked() { const Okteta::Bookmark bookmark = mTool->createBookmark(); if (bookmark.isValid()) { const QModelIndex index = mBookmarkListModel->index(bookmark, BookmarkListModel::TitleColumnId); if (index.isValid()) { mBookmarkListView->edit(index); } } } void BookmarksView::onDeleteBookmarkButtonClicked() { const QModelIndexList selectedRows = mBookmarkListView->selectionModel()->selectedRows(); QVector bookmarksToBeDeleted; bookmarksToBeDeleted.reserve(selectedRows.size()); for (const QModelIndex& index : selectedRows) { const Okteta::Bookmark& bookmark = mBookmarkListModel->bookmark(index); bookmarksToBeDeleted.append(bookmark); } mTool->deleteBookmarks(bookmarksToBeDeleted); } void BookmarksView::onGotoBookmarkButtonClicked() { const QModelIndex index = mBookmarkListView->selectionModel()->currentIndex(); if (index.isValid()) { mTool->gotoBookmark(mBookmarkListModel->bookmark(index)); } } void BookmarksView::onRenameBookmarkButtonClicked() { QModelIndex index = mBookmarkListView->selectionModel()->currentIndex(); const QModelIndex nameIndex = index.sibling(index.row(), BookmarkListModel::TitleColumnId); if (nameIndex.isValid()) { mBookmarkListView->edit(nameIndex); } } } diff --git a/kasten/controllers/view/bytetable/bytetableview.cpp b/kasten/controllers/view/bytetable/bytetableview.cpp index a88d32f6..0909a5af 100644 --- a/kasten/controllers/view/bytetable/bytetableview.cpp +++ b/kasten/controllers/view/bytetable/bytetableview.cpp @@ -1,177 +1,177 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2007,2009 Friedrich W. H. Kossebau Copyright 2011 Alex Richardson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytetableview.hpp" // tool #include "bytetabletool.hpp" #include "bytetablemodel.hpp" #include // KF5 #include #include #include // Qt #include #include #include #include #include #include #include namespace Kasten { ByteTableView::ByteTableView(ByteTableTool* tool, QWidget* parent) : AbstractToolWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mByteTableView = new QTreeView(this); // TODO: find a signal/event emitted when fixedfont changes // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged, // this, &ByteTableView::setFixedFontByGlobalSettings ); // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged, // this, &ByteTableView::resizeColumnsWidth ); // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayStyleChanged, // this, &ByteTableView::resizeColumnsWidth ); setFixedFontByGlobalSettings(); // do this before setting model mByteTableView->setObjectName(QStringLiteral("ByteTable")); mByteTableView->setRootIsDecorated(false); mByteTableView->setItemsExpandable(false); mByteTableView->setUniformRowHeights(true); mByteTableView->setAllColumnsShowFocus(true); mByteTableView->setSortingEnabled(false); QHeaderView* header = mByteTableView->header(); header->setFont(font()); header->setSectionResizeMode(QHeaderView::Interactive); header->setStretchLastSection(false); mByteTableView->setModel(mTool->byteTableModel()); connect(mByteTableView, &QTreeView::doubleClicked, this, &ByteTableView::onDoubleClicked); baseLayout->addWidget(mByteTableView, 10); auto* insertLayout = new QHBoxLayout(); QLabel* label = new QLabel(i18nc("@label:spinbox number of bytes to insert", "Number (bytes):"), this); insertLayout->addWidget(label); mInsertCountEdit = new QSpinBox(this); mInsertCountEdit->setRange(1, INT_MAX); mInsertCountEdit->setValue(1); label->setBuddy(mInsertCountEdit); insertLayout->addWidget(mInsertCountEdit); const QString insertCountToolTip = i18nc("@info:tooltip", "Number of repeats of the currently selected byte in the table to be inserted."); label->setToolTip(insertCountToolTip); mInsertCountEdit->setToolTip(insertCountToolTip); insertLayout->addStretch(); mInsertButton = new QPushButton(this); KGuiItem::assign(mInsertButton, KStandardGuiItem::insert()); mInsertButton->setEnabled(mTool->hasWriteable()); connect(mTool, &ByteTableTool::hasWriteableChanged, mInsertButton, &QPushButton::setEnabled); connect(mInsertButton, &QPushButton::clicked, this, &ByteTableView::onInsertClicked); const QString insertButtonToolTip = i18nc("@info:tooltip", "Insert the currently selected byte in the table repeated the given number of times."); mInsertButton->setToolTip(insertButtonToolTip); addButton(mInsertButton, AbstractToolWidget::Default); insertLayout->addWidget(mInsertButton); baseLayout->addLayout(insertLayout); // if nothing has changed reuse the old values. This means the bytetable is fully constructed // after ~3ms and not 800 as it was before. If the saved values can not be reused it takes ~100ms const QList columnsWidth = ByteTableViewSettings::columnsWidth(); const QString styleName = QApplication::style()->objectName(); const QString fixedFontData = QFontDatabase::systemFont(QFontDatabase::FixedFont).toString(); if (columnsWidth.size() < ByteTableModel::NoOfIds || styleName != ByteTableViewSettings::style() || fixedFontData != ByteTableViewSettings::fixedFont()) { resizeColumnsWidth(); } else { for (int i = 0; i < ByteTableModel::NoOfIds; ++i) { header->resizeSection(i, columnsWidth.at(i)); } } } ByteTableView::~ByteTableView() { QList columnsWidth; columnsWidth.reserve(ByteTableModel::NoOfIds); const QHeaderView* header = mByteTableView->header(); for (int i = 0; i < ByteTableModel::NoOfIds; ++i) { columnsWidth.append(header->sectionSize(i)); } ByteTableViewSettings::setColumnsWidth(columnsWidth); ByteTableViewSettings::setStyle(QApplication::style()->objectName()); ByteTableViewSettings::setFixedFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).toString()); ByteTableViewSettings::self()->save(); } void ByteTableView::resizeColumnsWidth() { QHeaderView* header = mByteTableView->header(); for (int i = 0; i < ByteTableModel::NoOfIds; ++i) { if (i == ByteTableModel::CharacterId) { mByteTableView->resizeColumnToContents(i); continue; } // since all indexes in one row have same number of chars it is enough to calculate one row // this speeds up calculating the width from 800ms to 100ms const QModelIndex index = mTool->byteTableModel()->index(0, i); const int indexWidthHint = mByteTableView->sizeHintForIndex(index).width(); const int headerWidthHint = header->sectionSizeHint(i); header->resizeSection(i, qMax(indexWidthHint, headerWidthHint)); } } void ByteTableView::setFixedFontByGlobalSettings() { mByteTableView->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); } void ByteTableView::onDoubleClicked(const QModelIndex& index) { if (!mTool->hasWriteable()) { return; } const unsigned char byte = index.row(); mTool->insert(byte, mInsertCountEdit->value()); } void ByteTableView::onInsertClicked() { const unsigned char byte = mByteTableView->currentIndex().row(); mTool->insert(byte, mInsertCountEdit->value()); } } diff --git a/kasten/controllers/view/charsetconversion/charsetconversionview.cpp b/kasten/controllers/view/charsetconversion/charsetconversionview.cpp index ea3ed0f4..c934c142 100644 --- a/kasten/controllers/view/charsetconversion/charsetconversionview.cpp +++ b/kasten/controllers/view/charsetconversion/charsetconversionview.cpp @@ -1,238 +1,238 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2011 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "charsetconversionview.hpp" // tool #include "charsetconversiontool.hpp" // Okteta Kasten gui #include // Okteta core #include // KF5 #include #include #include #include // Qt #include #include #include #include #include #include namespace Kasten { CharsetConversionView::CharsetConversionView(CharsetConversionTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // source/target charset auto* directionCharsetLayout = new QHBoxLayout(); mDirectionComboBox = new KComboBox(this); const QStringList directionList { i18nc("@item:inmenu Is converted _from_ charset (selected in combobox next to this)", "From"), i18nc("@item:inmenu Is converted _to_ charset (selected in combobox next to this)", "To"), }; mDirectionComboBox->addItems(directionList); mDirectionComboBox->setCurrentIndex(mTool->conversionDirection()); const QString directionToolTip = i18nc("@info:tooltip", "The direction the bytes are converted, to or from the selected charset."); mDirectionComboBox->setToolTip(directionToolTip); const QString directionWhatsThis = i18nc("@info:whatsthis", "Select the direction the bytes are converted, to or from the selected charset."); mDirectionComboBox->setWhatsThis(directionWhatsThis); connect(mDirectionComboBox, QOverload::of(&KComboBox::activated), mTool, &CharsetConversionTool::setConversionDirection); directionCharsetLayout->addWidget(mDirectionComboBox); mOtherCharSetComboBox = new KComboBox(this); const QStringList charCodecNames = Okteta::CharCodec::codecNames(); const int indexOfCurrentCharCodec = charCodecNames.indexOf(mTool->otherCharCodecName()); mOtherCharSetComboBox->addItems(charCodecNames); mOtherCharSetComboBox->setCurrentIndex(indexOfCurrentCharCodec); const QString targetCharsetToolTip = i18nc("@info:tooltip", "The charset the bytes are converted to."); mOtherCharSetComboBox->setToolTip(targetCharsetToolTip); const QString targetCharsetWhatsThis = i18nc("@info:whatsthis", "Select the charset the bytes are converted to."); mOtherCharSetComboBox->setWhatsThis(targetCharsetWhatsThis); connect(mOtherCharSetComboBox, QOverload::of(&KComboBox::activated), mTool, &CharsetConversionTool::setOtherCharCodecName); directionCharsetLayout->addWidget(mOtherCharSetComboBox, 10); baseLayout->addLayout(directionCharsetLayout); // settings QGroupBox* settingsBox = new QGroupBox(i18nc("@title:group", "Parameters"), this); auto* settingsLayout = new QFormLayout(); const QString substituteMissingCharLabelText = i18nc("@option:check substitute bytes whose char is not part of the target charset", "Substitute missing:"); mSubstituteMissingCharCheckBox = new QCheckBox(this); mSubstituteMissingCharCheckBox->setChecked(mTool->isSubstitutingMissingChars()); const QString substituteMissingCharToolTip = i18nc("@info:tooltip", "Selects if bytes should be substituted with a default byte " "if its char in the source charset is not part of the target charset."); const QString substituteMissingCharWhatsThis = i18nc("@info:whatsthis", "Set to true if bytes should be substituted with a default byte " "if its char in the source charset is not part of the target charset."); mSubstituteMissingCharCheckBox->setToolTip(substituteMissingCharToolTip); mSubstituteMissingCharCheckBox->setWhatsThis(substituteMissingCharWhatsThis); connect(mSubstituteMissingCharCheckBox, &QCheckBox::toggled, mTool, &CharsetConversionTool::setSubstitutingMissingChars); settingsLayout->addRow(substituteMissingCharLabelText, mSubstituteMissingCharCheckBox); // TODO: control what happens on conflicts or unmatched chars in the target set // option to try only if no conflicts or unmatched chars are hit // choosing substitute for unmatched and resolve conflicts (general/case-by-case) // TODO: extra button to request check if all chars are matched, shows state // TODO: option to switch view to target charset, once done, if "to" other charset // default byte const QString substituteByteLabelText = i18nc("@label:textbox byte to use for chars which are not part of the target charset", "Substitute byte:"); mSubstituteByteEdit = new Okteta::ByteArrayComboBox(this); mSubstituteByteEdit->setMinLength(1); mSubstituteByteEdit->setMaxLength(1); const QString substituteByteToolTip = i18nc("@info:tooltip", "The byte to use for chars which are not part of the target charset."); const QString substituteByteWhatsThis = i18nc("@info:whatsthis", "Define the byte to use for chars which are not part of the target charset."); mSubstituteByteEdit->setToolTip(substituteByteToolTip); mSubstituteByteEdit->setWhatsThis(substituteByteWhatsThis); // mSubstituteByteEdit->setEnabled( mTool->isSubstitutingMissingChars() ); mSubstituteByteEdit->setEnabled(false); // TODO: fix char entering and enable again connect(mSubstituteByteEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &CharsetConversionView::onDefaultByteEditChanged); // connect( mSubstituteMissingCharCheckBox, SIGNAL(toggled(bool)), // mSubstituteByteEdit, SLOT(setEnabled(bool)) ); mSubstituteByteEdit->setByteArray(QByteArray(1, mTool->substituteByte())); settingsLayout->addRow(substituteByteLabelText, mSubstituteByteEdit); settingsBox->setLayout(settingsLayout); baseLayout->addWidget(settingsBox); // action auto* actionsLayout = new QHBoxLayout(); actionsLayout->addStretch(); const KGuiItem convertGuiItem = KGuiItem(i18n("Con&vert"), QStringLiteral("run-build"), i18nc("@info:tooltip", "Converts the bytes in the selected range."), xi18nc("@info:whatsthis", "If you press the Convert button, " "all bytes in the selected range " "will be replaced by bytes which represent the same character " "in the selected target charset.")); mConvertButton = new QPushButton(this); KGuiItem::assign(mConvertButton, convertGuiItem); connect(mConvertButton, &QPushButton::clicked, this, &CharsetConversionView::onConvertButtonClicked); actionsLayout->addWidget(mConvertButton); baseLayout->addLayout(actionsLayout); baseLayout->addStretch(); connect(mTool, &CharsetConversionTool::isApplyableChanged, this, &CharsetConversionView::onApplyableChanged); connect(mTool, &CharsetConversionTool::conversionDone, this, &CharsetConversionView::onConversionDone); } CharsetConversionView::~CharsetConversionView() = default; void CharsetConversionView::onApplyableChanged(bool isApplyable) { mConvertButton->setEnabled(isApplyable); } void CharsetConversionView::onDefaultByteEditChanged(const QByteArray& byteArray) { Q_UNUSED(byteArray); } void CharsetConversionView::onConvertButtonClicked() { mTool->convertChars(); } void CharsetConversionView::onConversionDone(bool success, int convertedBytesCount, const QMap& failedPerByteCount) { const QString messageBoxTitle = mTool->title(); if (success) { QString conversionReport = (convertedBytesCount == 0) ? i18nc("@info", "No bytes converted.") : i18ncp("@info", "1 byte converted.", "%1 bytes converted.", convertedBytesCount); if (mTool->isSubstitutingMissingChars()) { int totalFailedByteCount = 0; for (int failedByteCount : failedPerByteCount) { totalFailedByteCount += failedByteCount; } // TODO: show table with failed bytes and their number. conversionReport += QLatin1String("
"); conversionReport += (totalFailedByteCount == 0) ? i18nc("@info", "No bytes substituted.") : i18ncp("@info", "1 byte substituted.", "%1 bytes substituted.", totalFailedByteCount); } KMessageBox::information(/*mParentWidget*/ nullptr, conversionReport, messageBoxTitle); } else { // TODO: show/goto byte which on which conversion fails KMessageBox::sorry(/*mParentWidget*/ nullptr, i18nc("@info", "Conversion cancelled because of chars which are not " "in the target charset."), messageBoxTitle); } } } diff --git a/kasten/controllers/view/checksum/checksumview.cpp b/kasten/controllers/view/checksum/checksumview.cpp index 6d80bf2b..5701cf5c 100644 --- a/kasten/controllers/view/checksum/checksumview.cpp +++ b/kasten/controllers/view/checksum/checksumview.cpp @@ -1,202 +1,202 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "checksumview.hpp" // tool #include "checksumtool.hpp" // lib #include #include #include #include // KF5 #include #include #include // Qt #include #include #include #include #include #include #include #include #include namespace Kasten { ChecksumView::ChecksumView(ChecksumTool* tool, QWidget* parent) : AbstractToolWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // algorithm auto* algorithmLayout = new QHBoxLayout(); QLabel* label = new QLabel(i18nc("@label:listbox algorithm to use for the checksum", "Algorithm:"), this); mAlgorithmComboBox = new KComboBox(this); connect(mAlgorithmComboBox, QOverload::of(&KComboBox::activated), this, &ChecksumView::onOperationChange); label->setBuddy(mAlgorithmComboBox); const QString algorithmWhatsThis = i18nc("@info:whatsthis", "Select the algorithm to use for the checksum."); label->setWhatsThis(algorithmWhatsThis); mAlgorithmComboBox->setWhatsThis(algorithmWhatsThis); algorithmLayout->addWidget(label); algorithmLayout->addWidget(mAlgorithmComboBox, 10); baseLayout->addLayout(algorithmLayout); // parameter QGroupBox* parameterSetBox = new QGroupBox(i18nc("@title:group", "Parameters"), this); baseLayout->addWidget(parameterSetBox); auto* parameterSetLayout = new QVBoxLayout(parameterSetBox); mParameterSetEditStack = new QStackedWidget(parameterSetBox); parameterSetLayout->addWidget(mParameterSetEditStack); // calculate auto* calculateLayout = new QHBoxLayout(); calculateLayout->addStretch(); const KGuiItem updateGuiItem = KGuiItem(i18nc("@action:button calculate the checksum", "&Calculate"), QStringLiteral("run-build"), i18nc("@info:tooltip", "Calculate the checksum for the bytes in the selected range."), xi18nc("@info:whatsthis", "If you press the Calculate button, the list will be updated " "to all strings which are contained in the selected range and have the set minimum length.")); mCalculateButton = new QPushButton(this); KGuiItem::assign(mCalculateButton, updateGuiItem); mCalculateButton->setEnabled(mTool->isApplyable()); connect(mCalculateButton, &QPushButton::clicked, this, &ChecksumView::onCalculateClicked); addButton(mCalculateButton, AbstractToolWidget::Default); calculateLayout->addWidget(mCalculateButton); baseLayout->addLayout(calculateLayout); mChecksumLabel = new QLineEdit(this); mChecksumLabel->setReadOnly(true); mChecksumLabel->setText(mTool->checkSum()); connect(mTool, &ChecksumTool::checksumChanged, mChecksumLabel, &QLineEdit::setText); baseLayout->addWidget(mChecksumLabel, 10); baseLayout->addStretch(10); connect(mTool, &ChecksumTool::uptodateChanged, this, &ChecksumView::onChecksumUptodateChanged); connect(mTool, &ChecksumTool::isApplyableChanged, this, &ChecksumView::onApplyableChanged); // automatically set focus to the parameters if a operation has been selected QAbstractItemView* algorithmComboBoxListView = mAlgorithmComboBox->view(); QObject::connect(algorithmComboBoxListView, &QAbstractItemView::activated, mParameterSetEditStack, QOverload<>::of(&QStackedWidget::setFocus)); // TODO: is a workaround for Qt 4.5.1 which doesn't emit activated() for mouse clicks QObject::connect(algorithmComboBoxListView, &QAbstractItemView::pressed, mParameterSetEditStack, QOverload<>::of(&QStackedWidget::setFocus)); // TODO: goto filter button if there are no parameters addAlgorithms(); } ChecksumView::~ChecksumView() = default; void ChecksumView::addAlgorithms() { // const QVector algorithmList = mTool->algorithmList(); for (AbstractByteArrayChecksumAlgorithm* algorithm : algorithmList) { mAlgorithmComboBox->addItem(algorithm->name()); const char* const parameterSetId = algorithm->parameterSet()->id(); AbstractByteArrayChecksumParameterSetEdit* parameterEdit = ByteArrayChecksumParameterSetEditFactory::createEdit(parameterSetId); mParameterSetEditStack->addWidget(parameterEdit); } onOperationChange(mTool->algorithmId()); } void ChecksumView::getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const { auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { parametersetEdit->getParameterSet(parameterSet); } } void ChecksumView::onCalculateClicked() { AbstractByteArrayChecksumParameterSet* parameterSet = mTool->parameterSet(); if (parameterSet) { getParameterSet(parameterSet); } mTool->calculateChecksum(); } void ChecksumView::onOperationChange(int index) { QWidget* oldWidget = mParameterSetEditStack->currentWidget(); if (oldWidget) { oldWidget->disconnect(this); oldWidget->disconnect(mTool); } mTool->setAlgorithm(index); mParameterSetEditStack->setCurrentIndex(index); auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { connect(parametersetEdit, &AbstractByteArrayChecksumParameterSetEdit::validityChanged, this, &ChecksumView::onValidityChanged); // TODO: hack, see checksum source connect(parametersetEdit, &AbstractByteArrayChecksumParameterSetEdit::valuesChanged, mTool, &ChecksumTool::resetSourceTool); onValidityChanged(parametersetEdit->isValid()); } } void ChecksumView::onChecksumUptodateChanged(bool checksumUptodate) { const bool isApplyable = mTool->isApplyable(); mCalculateButton->setEnabled(!checksumUptodate && isApplyable); } void ChecksumView::onApplyableChanged(bool isApplyable) { mCalculateButton->setEnabled(!mTool->isUptodate() && isApplyable); } void ChecksumView::onValidityChanged(bool isValid) { mCalculateButton->setEnabled(mTool->isApplyable() && isValid); } } diff --git a/kasten/controllers/view/filter/filterview.cpp b/kasten/controllers/view/filter/filterview.cpp index d61bde46..fa42184d 100644 --- a/kasten/controllers/view/filter/filterview.cpp +++ b/kasten/controllers/view/filter/filterview.cpp @@ -1,203 +1,203 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "filterview.hpp" // #include "filtertool.hpp" // filter #include #include #include #include // KF5 #include #include #include // Qt #include #include #include #include #include #include namespace Kasten { FilterView::FilterView(FilterTool* tool, QWidget* parent) : AbstractToolWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // filter auto* operationLayout = new QHBoxLayout(); QLabel* label = new QLabel(i18nc("@label:listbox operation to use by the filter", "Operation:"), this); mOperationComboBox = new KComboBox(this); connect(mOperationComboBox, QOverload::of(&KComboBox::activated), this, &FilterView::onOperationChange); label->setBuddy(mOperationComboBox); const QString operationToolTip = i18nc("@info:tooltip", "The operation to use for the filter."); label->setToolTip(operationToolTip); mOperationComboBox->setToolTip(operationToolTip); const QString operationWhatsThis = i18nc("@info:whatsthis", "Select the operation to use for the filter."); label->setWhatsThis(operationWhatsThis); mOperationComboBox->setWhatsThis(operationWhatsThis); operationLayout->addWidget(label); operationLayout->addWidget(mOperationComboBox, 10); baseLayout->addLayout(operationLayout); QGroupBox* parameterSetBox = new QGroupBox(i18nc("@title:group", "Parameters"), this); baseLayout->addWidget(parameterSetBox); auto* parameterSetLayout = new QVBoxLayout; parameterSetBox->setLayout(parameterSetLayout); mParameterSetEditStack = new QStackedWidget(parameterSetBox); parameterSetLayout->addWidget(mParameterSetEditStack); // filter button auto* buttonLayout = new QHBoxLayout(); buttonLayout->addStretch(10); mFilterButton = new QPushButton(this); KGuiItem::assign(mFilterButton, KGuiItem(i18nc("@action:button", "&Filter"), QStringLiteral("run-build"), i18nc("@info:tooltip", "Executes the filter for the bytes in the selected range."), xi18nc("@info:whatsthis", "If you press the Filter button, the operation you selected " "above is executed for the bytes in the selected range with the given options."))); mFilterButton->setEnabled(mTool->hasWriteable()); connect(mTool, &FilterTool::hasWriteableChanged, this, &FilterView::onHasWriteableChanged); connect(mTool, &FilterTool::charCodecChanged, this, &FilterView::onCharCodecChanged); connect(mFilterButton, &QPushButton::clicked, this, &FilterView::onFilterClicked); addButton(mFilterButton, AbstractToolWidget::Default); buttonLayout->addWidget(mFilterButton); baseLayout->addLayout(buttonLayout); baseLayout->addStretch(10); // automatically set focus to the parameters if a operation has been selected QAbstractItemView* operationComboBoxListView = mOperationComboBox->view(); QObject::connect(operationComboBoxListView, &QAbstractItemView::activated, mParameterSetEditStack, QOverload<>::of(&QStackedWidget::setFocus)); // TODO: is a workaround for Qt 4.5.1 which doesn't emit activated() for mouse clicks QObject::connect(operationComboBoxListView, &QAbstractItemView::pressed, mParameterSetEditStack, QOverload<>::of(&QStackedWidget::setFocus)); // TODO: goto filter button if there are no parameters addFilters(); } FilterView::~FilterView() = default; void FilterView::addFilters() { // const QVector filterList = mTool->filterList(); for (AbstractByteArrayFilter* filter : filterList) { mOperationComboBox->addItem(filter->name()); const char* parameterSetId = filter->parameterSet()->id(); AbstractByteArrayFilterParameterSetEdit* parameterEdit = ByteArrayFilterParameterSetEditFactory::createEdit(parameterSetId); mParameterSetEditStack->addWidget(parameterEdit); } onOperationChange(0); } void FilterView::getParameterSet(AbstractByteArrayFilterParameterSet* parameterSet) const { auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { parametersetEdit->getParameterSet(parameterSet); } } void FilterView::onFilterClicked() { const int filterId = mOperationComboBox->currentIndex(); auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { parametersetEdit->rememberCurrentSettings(); } AbstractByteArrayFilterParameterSet* parameterSet = mTool->parameterSet(filterId); if (parameterSet) { getParameterSet(parameterSet); } mTool->filter(filterId); } void FilterView::onOperationChange(int index) { QWidget* oldWidget = mParameterSetEditStack->currentWidget(); if (oldWidget) { oldWidget->disconnect(this); } mParameterSetEditStack->setCurrentIndex(index); auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { connect(parametersetEdit, &AbstractByteArrayFilterParameterSetEdit::validityChanged, this, &FilterView::onValidityChanged); onValidityChanged(parametersetEdit->isValid()); } } void FilterView::onHasWriteableChanged(bool hasWriteable) { auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); const bool isValid = (parametersetEdit ? parametersetEdit->isValid() : false); mFilterButton->setEnabled(hasWriteable && isValid); } void FilterView::onCharCodecChanged(const QString& charCodecName) { auto* parametersetEdit = qobject_cast(mParameterSetEditStack->currentWidget()); if (parametersetEdit) { parametersetEdit->setCharCodec(charCodecName); } } void FilterView::onValidityChanged(bool isValid) { mFilterButton->setEnabled(mTool->hasWriteable() && isValid); } } diff --git a/kasten/controllers/view/gotooffset/gotooffsetview.cpp b/kasten/controllers/view/gotooffset/gotooffsetview.cpp index ac8b5d1b..6113e154 100644 --- a/kasten/controllers/view/gotooffset/gotooffsetview.cpp +++ b/kasten/controllers/view/gotooffset/gotooffsetview.cpp @@ -1,186 +1,186 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "gotooffsetview.hpp" // tool #include "gotooffsettool.hpp" // Okteta Kasten gui #include #include // KF5 #include #include #include // Qt #include #include #include namespace Kasten { GotoOffsetView::GotoOffsetView(GotoOffsetTool* tool, QWidget* parent) : AbstractToolWidget(parent) , mTool(tool) { auto* baseLayout = new QHBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // offset auto* offsetLayout = new QHBoxLayout(); - offsetLayout->setMargin(0); + offsetLayout->setContentsMargins(0, 0, 0, 0); QLabel* label = new QLabel(i18nc("@label:listbox", "O&ffset:"), this); mAddressEdit = new Okteta::AddressComboBox(this); connect(mAddressEdit, &Okteta::AddressComboBox::addressChanged, mTool, &GotoOffsetTool::setTargetOffset); connect(mAddressEdit, &Okteta::AddressComboBox::formatChanged, this, &GotoOffsetView::onFormatChanged); connect(mAddressEdit, &Okteta::AddressComboBox::addressTypeChanged, this, &GotoOffsetView::onAddressTypeChanged); label->setBuddy(mAddressEdit); const QString inputWhatsThis = i18nc("@info:whatsthis", "Enter an offset to go to, or select a previous offset from the list."); label->setWhatsThis(inputWhatsThis); mAddressEdit->setWhatsThis(inputWhatsThis); offsetLayout->addWidget(label); offsetLayout->addWidget(mAddressEdit, 1); baseLayout->addLayout(offsetLayout, 1); baseLayout->setAlignment(offsetLayout, Qt::AlignTop); setFocusProxy(mAddressEdit); // TODO: see how KDialog does it, e.g. see if there is already a focuswidget as child // options auto* optionsLayout = new QVBoxLayout(); - optionsLayout->setMargin(0); + optionsLayout->setContentsMargins(0, 0, 0, 0); mAtCursorCheckBox = new QCheckBox(i18nc("@option:check", "From c&ursor"), this); mAtCursorCheckBox->setWhatsThis( i18nc("@info:whatsthis", "Go relative from the current cursor location and not absolute.")); connect(mAtCursorCheckBox, &QCheckBox::toggled, mTool, &GotoOffsetTool::setIsRelative); mExtendSelectionCheckBox = new QCheckBox(i18nc("@option:check", "&Extend selection"), this); mExtendSelectionCheckBox->setWhatsThis( i18nc("@info:whatsthis", "Extend the selection by the cursor move.")); connect(mExtendSelectionCheckBox, &QCheckBox::toggled, mTool, &GotoOffsetTool::setIsSelectionToExtent); mBackwardsCheckBox = new QCheckBox(i18nc("@option:check", "&Backwards"), this); mBackwardsCheckBox->setWhatsThis( i18nc("@info:whatsthis", "Go backwards from the end or the current cursor location.")); connect(mBackwardsCheckBox, &QCheckBox::toggled, mTool, &GotoOffsetTool::setIsBackwards); auto* upperOptionsLayout = new QHBoxLayout(); - upperOptionsLayout->setMargin(0); + upperOptionsLayout->setContentsMargins(0, 0, 0, 0); upperOptionsLayout->addWidget(mAtCursorCheckBox); upperOptionsLayout->addWidget(mBackwardsCheckBox); optionsLayout->addLayout(upperOptionsLayout); optionsLayout->addWidget(mExtendSelectionCheckBox); baseLayout->addLayout(optionsLayout); // Goto button const KGuiItem gotoGuiItem = KGuiItem(i18nc("@action:button", "&Go"), QStringLiteral("go-jump"), i18nc("@info:tooltip", "Go to the Offset"), xi18nc("@info:whatsthis", "If you press the Go " "button, the cursor will be moved in the document to or, " "on your option, by the offset you entered above.")); mGotoButton = new QPushButton(this); KGuiItem::assign(mGotoButton, gotoGuiItem); connect(mGotoButton, &QPushButton::clicked, this, &GotoOffsetView::onGotoButtonClicked); addButton(mGotoButton, AbstractToolWidget::Default); baseLayout->addWidget(mGotoButton); baseLayout->setAlignment(mGotoButton, Qt::AlignTop); setTabOrder(mAddressEdit, mAtCursorCheckBox); setTabOrder(mAtCursorCheckBox, mBackwardsCheckBox); setTabOrder(mBackwardsCheckBox, mExtendSelectionCheckBox); setTabOrder(mExtendSelectionCheckBox, mGotoButton); connect(mTool, &GotoOffsetTool::isApplyableChanged, this, &GotoOffsetView::onApplyableChanged); onApplyableChanged(mTool->isApplyable()); } GotoOffsetView::~GotoOffsetView() = default; void GotoOffsetView::onApplyableChanged(bool isApplyable) { // TODO: set error tooltip, like offset out of range or no document // TODO: set color flag to offset input mGotoButton->setEnabled(isApplyable); } void GotoOffsetView::onGotoButtonClicked() { // TODO: collect recently used offset in tool instead? mAddressEdit->rememberCurrentAddress(); mTool->gotoOffset(); // emit toolUsed(); } void GotoOffsetView::onAddressTypeChanged(int addressType) { const bool isNotExpression = (mAddressEdit->format() != 2); if (isNotExpression || addressType == Okteta::AddressValidator::InvalidAddressType) { return; } bool fromCursor = false; bool backwards = false; if (addressType == Okteta::AddressValidator::AbsoluteAddress) { fromCursor = false; backwards = false; // TODO: there is no way yet for: absolute from end } else if (addressType == Okteta::AddressValidator::RelativeForwards) { fromCursor = true; backwards = false; } else if (addressType == Okteta::AddressValidator::RelativeBackwards) { fromCursor = true; backwards = true; } mAtCursorCheckBox->setChecked(fromCursor); mTool->setIsRelative(fromCursor); mBackwardsCheckBox->setChecked(backwards); mTool->setIsBackwards(backwards); } void GotoOffsetView::onFormatChanged(int formatIndex) { // TODO: make sure Expr is always at index 2 const bool isNotExpression = (formatIndex != 2); mAtCursorCheckBox->setEnabled(isNotExpression); mBackwardsCheckBox->setEnabled(isNotExpression); } } diff --git a/kasten/controllers/view/info/infoview.cpp b/kasten/controllers/view/info/infoview.cpp index 3ec5d41a..fb425269 100644 --- a/kasten/controllers/view/info/infoview.cpp +++ b/kasten/controllers/view/info/infoview.cpp @@ -1,175 +1,175 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "infoview.hpp" // tool #include "infotool.hpp" #include "statistictablemodel.hpp" #include // KF5 #include #include // Qt #include #include #include #include #include #include #include #include #include namespace Kasten { InfoView::InfoView(InfoTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); auto* topLineLayout = new QHBoxLayout(); QLabel* label = new QLabel(i18nc("@label size of selected bytes", "Size:"), this); topLineLayout->addWidget(label); mSizeLabel = new QLabel(this); const QString sizeToolTip = i18nc("@info:tooltip", "The number of the bytes the statistic was built for."); label->setToolTip(sizeToolTip); mSizeLabel->setToolTip(sizeToolTip); topLineLayout->addWidget(mSizeLabel, 10); connect(mTool->statisticTableModel(), &StatisticTableModel::sizeChanged, this, &InfoView::setByteArraySize); topLineLayout->addStretch(); const KGuiItem updateGuiItem = KGuiItem(i18nc("@action:button build the statistic of the byte frequency", "&Build"), QStringLiteral("run-build"), i18nc("@info:tooltip", "Builds the byte frequency statistic for the bytes in the selected range."), xi18nc("@info:whatsthis", "If you press the Build button," " the byte frequency statistic is built for the bytes in the selected range.")); mUpdateButton = new QPushButton(this); KGuiItem::assign(mUpdateButton, updateGuiItem); mUpdateButton->setEnabled(mTool->isApplyable()); connect(mTool, &InfoTool::isApplyableChanged, mUpdateButton, &QPushButton::setEnabled); connect(mUpdateButton, &QPushButton::clicked, mTool, &InfoTool::updateStatistic); topLineLayout->addWidget(mUpdateButton); baseLayout->addLayout(topLineLayout); mStatisticTableView = new QTreeView(this); // TODO: find a signal/event emitted when fixedfont changes // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged, // this, &InfoView::setFixedFontByGlobalSettings ); // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged, // this, &InfoView::resizeColumnsWidth ); // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayStyleChanged, // this, &InfoView::resizeColumnsWidth ); setFixedFontByGlobalSettings(); // do this before setting model mStatisticTableView->setObjectName(QStringLiteral("StatisticTable")); mStatisticTableView->setRootIsDecorated(false); mStatisticTableView->setItemsExpandable(false); mStatisticTableView->setUniformRowHeights(true); mStatisticTableView->setAllColumnsShowFocus(true); mStatisticTableView->setSortingEnabled(true); QHeaderView* header = mStatisticTableView->header(); header->setFont(font()); header->setSectionResizeMode(QHeaderView::Interactive); header->setStretchLastSection(false); // TODO: write subclass to filter count and percent by num, not string auto* proxyModel = new QSortFilterProxyModel(this); proxyModel->setDynamicSortFilter(true); proxyModel->setSourceModel(mTool->statisticTableModel()); mStatisticTableView->setModel(proxyModel); mStatisticTableView->sortByColumn(StatisticTableModel::CountId, Qt::DescendingOrder); connect(mTool->statisticTableModel(), &StatisticTableModel::headerChanged, this, &InfoView::updateHeader); baseLayout->addWidget(mStatisticTableView, 10); setByteArraySize(mTool->size()); // if nothing has changed reuse the old values. This means the info view is fully constructed much quicker. const QList columnsWidth = InfoViewSettings::columnsWidth(); const QString styleName = QApplication::style()->objectName(); const QString fixedFontData = QFontDatabase::systemFont(QFontDatabase::FixedFont).toString(); if (columnsWidth.size() < StatisticTableModel::NoOfIds || styleName != InfoViewSettings::style() || fixedFontData != InfoViewSettings::fixedFont()) { resizeColumnsWidth(); } else { for (int i = 0; i < StatisticTableModel::NoOfIds; ++i) { header->resizeSection(i, columnsWidth.at(i)); } } } InfoView::~InfoView() { QList columnsWidth; columnsWidth.reserve(StatisticTableModel::NoOfIds); const QHeaderView* header = mStatisticTableView->header(); for (int i = 0; i < StatisticTableModel::NoOfIds; ++i) { columnsWidth.append(header->sectionSize(i)); } InfoViewSettings::setColumnsWidth(columnsWidth); InfoViewSettings::setStyle(QApplication::style()->objectName()); InfoViewSettings::setFixedFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).toString()); InfoViewSettings::self()->save(); } void InfoView::updateHeader() { mStatisticTableView->resizeColumnToContents(StatisticTableModel::ValueId); mStatisticTableView->header()->headerDataChanged(Qt::Horizontal, StatisticTableModel::ValueId, StatisticTableModel::ValueId); } void InfoView::resizeColumnsWidth() { for (int i = 0; i < StatisticTableModel::NoOfIds; ++i) { mStatisticTableView->resizeColumnToContents(i); } } void InfoView::setByteArraySize(int size) { const QString sizeText = (size < 1) ? // -1 is default, 0 should not happen QStringLiteral("-") : i18np("1 byte", "%1 bytes", size); mSizeLabel->setText(sizeText); } void InfoView::setFixedFontByGlobalSettings() { mStatisticTableView->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); } } diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/modsumbytearraychecksumparametersetedit.cpp b/kasten/controllers/view/libbytearraychecksum/algorithm/modsumbytearraychecksumparametersetedit.cpp index e3a5dc97..47c921ef 100644 --- a/kasten/controllers/view/libbytearraychecksum/algorithm/modsumbytearraychecksumparametersetedit.cpp +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/modsumbytearraychecksumparametersetedit.cpp @@ -1,76 +1,76 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "modsumbytearraychecksumparametersetedit.hpp" // parameterset #include "modsumbytearraychecksumparameterset.hpp" // KF5 #include #include // Qt #include const char ModSumByteArrayChecksumParameterSetEdit::Id[] = "ModSum"; ModSumByteArrayChecksumParameterSetEdit::ModSumByteArrayChecksumParameterSetEdit(QWidget* parent) : AbstractByteArrayChecksumParameterSetEdit(parent) { auto* baseLayout = new QFormLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mByteOrderComboBox = new KComboBox(this); mByteOrderComboBox->addItem(i18nc("@item:inlistbox", "Little-endian")); // add first for index mByteOrderComboBox->addItem(i18nc("@item:inlistbox", "Big-endian")); // add second for index connect(mByteOrderComboBox, QOverload::of(&KComboBox::activated), this, &ModSumByteArrayChecksumParameterSetEdit::valuesChanged); const QString byteOrderLabelText = i18nc("@label:listbox byte order to use for decoding the bytes into integer values", "Byte Order:"); const QString groupSizeToolTip = i18nc("@info:tooltip", "The byte order to use for decoding the bytes into integer values."); mByteOrderComboBox->setToolTip(groupSizeToolTip); baseLayout->addRow(byteOrderLabelText, mByteOrderComboBox); } ModSumByteArrayChecksumParameterSetEdit::~ModSumByteArrayChecksumParameterSetEdit() = default; bool ModSumByteArrayChecksumParameterSetEdit::isValid() const { return true; } void ModSumByteArrayChecksumParameterSetEdit::setParameterSet(const AbstractByteArrayChecksumParameterSet* parameterSet) { const auto* modSumParameterSet = static_cast(parameterSet); mByteOrderComboBox->setCurrentIndex(modSumParameterSet->endianness()); } void ModSumByteArrayChecksumParameterSetEdit::getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const { auto* modSumParameterSet = static_cast(parameterSet); modSumParameterSet->setEndianness(static_cast(mByteOrderComboBox->currentIndex())); } diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/template/template_bytearraychecksumparametersetedit.cpp b/kasten/controllers/view/libbytearraychecksum/algorithm/template/template_bytearraychecksumparametersetedit.cpp index 52220942..b1ef0c91 100644 --- a/kasten/controllers/view/libbytearraychecksum/algorithm/template/template_bytearraychecksumparametersetedit.cpp +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/template/template_bytearraychecksumparametersetedit.cpp @@ -1,117 +1,117 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau Public domain. */ //// ADAPT(start) //// rename "template_bytearraychecksumparametersetedit.hpp" to the name of the header of your filter, //// e.g. "mybytearraychecksumparametersetedit.hpp" #include "template_bytearraychecksumparametersetedit.hpp" //// ADAPT(end) // parameterset //// ADAPT(start) //// rename "template_bytearraychecksumparameterset.hpp" to the name of the header of your filter, //// e.g. "mybytearraychecksumparameterset.hpp" #include "template_bytearraychecksumparameterset.hpp" //// ADAPT(end) // KF5 #include //// ADAPT(start) //// add includes for all elements used in the widget #include // Qt #include //// ADAPT(end) //// ADAPT(start) //// rename "Template_ParameterSetId" to the id of your parameterset, //// e.g. "MyParameterSet" const char Template_ByteArrayChecksumParameterSetEdit::Id[] = "Template_ParameterSetId"; //// ADAPT(end) Template_ByteArrayChecksumParameterSetEdit::Template_ByteArrayChecksumParameterSetEdit(QWidget* parent) : AbstractByteArrayChecksumParameterSetEdit(parent) { //// ADAPT(start) //// setup the widget with all edit fields needed for the parameter set //// if there can be invalid states connect the change signals of the edit fields to some slots //// where you check if the validity changed auto* baseLayout = new QFormLayout(this); // margin is provided by the container for this widget - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mBitNumberEdit = new QSpinBox(this); // For demonstration purpose we start at 0, not 1, to show handling of an invalid state // Otherwise the range should start at 1 and there is no need to connect to the valueChanged signal mBitNumberEdit->setRange(0, 8); // start with the invalid number mBitNumberEdit->setValue(0); connect(mBitNumberEdit, QOverload::of(&QSpinBox::valueChanged), this, &Template_ByteArrayChecksumParameterSetEdit::onBitNumberChanged); const QString levelLabelText = i18nc("@label:spinbox number of the bit to use", "Number of bit:"); const QString levelToolTip = i18nc("@info:tooltip", "The number of the bit to use for the parity calculation. 1 means the LSB, 8 the MSB."); mBitNumberEdit->setToolTip(levelToolTip); const QString levelWhatsThis = i18nc("@info:whatsthis", "Select the bit which should be used for the parity calculation. And more explanation."); mBitNumberEdit->setWhatsThis(levelWhatsThis); baseLayout->addRow(levelLabelText, mBitNumberEdit); // note start state mIsValid = isValid(); //// ADAPT(end) } Template_ByteArrayChecksumParameterSetEdit::~Template_ByteArrayChecksumParameterSetEdit() = default; //// ADAPT(start) //// if invalid states are possible implement here the check bool Template_ByteArrayChecksumParameterSetEdit::isValid() const { return mBitNumberEdit->value() != 0; } //// ADAPT(end) //// ADAPT(start) //// change "Template_ByteArrayFilterParameterSet" to the class of the parameter set which this widget should edit //// e.g. "MyByteArrayFilterParameterSet" //// also adapt the passing of the values between the parameter set and the edit fields void Template_ByteArrayChecksumParameterSetEdit::setParameterSet(const AbstractByteArrayChecksumParameterSet* parameterSet) { const auto* template_ParameterSet = static_cast(parameterSet); mBitNumberEdit->setValue(template_ParameterSet->bitNumber()); } void Template_ByteArrayChecksumParameterSetEdit::getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const { auto* template_ParameterSet = static_cast(parameterSet); template_ParameterSet->setBitNumber(mBitNumberEdit->value()); } //// ADAPT(end) //// ADAPT(start) //// define the slots to catch changes in the values to check if the current state is valid or not //// not needed if there cannot be invalid states void Template_ByteArrayChecksumParameterSetEdit::onBitNumberChanged(int value) { const bool isValid = (value != 0); if (mIsValid == isValid) { return; } mIsValid = isValid; emit validityChanged(isValid); } //// ADAPT(end) diff --git a/kasten/controllers/view/libbytearrayfilter/filter/operandbytearrayfilterparametersetedit.cpp b/kasten/controllers/view/libbytearrayfilter/filter/operandbytearrayfilterparametersetedit.cpp index 6fe96a86..d63a955b 100644 --- a/kasten/controllers/view/libbytearrayfilter/filter/operandbytearrayfilterparametersetedit.cpp +++ b/kasten/controllers/view/libbytearrayfilter/filter/operandbytearrayfilterparametersetedit.cpp @@ -1,111 +1,111 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "operandbytearrayfilterparametersetedit.hpp" // #include "operandbytearrayfilterparameterset.hpp" // Okteta Kasten gui #include // KF5 #include // Qt #include #include const char OperandByteArrayFilterParameterSetEdit::Id[] = "Operand"; OperandByteArrayFilterParameterSetEdit::OperandByteArrayFilterParameterSetEdit(QWidget* parent) : AbstractByteArrayFilterParameterSetEdit(parent) { auto* baseLayout = new QFormLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); const QString operandLabelText = i18nc("@label:textbox operand to the arithmetic filter function", "Operand:"); mOperandEdit = new Okteta::ByteArrayComboBox(this); connect(mOperandEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &OperandByteArrayFilterParameterSetEdit::onInputChanged); const QString operandToolTip = i18nc("@info:tooltip", "The operand to do the operation with."); const QString operandWhatsThis = i18nc("@info:whatsthis", "Enter an operand, or select a previous operand from the list."); mOperandEdit->setToolTip(operandToolTip); mOperandEdit->setWhatsThis(operandWhatsThis); baseLayout->addRow(operandLabelText, mOperandEdit); const QString alignAtEndLabelText = i18nc("@option:check", "Align at end:"); mAlignAtEndCheckBox = new QCheckBox(this); mAlignAtEndCheckBox->setChecked(false); const QString alignToolTip = i18nc("@info:tooltip", "Sets if the operation will be aligned to the end of the data instead of to the begin."); const QString alignWhatsThis = i18nc("@info:whatsthis", "If set, the operation will be aligned to the end of the data."); mAlignAtEndCheckBox->setToolTip(alignToolTip); mAlignAtEndCheckBox->setWhatsThis(alignWhatsThis); baseLayout->addRow(alignAtEndLabelText, mAlignAtEndCheckBox); } OperandByteArrayFilterParameterSetEdit::~OperandByteArrayFilterParameterSetEdit() = default; bool OperandByteArrayFilterParameterSetEdit::isValid() const { return !mOperandEdit->byteArray().isEmpty(); } void OperandByteArrayFilterParameterSetEdit::setValues(const AbstractByteArrayFilterParameterSet* parameterSet) { const auto* operandParameterSet = static_cast(parameterSet); // mOperandEdit->setValue( operandParameterSet->operand() ); TODO: not yet implemented mAlignAtEndCheckBox->setChecked(operandParameterSet->alignAtEnd()); } void OperandByteArrayFilterParameterSetEdit::setCharCodec(const QString& charCodecName) { mOperandEdit->setCharCodec(charCodecName); } void OperandByteArrayFilterParameterSetEdit::getParameterSet(AbstractByteArrayFilterParameterSet* parameterSet) const { auto* operandParameterSet = static_cast(parameterSet); operandParameterSet->setOperand(mOperandEdit->byteArray()); operandParameterSet->setOperandFormat(mOperandEdit->format()); operandParameterSet->setAlignAtEnd(mAlignAtEndCheckBox->isChecked()); } void OperandByteArrayFilterParameterSetEdit::rememberCurrentSettings() { mOperandEdit->rememberCurrentByteArray(); } void OperandByteArrayFilterParameterSetEdit::onInputChanged(const QByteArray& data) { emit validityChanged(!data.isEmpty()); } diff --git a/kasten/controllers/view/libbytearrayfilter/filter/reversebytearrayfilterparametersetedit.cpp b/kasten/controllers/view/libbytearrayfilter/filter/reversebytearrayfilterparametersetedit.cpp index 4d474008..ff316b0d 100644 --- a/kasten/controllers/view/libbytearrayfilter/filter/reversebytearrayfilterparametersetedit.cpp +++ b/kasten/controllers/view/libbytearrayfilter/filter/reversebytearrayfilterparametersetedit.cpp @@ -1,68 +1,68 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "reversebytearrayfilterparametersetedit.hpp" // #include "reversebytearrayfilterparameterset.hpp" // KF5 #include // Qt #include #include const char ReverseByteArrayFilterParameterSetEdit::Id[] = "Reverse"; ReverseByteArrayFilterParameterSetEdit::ReverseByteArrayFilterParameterSetEdit(QWidget* parent) : AbstractByteArrayFilterParameterSetEdit(parent) { auto* baseLayout = new QFormLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); const QString invertsBitsLabelText = i18nc("@option:check", "Reverse also bits:"); mInvertsBitsCheckBox = new QCheckBox(this); mInvertsBitsCheckBox->setChecked(false); const QString alignWhatsThis = i18nc("@info:whatsthis", "If set, the bits are arranged in reverse order as well."); mInvertsBitsCheckBox->setWhatsThis(alignWhatsThis); baseLayout->addRow(invertsBitsLabelText, mInvertsBitsCheckBox); } ReverseByteArrayFilterParameterSetEdit::~ReverseByteArrayFilterParameterSetEdit() = default; void ReverseByteArrayFilterParameterSetEdit::setValues(const AbstractByteArrayFilterParameterSet* parameterSet) { const auto* reverseParameterSet = static_cast(parameterSet); mInvertsBitsCheckBox->setChecked(reverseParameterSet->invertsBits()); } void ReverseByteArrayFilterParameterSetEdit::getParameterSet(AbstractByteArrayFilterParameterSet* parameterSet) const { auto* reverseParameterSet = static_cast(parameterSet); reverseParameterSet->setInvertsBits(mInvertsBitsCheckBox->isChecked()); } diff --git a/kasten/controllers/view/libbytearrayfilter/filter/rotatebytearrayfilterparametersetedit.cpp b/kasten/controllers/view/libbytearrayfilter/filter/rotatebytearrayfilterparametersetedit.cpp index edde5498..5f182686 100644 --- a/kasten/controllers/view/libbytearrayfilter/filter/rotatebytearrayfilterparametersetedit.cpp +++ b/kasten/controllers/view/libbytearrayfilter/filter/rotatebytearrayfilterparametersetedit.cpp @@ -1,101 +1,101 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "rotatebytearrayfilterparametersetedit.hpp" // parameterset #include "rotatebytearrayfilterparameterset.hpp" // KF5 #include // Qt #include #include const char RotateByteArrayFilterParameterSetEdit::Id[] = "Rotate"; RotateByteArrayFilterParameterSetEdit::RotateByteArrayFilterParameterSetEdit(QWidget* parent) : AbstractByteArrayFilterParameterSetEdit(parent) { auto* baseLayout = new QFormLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mGroupSizeEdit = new QSpinBox(this); mGroupSizeEdit->setRange(1, INT_MAX); const QString groupSizeLabelText = i18nc("@label:spinbox number of bytes the movement is done within", "&Group size (bytes):"); const QString groupSizeToolTip = i18nc("@info:tooltip", "The number of bytes within which each movement is made."); mGroupSizeEdit->setToolTip(groupSizeToolTip); const QString groupSizeWhatsThis = i18nc("@info:whatsthis", "Control the number of bytes within which each movement is made."); mGroupSizeEdit->setWhatsThis(groupSizeWhatsThis); baseLayout->addRow(groupSizeLabelText, mGroupSizeEdit); mMoveBitWidthEdit = new QSpinBox(this); mMoveBitWidthEdit->setRange(INT_MIN, INT_MAX); connect(mMoveBitWidthEdit, QOverload::of(&QSpinBox::valueChanged), this, &RotateByteArrayFilterParameterSetEdit::onValueChanged); const QString moveBitWidthLabelText = i18nc("@label:spinbox width (in number of bits) the bits are moved", "S&hift width (bits):"); const QString moveBitWidthToolTip = i18nc("@info:tooltip", "The width of the shift. Positive numbers move the bits to the right, negative to the left."); mMoveBitWidthEdit->setToolTip(moveBitWidthToolTip); const QString moveBitWidthWhatsThis = i18nc("@info:whatsthis", "Control the width of the shift. Positive numbers move the bits to the right, negative to the left."); mMoveBitWidthEdit->setWhatsThis(moveBitWidthWhatsThis); baseLayout->addRow(moveBitWidthLabelText, mMoveBitWidthEdit); } RotateByteArrayFilterParameterSetEdit::~RotateByteArrayFilterParameterSetEdit() = default; bool RotateByteArrayFilterParameterSetEdit::isValid() const { return mMoveBitWidthEdit->value() != 0; } void RotateByteArrayFilterParameterSetEdit::setValues(const AbstractByteArrayFilterParameterSet* parameterSet) { const auto* rotateParameterSet = static_cast(parameterSet); mGroupSizeEdit->setValue(rotateParameterSet->groupSize()); mMoveBitWidthEdit->setValue(rotateParameterSet->moveBitWidth()); } void RotateByteArrayFilterParameterSetEdit::getParameterSet(AbstractByteArrayFilterParameterSet* parameterSet) const { auto* rotateParameterSet = static_cast(parameterSet); rotateParameterSet->setGroupSize(mGroupSizeEdit->value()); rotateParameterSet->setMoveBitWidth(mMoveBitWidthEdit->value()); } void RotateByteArrayFilterParameterSetEdit::onValueChanged(int value) { emit validityChanged(value != 0); } diff --git a/kasten/controllers/view/libbytearrayfilter/filter/template/template_bytearrayfilterparametersetedit.cpp b/kasten/controllers/view/libbytearrayfilter/filter/template/template_bytearrayfilterparametersetedit.cpp index 951264d5..fc98bcbf 100644 --- a/kasten/controllers/view/libbytearrayfilter/filter/template/template_bytearrayfilterparametersetedit.cpp +++ b/kasten/controllers/view/libbytearrayfilter/filter/template/template_bytearrayfilterparametersetedit.cpp @@ -1,115 +1,115 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau Public domain. */ //// ADAPT(start) //// rename "template_bytearrayfilterparametersetedit.hpp" to the name of the header of your filter, //// e.g. "mybytearrayfilterparametersetedit.hpp" #include "template_bytearrayfilterparametersetedit.hpp" //// ADAPT(end) // parameterset //// ADAPT(start) //// rename "template_bytearrayfilterparameterset.hpp" to the name of the header of your filter, //// e.g. "mybytearrayfilterparameterset.hpp" #include "template_bytearrayfilterparameterset.hpp" //// ADAPT(end) // KF5 #include //// ADAPT(start) //// add includes for all elements used in the widget #include // Qt #include //// ADAPT(end) //// ADAPT(start) //// rename "Template_ParameterSetId" to the id of your parameterset, //// e.g. "MyParameterSet" const char Template_ByteArrayFilterParameterSetEdit::Id[] = "Template_ParameterSetId"; //// ADAPT(end) Template_ByteArrayFilterParameterSetEdit::Template_ByteArrayFilterParameterSetEdit(QWidget* parent) : AbstractByteArrayFilterParameterSetEdit(parent) { //// ADAPT(start) //// setup the widget with all edit fields needed for the parameter set //// if there can be invalid states connect the change signals of the edit fields to some slots //// where you check if the validity changed auto* baseLayout = new QFormLayout(this); // margin is provided by the container for this widget - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mLevelEdit = new QSpinBox(this); // For demonstration purpose we start at -1, not 0, to show handling of an invalid state // Otherwise the range should start at 0 and there is no need to connect to the valueChanged signal mLevelEdit->setRange(-1, 256); // start with the invalid number mLevelEdit->setValue(-1); connect(mLevelEdit, QOverload::of(&QSpinBox::valueChanged), this, &Template_ByteArrayFilterParameterSetEdit::onLevelChanged); const QString levelLabelText = i18nc("@label:spinbox decimal value up to which bytes are set to 0", "Level:"); const QString levelToolTip = i18nc("@info:tooltip", "The decimal value up to which the bytes are set to x00. Bytes above this value are set to x01."); mLevelEdit->setToolTip(levelToolTip); const QString levelWhatsThis = i18nc("@info:whatsthis", "Control the value which decides how the bytes are ending up. And more explanation."); mLevelEdit->setWhatsThis(levelWhatsThis); baseLayout->addRow(levelLabelText, mLevelEdit); // note start state mIsValid = isValid(); //// ADAPT(end) } Template_ByteArrayFilterParameterSetEdit::~Template_ByteArrayFilterParameterSetEdit() = default; //// ADAPT(start) //// if invalid states are possible implement here the check bool Template_ByteArrayFilterParameterSetEdit::isValid() const { return mLevelEdit->value() != -1; } //// ADAPT(end) //// ADAPT(start) //// change "Template_ByteArrayFilterParameterSet" to the class of the parameter set which this widget should edit //// e.g. "MyByteArrayFilterParameterSet" //// also adapt the passing of the values between the parameter set and the edit fields void Template_ByteArrayFilterParameterSetEdit::setValues(const AbstractByteArrayFilterParameterSet* parameterSet) { const auto* template_ParameterSet = static_cast(parameterSet); mLevelEdit->setValue(template_ParameterSet->level()); } void Template_ByteArrayFilterParameterSetEdit::getParameterSet(AbstractByteArrayFilterParameterSet* parameterSet) const { auto* template_ParameterSet = static_cast(parameterSet); template_ParameterSet->setLevel(mLevelEdit->value()); } //// ADAPT(end) //// ADAPT(start) //// define the slots to catch changes in the values to check if the current state is valid or not //// not needed if there cannot be invalid states void Template_ByteArrayFilterParameterSetEdit::onLevelChanged(int value) { const bool isValid = (value != -1); if (mIsValid == isValid) { return; } mIsValid = isValid; emit validityChanged(isValid); } //// ADAPT(end) diff --git a/kasten/controllers/view/libfinddialog/abstractfinddialog.cpp b/kasten/controllers/view/libfinddialog/abstractfinddialog.cpp index 74c1889e..8eb58713 100644 --- a/kasten/controllers/view/libfinddialog/abstractfinddialog.cpp +++ b/kasten/controllers/view/libfinddialog/abstractfinddialog.cpp @@ -1,219 +1,219 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2006-2007 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "abstractfinddialog.hpp" // Okteta Kasten gui #include // Okteta core #include // KF5 #include // Qt #include #include #include #include #include #include namespace Kasten { AbstractFindDialog::AbstractFindDialog(QWidget* parent) : QDialog(parent) { // main widget QWidget* mainWidget = new QWidget; MainWidgetLayout = new QVBoxLayout(mainWidget); - MainWidgetLayout->setMargin(0); + MainWidgetLayout->setContentsMargins(0, 0, 0, 0); // dialog buttons auto* dialogButtonBox = new QDialogButtonBox; FindButton = new QPushButton; dialogButtonBox->addButton(FindButton, QDialogButtonBox::AcceptRole); connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &AbstractFindDialog::forwardFindButtonClicked); dialogButtonBox->addButton(QDialogButtonBox::Cancel); connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); // main layout auto* layout = new QVBoxLayout; layout->addWidget(mainWidget); layout->addStretch(); layout->addWidget(dialogButtonBox); setLayout(layout); // TODO: setting ok button to disabled as before done gets overwritten to true // if setting the button gui with an inline KGuiItem in the subclass, // which has no parameter for enabled and defaults to true } AbstractFindDialog::~AbstractFindDialog() = default; void AbstractFindDialog::setFindButton(const QString& buttonText, const QString& buttonIconName, const QString& buttonToolTip, const QString& buttonWhatsThis) { FindButton->setText(buttonText); FindButton->setIcon(QIcon::fromTheme(buttonIconName)); FindButton->setToolTip(buttonToolTip); FindButton->setWhatsThis(buttonWhatsThis); } void AbstractFindDialog::setFindButtonEnabled(bool enabled) { FindButton->setEnabled(enabled); } void AbstractFindDialog::setupFindBox() { // find term QGroupBox* findBox = new QGroupBox(i18nc("@title:window", "Find")); MainWidgetLayout->addWidget(findBox); auto* findBoxLayout = new QVBoxLayout; SearchDataEdit = new Okteta::ByteArrayComboBox(findBox); connect(SearchDataEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &AbstractFindDialog::onSearchDataChanged); connect(SearchDataEdit, &Okteta::ByteArrayComboBox::formatChanged, this, &AbstractFindDialog::onSearchDataFormatChanged); const QString toolTip = i18nc("@info:tooltip", "Enter the bytes to search for, or select bytes previously searched for from the list."); SearchDataEdit->setToolTip(toolTip); findBoxLayout->addWidget(SearchDataEdit); findBox->setLayout(findBoxLayout); } void AbstractFindDialog::setupOperationBox(QGroupBox* operationBox) { // operation box if (operationBox) { MainWidgetLayout->addWidget(operationBox); } } void AbstractFindDialog::setupCheckBoxes(QCheckBox* optionCheckBox) { // options QGroupBox* optionsBox = new QGroupBox(i18nc("@title:group", "Options")); MainWidgetLayout->addWidget(optionsBox); auto* optionsBoxLayout = new QGridLayout(optionsBox); CaseSensitiveCheckBox = new QCheckBox(i18nc("@option:check", "C&ase sensitive"), optionsBox); CaseSensitiveCheckBox->setWhatsThis(i18nc("@info:whatsthis", "Perform a case sensitive search: " "entering the pattern 'Joe' will not match 'joe' or 'JOE', only 'Joe'.")); WholeWordsCheckBox = new QCheckBox(i18nc("@option:check", "&Whole words only"), optionsBox); WholeWordsCheckBox->setWhatsThis(i18nc("@info:whatsthis", "Require word boundaries in both ends of a match to succeed.")); AtCursorCheckBox = new QCheckBox(i18nc("@option:check", "From c&ursor"), optionsBox); AtCursorCheckBox->setWhatsThis(i18nc("@info:whatsthis", "Start searching at the current cursor location rather than at the top.")); BackwardsCheckBox = new QCheckBox(i18nc("@option:check", "&Backwards"), optionsBox); BackwardsCheckBox->setWhatsThis(i18nc("@info:whatsthis", "Replace backwards.")); SelectedCheckBox = new QCheckBox(i18nc("@option:check", "&Selected bytes"), optionsBox); SelectedCheckBox->setWhatsThis(i18nc("@info:whatsthis", "Only search within the current selection.")); optionsBoxLayout->addWidget(CaseSensitiveCheckBox, 0, 0); optionsBoxLayout->addWidget(WholeWordsCheckBox, 1, 0); optionsBoxLayout->addWidget(AtCursorCheckBox, 2, 0); optionsBoxLayout->addWidget(BackwardsCheckBox, 0, 1); optionsBoxLayout->addWidget(SelectedCheckBox, 1, 1); if (optionCheckBox) { optionsBoxLayout->addWidget(optionCheckBox, 2, 1); } setTabOrder(CaseSensitiveCheckBox, WholeWordsCheckBox); setTabOrder(WholeWordsCheckBox, AtCursorCheckBox); setTabOrder(AtCursorCheckBox, BackwardsCheckBox); setTabOrder(BackwardsCheckBox, SelectedCheckBox); // if( optionCheckBox ) // setTabOrder( SelectedCheckBox, optionCheckBox ); onSearchDataFormatChanged(SearchDataEdit->format()); } bool AbstractFindDialog::fromCursor() const { return AtCursorCheckBox->isChecked(); } bool AbstractFindDialog::inSelection() const { return SelectedCheckBox->isChecked(); } FindDirection AbstractFindDialog::direction() const { return BackwardsCheckBox->isChecked() ? FindBackward : FindForward; } Qt::CaseSensitivity AbstractFindDialog::caseSensitivity() const { return (SearchDataEdit->format() == Okteta::ByteArrayComboBox::CharCoding) && !CaseSensitiveCheckBox->isChecked() ? Qt::CaseInsensitive : Qt::CaseSensitive; } QByteArray AbstractFindDialog::data() const { return SearchDataEdit->byteArray(); } void AbstractFindDialog::setDirection(FindDirection Direction) { BackwardsCheckBox->setChecked(Direction == FindBackward); } void AbstractFindDialog::setInSelection(bool InSelection) { SelectedCheckBox->setChecked(InSelection); } void AbstractFindDialog::setCharCodec(const QString& codecName) { SearchDataEdit->setCharCodec(codecName); } void AbstractFindDialog::rememberCurrentSettings() { SearchDataEdit->rememberCurrentByteArray(); } void AbstractFindDialog::onFindButtonClicked() { } void AbstractFindDialog::onSearchDataFormatChanged(int index) { const bool isCharCoding = (index == Okteta::ByteArrayComboBox::CharCoding); CaseSensitiveCheckBox->setEnabled(isCharCoding); WholeWordsCheckBox->setEnabled(false); // isCharCoding ); TODO: not implemented! } void AbstractFindDialog::onSearchDataChanged(const QByteArray& data) { FindButton->setEnabled(!data.isEmpty()); } void AbstractFindDialog::forwardFindButtonClicked() { onFindButtonClicked(); } void AbstractFindDialog::showEvent(QShowEvent* showEvent) { QDialog::showEvent(showEvent); SearchDataEdit->setFocus(); } } diff --git a/kasten/controllers/view/poddecoder/podtableview.cpp b/kasten/controllers/view/poddecoder/podtableview.cpp index 8d623979..f1ba49ce 100644 --- a/kasten/controllers/view/poddecoder/podtableview.cpp +++ b/kasten/controllers/view/poddecoder/podtableview.cpp @@ -1,212 +1,212 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2006-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "podtableview.hpp" // controller #include "podtablemodel.hpp" #include "poddelegate.hpp" #include "poddecodertool.hpp" // KF5 #include #include #include // Qt #include #include #include #include #include #include #include namespace Kasten { PODTableView::PODTableView(PODDecoderTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { QBoxLayout* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // table mPODTableModel = new PODTableModel(mTool, this); mPODTableView = new QTreeView(this); mPODTableView->setObjectName(QStringLiteral("PODTable")); mPODTableView->setRootIsDecorated(false); mPODTableView->setAlternatingRowColors(true); mPODTableView->setItemsExpandable(false); mPODTableView->setUniformRowHeights(true); mPODTableView->setAllColumnsShowFocus(true); mPODTableView->setItemDelegate(new PODDelegate(mTool, this)); mPODTableView->setEditTriggers(QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked); mPODTableView->setDragEnabled(true); mPODTableView->setSortingEnabled(false); mPODTableView->setModel(mPODTableModel); mPODTableView->installEventFilter(this); QHeaderView* header = mPODTableView->header(); header->setSectionResizeMode(QHeaderView::Interactive); header->setStretchLastSection(false); connect(mPODTableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &PODTableView::onCurrentRowChanged); baseLayout->addWidget(mPODTableView, 10); // settings QBoxLayout* settingsLayout = new QHBoxLayout(); - settingsLayout->setMargin(0); + settingsLayout->setContentsMargins(0, 0, 0, 0); mByteOrderSelection = new KComboBox(this); mByteOrderSelection->addItem(i18nc("@item:inlistbox", "Big-endian")); // add first for index mByteOrderSelection->addItem(i18nc("@item:inlistbox", "Little-endian")); // add second for index mByteOrderSelection->setCurrentIndex(mTool->byteOrder()); connect(mByteOrderSelection, QOverload::of(&KComboBox::activated), mTool, &PODDecoderTool::setByteOrder); const QString byteOrderToolTip = i18nc("@info:tooltip", "The byte order to use for decoding the bytes."); mByteOrderSelection->setToolTip(byteOrderToolTip); settingsLayout->addWidget(mByteOrderSelection); QLabel* unsignedAsHexLabel = new QLabel(i18nc("@option:check", "Unsigned as hexadecimal:"), this); settingsLayout->addWidget(unsignedAsHexLabel); mUnsignedAsHexCheck = new QCheckBox(this); mUnsignedAsHexCheck->setChecked(mTool->isUnsignedAsHex()); connect(mUnsignedAsHexCheck, &QCheckBox::toggled, mTool, &PODDecoderTool::setUnsignedAsHex); unsignedAsHexLabel->setBuddy(mUnsignedAsHexCheck); const QString unsignedAsHexToolTip = i18nc("@info:tooltip", "Sets whether the values of the unsigned integer types are shown as hexadecimal instead of as decimal."); unsignedAsHexLabel->setToolTip(unsignedAsHexToolTip); mUnsignedAsHexCheck->setToolTip(unsignedAsHexToolTip); settingsLayout->addWidget(mUnsignedAsHexCheck); settingsLayout->addStretch(); baseLayout->addLayout(settingsLayout); mTool->setDifferentSizeDialog(this); // resize to fit width of contents // this is much (!) faster than using setResizeMode(QHeaderView::ResizeToContents) QFont f; QFontMetrics metrics(f); // ideally we should check the width of the longest translated string, but this should be wide enough for most // anyway this is just an initial setting and the width can be changed manually header->resizeSection(0, metrics.width(QStringLiteral("Hexadecimal 8-bit")) + 30); header->resizeSection(1, metrics.width(QStringLiteral("1.01234567890123456789e-111")) + 15); } PODTableView::~PODTableView() = default; Answer PODTableView::query(int newValueSize, int oldValueSize, int sizeLeft) { Q_UNUSED(sizeLeft); Answer answer; int messageBoxAnswer; if (newValueSize < oldValueSize) { const QString message = xi18nc("@info", "The new value needs fewer bytes (%1 instead of %2)." "Keep the unused bytes or remove them?", newValueSize, oldValueSize); const KGuiItem keepGuiItem = KGuiItem(i18nc("@action:button keep the unused bytes", "&Keep"), QString(), i18nc("@info:tooltip", "Keep the unused bytes with their old values.")); messageBoxAnswer = KMessageBox::warningYesNoCancel(this, message, mTool->title(), keepGuiItem, KStandardGuiItem::remove()); } else { const QString message = xi18nc("@info", "The new value needs more bytes (%1 instead of %2)." "Overwrite the following bytes or insert new ones as needed?", newValueSize, oldValueSize); messageBoxAnswer = KMessageBox::warningYesNoCancel(this, message, mTool->title(), KStandardGuiItem::overwrite(), KStandardGuiItem::insert()); } answer = (messageBoxAnswer == KMessageBox::Yes) ? Overwrite : (messageBoxAnswer == KMessageBox::No) ? AdaptSize : Cancel; return answer; } bool PODTableView::eventFilter(QObject* object, QEvent* event) { if (object == mPODTableView) { if (event->type() == QEvent::FocusIn) { const QModelIndex current = mPODTableView->selectionModel()->currentIndex(); const int podId = current.row(); if (current.isValid() && mTool->isApplyable() && !mTool->value(podId).isNull()) { mTool->markPOD(podId); } } else if (event->type() == QEvent::FocusOut) { QWidget* tableViewFocusWidget = mPODTableView->focusWidget(); const bool subChildHasFocus = (tableViewFocusWidget != mPODTableView); if (subChildHasFocus) { mPODTableViewFocusChild = tableViewFocusWidget; mPODTableViewFocusChild->installEventFilter(this); } else if (mTool->isApplyable()) { mTool->unmarkPOD(); } } } else if (object == mPODTableViewFocusChild) { // TODO: it is only assumed the edit widget will be removed if it loses the focus if (event->type() == QEvent::FocusOut) { if (!mPODTableView->hasFocus() && mTool->isApplyable()) { mTool->unmarkPOD(); } mPODTableViewFocusChild->removeEventFilter(this); mPODTableViewFocusChild = nullptr; } } return QWidget::eventFilter(object, event); } void PODTableView::onCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous) { Q_UNUSED(previous) if (!mTool->isApplyable()) { return; } const int podId = current.row(); if (current.isValid() && !mTool->value(podId).isNull()) { mTool->markPOD(podId); } else { mTool->unmarkPOD(); } } } diff --git a/kasten/controllers/view/selectrange/selectrangeview.cpp b/kasten/controllers/view/selectrange/selectrangeview.cpp index 31c4043f..ab71aa7c 100644 --- a/kasten/controllers/view/selectrange/selectrangeview.cpp +++ b/kasten/controllers/view/selectrange/selectrangeview.cpp @@ -1,165 +1,165 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "selectrangeview.hpp" // tool #include "selectrangetool.hpp" // Okteta Kasten gui #include // KF5 #include #include #include // Qt #include #include #include namespace Kasten { SelectRangeView::SelectRangeView(SelectRangeTool* tool, QWidget* parent) : AbstractToolWidget(parent) , mTool(tool) { auto* baseLayout = new QHBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // offsets auto* offsetLayout = new QVBoxLayout(); - offsetLayout->setMargin(0); + offsetLayout->setContentsMargins(0, 0, 0, 0); // start offset auto* startOffsetLayout = new QHBoxLayout(); - startOffsetLayout->setMargin(0); + startOffsetLayout->setContentsMargins(0, 0, 0, 0); QLabel* label = new QLabel(i18nc("@label:listbox", "Start offset:"), this); mStartEdit = new Okteta::AddressComboBox(this); connect(mStartEdit, &Okteta::AddressComboBox::addressChanged, mTool, &SelectRangeTool::setTargetStart); label->setBuddy(mStartEdit); const QString startInputWhatsThis = i18nc("@info:whatsthis", "Enter an offset to go to, or select a previous offset from the list."); label->setWhatsThis(startInputWhatsThis); mStartEdit->setWhatsThis(startInputWhatsThis); startOffsetLayout->addWidget(label); startOffsetLayout->addWidget(mStartEdit); setFocusProxy(mStartEdit); // TODO: see how KDialog does it, e.g. see if there is already a focuswidget as child offsetLayout->addLayout(startOffsetLayout); // end offset auto* endOffsetLayout = new QHBoxLayout(); - endOffsetLayout->setMargin(0); + endOffsetLayout->setContentsMargins(0, 0, 0, 0); label = new QLabel(i18nc("@label:listbox", "End offset:"), this); mEndEdit = new Okteta::AddressComboBox(this); connect(mEndEdit, &Okteta::AddressComboBox::addressChanged, mTool, &SelectRangeTool::setTargetEnd); label->setBuddy(mEndEdit); const QString endInputWhatsThis = i18nc("@info:whatsthis", "Enter an offset to go to, or select a previous offset from the list."); label->setWhatsThis(endInputWhatsThis); mEndEdit->setWhatsThis(endInputWhatsThis); endOffsetLayout->addWidget(label); endOffsetLayout->addWidget(mEndEdit); offsetLayout->addLayout(endOffsetLayout); baseLayout->addLayout(offsetLayout); // options auto* optionsLayout = new QVBoxLayout(); - optionsLayout->setMargin(0); + optionsLayout->setContentsMargins(0, 0, 0, 0); mRelativeCheckBox = new QCheckBox(i18nc("@option:check", "End relative"), this); mRelativeCheckBox->setWhatsThis( i18nc("@info:whatsthis", "Extend the selection by the cursor move.")); connect(mRelativeCheckBox, &QCheckBox::toggled, mTool, &SelectRangeTool::setIsEndRelative); mRelativeCheckBox->setChecked(mTool->isEndRelative()); mBackwardsCheckBox = new QCheckBox(i18nc("@option:check", "&Backwards"), this); mBackwardsCheckBox->setWhatsThis( i18nc("@info:whatsthis", "Go backwards from the end or the current cursor location.")); connect(mBackwardsCheckBox, &QCheckBox::toggled, mTool, &SelectRangeTool::setIsEndBackwards); mBackwardsCheckBox->setChecked(mTool->isEndBackwards()); connect(mRelativeCheckBox, &QCheckBox::toggled, mBackwardsCheckBox, &QCheckBox::setEnabled); mBackwardsCheckBox->setEnabled(mRelativeCheckBox->isChecked()); optionsLayout->addWidget(mRelativeCheckBox); optionsLayout->addWidget(mBackwardsCheckBox); baseLayout->addLayout(optionsLayout); // Select button const KGuiItem selectGuiItem = KGuiItem(i18nc("@action:button", "&Select"), QString(), i18nc("@info:tooltip", "Select the range."), xi18nc("@info:whatsthis", "If you press the Select " "button, the cursor will be moved in the document to or, " "on your option, by the offset you entered above.")); mSelectButton = new QPushButton(this); KGuiItem::assign(mSelectButton, selectGuiItem); connect(mSelectButton, &QPushButton::clicked, this, &SelectRangeView::onSelectButtonClicked); addButton(mSelectButton, AbstractToolWidget::Default); baseLayout->addWidget(mSelectButton); baseLayout->setAlignment(mSelectButton, Qt::AlignTop); baseLayout->addStretch(); setTabOrder(mStartEdit, mEndEdit); setTabOrder(mEndEdit, mRelativeCheckBox); setTabOrder(mRelativeCheckBox, mBackwardsCheckBox); setTabOrder(mBackwardsCheckBox, mSelectButton); connect(mTool, &SelectRangeTool::isApplyableChanged, this, &SelectRangeView::onApplyableChanged); onApplyableChanged(mTool->isApplyable()); } SelectRangeView::~SelectRangeView() = default; void SelectRangeView::onApplyableChanged(bool isApplyable) { // TODO: set error tooltip, like offset out of range or no document // TODO: set color flag to offset input mSelectButton->setEnabled(isApplyable); } void SelectRangeView::onSelectButtonClicked() { // TODO: collect recently used offsets in tool instead? mStartEdit->rememberCurrentAddress(); mEndEdit->rememberCurrentAddress(); mTool->select(); // emit toolUsed(); } } diff --git a/kasten/controllers/view/stringsextract/stringsextractview.cpp b/kasten/controllers/view/stringsextract/stringsextractview.cpp index 46a9a67b..e724ab4e 100644 --- a/kasten/controllers/view/stringsextract/stringsextractview.cpp +++ b/kasten/controllers/view/stringsextract/stringsextractview.cpp @@ -1,273 +1,273 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2007-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "stringsextractview.hpp" // tool #include "containedstringtablemodel.hpp" #include "stringsextracttool.hpp" // KF5 #include #include // Qt #include #include #include #include #include #include #include #include #include #include #include #include namespace Kasten { static constexpr int MinimumStringLength = 1; StringsExtractView::StringsExtractView(StringsExtractTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // update auto* updateLayout = new QHBoxLayout(); updateLayout->addStretch(); QLabel* label = new QLabel(i18nc("@label:spinbox minimum length for consecutive chars to be seen as a string", "Minimum length:"), this); updateLayout->addWidget(label); mMinLengthSpinBox = new QSpinBox(this); mMinLengthSpinBox->setValue(mTool->minLength()); mMinLengthSpinBox->setMinimum(MinimumStringLength); connect(mMinLengthSpinBox, QOverload::of(&QSpinBox::valueChanged), mTool, &StringsExtractTool::setMinLength); label->setBuddy(mMinLengthSpinBox); updateLayout->addWidget(mMinLengthSpinBox); const KGuiItem updateGuiItem = KGuiItem(i18nc("@action:button extract the strings from the byte array", "&Extract"), QStringLiteral("document-export"), i18nc("@info:tooltip", "Finds the strings contained in the selected range and lists them in the view below."), xi18nc("@info:whatsthis", "If you press the Extract button, " "the selected range is searched for all strings which have the set minimum length. " "This strings found will be listed in the view below.")); mUpdateButton = new QPushButton(this); KGuiItem::assign(mUpdateButton, updateGuiItem); mUpdateButton->setEnabled(mTool->isApplyable()); connect(mUpdateButton, &QPushButton::clicked, mTool, &StringsExtractTool::extractStrings); updateLayout->addWidget(mUpdateButton); baseLayout->addLayout(updateLayout); // filter auto* filterLayout = new QHBoxLayout(); label = new QLabel(i18nc("@label:lineedit filter term for displayed strings", "Filter:"), this); filterLayout->addWidget(label); auto* mFilterEdit = new QLineEdit(this); mFilterEdit->setClearButtonEnabled(true); mFilterEdit->setPlaceholderText(i18n("Enter a term to limit the list.")); label->setBuddy(mFilterEdit); filterLayout->addWidget(mFilterEdit, 10); baseLayout->addLayout(filterLayout); // strings mContainedStringTableModel = new ContainedStringTableModel(mTool->containedStringList(), mTool->offsetCoding(), this); connect(mTool, &StringsExtractTool::offsetCodingChanged, mContainedStringTableModel, &ContainedStringTableModel::setOffsetCoding); mSortFilterProxyModel = new QSortFilterProxyModel(this); mSortFilterProxyModel->setDynamicSortFilter(true); mSortFilterProxyModel->setSourceModel(mContainedStringTableModel); mSortFilterProxyModel->setFilterKeyColumn(ContainedStringTableModel::StringColumnId); mSortFilterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); connect(mFilterEdit, &QLineEdit::textChanged, mSortFilterProxyModel, &QSortFilterProxyModel::setFilterFixedString); mContainedStringTableView = new QTreeView(this); // TODO: find a signal/event emitted when fixedfont changes // connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged, // this, &StringsExtractView::setFixedFontByGlobalSettings ); setFixedFontByGlobalSettings(); // do this before setting model mContainedStringTableView->setObjectName(QStringLiteral("ContainedStringTable")); mContainedStringTableView->setRootIsDecorated(false); mContainedStringTableView->setItemsExpandable(false); mContainedStringTableView->setUniformRowHeights(true); mContainedStringTableView->setAllColumnsShowFocus(true); mContainedStringTableView->setSelectionMode(QAbstractItemView::ExtendedSelection); mContainedStringTableView->setSortingEnabled(true); mContainedStringTableView->installEventFilter(this); QHeaderView* header = mContainedStringTableView->header(); header->setFont(font()); header->setSectionResizeMode(QHeaderView::Interactive); mContainedStringTableView->setModel(mSortFilterProxyModel); mContainedStringTableView->sortByColumn(ContainedStringTableModel::OffsetColumnId, Qt::AscendingOrder); connect(mContainedStringTableView, &QTreeView::doubleClicked, this, &StringsExtractView::onStringDoubleClicked); connect(mContainedStringTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &StringsExtractView::onStringSelectionChanged); baseLayout->addWidget(mContainedStringTableView, 10); // actions auto* actionsLayout = new QHBoxLayout(); const KGuiItem copyGuiItem = KGuiItem(i18n("C&opy"), QStringLiteral("edit-copy"), i18nc("@info:tooltip", "Copies the selected strings to the clipboard."), xi18nc("@info:whatsthis", "If you press the Copy button, all strings you selected " "in the list are copied to the clipboard.")); mCopyButton = new QPushButton(this); KGuiItem::assign(mCopyButton, copyGuiItem); connect(mCopyButton, &QPushButton::clicked, this, &StringsExtractView::onCopyButtonClicked); actionsLayout->addWidget(mCopyButton); actionsLayout->addStretch(); const KGuiItem gotoGuiItem = KGuiItem(i18n("&Show"), QStringLiteral("go-jump"), i18nc("@info:tooltip", "Shows the selected string in the view."), xi18nc("@info:whatsthis", "If you press the Go to button, the string which was last " "selected is marked and shown in the view.")); mGotoButton = new QPushButton(this); KGuiItem::assign(mGotoButton, gotoGuiItem); connect(mGotoButton, &QPushButton::clicked, this, &StringsExtractView::onGotoButtonClicked); actionsLayout->addWidget(mGotoButton); baseLayout->addLayout(actionsLayout); connect(mTool, &StringsExtractTool::uptodateChanged, this, &StringsExtractView::onStringsUptodateChanged); connect(mTool, &StringsExtractTool::isApplyableChanged, this, &StringsExtractView::onApplyableChanged); connect(mTool, &StringsExtractTool::canHighlightStringChanged, this, &StringsExtractView::onCanHighlightStringChanged); onStringSelectionChanged(); } StringsExtractView::~StringsExtractView() = default; bool StringsExtractView::eventFilter(QObject* object, QEvent* event) { if (object == mContainedStringTableView) { if (event->type() == QEvent::FocusOut) { auto* focusEvent = static_cast(event); const Qt::FocusReason focusReason = focusEvent->reason(); if (focusReason != Qt::ActiveWindowFocusReason && focusReason != Qt::PopupFocusReason) { mTool->unmarkString(); } } } return QWidget::eventFilter(object, event); } void StringsExtractView::setFixedFontByGlobalSettings() { mContainedStringTableView->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); } void StringsExtractView::onStringsUptodateChanged(bool stringsUptodate) { if (stringsUptodate) { mContainedStringTableModel->update(); } const bool isApplyable = mTool->isApplyable(); mUpdateButton->setEnabled(!stringsUptodate && isApplyable); } void StringsExtractView::onApplyableChanged(bool isApplyable) { mUpdateButton->setEnabled(!mTool->isUptodate() && isApplyable); } void StringsExtractView::onCanHighlightStringChanged(bool canHighlightString) { const bool stringSelected = mContainedStringTableView->selectionModel()->currentIndex().isValid(); mGotoButton->setEnabled(canHighlightString && stringSelected); } void StringsExtractView::onGotoButtonClicked() { const QModelIndex index = mContainedStringTableView->selectionModel()->currentIndex(); if (index.isValid()) { // TODO: hack: as currently the marking is only undone if the focus leaves the listview it needs to be moved there before mContainedStringTableView->setFocus(); onStringDoubleClicked(index); } } void StringsExtractView::onCopyButtonClicked() { const QModelIndexList selectedRows = mContainedStringTableView->selectionModel()->selectedRows(); const QList* containedStringList = mTool->containedStringList(); QString strings; for (const QModelIndex& index : selectedRows) { const int i = mSortFilterProxyModel->mapToSource(index).row(); strings += containedStringList->at(i).string(); strings += QLatin1Char('\n'); // TODO: specific linefeed for platforms } QApplication::clipboard()->setText(strings); } void StringsExtractView::onStringSelectionChanged() { const QItemSelectionModel* selectionModel = mContainedStringTableView->selectionModel(); // TODO: selectionModel->selectedIndexes() is a expensive operation, // but with Qt 4.4.3 hasSelection() has the flaw to return true with a current index const bool hasSelection = !selectionModel->selectedIndexes().isEmpty(); mCopyButton->setEnabled(hasSelection); const bool stringSelected = selectionModel->isSelected(selectionModel->currentIndex()); const bool canHighlightString = mTool->canHighlightString(); mGotoButton->setEnabled(canHighlightString && stringSelected); } void StringsExtractView::onStringDoubleClicked(const QModelIndex& index) { if (mTool->canHighlightString()) { mTool->markString(mSortFilterProxyModel->mapToSource(index).row()); } } } diff --git a/kasten/controllers/view/structures/script/scriptloggerview.cpp b/kasten/controllers/view/structures/script/scriptloggerview.cpp index 1f3ebc0d..463ccf1c 100644 --- a/kasten/controllers/view/structures/script/scriptloggerview.cpp +++ b/kasten/controllers/view/structures/script/scriptloggerview.cpp @@ -1,70 +1,70 @@ /* * This file is part of the Okteta Kasten Framework, made within the KDE community. * * Copyright 2012 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "scriptloggerview.hpp" #include #include #include #include #include "scriptlogger.hpp" ScriptLoggerView::ScriptLoggerView(const TopLevelDataInformation::List& data, QWidget* parent) : QWidget(parent) , mSelector(new KComboBox(this)) , mView(new QTableView(this)) , mList(data) { for (const auto& info : qAsConst(mList)) { mSelector->addItem(info->objectName()); } mView->setShowGrid(false); mView->setSelectionBehavior(QAbstractItemView::SelectRows); mView->setWordWrap(false); QHeaderView* horizHeader = mView->horizontalHeader(); horizHeader->setAcceptDrops(false); horizHeader->setSectionResizeMode(QHeaderView::Interactive); horizHeader->setSortIndicatorShown(false); horizHeader->setStretchLastSection(true); if (!mList.isEmpty()) { mView->setModel(mList.at(0)->logger()); mView->resizeRowsToContents(); } connect(mSelector, QOverload::of(&KComboBox::currentIndexChanged), this, &ScriptLoggerView::updateModel); auto* layout = new QVBoxLayout(); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(mSelector, 0); layout->addWidget(mView, 1); setLayout(layout); } ScriptLoggerView::~ScriptLoggerView() = default; void ScriptLoggerView::updateModel(int index) { Q_ASSERT(index >= 0 && index < mList.size()); mView->setModel(mList.at(index)->logger()); mView->resizeRowsToContents(); } diff --git a/kasten/controllers/view/structures/settings/structureaddremovewidget.cpp b/kasten/controllers/view/structures/settings/structureaddremovewidget.cpp index 40fbd7ed..0e2a1ae6 100644 --- a/kasten/controllers/view/structures/settings/structureaddremovewidget.cpp +++ b/kasten/controllers/view/structures/settings/structureaddremovewidget.cpp @@ -1,313 +1,313 @@ /* * This file is part of the Okteta Kasten Framework, made within the KDE community. * * Copyright 2009, 2012 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "structureaddremovewidget.hpp" #include "../structurestool.hpp" #include "../structuresmanager.hpp" #include "../structuredefinitionfile.hpp" #include "../structlogging.hpp" #include #include #include #include #include #include #include #include using namespace Kasten; StructureAddRemoveWidget::StructureAddRemoveWidget(const QStringList& selected, Kasten::StructuresTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { QHBoxLayout* baseLayout; QVBoxLayout* tree1Layout; QVBoxLayout* tree2Layout; QVBoxLayout* leftRightLayout; QVBoxLayout* upDownLayout; baseLayout = new QHBoxLayout(); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); tree1Layout = new QVBoxLayout(); mTree1Label = new QLabel(i18nc("@info:label", "Installed structures:"), this); tree1Layout->addWidget(mTree1Label); mTreeAvailable = new QTreeWidget(this); mTreeAvailable->setHeaderHidden(true); mTreeAvailable->setSelectionMode(QAbstractItemView::ExtendedSelection); mTreeAvailable->setColumnCount(2); mTreeAvailable->setColumnHidden(1, true); tree1Layout->addWidget(mTreeAvailable); tree2Layout = new QVBoxLayout(); mTree2Label = new QLabel(i18nc("@info:label", "Used structures:"), this); tree2Layout->addWidget(mTree2Label); mTreeSelected = new QTreeWidget(this); mTreeSelected->setHeaderHidden(true); mTreeSelected->setSelectionMode(QAbstractItemView::ExtendedSelection); mTreeSelected->setColumnCount(2); mTreeSelected->setColumnHidden(1, true); tree2Layout->addWidget(mTreeSelected); leftRightLayout = new QVBoxLayout(); leftRightLayout->addStretch(); mRightButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-right")), QString(), this); leftRightLayout->addWidget(mRightButton); mLeftButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-left")), QString(), this); leftRightLayout->addWidget(mLeftButton); leftRightLayout->addStretch(); upDownLayout = new QVBoxLayout(); upDownLayout->addStretch(); mUpButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-up")), QString(), this); upDownLayout->addWidget(mUpButton); mDownButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-down")), QString(), this); upDownLayout->addWidget(mDownButton); upDownLayout->addStretch(); baseLayout->addLayout(tree1Layout); baseLayout->addLayout(leftRightLayout); baseLayout->addLayout(tree2Layout); baseLayout->addLayout(upDownLayout); setLayout(baseLayout); connect(mLeftButton, &QPushButton::pressed, this, &StructureAddRemoveWidget::moveLeft); connect(mRightButton, &QPushButton::pressed, this, &StructureAddRemoveWidget::moveRight); connect(mUpButton, &QPushButton::pressed, this, &StructureAddRemoveWidget::moveUp); connect(mDownButton, &QPushButton::pressed, this, &StructureAddRemoveWidget::moveDown); buildAvailableList(); // already loaded defs: QRegExp regex(QStringLiteral("'(.+)':'(.+)'")); for (const QString& s : selected) { int pos = regex.indexIn(s); if (pos > -1) { QString pluginName = regex.cap(1); QString structName = regex.cap(2); if (structName == QLatin1String("*")) { // add all of them for (int i = 0; i < mTreeAvailable->topLevelItemCount(); i++) { QTreeWidgetItem* avail = mTreeAvailable->topLevelItem(i); if (avail->text(0) != pluginName) { continue; } for (int i = 0; i < avail->childCount(); i++) { QTreeWidgetItem* selStruct = avail->child(i); QTreeWidgetItem* item = new QTreeWidgetItem(mTreeSelected, QStringList { selStruct->text(0), pluginName }); mTreeSelected->addTopLevelItem(item); } break; } } else { QTreeWidgetItem* item = new QTreeWidgetItem(mTreeSelected, QStringList { structName, pluginName }); mTreeSelected->addTopLevelItem(item); } } } syncData(); } StructureAddRemoveWidget::~StructureAddRemoveWidget() = default; QStringList StructureAddRemoveWidget::values() const { return mValues; } void StructureAddRemoveWidget::buildAvailableList() { const auto loadedDefs = mTool->manager()->structureDefs(); QList availableItems; for (StructureDefinitionFile* def : loadedDefs) { if (!def->isValid()) { continue; } QString pluginName = def->pluginInfo().pluginName(); if (!def->pluginInfo().isPluginEnabled()) { continue; } QTreeWidgetItem* item = new QTreeWidgetItem(mTreeAvailable, QStringList { def->pluginInfo().pluginName(), pluginName }); const auto structureNames = def->structureNames(); for (const QString& name : structureNames) { QTreeWidgetItem* subItem = new QTreeWidgetItem(item, QStringList { name, pluginName }); item->addChild(subItem); } availableItems.append(item); } mTreeAvailable->addTopLevelItems(availableItems); } void StructureAddRemoveWidget::moveLeft() { const QList selected = mTreeSelected->selectedItems(); bool changed = false; for (QTreeWidgetItem* item : selected) { delete mTreeSelected->takeTopLevelItem( mTreeSelected->indexOfTopLevelItem(item)); changed = true; } if (changed) { syncData(); } } void StructureAddRemoveWidget::moveRight() { const QList selected = mTreeAvailable->selectedItems(); bool changed = false; for (const QTreeWidgetItem* item : selected) { if (!item->parent()) { continue; // maybe sometime add all subitems } QTreeWidgetItem* moveOver = new QTreeWidgetItem(mTreeSelected, QStringList { item->text(0), item->text(1) }); // item name then parent name then path mTreeSelected->addTopLevelItem(moveOver); changed = true; } if (changed) { syncData(); } } void StructureAddRemoveWidget::moveUp() { const QList selected = mTreeSelected->selectedItems(); bool changed = false; int firstIndex = -1; for (QTreeWidgetItem* item : selected) { int idx = mTreeSelected->indexOfTopLevelItem(item); int newIdx = qMax(0, idx - 1); mTreeSelected->insertTopLevelItem(newIdx, mTreeSelected->takeTopLevelItem(idx)); // only first index firstIndex = firstIndex == -1 ? newIdx : firstIndex; } if (changed) { syncData(); } if (firstIndex != -1) { mTreeSelected->setCurrentItem(mTreeSelected->topLevelItem(firstIndex)); } } void StructureAddRemoveWidget::moveDown() { const QList selected = mTreeSelected->selectedItems(); bool changed = false; int firstIndex = -1; int maxItmCount = mTreeSelected->topLevelItemCount(); for (QTreeWidgetItem* item : selected) { int idx = mTreeSelected->indexOfTopLevelItem(item); int newIdx = qMin(idx + 1, maxItmCount - 1); mTreeSelected->insertTopLevelItem(newIdx, mTreeSelected->takeTopLevelItem(idx)); // only first index firstIndex = firstIndex == -1 ? newIdx : firstIndex; } if (changed) { syncData(); } if (firstIndex != -1) { mTreeSelected->setCurrentItem(mTreeSelected->topLevelItem(firstIndex)); } } void StructureAddRemoveWidget::syncData() { const auto topLevelItemCount = mTreeSelected->topLevelItemCount(); QStringList strings; strings.reserve(topLevelItemCount); for (int i = 0; i < topLevelItemCount; ++i) { QTreeWidgetItem* item = mTreeSelected->topLevelItem(i); QString dataStr = QStringLiteral("\'%1\':\'%2\'").arg(item->text(1), item->text(0)); strings.append(dataStr); } qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "selection changed to: " << strings; mValues = strings; } void StructureAddRemoveWidget::updateAvailable() { // rebuild available tree mTreeAvailable->clear(); buildAvailableList(); // remove any structs that references not loaded files QStringList plugins; const auto loadedDefs = mTool->manager()->structureDefs(); for (const StructureDefinitionFile* def : loadedDefs) { QString pluginName = def->pluginInfo().pluginName(); if (def->pluginInfo().isValid() && !def->pluginInfo().isPluginEnabled()) { continue; } plugins << pluginName; } bool changed = false; QList toRemove; qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "paths = " << plugins; for (int i = 0; i < mTreeSelected->topLevelItemCount(); ++i) { QTreeWidgetItem* item = mTreeSelected->topLevelItem(i); // text(1) is plugin name if (!plugins.contains(item->text(1))) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "removed item: " << QStringLiteral("\'%1\':\'%2\'").arg(item->text(1), item->text(0)); changed = true; toRemove.append(item); } else { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "item " << QStringLiteral("\'%1\':\'%2\'").arg(item->text(1), item->text(0)) << "still loaded -> keep"; } } for (QTreeWidgetItem* itm : qAsConst(toRemove)) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "item " << QStringLiteral("\'%1\':\'%2\'").arg(itm->text(1), itm->text(0)) << "removed"; delete mTreeSelected->takeTopLevelItem(mTreeSelected->indexOfTopLevelItem(itm)); } if (changed) { syncData(); } } diff --git a/kasten/controllers/view/structures/settings/structuresmanagerview.cpp b/kasten/controllers/view/structures/settings/structuresmanagerview.cpp index 27cf5c38..006a80cc 100644 --- a/kasten/controllers/view/structures/settings/structuresmanagerview.cpp +++ b/kasten/controllers/view/structures/settings/structuresmanagerview.cpp @@ -1,199 +1,199 @@ /* This file is part of the Okteta Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau Copyright 2009, 2012 Alex Richardson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "structuresmanagerview.hpp" #include "structureaddremovewidget.hpp" #include "structureviewpreferences.h" #include "../structuresmanager.hpp" #include "../structurestool.hpp" #include "../structlogging.hpp" // KF5 #include #include #include #include #include // Qt #include #include #include #include #include #include StructuresManagerView::StructuresManagerView(Kasten::StructuresTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) , mRebuildingPluginsList(false) { mSelectedStructures = Kasten::StructureViewPreferences::loadedStructures(); auto* pageLayout = new QVBoxLayout(); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); setLayout(pageLayout); rebuildPluginSelectorEntries(); auto* buttonsLayout = new QHBoxLayout(); pageLayout->addLayout(buttonsLayout); mGetNewStructuresButton = new KNS3::Button(i18n("Get New Structures..."), QStringLiteral("okteta-structures.knsrc"), this); connect(mGetNewStructuresButton, &KNS3::Button::dialogFinished, this, &StructuresManagerView::onGetNewStructuresClicked); buttonsLayout->addWidget(mGetNewStructuresButton); mAdvancedSelectionButton = new QPushButton(QIcon::fromTheme(QStringLiteral("configure")), i18n("Advanced Selection..."), this); connect(mAdvancedSelectionButton, &QPushButton::clicked, this, &StructuresManagerView::advancedSelection); buttonsLayout->addWidget(mAdvancedSelectionButton); } StructuresManagerView::~StructuresManagerView() = default; void StructuresManagerView::onGetNewStructuresClicked(const KNS3::Entry::List& changedEntries) { for (const KNS3::Entry& e : changedEntries) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "Changed Entry: " << e.name(); if (e.status() == KNS3::Entry::Installed) { // new element installed qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "installed files:" << e.installedFiles(); } if (e.status() == KNS3::Entry::Deleted) { // element uninstalled qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "deleted files:" << e.uninstalledFiles(); } } if (!changedEntries.isEmpty()) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "installed structures changed -> rebuilding list of installed structures"; mTool->manager()->reloadPaths(); rebuildPluginSelectorEntries(); } } QStringList StructuresManagerView::values() const { return mSelectedStructures; } void StructuresManagerView::advancedSelection() { auto* advancedSelectionWidget = new StructureAddRemoveWidget(mSelectedStructures, mTool, this); QPointer dlg = new QDialog(this); // the dlg-on-heap-variant dlg->setWindowTitle(i18nc("@title:window", "Advanced Structures Selection")); auto* layout = new QVBoxLayout; auto* dialogButtonBox = new QDialogButtonBox; dialogButtonBox->addButton(QDialogButtonBox::Ok); connect(dialogButtonBox, &QDialogButtonBox::accepted, dlg.data(), &QDialog::accept); dialogButtonBox->addButton(QDialogButtonBox::Cancel); connect(dialogButtonBox, &QDialogButtonBox::rejected, dlg.data(), &QDialog::reject); layout->addWidget(advancedSelectionWidget); layout->addWidget(dialogButtonBox); dlg->setLayout(layout); if (dlg->exec() == QDialog::Accepted) { QStringList newVals = advancedSelectionWidget->values(); if (newVals != mSelectedStructures) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "selection changed from " << mSelectedStructures << "to" << newVals; mSelectedStructures = newVals; emit changed(newVals); } } delete dlg; } void StructuresManagerView::onPluginSelectorChange(bool change) { if (mRebuildingPluginsList) { return; } qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "pluginselector changed: " << change; if (!change) { return; } mStructuresSelector->save(); reloadSelectedItems(); } void StructuresManagerView::reloadSelectedItems() { QStringList newVals; const auto structureDefs = mTool->manager()->structureDefs(); for (const Kasten::StructureDefinitionFile* def : structureDefs) { KPluginInfo info = def->pluginInfo(); if (info.isPluginEnabled()) { newVals.append(QString(QStringLiteral("\'%1\':\'*\'")).arg(info.pluginName())); } } if (newVals != mSelectedStructures) { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "selection changed from " << mSelectedStructures << "to" << newVals; mSelectedStructures = newVals; emit changed(newVals); } else { qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "no change:" << mSelectedStructures; } } void StructuresManagerView::rebuildPluginSelectorEntries() { mRebuildingPluginsList = true; QStringList newVals; KPluginInfo::List plugins; KPluginInfo::List dynamicPlugins; const auto structureDefs = mTool->manager()->structureDefs(); for (const Kasten::StructureDefinitionFile* def : structureDefs) { KPluginInfo info = def->pluginInfo(); if (info.category() == QLatin1String("structure")) { plugins.append(info); } else if (info.category() == QLatin1String("structure/js")) { dynamicPlugins.append(info); } } // XXX is there any way to clear the plugins selector? auto* layoutObj = qobject_cast(layout()); Q_CHECK_PTR(layoutObj); if (mStructuresSelector) { layoutObj->removeWidget(mStructuresSelector); delete mStructuresSelector; } mStructuresSelector = new KPluginSelector(this); connect(mStructuresSelector, &KPluginSelector::changed, this, &StructuresManagerView::onPluginSelectorChange); layoutObj->insertWidget(0, mStructuresSelector); mStructuresSelector->addPlugins(plugins, KPluginSelector::ReadConfigFile, i18n("Structure Definitions"), QStringLiteral("structure"), mTool->manager()->config()); mStructuresSelector->addPlugins(dynamicPlugins, KPluginSelector::ReadConfigFile, i18n("Dynamic Structure Definitions"), QStringLiteral("structure/js"), mTool->manager()->config()); mStructuresSelector->load(); mStructuresSelector->updatePluginsState(); mRebuildingPluginsList = false; reloadSelectedItems(); } diff --git a/kasten/controllers/view/structures/structureview.cpp b/kasten/controllers/view/structures/structureview.cpp index c35d5009..261fbb27 100644 --- a/kasten/controllers/view/structures/structureview.cpp +++ b/kasten/controllers/view/structures/structureview.cpp @@ -1,308 +1,308 @@ /* * This file is part of the Okteta Kasten Framework, made within the KDE community. * * Copyright 2009, 2010, 2012 Alex Richardson * Copyright 2009 Friedrich W. H. Kossebau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "structureview.hpp" // controller #include "structuretreemodel.hpp" #include "structurestool.hpp" #include "structuresmanager.hpp" #include "structureviewitemdelegate.hpp" #include "structlogging.hpp" // settings #include "structureviewpreferences.h" #include "settings/structureviewsettingswidget.hpp" #include "settings/structuresmanagerview.hpp" #include "settings/structureaddremovewidget.hpp" #include "script/scriptutils.hpp" #include "script/scriptloggerview.hpp" // #include "modeltest.hpp" // KF5 #include #include #include // Qt #include #include #include #include #include #include #include #include namespace Kasten { StructureView::StructureView(StructuresTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) , mDelegate(new StructureViewItemDelegate(this)) , mStructTreeViewFocusChild(nullptr) { QBoxLayout* baseLayout = new QVBoxLayout(this); setLayout(baseLayout); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); // table mStructureTreeModel = new StructureTreeModel(mTool, this); // mModeltest = new ModelTest(mStructureTreeModel, this); mStructTreeView = new QTreeView(this); mStructTreeView->setObjectName(QStringLiteral("StructTree")); mStructTreeView->setRootIsDecorated(true); mStructTreeView->setAlternatingRowColors(true); mStructTreeView->setItemsExpandable(true); mStructTreeView->setUniformRowHeights(true); mStructTreeView->setAllColumnsShowFocus(true); mStructTreeView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed); mStructTreeView->setItemDelegate(mDelegate); mStructTreeView->setDragEnabled(false); mStructTreeView->setSortingEnabled(false); mStructTreeView->setModel(mStructureTreeModel); mStructTreeView->setHeaderHidden(false); mStructTreeView->setSortingEnabled(false); mStructTreeView->installEventFilter(this); QHeaderView* header = mStructTreeView->header(); header->setSectionResizeMode(QHeaderView::Interactive); baseLayout->addWidget(mStructTreeView, 10); // settings QBoxLayout* settingsLayout = new QHBoxLayout(); - settingsLayout->setMargin(0); + settingsLayout->setContentsMargins(0, 0, 0, 0); baseLayout->addLayout(settingsLayout); QIcon validateIcon = QIcon::fromTheme(QStringLiteral("document-sign")); mValidateButton = new QPushButton(validateIcon, i18nc("@action:button", "Validate"), this); const QString validationToolTip = i18nc("@info:tooltip", "Validate all structures."); mValidateButton->setToolTip(validationToolTip); mValidateButton->setEnabled(false); // no point validating without file open connect(mValidateButton, &QPushButton::clicked, mTool, &StructuresTool::validateAllStructures); connect(mTool, &StructuresTool::byteArrayModelChanged, this, &StructureView::onByteArrayModelChanged); // TODO also disable the button if the structure has no validatable members settingsLayout->addWidget(mValidateButton); mLockStructureButton = new QPushButton(this); mLockStructureButton->setCheckable(true); setLockButtonState(false); mLockStructureButton->setEnabled(false); // won't work at beginning connect(mLockStructureButton, &QPushButton::toggled, this, &StructureView::lockButtonToggled); settingsLayout->addWidget(mLockStructureButton); settingsLayout->addStretch(); // stretch before the settings button QIcon console = QIcon::fromTheme(QStringLiteral("utilities-terminal")); mScriptConsoleButton = new QPushButton(console, i18nc("@action:button", "Script console"), this); mScriptConsoleButton->setToolTip(i18nc("@info:tooltip", "Open script console.")); connect(mScriptConsoleButton, &QPushButton::pressed, this, &StructureView::openScriptConsole); settingsLayout->addWidget(mScriptConsoleButton); QIcon settings = QIcon::fromTheme(QStringLiteral("configure")); mSettingsButton = new QPushButton(settings, i18nc("@action:button", "Settings"), this); const QString settingsTooltip = i18nc("@info:tooltip", "Open settings."); mSettingsButton->setToolTip(settingsTooltip); connect(mSettingsButton, &QPushButton::pressed, this, &StructureView::openSettingsDlg); settingsLayout->addWidget(mSettingsButton); connect(mStructTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &StructureView::onCurrentRowChanged); connect(mTool, &StructuresTool::cursorIndexChanged, this, &StructureView::onCursorIndexChange); } StructureView::~StructureView() = default; StructuresTool* StructureView::tool() const { return mTool; } void StructureView::onCursorIndexChange() { QModelIndex idx = mStructTreeView->currentIndex(); if (idx.isValid()) { mTool->mark(idx); } } void StructureView::openSettingsDlg() { // An instance of your dialog could be already created and could be cached, // in which case you want to display the cached dialog instead of creating // another one if (KConfigDialog::showDialog(QStringLiteral("Structures Tool Settings"))) { return; } // KConfigDialog didn't find an instance of this dialog, so lets create it : KConfigDialog* dialog = new KConfigDialog(this, QStringLiteral("Structures Tool Settings"), StructureViewPreferences::self()); auto* displaySettings = new StructureViewSettingsWidget(); KPageWidgetItem* displ = dialog->addPage(displaySettings, i18n("Value Display"), QStringLiteral("configure")); // cannot use StructuresManagerView directly as page even if the only element // because KConfigDialogManager only scans the children of the page for kcfg_ elements QWidget* structSelectionPage = new QWidget(); auto* hbox = new QHBoxLayout(); - hbox->setMargin(0); + hbox->setContentsMargins(0, 0, 0, 0); structSelectionPage->setLayout(hbox); auto* structureSettings = new StructuresManagerView(mTool, this); structureSettings->setObjectName(QStringLiteral("kcfg_LoadedStructures")); hbox->addWidget(structureSettings); dialog->addPage(structSelectionPage, i18n("Structures management"), QStringLiteral("preferences-plugin")); // User edited the configuration - update your local copies of the configuration data connect(dialog, &KConfigDialog::settingsChanged, mTool, &StructuresTool::setSelectedStructuresInView); // TODO: kconfig_compiler signals work now, use those signals and not the generic KConfigDialog::settingsChanged dialog->setCurrentPage(displ); dialog->show(); } bool StructureView::eventFilter(QObject* object, QEvent* event) { if (object == mStructTreeView) { if (event->type() == QEvent::FocusIn) { const QModelIndex current = mStructTreeView->selectionModel()->currentIndex(); if (current.isValid()) { mTool->mark(current); } else { mTool->unmark(); } setLockButtonState(current); } else if (event->type() == QEvent::FocusOut) { QWidget* treeViewFocusWidget = mStructTreeView->focusWidget(); const bool subChildHasFocus = (treeViewFocusWidget != mStructTreeView); if (subChildHasFocus) { mStructTreeViewFocusChild = treeViewFocusWidget; mStructTreeViewFocusChild->installEventFilter(this); } else { mTool->unmark(); } } } else if (object == mStructTreeViewFocusChild) { // TODO: it is only assumed the edit widget will be removed if it loses the focus if (event->type() == QEvent::FocusOut) { if (!mStructTreeView->hasFocus()) { mTool->unmark(); } mStructTreeViewFocusChild->removeEventFilter(this); mStructTreeViewFocusChild = nullptr; } } return QWidget::eventFilter(object, event); } void StructureView::setLockButtonState(const QModelIndex& current) { // qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "setLockButtonState() for" << current; // we don't want the toggled signal here, only when the user clicks the button! QSignalBlocker block(mLockStructureButton); setLockButtonState(mTool->isStructureLocked(current)); mLockStructureButton->setEnabled(mTool->canStructureBeLocked(current)); } void StructureView::onCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous) { Q_UNUSED(previous) if (current.isValid() && mTool->byteArrayModel()) { mTool->mark(current); setLockButtonState(current); } else { mTool->unmark(); } } void StructureView::lockButtonToggled() { // qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "Lock button toggled"; setLockButtonState(mLockStructureButton->isChecked()); const QModelIndex current = mStructTreeView->selectionModel()->currentIndex(); if (!current.isValid()) { qCWarning(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "it should not be possible to toggle this button when current index is invalid!"; return; } if (mLockStructureButton->isChecked()) { mTool->lockStructure(current); } else { mTool->unlockStructure(current); } } void StructureView::setLockButtonState(bool structureLocked) { if (structureLocked) { mLockStructureButton->setIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); mLockStructureButton->setText(i18nc("@action:button" " unlock the starting offset of the current structure", "Unlock")); mLockStructureButton->setToolTip(i18nc("@info:tooltip", "Unlock selected structure, i.e. the starting offset is" " always set to the current cursor position.")); } else { mLockStructureButton->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); mLockStructureButton->setText(i18nc("@action:button" " unlock the starting offset of the current structure", "Lock")); mLockStructureButton->setToolTip(i18nc("@info:tooltip", "Lock selected structure to current offset.")); } mLockStructureButton->setChecked(structureLocked); } void StructureView::openScriptConsole() { QDialog* dialog = new QDialog(this); dialog->setWindowTitle(i18nc("@title:window", "Structures Script Console")); auto* layout = new QVBoxLayout; auto* dialogButtonBox = new QDialogButtonBox; QPushButton* closeButton = dialogButtonBox->addButton(QDialogButtonBox::Close); connect(closeButton, &QPushButton::clicked, dialog, &QDialog::accept); layout->addWidget(new ScriptLoggerView(mTool->allData())); layout->addWidget(dialogButtonBox); dialog->setLayout(layout); dialog->show(); } void StructureView::onByteArrayModelChanged(Okteta::AbstractByteArrayModel* model) { const bool validModel = (model != nullptr); QModelIndex current = mStructTreeView->currentIndex(); mLockStructureButton->setEnabled(mTool->canStructureBeLocked(current)); setLockButtonState(mTool->isStructureLocked(current)); mValidateButton->setEnabled(validModel); } } diff --git a/kasten/controllers/view/viewprofiles/viewprofileedit.cpp b/kasten/controllers/view/viewprofiles/viewprofileedit.cpp index 9406e46a..e95b9570 100644 --- a/kasten/controllers/view/viewprofiles/viewprofileedit.cpp +++ b/kasten/controllers/view/viewprofiles/viewprofileedit.cpp @@ -1,251 +1,251 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2010,2012 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "viewprofileedit.hpp" // Okteta Gui Kasten #include // Okteta core #include // KF5 #include #include // Qt #include #include #include #include #include #include namespace Kasten { static constexpr int listIndexFromByteArrayCodingsFlags(int byteArrayCodingsFlags) { return byteArrayCodingsFlags - 1; } static constexpr int byteArrayCodingsFlagsFromListIndex(int listIndex) { return listIndex + 1; } ViewProfileEdit::ViewProfileEdit(QWidget* parent) : QWidget(parent) { auto* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); // titel auto* titleFormLayout = new QFormLayout; // char for non-printable bytes mTitleEdit = new QLineEdit(this); mTitleEdit->setClearButtonEnabled(true); connect(mTitleEdit, &QLineEdit::textChanged, this, &ViewProfileEdit::profileTitleChanged); titleFormLayout->addRow(i18n("Title:"), mTitleEdit); // display settings auto* displayBox = new QGroupBox(this); displayBox->setTitle(i18n("Display")); auto* displayBoxFormLayout = new QFormLayout(displayBox); // line offset shown mLineOffsetShownCheckBox = new QCheckBox(displayBox); displayBoxFormLayout->addRow(i18n("Show Line Offset:"), mLineOffsetShownCheckBox); // offset coding mOffsetCodingComboBox = new KComboBox(displayBox); const QStringList offsetCodingList { i18nc("@item:inmenu offset in the hexadecimal format", "Hexadecimal"), i18nc("@item:inmenu offset in the decimal format", "Decimal"), }; mOffsetCodingComboBox->addItems(offsetCodingList); displayBoxFormLayout->addRow(i18n("Offset Coding:"), mOffsetCodingComboBox); // values or char shown mValuesCharsShownComboBox = new KComboBox(displayBox); const QStringList valuesCharsList { i18nc("@item:", "Values"), i18nc("@item:", "Chars"), i18nc("@item:", "Values & Chars"), }; mValuesCharsShownComboBox->addItems(valuesCharsList); displayBoxFormLayout->addRow(i18n("Show Values or Chars:"), mValuesCharsShownComboBox); // display mode const QString displayModeLabel = i18nc("@label:listbox ", "Show with Rows or Columns:"); mDisplayModeComboBox = new KComboBox(displayBox); const QStringList displayModeList { i18nc("@item:", "Columns"), i18nc("@item:", "Rows"), }; mDisplayModeComboBox->addItems(displayModeList); displayBoxFormLayout->addRow(displayModeLabel, mDisplayModeComboBox); // layout settings auto* layoutBox = new QGroupBox(this); layoutBox->setTitle(i18n("Layout")); auto* layoutBoxFormLayout = new QFormLayout(layoutBox); // line break mLineBreakComboBox = new KComboBox(layoutBox); const QStringList lineBreakList { i18nc("@item:inmenu The layout will not change on size changes.", "Off"), i18nc("@item:inmenu The layout will adapt to the size, but only with complete groups of bytes.", "Wrap Only Complete Byte Groups"), i18nc("@item:inmenu The layout will adapt to the size and fit in as much bytes per line as possible.", "On"), }; mLineBreakComboBox->addItems(lineBreakList); connect(mLineBreakComboBox, QOverload::of(&KComboBox::currentIndexChanged), this, &ViewProfileEdit::onLineBreakIndexChanged); layoutBoxFormLayout->addRow(i18n("Break lines:"), mLineBreakComboBox); // bytes per group mGroupedBytesCountEdit = new QSpinBox(this); mGroupedBytesCountEdit->setRange(0, INT_MAX); const QString noGroupingText = i18nc("@label", "No grouping."); mGroupedBytesCountEdit->setSpecialValueText(noGroupingText); const QString groupedBytesCountLabel = i18nc("@label:spinbox number of bytes which are grouped", "Bytes per Group:"); layoutBoxFormLayout->addRow(groupedBytesCountLabel, mGroupedBytesCountEdit); // bytes per group mBytesPerLineEdit = new QSpinBox(this); mBytesPerLineEdit->setRange(1, INT_MAX); const QString bytesPerLineLabel = i18nc("@label:spinbox number of bytes which are shown per line", "Bytes per Line:"); layoutBoxFormLayout->addRow(bytesPerLineLabel, mBytesPerLineEdit); // value settings auto* valuesBox = new QGroupBox(this); valuesBox->setTitle(i18n("Values")); auto* valuesBoxFormLayout = new QFormLayout(valuesBox); // coding mValueCodingComboBox = new KComboBox(valuesBox); const QStringList valueCodingList { i18nc("@item:inmenu encoding of the bytes as values in the hexadecimal format", "Hexadecimal"), i18nc("@item:inmenu encoding of the bytes as values in the decimal format", "Decimal"), i18nc("@item:inmenu encoding of the bytes as values in the octal format", "Octal"), i18nc("@item:inmenu encoding of the bytes as values in the binary format", "Binary"), }; mValueCodingComboBox->addItems(valueCodingList); valuesBoxFormLayout->addRow(i18n("Coding:"), mValueCodingComboBox); // char settings auto* charsBox = new QGroupBox(this); charsBox->setTitle(i18n("Chars")); auto* charsBoxFormLayout = new QFormLayout(charsBox); // coding mCharCodingComboBox = new KComboBox(charsBox); mCharCodingComboBox->addItems(Okteta::CharCodec::codecNames()); charsBoxFormLayout->addRow(i18n("Coding:"), mCharCodingComboBox); // line offset shown mNonPrintableShownCheckBox = new QCheckBox(charsBox); // TODOSHOWNONPRINTING hide from UI for now mNonPrintableShownCheckBox->hide(); // charsBoxFormLayout->addRow(i18n("Show Non-printable:"), mNonPrintableShownCheckBox); // char for non-printable bytes mNonPrintableCharEdit = new QLineEdit(charsBox); // TODO: use a validator to ensure always one char mNonPrintableCharEdit->setClearButtonEnabled(true); mNonPrintableCharEdit->setMaxLength(1); charsBoxFormLayout->addRow(i18n("Char for non-printable bytes:"), mNonPrintableCharEdit); // char for undefined bytes mUndefinedCharEdit = new QLineEdit(charsBox); // TODO: use a validator to ensure always one char mUndefinedCharEdit->setClearButtonEnabled(true); mUndefinedCharEdit->setMaxLength(1); charsBoxFormLayout->addRow(i18n("Char for undefined bytes:"), mUndefinedCharEdit); layout->addLayout(titleFormLayout); layout->addWidget(displayBox); layout->addWidget(layoutBox); layout->addWidget(valuesBox); layout->addWidget(charsBox); mTitleEdit->setFocus(); } ViewProfileEdit::~ViewProfileEdit() = default; ByteArrayViewProfile ViewProfileEdit::viewProfile() const { ByteArrayViewProfile viewProfile; viewProfile.setViewProfileTitle(mTitleEdit->text()); viewProfile.setOffsetColumnVisible(mLineOffsetShownCheckBox->isChecked()); viewProfile.setOffsetCoding(mOffsetCodingComboBox->currentIndex()); const int visibleByteArrayCodings = byteArrayCodingsFlagsFromListIndex(mValuesCharsShownComboBox->currentIndex()); viewProfile.setVisibleByteArrayCodings(visibleByteArrayCodings); viewProfile.setViewModus(mDisplayModeComboBox->currentIndex()); viewProfile.setLayoutStyle(mLineBreakComboBox->currentIndex()); viewProfile.setNoOfGroupedBytes(mGroupedBytesCountEdit->value()); viewProfile.setNoOfBytesPerLine(mBytesPerLineEdit->value()); viewProfile.setValueCoding(mValueCodingComboBox->currentIndex()); viewProfile.setCharCoding(mCharCodingComboBox->currentText()); viewProfile.setShowsNonprinting(mNonPrintableShownCheckBox->isChecked()); viewProfile.setSubstituteChar(mNonPrintableCharEdit->text().at(0)); // TODO: need make sure is one char viewProfile.setUndefinedChar(mUndefinedCharEdit->text().at(0)); // TODO: need make sure is one char return viewProfile; } void ViewProfileEdit::setViewProfile(const ByteArrayViewProfile& viewProfile) { mTitleEdit->setText(viewProfile.viewProfileTitle()); mLineOffsetShownCheckBox->setChecked(viewProfile.offsetColumnVisible()); mOffsetCodingComboBox->setCurrentIndex(viewProfile.offsetCoding()); const int valuesCharsShownListIndex = listIndexFromByteArrayCodingsFlags(viewProfile.visibleByteArrayCodings()); mValuesCharsShownComboBox->setCurrentIndex(valuesCharsShownListIndex); mDisplayModeComboBox->setCurrentIndex(viewProfile.viewModus()); mLineBreakComboBox->setCurrentIndex(viewProfile.layoutStyle()); mGroupedBytesCountEdit->setValue(viewProfile.noOfGroupedBytes()); mBytesPerLineEdit->setValue(viewProfile.noOfBytesPerLine()); mValueCodingComboBox->setCurrentIndex(viewProfile.valueCoding()); mCharCodingComboBox->setCurrentItem(viewProfile.charCodingName()); mNonPrintableShownCheckBox->setChecked(viewProfile.showsNonprinting()); mNonPrintableCharEdit->setText(viewProfile.substituteChar()); mUndefinedCharEdit->setText(viewProfile.undefinedChar()); } void ViewProfileEdit::onLineBreakIndexChanged(int lineBreakIndex) { const bool isLineBreakByByte = (lineBreakIndex == 0); mBytesPerLineEdit->setEnabled(isLineBreakByByte); } } diff --git a/kasten/gui/io/generator/pattern/bytearraypatterngeneratorconfigeditor.cpp b/kasten/gui/io/generator/pattern/bytearraypatterngeneratorconfigeditor.cpp index ee5fff34..93510afb 100644 --- a/kasten/gui/io/generator/pattern/bytearraypatterngeneratorconfigeditor.cpp +++ b/kasten/gui/io/generator/pattern/bytearraypatterngeneratorconfigeditor.cpp @@ -1,106 +1,106 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraypatterngeneratorconfigeditor.hpp" // lib #include // KF5 #include // Qt #include #include namespace Kasten { ByteArrayPatternGeneratorConfigEditor::ByteArrayPatternGeneratorConfigEditor(ByteArrayPatternGenerator* generator, QWidget* parent) : AbstractModelDataGeneratorConfigEditor(parent) , mGenerator(generator) { mSettings = mGenerator->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // pattern const QString patternEditLabel = i18nc("@label:textbox", "Pattern:"); mPatternEdit = new Okteta::ByteArrayComboBox(this); mPatternEdit->setByteArray(mSettings.pattern); connect(mPatternEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &ByteArrayPatternGeneratorConfigEditor::onSettingsChanged); connect(mPatternEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &ByteArrayPatternGeneratorConfigEditor::onPatternChanged); const QString inputWhatsThis = i18nc("@info:whatsthis", "Enter a pattern to search for, or select a previous pattern from the list."); mPatternEdit->setWhatsThis(inputWhatsThis); pageLayout->addRow(patternEditLabel, mPatternEdit); // number const QString numberInputLabel = i18nc("@label:spinbox number of times to insert the pattern", "&Number:"); mNumberInput = new QSpinBox(this); mNumberInput->setRange(1, INT_MAX); mNumberInput->setValue(mSettings.count); connect(mNumberInput, QOverload::of(&QSpinBox::valueChanged), this, &ByteArrayPatternGeneratorConfigEditor::onSettingsChanged); const QString numberWhatsThis = i18nc("@info:whatsthis", "Enter the number of times the pattern should be inserted."); mNumberInput->setWhatsThis(numberWhatsThis); pageLayout->addRow(numberInputLabel, mNumberInput); } ByteArrayPatternGeneratorConfigEditor::~ByteArrayPatternGeneratorConfigEditor() = default; bool ByteArrayPatternGeneratorConfigEditor::isValid() const { return (!mSettings.pattern.isEmpty()); } QString ByteArrayPatternGeneratorConfigEditor::name() const { return i18nc("@item name of the generated data", "Pattern"); } // TODO: get char codec #if 0 void InsertPatternDialog::setCharCodec(const QString& codecName) { mPatternEdit->setCharCodec(codecName); } #endif void ByteArrayPatternGeneratorConfigEditor::onSettingsChanged() { mSettings.pattern = mPatternEdit->byteArray(); mSettings.count = mNumberInput->value(); mGenerator->setSettings(mSettings); } void ByteArrayPatternGeneratorConfigEditor::onPatternChanged(const QByteArray& pattern) { emit validityChanged(!pattern.isEmpty()); } } diff --git a/kasten/gui/io/generator/randomdata/bytearrayrandomdatageneratorconfigeditor.cpp b/kasten/gui/io/generator/randomdata/bytearrayrandomdatageneratorconfigeditor.cpp index 7552a8f3..c86652c7 100644 --- a/kasten/gui/io/generator/randomdata/bytearrayrandomdatageneratorconfigeditor.cpp +++ b/kasten/gui/io/generator/randomdata/bytearrayrandomdatageneratorconfigeditor.cpp @@ -1,81 +1,81 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayrandomdatageneratorconfigeditor.hpp" // KF5 #include // Qt #include #include namespace Kasten { ByteArrayRandomDataGeneratorConfigEditor::ByteArrayRandomDataGeneratorConfigEditor(ByteArrayRandomDataGenerator* generator, QWidget* parent) : AbstractModelDataGeneratorConfigEditor(parent) , mGenerator(generator) { mSettings = mGenerator->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // number const QString numberInputLabel = i18nc("@label:spinbox size of the bytearray to generate", "&Size (bytes):"); mSizeInput = new QSpinBox(this); mSizeInput->setRange(1, INT_MAX); mSizeInput->setValue(mSettings.size); connect(mSizeInput, QOverload::of(&QSpinBox::valueChanged), this, &ByteArrayRandomDataGeneratorConfigEditor::onSettingsChanged); const QString numberWhatsThis = i18nc("@info:whatsthis", "Enter the size of the bytearray to generate."); mSizeInput->setWhatsThis(numberWhatsThis); pageLayout->addRow(numberInputLabel, mSizeInput); } ByteArrayRandomDataGeneratorConfigEditor::~ByteArrayRandomDataGeneratorConfigEditor() = default; QString ByteArrayRandomDataGeneratorConfigEditor::name() const { return i18nc("@item name of the generated data", "Random Data"); } // TODO: get char codec #if 0 void InsertRandomDataDialog::setCharCodec(const QString& codecName) { mRandomDataEdit->setCharCodec(codecName); } #endif void ByteArrayRandomDataGeneratorConfigEditor::onSettingsChanged() { mSettings.size = mSizeInput->value(); mGenerator->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/base32/bytearraybase32streamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/base32/bytearraybase32streamencoderconfigeditor.cpp index 99654d33..224737b2 100644 --- a/kasten/gui/io/streamencoder/base32/bytearraybase32streamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/base32/bytearraybase32streamencoderconfigeditor.cpp @@ -1,80 +1,80 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraybase32streamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include #include // Qt #include #include namespace Kasten { ByteArrayBase32StreamEncoderConfigEditor::ByteArrayBase32StreamEncoderConfigEditor(ByteArrayBase32StreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // data type const QString encodingTypeLabel = i18nc("@label:listbox the type of the used encoding: Classic, Base32hex or z-base-32.", "Encoding:"); mEncodingSelect = new KComboBox(this); const QStringList list { i18nc("@item:inmenu Doing the base32 using the classical encoding", "Classic"), i18nc("@item:inmenu Doing the base32 using the Base32hex encoding", "Base32hex"), i18nc("@item:inmenu Doing the base32 using the z-base-32 encoding", "z-base-32"), }; mEncodingSelect->addItems(list); mEncodingSelect->setCurrentIndex(static_cast(mSettings.algorithmId)); connect(mEncodingSelect, QOverload::of(&KComboBox::activated), this, &ByteArrayBase32StreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(encodingTypeLabel, mEncodingSelect); } ByteArrayBase32StreamEncoderConfigEditor::~ByteArrayBase32StreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArrayBase32StreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArrayBase32StreamEncoderConfigEditor::onSettingsChanged() { mSettings.algorithmId = static_cast(mEncodingSelect->currentIndex()); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/ihex/bytearrayihexstreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/ihex/bytearrayihexstreamencoderconfigeditor.cpp index 0643e65f..008d1014 100644 --- a/kasten/gui/io/streamencoder/ihex/bytearrayihexstreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/ihex/bytearrayihexstreamencoderconfigeditor.cpp @@ -1,81 +1,81 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayihexstreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include #include // Qt #include #include namespace Kasten { ByteArrayIHexStreamEncoderConfigEditor::ByteArrayIHexStreamEncoderConfigEditor(ByteArrayIHexStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // data type const QString addressSizeLabel = i18nc("@label:listbox the size in bits of the addresses.", "Address size:"); mAddressSizeSelect = new KComboBox(this); // keep order in sync with IHexStreamEncoderSettings::AddressSizeId const QStringList addressSizeList { i18nc("@item:inmenu address size", "32-bit"), i18nc("@item:inmenu address size", "16-bit"), i18nc("@item:inmenu address size", "8-bit"), }; mAddressSizeSelect->addItems(addressSizeList); mAddressSizeSelect->setCurrentIndex(static_cast(mSettings.addressSizeId)); connect(mAddressSizeSelect, QOverload::of(&KComboBox::activated), this, &ByteArrayIHexStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(addressSizeLabel, mAddressSizeSelect); } ByteArrayIHexStreamEncoderConfigEditor::~ByteArrayIHexStreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArrayIHexStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArrayIHexStreamEncoderConfigEditor::onSettingsChanged() { mSettings.addressSizeId = static_cast(mAddressSizeSelect->currentIndex()); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/sourcecode/bytearraysourcecodestreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/sourcecode/bytearraysourcecodestreamencoderconfigeditor.cpp index 6bc8bc4d..f554f6ea 100644 --- a/kasten/gui/io/streamencoder/sourcecode/bytearraysourcecodestreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/sourcecode/bytearraysourcecodestreamencoderconfigeditor.cpp @@ -1,123 +1,123 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraysourcecodestreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include #include // Qt #include #include #include #include namespace Kasten { ByteArraySourceCodeStreamEncoderConfigEditor::ByteArraySourceCodeStreamEncoderConfigEditor(ByteArraySourceCodeStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // variable name const QString variableNameLabel = i18nc("@label:textbox name of the created variable", "Name of variable:"); mVariableNameEdit = new QLineEdit(this); mVariableNameEdit->setClearButtonEnabled(true); mVariableNameEdit->setText(mSettings.variableName); connect(mVariableNameEdit, &QLineEdit::textChanged, this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(variableNameLabel, mVariableNameEdit); // items per line const QString itemsPerLineLabel = i18nc("@label:textbox to define after how many items the list is wrapped", "Items per line:"); mItemsPerLineEdit = new QSpinBox(this); mItemsPerLineEdit->setMinimum(1); mItemsPerLineEdit->setValue(mSettings.elementsPerLine); connect(mItemsPerLineEdit, QOverload::of(&QSpinBox::valueChanged), this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(itemsPerLineLabel, mItemsPerLineEdit); // data type const QString dataTypeLabel = i18nc("@label:listbox the type of the data: char, integer, etc.", "Data type:"); mDataTypeSelect = new KComboBox(this); const char* const* dataTypeNames = mEncoder->dataTypeNames(); const int dataTypesCount = mEncoder->dataTypesCount(); QStringList dataTypeNameStrings; dataTypeNameStrings.reserve(dataTypesCount); for (int i = 0; i < dataTypesCount; ++i) { dataTypeNameStrings << QLatin1String(dataTypeNames[i]); } mDataTypeSelect->addItems(dataTypeNameStrings); mDataTypeSelect->setCurrentIndex(static_cast(mSettings.dataType)); connect(mDataTypeSelect, QOverload::of(&KComboBox::activated), this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(dataTypeLabel, mDataTypeSelect); // unsigned as hexadezimal const QString unsignedAsHexadecimalLabel = i18nc("@option:check Encode the values in hexadecimal instead of decimal, " "if the datatype has the property Unsigned", "Unsigned as hexadecimal:"); mUnsignedAsHexadecimalCheck = new QCheckBox(this); mUnsignedAsHexadecimalCheck->setChecked(mSettings.unsignedAsHexadecimal); connect(mUnsignedAsHexadecimalCheck, &QCheckBox::toggled, this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(unsignedAsHexadecimalLabel, mUnsignedAsHexadecimalCheck); } ByteArraySourceCodeStreamEncoderConfigEditor::~ByteArraySourceCodeStreamEncoderConfigEditor() = default; bool ByteArraySourceCodeStreamEncoderConfigEditor::isValid() const { return true; // TODO: warn if not all selected bytes are used due to the data type length } AbstractSelectionView* ByteArraySourceCodeStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged() { mSettings.variableName = mVariableNameEdit->text(); mSettings.elementsPerLine = mItemsPerLineEdit->value(); mSettings.dataType = static_cast(mDataTypeSelect->currentIndex()); mSettings.unsignedAsHexadecimal = mUnsignedAsHexadecimalCheck->isChecked(); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/srec/bytearraysrecstreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/srec/bytearraysrecstreamencoderconfigeditor.cpp index 3af6dc3a..7e2657c0 100644 --- a/kasten/gui/io/streamencoder/srec/bytearraysrecstreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/srec/bytearraysrecstreamencoderconfigeditor.cpp @@ -1,80 +1,80 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraysrecstreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include #include // Qt #include #include namespace Kasten { ByteArraySRecStreamEncoderConfigEditor::ByteArraySRecStreamEncoderConfigEditor(ByteArraySRecStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // data type const QString addressSizeLabel = i18nc("@label:listbox the size in bits of the addresses.", "Address size:"); mAddressSizeSelect = new KComboBox(this); const QStringList list { i18nc("@item:inmenu address size", "32-bit"), i18nc("@item:inmenu address size", "24-bit"), i18nc("@item:inmenu address size", "16-bit"), }; mAddressSizeSelect->addItems(list); mAddressSizeSelect->setCurrentIndex(static_cast(mSettings.addressSizeId)); connect(mAddressSizeSelect, QOverload::of(&KComboBox::activated), this, &ByteArraySRecStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(addressSizeLabel, mAddressSizeSelect); } ByteArraySRecStreamEncoderConfigEditor::~ByteArraySRecStreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArraySRecStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArraySRecStreamEncoderConfigEditor::onSettingsChanged() { mSettings.addressSizeId = static_cast(mAddressSizeSelect->currentIndex()); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/uuencoding/bytearrayuuencodingstreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/uuencoding/bytearrayuuencodingstreamencoderconfigeditor.cpp index a0954bb9..18745ca4 100644 --- a/kasten/gui/io/streamencoder/uuencoding/bytearrayuuencodingstreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/uuencoding/bytearrayuuencodingstreamencoderconfigeditor.cpp @@ -1,91 +1,91 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayuuencodingstreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include #include // Qt #include #include #include namespace Kasten { ByteArrayUuencodingStreamEncoderConfigEditor::ByteArrayUuencodingStreamEncoderConfigEditor(ByteArrayUuencodingStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // internal file name const QString fileNameLabel = i18nc("@label:textbox file name internally given to the encoded data", "Internal name of file:"); mFileNameEdit = new QLineEdit(this); mFileNameEdit->setClearButtonEnabled(true); mFileNameEdit->setText(mSettings.fileName); connect(mFileNameEdit, &QLineEdit::textChanged, this, &ByteArrayUuencodingStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(fileNameLabel, mFileNameEdit); // data type const QString encodingTypeLabel = i18nc("@label:listbox the type of the used encoding: historical or Base64.", "Encoding:"); mEncodingSelect = new KComboBox(this); const QStringList list { i18nc("@item:inmenu Doing the uuencoding using the historical encoding", "Historical"), i18nc("@item:inmenu Doing the uuencoding using the base64 encoding", "Base64"), }; mEncodingSelect->addItems(list); mEncodingSelect->setCurrentIndex(static_cast(mSettings.algorithmId)); connect(mEncodingSelect, QOverload::of(&KComboBox::activated), this, &ByteArrayUuencodingStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(encodingTypeLabel, mEncodingSelect); } ByteArrayUuencodingStreamEncoderConfigEditor::~ByteArrayUuencodingStreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArrayUuencodingStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArrayUuencodingStreamEncoderConfigEditor::onSettingsChanged() { mSettings.algorithmId = static_cast(mEncodingSelect->currentIndex()); mSettings.fileName = mFileNameEdit->text(); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/values/bytearrayvaluesstreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/values/bytearrayvaluesstreamencoderconfigeditor.cpp index 741201ff..eed040c8 100644 --- a/kasten/gui/io/streamencoder/values/bytearrayvaluesstreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/values/bytearrayvaluesstreamencoderconfigeditor.cpp @@ -1,93 +1,93 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayvaluesstreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include // #include // Qt #include #include #include namespace Kasten { ByteArrayValuesStreamEncoderConfigEditor::ByteArrayValuesStreamEncoderConfigEditor(ByteArrayValuesStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QGridLayout(this); // unknown rows - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); pageLayout->setColumnStretch(0, 0); pageLayout->setColumnStretch(1, 0); #if 0 // data type QLabel* label = new QLabel(i18n("Value coding:"), this); pageLayout->addWidget(label, 0, 0, Qt::AlignRight); mValueCodingSelect = new KComboBox(this); QStringList list; list.append(i18nc("@item:inmenu encoding of the bytes as values in the hexadecimal format", "Hexadecimal")); list.append(i18nc("@item:inmenu encoding of the bytes as values in the decimal format", "Decimal")); list.append(i18nc("@item:inmenu encoding of the bytes as values in the octal format", "Octal")); list.append(i18nc("@item:inmenu encoding of the bytes as values in the binary format", "Binary")); mValueCodingSelect->addItems(list); mValueCodingSelect->setCurrentIndex(mSettings.valueCoding); connect(mValueCodingSelect, SIGNAL(activated(int)), SLOT(onSettingsChanged())); pageLayout->addWidget(mValueCodingSelect, 0, 1); #endif // separation string QLabel* label = new QLabel(i18nc("@label:textbox substring which separates the values", "Separation:"), this); pageLayout->addWidget(label, 0, 0, Qt::AlignRight); mSeparationEdit = new QLineEdit(this); mSeparationEdit->setClearButtonEnabled(true); mSeparationEdit->setText(mSettings.separation); connect(mSeparationEdit, &QLineEdit::textChanged, this, &ByteArrayValuesStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addWidget(mSeparationEdit, 0, 1); // finish pageLayout->setRowStretch(2, 10); } ByteArrayValuesStreamEncoderConfigEditor::~ByteArrayValuesStreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArrayValuesStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArrayValuesStreamEncoderConfigEditor::onSettingsChanged() { // mSettings.valueCoding = (Okteta::ValueCoding) mValueCodingSelect->currentIndex(); mSettings.separation = mSeparationEdit->text(); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/io/streamencoder/xxencoding/bytearrayxxencodingstreamencoderconfigeditor.cpp b/kasten/gui/io/streamencoder/xxencoding/bytearrayxxencodingstreamencoderconfigeditor.cpp index 4e1c9e1e..14a8ffe3 100644 --- a/kasten/gui/io/streamencoder/xxencoding/bytearrayxxencodingstreamencoderconfigeditor.cpp +++ b/kasten/gui/io/streamencoder/xxencoding/bytearrayxxencodingstreamencoderconfigeditor.cpp @@ -1,71 +1,71 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayxxencodingstreamencoderconfigeditor.hpp" // lib #include "bytearraytextstreamencoderpreview.hpp" // KF5 #include // Qt #include #include #include namespace Kasten { ByteArrayXxencodingStreamEncoderConfigEditor::ByteArrayXxencodingStreamEncoderConfigEditor(ByteArrayXxencodingStreamEncoder* encoder, QWidget* parent) : AbstractModelStreamEncoderConfigEditor(parent) , mEncoder(encoder) { mSettings = mEncoder->settings(); auto* pageLayout = new QFormLayout(this); - pageLayout->setMargin(0); + pageLayout->setContentsMargins(0, 0, 0, 0); // internal file name const QString fileNameLabel = i18nc("@label:textbox file name internally given to the encoded data", "Internal name of file:"); mFileNameEdit = new QLineEdit(this); mFileNameEdit->setClearButtonEnabled(true); mFileNameEdit->setText(mSettings.fileName); connect(mFileNameEdit, &QLineEdit::textChanged, this, &ByteArrayXxencodingStreamEncoderConfigEditor::onSettingsChanged); pageLayout->addRow(fileNameLabel, mFileNameEdit); } ByteArrayXxencodingStreamEncoderConfigEditor::~ByteArrayXxencodingStreamEncoderConfigEditor() = default; AbstractSelectionView* ByteArrayXxencodingStreamEncoderConfigEditor::createPreviewView() const { return new ByteArrayTextStreamEncoderPreview(mEncoder); } void ByteArrayXxencodingStreamEncoderConfigEditor::onSettingsChanged() { mSettings.fileName = mFileNameEdit->text(); mEncoder->setSettings(mSettings); } } diff --git a/kasten/gui/liboktetawidgets/addresscombobox_p.cpp b/kasten/gui/liboktetawidgets/addresscombobox_p.cpp index d4a16f29..65683525 100644 --- a/kasten/gui/liboktetawidgets/addresscombobox_p.cpp +++ b/kasten/gui/liboktetawidgets/addresscombobox_p.cpp @@ -1,172 +1,172 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "addresscombobox_p.hpp" #include "addresscombobox.hpp" // KF5 #include // Qt #include #include #include /* Problem: what to do if the format is changed for which the current string is not valid? Solution: we always convert the string to the new format, so there is never such a situation */ namespace Okteta { static const QStringList& formatStrings() { static QStringList list = QStringList { // i18nc("@item:inlistbox guessing the format of the address by the input", "Auto"), i18nc("@item:inlistbox coding of offset in the hexadecimal format", "Hex"), i18nc("@item:inlistbox coding of offset in the decimal format", "Dec"), i18nc("@item:inlistbox coding of offset in the expression format", "Expr"), }; return list; } void AddressComboBoxPrivate::init() { Q_Q(AddressComboBox); auto* baseLayout = new QHBoxLayout(q); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); baseLayout->setSpacing(0); mFormatComboBox = new KComboBox(q); mFormatComboBox->addItems(formatStrings()); QObject::connect(mFormatComboBox, QOverload::of(&QComboBox::activated), q, [&](int index) { onFormatChanged(index); }); mValueComboBox = new KComboBox(q); mValueComboBox->setEditable(true); mValueComboBox->setMaxCount(10); mValueComboBox->setInsertPolicy(QComboBox::NoInsert); mValueComboBox->setDuplicatesEnabled(false); q->setFocusProxy(mValueComboBox); QObject::connect(mValueComboBox->lineEdit(), &QLineEdit::textEdited, q, [&](const QString& text) { onValueEdited(text); }); QAbstractItemView* formatComboBoxListView = mFormatComboBox->view(); QObject::connect(formatComboBoxListView, &QAbstractItemView::activated, mValueComboBox, QOverload<>::of(&KComboBox::setFocus)); // TODO: is a workaround for Qt 4.5.1 which doesn't emit activated() for mouse clicks QObject::connect(formatComboBoxListView, &QAbstractItemView::pressed, mValueComboBox, QOverload<>::of(&KComboBox::setFocus)); mValidator = new AddressValidator(mValueComboBox, AddressValidator::HexadecimalCoding); const AddressValidator::Coding coding = static_cast(mFormatComboBox->currentIndex()); mValidator->setCodec(coding); mValueComboBox->setValidator(mValidator); QObject::connect(mValueComboBox, QOverload::of(&QComboBox::activated), q, [&](int index) { onValueActivated(index); }); baseLayout->addWidget(mFormatComboBox); baseLayout->addWidget(mValueComboBox, 1); QWidget::setTabOrder(mFormatComboBox, mValueComboBox); } void AddressComboBoxPrivate::rememberCurrentAddress() { // don't insert same value multiple times in a row if (mValueComboBox->itemText(0) != mValueComboBox->currentText()) { mValueComboBox->insertItem(-1, mValueComboBox->currentText(), mFormatComboBox->currentIndex()); } } void AddressComboBoxPrivate::onFormatChanged(int formatIndex) { Q_Q(AddressComboBox); const QString currentValueText = mValueComboBox->currentText(); const bool isCurrentValueTextEmpty = currentValueText.isEmpty(); AddressValidator::AddressType addressType; Address address; if (isCurrentValueTextEmpty) { address = -1; addressType = mAddressType; } else { address = mValidator->toAddress(currentValueText, &addressType); } mValidator->setCodec(static_cast(formatIndex)); if (!isCurrentValueTextEmpty) { const QString convertedValueText = mValidator->toString(address, addressType); mValueComboBox->setEditText(convertedValueText); } if (mAddressType != addressType) { mAddressType = addressType; emit q->addressTypeChanged(mAddressType); } emit q->formatChanged(formatIndex); } void AddressComboBoxPrivate::onValueEdited(const QString& value) { Q_Q(AddressComboBox); AddressValidator::AddressType addressType; const Address address = mValidator->toAddress(value, &addressType); if (mAddressType != addressType) { mAddressType = addressType; emit q->addressTypeChanged(mAddressType); } emit q->addressChanged(address); } void AddressComboBoxPrivate::onValueActivated(int index) { Q_Q(AddressComboBox); if (index != -1) { const int oldFormatIndex = mFormatComboBox->currentIndex(); const int itemFormatIndex = mValueComboBox->itemData(index).toInt(); const bool isOtherFormat = (oldFormatIndex != itemFormatIndex); if (isOtherFormat) { mFormatComboBox->setCurrentIndex(itemFormatIndex); mValidator->setCodec(static_cast(itemFormatIndex)); } const QString currentValueText = mValueComboBox->currentText(); AddressValidator::AddressType addressType; const Address address = mValidator->toAddress(currentValueText, &addressType); if (mAddressType != addressType) { mAddressType = addressType; emit q->addressTypeChanged(mAddressType); } emit q->addressChanged(address); if (isOtherFormat) { emit q->formatChanged(itemFormatIndex); } } } } diff --git a/kasten/gui/liboktetawidgets/bytearraycombobox_p.cpp b/kasten/gui/liboktetawidgets/bytearraycombobox_p.cpp index 1953338a..ee30df7f 100644 --- a/kasten/gui/liboktetawidgets/bytearraycombobox_p.cpp +++ b/kasten/gui/liboktetawidgets/bytearraycombobox_p.cpp @@ -1,214 +1,214 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009,2011 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraycombobox_p.hpp" #include "bytearraycombobox.hpp" // KF5 #include // Qt #include #include #include namespace Okteta { const QStringList& formatNames() { static QStringList list = QStringList { // i18nc("@item:inlistbox guessing the coding of the bytes by the input", "Auto"), i18nc("@item:inlistbox coding of the bytes as values in the hexadecimal format", "Hex"), i18nc("@item:inlistbox coding of the bytes as values in the decimal format", "Dec"), i18nc("@item:inlistbox coding of the bytes as values in the octal format", "Oct"), i18nc("@item:inlistbox coding of the bytes as values in the binary format", "Bin"), i18nc("@item:inlistbox coding of the bytes as characters with the values", "Char"), i18nc("@item:inlistbox coding of the bytes as UTF-8 characters with the values", "UTF-8"), }; return list; } void ByteArrayComboBoxPrivate::init() { Q_Q(ByteArrayComboBox); auto* baseLayout = new QHBoxLayout(q); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); baseLayout->setSpacing(0); mFormatComboBox = new KComboBox(q); mFormatComboBox->addItems(formatNames()); QObject::connect(mFormatComboBox, QOverload::of(&QComboBox::activated), q, [&](int index) { onFormatChanged(index); }); mValueComboBox = new KComboBox(q); mValueComboBox->setEditable(true); mValueComboBox->setMaxCount(10); mValueComboBox->setInsertPolicy(QComboBox::NoInsert); mValueComboBox->setDuplicatesEnabled(false); q->setFocusProxy(mValueComboBox); QObject::connect(mValueComboBox->lineEdit(), &QLineEdit::textEdited, q, [&](const QString& text) { onValueEdited(text); }); QAbstractItemView* formatComboBoxListView = mFormatComboBox->view(); QObject::connect(formatComboBoxListView, &QAbstractItemView::activated, mValueComboBox, QOverload<>::of(&KComboBox::setFocus)); // TODO: is a workaround for Qt 4.5.1 which doesn't emit activated() for mouse clicks QObject::connect(formatComboBoxListView, &QAbstractItemView::pressed, mValueComboBox, QOverload<>::of(&KComboBox::setFocus)); mValidator = new ByteArrayValidator(mValueComboBox); const ByteArrayValidator::Coding coding = static_cast(mFormatComboBox->currentIndex()); mValidator->setCodec(coding); mValueComboBox->setValidator(mValidator); QObject::connect(mValueComboBox, QOverload::of(&QComboBox::activated), q, [&](int index) { onValueActivated(index); }); baseLayout->addWidget(mFormatComboBox); baseLayout->addWidget(mValueComboBox, 1); QWidget::setTabOrder(mFormatComboBox, mValueComboBox); } void ByteArrayComboBoxPrivate::setByteArray(const QByteArray& byteArray) { mValueComboBox->setEditText(mValidator->toString(byteArray)); } void ByteArrayComboBoxPrivate::setCharCodec(const QString& charCodecName) { const bool isChar8Visible = (mFormatComboBox->currentIndex() == ByteArrayValidator::CharCoding); // update the char string if shown QByteArray currentByteArray; if (isChar8Visible) { const QString currentChar8String = mValueComboBox->currentText(); currentByteArray = mValidator->toByteArray(currentChar8String); } mValidator->setCharCodec(charCodecName); if (isChar8Visible) { const QString char8String = mValidator->toString(currentByteArray); mValueComboBox->setEditText(char8String); } } void ByteArrayComboBoxPrivate::setMaxLength(int maxLength) { const int oldMaxLength = mValidator->maxLength(); if (oldMaxLength == maxLength) { return; } mValidator->setMaxLength(maxLength); if (oldMaxLength > maxLength) { QString currentText = mValueComboBox->currentText(); int dummyPos; mValidator->validate(currentText, dummyPos); mValueComboBox->setEditText(currentText); } } void ByteArrayComboBoxPrivate::setMinLength(int minLength) { const int oldMinLength = mValidator->minLength(); if (oldMinLength == minLength) { return; } mValidator->setMinLength(minLength); if (oldMinLength < minLength) { QString currentText = mValueComboBox->currentText(); int dummyPos; mValidator->validate(currentText, dummyPos); mValueComboBox->setEditText(currentText); } } void ByteArrayComboBoxPrivate::rememberCurrentByteArray() { mValueComboBox->insertItem(-1, mValueComboBox->currentText(), mFormatComboBox->currentIndex()); } int ByteArrayComboBoxPrivate::maxLength() const { return mValidator->maxLength(); } int ByteArrayComboBoxPrivate::minLength() const { return mValidator->minLength(); } void ByteArrayComboBoxPrivate::onFormatChanged(int index) { Q_Q(ByteArrayComboBox); const QString currentValueText = mValueComboBox->currentText(); const bool isCurrentValueTextEmpty = currentValueText.isEmpty(); const QByteArray byteArray = isCurrentValueTextEmpty ? QByteArray() : mValidator->toByteArray(currentValueText); mValidator->setCodec(static_cast(index)); if (!isCurrentValueTextEmpty) { const QString convertedValueText = mValidator->toString(byteArray); mValueComboBox->setEditText(convertedValueText); } emit q->formatChanged(index); } void ByteArrayComboBoxPrivate::onValueEdited(const QString& value) { Q_Q(ByteArrayComboBox); const QByteArray byteArray = mValidator->toByteArray(value); emit q->byteArrayChanged(byteArray); } void ByteArrayComboBoxPrivate::onValueActivated(int index) { Q_Q(ByteArrayComboBox); if (index != -1) { const int oldFormatIndex = mFormatComboBox->currentIndex(); const int itemFormatIndex = mValueComboBox->itemData(index).toInt(); const bool isOtherFormat = (oldFormatIndex != itemFormatIndex); if (isOtherFormat) { mFormatComboBox->setCurrentIndex(itemFormatIndex); mValidator->setCodec(static_cast(itemFormatIndex)); } const QString currentValueText = mValueComboBox->currentText(); const QByteArray byteArray = mValidator->toByteArray(currentValueText); emit q->byteArrayChanged(byteArray); if (isOtherFormat) { emit q->formatChanged(itemFormatIndex); } } } } diff --git a/kasten/gui/view/bytearrayjanusview.cpp b/kasten/gui/view/bytearrayjanusview.cpp index 2267e6ed..953f865f 100644 --- a/kasten/gui/view/bytearrayjanusview.cpp +++ b/kasten/gui/view/bytearrayjanusview.cpp @@ -1,386 +1,386 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2008-2012 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearrayjanusview.hpp" // Okteta gui #include #include // Qt #include #include namespace Okteta { ByteArrayJanusView::ByteArrayJanusView(QWidget* parent) : QWidget(parent) { mLayout = new QHBoxLayout(this); - mLayout->setMargin(0); + mLayout->setContentsMargins(0, 0, 0, 0); setViewModus(ColumnViewId); } ByteArrayJanusView::~ByteArrayJanusView() = default; void ByteArrayJanusView::setByteArrayModel(AbstractByteArrayModel* byteArrayModel) { mView->setByteArrayModel(byteArrayModel); } void ByteArrayJanusView::setViewModus(int viewModus) { if (viewModus == mViewModus) { return; } AbstractByteArrayView* newView = (viewModus == ColumnViewId) ? (AbstractByteArrayView*)new ByteArrayColumnView(this) : (AbstractByteArrayView*)new ByteArrayRowView(this); const bool hasFocus = mView ? mView->hasFocus() : false; if (mView) { newView->setFont(mView->font()); newView->setByteArrayModel(mView->byteArrayModel()); newView->setReadOnly(mView->isReadOnly()); newView->setOverwriteMode(mView->isOverwriteMode()); newView->setZoomLevel(mView->zoomLevel()); newView->setShowsNonprinting(mView->showsNonprinting()); newView->setValueCoding(mView->valueCoding()); newView->setCharCoding(mView->charCodingName()); newView->setVisibleCodings(mView->visibleCodings()); newView->setActiveCoding(mView->activeCoding()); newView->toggleOffsetColumn(mView->offsetColumnVisible()); newView->setOffsetCoding(mView->offsetCoding()); newView->setStartOffset(mView->startOffset()); newView->setFirstLineOffset(mView->firstLineOffset()); newView->setNoOfBytesPerLine(mView->noOfBytesPerLine()); newView->setNoOfGroupedBytes(mView->noOfGroupedBytes()); newView->setLayoutStyle(mView->layoutStyle()); newView->setSubstituteChar(mView->substituteChar()); newView->setUndefinedChar(mView->undefinedChar()); newView->setCursorPosition(mView->cursorPosition()); newView->setSelection(mView->selection()); newView->setMarking(mView->marking()); mLayout->removeWidget(mView); delete mView; } mView = newView; mLayout->addWidget(mView); setFocusProxy(mView); if (hasFocus) { mView->setFocus(); } mViewModus = viewModus; mView->setContextMenuPolicy(Qt::CustomContextMenu); connect(mView, &QWidget::customContextMenuRequested, this, &ByteArrayJanusView::viewContextMenuRequested); connect(mView, &AbstractByteArrayView::hasSelectedDataChanged, this, &ByteArrayJanusView::hasSelectedDataChanged); connect(mView, &AbstractByteArrayView::selectionChanged, this, &ByteArrayJanusView::selectionChanged); connect(mView, &AbstractByteArrayView::readOnlyChanged, this, &ByteArrayJanusView::readOnlyChanged); connect(mView, &AbstractByteArrayView::overwriteModeChanged, this, &ByteArrayJanusView::overwriteModeChanged); connect(mView, &AbstractByteArrayView::cursorPositionChanged, this, &ByteArrayJanusView::cursorPositionChanged); connect(mView, &AbstractByteArrayView::valueCodingChanged, this, &ByteArrayJanusView::valueCodingChanged); connect(mView, &AbstractByteArrayView::charCodecChanged, this, &ByteArrayJanusView::charCodecChanged); connect(mView, &AbstractByteArrayView::focusChanged, this, &ByteArrayJanusView::focusChanged); connect(mView, &AbstractByteArrayView::offsetColumnVisibleChanged, this, &ByteArrayJanusView::offsetColumnVisibleChanged); connect(mView, &AbstractByteArrayView::offsetCodingChanged, this, &ByteArrayJanusView::offsetCodingChanged); connect(mView, &AbstractByteArrayView::visibleByteArrayCodingsChanged, this, &ByteArrayJanusView::visibleByteArrayCodingsChanged); connect(mView, &AbstractByteArrayView::layoutStyleChanged, this, &ByteArrayJanusView::layoutStyleChanged); connect(mView, &AbstractByteArrayView::noOfBytesPerLineChanged, this, &ByteArrayJanusView::noOfBytesPerLineChanged); connect(mView, &AbstractByteArrayView::showsNonprintingChanged, this, &ByteArrayJanusView::showsNonprintingChanged); connect(mView, &AbstractByteArrayView::substituteCharChanged, this, &ByteArrayJanusView::substituteCharChanged); connect(mView, &AbstractByteArrayView::undefinedCharChanged, this, &ByteArrayJanusView::undefinedCharChanged); connect(mView, &AbstractByteArrayView::noOfGroupedBytesChanged, this, &ByteArrayJanusView::noOfGroupedBytesChanged); connect(mView, &AbstractByteArrayView::zoomLevelChanged, this, &ByteArrayJanusView::zoomLevelChanged); emit viewModusChanged(mViewModus); } bool ByteArrayJanusView::isReadOnly() const { return mView->isReadOnly(); } void ByteArrayJanusView::setReadOnly(bool isReadOnly) { mView->setReadOnly(isReadOnly); } void ByteArrayJanusView::setZoomLevel(double Level) { mView->setZoomLevel(Level); } double ByteArrayJanusView::zoomLevel() const { return mView->zoomLevel(); } void ByteArrayJanusView::selectAll(bool selectAll) { mView->selectAll(selectAll); } bool ByteArrayJanusView::hasSelectedData() const { return mView->hasSelectedData(); } QMimeData* ByteArrayJanusView::selectionAsMimeData() const { return mView->selectionAsMimeData(); } void ByteArrayJanusView::pasteData(const QMimeData* data) { mView->pasteData(data); } void ByteArrayJanusView::removeSelectedData() { mView->removeSelectedData(); } bool ByteArrayJanusView::canReadData(const QMimeData* data) const { return mView->canReadData(data); } void ByteArrayJanusView::setCursorPosition(Address cursorPosition) { mView->setCursorPosition(cursorPosition); } void ByteArrayJanusView::setSelectionCursorPosition(Address index) { mView->setSelectionCursorPosition(index); } Address ByteArrayJanusView::cursorPosition() const { return mView->cursorPosition(); } QRect ByteArrayJanusView::cursorRect() const { // Okteta Gui uses viewport coordinates like QTextEdit, // but here view coordinates are used, so map the rect as needed QRect cursorRect = mView->cursorRect(); const QPoint viewTopLeft = mView->viewport()->mapToParent(cursorRect.topLeft()); cursorRect.moveTopLeft(viewTopLeft); return cursorRect; } void ByteArrayJanusView::setStartOffset(Address startOffset) { mView->setStartOffset(startOffset); } void ByteArrayJanusView::setFirstLineOffset(Address firstLineOffset) { mView->setFirstLineOffset(firstLineOffset); } void ByteArrayJanusView::setNoOfBytesPerLine(int noOfBytesPerLine) { mView->setNoOfBytesPerLine(noOfBytesPerLine); } Address ByteArrayJanusView::startOffset() const { return mView->startOffset(); } Address ByteArrayJanusView::firstLineOffset() const { return mView->firstLineOffset(); } int ByteArrayJanusView::noOfBytesPerLine() const { return mView->noOfBytesPerLine(); } int ByteArrayJanusView::valueCoding() const { return mView->valueCoding(); } QString ByteArrayJanusView::charCodingName() const { return mView->charCodingName(); } void ByteArrayJanusView::setValueCoding(int valueCoding) { mView->setValueCoding((AbstractByteArrayView::ValueCoding)valueCoding); } void ByteArrayJanusView::setCharCoding(const QString& charCodingName) { mView->setCharCoding(charCodingName); } AddressRange ByteArrayJanusView::selection() const { return mView->selection(); } void ByteArrayJanusView::setSelection(Address start, Address end) { mView->setSelection(start, end); } void ByteArrayJanusView::setMarking(const AddressRange& marking) { mView->setMarking(marking); } void ByteArrayJanusView::ensureVisible(const AddressRange& range) { mView->ensureVisible(range); } void ByteArrayJanusView::insert(const QByteArray& byteArray) { mView->insert(byteArray); } bool ByteArrayJanusView::showsNonprinting() const { return false; // TODOSHOWNONPRINTING pin to false for now return mView->showsNonprinting(); } bool ByteArrayJanusView::offsetColumnVisible() const { return mView->offsetColumnVisible(); } int ByteArrayJanusView::offsetCoding() const { return mView->offsetCoding(); } int ByteArrayJanusView::layoutStyle() const { return (int)mView->layoutStyle(); } int ByteArrayJanusView::visibleCodings() const { return (int)mView->visibleCodings(); } bool ByteArrayJanusView::isOverwriteMode() const { return mView->isOverwriteMode(); } void ByteArrayJanusView::setShowsNonprinting(bool on) { Q_UNUSED(on); // TODOSHOWNONPRINTING mView->setShowsNonprinting(on); } void ByteArrayJanusView::setNoOfGroupedBytes(int noOfGroupedBytes) { mView->setNoOfGroupedBytes(noOfGroupedBytes); } void ByteArrayJanusView::setSubstituteChar(QChar substituteChar) { mView->setSubstituteChar(substituteChar); } void ByteArrayJanusView::setUndefinedChar(QChar undefinedChar) { mView->setUndefinedChar(undefinedChar); } void ByteArrayJanusView::toggleOffsetColumn(bool on) { mView->toggleOffsetColumn(on); } void ByteArrayJanusView::setOffsetCoding(int offsetCoding) { mView->setOffsetCoding((AbstractByteArrayView::OffsetCoding)offsetCoding); } void ByteArrayJanusView::setLayoutStyle(int layoutStyle) { mView->setLayoutStyle((AbstractByteArrayView::LayoutStyle)layoutStyle); } void ByteArrayJanusView::setVisibleCodings(int visibleColumns) { mView->setVisibleCodings(visibleColumns); } QChar ByteArrayJanusView::substituteChar() const { return mView->substituteChar(); } QChar ByteArrayJanusView::undefinedChar() const { return mView->undefinedChar(); } int ByteArrayJanusView::byteSpacingWidth() const { return mView->byteSpacingWidth(); } int ByteArrayJanusView::noOfGroupedBytes() const { return mView->noOfGroupedBytes(); } int ByteArrayJanusView::groupSpacingWidth() const { return mView->groupSpacingWidth(); } int ByteArrayJanusView::binaryGapWidth() const { return mView->binaryGapWidth(); } bool ByteArrayJanusView::isOverwriteOnly() const { return mView->isOverwriteOnly(); } void ByteArrayJanusView::setOverwriteMode(bool overwriteMode) { mView->setOverwriteMode(overwriteMode); } void ByteArrayJanusView::setViewPos(const QPoint& pos) { mView->horizontalScrollBar()->setValue(pos.x()); mView->verticalScrollBar()->setValue(pos.y()); } QRect ByteArrayJanusView::viewRect() const { // TODO: find why mView->viewport()->rect() doesn't work but is always at pos (0.0) const QRect result( QPoint(mView->horizontalScrollBar()->value(), mView->verticalScrollBar()->value()), mView->viewport()->size()); return result; } void ByteArrayJanusView::propagateFont(const QFont& font) { setFont(font); mView->setFont(font); } } diff --git a/libs/kasten/controllers/document/terminal/terminalview.cpp b/libs/kasten/controllers/document/terminal/terminalview.cpp index c553d74f..acc8a868 100644 --- a/libs/kasten/controllers/document/terminal/terminalview.cpp +++ b/libs/kasten/controllers/document/terminal/terminalview.cpp @@ -1,108 +1,108 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "terminalview.hpp" // lib #include "terminaltool.hpp" // KF5 #include #include #include #include // Qt #include #include #include #include namespace Kasten { TerminalView::TerminalView(TerminalTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { auto* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); connect(mTool, &TerminalTool::currentUrlChanged, this, &TerminalView::onCurrentUrlChanged); QMetaObject::invokeMethod(this, "createTerminalPart", Qt::QueuedConnection); } TerminalView::~TerminalView() { if (mTerminalPart) { disconnect(mTerminalPart, &QObject::destroyed, this, &TerminalView::onTerminalPartDestroyed); } } void TerminalView::createTerminalPart() { mTerminalPart = KServiceTypeTrader::createInstanceFromQuery( QStringLiteral("TerminalEmulator"), this, this); if (mTerminalPart) { connect(mTerminalPart, &QObject::destroyed, this, &TerminalView::onTerminalPartDestroyed); QWidget* terminalWidget = mTerminalPart->widget(); terminalWidget->setFocusPolicy(Qt::WheelFocus); terminalWidget->setFocus(); setFocusProxy(terminalWidget); auto* frame = qobject_cast(terminalWidget); if (frame) { frame->setFrameStyle(QFrame::Panel | QFrame::Sunken); } auto* layout = static_cast(this->layout()); layout->addWidget(terminalWidget); terminalWidget->show(); mTerminalInterface = qobject_cast(mTerminalPart); QUrl currentUrl = mTool->currentUrl(); if (currentUrl.isEmpty()) { currentUrl = QUrl::fromLocalFile(QDir::homePath()); } onCurrentUrlChanged(currentUrl); } } void TerminalView::onCurrentUrlChanged(const QUrl& currentUrl) { if (mTerminalInterface && currentUrl.isLocalFile()) { mTerminalInterface->showShellInDir(currentUrl.path()); } // TODO: Konsole currently seems to ignore this call if shell is running? } void TerminalView::onTerminalPartDestroyed() { mTerminalPart = nullptr; mTerminalInterface = nullptr; createTerminalPart(); } } diff --git a/libs/kasten/controllers/document/versionview/versionview.cpp b/libs/kasten/controllers/document/versionview/versionview.cpp index 0f8ba50f..5cf9cb79 100644 --- a/libs/kasten/controllers/document/versionview/versionview.cpp +++ b/libs/kasten/controllers/document/versionview/versionview.cpp @@ -1,75 +1,75 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2008 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "versionview.hpp" // tool #include "versiontablemodel.hpp" #include "versionviewtool.hpp" // Kasten core #include #include // Qt #include #include namespace Kasten { VersionView::VersionView(VersionViewTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { mVersionTableModel = new VersionTableModel(nullptr, nullptr, this); auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); mVersionTableView = new QTreeView(this); mVersionTableView->setObjectName(QStringLiteral("VersionsTable")); mVersionTableView->setRootIsDecorated(false); mVersionTableView->setItemsExpandable(false); mVersionTableView->setUniformRowHeights(true); mVersionTableView->setAllColumnsShowFocus(true); mVersionTableView->setModel(mVersionTableModel); baseLayout->addWidget(mVersionTableView, 10); connect(mTool, &Kasten::VersionViewTool::modelChanged, this, &VersionView::setModel); setModel(mTool->model()); } VersionView::~VersionView() = default; void VersionView::setModel(AbstractModel* model) { If::Versionable* versionControl = model ? qobject_cast(model) : nullptr; mVersionTableModel->setModel(model, versionControl); for (int c = 0; c < VersionTableModel::NoOfColumnIds; ++c) { mVersionTableView->resizeColumnToContents(c); } } } diff --git a/libs/kasten/controllers/documentsystem/documentsbrowser/documentsview.cpp b/libs/kasten/controllers/documentsystem/documentsbrowser/documentsview.cpp index d4925802..4b44b3ea 100644 --- a/libs/kasten/controllers/documentsystem/documentsbrowser/documentsview.cpp +++ b/libs/kasten/controllers/documentsystem/documentsbrowser/documentsview.cpp @@ -1,72 +1,72 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "documentsview.hpp" // tool #include "documentlistmodel.hpp" #include "documentstool.hpp" // Qt #include #include namespace Kasten { DocumentsView::DocumentsView(DocumentsTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { mDocumentListModel = new DocumentListModel(mTool, this); auto* baseLayout = new QVBoxLayout(this); - baseLayout->setMargin(0); + baseLayout->setContentsMargins(0, 0, 0, 0); baseLayout->setSpacing(0); mDocumentListView = new QTreeView(this); mDocumentListView->setObjectName(QStringLiteral("DocumentListView")); mDocumentListView->setRootIsDecorated(false); mDocumentListView->setItemsExpandable(false); mDocumentListView->setUniformRowHeights(true); mDocumentListView->setAllColumnsShowFocus(true); mDocumentListView->setModel(mDocumentListModel); connect(mDocumentListView, &QAbstractItemView::activated, this, &DocumentsView::onDocumentActivated); for (int c = 0; c < DocumentListModel::NoOfColumnIds; ++c) { mDocumentListView->resizeColumnToContents(c); } baseLayout->addWidget(mDocumentListView, 10); } DocumentsView::~DocumentsView() = default; void DocumentsView::onDocumentActivated(const QModelIndex& index) { const int documentIndex = index.row(); AbstractDocument* document = mTool->documents().at(documentIndex); if (document) { mTool->setFocussedDocument(document); } } } diff --git a/libs/kasten/controllers/documentsystem/filesystembrowser/filesystembrowserview.cpp b/libs/kasten/controllers/documentsystem/filesystembrowser/filesystembrowserview.cpp index 1684fd21..be07d636 100644 --- a/libs/kasten/controllers/documentsystem/filesystembrowser/filesystembrowserview.cpp +++ b/libs/kasten/controllers/documentsystem/filesystembrowser/filesystembrowserview.cpp @@ -1,123 +1,123 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "filesystembrowserview.hpp" // lib #include "filesystembrowsertool.hpp" // KF5 #include #include #include #include #include #include // Qt #include #include #include namespace Kasten { FileSystemBrowserView::FileSystemBrowserView(FileSystemBrowserTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) { QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } FileSystemBrowserView::~FileSystemBrowserView() = default; void FileSystemBrowserView::init() { auto* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); // tool bar mToolbar = new KToolBar(this); mToolbar->setMovable(false); mToolbar->setToolButtonStyle(Qt::ToolButtonIconOnly); mToolbar->setIconDimensions(16); mToolbar->setContextMenuPolicy(Qt::NoContextMenu); layout->addWidget(mToolbar); // url bar auto* filePlacesModel = new KFilePlacesModel(this); mUrlNavigator = new KUrlNavigator(filePlacesModel, QUrl::fromLocalFile(QDir::homePath()), this); connect(mUrlNavigator, &KUrlNavigator::urlChanged, this, &FileSystemBrowserView::setDirOperatorUrl); layout->addWidget(mUrlNavigator); // view mDirOperator = new KDirOperator(QUrl::fromLocalFile(QDir::homePath()), this); mDirOperator->setView(KFile::Detail); connect(mDirOperator, &KDirOperator::urlEntered, this, &FileSystemBrowserView::setNavigatorUrl); connect(mDirOperator, &KDirOperator::fileSelected, this, &FileSystemBrowserView::openFile); layout->addWidget(mDirOperator); // fill toolbar constexpr const char* ToolbarActionNames[] = { "back", "forward", "up", "home", "short view", "detailed view", "tree view" }; const KActionCollection* dirOperatorActionCollection = mDirOperator->actionCollection(); for (auto* actionName : ToolbarActionNames) { QAction* action = dirOperatorActionCollection->action(QLatin1String(actionName)); if (action) { mToolbar->addAction(action); } } mActionCollection = new KActionCollection(this); QAction* syncDirAction = mActionCollection->addAction(QStringLiteral("sync_dir"), this, &FileSystemBrowserView::syncCurrentDocumentDirectory); syncDirAction->setIcon(QIcon::fromTheme(QStringLiteral("go-parent-folder"))); syncDirAction->setText(i18nc("@action:intoolbar", "Folder of Current Document")); connect(mTool, &FileSystemBrowserTool::hasCurrentUrlChanged, syncDirAction, &QAction::setEnabled); syncDirAction->setEnabled(mTool->hasCurrentUrl()); mToolbar->addAction(syncDirAction); } void FileSystemBrowserView::setDirOperatorUrl(const QUrl& url) { mDirOperator->setUrl(url, true); } void FileSystemBrowserView::setNavigatorUrl(const QUrl& url) { mUrlNavigator->setLocationUrl(url); } void FileSystemBrowserView::syncCurrentDocumentDirectory() { const QUrl url = mTool->currentUrl(); if (!url.isEmpty()) { setNavigatorUrl(url); } } void FileSystemBrowserView::openFile(const KFileItem& fileItem) { mTool->open(fileItem.url()); } } diff --git a/libs/kasten/controllers/view/zoom/zoomslider.cpp b/libs/kasten/controllers/view/zoom/zoomslider.cpp index a700780c..61e8377f 100644 --- a/libs/kasten/controllers/view/zoom/zoomslider.cpp +++ b/libs/kasten/controllers/view/zoom/zoomslider.cpp @@ -1,178 +1,178 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2008-2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "zoomslider.hpp" // Kasten gui #include // Kasten core #include // KF5 #include // Qt #include #include #include #include #include namespace Kasten { static constexpr int ZoomSliderWidth = 150; // TODO: look at Dolphin/Krita/KOffice zoom tool // TODO: different zoom strategies: fixed step size, relative step size // where to put this, behind interface? or better into a zoomtool? ZoomSlider::ZoomSlider(QWidget* parent) : QWidget(parent) { mZoomOutButton = new QToolButton(this); mZoomOutButton->setIcon(QIcon::fromTheme(QStringLiteral("zoom-out"))); mZoomOutButton->setAutoRaise(true); mSlider = new QSlider(Qt::Horizontal, this); mZoomInButton = new QToolButton(this); mZoomInButton->setIcon(QIcon::fromTheme(QStringLiteral("zoom-in"))); mZoomInButton->setAutoRaise(true); auto* layout = new QHBoxLayout(this); layout->setSpacing(0); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(mZoomOutButton); layout->addWidget(mSlider); layout->addWidget(mZoomInButton); connect(mZoomOutButton, &QAbstractButton::clicked, this, &ZoomSlider::zoomOut); connect(mZoomInButton, &QAbstractButton::clicked, this, &ZoomSlider::zoomIn); connect(mSlider, &QSlider::valueChanged, this, &ZoomSlider::onSliderValueChanged); connect(mSlider, &QSlider::sliderMoved, this, &ZoomSlider::onSliderMoved); setFixedWidth(ZoomSliderWidth); setTargetModel(nullptr); } ZoomSlider::~ZoomSlider() = default; void ZoomSlider::setTargetModel(AbstractModel* model) { if (mModel) { mModel->disconnect(this); } mModel = model ? model->findBaseModelWithInterface() : nullptr; mZoomControl = mModel ? qobject_cast(mModel) : nullptr; const bool hasView = (mZoomControl != nullptr); if (hasView) { mSlider->setSingleStep(1); // mZoomControl->zoomLevelSingleStep()? mSlider->setPageStep(5); // mZoomControl->zoomLevelPageStep()? const int min = 0; // mZoomControl->minimumZoomLevel(); const int max = 99; // mZoomControl->maximumZoomLevel(); mSlider->setRange(min, max); onZoomLevelChange(mZoomControl->zoomLevel()); const int sliderValue = mSlider->value(); mZoomOutButton->setEnabled(sliderValue > mSlider->minimum()); mZoomInButton->setEnabled(sliderValue < mSlider->maximum()); connect(mModel, SIGNAL(zoomLevelChanged(double)), SLOT(onZoomLevelChange(double))); } else { mZoomOutButton->setEnabled(false); mZoomInButton->setEnabled(false); // put slider in the middle mSlider->setRange(0, 99); mSlider->setValue(50); } mSlider->setEnabled(hasView); } void ZoomSlider::updateToolTip(int sliderValue) { const float zoomLevel = 50.0 / (100 - sliderValue); const int zoomPercent = static_cast(zoomLevel * 100 + 0.5); mSlider->setToolTip(i18nc("@info:tooltip", "Zoom: %1%", zoomPercent)); // TODO: get the text by a signal toolTipNeeded( int zoomLevel, QString* toolTipText ); ? } void ZoomSlider::zoomOut() { const int newValue = mSlider->value() - mSlider->singleStep(); mSlider->setValue(newValue); } void ZoomSlider::zoomIn() { const int newValue = mSlider->value() + mSlider->singleStep(); mSlider->setValue(newValue); } void ZoomSlider::onSliderValueChanged(int sliderValue) { updateToolTip(sliderValue); mZoomOutButton->setEnabled(sliderValue > mSlider->minimum()); mZoomInButton->setEnabled(sliderValue < mSlider->maximum()); if (mZoomControl) { mZoomControl->setZoomLevel(50.0 / (100 - sliderValue)); } } // TODO: which signal comes first, valueChanged or sliderMoved? // ensure correct calculation of zoomLevel, best by model // but can be timeconsuming? // use timer to delay resize, so that sliding is not delayed by resizing void ZoomSlider::onSliderMoved(int sliderValue) { Q_UNUSED(sliderValue) QPoint toolTipPoint = mSlider->rect().topLeft(); toolTipPoint.ry() += mSlider->height() / 2; toolTipPoint = mSlider->mapToGlobal(toolTipPoint); QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), toolTipPoint); QApplication::sendEvent(mSlider, &toolTipEvent); } void ZoomSlider::onZoomLevelChange(double level) { mZoomLevel = level; const int newSliderValue = 100 - static_cast(50.0 / mZoomLevel + 0.5); if (newSliderValue != mSlider->value()) { disconnect(mSlider, &QSlider::valueChanged, this, &ZoomSlider::onSliderValueChanged); mSlider->setSliderPosition(newSliderValue); updateToolTip(mSlider->value()); connect(mSlider, &QSlider::valueChanged, this, &ZoomSlider::onSliderValueChanged); } } } diff --git a/libs/kasten/gui/controller/abstractlinepopup_p.cpp b/libs/kasten/gui/controller/abstractlinepopup_p.cpp index 8207386b..271b8ae6 100644 --- a/libs/kasten/gui/controller/abstractlinepopup_p.cpp +++ b/libs/kasten/gui/controller/abstractlinepopup_p.cpp @@ -1,90 +1,90 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "abstractlinepopup_p.hpp" // Qt #include #include #include #include namespace Kasten { void AbstractLinePopupPrivate::init() { // TODO: what kind of border should there be? like a QMenu? p->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu); // setAttribute( Qt::WA_DeleteOnClose ); p->setMouseTracking(true); mBaseLayout = new QHBoxLayout(p); - mBaseLayout->setMargin(0); + mBaseLayout->setContentsMargins(0, 0, 0, 0); mBaseLayout->setSpacing(0); mIconLabel = new QLabel(p); mBaseLayout->addWidget(mIconLabel); qApp->installEventFilter(p); } void AbstractLinePopupPrivate::setIcon(const QIcon& icon) { mIconLabel->setPixmap(icon.pixmap(22)); // TODO: correct call, using KDE size } void AbstractLinePopupPrivate::setWidget(QWidget* widget) { mWidget = widget; mBaseLayout->addWidget(widget, 10); } void AbstractLinePopupPrivate::setPosition(const QPoint& globalPosition) { p->move(globalPosition.x(), globalPosition.y() - p->height()); } void AbstractLinePopupPrivate::setVisible(bool visible) { p->QWidget::setVisible(visible); if (mEventLoop) { mEventLoop->exit(); } } int AbstractLinePopupPrivate::exec() { if (mWidget) { mWidget->setFocus(); } p->show(); QEventLoop eventLoop; mEventLoop = &eventLoop; eventLoop.exec(); mEventLoop = nullptr; return mResult; } } diff --git a/libs/kasten/gui/shell/statusbarlayout.cpp b/libs/kasten/gui/shell/statusbarlayout.cpp index c3d9c2ff..d20088b9 100644 --- a/libs/kasten/gui/shell/statusbarlayout.cpp +++ b/libs/kasten/gui/shell/statusbarlayout.cpp @@ -1,245 +1,245 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "statusbarlayout.hpp" // lib #include // Qt #include #include #include namespace Kasten { StatusBarLayout::StatusBarLayout(QWidget* parent) : QLayout(parent) , mIsDirty(true) , mIsEmpty(true) { - setMargin(0); + setContentsMargins(0, 0, 0, 0); } StatusBarLayout::~StatusBarLayout() { // while( !mWidgetList.isEmpty() ) // { // QWidgetItem *item = mWidgetList.takeFirst(); // delete item; // } } int StatusBarLayout::count() const { return mWidgetList.count(); } bool StatusBarLayout::isEmpty() const { if (mIsDirty) { updateLayoutStructs(); } return mIsEmpty; } QLayoutItem* StatusBarLayout::itemAt(int index) const { if (index < 0 || mWidgetList.count() <= index) { return nullptr; } return mWidgetList.at(index); } int StatusBarLayout::indexOf(QWidget* widget) const { int result = -1; for (int i = 0; i < mWidgetList.count(); ++i) { if (mWidgetList.at(i)->widget() == widget) { result = i; break; } } return result; } QSize StatusBarLayout::sizeHint() const { updateLayoutStructs(); return mSizeHint; } QSize StatusBarLayout::minimumSize() const { updateLayoutStructs(); return {0, mSizeHint.height()}; } void StatusBarLayout::addItem(QLayoutItem* item) { Q_UNUSED(item) qCWarning(LOG_KASTEN_GUI) << "not implemented! Please use addWidget() instead"; return; } QLayoutItem* StatusBarLayout::takeAt(int index) { if (index < 0 || mWidgetList.count() <= index) { return nullptr; } QWidgetItem* item = mWidgetList.takeAt(index); // TODO: any need to delete or reparent the widget? invalidate(); return item; } void StatusBarLayout::invalidate() { mIsDirty = true; QLayout::invalidate(); } Qt::Orientations StatusBarLayout::expandingDirections() const { return {}; } void StatusBarLayout::addWidget(QWidget* widget) { if (widget) { mWidgetList.append(new QWidgetItem(widget)); invalidate(); } } #if 0 void StatusBarLayout::updateMarginAndSpacing() { Statusbar* statusBar = qobject_cast(parentWidget()); if (!statusBar) { return; } QStyle* style = statusBar->style(); QStyleOptionToolBar opt; statusBar->initStyleOption(&opt); setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, statusBar) + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, statusBar)); setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, statusBar)); } #endif void StatusBarLayout::setGeometry(const QRect& _rect) { QLayout::setGeometry(_rect); if (mIsDirty) { updateLayoutStructs(); } QRect rect(0, 0, _rect.width(), _rect.height()); const int margin = 0;// this->margin(); const int spacing = this->spacing(); int availableWidth = rect.size().width() - 2 * margin; const int availableHeight = rect.size().height() - 2 * margin; int usedWidth = 0; int visibleCount = 0; int i; for (i = 0; i < mWidgetList.count(); ++i) { QWidgetItem* item = mWidgetList.at(i); QWidget* widget = item->widget(); // TODO: is there really no way to get to the geometry data if a widget is hidden? if (widget->isHidden()) { widget->show(); } const int itemWidth = item->sizeHint().width(); const int itemSpacing = (visibleCount == 0) ? 0 : spacing; const int newUsedWidth = usedWidth + itemSpacing + itemWidth; // qCDebug(LOG_KASTEN_GUI)< availableWidth); if (isTooWide) { break; } const QPoint pos(margin + usedWidth + itemSpacing, margin); const QSize size(itemWidth, availableHeight); QRect r(pos, size); r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r); item->setGeometry(r); usedWidth = newUsedWidth; ++visibleCount; } // hide the rest if needed for (; i < mWidgetList.count(); ++i) { QWidgetItem* item = mWidgetList.at(i); QWidget* widget = item->widget(); if (!widget->isHidden()) { widget->hide(); } } } void StatusBarLayout::updateLayoutStructs() const { auto* that = const_cast(this); // const int margin = this->margin(); const int spacing = this->spacing(); QSize sizeHint(0, 0); int visibleCount = 0; for (int i = 0; i < mWidgetList.count(); ++i) { QWidgetItem* item = mWidgetList.at(i); if (!item->isEmpty()) { const QSize itemSizeHint = item->sizeHint(); sizeHint.rwidth() += (visibleCount == 0 ? 0 : spacing) + itemSizeHint.width(); sizeHint.rheight() = qMax(sizeHint.height(), itemSizeHint.height()); ++visibleCount; } } // sizeHint += QSize( 2*margin, 2*margin ); that->mIsEmpty = (visibleCount == 0); that->mSizeHint = sizeHint; that->mIsDirty = false; } } diff --git a/libs/kasten/gui/shell/viewareabox.cpp b/libs/kasten/gui/shell/viewareabox.cpp index 546cd2ab..a2d4d7be 100644 --- a/libs/kasten/gui/shell/viewareabox.cpp +++ b/libs/kasten/gui/shell/viewareabox.cpp @@ -1,141 +1,141 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009,2011 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "viewareabox.hpp" // lib #include "toolinlineviewwidget.hpp" // Qt #include #include namespace Kasten { ViewAreaBox::ViewAreaBox(QWidget* centralWidget, QWidget* parent) : QWidget(parent) , mCentralWidget(centralWidget) { setFocusProxy(mCentralWidget); auto* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); if (mCentralWidget) { layout->addWidget(mCentralWidget); } mEscapeShortcut = new QShortcut(Qt::Key_Escape, this); mEscapeShortcut->setContext(Qt::WidgetWithChildrenShortcut); mEscapeShortcut->setEnabled(false); connect(mEscapeShortcut, &QShortcut::activated, this, &ViewAreaBox::onDone); // TODO: better use onCancelled } ViewAreaBox::~ViewAreaBox() { if (mCentralWidget) { mCentralWidget->setParent(nullptr); } } QWidget* ViewAreaBox::centralWidget() const { return mCentralWidget; } QWidget* ViewAreaBox::bottomToolWidget() const { return mBottomToolWidget; } void ViewAreaBox::setCentralWidget(QWidget* centralWidget) { if (mCentralWidget == centralWidget) { return; } auto* layout = static_cast(this->layout()); const bool centralWidgetIsFocusProxy = mCentralWidget ? (focusProxy() == mCentralWidget) : false; // TODO: works if focus is on childwidget? const bool centralWidgetHasFocus = mCentralWidget ? mCentralWidget->hasFocus() : false; if (mCentralWidget) { layout->removeWidget(mCentralWidget); } mCentralWidget = centralWidget; if (mCentralWidget) { layout->insertWidget(0, mCentralWidget); mCentralWidget->show(); // TODO: needed? if (centralWidgetHasFocus) { mCentralWidget->setFocus(); } if (centralWidgetIsFocusProxy) { setFocusProxy(mCentralWidget); } } } void ViewAreaBox::setBottomToolWidget(QWidget* bottomToolWidget) { if (mBottomToolWidget == bottomToolWidget) { return; } auto* layout = static_cast(this->layout()); if (mToolInlineViewWidget) { layout->removeWidget(mToolInlineViewWidget); delete mToolInlineViewWidget; mToolInlineViewWidget = nullptr; setFocusProxy(mCentralWidget); } mBottomToolWidget = bottomToolWidget; if (mBottomToolWidget) { mToolInlineViewWidget = new ToolInlineViewWidget(mBottomToolWidget); connect(mToolInlineViewWidget, &ToolInlineViewWidget::done, this, &ViewAreaBox::onDone); layout->addWidget(mToolInlineViewWidget); } } void ViewAreaBox::showBottomToolWidget() { if (!mToolInlineViewWidget) { return; } setFocusProxy(mToolInlineViewWidget); mToolInlineViewWidget->show(); mBottomToolWidget->setFocus(); mEscapeShortcut->setEnabled(true); } void ViewAreaBox::onDone() { if (!mToolInlineViewWidget) { return; } setFocusProxy(mCentralWidget); mToolInlineViewWidget->hide(); mEscapeShortcut->setEnabled(false); } } diff --git a/libs/kasten/gui/shell/viewbox.cpp b/libs/kasten/gui/shell/viewbox.cpp index 8fd7d39c..7a305568 100644 --- a/libs/kasten/gui/shell/viewbox.cpp +++ b/libs/kasten/gui/shell/viewbox.cpp @@ -1,57 +1,57 @@ /* This file is part of the Kasten Framework, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "viewbox.hpp" // lib #include "abstractview.hpp" // Qt #include namespace Kasten { ViewBox::ViewBox(AbstractView* view, QWidget* parent) : QWidget(parent) , mView(view) { QWidget* widget = view->widget(); setFocusProxy(widget); auto* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addWidget(widget); } ViewBox::~ViewBox() { mView->widget()->setParent(nullptr); } AbstractView* ViewBox::view() const { return mView; } void ViewBox::add(ViewBox::Area area) { Q_UNUSED(area); } } diff --git a/parts/kpart/part.cpp b/parts/kpart/part.cpp index cd69ca8a..8673b04a 100644 --- a/parts/kpart/part.cpp +++ b/parts/kpart/part.cpp @@ -1,243 +1,243 @@ /* This file is part of the Okteta KPart module, made within the KDE community. Copyright 2003,2007,2009,2011,2019 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "part.hpp" // part #include "partfactory.hpp" #include "browserextension.hpp" // Okteta Kasten controllers // #include #include #include #include #include #include #include #include #include #include #include #include #include // Okteta Kasten #include #include #include #include #include // Kasten controllers #include // #include // #include #include #include #include #include #include #include // #include #include // Kasten #include #include #include #include #include // Qt #include #include #include static constexpr const char* UIFileName[] = { "oktetapartreadonlyui.rc", "oktetapartbrowserui.rc", "oktetapartreadwriteui.rc" }; OktetaPart::OktetaPart(QObject* parent, const KAboutData& componentData, Modus modus, Kasten::ByteArrayViewProfileManager* viewProfileManager, Kasten::ModelCodecManager* modelCodecManager, Kasten::ModelCodecViewManager* modelCodecViewManager) : KParts::ReadWritePart(parent) , mModus(modus) , mViewProfileManager(viewProfileManager) { setComponentData(componentData); QWidget* widget = new QWidget(); mLayout = new QVBoxLayout(widget); - mLayout->setMargin(0); + mLayout->setContentsMargins(0, 0, 0, 0); setWidget(widget); setXMLFile(QLatin1String(UIFileName[modus])); mSingleViewArea = new Kasten::SingleViewArea(); auto areaWidget = mSingleViewArea->widget(); mLayout->addWidget(areaWidget); mLayout->parentWidget()->setFocusProxy(areaWidget); if (modus == Modus::ReadWrite) { addController(Kasten::VersionControllerFactory()); } if (modus == Modus::ReadWrite) { addController(Kasten::ReadOnlyControllerFactory()); } // TODO: save_as addController(Kasten::ExportControllerFactory(modelCodecViewManager, modelCodecManager)); addController(Kasten::ZoomControllerFactory()); addController(Kasten::SelectControllerFactory()); if (modus != Modus::BrowserView) { addController(Kasten::ClipboardControllerFactory()); } if (modus == Modus::ReadWrite) { addController(Kasten::InsertControllerFactory(modelCodecViewManager, modelCodecManager)); } addController(Kasten::CopyAsControllerFactory(modelCodecViewManager, modelCodecManager)); if (modus == Modus::ReadWrite) { addController(Kasten::OverwriteModeControllerFactory()); } addController(Kasten::SearchControllerFactory(widget)); if (modus == Modus::ReadWrite) { addController(Kasten::ReplaceControllerFactory(widget)); } addController(Kasten::GotoOffsetControllerFactory(mSingleViewArea)); addController(Kasten::SelectRangeControllerFactory(mSingleViewArea)); // addController(Kasten::BookmarksControllerFactory()); addController(Kasten::PrintControllerFactory()); addController(Kasten::ViewConfigControllerFactory()); addController(Kasten::ViewModeControllerFactory()); addController(Kasten::ViewContextMenuControllerFactory()); addController(Kasten::ViewProfileControllerFactory(mViewProfileManager, widget)); // Kasten::StatusBar* bottomBar = static_cast( statusBar() ); // addController(ViewStatusControllerFactory(bottomBar) ); // addController(ReadOnlyBarControllerFactory(bottomBar) ); // addController(ZoomBarControllerFactory(bottomBar) ); // addTool( new DocumentInfoToolView(new DocumentInfoTool(mProgram->documentManager()->syncManager())) ); // addTool( new ChecksumToolView(new ChecksumTool()) ); // addTool( new FilterToolView(new FilterTool()) ); // addTool( new StringsExtractToolView(new StringsExtractTool()) ); // addTool( new ByteTableToolView(new ByteTableTool()) ); // addTool( new InfoToolView(new InfoTool()) ); // addTool( new PODDecoderToolView(new PODDecoderTool()) ); // addTool( new BookmarksToolView(new BookmarksTool()) ); // TODO: BrowserExtension might rely on existing objects (session snap while loadJob), // so this hack just creates some dummies mDocument = new Kasten::ByteArrayDocument(QString()); auto* viewProfileSynchronizer = new Kasten::ByteArrayViewProfileSynchronizer(viewProfileManager); mByteArrayView = new Kasten::ByteArrayView(mDocument, viewProfileSynchronizer); if (modus == Modus::BrowserView) { new OktetaBrowserExtension(this); } } OktetaPart::~OktetaPart() { qDeleteAll(mControllers); delete mSingleViewArea; delete mByteArrayView; delete mDocument; } void OktetaPart::addController(const Kasten::AbstractXmlGuiControllerFactory& factory) { Kasten::AbstractXmlGuiController* controller = factory.create(this); mControllers.append(controller); } void OktetaPart::setReadWrite(bool readWrite) { mDocument->setReadOnly(!readWrite); KParts::ReadWritePart::setReadWrite(readWrite); // TODO: call to super needed? } bool OktetaPart::openFile() { auto* synchronizerFactory = new Kasten::ByteArrayRawFileSynchronizerFactory(); Kasten::AbstractModelSynchronizer* synchronizer = synchronizerFactory->createSynchronizer(); Kasten::AbstractLoadJob* loadJob = synchronizer->startLoad(QUrl::fromLocalFile(localFilePath())); connect(loadJob, &Kasten::AbstractLoadJob::documentLoaded, this, &OktetaPart::onDocumentLoaded); Kasten::JobManager::executeJob(loadJob); delete synchronizerFactory; return true; } bool OktetaPart::saveFile() { Kasten::AbstractModelSynchronizer* synchronizer = mDocument->synchronizer(); Kasten::AbstractSyncWithRemoteJob* syncJob = synchronizer->startSyncWithRemote(QUrl::fromLocalFile(localFilePath()), Kasten::AbstractModelSynchronizer::ReplaceRemote); const bool syncSucceeded = Kasten::JobManager::executeJob(syncJob); return syncSucceeded; } void OktetaPart::onDocumentLoaded(Kasten::AbstractDocument* document) { if (document) { for (Kasten::AbstractXmlGuiController* controller : qAsConst(mControllers)) { controller->setTargetModel(nullptr); } mSingleViewArea->setView(nullptr); delete mByteArrayView; delete mDocument; mDocument = static_cast(document); mDocument->setReadOnly(mModus != Modus::ReadWrite); connect(mDocument->synchronizer(), &Kasten::AbstractModelSynchronizer::localSyncStateChanged, this, &OktetaPart::onModified); auto* viewProfileSynchronizer = new Kasten::ByteArrayViewProfileSynchronizer(mViewProfileManager); viewProfileSynchronizer->setViewProfileId(mViewProfileManager->defaultViewProfileId()); mByteArrayView = new Kasten::ByteArrayView(mDocument, viewProfileSynchronizer); connect(mByteArrayView, SIGNAL(hasSelectedDataChanged(bool)), SIGNAL(hasSelectedDataChanged(bool))); mSingleViewArea->setView(mByteArrayView); for (Kasten::AbstractXmlGuiController* controller : qAsConst(mControllers)) { controller->setTargetModel(mByteArrayView); } setModified(false); } } void OktetaPart::onModified(Kasten::LocalSyncState state) { const bool isModified = (state != Kasten::LocalInSync); setModified(isModified); }