From 0e3b4c23dc6e93441615da23bfe17db86abfd62f Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 24 Apr 2016 22:08:41 +0200 Subject: [PATCH] added context menu for file info tree view --- gui/fileinfomodel.cpp | 13 +- gui/tageditorwidget.cpp | 44 ++++- gui/tageditorwidget.h | 2 +- translations/tageditor_de_DE.ts | 287 +++++++++++++++++--------------- translations/tageditor_en_US.ts | 287 +++++++++++++++++--------------- 5 files changed, 341 insertions(+), 292 deletions(-) diff --git a/gui/fileinfomodel.cpp b/gui/fileinfomodel.cpp index b1c543e..ebdf64e 100644 --- a/gui/fileinfomodel.cpp +++ b/gui/fileinfomodel.cpp @@ -151,8 +151,11 @@ template void addElementNode(Eleme auto *firstItem = defaultItem(QString::fromLatin1(element->idToString().data())); parent->appendRow(QList() << firstItem - << defaultItem(QStringLiteral("offset: 0x") + QString::number(element->startOffset(), 16)) - << defaultItem(QStringLiteral("size: 0x") + QString::number(element->totalSize(), 16))); + << defaultItem( + QStringLiteral("offset: 0x") + % QString::number(element->startOffset(), 16) + % QStringLiteral(", size: 0x") + % QString::number(element->totalSize(), 16))); if(element->firstChild()) { addElementNode(element->firstChild(), firstItem); } @@ -198,11 +201,9 @@ QVariant FileInfoModel::headerData(int section, Qt::Orientation orientation, int case Qt::DisplayRole: switch(section) { case 0: - tr("Property"); - break; + return tr("Property"); case 1: - tr("Value"); - break; + return tr("Value"); default: ; } diff --git a/gui/tageditorwidget.cpp b/gui/tageditorwidget.cpp index c951cf1..a0323f0 100644 --- a/gui/tageditorwidget.cpp +++ b/gui/tageditorwidget.cpp @@ -573,6 +573,10 @@ void TagEditorWidget::initInfoView() #endif if(!m_infoTreeView) { m_infoTreeView = new QTreeView(this); + m_infoTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + m_infoTreeView->setSelectionBehavior(QAbstractItemView::SelectItems); + m_infoTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection); + connect(m_infoTreeView, &QWidget::customContextMenuRequested, this, &TagEditorWidget::showInfoTreeViewContextMenu); m_ui->tagSplitter->addWidget(m_infoTreeView); } if(!m_infoModel) { @@ -605,6 +609,34 @@ void TagEditorWidget::updateInfoView() } } +void TagEditorWidget::showInfoTreeViewContextMenu(const QPoint &) +{ + QAction copyAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy"), nullptr); + copyAction.setDisabled(m_infoTreeView->selectionModel()->selectedIndexes().isEmpty()); + connect(©Action, &QAction::triggered, [this] { + const auto selection = m_infoTreeView->selectionModel()->selectedIndexes(); + if(!selection.isEmpty()) { + QStringList text; + text.reserve(selection.size()); + for(const QModelIndex &index : selection) { + text << index.data().toString(); + } + QApplication::clipboard()->setText(text.join(QChar(' '))); + // TODO: improve copied text + } + }); + QAction expandAllAction(QIcon::fromTheme(QStringLiteral("expand-menu-hover")), tr("Expand all"), nullptr); + connect(&expandAllAction, &QAction::triggered, m_infoTreeView, &QTreeView::expandAll); + QAction collapseAllAction(QIcon::fromTheme(QStringLiteral("collapse-menu-hover")), tr("Collapse all"), nullptr); + connect(&collapseAllAction, &QAction::triggered, m_infoTreeView, &QTreeView::collapseAll); + QMenu menu; + menu.addAction(©Action); + menu.addSeparator(); + menu.addAction(&expandAllAction); + menu.addAction(&collapseAllAction); + menu.exec(QCursor::pos()); +} + #ifndef TAGEDITOR_NO_WEBVIEW /*! * \brief Shows the context menu for the info web view. @@ -613,19 +645,13 @@ void TagEditorWidget::showInfoWebViewContextMenu(const QPoint &) { QAction copyAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy"), nullptr); copyAction.setDisabled(m_infoWebView->selectedText().isEmpty()); - connect(©Action, &QAction::triggered, this, &TagEditorWidget::copyInfoWebViewSelection); + connect(©Action, &QAction::triggered, [this] { + QApplication::clipboard()->setText(m_infoWebView->selectedText()); + }); QMenu menu; menu.addAction(©Action); menu.exec(QCursor::pos()); } - -/*! - * \brief Copies the current selection of the info web view. - */ -void TagEditorWidget::copyInfoWebViewSelection() -{ - QApplication::clipboard()->setText(m_infoWebView->selectedText()); -} #endif /*! diff --git a/gui/tageditorwidget.h b/gui/tageditorwidget.h index af8bff8..70a88f7 100644 --- a/gui/tageditorwidget.h +++ b/gui/tageditorwidget.h @@ -118,9 +118,9 @@ private slots: // info (web) view void initInfoView(); void updateInfoView(); + void showInfoTreeViewContextMenu(const QPoint &); #ifndef TAGEDITOR_NO_WEBVIEW void showInfoWebViewContextMenu(const QPoint &); - void copyInfoWebViewSelection(); #endif private: diff --git a/translations/tageditor_de_DE.ts b/translations/tageditor_de_DE.ts index 548af69..ffbd443 100644 --- a/translations/tageditor_de_DE.ts +++ b/translations/tageditor_de_DE.ts @@ -1033,99 +1033,99 @@ Remarks QtGui::FileInfoModel - + Property - + Value - + Path - - - - + + + + Size - - + + Duration - + Overall avg. bitrate - - + + Mime-type - + Container - + Title (segment %1) - + Title - - - + + + Version - + Read version - + Document type - + Document version - + Document read version - + Padding size - + Tags - + %1 tag(s) assigned @@ -1133,23 +1133,23 @@ Remarks - + Target level - + Field count - - + + Tracks - + %1 track(s) contained @@ -1157,205 +1157,205 @@ Remarks - + Track #%1 - - - - + + + + ID - + Number - - + + Name - + Type - + Format - + Abbreviation - + Level - + Extension - + Format/codec ID - + Avg. bitrate - + Max. bitrate - + Creation time - + Modification time - + Language - + Compressor name - + Sampling frequency - + Sample count - + Bits per sample - + Quality - + Pixel size - + Display size - + Pixel Aspect Ratio - + Cropping - + Resolution - + Channel config - + Channel count - + Bit depth - + Frames per second - + Chroma format - + interlaced - - + + disabled - - + + default - + forced - + has lacing - + encrypted - - - + + + Labeled as - + Attachments - + %1 attachment(s) present @@ -1363,48 +1363,48 @@ Remarks - + Attachment #%1 - + Description - + Chapter #%1 - + Name (%1) - + Start time - + End time - - + + hidden - + Editions - + %1 edition(s) present @@ -1412,22 +1412,22 @@ Remarks - + Edition #%1 - + ordered - + Chapters - + %1 chapter(s) present @@ -1435,18 +1435,18 @@ Remarks - + Structure - + Notifications (reparsing after saving) - - + + Notifications @@ -2621,7 +2621,7 @@ the file reverting all unsaved changings. - + Abort @@ -2737,121 +2737,122 @@ the file reverting all unsaved changings. + Copy - + Unable to load the selected file "%1" because the current process hasn't finished yet. - + The file is beeing parsed ... - + Unable to reload the file because the current process hasn't finished yet. - + Currently is not file opened. - + The file could not be opened because an IO error occurred. - + File could be parsed correctly. - + File couldn't be parsed correctly. - + There are critical parsing notifications. - + There are warnings. - + There is no (supported) tag assigned. - + File format is not supported (an ID3 tag can be added anyways). - + The file %1 has been opened. - + Unable to apply the entered tags to the file because the current process hasn't finished yet. - + Saving tags ... - + No file has been opened. - + Unable to delete all tags from the file because the current process hasn't been finished yet. - + Do you really want to delete all tags from the file? - + don't show this message again - + Deleting all tags ... - + The selected file stores no tag (at least no supported), so there is nothing to delete. - + No file has been opened, so no tags can be deleted. - + Unable to start saving process because there an other process hasn't finished yet. - + Cancelling ... @@ -2861,17 +2862,27 @@ the file reverting all unsaved changings. - + + Expand all + + + + + Collapse all + + + + No write access; the file has been opened in read-only mode. - + The file is composed of multiple segments. Dealing with such files has not been tested yet and might be broken. - + The tags have been saved, but there is/are %1 warning(s) @@ -2879,7 +2890,7 @@ the file reverting all unsaved changings. - + and %1 error(s). @@ -2887,7 +2898,7 @@ the file reverting all unsaved changings. - + The tags have been saved, but there is/are %1 warning(s). @@ -2895,72 +2906,72 @@ the file reverting all unsaved changings. - + The tags have been saved. - + The tags couldn't be saved. See the info box for detail. - + The tags couldn't be saved because an IO error occured. - + Automatic tag management - + The container format of the selected file is not supported. The file can be treated as MP3 file (an ID3 tag according to the settings will be created). This might break the file. Do you want to continue? - + Treat file as MP3 file - + The currently opened file changed on the disk. - + A tag (with the selected target) already exists. - + The tag can not be created. - + Unable to remove the tag because the current process hasn't been finished yet. - + Unable to remove the tag because no file is opened. - + Unable to change the target because the current process hasn't been finished yet. - + Unable to change the target because no file is opened. - + Can not change the target of the selected tag because the tag does not support targets. diff --git a/translations/tageditor_en_US.ts b/translations/tageditor_en_US.ts index 2612ee6..b306fe0 100644 --- a/translations/tageditor_en_US.ts +++ b/translations/tageditor_en_US.ts @@ -1033,99 +1033,99 @@ Remarks QtGui::FileInfoModel - + Property - + Value - + Path - - - - + + + + Size - - + + Duration - + Overall avg. bitrate - - + + Mime-type - + Container - + Title (segment %1) - + Title - - - + + + Version - + Read version - + Document type - + Document version - + Document read version - + Padding size - + Tags - + %1 tag(s) assigned %1 tag assigned @@ -1133,23 +1133,23 @@ Remarks - + Target level - + Field count - - + + Tracks - + %1 track(s) contained %1 track contained @@ -1157,205 +1157,205 @@ Remarks - + Track #%1 - - - - + + + + ID - + Number - - + + Name - + Type - + Format - + Abbreviation - + Level - + Extension - + Format/codec ID - + Avg. bitrate - + Max. bitrate - + Creation time - + Modification time - + Language - + Compressor name - + Sampling frequency - + Sample count - + Bits per sample - + Quality - + Pixel size - + Display size - + Pixel Aspect Ratio - + Cropping - + Resolution - + Channel config - + Channel count - + Bit depth - + Frames per second - + Chroma format - + interlaced - - + + disabled - - + + default - + forced - + has lacing - + encrypted - - - + + + Labeled as - + Attachments - + %1 attachment(s) present %1 attachment present @@ -1363,48 +1363,48 @@ Remarks - + Attachment #%1 - + Description - + Chapter #%1 - + Name (%1) - + Start time - + End time - - + + hidden - + Editions - + %1 edition(s) present %1 edition present @@ -1412,22 +1412,22 @@ Remarks - + Edition #%1 - + ordered - + Chapters - + %1 chapter(s) present %1 chapter present @@ -1435,18 +1435,18 @@ Remarks - + Structure - + Notifications (reparsing after saving) - - + + Notifications @@ -2612,136 +2612,147 @@ Error in line %1: %3 + Copy - + + Expand all + + + + + Collapse all + + + + The file is beeing parsed ... - + Unable to load the selected file "%1" because the current process hasn't finished yet. - + Currently is not file opened. - + Unable to reload the file because the current process hasn't finished yet. - + The file could not be opened because an IO error occurred. - + File could be parsed correctly. - + File couldn't be parsed correctly. - + There are critical parsing notifications. - + There are warnings. - + No write access; the file has been opened in read-only mode. - + File format is not supported (an ID3 tag can be added anyways). - + The file is composed of multiple segments. Dealing with such files has not been tested yet and might be broken. - + There is no (supported) tag assigned. - + The file %1 has been opened. - + Saving tags ... - + No file has been opened. - + Unable to apply the entered tags to the file because the current process hasn't finished yet. - + Do you really want to delete all tags from the file? - + don't show this message again - + Deleting all tags ... - + The selected file stores no tag (at least no supported), so there is nothing to delete. - + No file has been opened, so no tags can be deleted. - + Unable to delete all tags from the file because the current process hasn't been finished yet. - + Cancelling ... - + Unable to start saving process because there an other process hasn't finished yet. - + The tags have been saved, but there is/are %1 warning(s) The tags have been saved, but there is %1 warning @@ -2749,7 +2760,7 @@ Error in line %1: %3 - + and %1 error(s). @@ -2757,7 +2768,7 @@ Error in line %1: %3 - + The tags have been saved, but there is/are %1 warning(s). The tags have been saved, but there is %1 warning. @@ -2765,72 +2776,72 @@ Error in line %1: %3 - + The tags have been saved. - + The tags couldn't be saved. See the info box for detail. - + The tags couldn't be saved because an IO error occured. - + Automatic tag management - + The container format of the selected file is not supported. The file can be treated as MP3 file (an ID3 tag according to the settings will be created). This might break the file. Do you want to continue? - + Treat file as MP3 file - + The currently opened file changed on the disk. - + A tag (with the selected target) already exists. - + The tag can not be created. - + Unable to remove the tag because no file is opened. - + Unable to remove the tag because the current process hasn't been finished yet. - + Unable to change the target because no file is opened. - + Can not change the target of the selected tag because the tag does not support targets. - + Unable to change the target because the current process hasn't been finished yet. @@ -2900,7 +2911,7 @@ the file reverting all unsaved changings. - + Abort