Hydra 0.20
|
00001 00002 /* 00003 * Copyright (c) 2010 Aleksander B. Demko 00004 * This source code is distributed under the MIT license. 00005 * See the accompanying file LICENSE.MIT.txt for details. 00006 */ 00007 00008 #ifndef __INCLUDED_HYDRADESKTOP_MAINWINDOW_H__ 00009 #define __INCLUDED_HYDRADESKTOP_MAINWINDOW_H__ 00010 00011 #include <hydra/TR1.h> 00012 00013 #include <QMainWindow> 00014 00015 #include <hydra/Registry.h> 00016 #include <desktop/FileList.h> 00017 #include <desktop/ImageCache.h> 00018 #include <desktop/ThumbCache.h> 00019 #include <desktop/View.h> 00020 #include <desktop/RunnableEvent.h> 00021 #include <desktop/FutureLoader.h> 00022 00023 /** 00024 * The desktop namespace contains all the classes 00025 * for the Hydra Desktop GUI application. 00026 * This application uses the hydra library. 00027 * 00028 * @author Aleksander Demko 00029 */ 00030 namespace desktop 00031 { 00032 class MainPlugin; 00033 00034 class MainImageView; //fwd 00035 00036 class MainState; 00037 class MainWindow; 00038 } 00039 00040 class QStackedWidget; //fwd 00041 00042 class desktop::MainPlugin 00043 { 00044 public: 00045 typedef hydra::Registry<MainPlugin> registry_type; 00046 static registry_type registry; 00047 public: 00048 enum { 00049 // when menu it should be in 00050 menuSelection = 1, 00051 menuView, 00052 menuPlugin, 00053 }; 00054 public: 00055 virtual ~MainPlugin() { } 00056 00057 virtual QString description(void) const = 0; 00058 virtual int menuType(void) const { return menuSelection; } 00059 virtual void go(desktop::MainWindow *mainwindow, desktop::FileList *filelist) = 0; 00060 }; 00061 00062 /** 00063 * This is shared state by all the MainWindows 00064 * 00065 * @author Aleksander Demko 00066 */ 00067 class desktop::MainState 00068 { 00069 private: 00070 desktop::RunnableEventProcessor dm_runnableeventprocessor; 00071 00072 public: 00073 //FileItemCache dm_fileitemcache; 00074 FileEntryCache dm_fileentrycache; 00075 ImageCache dm_imagecache; 00076 ThreadedThumbCache dm_thumbcache; 00077 00078 FileList dm_leftlist;//, dm_rightlist; 00079 00080 FutureLoader dm_futureloader; 00081 00082 public: 00083 /// ctor 00084 MainState(void); 00085 /// dtor 00086 ~MainState(); 00087 }; 00088 00089 class desktop::MainWindow : public QMainWindow 00090 { 00091 Q_OBJECT 00092 00093 public: 00094 static const short FULL_VIEW = 0; 00095 static const short VCR_VIEW = 1; 00096 static const short STRIP_VIEW = 2; 00097 static const short CATALOG_VIEW = 3; 00098 static const short LISTIMAGE_VIEW = 4; // aka Folder and List 00099 static const short THUMBS_VIEW = 11; 00100 00101 public: 00102 MainWindow(short initMode, std::shared_ptr<MainState> state 00103 = std::shared_ptr<MainState>(new MainState())); 00104 00105 virtual ~MainWindow(); 00106 00107 MainState & mainState(void) const { return *dm_state; } 00108 std::shared_ptr<MainState> mainStatePtr(void) const { return dm_state; } 00109 00110 // used by hydra.cpp, mostly 00111 00112 desktop::FileList & leftList(void) { return dm_leftlist; } 00113 const desktop::FileList & leftList(void) const { return dm_leftlist; } 00114 00115 //desktop::FileList & rightList(void) { return dm_rightlist; } 00116 //const desktop::FileList & rightList(void) const { return dm_rightlist; } 00117 00118 void buildMenuFile(QMenu &outmenu); 00119 void buildMenuImage(QMenu &outmenu); 00120 void buildMenuSelection(QMenu &outmenu); 00121 void buildMenuView(QMenu &outmenu); 00122 void buildMenuPlugin(QMenu &outmenu); 00123 void buildMenuWindow(QMenu &outmenu); 00124 00125 void popupWidgetAsDockWidget(QWidget *w); 00126 00127 /** 00128 * Increment the current file, aswell as preload the next file 00129 * in the cache. 00130 * 00131 * In the future, this should be abtracted away to handle any 00132 * FileList or ImageCache 00133 * 00134 * @author Aleksander Demko 00135 */ 00136 void advanceAndPreloadSelectedFile(void); 00137 00138 /** 00139 * Sets the "last tag". The last tag is the last keyword 00140 * tag that was added to a record. 00141 * 00142 * @author Aleksander Demko 00143 */ 00144 void setLastTag(const QString <) { dm_lasttag = lt; } 00145 00146 /// returns the last tag 00147 const QString &lastTag(void) const { return dm_lasttag; } 00148 00149 protected: 00150 QDockWidget * dockifyWidget(QWidget *v); 00151 virtual void timerEvent(QTimerEvent * event); 00152 00153 public slots: 00154 void toggleFullScreen(void); 00155 void toggleSlideShow(void); 00156 00157 private slots: 00158 void onCurrentChanged(void); 00159 void onAbout(void); 00160 void onQuit(void); 00161 void onMenuOpenDir(void); 00162 void onMenuOpenDirBrowser(void); 00163 void onMenuImage(void); 00164 void onMenuAnyPlugin(void); 00165 void onMenuWindow(void); 00166 void onMenuRotate(void); 00167 00168 void onTimePreloadNextImage(void); 00169 00170 private: 00171 void initActions(void); 00172 void buildMenuBar(QMenuBar &outmenu); 00173 void initGui(short initModevoid); 00174 void initPlugins(void); 00175 00176 QWidget * initLayout(short ty, QWidget * &focuswidget); 00177 00178 private: 00179 std::shared_ptr<MainState> dm_state; 00180 00181 FileList &dm_leftlist; 00182 00183 MainImageView *dm_fullscreenview; 00184 00185 bool dm_slideshow_active; 00186 00187 // menus 00188 QAction *dm_file_directory, *dm_file_directory_r, *dm_file_directory_popout, *dm_file_about, *dm_file_quit; 00189 QAction *dm_fullscreen_action, *dm_slideshow_action; 00190 QAction *dm_rotate_reset, *dm_rotate_left, *dm_rotate_right; // future: move this to an edit menu? 00191 QAction *dm_image_first, *dm_image_prev, *dm_image_next, *dm_image_last; // future: random, slideshow, full screen 00192 00193 std::vector<QAction*> dm_selectionmenu, dm_viewmenu, dm_pluginmenu, dm_windowmenu; 00194 00195 // plugins 00196 std::vector<std::shared_ptr<MainPlugin> > dm_allplugins; 00197 00198 // the last applied tag 00199 QString dm_lasttag; 00200 }; 00201 00202 #endif 00203