File indexing completed on 2024-04-21 04:20:51
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) 2000-2016 Klaas Freitag <freitag@suse.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 KOOKAVIEW_H 0033 #define KOOKAVIEW_H 0034 0035 #include <qtabwidget.h> 0036 0037 #include <kservice.h> 0038 0039 #include "statusbarmanager.h" 0040 0041 #include "imagecanvas.h" 0042 #include "kscandevice.h" 0043 #include "scanimage.h" 0044 0045 class QSplitter; 0046 class QUrl; 0047 0048 class QAction; 0049 class KMainWindow; 0050 class KActionMenu; 0051 0052 class ThumbView; 0053 class KookaGallery; 0054 class OcrResEdit; 0055 class ScanGallery; 0056 class KookaScanParams; 0057 class Previewer; 0058 class KScanDevice; 0059 class ImageCanvas; 0060 0061 class WidgetSite; 0062 0063 0064 /** 0065 * This is the main view class for Kooka. Most of the non-menu, 0066 * non-toolbar, and non-statusbar (e.g., non frame) GUI code should go 0067 * here. 0068 * 0069 * @short Main view 0070 * @author Klaas Freitag <freitag@suse.de> 0071 * @version 0.1 0072 */ 0073 class KookaView : public QTabWidget 0074 { 0075 Q_OBJECT 0076 0077 public: 0078 enum MirrorType { MirrorVertical, MirrorHorizontal, MirrorBoth }; 0079 enum TabPage { TabScan = 0, TabGallery = 1, TabOcr = 2, TabNone = 0xFF }; 0080 0081 /** 0082 * To avoid a proliferation of boolean parameters, these flags are 0083 * used to indicate the state of the gallery and image viewers. 0084 */ 0085 enum StateFlag 0086 { 0087 GalleryShown = 0x001, // in Gallery/OCR mode 0088 PreviewValid = 0x002, // scan preview valid 0089 ImageValid = 0x004, // viewer image loaded 0090 IsDirectory = 0x008, // directory selected 0091 FileSelected = 0x010, // 1 file selected 0092 ManySelected = 0x020, // multiple selection 0093 RootSelected = 0x040, // root is selected 0094 IsSubImage = 0x080, // a subimage selected 0095 HasSubImages = 0x100 // contains subimages 0096 }; 0097 Q_DECLARE_FLAGS(StateFlags, StateFlag) 0098 0099 /** 0100 * Default constructor 0101 */ 0102 explicit KookaView(KMainWindow *parent, const QByteArray &deviceToUse); 0103 0104 /** 0105 * Destructor 0106 */ 0107 virtual ~KookaView(); 0108 0109 /** 0110 * Print this view to any medium -- paper or not 0111 */ 0112 void print(); 0113 0114 void loadStartupImage(); 0115 ScanGallery *gallery() const; 0116 ImageCanvas *imageViewer() const; 0117 Previewer *previewer() const; 0118 0119 bool isScannerConnected() const; 0120 QString scannerName() const; 0121 void closeScanDevice(); 0122 0123 void connectViewerAction(QAction *action, bool sepBefore = false); 0124 void connectGalleryAction(QAction *action, bool sepBefore = false); 0125 void connectThumbnailAction(QAction *action); 0126 void connectPreviewAction(QAction *action); 0127 void imageViewerAction(ImageCanvas::UserAction act); 0128 0129 void saveWindowSettings(KConfigGroup &grp); 0130 void applyWindowSettings(const KConfigGroup &grp); 0131 0132 public slots: 0133 void slotStartOcr(); 0134 void slotStartOcrSelection(); 0135 void slotStartOcrFile(); 0136 void slotSetOcrSpellConfig(const QString &configFile); 0137 void slotOcrSpellCheck(bool interactive = true, bool background = false); 0138 void slotSaveOcrResult(); 0139 0140 void slotStartPreview(); 0141 void slotNewPreview(ScanImage::Ptr newimg); 0142 void slotStartFinalScan(); 0143 void slotAutoSelect(bool on); 0144 0145 void slotCreateNewImgFromSelection(); 0146 void slotTransformImage(); 0147 0148 void slotScanParams(); 0149 void slotApplySettings(); 0150 0151 /** 0152 * slot to select the scanner device. Does all the work with selection 0153 * of scanner, disconnection of the old device and connecting the new. 0154 */ 0155 bool slotSelectDevice(const QByteArray &useDevice = "", bool alwaysAsk = true); 0156 void slotAddDevice(); 0157 0158 void slotScanStart(ScanImage::ImageType type); 0159 void slotScanFinished(KScanDevice::Status stat); 0160 void slotAcquireStart(); 0161 0162 void showOpenWithMenu(KActionMenu *menu); 0163 0164 protected slots: 0165 void slotShowImage(ScanImage::Ptr img, bool isDir); 0166 void slotUnloadImage(); 0167 0168 void slotNewImageScanned(ScanImage::Ptr img); 0169 0170 void slotSelectionChanged(const QRect &newSelection); 0171 void slotGallerySelectionChanged(); 0172 0173 void slotOcrResultAvailable(); 0174 0175 void slotTabChanged(int index); 0176 0177 signals: 0178 /** 0179 * Change the content of the statusbar 0180 */ 0181 void changeStatus(const QString &text, StatusBarManager::Item item = StatusBarManager::Message); 0182 0183 /** 0184 * Clean up the statusbar 0185 */ 0186 void clearStatus(StatusBarManager::Item item = StatusBarManager::Message); 0187 0188 /** 0189 * Use this signal to change the content of the caption 0190 */ 0191 void signalChangeCaption(const QString &text); 0192 0193 void signalViewSelectionState(KookaView::StateFlags state); 0194 void signalScannerChanged(bool haveConnection); 0195 void signalRectangleChanged(bool haveSelection); 0196 void signalOcrResultAvailable(bool haveText); 0197 void signalOcrPrefs(); 0198 0199 private: 0200 void startOCR(ScanImage::Ptr img); 0201 0202 QByteArray userDeviceSelection(bool alwaysAsk); 0203 0204 void saveGalleryState(int index = -1) const; 0205 void restoreGalleryState(int index = -1); 0206 0207 void updateSelectionState(); 0208 0209 private slots: 0210 void slotStartLoading(const QUrl &url); 0211 void slotOpenWith(int idx); 0212 void slotPreviewDimsChanged(const QString &dims); 0213 0214 private: 0215 KMainWindow *mMainWindow; 0216 0217 ImageCanvas *mImageCanvas; 0218 ThumbView *mThumbView; 0219 Previewer *mPreviewCanvas; 0220 KookaGallery *mGallery; 0221 KookaScanParams *mScanParams; 0222 0223 KScanDevice *mScanDevice; 0224 0225 OcrResEdit *mOcrResEdit; 0226 0227 KookaView::TabPage mCurrentTab; 0228 0229 QSplitter *mScanPage; 0230 QSplitter *mScanSubSplitter; 0231 QSplitter *mGalleryPage; 0232 QSplitter *mGallerySubSplitter; 0233 QSplitter *mOcrPage; 0234 QSplitter *mOcrSubSplitter; 0235 0236 WidgetSite *mParamsSite; 0237 0238 WidgetSite *mScanGallerySite; 0239 WidgetSite *mGalleryGallerySite; 0240 WidgetSite *mOcrGallerySite; 0241 0242 WidgetSite *mGalleryImgviewSite; 0243 WidgetSite *mOcrImgviewSite; 0244 0245 KService::List mOpenWithOffers; 0246 }; 0247 0248 Q_DECLARE_OPERATORS_FOR_FLAGS(KookaView::StateFlags) 0249 0250 #endif // KOOKAVIEW_H