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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "common/extactioncontainer.h"
#include "db/db.h"
#include "ui_mainwindow.h"
#include "mdiwindow.h"
#include "guiSQLiteStudio_global.h"
#include <QMainWindow>
#include <QHash>
#include <QQueue>
class QUiLoader;
class DbTree;
class StatusField;
class EditorWindow;
class MdiArea;
class QActionGroup;
class MdiWindow;
class ViewWindow;
class TableWindow;
class FormManager;
class DdlHistoryWindow;
class FunctionsEditor;
class CollationsEditor;
class BugReportHistoryWindow;
class NewVersionDialog;
class Committable;
class WidgetCover;
class QProgressBar;
class QLabel;
class QTimer;
class ThemeTuner;
class SqliteExtensionEditor;
class CodeSnippetEditor;
#ifdef Q_OS_MACX
#define PREV_TASK_KEY_SEQ Qt::CTRL + Qt::ALT + Qt::Key_Left
#define NEXT_TASK_KEY_SEQ Qt::CTRL + Qt::ALT + Qt::Key_Right
#else
#define PREV_TASK_KEY_SEQ Qt::CTRL + Qt::Key_PageUp
#define NEXT_TASK_KEY_SEQ Qt::CTRL + Qt::Key_PageDown
#endif
CFG_KEY_LIST(MainWindow, QObject::tr("Main window"),
CFG_KEY_ENTRY(OPEN_SQL_EDITOR, Qt::ALT + Qt::Key_E, QObject::tr("Open SQL editor"))
CFG_KEY_ENTRY(OPEN_DDL_HISTORY, Qt::CTRL + Qt::Key_H, QObject::tr("Open DDL history window"))
CFG_KEY_ENTRY(OPEN_SNIPPETS_EDITOR, Qt::CTRL + Qt::SHIFT + Qt::Key_P, QObject::tr("Open snippets editor window"))
CFG_KEY_ENTRY(OPEN_FUNCTION_EDITOR, Qt::CTRL + Qt::SHIFT + Qt::Key_F, QObject::tr("Open function editor window"))
CFG_KEY_ENTRY(OPEN_COLLATION_EDITOR, Qt::CTRL + Qt::SHIFT + Qt::Key_L, QObject::tr("Open collation editor window"))
CFG_KEY_ENTRY(OPEN_EXTENSION_MANAGER, Qt::CTRL + Qt::SHIFT + Qt::Key_E, QObject::tr("Open extension manager window"))
CFG_KEY_ENTRY(PREV_TASK, PREV_TASK_KEY_SEQ, QObject::tr("Previous window"))
CFG_KEY_ENTRY(NEXT_TASK, NEXT_TASK_KEY_SEQ, QObject::tr("Next window"))
CFG_KEY_ENTRY(HIDE_STATUS_FIELD, Qt::Key_Escape, QObject::tr("Hide status area"))
CFG_KEY_ENTRY(USER_MANUAL, Qt::Key_F1, QObject::tr("Open user manual"))
CFG_KEY_ENTRY(OPEN_CONFIG, Qt::Key_F10, QObject::tr("Open configuration dialog"))
CFG_KEY_ENTRY(OPEN_DEBUG_CONSOLE, Qt::Key_F12, QObject::tr("Open Debug Console"))
CFG_KEY_ENTRY(OPEN_CSS_CONSOLE, Qt::Key_F11, QObject::tr("Open CSS Console"))
CFG_KEY_ENTRY(ABOUT, Qt::SHIFT + Qt::Key_F1, QObject::tr("Open the About dialog"))
CFG_KEY_ENTRY(QUIT, Qt::CTRL + Qt::Key_Q, QObject::tr("Quit the application"))
)
class GUI_API_EXPORT MainWindow : public QMainWindow, public ExtActionContainer
{
Q_OBJECT
public:
enum Action
{
MDI_TILE,
MDI_CASCADE,
MDI_TILE_HORIZONTAL,
MDI_TILE_VERTICAL,
OPEN_SQL_EDITOR,
NEXT_TASK,
PREV_TASK,
HIDE_STATUS_FIELD,
OPEN_CONFIG,
OPEN_DDL_HISTORY,
OPEN_SNIPPETS_EDITOR,
OPEN_FUNCTION_EDITOR,
OPEN_COLLATION_EDITOR,
OPEN_EXTENSION_MANAGER,
EXPORT,
IMPORT,
CLOSE_WINDOW,
CLOSE_ALL_WINDOWS,
CLOSE_ALL_WINDOWS_LEFT,
CLOSE_ALL_WINDOWS_RIGHT,
CLOSE_OTHER_WINDOWS,
RESTORE_WINDOW,
RENAME_WINDOW,
OPEN_DEBUG_CONSOLE,
OPEN_CSS_CONSOLE,
LICENSES,
HOMEPAGE,
USER_MANUAL,
SQLITE_DOCS,
REPORT_BUG,
FEATURE_REQUEST,
ABOUT,
DONATE,
BUG_REPORT_HISTORY,
CHECK_FOR_UPDATES,
QUIT
};
Q_ENUM(Action)
enum ToolBar
{
TOOLBAR_MAIN,
TOOLBAR_DATABASE,
TOOLBAR_STRUCTURE,
TOOLBAR_VIEW
};
static MainWindow* getInstance();
static void setSafeMode(bool enabled);
static bool isSafeMode();
MdiArea* getMdiArea() const;
DbTree* getDbTree() const;
StatusField* getStatusField() const;
void restoreSession();
bool setStyle(const QString& styleName);
FormManager* getFormManager() const;
bool eventFilter(QObject* obj, QEvent* e);
void pushClosedWindowSessionValue(const QVariant& value);
bool hasClosedWindowToRestore() const;
bool isClosingApp() const;
QToolBar* getToolBar(int toolbar) const;
void openDb(const QString& path);
QMenu* getDatabaseMenu() const;
QMenu* getStructureMenu() const;
QMenu* getViewMenu() const;
QMenu* getToolsMenu() const;
QMenu* getSQLiteStudioMenu() const;
QString currentStyle() const;
ThemeTuner* getThemeTuner() const;
EditorWindow* openSqlEditor(Db* dbToSet, const QString& sql);
static_char* ALLOW_MULTIPLE_SESSIONS_SETTING = "AllowMultipleSessions";
protected:
void closeEvent(QCloseEvent *event);
private:
MainWindow();
~MainWindow();
void init();
void observeSessionChanges();
void createActions();
void setupDefShortcuts();
void initMenuBar();
void saveSession(MdiWindow* currWindow);
void saveSession(bool hide);
void restoreWindowSessions(const QList<QVariant>& windowSessions);
MdiWindow *restoreWindowSession(const QVariant& windowSessions);
void closeNonSessionWindows();
DdlHistoryWindow* openDdlHistory();
FunctionsEditor* openFunctionEditor();
CodeSnippetEditor* openCodeSnippetEditor();
CollationsEditor* openCollationEditor();
SqliteExtensionEditor* openExtensionManager();
void fixFonts();
void fixToolbars();
template <class T>
T* openMdiWindow();
static bool confirmQuit(const QList<Committable*>& instances);
static MainWindow* instance;
static bool safeModeEnabled;
static constexpr int closedWindowsStackSize = 20;
static_char* openUpdatesUrl = "open_updates://";
static constexpr int saveSessionDelayMs = 500;
Ui::MainWindow *ui = nullptr;
DbTree* dbTree = nullptr;
StatusField* statusField = nullptr;
QMenu* mdiMenu = nullptr;
FormManager* formManager = nullptr;
QQueue<QVariant> closedWindowSessionValues;
bool closingApp = false;
QMenu* dbMenu = nullptr;
QMenu* structMenu = nullptr;
QMenu* viewMenu = nullptr;
QMenu* toolsMenu = nullptr;
QMenu* sqlitestudioMenu = nullptr;
#ifdef PORTABLE_CONFIG
QPointer<NewVersionDialog> newVersionDialog;
#endif
WidgetCover* widgetCover = nullptr;
QTimer* saveSessionTimer = nullptr;
public slots:
EditorWindow* openSqlEditor();
void updateWindowActions();
void updateCornerDocking();
void messageFromSecondaryInstance(quint32 instanceId, QByteArray message);
void licenses();
void homepage();
void githubReleases();
void userManual();
void sqliteDocs();
void reportHistory();
void donate();
private slots:
void notifyAboutLanguageChange();
void cleanUp();
void openSqlEditorSlot();
void refreshMdiWindows();
void hideStatusField();
void openConfig();
void openDdlHistorySlot();
void openFunctionEditorSlot();
void openCodeSnippetsEditorSlot();
void openCollationEditorSlot();
void openExtensionManagerSlot();
void exportAnything();
void importAnything();
void closeAllWindows();
void closeAllLeftWindows();
void closeAllRightWindows();
void closeAllWindowsButSelected();
void closeSelectedWindow();
void restoreLastClosedWindow();
void renameWindow();
void openDebugConsole();
void openCssConsole();
void reportBug();
void requestFeature();
void aboutSqlitestudio();
#ifdef PORTABLE_CONFIG
void updateAvailable(const QString& version, const QString& url);
void noUpdatesAvailable(bool enforced);
void checkForUpdates();
#endif
void statusFieldLinkClicked(const QString& link);
void quit();
void updateMultipleSessionsSetting();
void updateMultipleSessionsSetting(const QVariant& newValue);
void saveSession();
void scheduleSessionSave();
signals:
void sessionValueChanged();
};
template <class T>
T* MainWindow::openMdiWindow()
{
T* win = nullptr;
for (MdiWindow* mdiWin : ui->mdiArea->getWindows())
{
win = dynamic_cast<T*>(mdiWin->getMdiChild());
if (win)
{
ui->mdiArea->setActiveSubWindow(mdiWin);
return win;
}
}
win = new T(ui->mdiArea);
if (win->isInvalid())
{
delete win;
return nullptr;
}
ui->mdiArea->addSubWindow(win);
return win;
}
#define MAINWINDOW MainWindow::getInstance()
#endif // MAINWINDOW_H
|