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