File indexing completed on 2025-02-16 14:33:58
0001 /*************************************************************************** 0002 previewlist.cpp - description 0003 ------------------- 0004 begin : Sat Oct 06 2007 0005 copyright : (C) 2007 by Dominik Seichter 0006 email : domseichter@web.de 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "previewlist.h" 0019 0020 #include "customdialog.h" 0021 #include "krenamemodel.h" 0022 0023 #include <QContextMenuEvent> 0024 #include <QMenu> 0025 #include <QPointer> 0026 0027 PreviewList::PreviewList(QWidget *parent) 0028 : QTreeView(parent), m_model(nullptr) 0029 { 0030 m_menu = new QMenu("KRename", this); // we need any text here so that we have a title 0031 m_menu->addAction(i18n("&Change filename manually..."), this, SLOT(slotManually()), QKeySequence("F2")); 0032 m_menu->addSeparator(); 0033 m_menu->addAction(i18n("&Open"), this, SLOT(slotOpen())); 0034 m_menu->addSeparator(); 0035 m_menu->addAction(i18n("&Add..."), this, SIGNAL(addFiles())); 0036 m_menu->addAction(i18n("&Remove"), this, SLOT(slotRemove())); 0037 0038 connect(this, &PreviewList::activated, this, &PreviewList::slotManually); 0039 } 0040 0041 PreviewList::~PreviewList() 0042 { 0043 0044 } 0045 0046 void PreviewList::contextMenuEvent(QContextMenuEvent *e) 0047 { 0048 // only show a context menu if we have model and contents 0049 if (m_model && m_model->rowCount() && currentIndex().isValid()) { 0050 const KRenameFile &file = m_model->file(this->currentIndex().row()); 0051 0052 m_menu->setTitle(file.srcUrl().toDisplayString(QUrl::PreferLocalFile)); 0053 m_menu->popup(e->globalPos()); 0054 } 0055 } 0056 0057 void PreviewList::slotOpen() 0058 { 0059 m_model->run(this->currentIndex(), this); 0060 } 0061 0062 void PreviewList::slotRemove() 0063 { 0064 QList<int> list; 0065 0066 list.append(this->currentIndex().row()); 0067 0068 m_model->removeFiles(list); 0069 0070 emit updateCount(); 0071 } 0072 0073 void PreviewList::slotManually() 0074 { 0075 QPointer<CustomDialog> dialog = new CustomDialog(m_model->file(this->currentIndex().row()), this); 0076 if (dialog->exec() == QDialog::Accepted) { 0077 QString manual; 0078 EManualChangeMode mode = eManualChangeMode_None; 0079 if (dialog->hasManualChanges()) { 0080 manual = dialog->manualChanges(); 0081 mode = dialog->manualChangeMode(); 0082 } 0083 0084 m_model->file(this->currentIndex().row()).setManualChanges(manual, mode); 0085 } 0086 delete dialog; 0087 }