File indexing completed on 2024-04-28 08:11:06
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 1999-2016 Klaas Freitag <Klaas.Freitag@gmx.de> * 0007 * Jonathan Marten <jjm@keelhaul.me.uk> * 0008 * * 0009 * Kooka is free software; you can redistribute it and/or modify it * 0010 * under the terms of the GNU Library General Public License as * 0011 * published by the Free Software Foundation and appearing in the * 0012 * file COPYING included in the packaging of this file; either * 0013 * version 2 of the License, or (at your option) any later version. * 0014 * * 0015 * As a special exception, permission is given to link this program * 0016 * with any version of the KADMOS OCR/ICR engine (a product of * 0017 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0018 * executable without including the source code for KADMOS in the * 0019 * source distribution. * 0020 * * 0021 * This program is distributed in the hope that it will be useful, * 0022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0024 * GNU General Public License for more details. * 0025 * * 0026 * You should have received a copy of the GNU General Public * 0027 * License along with this program; see the file COPYING. If * 0028 * not, see <http://www.gnu.org/licenses/>. * 0029 * * 0030 ************************************************************************/ 0031 0032 #ifndef SCANGALLERY_H 0033 #define SCANGALLERY_H 0034 0035 #include "kookacore_export.h" 0036 0037 #include "filetreeview.h" 0038 0039 #include "imageformat.h" 0040 #include "scanimage.h" 0041 0042 class QImage; 0043 class QTreeWidgetItem; 0044 class QMenu; 0045 class QUrl; 0046 0047 class ImgSaver; 0048 0049 0050 class KOOKACORE_EXPORT ScanGallery : public FileTreeView 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 explicit ScanGallery(QWidget *parent); 0056 ~ScanGallery() override; 0057 0058 QString currentImageFileName() const; 0059 ScanImage::Ptr getCurrImage(bool loadOnDemand = false); 0060 0061 QMenu *contextMenu() const 0062 { 0063 return m_contextMenu; 0064 } 0065 void openRoots(); 0066 0067 void setAllowRename(bool on); 0068 0069 bool prepareToSave(ScanImage::ImageType type); 0070 void addImage(ScanImage::Ptr img); 0071 0072 void saveHeaderState(int forIndex) const; 0073 void restoreHeaderState(int forIndex); 0074 QUrl saveURL() const; 0075 0076 public slots: 0077 void slotExportFile(); 0078 void slotImportFile(); 0079 void slotSelectImage(const QUrl &url); 0080 void slotSelectDirectory(const QString &branchName, const QString &relPath); 0081 void slotUnloadItems(); 0082 0083 void slotHighlightItem(const QUrl &url); 0084 void slotActivateItem(const QUrl &url); 0085 void slotUpdatedItem(const QUrl &url); 0086 0087 void slotCreateFolder(); 0088 void slotDeleteItems(); 0089 void slotRenameItems(); 0090 void slotItemProperties(); 0091 0092 protected: 0093 // TODO: port D&D 0094 //virtual void contentsDragMoveEvent( QDragMoveEvent *ev); 0095 void contextMenuEvent(QContextMenuEvent *ev) override; 0096 0097 protected slots: 0098 void slotImageArrived(FileTreeViewItem *item, ScanImage::Ptr img); 0099 void slotUnloadItem(FileTreeViewItem *curr); 0100 void slotDirCount(FileTreeViewItem *item, int cnt); 0101 void slotStartupFinished(FileTreeViewItem *item); 0102 void slotItemExpanded(QTreeWidgetItem *item); 0103 0104 void slotUrlsDropped(QDropEvent *ev, FileTreeViewItem *item); 0105 void slotJobResult(KJob *job); 0106 bool slotFileRenamed(FileTreeViewItem *item, const QString &newName); 0107 0108 void slotDecorate(FileTreeViewItem *item); 0109 void slotDecorate(FileTreeBranch *branch, const FileTreeViewItemList &list); 0110 0111 void slotItemHighlighted(QTreeWidgetItem *curr = nullptr); 0112 void slotItemActivated(QTreeWidgetItem *curr); 0113 0114 signals: 0115 void aboutToShowImage(const QUrl &url); 0116 void showImage(ScanImage::Ptr img, bool isDir); 0117 void deleteImage(ScanImage::Ptr img); 0118 void unloadImage(ScanImage::Ptr img); 0119 void galleryPathChanged(const FileTreeBranch *branch, const QString &relPath); 0120 void galleryDirectoryRemoved(const FileTreeBranch *branch, const QString &relPath); 0121 0122 void imageChanged(const KFileItem *kfi); 0123 void fileChanged(const KFileItem *kfi); 0124 void fileRenamed(const KFileItem *item, const QString &newName); 0125 void showItem(const KFileItem *kfi); 0126 0127 void itemHighlighted(const QUrl &url, bool isDir); 0128 0129 private: 0130 void loadImageForItem(FileTreeViewItem *item); 0131 FileTreeBranch *openRoot(const QUrl &root, const QString &title = QString()); 0132 0133 FileTreeViewItem *findItemByUrl(const QUrl &url, FileTreeBranch *branch = nullptr); 0134 QUrl itemDirectory(const FileTreeViewItem *item) const; 0135 QString itemDirectoryRelative(const FileTreeViewItem *item) const; 0136 void updateParent(const FileTreeViewItem *curr); 0137 0138 QUrl m_currSelectedDir; 0139 QMenu *m_contextMenu; 0140 0141 ImgSaver *mSaver; 0142 FileTreeViewItem *mSavedTo; 0143 0144 // like m_nextUrlToSelect in KFileTreeView, 0145 // but for our own purposes (showing the image) 0146 QUrl m_nextUrlToShow; 0147 0148 FileTreeBranch *m_defaultBranch; 0149 bool m_startup; 0150 }; 0151 0152 #endif // SCANGALLERY_H