Warning, file /utilities/kronometer/src/gui/mainwindow.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 Copyright (C) 2014 by Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 This file is part of Kronometer. 0005 0006 Kronometer is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 2 of the License, or 0009 (at your option) any later version. 0010 0011 Kronometer is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with Kronometer. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 0021 #ifndef MAINWINDOW_H 0022 #define MAINWINDOW_H 0023 0024 #include "session.h" 0025 0026 #include <KXmlGuiWindow> 0027 0028 #include <QPointer> 0029 #include <QTimer> 0030 0031 #include <memory> 0032 0033 class LapModel; 0034 class SessionModel; 0035 class Stopwatch; 0036 class TimeDisplay; 0037 0038 class KToggleAction; 0039 0040 class QAction; 0041 class QDBusInterface; 0042 class QLabel; 0043 class QSortFilterProxyModel; 0044 class QSplitter; 0045 class QTableView; 0046 class QTextStream; 0047 class QToolButton; 0048 0049 /** 0050 * @brief Kronometer main window. 0051 */ 0052 class MainWindow : public KXmlGuiWindow 0053 { 0054 Q_OBJECT 0055 0056 public: 0057 0058 explicit MainWindow(QWidget *parent = nullptr, const Session& session = Session {}); 0059 virtual ~MainWindow(); 0060 0061 /** 0062 * @param title The title for this window. 0063 */ 0064 void setWindowTitle(const QString& title); 0065 0066 protected: 0067 0068 bool queryClose() override; 0069 0070 private slots: 0071 0072 /** 0073 * Stopwatch running state triggers. 0074 */ 0075 void slotRunning(); 0076 0077 /** 0078 * Stopwatch paused state triggers. 0079 */ 0080 void slotPaused(); 0081 0082 /** 0083 * Stopwatch inactive state triggers. 0084 */ 0085 void slotInactive(); 0086 0087 /** 0088 * Slot for the system bus PrepareForSleep signal. 0089 * @param beforeSleep Whether the signal has been emitted before suspension. 0090 */ 0091 void slotPrepareForSleep(bool beforeSleep); 0092 0093 /** 0094 * Setup the settings dialog. 0095 */ 0096 void slotShowSettings(); 0097 0098 /** 0099 * Write the new settings on filesystem. 0100 */ 0101 void slotWriteSettings(); 0102 0103 /** 0104 * Fix lap dock appereance. 0105 */ 0106 void slotUpdateLapDock(); 0107 0108 /** 0109 * Open a new MainWindow instance. 0110 */ 0111 void slotNewSession(); 0112 0113 /** 0114 * Open an existing session in a new MainWindow instance. 0115 */ 0116 void slotOpenSession(); 0117 0118 /** 0119 * Save current times in the current session. 0120 */ 0121 void slotSaveSession(); 0122 0123 /** 0124 * Save current times as a new session. 0125 */ 0126 void slotSaveSessionAs(); 0127 0128 /** 0129 * Export current lap times on a file. 0130 */ 0131 void slotExportLapsAs(); 0132 0133 /** 0134 * Copy current stopwatch time to clipboard. 0135 */ 0136 void slotCopyToClipboard(); 0137 0138 /** 0139 * Toggle menubar visibility. 0140 */ 0141 void slotToggleMenuBar(); 0142 0143 void slotUpdateControlMenu(); 0144 0145 void slotToolBarUpdated(); 0146 0147 private: 0148 0149 Stopwatch *m_stopwatch; 0150 TimeDisplay *m_stopwatchDisplay; 0151 QTableView *m_lapView; 0152 0153 QAction *m_startAction; 0154 QAction *m_pauseAction; 0155 QAction *m_resetAction; 0156 QAction *m_lapAction; 0157 QAction *m_exportAction; 0158 std::unique_ptr<QTimer> m_controlMenuTimer; 0159 QPointer<QToolButton> m_controlMenuButton; 0160 KToggleAction *m_toggleMenuAction; 0161 0162 LapModel *m_lapModel; 0163 SessionModel *m_sessionModel; 0164 0165 Session m_session; 0166 0167 QDBusInterface *m_screensaverInterface = nullptr; 0168 quint32 m_screenInhibitCookie = 0; 0169 0170 /** 0171 * Setup the central widget of the window. 0172 */ 0173 void setupCentralWidget(); 0174 0175 /** 0176 * Setup standard and custom QActions. 0177 */ 0178 void setupActions(); 0179 0180 /** 0181 * Load settings from app Config and apply them to the other objects. 0182 */ 0183 void loadSettings(); 0184 0185 /** 0186 * Set the stopwatch refresh granularity. 0187 */ 0188 void setupGranularity(); 0189 0190 /** 0191 * Create a session with the current stopwatch time and lap times. 0192 * @param name The name of the session to be saved. 0193 */ 0194 void saveSessionAs(const QString& name); 0195 0196 /** 0197 * Load a saved session. 0198 */ 0199 void loadSession(); 0200 0201 /** 0202 * Export current lap times on a new file. 0203 * @param name The name of the file to be created. 0204 * @param mimeType The mime type of the file to be created. 0205 */ 0206 void exportLapsAs(const QString& name, const QString& mimeType); 0207 0208 /** 0209 * Write the JSON laps representation on the given object. 0210 * @param json The JSON object to be written. 0211 */ 0212 void exportLapsAsJson(QJsonObject& json); 0213 0214 /** 0215 * Write the CSV laps representation on the given stream. 0216 * @param out The stream to be written. 0217 */ 0218 void exportLapsAsCsv(QTextStream& out); 0219 0220 /** 0221 * @return Whether there is a window size saved in the kronometer config. 0222 */ 0223 bool isWindowSizeSaved() const; 0224 0225 /** 0226 * A "comment" message with timestamp, to be used in the created files. 0227 * @return The string "Created by Kronomer on <timestamp>" 0228 */ 0229 QString timestampMessage(); 0230 0231 void createControlMenuButton(); 0232 0233 void deleteControlMenuButton(); 0234 0235 /** 0236 * @return true if @p action has been added to @p menu; 0237 * false if @p action or @p menu is null, or if @p action 0238 * is already on the toolBar(). 0239 */ 0240 bool addActionToMenu(QAction* action, QMenu* menu); 0241 0242 void activateScreenInhibition(); 0243 0244 void disactivateScreenInhibition(); 0245 0246 Q_DISABLE_COPY(MainWindow) 0247 }; 0248 0249 0250 #endif