1 /* 2 * Copyright 2012, 2013, 2014 Thomas Schöps, Kai Pastor 3 * 4 * This file is part of OpenOrienteering. 5 * 6 * OpenOrienteering is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * OpenOrienteering is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 21 #ifndef OPENORIENTEERING_HOME_SCREEN_WIDGET_H 22 #define OPENORIENTEERING_HOME_SCREEN_WIDGET_H 23 24 #include <vector> 25 26 #include <QIcon> 27 #include <QObject> 28 #include <QPixmap> 29 #include <QString> 30 #include <QStringList> 31 #include <QWidget> 32 33 class QAbstractButton; 34 class QCheckBox; 35 class QFileInfo; 36 class QIcon; 37 class QLabel; 38 class QListWidget; 39 class QListWidgetItem; 40 class QPaintEvent; 41 class QPushButton; 42 class QResizeEvent; 43 class QStackedLayout; 44 45 namespace OpenOrienteering { 46 47 class HomeScreenController; 48 class StorageLocation; 49 50 51 /** 52 * The user interface of the OpenOrienteering Mapper home screen. 53 * The OpenOrienteering Mapper home screen is shown when no document is open, 54 * for example after the program is started for the first time. 55 */ 56 class AbstractHomeScreenWidget : public QWidget 57 { 58 Q_OBJECT 59 public: 60 /** Creates a new AbstractHomeScreenWidget for the given controller. */ 61 AbstractHomeScreenWidget(HomeScreenController* controller, QWidget* parent = nullptr); 62 63 /** Destroys the AbstractHomeScreenWidget. */ 64 ~AbstractHomeScreenWidget() override; 65 66 public slots: 67 /** Sets the list of recent files. */ 68 virtual void setRecentFiles(const QStringList& files) = 0; 69 70 /** Sets the "checked" state of the control for opening 71 * the most recently used file on startup. */ 72 virtual void setOpenMRUFileChecked(bool state) = 0; 73 74 /** Sets the text of the the tip-of-the-day. */ 75 virtual void setTipOfTheDay(const QString& text) = 0; 76 77 /** Sets the visibility of the tip-of-the-day, and 78 * sets the "checked" state of the control for displaying the tip. */ 79 virtual void setTipsVisible(bool state) = 0; 80 81 protected: 82 /** Returns a QLabel for displaying a headline in the home screen. */ 83 QLabel* makeHeadline(const QString& text, QWidget* parent = nullptr) const; 84 85 /** Returns a button with the given text 86 * for triggering a top level activity in the home screen. 87 * There will be no icon or a default icon. */ 88 QAbstractButton* makeButton(const QString& text, QWidget* parent = nullptr) const; 89 90 /** Returns a button with the given text and icon 91 * for triggering a top level activity in the home screen. */ 92 QAbstractButton* makeButton(const QString& text, const QIcon& icon, QWidget* parent = nullptr) const; 93 94 /** Returns the role to be used for storing paths. */ pathRole()95 constexpr static int pathRole() { return Qt::UserRole; } 96 97 HomeScreenController* controller; 98 }; 99 100 101 /** 102 * Implementation of AbstractHomeScreenWidget for desktop PCs. 103 */ 104 class HomeScreenWidgetDesktop : public AbstractHomeScreenWidget 105 { 106 Q_OBJECT 107 public: 108 /** Creates a new HomeScreenWidgetDesktop for the given controller. */ 109 HomeScreenWidgetDesktop(HomeScreenController* controller, QWidget* parent = nullptr); 110 111 /** Destroys the HomeScreenWidgetDesktop. */ 112 ~HomeScreenWidgetDesktop() override; 113 114 public slots: 115 /** Sets the list of recent files. */ 116 void setRecentFiles(const QStringList& files) override; 117 118 /** Sets the "checked" state of the control for opening 119 * the most recently used file on startup. */ 120 void setOpenMRUFileChecked(bool state) override; 121 122 /** Sets the text of the the tip-of-the-day. */ 123 void setTipOfTheDay(const QString& text) override; 124 125 /** Sets the visibility of the tip-of-the-day, and 126 * sets the "checked" state of the control for displaying the tip. */ 127 void setTipsVisible(bool state) override; 128 129 protected slots: 130 /** Opens a file when its is list item is clicked. */ 131 void recentFileClicked(QListWidgetItem* item); 132 133 protected: 134 /** Draws the home screen background when a paint event occurs. */ 135 void paintEvent(QPaintEvent* event) override; 136 137 /** Creates the activities widget. */ 138 QWidget* makeMenuWidget(HomeScreenController* controller, QWidget* parent = nullptr); 139 140 /** Creates the recent files widget. */ 141 QWidget* makeRecentFilesWidget(HomeScreenController* controller, QWidget* parent = nullptr); 142 143 /** Creates the tip-of-the-day widget. */ 144 QWidget* makeTipsWidget(HomeScreenController* controller, QWidget* parent = nullptr); 145 146 147 QListWidget* recent_files_list; 148 QCheckBox* open_mru_file_check; 149 QLabel* tips_label; 150 QCheckBox* tips_check; 151 std::vector<QWidget*> tips_children; 152 }; 153 154 155 /** 156 * Implementation of AbstractHomeScreenWidget for mobile devices. 157 */ 158 class HomeScreenWidgetMobile : public AbstractHomeScreenWidget 159 { 160 Q_OBJECT 161 public: 162 /** Creates a new HomeScreenWidgetMobile for the given controller. */ 163 HomeScreenWidgetMobile(HomeScreenController* controller, QWidget* parent = nullptr); 164 165 /** Destroys the HomeScreenWidgetMobile. */ 166 ~HomeScreenWidgetMobile() override; 167 168 public slots: 169 /** Sets the list of recent files. */ 170 void setRecentFiles(const QStringList& files) override; 171 172 /** Sets the "checked" state of the control for opening 173 * the most recently used file on startup. */ 174 void setOpenMRUFileChecked(bool state) override; 175 176 /** Sets the text of the the tip-of-the-day. */ 177 void setTipOfTheDay(const QString& text) override; 178 179 /** Sets the visibility of the tip-of-the-day, and 180 * sets the "checked" state of the control for displaying the tip. */ 181 void setTipsVisible(bool state) override; 182 183 /** Shows the settings dialog, adjusted for small screens. */ 184 void showSettings(); 185 186 protected: 187 /** Opens a file when its is list item is clicked. */ 188 void itemClicked(QListWidgetItem* item); 189 190 /** Rechecks the current selected item. */ 191 void permissionRequestDone(); 192 193 /** Triggers title image adjustment on resize events. */ 194 void resizeEvent(QResizeEvent* event) override; 195 196 /** Resizes the title image to fit both the labels width and height */ 197 void adjustTitlePixmapSize(); 198 199 /** Creates the file list widget. */ 200 QListWidget* makeFileListWidget(); 201 202 /** Updates the file list widget. */ 203 void updateFileListWidget(); 204 205 /** Add a single file or dir item to the file list. */ 206 void addItemToFileList(const QFileInfo& file_info, int hint = 0, const QIcon& icon = {}); 207 208 /** Add a single item to the file list, using a custom display name. */ 209 void addItemToFileList(const QString& label, const QFileInfo& file_info, int hint = 0, const QIcon& icon = {}); 210 211 /** Returns the role to be used for storing hints (number or text). */ hintRole()212 constexpr static int hintRole() { return Qt::UserRole + 1; } 213 214 private: 215 QPixmap title_pixmap; 216 QLabel* title_label; 217 QListWidget* file_list_widget; 218 std::vector<StorageLocation> history; 219 }; 220 221 222 } // namespace OpenOrienteering 223 #endif 224